diff options
Diffstat (limited to 'source/blender/gpu')
4 files changed, 33 insertions, 27 deletions
diff --git a/source/blender/gpu/GPU_batch_presets.h b/source/blender/gpu/GPU_batch_presets.h index 7a235dd0e12..19f200fecbf 100644 --- a/source/blender/gpu/GPU_batch_presets.h +++ b/source/blender/gpu/GPU_batch_presets.h @@ -43,6 +43,8 @@ struct GPUBatch *GPU_batch_preset_panel_drag_widget(const float pixelsize, const float col_dark[4], const float width) ATTR_WARN_UNUSED_RESULT; +struct GPUBatch *GPU_batch_preset_quad(void); + void gpu_batch_presets_init(void); void gpu_batch_presets_register(struct GPUBatch *preset_batch); bool gpu_batch_presets_unregister(struct GPUBatch *preset_batch); diff --git a/source/blender/gpu/intern/gpu_batch_presets.c b/source/blender/gpu/intern/gpu_batch_presets.c index 8adb1ba1ed3..6a1645a71d8 100644 --- a/source/blender/gpu/intern/gpu_batch_presets.c +++ b/source/blender/gpu/intern/gpu_batch_presets.c @@ -62,6 +62,7 @@ static struct { static struct { struct { GPUBatch *panel_drag_widget; + GPUBatch *quad; } batch; float panel_drag_widget_pixelsize; @@ -330,6 +331,24 @@ GPUBatch *GPU_batch_preset_panel_drag_widget(const float pixelsize, return g_presets_2d.batch.panel_drag_widget; } +/* To be used with procedural placement inside shader. */ +GPUBatch *GPU_batch_preset_quad(void) +{ + if (!g_presets_2d.batch.quad) { + GPUVertBuf *vbo = GPU_vertbuf_create_with_format(preset_2d_format()); + GPU_vertbuf_data_alloc(vbo, 4); + + float pos_data[4][2] = {{0.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}, {1.0f, 0.0f}}; + GPU_vertbuf_attr_fill(vbo, g_presets_2d.attr_id.pos, pos_data); + /* Don't fill the color. */ + + g_presets_2d.batch.quad = GPU_batch_create_ex(GPU_PRIM_TRI_FAN, vbo, NULL, GPU_BATCH_OWNS_VBO); + + gpu_batch_presets_register(g_presets_2d.batch.quad); + } + return g_presets_2d.batch.quad; +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl index d25cd586e65..640ceb97e5b 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl @@ -13,34 +13,19 @@ flat out vec4 finalColor; void main() { - /* Rendering 2 triangle per icon. */ - int i = gl_VertexID / 6; - int v = gl_VertexID % 6; + vec4 pos = calls_data[gl_InstanceID * 3]; + vec4 tex = calls_data[gl_InstanceID * 3 + 1]; + finalColor = calls_data[gl_InstanceID * 3 + 2]; - vec4 pos = calls_data[i * 3]; - vec4 tex = calls_data[i * 3 + 1]; - finalColor = calls_data[i * 3 + 2]; - - /* TODO Remove this */ - if (v == 2) { - v = 4; - } - else if (v == 3) { - v = 0; - } - else if (v == 5) { - v = 2; + if (gl_VertexID == 0) { + pos.xy = pos.xz; + tex.xy = tex.xz; } - - if (v == 0) { + else if (gl_VertexID == 1) { pos.xy = pos.xw; tex.xy = tex.xw; } - else if (v == 1) { - pos.xy = pos.xz; - tex.xy = tex.xz; - } - else if (v == 2) { + else if (gl_VertexID == 2) { pos.xy = pos.yw; tex.xy = tex.yw; } diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl index fcd877a37eb..ab9c30505c2 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl @@ -14,13 +14,13 @@ void main() vec2 uv; vec2 co; if (gl_VertexID == 0) { - co = rect_geom.xw; - uv = rect_icon.xw; - } - else if (gl_VertexID == 1) { co = rect_geom.xy; uv = rect_icon.xy; } + else if (gl_VertexID == 1) { + co = rect_geom.xw; + uv = rect_icon.xw; + } else if (gl_VertexID == 2) { co = rect_geom.zw; uv = rect_icon.zw; |