Make image drawing code working with core profile
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 11 Apr 2017 14:30:00 +0000 (16:30 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 11 Apr 2017 14:49:39 +0000 (16:49 +0200)
The issue was caused here by usage of deprecated GL_CURRENT_PROGRAM
which was returning rubbish value.

Now we use imm API and create vertex format prior to immBindProgram.
This made us required to have some sort of state passed from setup
function to actual drawing.

15 files changed:
source/blender/editors/include/BIF_glutil.h
source/blender/editors/interface/interface_draw.c
source/blender/editors/interface/interface_icons.c
source/blender/editors/mask/mask_draw.c
source/blender/editors/render/render_internal.c
source/blender/editors/render/render_preview.c
source/blender/editors/screen/glutil.c
source/blender/editors/space_file/file_draw.c
source/blender/editors/space_image/image_draw.c
source/blender/editors/space_node/drawnode.c
source/blender/editors/space_node/node_draw.c
source/blender/editors/space_view3d/view3d_draw_legacy.c
source/blender/windowmanager/intern/wm_dragdrop.c
source/blender/windowmanager/intern/wm_gesture.c
source/blender/windowmanager/intern/wm_playanim.c

index 0d90dab1f1ec6dde8020517d45ce5aee004c4745..1477d20f7f17c9fcf4ba03f96f6e97f0cc2ef068 100644 (file)
@@ -67,10 +67,16 @@ int glaGetOneInt(int param);
  */
 void glaRasterPosSafe2f(float x, float y, float known_good_x, float known_good_y);
 
+typedef struct IMMDrawPixelsTexState {
+       struct GPUShader *shader;
+       unsigned int pos;
+       unsigned int texco;
+} IMMDrawPixelsTexState;
+
 /* To be used before calling immDrawPixelsTex
  * Default shader is GPU_SHADER_2D_IMAGE_COLOR
  * Returns a shader to be able to set uniforms */
-struct GPUShader *immDrawPixelsTexSetup(int builtin);
+IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin);
 
 /**
  * immDrawPixelsTex - Functions like a limited glDrawPixels, but actually draws the
@@ -86,14 +92,18 @@ struct GPUShader *immDrawPixelsTexSetup(int builtin);
  * modelview and projection matrices are assumed to define a
  * 1-to-1 mapping to screen space.
  */
-void immDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
+void immDrawPixelsTex(IMMDrawPixelsTexState *state,
+                      float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
                       float xzoom, float yzoom, float color[4]);
-void immDrawPixelsTex_clipping(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
+void immDrawPixelsTex_clipping(IMMDrawPixelsTexState *state,
+                               float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
                                float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y,
                                float xzoom, float yzoom, float color[4]);
-void immDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY,
-                           float xzoom, float yzoom, float color[4]);
-void immDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY,
+void immDrawPixelsTexScaled(IMMDrawPixelsTexState *state,
+                            float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY,
+                            float xzoom, float yzoom, float color[4]);
+void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state,
+                                     float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY,
                                      float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y,
                                      float xzoom, float yzoom, float color[4]);
 /* 2D Drawing Assistance */
index 5c3dd83e2a1c459e7d3f01b62465754e0503f9cc..fac19d7ed9bdc4467cce95aa767daf014eded786 100644 (file)
@@ -560,8 +560,8 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w
                facy = (float)h / (float)ibuf->y;
        }
 
