Orange;
authorTon Roosendaal <ton@blender.org>
Wed, 11 Jan 2006 22:36:31 +0000 (22:36 +0000)
committerTon Roosendaal <ton@blender.org>
Wed, 11 Jan 2006 22:36:31 +0000 (22:36 +0000)
Until now, the zbuffer was written straight from the internal zbuffer,
which has values that are inverse-proportional (like 1.0/z) which makes
it very hard to use it for postprocess, like zblur or other composit effects
that require Z.

Based on info from ILM, the values stored for Z in exr files is the
actual distance from a camera. I think that's about time to migrate to that
convention!

By default now, after render, the z values are converted to floats. This
saves in exr files now, but not in the Iris Z files. That latter was a
blender-only anyway, so might be not a real hassle to drop. :)

You can see the difference in the image window, but notice the range now
is linear mapped from camera clipstart to clipend.

Note; I just discover that ortho Z values need a different correction...

18 files changed:
source/blender/imbuf/IMB_imbuf.h
source/blender/imbuf/IMB_imbuf_types.h
source/blender/imbuf/intern/allocimbuf.c
source/blender/imbuf/intern/divers.c
source/blender/imbuf/intern/openexr/openexr_api.cpp
source/blender/include/BIF_glutil.h
source/blender/render/extern/include/render_types.h
source/blender/render/intern/source/initrender.c
source/blender/render/intern/source/rendercore.c
source/blender/src/drawimage.c
source/blender/src/drawseq.c
source/blender/src/drawview.c
source/blender/src/editsima.c
source/blender/src/glutil.c
source/blender/src/header_image.c
source/blender/src/previewrender.c
source/blender/src/renderwin.c
source/blender/src/toets.c

index 63ffeb0260381664daec5c387aa153de00397a98..20a31f5de28b05f47c46bd26e97825b21bd83f79 100644 (file)
@@ -185,6 +185,7 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1);
  * @attention Defined in allocimbuf.c
  */
 short addzbufImBuf(struct ImBuf * ibuf);
+short addzbuffloatImBuf(struct ImBuf * ibuf);
 
 /**
  *
@@ -468,6 +469,7 @@ void IMB_cspace(struct ImBuf *ibuf, float mat[][4]);
  * @attention Defined in allocimbuf.c
  */
 void IMB_freezbufImBuf(struct ImBuf * ibuf);
+void IMB_freezbuffloatImBuf(struct ImBuf * ibuf);
 
 /**
  *
index 652c15afdd3de96ece773002dc388e52c0babad7..ef1aa631fc672e897aa59487122be1713bef6320 100644 (file)
@@ -88,7 +88,8 @@ typedef struct ImBuf{
        char    name[1023];             /**< The file name assocated with this image */
        char    namenull;               /**< Unused don't want to remove it thought messes things up */
        int     userflags;              /**< Used to set imbuf to Dirty and other stuff */
-       int     *zbuf;                  /**< z buffer data */
+       int     *zbuf;                  /**< z buffer data, original zbuffer */
+       float *zbuf_float;      /**< z buffer data, camera coordinates */
        void *userdata; 
        unsigned char *encodedbuffer;     /**< Compressed image only used with png currently */
        unsigned int   encodedsize;       /**< Size of data written to encodedbuffer */
