Fix T41414, T41386.
authorAntony Riakiotakis <kalast@gmail.com>
Tue, 12 Aug 2014 11:49:27 +0000 (13:49 +0200)
committerAntony Riakiotakis <kalast@gmail.com>
Tue, 12 Aug 2014 11:49:45 +0000 (13:49 +0200)
There were a few issues to fix here:

* We did not really unpremultiply float image dabs prior to sending them
to the GPU. That made float and byte image result different in texture
painting and undoing could change the result.
* To make textures nicely composited over the mesh, I used decal mode in
OpenGL texture environment for the texture unit. This uses the texture's
alpha channel with a nice over operator.
* Texture creation used to override the alpha setting due to the display
restrictions. Not so anymore, people can now create transparent byte
images.

Also, made alpha zero default for new textures now, since it has such a
nice effect here.

source/blender/editors/sculpt_paint/paint_image_proj.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/gpu/intern/gpu_draw.c
source/blender/imbuf/intern/divers.c

index e10c97ea9f0dab79951a38053d05a35f6eb76d58..516666e8c2ce71718081317b1b362caffca6f8b7 100644 (file)
@@ -4852,7 +4852,7 @@ bool proj_paint_add_slot(bContext *C, Material *ma, wmOperator *op)
                                mtex->mapto = type;
 
                                if (mtex->tex) {
-                                       float color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+                                       float color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
                                        char imagename[MAX_ID_NAME - 2] = "Material Diffuse Color";
                                        int width = 1024;
                                        int height = 1024;
@@ -4870,12 +4870,6 @@ bool proj_paint_add_slot(bContext *C, Material *ma, wmOperator *op)
                                                RNA_string_get(op->ptr, "name", imagename);
                                        }
 
-                                       if (!use_float) {
-                                               /* crappy workaround because we only upload straight color to OpenGL and that makes
-                                                * painting result on viewport too opaque */
-                                               color[3] = 1.0;
-                                       }
-
                                        ima = mtex->tex->ima = BKE_image_add_generated(bmain, width, height, imagename, alpha ? 32 : 24, use_float,
                                                                                       gen_type, color);
 
@@ -4926,7 +4920,7 @@ static int texture_paint_add_texture_paint_slot_invoke(bContext *C, wmOperator *
 void PAINT_OT_add_texture_paint_slot(wmOperatorType *ot)
 {
        PropertyRNA *prop;
-       static float default_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+       static float default_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
 
        /* identifiers */
        ot->name = "Add Texture Paint Slot";
index 89babf977e15482d3f376e4e736747f998f67a19..e571584a10ff712af44a1cc7b04e31dcef97768c 100644 (file)
@@ -303,11 +303,13 @@ static bool set_draw_settings_cached(int clearcache, MTFace *texface, Material *
                                c_badtex = false;
                                if (GPU_verify_image(ima, NULL, 0, 1, 0, false)) {
                                        glEnable(GL_TEXTURE_2D);
+                                       glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
                                }
                                else {
                                        c_badtex = true;
                                        GPU_clear_tpage(true);
                                        glDisable(GL_TEXTURE_2D);
+                                       glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
                                        glBindTexture(GL_TEXTURE_2D, 0);
                                }
                        }
@@ -437,7 +439,8 @@ static void draw_textured_end(void)
                        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
                        glBindTexture(GL_TEXTURE_2D, 0);
                        glActiveTexture(GL_TEXTURE0);
-               }
+               }               
+               glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
                /* manual reset, since we don't use tpage */
                glBindTexture(GL_TEXTURE_2D, 0);
                /* force switch off textures */
index 8abe7d5534ae8cdd7b16c101ce7afeb4c5cc583d..7295f0259c583a325818412997cdd7f925a77f50 100644 (file)
@@ -1039,21 +1039,14 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h)
                 * which is much quicker for painting */
                GLint row_length, skip_pixels, skip_rows;
 
-               glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length);
-               glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels);
-               glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows);
-
                /* if color correction is needed, we must update the part that needs updating. */
                if (ibuf->rect_float) {
-                       float *buffer = MEM_mallocN(w*h*sizeof(float)*4, "temp_texpaint_float_buf");
+                       float *buffer = MEM_mallocN(w * h * sizeof(float) * 4, "temp_texpaint_float_buf");
                        bool is_data = (ima->tpageflag & IMA_GLBIND_IS_DATA) != 0;
                        IMB_partial_rect_from_float(ibuf, buffer, x, y, w, h, is_data);
-
+                       
                        if (GPU_check_scaled_image(ibuf, ima, buffer, x, y, w, h)) {
                                MEM_freeN(buffer);
-                               glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length);
-                               glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels);
-                               glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows);
                                BKE_image_release_ibuf(ima, ibuf, NULL);
                                return;
                        }
@@ -1078,15 +1071,16 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h)
                }
 
                if (GPU_check_scaled_image(ibuf, ima, NULL, x, y, w, h)) {
-                       glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length);
-                       glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels);
-                       glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows);
                        BKE_image_release_ibuf(ima, ibuf, NULL);
                        return;
                }
 
                glBindTexture(GL_TEXTURE_2D, ima->bindcode);
 
+               glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length);
+               glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels);
+               glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows);
+
                glPixelStorei(GL_UNPACK_ROW_LENGTH, ibuf->x);
                glPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
                glPixelStorei(GL_UNPACK_SKIP_ROWS, y);
index 9975c58bdd2638aa06b29b27d744ef4b9e529052..03cd5ecd64666ff43fb91454652c91c803f4911d 100644 (file)
@@ -720,6 +720,7 @@ void IMB_partial_rect_from_float(ImBuf *ibuf, float *buffer, int x, int y, int w
                                            ibuf->channels, IB_PROFILE_SRGB, profile_from, true,
                                            w, h, w, ibuf->x);
 
+               IMB_buffer_float_unpremultiply(buffer, w, h);
                /* XXX: need to convert to image buffer's rect space */
                IMB_buffer_byte_from_float(rect_byte, buffer,
                                           4, ibuf->dither, IB_PROFILE_SRGB, IB_PROFILE_SRGB, 0,