Fix for "draw images as texture"
authorTon Roosendaal <ton@blender.org>
Sun, 17 Mar 2013 17:32:45 +0000 (17:32 +0000)
committerTon Roosendaal <ton@blender.org>
Sun, 17 Mar 2013 17:32:45 +0000 (17:32 +0000)
Zooming in on images in Image window now shows pixels again (was filtered).

Now the glaDrawPixelsTex() and glaDrawPixelsAuto() have an argument to
define if images should zoom in with linear filter, or draw pixels.

source/blender/editors/include/BIF_glutil.h
source/blender/editors/interface/interface_draw.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/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/windowmanager/intern/wm_dragdrop.c

index 40d73c39b8c08833ce00947861582677346a63b2..39d1e283f542bdbfd9817b96a5aac3c92111807b 100644 (file)
@@ -141,17 +141,17 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo
  * 1-to-1 mapping to screen space.
  */
 
-void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void *rect);
+void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int zoomfilter, void *rect);
 
 /**
  * glaDrawPixelsAuto - Switches between texture or pixel drawing using UserDef.
  * only RGBA
  * needs glaDefine2DArea to be set.
  */
-void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, void *rect);
+void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int zoomfilter, void *rect);
 
 
-void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, void *rect, float scaleX, float scaleY);
+void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int zoomfilter, void *rect, float scaleX, float scaleY);
 
 /* 2D Drawing Assistance */
 
index be57357b6e51ac61be2f67b97c68c090913c2d40..5486e12c6bfcd3f9440b90007446ecfeb761d069 100644 (file)
@@ -453,8 +453,7 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w
                float facy = (float)h / (float)ibuf->y;
                glPixelZoom(facx, facy);
        }
-       glaDrawPixelsSafe((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
-       //glaDrawPixelsTex((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
+       glaDrawPixelsAuto((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, GL_NEAREST, ibuf->rect);
        
        glPixelZoom(1.0f, 1.0f);
        
index 6e7972200c773c9e61eb4bf97a5258ab90136cba..8501b53afaed0279c65446278302891dcfa92aa2 100644 (file)
@@ -482,7 +482,7 @@ static int get_cached_work_texture(int *w_r, int *h_r)
        return texid;
 }
 
-void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, void *rect, float scaleX, float scaleY)
+void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int zoomfilter, void *rect, float scaleX, float scaleY)
 {
        unsigned char *uc_rect = (unsigned char *) rect;
        float *f_rect = (float *)rect;
@@ -503,6 +503,7 @@ void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format,
        /* don't want nasty border artifacts */
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, zoomfilter);
 
 #ifdef __APPLE__
        /* workaround for os x 10.5/10.6 driver bug: http://lists.apple.com/archives/Mac-opengl/2008/Jul/msg00117.html */
@@ -585,9 +586,9 @@ void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format,
 #endif
 }
 
-void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void *rect)
+void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int zoomfilter, void *rect)
 {
-       glaDrawPixelsTexScaled(x, y, img_w, img_h, format, rect, 1.0f, 1.0f);
+       glaDrawPixelsTexScaled(x, y, img_w, img_h, format, zoomfilter, rect, 1.0f, 1.0f);
 }
 
 void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int format, int type, void *rect)
@@ -670,7 +671,7 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo
 }
 
 /* uses either DrawPixelsSafe or DrawPixelsTex, based on user defined maximum */
-void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, void *rect)
+void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int zoomfilter, void *rect)
 {
        if (U.image_gpubuffer_limit) {
                /* Megapixels, use float math to prevent overflow */
@@ -678,7 +679,7 @@ void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, void
                
                if (U.image_gpubuffer_limit > (int)img_size) {
                        glColor4f(1.0, 1.0, 1.0, 1.0);
-                       glaDrawPixelsTex(x, y, img_w, img_h, format, rect);
+                       glaDrawPixelsTex(x, y, img_w, img_h, format, zoomfilter, rect);
                        return;
                }
        }
index 269ec74c55586e0b0374804c91fe0945d542cbab..5b6b8656072fe627943a2c3b938a86d4b86ae4a7 100644 (file)
@@ -376,7 +376,7 @@ static void file_draw_preview(uiBlock *block, struct direntry *file, int sx, int
                
                /* the image */
                glColor4f(1.0, 1.0, 1.0, 1.0);
-               glaDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_UNSIGNED_BYTE, imb->rect, scale, scale);
+               glaDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_UNSIGNED_BYTE, GL_NEAREST, imb->rect, scale, scale);
                
                /* border */
                if (dropshadow) {
index 5ae6ac8a54bdc810279b0ab57c40c5f9237f3d34..e69ce56c9d9474e34c1ddd7ce228398c4c28ff81 100644 (file)
@@ -525,7 +525,7 @@ static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar,
                display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
 
                if (display_buffer)
-                       glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, display_buffer);
+                       glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer);
 
                IMB_display_buffer_release(cache_handle);
 
