[Bf-blender-cvs] [bfaf7a3eb15] blender2.8: OpenGL: stop enabling GL_TEXTURE

Mike Erwin noreply at git.blender.org
Thu Apr 27 17:29:25 CEST 2017


Commit: bfaf7a3eb15e36e69fc00448e6c7fd938a6fa2fa
Author: Mike Erwin
Date:   Thu Apr 27 11:24:35 2017 -0400
Branches: blender2.8
https://developer.blender.org/rBbfaf7a3eb15e36e69fc00448e6c7fd938a6fa2fa

OpenGL: stop enabling GL_TEXTURE

Texturing is always enabled in GLSL. Simply use a sampler in the shader.

Replaced gpu_generate_mipmap with glGenerateMipmap since the former just Enabled/Disabled the texture target and called the latter.

Part of T51164

===================================================================

M	source/blender/editors/space_view3d/drawmesh.c
M	source/blender/gpu/GPU_draw.h
M	source/blender/gpu/intern/gpu_draw.c
M	source/blender/gpu/intern/gpu_texture.c

===================================================================

diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c
index 1162a7ac36d..7db72d2c338 100644
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ b/source/blender/editors/space_view3d/drawmesh.c
@@ -323,7 +323,6 @@ static bool set_draw_settings_cached(
 			if (texpaint) {
 				c_badtex = false;
 				if (GPU_verify_image(ima, NULL, GL_TEXTURE_2D, 0, 1, 0, false)) {
-					glEnable(GL_TEXTURE_2D);
 					glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
 					glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
 					glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
@@ -332,7 +331,6 @@ static bool set_draw_settings_cached(
 					glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
 					
 					glActiveTexture(GL_TEXTURE1);
-					glEnable(GL_TEXTURE_2D);
 					glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
 					glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
 					glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
@@ -346,14 +344,12 @@ static bool set_draw_settings_cached(
 				}
 				else {
 					glActiveTexture(GL_TEXTURE1);
-					glDisable(GL_TEXTURE_2D);
 					glBindTexture(GL_TEXTURE_2D, 0);
 					glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 					glActiveTexture(GL_TEXTURE0);									
 
 					c_badtex = true;
 					GPU_clear_tpage(true);
-					glDisable(GL_TEXTURE_2D);
 					glBindTexture(GL_TEXTURE_2D, 0);
 					glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 				}
@@ -459,7 +455,6 @@ static void draw_textured_begin(Scene *scene, SceneLayer *sl, View3D *v3d, Regio
 	 * in new texpaint code. The better solution here would be to support GLSL */
 	if (Gtexdraw.is_texpaint) {			
 		glActiveTexture(GL_TEXTURE1);
-		glEnable(GL_TEXTURE_2D);
 		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
 		glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
 		glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
@@ -474,7 +469,6 @@ static void draw_textured_begin(Scene *scene, SceneLayer *sl, View3D *v3d, Regio
 			glActiveTexture(GL_TEXTURE2);
 			if (GPU_verify_image(Gtexdraw.stencil, NULL, GL_TEXTURE_2D, false, false, false, false)) {
 				float col[4] = {imapaint->stencil_col[0], imapaint->stencil_col[1], imapaint->stencil_col[2], 1.0f};
-				glEnable(GL_TEXTURE_2D);
 				glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
 				glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
 				glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
@@ -509,14 +503,12 @@ static void draw_textured_end(void)
 {
 	if (Gtexdraw.ob->mode & OB_MODE_TEXTURE_PAINT) {
 		glActiveTexture(GL_TEXTURE1);
-		glDisable(GL_TEXTURE_2D);
 		glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);
 		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 		glBindTexture(GL_TEXTURE_2D, 0);
 
 		if (Gtexdraw.stencil != NULL) {
 			glActiveTexture(GL_TEXTURE2);
-			glDisable(GL_TEXTURE_2D);
 			glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);
 			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 			glBindTexture(GL_TEXTURE_2D, 0);
diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h
index 7afb4c2b88b..f6bfada7fd8 100644
--- a/source/blender/gpu/GPU_draw.h
+++ b/source/blender/gpu/GPU_draw.h
@@ -204,7 +204,6 @@ typedef struct GPUStateValues
 	unsigned int is_sample_alpha_to_coverage : 1;
 	unsigned int is_scissor_test : 1;
 	unsigned int is_stencil_test : 1;
-	unsigned int is_texture_2d : 1;
 
 	/* GL_DEPTH_BUFFER_BIT */
 	/* unsigned int is_depth_test : 1; */
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 19fb37b47a6..3567fc1f062 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -286,25 +286,6 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap)
 	}
 }
 
-static void gpu_generate_mipmap(GLenum target)
-{
-	const bool is_ati = GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY);
-	int target_enabled = 0;
-
-	/* work around bug in ATI driver, need to have GL_TEXTURE_2D enabled
-	 * http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation */
-	if (is_ati) {
-		target_enabled = glIsEnabled(target);
-		if (!target_enabled)
-			glEnable(target);
-	}
-
-	glGenerateMipmap(target);
-
-	if (is_ati && !target_enabled)
-		glDisable(target);
-}
-
 void GPU_set_mipmap(bool mipmap)
 {
 	if (GTS.domipmap != mipmap) {
@@ -432,7 +413,6 @@ void GPU_clear_tpage(bool force)
 	GTS.alphablend = -1;
 
 	glDisable(GL_BLEND);
-	glDisable(GL_TEXTURE_2D);
 	glDisable(GL_TEXTURE_GEN_S);
 	glDisable(GL_TEXTURE_GEN_T);
 	glDisable(GL_ALPHA_TEST);
@@ -876,7 +856,7 @@ void GPU_create_gl_tex(
 
 		if (GPU_get_mipmap() && mipmap) {
 			if (GTS.gpu_mipmap) {
-				gpu_generate_mipmap(GL_TEXTURE_2D);
+				glGenerateMipmap(GL_TEXTURE_2D);
 			}
 			else {
 				int i;
@@ -927,7 +907,7 @@ void GPU_create_gl_tex(
 
 			if (GPU_get_mipmap() && mipmap) {
 				if (GTS.gpu_mipmap) {
-					gpu_generate_mipmap(GL_TEXTURE_CUBE_MAP);
+					glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
 				}
 				else {
 					if (!ibuf) {
@@ -1101,12 +1081,8 @@ int GPU_set_tpage(MTexPoly *mtexpoly, int mipmap, int alphablend)
 		GTS.curtilemode = GTS.tilemode;
 		GTS.curtileXRep = GTS.tileXRep;
 		GTS.curtileYRep = GTS.tileYRep;
-
-		glEnable(GL_TEXTURE_2D);
 	}
 	else {
-		glDisable(GL_TEXTURE_2D);
-
 		GTS.curtile = 0;
 		GTS.curima = NULL;
 		GTS.curtilemode = 0;
@@ -1235,7 +1211,7 @@ static bool gpu_check_scaled_image(ImBuf *ibuf, Image *ima, float *frect, int x,
 		}
 
 		if (GPU_get_mipmap()) {
-			gpu_generate_mipmap(GL_TEXTURE_2D);
+			glGenerateMipmap(GL_TEXTURE_2D);
 		}
 		else {
 			ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
@@ -1285,7 +1261,7 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
 			/* we have already accounted for the case where GTS.gpu_mipmap is false
 			 * so we will be using GPU mipmap generation here */
 			if (GPU_get_mipmap()) {
-				gpu_generate_mipmap(GL_TEXTURE_2D);
+				glGenerateMipmap(GL_TEXTURE_2D);
 			}
 			else {
 				ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
@@ -1319,7 +1295,7 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
 
 		/* see comment above as to why we are using gpu mipmap generation here */
 		if (GPU_get_mipmap()) {
-			gpu_generate_mipmap(GL_TEXTURE_2D);
+			glGenerateMipmap(GL_TEXTURE_2D);
 		}
 		else {
 			ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
@@ -2297,8 +2273,6 @@ void GPU_state_init(void)
 	glDisable(GL_DEPTH_TEST);
 	glDisable(GL_LOGIC_OP);
 	glDisable(GL_STENCIL_TEST);
-	glDisable(GL_TEXTURE_1D);
-	glDisable(GL_TEXTURE_2D);
 	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
 	glDepthRange(0.0, 1.0);
@@ -2552,7 +2526,6 @@ void gpuSaveState(GPUStateValues *values, eGPUStateMask mask)
 		values->is_sample_alpha_to_coverage = glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE);
 		values->is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
 		values->is_stencil_test = glIsEnabled(GL_STENCIL_TEST);
-		values->is_texture_2d = glIsEnabled(GL_TEXTURE_2D);
 	}
 
 	if ((mask & GPU_SCISSOR_BIT) != 0) {
@@ -2615,7 +2588,6 @@ void gpuRestoreState(GPUStateValues *values)
 		restore_mask(GL_SAMPLE_ALPHA_TO_COVERAGE, values->is_sample_alpha_to_coverage);
 		restore_mask(GL_SCISSOR_TEST, values->is_scissor_test);
 		restore_mask(GL_STENCIL_TEST, values->is_stencil_test);
-		restore_mask(GL_TEXTURE_2D, values->is_texture_2d);
 	}
 
 	if ((mask & GPU_VIEWPORT_BIT) != 0) {
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c
index 1eab7f37c83..31c871008bd 100644
--- a/source/blender/gpu/intern/gpu_texture.c
+++ b/source/blender/gpu/intern/gpu_texture.c
@@ -675,14 +675,6 @@ void GPU_texture_bind(GPUTexture *tex, int number)
 	else
 		GPU_invalid_tex_bind(tex->target_base);
 
-	/* TODO: remove this lines once we're using GLSL everywhere */
-	GLenum target = tex->target_base;
-	if (tex->target_base == GL_TEXTURE_1D_ARRAY)
-		target = GL_TEXTURE_2D;
-	if (tex->target_base == GL_TEXTURE_2D_ARRAY)
-		target = GL_TEXTURE_3D;
-	glEnable(target);
-
 	if (number != 0)
 		glActiveTexture(GL_TEXTURE0);
 
@@ -704,14 +696,6 @@ void GPU_texture_unbind(GPUTexture *tex)
 
 	glBindTexture(tex->target_base, 0);
 
-	/* TODO: remove this lines */
-	GLenum target = tex->target_base;
-	if (tex->target_base == GL_TEXTURE_1D_ARRAY)
-		target = GL_TEXTURE_2D;
-	if (tex->target_base == GL_TEXTURE_2D_ARRAY)
-		target = GL_TEXTURE_3D;
-	glDisable(target);
-
 	if (tex->number != 0)
 		glActiveTexture(GL_TEXTURE0);




More information about the Bf-blender-cvs mailing list