Commit: 13ac2a49b04ed129e7cd41af0b60bf8c96e1b72e
Author: Antonio Vazquez
Date:   Thu Jun 22 19:08:34 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB13ac2a49b04ed129e7cd41af0b60bf8c96e1b72e

WIP: First step to fix z-depth problem

Need a change in draw manager to allow writting zdepth without checking adding 
DRW_STATE_DEPTH_ALWAYS

Thanks to Clement Foucault for all the help fixing this bug.

===================================================================

M       source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M       source/blender/draw/engines/gpencil/gpencil_engine.c
M       source/blender/draw/engines/gpencil/gpencil_engine.h

===================================================================

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c 
b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 4728267fd4f..a136c5d434a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -194,7 +194,8 @@ static GpencilBatchCache *gpencil_batch_cache_get(bGPdata 
*gpd, int cfra)
 }
 
  /* create shading group for filling */
-static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(GPENCIL_Data *vedata, 
DRWPass *pass, GPUShader *shader, Object *ob, 
+static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(GPENCIL_e_data 
*e_data, GPENCIL_Data *vedata, DRWPass *pass, 
+       GPUShader *shader, Object *ob,
        bGPdata *gpd, PaletteColor *palcolor, int id)
 {
        GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
@@ -248,6 +249,12 @@ static DRWShadingGroup 
*DRW_gpencil_shgroup_fill_create(GPENCIL_Data *vedata, DR
                        BKE_image_release_ibuf(image, ibuf, NULL);
                }
        }
+       else {
+               /* if no texture defined, need a blank texture to avoid errors 
in draw manager */
+               DRW_shgroup_uniform_texture(grp, "myTexture", 
e_data->gpencil_blank_texture);
+               stl->shgroups[id].t_clamp = 0;
+               DRW_shgroup_uniform_int(grp, "t_clamp", 
&stl->shgroups[id].t_clamp, 1);
+       }
 
        /* object scale */
        if ((ob) && (id > -1)) {
@@ -457,7 +464,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, 
GPENCIL_e_data *e_dat
 #endif
                if (gps->totpoints > 1) {
                        int id = stl->storage->pal_id;
-                       stl->shgroups[id].shgrps_fill = 
DRW_gpencil_shgroup_fill_create(vedata, psl->stroke_pass, 
e_data->gpencil_fill_sh, ob, gpd, gps->palcolor, id);
+                       stl->shgroups[id].shgrps_fill = 
DRW_gpencil_shgroup_fill_create(e_data, vedata, psl->stroke_pass, 
e_data->gpencil_fill_sh, ob, gpd, gps->palcolor, id);
                        stl->shgroups[id].shgrps_stroke = 
DRW_gpencil_shgroup_stroke_create(vedata, psl->stroke_pass, 
e_data->gpencil_stroke_sh, ob, gpd, id);
                        ++stl->storage->pal_id;
 
@@ -639,3 +646,15 @@ void DRW_gpencil_batch_cache_free(bGPdata *gpd)
        MEM_SAFE_FREE(gpd->batch_cache);
 }
 
+struct GPUTexture *DRW_gpencil_create_blank_texture(int width, int height)
+{
+       struct GPUTexture *tex;
+       int w = width;
+       int h = height;
+       float *final_rect = MEM_callocN(sizeof(float) * 4 * w * h, "Gpencil 
Blank Texture");
+
+       tex = DRW_texture_create_2D(w, h, DRW_TEX_RGBA_8, DRW_TEX_FILTER, 
final_rect);
+       MEM_freeN(final_rect);
+
+       return tex;
+}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 1054943ecde..2d93ae7ad98 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -94,6 +94,12 @@ static void GPENCIL_engine_init(void *vedata)
        }
 
        unit_m4(stl->storage->unit_matrix);
+
+       /* blank texture used if no texture defined for fill shader*/
+       if (!e_data.gpencil_blank_texture) {
+               e_data.gpencil_blank_texture = 
DRW_gpencil_create_blank_texture(64, 64);
+       }
+
 }
 
 static void GPENCIL_engine_free(void)
@@ -102,6 +108,7 @@ static void GPENCIL_engine_free(void)
        DRW_SHADER_FREE_SAFE(e_data.gpencil_fill_sh);
        DRW_SHADER_FREE_SAFE(e_data.gpencil_stroke_sh);
        DRW_SHADER_FREE_SAFE(e_data.gpencil_fullscreen_sh);
+       DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture);
 }
 
 static void GPENCIL_cache_init(void *vedata)
@@ -224,6 +231,9 @@ static void GPENCIL_draw_scene(void *vedata)
                /* detach temp textures */
                DRW_framebuffer_texture_detach(e_data.temp_fbcolor_depth_tx);
                DRW_framebuffer_texture_detach(e_data.temp_fbcolor_color_tx);
+               
+               /* attach again default framebuffer */
+               DRW_framebuffer_bind(dfbl->default_fb);
        }
        /* free memory */
        MEM_SAFE_FREE(stl->g_data->gp_object_cache);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h 
b/source/blender/draw/engines/gpencil/gpencil_engine.h
index f1408e52483..29193c7f443 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -112,6 +112,7 @@ typedef struct GPENCIL_e_data {
        /* temp depth texture */
        struct GPUTexture *temp_fbcolor_depth_tx;
        struct GPUTexture *temp_fbcolor_color_tx;
+       struct GPUTexture *gpencil_blank_texture;
 } GPENCIL_e_data; /* Engine data */
 
 /* Gwn_Batch Cache */
@@ -154,6 +155,8 @@ struct Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(struct 
bGPdata *gpd, float
 struct Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(const struct tGPspoint 
*points, int totpoints, float ink[4]);
 struct Gwn_Batch *DRW_gpencil_get_buffer_point_geom(struct bGPdata *gpd, short 
thickness);
 
+struct GPUTexture *DRW_gpencil_create_blank_texture(int width, int height);
+
 void gpencil_batch_cache_clear(struct bGPdata *gpd);
 
 bool gpencil_can_draw_stroke(const struct bGPDstroke *gps, const bool onion);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to