Cleanup: Use GPUBatch for icon and area drawing
This is in order to remove GPU_draw_primitive to streamline the drawing abstraction.
This commit is contained in:
parent
3e7feaff44
commit
052538edc1
Notes:
blender-bot
2023-02-14 11:08:33 +01:00
Referenced by commit 92fc32e48d
, UI: Fix Icon drawing on MacOS
|
@ -28,6 +28,7 @@
|
|||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "GPU_batch.h"
|
||||
#include "GPU_batch_presets.h"
|
||||
#include "GPU_immediate.h"
|
||||
#include "GPU_matrix.h"
|
||||
#include "GPU_state.h"
|
||||
|
@ -1573,7 +1574,9 @@ static void icon_draw_cache_texture_flush_ex(GPUTexture *texture,
|
|||
GPU_shader_uniform_vector(
|
||||
shader, data_loc, 4, ICON_DRAW_CACHE_SIZE * 3, (float *)texture_draw_calls->drawcall_cache);
|
||||
|
||||
GPU_draw_primitive(GPU_PRIM_TRIS, 6 * texture_draw_calls->calls);
|
||||
GPUBatch *quad = GPU_batch_preset_quad();
|
||||
GPU_batch_set_shader(quad, shader);
|
||||
GPU_batch_draw_instanced(quad, texture_draw_calls->calls);
|
||||
|
||||
GPU_texture_unbind(texture);
|
||||
|
||||
|
@ -1721,7 +1724,9 @@ static void icon_draw_texture(float x,
|
|||
GPU_texture_bind(texture, img_binding);
|
||||
GPU_sampler_icon_bind(img_binding);
|
||||
|
||||
GPU_draw_primitive(GPU_PRIM_TRI_STRIP, 4);
|
||||
GPUBatch *quad = GPU_batch_preset_quad();
|
||||
GPU_batch_set_shader(quad, shader);
|
||||
GPU_batch_draw(quad);
|
||||
|
||||
GPU_texture_unbind(texture);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
|
|
@ -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 (v == 0) {
|
||||
pos.xy = pos.xw;
|
||||
tex.xy = tex.xw;
|
||||
}
|
||||
else if (v == 1) {
|
||||
if (gl_VertexID == 0) {
|
||||
pos.xy = pos.xz;
|
||||
tex.xy = tex.xz;
|
||||
}
|
||||
else if (v == 2) {
|
||||
else if (gl_VertexID == 1) {
|
||||
pos.xy = pos.xw;
|
||||
tex.xy = tex.xw;
|
||||
}
|
||||
else if (gl_VertexID == 2) {
|
||||
pos.xy = pos.yw;
|
||||
tex.xy = tex.yw;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include "ED_screen.h"
|
||||
#include "ED_view3d.h"
|
||||
|
||||
#include "GPU_batch_presets.h"
|
||||
#include "GPU_context.h"
|
||||
#include "GPU_framebuffer.h"
|
||||
#include "GPU_immediate.h"
|
||||
|
@ -597,7 +598,9 @@ void wm_draw_region_blend(ARegion *region, int view, bool blend)
|
|||
GPU_shader_uniform_vector(shader, rect_geo_loc, 4, 1, rectg);
|
||||
GPU_shader_uniform_vector(shader, color_loc, 4, 1, (const float[4]){1, 1, 1, 1});
|
||||
|
||||
GPU_draw_primitive(GPU_PRIM_TRI_STRIP, 4);
|
||||
GPUBatch *quad = GPU_batch_preset_quad();
|
||||
GPU_batch_set_shader(quad, shader);
|
||||
GPU_batch_draw(quad);
|
||||
|
||||
GPU_texture_unbind(texture);
|
||||
|
||||
|
|
Loading…
Reference in New Issue