@@ -133,6 +134,7 @@ typedef enum {
 
 #define IB_mem                 (1 << 14)
 #define IB_rectfloat   (1 << 15)
+#define IB_zbuffloat   (1 << 16)
 
 /*
  * The bit flag is stored in the ImBuf.ftype variable.
index 51d294d2d26134996a14e8f41688c1a84b6af888..0c1d182f4b216fda07313db60610d40c6e45dbba 100644 (file)
@@ -112,6 +112,16 @@ void IMB_freezbufImBuf(struct ImBuf * ibuf)
        ibuf->mall &= ~IB_zbuf;
 }
 
+void IMB_freezbuffloatImBuf(struct ImBuf * ibuf)
+{
+       if (ibuf==NULL) return;
+       if (ibuf->zbuf_float){
+               if (ibuf->mall & IB_zbuffloat) MEM_freeN(ibuf->zbuf_float);
+       }
+       ibuf->zbuf_float= NULL;
+       ibuf->mall &= ~IB_zbuffloat;
+}
+
 void IMB_freecmapImBuf(struct ImBuf * ibuf)
 {
        if (ibuf==NULL) return;
@@ -129,6 +139,7 @@ void IMB_freeImBuf(struct ImBuf * ibuf)
                imb_freerectImBuf(ibuf);
                imb_freerectfloatImBuf(ibuf);
                IMB_freezbufImBuf(ibuf);
+               IMB_freezbuffloatImBuf(ibuf);
                IMB_freecmapImBuf(ibuf);
                freeencodedbufferImBuf(ibuf);
                MEM_freeN(ibuf);
@@ -138,18 +149,36 @@ void IMB_freeImBuf(struct ImBuf * ibuf)
 short addzbufImBuf(struct ImBuf * ibuf)
 {
        int size;
-
+       
        if (ibuf==NULL) return(FALSE);
        
        IMB_freezbufImBuf(ibuf);
-
+       
        size = ibuf->x * ibuf->y * sizeof(unsigned int);
        if ( (ibuf->zbuf = MEM_mallocN(size, "addzbufImBuf")) ){
                ibuf->mall |= IB_zbuf;
                ibuf->flags |= IB_zbuf;
                return (TRUE);
        }
+       
+       return (FALSE);
+}
 
+short addzbuffloatImBuf(struct ImBuf * ibuf)
+{
+       int size;
+       
+       if (ibuf==NULL) return(FALSE);
+       
+       IMB_freezbuffloatImBuf(ibuf);
+       
+       size = ibuf->x * ibuf->y * sizeof(float);
+       if ( (ibuf->zbuf_float = MEM_mallocN(size, "addzbuffloatImBuf")) ){
+               ibuf->mall |= IB_zbuffloat;
+               ibuf->flags |= IB_zbuffloat;
+               return (TRUE);
+       }
+       
        return (FALSE);
 }
 
@@ -345,6 +374,13 @@ struct ImBuf *IMB_allocImBuf(short x, short y, uchar d, unsigned int flags, ucha
                        }
                }
                
+               if (flags & IB_zbuffloat){
+                       if (addzbuffloatImBuf(ibuf)==FALSE){
+                               IMB_freeImBuf(ibuf);
+                               return NULL;
+                       }
+               }
+               
                if (flags & IB_planes){
                        if (imb_addplanesImBuf(ibuf)==FALSE){
                                IMB_freeImBuf(ibuf);
@@ -355,6 +391,7 @@ struct ImBuf *IMB_allocImBuf(short x, short y, uchar d, unsigned int flags, ucha
        return (ibuf);
 }
 
+/* does no zbuffers? */
 struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1)
 {
        struct ImBuf *ibuf2, tbuf;
@@ -402,6 +439,8 @@ struct ImBuf *IMB_dupImBuf(struct ImBuf *ibuf1)
        tbuf.planes             = ibuf2->planes;
        tbuf.cmap               = ibuf2->cmap;
        tbuf.encodedbuffer = ibuf2->encodedbuffer;
+       tbuf.zbuf= NULL;
+       tbuf.zbuf_float= NULL;
        
        // set malloc flag
        tbuf.mall               = ibuf2->mall;
index cca92741275e6c12970559cfd074acaf2737bef8..f73431cb28eae3a3dff9f484ea28fefc3134e54f 100644 (file)
@@ -190,6 +190,5 @@ void IMB_rect_from_float(struct ImBuf *ibuf)
                to += 4; 
                tof += 4;
        }
-                               
 }
 
index 1fefe48c2277d174236cf98742faeb61e10d67c4..b310f128d8e4389a14d58014849246d1a6d13916 100644 (file)
@@ -167,7 +167,7 @@ static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
        
        int width = ibuf->x;
        int height = ibuf->y;
