OpenGL: remove unnecessarily paranoid bound texture preservation.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 28 Nov 2015 00:45:23 +0000 (01:45 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 28 Nov 2015 14:35:34 +0000 (15:35 +0100)
source/blender/editors/include/BIF_glutil.h
source/blender/editors/screen/glutil.c
source/blender/editors/space_clip/clip_draw.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/gpu/intern/gpu_extensions.c
source/blender/gpu/intern/gpu_material.c

index b904417cfcb1e3b0898cc499c79c51f7285c6da8..05b733d25645dc20e607bef2b92b3f9e327d4bf8 100644 (file)
@@ -89,12 +89,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.
index dd67126a5eca07e90a435762cb041fce8229cfa8..337a959200af58f6a025f84104c4cc35eba1352c 100644 (file)
@@ -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);
        }
 }
 
index d3538f6557a2bc58c43eecc41afeb6f145da165c..848883aacc160d6e5585571684f1a8588b8b40e2 100644 (file)
@@ -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) {
index 889c25e09243d5946b881fe840968c155e047ad7..6c76dbd5149b50ae2eb81f29a3a90c972ec42fe6 100644 (file)
@@ -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);
index cb7b192b0d9404378f24b2b3dabae1fd75094cc5..ddb7aa4cf8fa27146b643ea5a0994f826e122141 100644 (file)
@@ -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;
 
index 85dc968602eaf2829e1c0080385553708bc7b3c4..a28a659efbb7b2d6b45ee69fe7d4b34fc4f4b7df 100644 (file)
@@ -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;