-       immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-       immDrawPixelsTex((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, ibuf->rect,
+       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+       immDrawPixelsTex(&state, (float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, ibuf->rect,
                         facx, facy, NULL);
        
        glDisable(GL_BLEND);
@@ -1788,8 +1788,8 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
                                UI_draw_roundbox_4fv(true, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f, color);
                        }
 
-                       immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-                       immDrawPixelsTex(rect.xmin, rect.ymin + 1, drawibuf->x, drawibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, drawibuf->rect, 1.0f, 1.0f, NULL);
+                       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+                       immDrawPixelsTex(&state, rect.xmin, rect.ymin + 1, drawibuf->x, drawibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, drawibuf->rect, 1.0f, 1.0f, NULL);
 
                        /* draw cross for pixel position */
                        gpuTranslate2f(rect.xmin + scopes->track_pos[0], rect.ymin + scopes->track_pos[1]);
index 12730943f8830743bb2640654875e2c612a9a8d0..86fe517c9758b653996385a40e81e79e245e77af 100644 (file)
@@ -1005,8 +1005,8 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
        }
 
        /* draw */
-       immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-       immDrawPixelsTex(draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
+       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+       immDrawPixelsTex(&state, draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
                         1.0f, 1.0f, col);
 
        if (ima)
index 09ac1f12aa2c3015161be3be18855a1d456deb84..c4f62fdaf97ef47b229839361950536d2c5061bd 100644 (file)
@@ -769,9 +769,9 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar,
                if (stabmat) {
                        gpuMultMatrix3D(stabmat); /* XXX make this a 2D matrix */
                }
-               GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
-               GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, red);
-               immDrawPixelsTex(0.0f, 0.0f, width, height, GL_RED, GL_FLOAT, GL_NEAREST, buffer, 1.0f, 1.0f, NULL);
+               IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+               GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
+               immDrawPixelsTex(&state, 0.0f, 0.0f, width, height, GL_RED, GL_FLOAT, GL_NEAREST, buffer, 1.0f, 1.0f, NULL);
 
                gpuPopMatrix();
 
index a28e9e4b4a34fc3c93d1ef442d91895538b551a1..e91c01bb0eb31e7ca26c371f5924d1fcf3e059bc 100644 (file)
@@ -1538,8 +1538,8 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C)
                if (force_fallback == false) {
                        if (IMB_colormanagement_setup_glsl_draw(&scene->view_settings, &scene->display_settings, dither, true)) {
                                glEnable(GL_BLEND);
-                               immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-                               immDrawPixelsTex(xof, yof, rres.rectx, rres.recty,
+                               IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+                               immDrawPixelsTex(&state, xof, yof, rres.rectx, rres.recty,
                                                 GL_RGBA, GL_FLOAT, GL_NEAREST, rres.rectf,
                                                 scale_x, scale_y, NULL);;
                                glDisable(GL_BLEND);
@@ -1558,8 +1558,8 @@ void render_view3d_draw(RenderEngine *engine, const bContext *C)
                                                                      4, dither, &scene->view_settings, &scene->display_settings);
 
                        glEnable(GL_BLEND);
-                       immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-                       immDrawPixelsTex(xof, yof, rres.rectx, rres.recty,
+                       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+                       immDrawPixelsTex(&state, xof, yof, rres.rectx, rres.recty,
                                         GL_RGBA, GL_UNSIGNED_BYTE,
                                         GL_NEAREST, display_buffer,
                                         scale_x, scale_y, NULL);
index 3fb09123131a5def1cb450a2b2c426aeba4b8de4..9a8e5631b7f3ff298d13280a98e4af5733496e0b 100644 (file)
@@ -600,8 +600,8 @@ static bool ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect,
                                if (re)
                                        RE_AcquiredResultGet32(re, &rres, (unsigned int *)rect_byte, 0);
 
-                               immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-                               immDrawPixelsTex(fx, fy, rres.rectx, rres.recty, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect_byte,
+                               IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+                               immDrawPixelsTex(&state, fx, fy, rres.rectx, rres.recty, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect_byte,
                                                 1.0f, 1.0f, NULL);
                                
                                MEM_freeN(rect_byte);
index 7387d9481d5c308bd0aab3b484f389dd7d255d98..233ecf8c83df7e42b43b300c74a0dadfca5e4a4d 100644 (file)
@@ -137,19 +137,33 @@ static int get_cached_work_texture(int *r_w, int *r_h)
        return texid;
 }
 
+static void immDrawPixelsTexSetupAttributes(IMMDrawPixelsTexState *state)
+{
+       VertexFormat *vert_format = immVertexFormat();
+       unsigned int pos = VertexFormat_add_attrib(vert_format, "pos", COMP_F32, 2, KEEP_FLOAT);
+       unsigned int texco = VertexFormat_add_attrib(vert_format, "texCoord", COMP_F32, 2, KEEP_FLOAT);
+       state->pos = pos;
+       state->texco = texco;
+}
+
 /* To be used before calling immDrawPixelsTex
  * Default shader is GPU_SHADER_2D_IMAGE_COLOR
  * You can still set uniforms with :
  * GPU_shader_uniform_int(shader, GPU_shader_get_uniform(shader, "name"), 0);
  * */
-GPUShader *immDrawPixelsTexSetup(int builtin)
+IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin)
 {
+       IMMDrawPixelsTexState state;
+       immDrawPixelsTexSetupAttributes(&state);
+
        GPUShader *shader = GPU_shader_get_builtin_shader(builtin);
        /* Shader will be unbind by immUnbindProgram in immDrawPixelsTexScaled_clipping */
-       GPU_shader_bind(shader);
+       immBindBuiltinProgram(builtin);
        GPU_shader_uniform_int(shader, GPU_shader_get_uniform(shader, "image"), 0);
 
-       return shader;
+       state.shader = shader;
+
+       return state;
 }
 
 /* Use the currently bound shader.
@@ -165,7 +179,8 @@ GPUShader *immDrawPixelsTexSetup(int builtin)
  * Be also aware that this function unbinds the shader when
  * it's finished.
  * */
-void immDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
+void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state,
+                                     float x, float y, int img_w, int img_h,
                                      int format, int type, int zoomfilter, void *rect,
                                      float scaleX, float scaleY,
                                      float clip_min_x, float clip_min_y,
@@ -229,25 +244,15 @@ void immDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0, format, GL_UNSIGNED_BYTE, NULL);
        }
 
