WM Draw Methods now has a new option Automatic (default). This will
[blender-staging.git] / source / blender / editors / screen / glutil.c
index 74e0bc3852eb4b8854c81829daaaa6cd3f82ba1f..1ea0c2ccdbdc592df0726eab74fa58d1442c4c8f 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * $Id: glutil.c 11920 2007-09-02 17:25:03Z elubie $
+ * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -35,8 +35,9 @@
 #include "DNA_listBase.h"
 
 #include "BKE_utildefines.h"
+#include "BKE_colortools.h"
 
-#include "BLI_arithb.h"
+#include "BLI_math.h"
 #include "BLI_threads.h"
 
 #include "BIF_gl.h"
@@ -419,7 +420,7 @@ static int get_cached_work_texture(int *w_r, int *h_r)
        return texid;
 }
 
-void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void *rect)
+void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, void *rect, float scaleX, float scaleY)
 {
        unsigned char *uc_rect= (unsigned char*) rect;
        float *f_rect= (float *)rect;
@@ -438,10 +439,15 @@ void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void *
        glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
        glBindTexture(GL_TEXTURE_2D, texid);
 
-        /* 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);
+       /* 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);
 
+#ifdef __APPLE__
+       /* workaround for os x 10.5/10.6 driver bug: http://lists.apple.com/archives/Mac-opengl/2008/Jul/msg00117.html */
+       glPixelZoom(1.f, 1.f);
+#endif
+       
        for (subpart_y=0; subpart_y<nsubparts_y; subpart_y++) {
                for (subpart_x=0; subpart_x<nsubparts_x; subpart_x++) {
                        int subpart_w= (subpart_x==nsubparts_x-1)?(img_w-subpart_x*tex_w):tex_w;
@@ -460,13 +466,13 @@ void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void *
                        glVertex2f(rast_x, rast_y);
 
                        glTexCoord2f((float) (subpart_w-1)/tex_w, 0);
-                       glVertex2f(rast_x+subpart_w*xzoom, rast_y);
+                       glVertex2f(rast_x+subpart_w*xzoom*scaleX, rast_y);
 
                        glTexCoord2f((float) (subpart_w-1)/tex_w, (float) (subpart_h-1)/tex_h);
-                       glVertex2f(rast_x+subpart_w*xzoom, rast_y+subpart_h*yzoom);
+                       glVertex2f(rast_x+subpart_w*xzoom*scaleX, rast_y+subpart_h*yzoom*scaleY);
 
                        glTexCoord2f(0, (float) (subpart_h-1)/tex_h);
-                       glVertex2f(rast_x, rast_y+subpart_h*yzoom);
+                       glVertex2f(rast_x, rast_y+subpart_h*yzoom*scaleY);
                        glEnd();
                        glDisable(GL_TEXTURE_2D);
                }
@@ -475,29 +481,32 @@ void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void *
        glBindTexture(GL_TEXTURE_2D, ltexid);
        glPixelStorei(GL_UNPACK_ROW_LENGTH, lrowlength);
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+       
+#ifdef __APPLE__
+       /* workaround for os x 10.5/10.6 driver bug (above) */
+       glPixelZoom(xzoom, yzoom);
+#endif
+}
+
+void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void *rect)
+{
+       glaDrawPixelsTexScaled(x, y, img_w, img_h, format, rect, 1.0f, 1.0f);
 }
 
-void glaDrawPixelsSafe_to32(float fx, float fy, int img_w, int img_h, int row_w, float *rectf)
+void glaDrawPixelsSafe_to32(float fx, float fy, int img_w, int img_h, int row_w, float *rectf, int gamma_correct)
 {
-       float *rf;
-       int x, y;
-       char *rect32, *rc;
+       unsigned char *rect32;
        
        /* copy imgw-imgh to a temporal 32 bits rect */
        if(img_w<1 || img_h<1) return;
        
-       rc= rect32= MEM_mallocN(img_w*img_h*sizeof(int), "temp 32 bits");
+       rect32= MEM_mallocN(img_w*img_h*sizeof(int), "temp 32 bits");
        
-       for(y=0; y<img_h; y++) {
-               rf= rectf;
-               for(x=0; x<img_w; x++, rf+=4, rc+=4) {
-                       rc[0]= FTOCHAR(rf[0]);
-                       rc[1]= FTOCHAR(rf[1]);
-                       rc[2]= FTOCHAR(rf[2]);
-                       rc[3]= FTOCHAR(rf[3]);
-               }
-               rectf+= 4*row_w;
-       }
+       if (gamma_correct) {
+               floatbuf_to_srgb_byte(rectf, rect32, 0, img_w, 0, img_h, img_w);
+       } else {
+               floatbuf_to_byte(rectf, rect32, 0, img_w, 0, img_h, img_w);
+       }
        
        glaDrawPixelsSafe(fx, fy, img_w, img_h, img_w, GL_RGBA, GL_UNSIGNED_BYTE, rect32);
 
@@ -586,8 +595,8 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo
 
 void glaDefine2DArea(rcti *screen_rect)
 {
-       int sc_w= screen_rect->xmax - screen_rect->xmin;
-       int sc_h= screen_rect->ymax - screen_rect->ymin;
+       int sc_w= screen_rect->xmax - screen_rect->xmin + 1;
+       int sc_h= screen_rect->ymax - screen_rect->ymin + 1;
 
        glViewport(screen_rect->xmin, screen_rect->ymin, sc_w, sc_h);
        glScissor(screen_rect->xmin, screen_rect->ymin, sc_w, sc_h);
@@ -721,6 +730,18 @@ void bglBegin(int mode)
        }
 }
 
+int bglPointHack() {
+       float value[4];
+       int pointhack;
+       glGetFloatv(GL_POINT_SIZE_RANGE, value);
+       if(value[1]<2.0) {
+               glGetFloatv(GL_POINT_SIZE, value);
+               pointhack= floor(value[0]+0.5);
+               if(pointhack>4) pointhack= 4;
+               return pointhack;
+       }
+       return 0;
+}
 
 void bglVertex3fv(float *vec)
 {
@@ -830,24 +851,12 @@ void bglPolygonOffset(float viewdist, float dist)
        }
 }
 
-int is_a_really_crappy_intel_card(void)
-{
-       static int well_is_it= -1;
-
-               /* Do you understand the implication? Do you? */
-       if (well_is_it==-1)
-               well_is_it= (strcmp((char*) glGetString(GL_VENDOR), "Intel Inc.") == 0);
-
-       return well_is_it;
-}
-
 void bglFlush(void) 
 {
        glFlush();
 #ifdef __APPLE__
-//     if(is_a_really_crappy_intel_card())
+//     if(GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_MAC, GPU_DRIVER_OFFICIAL))
 // XXX         myswapbuffers(); //hack to get mac intel graphics to show frontbuffer
 #endif
 }
 
-