index 3b4d1f1ae2609c4dafc265f891f908a117f30266..4a14d6ba6fd0f872e8acf4b9f7d6fdf48509d831 100644 (file)
@@ -3301,7 +3301,7 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode)
                                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                                        glPixelZoom(snode->zoom, snode->zoom);
                                        
-                                       glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, display_buffer);
+                                       glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, GL_LINEAR, display_buffer);
                                        
                                        glPixelZoom(1.0f, 1.0f);
                                        glDisable(GL_BLEND);
@@ -3309,7 +3309,7 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode)
                                else {
                                        glPixelZoom(snode->zoom, snode->zoom);
 
-                                       glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, display_buffer);
+                                       glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, GL_LINEAR, display_buffer);
                                        
                                        glPixelZoom(1.0f, 1.0f);
                                }
index 34f7799d47cc22f7a43927d350f032a4e7f40dd6..d6a3a6a6a3f46dddef72d5ff94a8ba4234495e62 100644 (file)
@@ -629,7 +629,7 @@ static void node_draw_preview(bNodePreview *preview, rctf *prv)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);  /* premul graphics */
        
        glColor4f(1.0, 1.0, 1.0, 1.0);
-       glaDrawPixelsTex(prv->xmin, prv->ymin, preview->xsize, preview->ysize, GL_UNSIGNED_BYTE, preview->rect);
+       glaDrawPixelsTex(prv->xmin, prv->ymin, preview->xsize, preview->ysize, GL_UNSIGNED_BYTE, GL_LINEAR, preview->rect);
        
        glDisable(GL_BLEND);
        glPixelZoom(1.0f, 1.0f);
index da3ebf586e91dd5ef750984f38b792d9ad91ec69..1f41e7e0d34a3fd6cbf27bc12b5412f18c84ff2e 100644 (file)
@@ -611,7 +611,7 @@ static void draw_empty_image(Object *ob, const short dflag, const unsigned char
                glColor4fv(ob->col);
 
                /* Draw the Image on the screen */
-               glaDrawPixelsTex(ofs_x, ofs_y, ima_x, ima_y, GL_UNSIGNED_BYTE, ibuf->rect);
+               glaDrawPixelsTex(ofs_x, ofs_y, ima_x, ima_y, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect);
                glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
 
                glDisable(GL_BLEND);
index 9173c11940d52a721abf02e0e0b15335d2e22a59..8fdc9416513428a36eec8a2b70e2167cae27eb40 100644 (file)
@@ -1819,7 +1819,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
 
                        glPixelZoom(zoomx, zoomy);
                        glColor4f(1.0f, 1.0f, 1.0f, 1.0f - bgpic->blend);
-                       glaDrawPixelsAuto(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
+                       glaDrawPixelsAuto(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect);
 
                        glPixelZoom(1.0, 1.0);
                        glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
index 00ccfedafa8a43637662990da7fd7ea9e4a19731..ed066117b28d6cc06bcb2cad17663b224f43351b 100644 (file)
@@ -323,7 +323,7 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
                                drag_rect_minmax(rect, x, y, x + drag->sx, y + drag->sy);
                        else {
                                glColor4f(1.0, 1.0, 1.0, 0.65); /* this blends texture */
-                               glaDrawPixelsTexScaled(x, y, drag->imb->x, drag->imb->y, GL_UNSIGNED_BYTE, drag->imb->rect, drag->scale, drag->scale);
+                               glaDrawPixelsTexScaled(x, y, drag->imb->x, drag->imb->y, GL_UNSIGNED_BYTE, GL_NEAREST, drag->imb->rect, drag->scale, drag->scale);
                        }
                }
                else {