diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-12-07 07:32:59 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-12-07 07:33:53 +0300 |
commit | 0c6d5232a3999770accf0433b436a3bdf5f6f7a8 (patch) | |
tree | eb38360a78eb403f6d664643db16f4693f57d521 /source | |
parent | e929cad7067875bb2f1815a01daae32e441f99b7 (diff) |
DRW: Remove the use of GPUTexture buffers for edit wire rendering
See previous commit for detail as why.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/intern/draw_cache.c | 4 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache.h | 3 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl.h | 1 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_cache_impl_mesh.c | 29 | ||||
-rw-r--r-- | source/blender/draw/modes/edit_mesh_mode.c | 9 | ||||
-rw-r--r-- | source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl | 16 |
6 files changed, 18 insertions, 44 deletions
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index f68239440b1..70d9f960265 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -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( diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h index 87021360108..e69c29a7375 100644 --- a/source/blender/draw/intern/draw_cache.h +++ b/source/blender/draw/intern/draw_cache.h @@ -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, diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h index d316f63ffa2..287b29ff1ba 100644 --- a/source/blender/draw/intern/draw_cache_impl.h +++ b/source/blender/draw/intern/draw_cache_impl.h @@ -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); diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index 55a0467c7a8..89b73d5e39a 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -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); diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c index 02b92843064..7245d9bafab 100644 --- a/source/blender/draw/modes/edit_mesh_mode.c +++ b/source/blender/draw/modes/edit_mesh_mode.c @@ -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); diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl index e4268188e09..aea1eb55644 100644 --- a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl +++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl @@ -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); |