-       VertexFormat *vert_format = immVertexFormat();
-       unsigned int pos = VertexFormat_add_attrib(vert_format, "pos", COMP_F32, 2, KEEP_FLOAT);
-       unsigned int texco = VertexFormat_add_attrib(vert_format, "texCoord", COMP_F32, 2, KEEP_FLOAT);
-
-       unsigned int program = glaGetOneInt(GL_CURRENT_PROGRAM);
-
-       /* This is needed for the OCIO case.
-        * Shader program is set outside of blender and
-        * we need it in imm module to do all attrib /
-        * uniform bindings. */
+       unsigned int pos = 0, texco = 1;
 
-       /* A program is already bound.
-        * set it in imm.bound_program to be able to use imm functions */
-       BLI_assert(program);
-       immBindProgram(program);
-
-       /* optionnal */
-       if (glGetUniformLocation(program, "color") != -1)
+       /* optional */
+       /* NOTE: Shader could be null for GLSL OCIO drawing, it is fine, since
+        * it does not need color.
+        */
+       if (state->shader != NULL && GPU_shader_get_uniform(state->shader, "color") != -1) {
                immUniform4fv("color", (color) ? color : white);
+       }
 
        for (subpart_y = 0; subpart_y < nsubparts_y; subpart_y++) {
                for (subpart_x = 0; subpart_x < nsubparts_x; subpart_x++) {
@@ -322,27 +327,30 @@ void immDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
        glPixelStorei(GL_UNPACK_ROW_LENGTH, unpack_row_length);
 }
 
-void immDrawPixelsTexScaled(float x, float y, int img_w, int img_h,
+void immDrawPixelsTexScaled(IMMDrawPixelsTexState *state,
+                            float x, float y, int img_w, int img_h,
                             int format, int type, int zoomfilter, void *rect,
                             float scaleX, float scaleY, float xzoom, float yzoom, float color[4])
 {
-       immDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect,
+       immDrawPixelsTexScaled_clipping(state, x, y, img_w, img_h, format, type, zoomfilter, rect,
                                        scaleX, scaleY, 0.0f, 0.0f, 0.0f, 0.0f, xzoom, yzoom, color);
 }
 
-void immDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
+void immDrawPixelsTex(IMMDrawPixelsTexState *state,
+                      float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
                       float xzoom, float yzoom, float color[4])
 {
-       immDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f,
+       immDrawPixelsTexScaled_clipping(state, x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f,
                                        0.0f, 0.0f, 0.0f, 0.0f, xzoom, yzoom, color);
 }
 
-void immDrawPixelsTex_clipping(float x, float y, int img_w, int img_h,
+void immDrawPixelsTex_clipping(IMMDrawPixelsTexState *state,
+                               float x, float y, int img_w, int img_h,
                                int format, int type, int zoomfilter, void *rect,
                                float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y,
                                float xzoom, float yzoom, float color[4])
 {
-       immDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f,
+       immDrawPixelsTexScaled_clipping(state, x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f,
                                        clip_min_x, clip_min_y, clip_max_x, clip_max_y, xzoom, yzoom, color);
 }
 
@@ -575,6 +583,9 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
        if (force_fallback == false) {
                int ok;
 
+               IMMDrawPixelsTexState state = {0};
+               immDrawPixelsTexSetupAttributes(&state);
+
                if (ibuf->rect_float) {
                        if (ibuf->float_colorspace) {
                                ok = IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings,
@@ -604,7 +615,8 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
                                        BLI_assert(!"Incompatible number of channels for GLSL display");
 
                                if (format != 0) {
-                                       immDrawPixelsTex_clipping(x, y, ibuf->x, ibuf->y, format, GL_FLOAT,
+                                       immDrawPixelsTex_clipping(&state,
+                                                                 x, y, ibuf->x, ibuf->y, format, GL_FLOAT,
                                                                  zoomfilter, ibuf->rect_float,
                                                                  clip_min_x, clip_min_y, clip_max_x, clip_max_y,
                                                                  zoom_x, zoom_y, NULL);
@@ -612,7 +624,8 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
                        }
                        else if (ibuf->rect) {
                                /* ibuf->rect is always RGBA */
-                               immDrawPixelsTex_clipping(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
+                               immDrawPixelsTex_clipping(&state,
+                                                         x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
                                                          zoomfilter, ibuf->rect,
                                                          clip_min_x, clip_min_y, clip_max_x, clip_max_y,
                                                          zoom_x, zoom_y, NULL);
@@ -632,8 +645,9 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
                display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle);
 
                if (display_buffer) {
-                       immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-                       immDrawPixelsTex_clipping(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
+                       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+                       immDrawPixelsTex_clipping(&state,
+                                                 x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
                                                  zoomfilter, display_buffer,
                                                  clip_min_x, clip_min_y, clip_max_x, clip_max_y,
                                                  zoom_x, zoom_y, NULL);
index bf47657f27dc3c871458f1a775fb9827a8184301..329b3f7f5256680c726663d6811f1db5b29f7c46 100644 (file)
@@ -389,8 +389,8 @@ static void file_draw_preview(
                UI_GetThemeColor4fv(TH_TEXT, col);
        }
 
-       immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-       immDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, imb->rect,
+       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+       immDrawPixelsTexScaled(&state, (float)xco, (float)yco, imb->x, imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, imb->rect,
                               scale, scale, 1.0f, 1.0f, col);
 
        if (icon) {
index 554ec573a9c018b61affc4dbc3ea9ee17cf87282..f66234ab22cbd84061d2c027d7d44884ec93dc94 100644 (file)
@@ -432,10 +432,10 @@ static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int
                recti[a] = rect[a] * 0.5f + 0.5f;
        }
 
-       GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
-       GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, red);
+       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+       GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
 
-       immDrawPixelsTex(x1, y1, rectx, recty, GL_RED, GL_INT, GL_NEAREST, recti, zoomx, zoomy, NULL);
+       immDrawPixelsTex(&state, x1, y1, rectx, recty, GL_RED, GL_INT, GL_NEAREST, recti, zoomx, zoomy, NULL);
 
        MEM_freeN(recti);
 }
@@ -470,10 +470,10 @@ static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rec
                }
        }
 
-       GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
-       GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, red);
+       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+       GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
 
-       immDrawPixelsTex(x1, y1, rectx, recty, GL_RED, GL_FLOAT, GL_NEAREST, rectf, zoomx, zoomy, NULL);
+       immDrawPixelsTex(&state, x1, y1, rectx, recty, GL_RED, GL_FLOAT, GL_NEAREST, rectf, zoomx, zoomy, NULL);
 
        MEM_freeN(rectf);
 }
@@ -531,14 +531,14 @@ static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar,
                        else if (sima->flag & SI_SHOW_ALPHA)
                                shuffle[3] = 1.0f;
 
-                       GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
-                       GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, shuffle);
+                       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+                       GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, shuffle);
 
                        IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings);
                        display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle);
 
                        if (display_buffer) {
-                               immDrawPixelsTex_clipping(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer,
+                               immDrawPixelsTex_clipping(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer,
                                                          0, 0, clip_max_x, clip_max_y, zoomx, zoomy, NULL);
                        }
 
@@ -619,14 +619,14 @@ static void draw_image_buffer_tiled(SpaceImage *sima, ARegion *ar, Scene *scene,
                        UI_view2d_view_to_region(&ar->v2d, fx + (float)sx / (float)ibuf->x, fy + (float)sy / (float)ibuf->y, &x, &y);
 
                        if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B | SI_SHOW_ALPHA)) == 0) {
-                               immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-                               immDrawPixelsTex(x, y, dx, dy, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect, zoomx, zoomy, NULL);
+                               IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+                               immDrawPixelsTex(&state, x, y, dx, dy, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect, zoomx, zoomy, NULL);
                        }
                        else {
-                               GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
-                               GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, shuffle);
+                               IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+                               GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, shuffle);
 
