DRW: Remove the use of GPUTexture buffers for edit wire rendering
authorClément Foucault <foucault.clem@gmail.com>
Fri, 7 Dec 2018 04:32:59 +0000 (05:32 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Fri, 7 Dec 2018 04:33:53 +0000 (05:33 +0100)
See previous commit for detail as why.

source/blender/draw/intern/draw_cache.c
source/blender/draw/intern/draw_cache.h
source/blender/draw/intern/draw_cache_impl.h
source/blender/draw/intern/draw_cache_impl_mesh.c
source/blender/draw/modes/edit_mesh_mode.c
source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl

index f68239440b1430eb871277048ed55b3d320e560d..70d9f9602650a3ae9be92708db789698f76880ad 100644 (file)
@@ -3001,8 +3001,7 @@ GPUBatch *DRW_cache_mesh_surface_overlay_get(Object *ob)
 
 void DRW_cache_mesh_wire_overlay_get(
         Object *ob,
-        GPUBatch **r_tris, GPUBatch **r_ledges, GPUBatch **r_lverts,
-        struct GPUTexture **r_data_tex)
+        GPUBatch **r_tris, GPUBatch **r_ledges, GPUBatch **r_lverts)
 {
        BLI_assert(ob->type == OB_MESH);
 
@@ -3011,7 +3010,6 @@ void DRW_cache_mesh_wire_overlay_get(
        *r_tris = DRW_mesh_batch_cache_get_overlay_triangles(me);
        *r_ledges = DRW_mesh_batch_cache_get_overlay_loose_edges(me);
        *r_lverts = DRW_mesh_batch_cache_get_overlay_loose_verts(me);
-       *r_data_tex = DRW_mesh_batch_cache_get_overlay_data_tex(me);
 }
 
 void DRW_cache_mesh_normals_overlay_get(
index 8702136010810076bb15872b4782e2cf498ba4b6..e69c29a7375e6fe3c6f4388b8e8272bdf7d03501 100644 (file)
@@ -128,8 +128,7 @@ struct GPUBatch *DRW_cache_bone_dof_lines_get(void);
 struct GPUBatch *DRW_cache_mesh_surface_overlay_get(struct Object *ob);
 void DRW_cache_mesh_wire_overlay_get(
         struct Object *ob,
-        struct GPUBatch **r_tris, struct GPUBatch **r_ledges, struct GPUBatch **r_lverts,
-        struct GPUTexture **r_data_tex);
+        struct GPUBatch **r_tris, struct GPUBatch **r_ledges, struct GPUBatch **r_lverts);
 void DRW_cache_mesh_normals_overlay_get(
         struct Object *ob,
         struct GPUBatch **r_tris, struct GPUBatch **r_tris_lnor,
index d316f63ffa29ad66634c6b3090448f8799d0bdf2..287b29ff1ba861fe38b7c67db41d23884e2433b6 100644 (file)
@@ -152,7 +152,6 @@ struct GPUBatch *DRW_mesh_batch_cache_get_overlay_loose_edges(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_overlay_loose_edges_nor(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_overlay_loose_verts(struct Mesh *me);
 struct GPUBatch *DRW_mesh_batch_cache_get_overlay_facedots(struct Mesh *me);
-struct GPUTexture *DRW_mesh_batch_cache_get_overlay_data_tex(struct Mesh *me);
 /* edit-mesh selection (use generic function for faces) */
 struct GPUBatch *DRW_mesh_batch_cache_get_facedots_with_select_id(struct Mesh *me, uint select_id_offset);
 struct GPUBatch *DRW_mesh_batch_cache_get_edges_with_select_id(struct Mesh *me, uint select_id_offset);
index 55a0467c7a808f13ce4d75a6d162f419219ca1ad..89b73d5e39acfa4da73c43ce6a087ad8b624c2a7 100644 (file)
@@ -62,7 +62,6 @@
 #include "GPU_batch_presets.h"
 #include "GPU_draw.h"
 #include "GPU_material.h"
-#include "GPU_texture.h"
 
 #include "DRW_render.h"
 
@@ -2008,8 +2007,6 @@ typedef struct MeshBatchCache {
        GPUIndexBuf *triangles_in_order;
        GPUIndexBuf *ledges_in_order;
 
-       GPUTexture *pos_in_order_tx; /* Depending on pos_in_order */
-
        GPUBatch *all_verts;
        GPUBatch *all_edges;
        GPUBatch *all_triangles;
@@ -2054,10 +2051,6 @@ typedef struct MeshBatchCache {
 
        GPUVertBuf *edges_face_overlay_data;
        GPUBatch *edges_face_overlay;
-       GPUTexture *edges_face_overlay_tx;
-       int edges_face_overlay_tri_count; /* Number of tri in edges_face_overlay(_adj)_tx */
-       int edges_face_overlay_tri_count_low; /* Number of tri that are sure to produce edges. */
-       bool edges_face_reduce_len; /* Has the edges_face_overlay vertbuf has been sorted. */
 
        /* Maybe have shaded_triangles_data split into pos_nor and uv_tangent
         * to minimize data transfer for skinned mesh. */
@@ -2075,7 +2068,6 @@ typedef struct MeshBatchCache {
        GPUVertBuf *ed_tri_pos;
        GPUVertBuf *ed_tri_nor; /* LoopNor, VertNor */
        GPUVertBuf *ed_tri_data;
-       GPUTexture *ed_tri_data_tx;
        GPUIndexBuf *ed_tri_verts;
 
        GPUVertBuf *ed_ledge_pos;
@@ -2320,8 +2312,6 @@ void DRW_mesh_batch_cache_dirty_tag(Mesh *me, int mode)
                        GPU_VERTBUF_DISCARD_SAFE(cache->ed_edge_pos);
                        GPU_VERTBUF_DISCARD_SAFE(cache->ed_vert_pos);
                        GPU_INDEXBUF_DISCARD_SAFE(cache->ed_tri_verts);
-                       DRW_TEXTURE_FREE_SAFE(cache->ed_tri_data_tx);
-
                        GPU_BATCH_DISCARD_SAFE(cache->overlay_triangles);
                        GPU_BATCH_DISCARD_SAFE(cache->overlay_loose_verts);
                        GPU_BATCH_DISCARD_SAFE(cache->overlay_loose_edges);
@@ -2417,7 +2407,6 @@ static void mesh_batch_cache_clear(Mesh *me)
        GPU_BATCH_DISCARD_SAFE(cache->all_triangles);
 
        GPU_VERTBUF_DISCARD_SAFE(cache->pos_in_order);
-       DRW_TEXTURE_FREE_SAFE(cache->pos_in_order_tx);
        GPU_INDEXBUF_DISCARD_SAFE(cache->edges_in_order);
        GPU_INDEXBUF_DISCARD_SAFE(cache->triangles_in_order);
        GPU_INDEXBUF_DISCARD_SAFE(cache->ledges_in_order);
@@ -2438,7 +2427,6 @@ static void mesh_batch_cache_clear(Mesh *me)
        GPU_BATCH_DISCARD_SAFE(cache->overlay_loose_verts);
        GPU_BATCH_DISCARD_SAFE(cache->overlay_loose_edges);
        GPU_BATCH_DISCARD_SAFE(cache->overlay_loose_edges_nor);
-       DRW_TEXTURE_FREE_SAFE(cache->ed_tri_data_tx);
 
        GPU_BATCH_DISCARD_SAFE(cache->overlay_weight_faces);
        GPU_BATCH_DISCARD_SAFE(cache->overlay_weight_verts);
@@ -2471,7 +2459,6 @@ static void mesh_batch_cache_clear(Mesh *me)
 
        GPU_VERTBUF_DISCARD_SAFE(cache->edges_face_overlay_data);
        GPU_BATCH_DISCARD_SAFE(cache->edges_face_overlay);
-       DRW_TEXTURE_FREE_SAFE(cache->edges_face_overlay_tx);
 
        mesh_batch_cache_discard_shaded_tri(cache);
 
@@ -3726,6 +3713,7 @@ static GPUVertFormat *edit_mesh_overlay_data_format(uint *r_data_id)
        static uint data_id;
        if (format_flag.attr_len == 0) {
                data_id = GPU_vertformat_attr_add(&format_flag, "data", GPU_COMP_U8, 4, GPU_FETCH_INT);
+               GPU_vertformat_triple_load(&format_flag);
        }
        *r_data_id = data_id;
        return &format_flag;
@@ -3835,10 +3823,6 @@ static void mesh_batch_cache_create_overlay_tri_buffers(
                        GPU_vertbuf_data_resize(vbo_data, vbo_len_used);
                }
        }
-
-       /* Upload data early because we need to create the texture for it. */
-       GPU_vertbuf_use(vbo_data);
-       cache->ed_tri_data_tx = GPU_texture_create_from_vertbuf(vbo_data);
 }
 
 static void mesh_batch_cache_create_overlay_ledge_buffers(
@@ -5194,17 +5178,6 @@ GPUBatch *DRW_mesh_batch_cache_get_overlay_triangles(Mesh *me)
        return cache->overlay_triangles;
 }
 
-GPUTexture *DRW_mesh_batch_cache_get_overlay_data_tex(Mesh *me)
-{
-       MeshBatchCache *cache = mesh_batch_cache_get(me);
-
-       if (cache->ed_tri_data_tx == NULL) {
-               mesh_batch_cache_create_overlay_batches(me);
-       }
-
-       return cache->ed_tri_data_tx;
-}
-
 GPUBatch *DRW_mesh_batch_cache_get_overlay_loose_edges(Mesh *me)
 {
        MeshBatchCache *cache = mesh_batch_cache_get(me);
index 02b928430644f05c74d877db07e2c98bb80ff08b..7245d9bafabb5fabcff13c31d633c112a683772d 100644 (file)
@@ -385,6 +385,10 @@ static DRWPass *edit_mesh_create_overlay_pass(
        if (!fast_mode) {
                DRW_shgroup_uniform_bool_copy(*r_face_shgrp, "isXray", xray);
        }
+       else {
+               /* To be able to use triple load. */
+               DRW_shgroup_state_enable(*r_face_shgrp, DRW_STATE_FIRST_VERTEX_CONVENTION);
+       }
 
        *r_ledges_shgrp = DRW_shgroup_create(ledge_sh, pass);
        DRW_shgroup_uniform_block(*r_ledges_shgrp, "globalsBlock", globals_ubo);
@@ -571,13 +575,10 @@ static void edit_mesh_add_ob_to_pass(
         DRWShadingGroup *facefill_shgrp)
 {
        struct GPUBatch *geo_ovl_tris, *geo_ovl_verts, *geo_ovl_lnor, *geo_ovl_ledges, *geo_ovl_lverts, *geo_ovl_fcenter;
-       struct GPUTexture *data_texture;
        ToolSettings *tsettings = scene->toolsettings;
 
-       DRW_cache_mesh_wire_overlay_get(ob, &geo_ovl_tris, &geo_ovl_ledges, &geo_ovl_lverts, &data_texture);
+       DRW_cache_mesh_wire_overlay_get(ob, &geo_ovl_tris, &geo_ovl_ledges, &geo_ovl_lverts);
 
-       face_shgrp = DRW_shgroup_create_sub(face_shgrp);
-       DRW_shgroup_uniform_texture(face_shgrp, "dataBuffer", data_texture);
        DRW_shgroup_call_add(face_shgrp, geo_ovl_tris, ob->obmat);
 
        DRW_shgroup_call_add(ledges_shgrp, geo_ovl_ledges, ob->obmat);
index e4268188e09c5c4822424c95ec712a9df2eb17ea..aea1eb55644120c5724a0b0817d6084e6dce609e 100644 (file)
@@ -10,8 +10,6 @@ uniform ivec4 dataMask = ivec4(0xFF);
 
 uniform float ofs = 1e-5;
 
-uniform isamplerBuffer dataBuffer;
-
 in vec3 pos;
 #ifdef VERTEX_FACING
 in vec3 vnor;
@@ -43,6 +41,13 @@ void main()
 
 #else /* EDGE_FIX */
 
+/* Consecutive data of the nth vertex.
+ * Only valid for first vertex in the triangle.
+ * Assuming GL_FRIST_VERTEX_CONVENTION. */
+in ivec4 data0;
+in ivec4 data1;
+in ivec4 data2;
+
 flat out vec3 edgesCrease;
 flat out vec3 edgesBweight;
 flat out vec4 faceColor;
@@ -66,11 +71,10 @@ void main()
        barycentric = vec3(equal(ivec3(0, 1, 2), ivec3(vidx)));
 
        /* Edge */
-       ivec4 vData[3], data = ivec4(0);
+       ivec4 vData[3] = ivec4[3](data0, data1, data2);
        ivec3 eflag;
        for (int v = 0; v < 3; ++v) {
-               data = texelFetch(dataBuffer, v_0 + v);
-               vData[v] = data & dataMask;
+               vData[v] = vData[v] & dataMask;
                flag[v] = eflag[v] = vData[v].y | (vData[v].x << 8);
                edgesCrease[v] = vData[v].z / 255.0;
                edgesBweight[v] = vData[v].w / 255.0;
@@ -87,7 +91,7 @@ void main()
                faceColor = colorFace;
 
 #  ifdef VERTEX_SELECTION
-       vertexColor = EDIT_MESH_vertex_color(vData[vidx].x).rgb;
+       vertexColor = EDIT_MESH_vertex_color(data0.x).rgb;
 #  endif
 #  ifdef VERTEX_FACING
        vec4 vPos = ModelViewMatrix * vec4(pos, 1.0);