[Bf-blender-cvs] [c76fbf1] master: OpenGL: remove unnecessarily paranoid bound texture preservation.

Brecht Van Lommel noreply at git.blender.org
Sat Nov 28 15:36:39 CET 2015


Commit: c76fbf10e2f6dc766763a760e5bb34f64274a253
Author: Brecht Van Lommel
Date:   Sat Nov 28 01:45:23 2015 +0100
Branches: master
https://developer.blender.org/rBc76fbf10e2f6dc766763a760e5bb34f64274a253

OpenGL: remove unnecessarily paranoid bound texture preservation.

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

M	source/blender/editors/include/BIF_glutil.h
M	source/blender/editors/screen/glutil.c
M	source/blender/editors/space_clip/clip_draw.c
M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/gpu/intern/gpu_extensions.c
M	source/blender/gpu/intern/gpu_material.c

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

diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h
index b904417..05b733d 100644
--- a/source/blender/editors/include/BIF_glutil.h
+++ b/source/blender/editors/include/BIF_glutil.h
@@ -90,12 +90,6 @@ void glutil_draw_lined_arc(float start, float angle, float radius, int nsegments
 void glutil_draw_filled_arc(float start, float angle, float radius, int nsegments);
 
 /**
- * Returns an integer value as obtained by glGetIntegerv.
- * The param must cause only one value to be gotten from GL.
- */
-int glaGetOneInteger(int param);
-
-/**
  * Returns a float value as obtained by glGetFloatv.
  * The param must cause only one value to be gotten from GL.
  */
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c
index dd67126..337a959 100644
--- a/source/blender/editors/screen/glutil.c
+++ b/source/blender/editors/screen/glutil.c
@@ -436,13 +436,6 @@ void glutil_draw_lined_arc(float start, float angle, float radius, int nsegments
 	glEnd();
 }
 
-int glaGetOneInteger(int param)
-{
-	GLint i;
-	glGetIntegerv(param, &i);
-	return i;
-}
-
 float glaGetOneFloat(int param)
 {
 	GLfloat v;
@@ -474,7 +467,6 @@ static int get_cached_work_texture(int *r_w, int *r_h)
 	static int tex_h = 256;
 
 	if (texid == -1) {
-		GLint ltexid = glaGetOneInteger(GL_TEXTURE_2D);
 		unsigned char *tbuf;
 
 		glGenTextures(1, (GLuint *)&texid);
@@ -488,7 +480,7 @@ static int get_cached_work_texture(int *r_w, int *r_h)
 		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tbuf);
 		MEM_freeN(tbuf);
 
-		glBindTexture(GL_TEXTURE_2D, ltexid);
+		glBindTexture(GL_TEXTURE_2D, 0);
 	}
 
 	*r_w = tex_w;
@@ -501,8 +493,6 @@ void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format,
 	unsigned char *uc_rect = (unsigned char *) rect;
 	const float *f_rect = (float *)rect;
 	float xzoom = glaGetOneFloat(GL_ZOOM_X), yzoom = glaGetOneFloat(GL_ZOOM_Y);
-	int ltexid = glaGetOneInteger(GL_TEXTURE_2D);
-	int lrowlength = glaGetOneInteger(GL_UNPACK_ROW_LENGTH);
 	int subpart_x, subpart_y, tex_w, tex_h;
 	int seamless, offset_x, offset_y, nsubparts_x, nsubparts_y;
 	int texid = get_cached_work_texture(&tex_w, &tex_h);
@@ -617,8 +607,8 @@ void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format,
 		}
 	}
 
-	glBindTexture(GL_TEXTURE_2D, ltexid);
-	glPixelStorei(GL_UNPACK_ROW_LENGTH, lrowlength);
+	glBindTexture(GL_TEXTURE_2D, 0);
+	glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
 	
 #ifdef __APPLE__
 	/* workaround for os x 10.5/10.6 driver bug (above) */
@@ -674,8 +664,6 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo
 	draw_h = min_ii(img_h - off_y, ceil((scissor[3] - rast_y) / yzoom));
 
 	if (draw_w > 0 && draw_h > 0) {
-		int old_row_length = glaGetOneInteger(GL_UNPACK_ROW_LENGTH);
-
 		/* Don't use safe RasterPos (slower) if we can avoid it. */
 		if (rast_x >= 0 && rast_y >= 0) {
 			glRasterPos2f(rast_x, rast_y);
@@ -706,7 +694,7 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo
 			}
 		}
 		