-       int write_zbuf = (flags & IB_zbuf) && ibuf->zbuf != NULL;   // summarize
+       int write_zbuf = (flags & IB_zbuffloat) && ibuf->zbuf_float != NULL;   // summarize
        
        try
        {
@@ -179,8 +179,8 @@ static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
                header.channels().insert ("G", Channel (HALF));
                header.channels().insert ("B", Channel (HALF));
                header.channels().insert ("A", Channel (HALF));
-               if (write_zbuf)         // z we do as uint always
-                       header.channels().insert ("Z", Channel (UINT));
+               if (write_zbuf)         // z we do as float always
+                       header.channels().insert ("Z", Channel (FLOAT));
                
                FrameBuffer frameBuffer;                        
                OutputFile *file = new OutputFile(name, header);                        
@@ -198,8 +198,8 @@ static short imb_save_openexr_half(struct ImBuf *ibuf, char *name, int flags)
                frameBuffer.insert ("A", Slice (HALF, (char *) &pixels[0].a, xstride, ystride));
        
                if (write_zbuf)
-                       frameBuffer.insert ("Z", Slice (UINT, (char *) ibuf->zbuf + 4*(height-1)*width,
-                                                                                       sizeof(int), sizeof(int) * -width));
+                       frameBuffer.insert ("Z", Slice (FLOAT, (char *) ibuf->zbuf_float + 4*(height-1)*width,
+                                                                                       sizeof(float), sizeof(float) * -width));
                if(ibuf->rect_float) {
                        float *from;
                        
@@ -257,8 +257,8 @@ static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
        
        int width = ibuf->x;
        int height = ibuf->y;
-       int write_zbuf = (flags & IB_zbuf) && ibuf->zbuf != NULL;   // summarize
-       
+       int write_zbuf = (flags & IB_zbuffloat) && ibuf->zbuf_float != NULL;   // summarize
+
        try
        {
                Header header (width, height);
@@ -270,7 +270,7 @@ static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
                header.channels().insert ("B", Channel (FLOAT));
                header.channels().insert ("A", Channel (FLOAT));
                if (write_zbuf)
-                       header.channels().insert ("Z", Channel (UINT));
+                       header.channels().insert ("Z", Channel (FLOAT));
                
                FrameBuffer frameBuffer;                        
                OutputFile *file = new OutputFile(name, header);                        
@@ -284,8 +284,8 @@ static short imb_save_openexr_float(struct ImBuf *ibuf, char *name, int flags)
                frameBuffer.insert ("A", Slice (FLOAT,  (char *) (first+3), xstride, ystride));
 
                if (write_zbuf)
-                       frameBuffer.insert ("Z", Slice (UINT, (char *) ibuf->zbuf + 4*(height-1)*width,
-                                                                                       sizeof(int), sizeof(int) * -width));
+                       frameBuffer.insert ("Z", Slice (FLOAT, (char *) ibuf->zbuf_float + 4*(height-1)*width,
+                                                                                       sizeof(float), sizeof(float) * -width));
                file->setFrameBuffer (frameBuffer);                               
                file->writePixels (height);                                       
                delete file;
@@ -407,12 +407,12 @@ struct ImBuf *imb_load_openexr(unsigned char *mem, int size, int flags)
                                frameBuffer.insert ("A", Slice (FLOAT,  (char *) (first+3), xstride, ystride, 1, 1, 1.0f));
 
                                if(exr_has_zbuffer(file)) {
-                                       int *firstz;
+                                       float *firstz;
                                        
-                                       addzbufImBuf(ibuf);
-                                       firstz= ibuf->zbuf - (dw.min.x - dw.min.y*width);
+                                       addzbuffloatImBuf(ibuf);
+                                       firstz= ibuf->zbuf_float - (dw.min.x - dw.min.y*width);
                                        firstz+= (height-1)*width;
-                                       frameBuffer.insert ("Z", Slice (UINT,  (char *)firstz , sizeof(int), -width*sizeof(int)));
+                                       frameBuffer.insert ("Z", Slice (FLOAT,  (char *)firstz , sizeof(float), -width*sizeof(float)));
                                }
                                
                                file->setFrameBuffer (frameBuffer);
index b585f91ec3e039022d1a9999a2ba5e9818ab60b2..af231de66f83b27b9e1184f408b9d73a977ee7f2 100644 (file)
@@ -125,7 +125,7 @@ void glaRasterPosSafe2f             (float x, float y, float known_good_x, float known_good
         * to use the glScissor functionality if images are to be drawn
         * with an inset view matrix.
         */
-void glaDrawPixelsSafe         (float x, float y, int img_w, int img_h, int format, void *rect);
+void glaDrawPixelsSafe         (float x, float y, int img_w, int img_h, int format, int type, void *rect);
 
        /**
         * Functions like a limited glDrawPixels, but actually draws the
index efb0863b94a6b0a320564329d258aa1383b5387a..8fad87c270766f81ea4715b203f7cb58f99b0c06 100644 (file)
@@ -161,7 +161,8 @@ typedef struct RE_Render
        struct MemArena *memArena;
 
        int *rectaccu;
-       int *rectz; /* z buffer: distance buffer */
+       int *rectz;             /* z buffer: distance buffer */
+       float *rectzf;  /* z distances, camera space */
        unsigned int *rectf1, *rectf2;
        unsigned int *rectot; /* z buffer: face index buffer, recycled as colour buffer! */
        unsigned int *rectspare; /*  */
index c0c175709e12591c15f54703ee27bcc661217242..948c1179b3b986f6364509dc7be1172edf12ded9 100644 (file)
@@ -501,10 +501,12 @@ void RE_free_render_data()
        if(R.rectot) MEM_freeN(R.rectot);
        if(R.rectftot) MEM_freeN(R.rectftot);
        if(R.rectz) MEM_freeN(R.rectz);
+       if(R.rectzf) MEM_freeN(R.rectzf);
        if(R.rectspare) MEM_freeN(R.rectspare);
        R.rectot= NULL;
        R.rectftot= NULL;
        R.rectz= NULL;
+       R.rectzf= NULL;
        R.rectspare= NULL;
        
        free_filt_mask();
@@ -805,6 +807,43 @@ static void addparttorect(Part *pa)
        }
 }
 
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+static void convert_zbuf_to_distbuf(void)
+{
+       float *rectzf, zco;
+       int a, *rectz;
+       
+       if(R.rectz==NULL) return;
+       if(R.rectzf) {
+               printf("called convert zbuf wrong...\n");
+               MEM_freeN(R.rectzf);
+       }
+       
+       /* need to make sure winmat is OK */
+       R.xstart= -R.afmx;
+       R.ystart= -R.afmy;
+       R.xend= R.xstart+R.rectx-1;
+       R.yend= R.ystart+R.recty-1;
+       
+       RE_setwindowclip(0, -1);
+       
+       rectzf= R.rectzf= MEM_mallocN(R.rectx*R.recty*sizeof(float), "rectzf");
+       rectz= R.rectz;
+       
+       for(a=R.rectx*R.recty; a>0; a--, rectz++, rectzf++) {
+               if(*rectz==0x7FFFFFFF)
+                       *rectzf= 10e10;
+               else {
+                       zco= ((float)*rectz)/2147483647.0f;
+                       *rectzf= R.winmat[3][2]/(R.winmat[2][2] - R.winmat[2][3]*zco);
+               }
+       }
+       
+       MEM_freeN(R.rectz);
+       R.rectz= NULL;
+}
+
 
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
 
@@ -872,6 +911,9 @@ static void add_to_blurbuf(int blur)
 }
 
 
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+
 /* yafray: main yafray render/export call */
 static void yafrayRender(void)
 {
@@ -889,6 +931,8 @@ static void yafrayRender(void)
        R.rectot = MEM_callocN(sizeof(int)*R.rectx*R.recty, "rectot");
        /* zbuf */
        if (R.rectz) MEM_freeN(R.rectz);
+       if (R.rectzf) MEM_freeN(R.rectzf);
+       R.rectzf= NULL;
        R.rectz = (unsigned int *)MEM_mallocN(sizeof(int)*R.rectx*R.recty, "rectz");
        /* float rgba buf */
        if (R.rectftot) MEM_freeN(R.rectftot);
@@ -970,6 +1014,8 @@ static void mainRenderLoop(void)  /* here the PART and FIELD loops */
        
        if(R.rectz) MEM_freeN(R.rectz);
        R.rectz = NULL;
+       if(R.rectzf) MEM_freeN(R.rectzf);
+       R.rectzf = NULL;
        if(R.rectftot) MEM_freeN(R.rectftot);
        R.rectftot = NULL;
        
@@ -1448,6 +1494,9 @@ void RE_initrender(struct View3D *ogl_render_view3d)
        /* grms... this is a nasty global */
        do_gamma= 0;
        
+       /* for now, we do always */
+       convert_zbuf_to_distbuf();
+       
        /* these flags remain on, until reset in caller to render (renderwin.c) */
        R.flag &= (R_RENDERING|R_ANIMRENDER|R_REDRAW_PRV);
 }
index 5ad6f4e84a9fec250cdb8621d64bc03a745665c9..24751c6a66fd59e98787c2b59e7665d46792027e 100644 (file)
@@ -2345,7 +2345,7 @@ void *shadepixel(float x, float y, int z, int facenr, int mask, float *col, floa
                        float zco;
                        /* inverse of zbuf calc: zbuf = MAXZ*hoco_z/hoco_w */
                        
-                       zco= ((float)z)/(float)0x7FFFFFFF;
+                       zco= ((float)z)/2147483647.0f;
                        shi.co[2]= R.winmat[3][2]/( R.winmat[2][3]*zco - R.winmat[2][2] );
                        
                        fac= zcor= shi.co[2]/shi.view[2];
index 6be938236ff77545b9f2233d330fc50cecbb6674..0f5edee1328a4a28795604c68913a7345dcaf25b 100644 (file)
 
 #include "IMB_imbuf_types.h"
 
+#include "DNA_camera_types.h"
 #include "DNA_color_types.h"
 #include "DNA_image_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
 #include "DNA_packedFile_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
@@ -1104,7 +1106,7 @@ static void sima_draw_alpha_pixels(float x1, float y1, int rectx, int recty, uns
        
        /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
        glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
-       glaDrawPixelsSafe(x1, y1, rectx, recty, GL_UNSIGNED_INT, recti);
+       glaDrawPixelsSafe(x1, y1, rectx, recty, GL_LUMINANCE, GL_UNSIGNED_INT, recti);
        glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
 }
 
@@ -1112,7 +1114,7 @@ static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int
 {
        if(recti==NULL)
                return;
-
+       
        /* zbuffer values are signed, so we need to shift color range */
        glPixelTransferf(GL_RED_SCALE, 0.5f);
        glPixelTransferf(GL_GREEN_SCALE, 0.5f);
@@ -1121,8 +1123,8 @@ static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int
        glPixelTransferf(GL_GREEN_BIAS, 0.5f);
        glPixelTransferf(GL_BLUE_BIAS, 0.5f);
        
-       glaDrawPixelsSafe(x1, y1, rectx, recty, GL_INT, recti);
-
+       glaDrawPixelsSafe(x1, y1, rectx, recty, GL_LUMINANCE, GL_INT, recti);
+       
        glPixelTransferf(GL_RED_SCALE, 1.0f);
        glPixelTransferf(GL_GREEN_SCALE, 1.0f);
        glPixelTransferf(GL_BLUE_SCALE, 1.0f);
@@ -1131,6 +1133,32 @@ static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int
        glPixelTransferf(GL_BLUE_BIAS, 0.0f);
 }
 
+static void sima_draw_zbuffloat_pixels(float x1, float y1, int rectx, int recty, float *rect_float)
+{
+       float bias, scale, *rectf;
+       int a;
+       
+       if(rect_float==NULL)
+               return;
+       
+       if(G.scene->camera && G.scene->camera->type==OB_CAMERA) {
+               bias= ((Camera *)G.scene->camera->data)->clipsta;
+               scale= 1.0f/((Camera *)G.scene->camera->data)->clipend;
+       }
+       else {
+               bias= 0.1f;
+               scale= 0.01f;
+       }
+       
+       rectf= MEM_mallocN(rectx*recty*4, "temp");
+       for(a= rectx*recty -1; a>=0; a--)
+               rectf[a]= (rect_float[a]-bias)*scale;
+
+       glaDrawPixelsSafe(x1, y1, rectx, recty, GL_LUMINANCE, GL_FLOAT, rectf);
+       
+       MEM_freeN(rectf);
+}
+
 void drawimagespace(ScrArea *sa, void *spacedata)
 {
        SpaceImage *sima= spacedata;
@@ -1188,7 +1216,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
                glPixelZoom((float)sima->zoom, (float)sima->zoom);
                                
                if(sima->flag & SI_EDITTILE) {
-                       glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
+                       glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
                        
                        glPixelZoom(1.0, 1.0);
                        
@@ -1233,7 +1261,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
                                /* rect= ibuf->rect; */
                                for(sy= 0; sy+dy<=ibuf->y; sy+= dy) {
                                        for(sx= 0; sx+dx<=ibuf->x; sx+= dx) {
-                                               glaDrawPixelsSafe(x1+sx*sima->zoom, y1+sy*sima->zoom, dx, dy, GL_UNSIGNED_BYTE, rect);
+                                               glaDrawPixelsSafe(x1+sx*sima->zoom, y1+sy*sima->zoom, dx, dy, GL_RGBA, GL_UNSIGNED_BYTE, rect);
                                        }
                                }
                                
@@ -1244,14 +1272,17 @@ void drawimagespace(ScrArea *sa, void *spacedata)
                                        sima_draw_alpha_pixels(x1, y1, ibuf->x, ibuf->y, ibuf->rect);
                                }
                                else if(sima->flag & SI_SHOW_ZBUF) {
-                                       sima_draw_zbuf_pixels(x1, y1, ibuf->x, ibuf->y, ibuf->zbuf);
+                                       if(ibuf->zbuf)
+                                               sima_draw_zbuf_pixels(x1, y1, ibuf->x, ibuf->y, ibuf->zbuf);
+                                       else
+                                               sima_draw_zbuffloat_pixels(x1, y1, ibuf->x, ibuf->y, ibuf->zbuf_float);
                                }
                                else {
                                        if(sima->flag & SI_USE_ALPHA) {
                                                sima_draw_alpha_backdrop(sima, x1, y1, (float)ibuf->x, (float)ibuf->y);
                                                glEnable(GL_BLEND);
                                        }
-                                       glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
+                                       glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
                                        
                                        if(sima->flag & SI_USE_ALPHA)
                                                glDisable(GL_BLEND);
@@ -1273,7 +1304,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
 
                                        glEnable(GL_BLEND);
                                        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-                                       glaDrawPixelsSafe(x1 + offx, y1 + offy, w, h, GL_UNSIGNED_BYTE, clonerect);
+                                       glaDrawPixelsSafe(x1 + offx, y1 + offy, w, h, GL_RGBA, GL_UNSIGNED_BYTE, clonerect);
                                        glDisable(GL_BLEND);
 
                                        MEM_freeN(clonerect);
index ea39e172d7e19fa17af61080764dcd7aac63693b..36647ea5064a03ab2c4ca2bac0b4460657ac7863 100644 (file)
@@ -503,7 +503,7 @@ static void draw_image_seq(ScrArea *sa)
        glaDefine2DArea(&curarea->winrct);
        glPixelZoom(zoom, zoom);
        
-       glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
+       glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
        
        glPixelZoom(1.0, 1.0);
 
index b6007dad9e7890195f2e0fae0ae3508c98867428..f065a052dd70a9fe641a8c06b17fa6ece5c2c4fd 100644 (file)
@@ -435,7 +435,7 @@ static void draw_bgpic(void)
        
        glaDefine2DArea(&curarea->winrct);
        glPixelZoom(zoomx, zoomy);
-       glaDrawPixelsSafe(x1, y1, ima->ibuf->x, ima->ibuf->y, GL_UNSIGNED_BYTE, bgpic->rect);
+       glaDrawPixelsSafe(x1, y1, ima->ibuf->x, ima->ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, bgpic->rect);
        glPixelZoom(1.0, 1.0);
 
        glMatrixMode(GL_PROJECTION);
index 93dab74debc022d089cb90cc2db64348e99465f2..72e1baa17f3330f87874d348b33621550c657541 100644 (file)
@@ -1398,7 +1398,7 @@ int minmax_tface_uv(float *min, float *max)
        return sel;
 }
 
-static void sima_show_info(int x, int y, char *cp, float *fp, int *zp)
+static void sima_show_info(int x, int y, char *cp, float *fp, int *zp, float *zpf)
 {
        short ofs;
        char str[256];
@@ -1410,6 +1410,8 @@ static void sima_show_info(int x, int y, char *cp, float *fp, int *zp)
                ofs+= sprintf(str+ofs, "| R: %.3f G: %.3f B: %.3f A: %.3f ", fp[0], fp[1], fp[2], fp[3]);
        if(zp)
                ofs+= sprintf(str+ofs, "| Z: %.4f ", 0.5+0.5*( ((float)*zp)/(float)0x7fffffff));
+       if(zpf)
+               ofs+= sprintf(str+ofs, "| Z: %.3f ", *zpf);
        
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_BLEND);
@@ -1446,7 +1448,7 @@ void sima_sample_color(void)
                        areamouseco_to_ipoco(G.v2d, mval, &fx, &fy);
                        
                        if(fx>=0.0 && fy>=0.0 && fx<1.0 && fy<1.0) {
-                               float *fp= NULL;
+                               float *fp= NULL, *zpf= NULL;
                                int *zp= NULL;
                                char *cp= NULL;
                                
@@ -1456,12 +1458,13 @@ void sima_sample_color(void)
                                if(x>=ibuf->x) x= ibuf->x-1;
                                if(y>=ibuf->y) y= ibuf->y-1;
                                
-                               if(ibuf->rect) {
+                               if(ibuf->rect)
                                        cp= (char *)(ibuf->rect + y*ibuf->x + x);
-                               }
-                               if(ibuf->zbuf) {
+                               if(ibuf->zbuf)
                                        zp= ibuf->zbuf + y*ibuf->x + x;
-                               }
+                               if(ibuf->zbuf_float)
+                                       zpf= ibuf->zbuf_float + y*ibuf->x + x;
+                               
                                if(ibuf->rect_float) {
                                        fp= (ibuf->rect_float + 4*(y*ibuf->x + x));
                                        
@@ -1480,7 +1483,7 @@ void sima_sample_color(void)
                                scrarea_do_windraw(curarea);
                                myortho2(-0.375, curarea->winx-0.375, -0.375, curarea->winy-0.375);
                                glLoadIdentity();
-                               sima_show_info(x, y, cp, fp, zp);
+                               sima_show_info(x, y, cp, fp, zp, zpf);
                                screen_swapbuffers();
                        }
                        
index cc5c2f3c9ec36e1a3f20b268399dc0780ab9c166..a8e10f05b28cef62be4224dc40c2f134c976e464 100644 (file)
@@ -286,7 +286,7 @@ void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void *
        glPixelStorei(GL_UNPACK_ROW_LENGTH, lrowlength);
 }
 
-void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int format, void *rect)
+void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int format, int type, void *rect)
 {
        float xzoom= glaGetOneFloat(GL_ZOOM_X);
        float yzoom= glaGetOneFloat(GL_ZOOM_Y);
@@ -339,17 +339,25 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int format, void
                }
 
                glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
-               if(format==GL_FLOAT) {
-                       float *f_rect= (float *)rect;
-                       glDrawPixels(draw_w, draw_h, GL_RGBA, GL_FLOAT, f_rect + (off_y*img_w + off_x)*4);
-               }
-               else if(format==GL_INT || format==GL_UNSIGNED_INT) {
-                       int *i_rect= (int *)rect;
-                       glDrawPixels(draw_w, draw_h, GL_LUMINANCE, format, i_rect + (off_y*img_w + off_x));
+               if(format==GL_LUMINANCE || format==GL_RED) {
+                       if(type==GL_FLOAT) {
+                               float *f_rect= (float *)rect;
+                               glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y*img_w + off_x));
+                       }
+                       else if(type==GL_INT || type==GL_UNSIGNED_INT) {
+                               int *i_rect= (int *)rect;
+                               glDrawPixels(draw_w, draw_h, format, type, i_rect + (off_y*img_w + off_x));
+                       }
                }