-                               immDrawPixelsTex(x, y, dx, dy, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect, zoomx, zoomy, NULL);
+                               immDrawPixelsTex(&state, x, y, dx, dy, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect, zoomx, zoomy, NULL);
                        }
                }
        }
@@ -734,8 +734,8 @@ static void draw_image_paint_helpers(const bContext *C, ARegion *ar, Scene *scen
                        glEnable(GL_BLEND);
                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
-                       immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-                       immDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer, zoomx, zoomy, col);
+                       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+                       immDrawPixelsTex(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer, zoomx, zoomy, col);
 
                        glDisable(GL_BLEND);
 
index 6620dec41307130da0381ff83c48dfb7f56ac880..54f620140bfebc841e5ca11807e963cb4a0b655e 100644 (file)
@@ -3204,10 +3204,10 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
                                else
                                        shuffle[3] = 1.0f;
 
-                               GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
-                               GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, shuffle);
+                               IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+                               GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, shuffle);
 
-                               immDrawPixelsTex(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
+                               immDrawPixelsTex(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
                                                 display_buffer, snode->zoom, snode->zoom, NULL);
 
                                GPU_shader_unbind();
index 3e0adb3243f50750a4c38fa4c435a4becd407712..cb5f434849ef93dc1cc7443103952f56e64ef904 100644 (file)
@@ -706,8 +706,8 @@ static void node_draw_preview(bNodePreview *preview, rctf *prv)
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);  /* premul graphics */
        