-		glPixelStorei(GL_UNPACK_ROW_LENGTH,  old_row_length);
+		glPixelStorei(GL_UNPACK_ROW_LENGTH,  0);
 	}
 }
 
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c
index d3538f6..848883a 100644
--- a/source/blender/editors/space_clip/clip_draw.c
+++ b/source/blender/editors/space_clip/clip_draw.c
@@ -1063,7 +1063,7 @@ static void draw_plane_marker_image(Scene *scene,
 		}
 
 		if (display_buffer) {
-			GLuint texid, last_texid;
+			GLuint texid;
 			float frame_corners[4][2] = {{0.0f, 0.0f},
 			                             {1.0f, 0.0f},
 			                             {1.0f, 1.0f},
@@ -1085,7 +1085,6 @@ static void draw_plane_marker_image(Scene *scene,
 
 			glColor4f(1.0, 1.0, 1.0, plane_track->image_opacity);
 
-			last_texid = glaGetOneInteger(GL_TEXTURE_2D);
 			glEnable(GL_TEXTURE_2D);
 			glGenTextures(1, (GLuint *)&texid);
 
@@ -1109,7 +1108,7 @@ static void draw_plane_marker_image(Scene *scene,
 
 			glPopMatrix();
 
-			glBindTexture(GL_TEXTURE_2D, last_texid);
+			glBindTexture(GL_TEXTURE_2D, 0);
 			glDisable(GL_TEXTURE_2D);
 
 			if (transparent) {
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index 889c25e..6c76dbd 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -1093,7 +1093,6 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
 	float viewrect[2];
 	float col[3];
 	GLuint texid;
-	GLuint last_texid;
 	void *display_buffer;
 	void *cache_handle = NULL;
 	const bool is_imbuf = ED_space_sequencer_check_show_imbuf(sseq);
@@ -1291,7 +1290,6 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
 
 	glColor4f(1.0, 1.0, 1.0, 1.0);
 
-	last_texid = glaGetOneInteger(GL_TEXTURE_2D);
 	glEnable(GL_TEXTURE_2D);
 	glGenTextures(1, (GLuint *)&texid);
 
@@ -1366,7 +1364,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
 	}
 	glEnd();
 
-	glBindTexture(GL_TEXTURE_2D, last_texid);
+	glBindTexture(GL_TEXTURE_2D, 0);
 	glDisable(GL_TEXTURE_2D);
 	if (sseq->mainb == SEQ_DRAW_IMG_IMBUF && sseq->flag & SEQ_USE_ALPHA)
 		glDisable(GL_BLEND);
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index cb7b192..ddb7aa4 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -701,17 +701,15 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const f
 GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data, double time, int mipmap)
 {
 	GPUTexture *tex;
-	GLint w, h, border, lastbindcode, bindcode;
-
-	glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
+	GLint w, h, border, bindcode;
 
 	GPU_update_image_time(ima, time);
-	/* this binds a texture, so that's why to restore it with lastbindcode */
+	/* this binds a texture, so that's why to restore it to 0 */
 	bindcode = GPU_verify_image(ima, iuser, 0, 0, mipmap, is_data);
 
 	if (ima->gputexture) {
 		ima->gputexture->bindcode = bindcode;
-		glBindTexture(GL_TEXTURE_2D, lastbindcode);
+		glBindTexture(GL_TEXTURE_2D, 0);
 		return ima->gputexture;
 	}
 
@@ -738,7 +736,7 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data,
 		tex->h = tex->h_orig = h - border;
 	}
 
-	glBindTexture(GL_TEXTURE_2D, lastbindcode);
+	glBindTexture(GL_TEXTURE_2D, 0);
 
 	return tex;
 }
@@ -746,21 +744,19 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, bool is_data,
 GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap)
 {
 	GPUTexture *tex = prv->gputexture[0];
-	GLint w, h, lastbindcode;
+	GLint w, h;
 	GLuint bindcode = 0;
 	
-	glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
-	
 	if (tex)
 		bindcode = tex->bindcode;
 	
-	/* this binds a texture, so that's why to restore it */
+	/* this binds a texture, so that's why we restore it to 0 */
 	if (bindcode == 0) {
 		GPU_create_gl_tex(&bindcode, prv->rect[0], NULL, prv->w[0], prv->h[0], mipmap, 0, NULL);
 	}
 	if (tex) {
 		tex->bindcode = bindcode;
-		glBindTexture(GL_TEXTURE_2D, lastbindcode);
+		glBindTexture(GL_TEXTURE_2D, 0);
 		return tex;
 	}
 
@@ -785,7 +781,7 @@ GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap)
 		tex->h = tex->h_orig = h;
 	}
 	
-	glBindTexture(GL_TEXTURE_2D, lastbindcode);
+	glBindTexture(GL_TEXTURE_2D, 0);
 	
 	return tex;
 
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index 85dc968..a28a659 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -2275,7 +2275,6 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
 	GPUMaterial *mat;
 	GPUInputUniform *uniform;
 	GPUInputAttribute *attribute;
-	GLint lastbindcode;
 	int i, liblen, fraglen;
 
 	/* TODO(sergey): How to detemine whether we need OSD or not here? */
@@ -2310,12 +2309,11 @@ GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
 				case GPU_TEX2D:
 					if (GPU_texture_opengl_bindcode(input->tex)) {
 						uniform->type = GPU_DYNAMIC_SAMPLER_2DBUFFER;
-						glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode);
 						glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(input->tex));
 						uniform->texsize = GPU_texture_opengl_width(input->tex) * GPU_texture_opengl_height(input->tex);
 						uniform->texpixels = MEM_mallocN(uniform->texsize*4, "RGBApixels");
 						glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, uniform->texpixels); 
-						glBindTexture(GL_TEXTURE_2D, lastbindcode);
+						glBindTexture(GL_TEXTURE_2D, 0);
 					}
 					break;




More information about the Bf-blender-cvs mailing list