-               else {
-                       unsigned char *uc_rect= (unsigned char *) rect;
-                       glDrawPixels(draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, uc_rect + (off_y*img_w + off_x)*4);
+               else { /* RGBA */
+                       if(type==GL_FLOAT) {
+                               float *f_rect= (float *)rect;
+                               glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y*img_w + off_x)*4);
+                       }
+                       else if(type==GL_UNSIGNED_BYTE) {
+                               unsigned char *uc_rect= (unsigned char *) rect;
+                               glDrawPixels(draw_w, draw_h, format, type, uc_rect + (off_y*img_w + off_x)*4);
+                       }
                }
                
                glPixelStorei(GL_UNPACK_ROW_LENGTH,  old_row_length);
index 29546276fd826fa13ec3b1b6bfea9244b392196d..22cd439f543b404c45fe103b64787479a6205e1e 100644 (file)
@@ -1186,12 +1186,13 @@ void image_buttons(void)
                xco+= XIC;
                uiDefIconButBitS(block, TOG, SI_SHOW_ALPHA, B_SIMA_SHOW_ALPHA, ICON_DOT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws only alpha");
                xco+= XIC;
-               if(G.sima->image->ibuf &&  G.sima->image->ibuf->zbuf) {
-                       uiDefIconButBitS(block, TOG, SI_SHOW_ZBUF, B_SIMA_SHOW_ZBUF, ICON_SOLID, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws zbuffer values");
-                       xco+= XIC;
-               }
-               else G.sima->flag &= ~SI_SHOW_ZBUF;     /* no confusing display for non-zbuf images */
-               
+               if(G.sima->image->ibuf) {
+                       if(G.sima->image->ibuf->zbuf || G.sima->image->ibuf->zbuf_float) {
+                               uiDefIconButBitS(block, TOG, SI_SHOW_ZBUF, B_SIMA_SHOW_ZBUF, ICON_SOLID, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws zbuffer values");
+                               xco+= XIC;
+                       }
+                       else G.sima->flag &= ~SI_SHOW_ZBUF;     /* no confusing display for non-zbuf images */
+               }               
                uiBlockEndAlign(block);
                xco+= 8;
        }
index 6d9c327d2f04847f0d3915b6eb6d024f8e3082be..a632eb6661e990f5391f167d5d139e713ce53898 100644 (file)
@@ -316,11 +316,11 @@ static void display_pr_scanline(unsigned int *rect, int recty, short pr_rectx)
        if( (recty & 3)==3) {
                
                if(recty == 3) {
-                       glaDrawPixelsSafe(prerect.xmin, prerect.ymin, pr_rectx, 4, GL_UNSIGNED_BYTE, rect);
+                       glaDrawPixelsSafe(prerect.xmin, prerect.ymin, pr_rectx, 4, GL_RGBA, GL_UNSIGNED_BYTE, rect);
                }
                else {
                        rect+= (recty-4)*pr_rectx;
-                       glaDrawPixelsSafe(prerect.xmin, prerect.ymin + (((float)recty-4.0)*pr_facy), pr_rectx, 5, GL_UNSIGNED_BYTE, rect);
+                       glaDrawPixelsSafe(prerect.xmin, prerect.ymin + (((float)recty-4.0)*pr_facy), pr_rectx, 5, GL_RGBA, GL_UNSIGNED_BYTE, rect);
                }
        }
 }
index ca81ec97b6b5d6df47bda2106e3671139f6dc032..51ff8ea3219810f7cf155ff145e7cfcedc9d644f 100644 (file)
@@ -328,11 +328,11 @@ static void renderwin_draw(RenderWin *rw, int just_clear)
                if(rw->flags & RW_FLAGS_ALPHA) {
                        /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
                        glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
-                       glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_INT, R.rectot);
+                       glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_LUMINANCE, GL_UNSIGNED_INT, R.rectot);
                        glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
                }
                else {
-                       glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_BYTE, R.rectot);
+                       glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_RGBA, GL_UNSIGNED_BYTE, R.rectot);
                }
                glPixelZoom(1.0, 1.0);
        }