-       immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-       immDrawPixelsTex(draw_rect.xmin, draw_rect.ymin, preview->xsize, preview->ysize, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, preview->rect,
+       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+       immDrawPixelsTex(&state, draw_rect.xmin, draw_rect.ymin, preview->xsize, preview->ysize, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, preview->rect,
                         scale, scale, NULL);
        
        glDisable(GL_BLEND);
index 7cd926d180c3a6d7c9211be42e906c83e969cfa6..db6657de18b4746b3889bb4cdfdef22bab9d30d4 100644 (file)
@@ -773,8 +773,8 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                        }
 
                        float col[4] = {1.0f, 1.0f, 1.0f, 1.0f - bgpic->blend};
-                       immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-                       immDrawPixelsTex(x1 - centx, y1 - centy, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect,
+                       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+                       immDrawPixelsTex(&state, x1 - centx, y1 - centy, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect,
                                         zoomx, zoomy, col);
 
                        glMatrixMode(GL_PROJECTION);
index 0402a528e8d0fe08914fb07cb4c2547ebd1259fd..40a2bf42a28cc180ecc46d4b8e72995ed7b76909 100644 (file)
@@ -335,8 +335,8 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
                                drag_rect_minmax(rect, x, y, x + drag->sx, y + drag->sy);
                        else {
                                float col[4] = {1.0f, 1.0f, 1.0f, 0.65f}; /* this blends texture */
-                               immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
-                               immDrawPixelsTexScaled(x, y, drag->imb->x, drag->imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
+                               IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+                               immDrawPixelsTexScaled(&state, x, y, drag->imb->x, drag->imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
                                                       drag->imb->rect, drag->scale, drag->scale, 1.0f, 1.0f, col);
                        }
                }
index 460b4ac3b6da290ba09c07a7881ab0e4a330e7e0..277a219ca5cfd2e359fb7b0c33619d37601c1fca 100644 (file)
@@ -367,11 +367,11 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
 
                glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
-               GPUShader *shader = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
-               GPU_shader_bind(shader);
-               GPU_shader_uniform_vector(shader, GPU_shader_get_uniform(shader, "shuffle"), 4, 1, red);
+               IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+               GPU_shader_bind(state.shader);
+               GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
 
-               immDrawPixelsTex(rect.xmin, rect.ymin, w, h, GL_RED, GL_UNSIGNED_BYTE, GL_NEAREST, pixel_buf, 1.0f, 1.0f, NULL);
+               immDrawPixelsTex(&state, rect.xmin, rect.ymin, w, h, GL_RED, GL_UNSIGNED_BYTE, GL_NEAREST, pixel_buf, 1.0f, 1.0f, NULL);
 
                GPU_shader_unbind();
 
index 570bbbf90decf2638eef1dc05d1e535c308fb53c..efddfb3312bdcf4c276e3a52f8a916bc135fd74b 100644 (file)
@@ -322,9 +322,10 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
                imm_draw_checker_box(offs_x, offs_y, offs_x + span_x, offs_y + span_y);
        }
 
-       immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+       IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
 
        immDrawPixelsTex(
+               &state,
                offs_x + (ps->draw_flip[0] ? span_x : 0.0f),
                offs_y + (ps->draw_flip[1] ? span_y : 0.0f),
                ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,