GPU: avoid disabling basic-shader for lasso
authorCampbell Barton <ideasman42@gmail.com>
Wed, 8 Jun 2016 19:02:52 +0000 (05:02 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 8 Jun 2016 19:17:43 +0000 (05:17 +1000)
Replace glDrawPixels w/ glaDrawPixelsTex

source/blender/windowmanager/intern/wm_gesture.c

index db933ad2d761e68b9d72f67946fa7e6efdfc7a14..1357729e898e65ce6bd6374f6841a2b5f12aee85 100644 (file)
@@ -233,19 +233,15 @@ static void wm_gesture_draw_circle(wmGesture *gt)
 }
 
 struct LassoFillData {
-       unsigned int *px;
+       unsigned char *px;
        int width;
 };
 
 static void draw_filled_lasso_px_cb(int x, int x_end, int y, void *user_data)
 {
        struct LassoFillData *data = user_data;
-       unsigned char *col = (unsigned char *)&(data->px[(y * data->width) + x]);
-       do {
-               col[0] = col[1] = col[2] = 0xff;
-               col[3] = 0x10;
-               col += 4;
-       } while (++x != x_end);
+       unsigned char *col = &(data->px[(y * data->width) + x]);
+       memset(col, 0x10, x_end - x);
 }
 
 static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
@@ -273,7 +269,7 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
        if (BLI_rcti_is_empty(&rect) == false) {
                const int w = BLI_rcti_size_x(&rect);
                const int h = BLI_rcti_size_y(&rect);
-               unsigned int *pixel_buf = MEM_callocN(sizeof(*pixel_buf) * w * h, __func__);
+               unsigned char *pixel_buf = MEM_callocN(sizeof(*pixel_buf) * w * h, __func__);
                struct LassoFillData lasso_fill_data = {pixel_buf, w};
 
                fill_poly_v2i_n(
@@ -281,19 +277,27 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
                       (const int (*)[2])moves, tot,
                       draw_filled_lasso_px_cb, &lasso_fill_data);
 
-               int bound_options;
-               GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);
+               glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+               glColor4f(1, 1, 1, 1);
+               glPixelTransferf(GL_RED_BIAS, 1);
+               glPixelTransferf(GL_GREEN_BIAS, 1);
+               glPixelTransferf(GL_BLUE_BIAS, 1);
+
+               GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
 
                glEnable(GL_BLEND);
-               // glColor4f(1.0, 1.0, 1.0, 0.05);
+               glaDrawPixelsTex(rect.xmin, rect.ymin, w, h, GL_ALPHA, GL_UNSIGNED_BYTE, GL_NEAREST, pixel_buf);
+               glDisable(GL_BLEND);
 
-               glRasterPos2f(rect.xmin, rect.ymin);
+               GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 
-               glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixel_buf);
+               glPixelTransferf(GL_RED_BIAS, 0);
+               glPixelTransferf(GL_GREEN_BIAS, 0);
+               glPixelTransferf(GL_BLUE_BIAS, 0);
 
-               GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options);
+               glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
 
-               glDisable(GL_BLEND);
                MEM_freeN(pixel_buf);
        }