@@ -363,7 +363,6 @@ static void renderwin_mouse_moved(RenderWin *rw)
        if (rw->flags & RW_FLAGS_PIXEL_EXAMINING) {
                int imgco[2], ofs;
                char buf[128];
-               int *pxlz;      // zbuffer is signed 
                char *pxl;
 
                if (R.rectot && renderwin_win_to_image_co(rw, rw->lmouse, imgco)) {
@@ -375,9 +374,9 @@ static void renderwin_mouse_moved(RenderWin *rw)
                                float *pxlf= R.rectftot + 4*(R.rectx*imgco[1] + imgco[0]);
                                ofs+= sprintf(buf+ofs, " | R: %.3f G: %.3f B: %.3f A: %.3f ", pxlf[0], pxlf[1], pxlf[2], pxlf[3]);
                        }
-                       if (R.rectz) {
-                               pxlz= &R.rectz[R.rectx*imgco[1] + imgco[0]];                    
-                               sprintf(buf+ofs, "| Z: %f", 0.5+0.5*( ((float)*pxlz)/(float)INT_MAX) );
+                       if (R.rectzf) {
+                               float *pxlz= &R.rectzf[R.rectx*imgco[1] + imgco[0]];                    
+                               sprintf(buf+ofs, "| Z: %.3f", *pxlz );
                        }
 
                        renderwin_set_infotext(rw, buf);
@@ -740,7 +739,7 @@ static void renderwin_progress(RenderWin *rw, int start_y, int nlines, int rect_
 
        glDrawBuffer(GL_FRONT);
        glPixelZoom(rw->zoom, rw->zoom);
-       glaDrawPixelsSafe(disprect[0][0], disprect[0][1] + start_y*rw->zoom, rect_w, nlines, GL_UNSIGNED_BYTE, &rect[start_y*rect_w*4]);
+       glaDrawPixelsSafe(disprect[0][0], disprect[0][1] + start_y*rw->zoom, rect_w, nlines, GL_RGBA, GL_UNSIGNED_BYTE, &rect[start_y*rect_w*4]);
        glPixelZoom(1.0, 1.0);
        glFlush();
        glDrawBuffer(GL_BACK);
@@ -827,7 +826,7 @@ static void renderview_progress_display_cb(int y1, int y2, int w, int h, unsigne
                sy= vb.ymin + facy*y1;
 
                glPixelZoom(facx, facy);
-               glaDrawPixelsSafe(sx, sy, w, nlines, GL_UNSIGNED_BYTE, rect+w*y1);
+               glaDrawPixelsSafe(sx, sy, w, nlines, GL_RGBA, GL_UNSIGNED_BYTE, rect+w*y1);
                glPixelZoom(1.0, 1.0);
 
                glFlush();
index 62f31f7f5853ce6a9e65f925a12e54a8bed9c8a3..8eba2c0acd8a1a691e9dc40e6a2d512cf4e64d17 100644 (file)
@@ -217,8 +217,8 @@ void schrijfplaatje(char *name)
                        
                        ibuf->ftype |= (R.r.quality & OPENEXR_COMPRESS);
                        
-                       if(R.rectz && (R.r.subimtype & R_OPENEXR_ZBUF))
-                               ibuf->zbuf = (int *)R.rectz;
+                       if(R.rectzf && (R.r.subimtype & R_OPENEXR_ZBUF))
+                               ibuf->zbuf_float = R.rectzf;
                }
 #endif
                else if((R.r.imtype==R_TARGA) || (R.r.imtype==R_PNG)) {
@@ -241,7 +241,7 @@ void schrijfplaatje(char *name)
        
                RE_make_existing_file(name);
 
-               if(IMB_saveiff(ibuf, name, IB_rect | IB_zbuf)==0) {
+               if(IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat)==0) {
                        perror(name);
                        G.afbreek= 1;
                }