GPUBatch: Remove most use of GPU_batch_draw_advanced()
This is in order to better encapsulate / isolate the drawing code.
This commit is contained in:
parent
de4eb115ac
commit
93165cbf47
|
@ -1181,10 +1181,7 @@ void UI_widgetbase_draw_cache_flush(void)
|
|||
MAX_WIDGET_PARAMETERS * MAX_WIDGET_BASE_BATCH,
|
||||
(float *)g_widget_base_batch.params);
|
||||
GPU_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
|
||||
GPU_matrix_bind(batch->interface);
|
||||
GPU_shader_set_srgb_uniform(batch->interface);
|
||||
GPU_batch_bind(batch);
|
||||
GPU_batch_draw_advanced(batch, 0, 0, 0, g_widget_base_batch.count);
|
||||
GPU_batch_draw_instanced(batch, g_widget_base_batch.count);
|
||||
}
|
||||
g_widget_base_batch.count = 0;
|
||||
}
|
||||
|
|
|
@ -1147,7 +1147,6 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(region), v
|
|||
|
||||
GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_POINTS, vert, NULL, GPU_BATCH_OWNS_VBO);
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
GPU_batch_bind(batch);
|
||||
|
||||
/* draw any snapped verts first */
|
||||
rgba_uchar_to_float(fcol, kcd->colors.point_a);
|
||||
|
@ -1156,7 +1155,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(region), v
|
|||
GPU_shader_set_srgb_uniform(batch->interface);
|
||||
GPU_point_size(11);
|
||||
if (snapped_verts_count > 0) {
|
||||
GPU_batch_draw_advanced(batch, 0, snapped_verts_count, 0, 0);
|
||||
GPU_batch_draw_range(batch, 0, snapped_verts_count);
|
||||
}
|
||||
|
||||
/* now draw the rest */
|
||||
|
@ -1164,7 +1163,7 @@ static void knifetool_draw(const bContext *UNUSED(C), ARegion *UNUSED(region), v
|
|||
GPU_batch_uniform_4fv(batch, "color", fcol);
|
||||
GPU_point_size(7);
|
||||
if (other_verts_count > 0) {
|
||||
GPU_batch_draw_advanced(batch, snapped_verts_count, other_verts_count, 0, 0);
|
||||
GPU_batch_draw_range(batch, snapped_verts_count, other_verts_count);
|
||||
}
|
||||
|
||||
GPU_batch_discard(batch);
|
||||
|
|
|
@ -262,8 +262,6 @@ static void draw_line_loop(const float coords[][3], int coords_len, const float
|
|||
GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_LINE_LOOP, vert, NULL, GPU_BATCH_OWNS_VBO);
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
|
||||
|
||||
GPU_batch_bind(batch);
|
||||
|
||||
GPU_batch_uniform_4fv(batch, "color", color);
|
||||
|
||||
float viewport[4];
|
||||
|
@ -297,8 +295,6 @@ static void draw_line_pairs(const float coords_a[][3],
|
|||
GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_LINES, vert, NULL, GPU_BATCH_OWNS_VBO);
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
|
||||
|
||||
GPU_batch_bind(batch);
|
||||
|
||||
GPU_batch_uniform_4fv(batch, "color", color);
|
||||
|
||||
float viewport[4];
|
||||
|
@ -347,8 +343,6 @@ static void draw_line_bounds(const BoundBox *bounds, const float color[4])
|
|||
GPUBatch *batch = GPU_batch_create_ex(GPU_PRIM_LINES, vert, NULL, GPU_BATCH_OWNS_VBO);
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
|
||||
|
||||
GPU_batch_bind(batch);
|
||||
|
||||
GPU_batch_uniform_4fv(batch, "color", color);
|
||||
|
||||
float viewport[4];
|
||||
|
|
|
@ -288,10 +288,6 @@ static void draw_uvs_texpaint(const Scene *scene, Object *ob, Depsgraph *depsgra
|
|||
uint idx = 0;
|
||||
bool prev_ma_match = (mpoly->mat_nr == (ob_eval->actcol - 1));
|
||||
|
||||
GPU_matrix_bind(geom->interface);
|
||||
GPU_shader_set_srgb_uniform(geom->interface);
|
||||
GPU_batch_bind(geom);
|
||||
|
||||
/* TODO(fclem): If drawcall count becomes a problem in the future
|
||||
* we can use multi draw indirect drawcalls for this.
|
||||
* (not implemented in GPU module at the time of writing). */
|
||||
|
@ -299,7 +295,7 @@ static void draw_uvs_texpaint(const Scene *scene, Object *ob, Depsgraph *depsgra
|
|||
bool ma_match = (mpoly->mat_nr == (ob_eval->actcol - 1));
|
||||
if (ma_match != prev_ma_match) {
|
||||
if (ma_match == false) {
|
||||
GPU_batch_draw_advanced(geom, draw_start, idx - draw_start, 0, 0);
|
||||
GPU_batch_draw_range(geom, draw_start, idx - draw_start);
|
||||
}
|
||||
else {
|
||||
draw_start = idx;
|
||||
|
@ -309,7 +305,7 @@ static void draw_uvs_texpaint(const Scene *scene, Object *ob, Depsgraph *depsgra
|
|||
prev_ma_match = ma_match;
|
||||
}
|
||||
if (prev_ma_match == true) {
|
||||
GPU_batch_draw_advanced(geom, draw_start, idx - draw_start, 0, 0);
|
||||
GPU_batch_draw_range(geom, draw_start, idx - draw_start);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -135,6 +135,7 @@ void GPU_batch_program_set_builtin_with_config(GPUBatch *batch,
|
|||
eGPUBuiltinShader shader_id,
|
||||
eGPUShaderConfig sh_cfg);
|
||||
|
||||
/* Will only work after setting the batch program. */
|
||||
void GPU_batch_uniform_1i(GPUBatch *, const char *name, int value);
|
||||
void GPU_batch_uniform_1b(GPUBatch *, const char *name, bool value);
|
||||
void GPU_batch_uniform_1f(GPUBatch *, const char *name, float value);
|
||||
|
@ -148,10 +149,10 @@ void GPU_batch_uniform_2fv_array(GPUBatch *, const char *name, const int len, co
|
|||
void GPU_batch_uniform_4fv_array(GPUBatch *, const char *name, const int len, const float *data);
|
||||
void GPU_batch_uniform_mat4(GPUBatch *, const char *name, const float data[4][4]);
|
||||
|
||||
void GPU_batch_draw(GPUBatch *);
|
||||
void GPU_batch_draw(GPUBatch *batch);
|
||||
void GPU_batch_draw_range(GPUBatch *batch, int v_first, int v_count);
|
||||
void GPU_batch_draw_instanced(GPUBatch *batch, int i_count);
|
||||
|
||||
/* Needs to be called before GPU_batch_draw_advanced. */
|
||||
void GPU_batch_bind(GPUBatch *);
|
||||
/* This does not bind/unbind shader and does not call GPU_matrix_bind() */
|
||||
void GPU_batch_draw_advanced(GPUBatch *, int v_first, int v_count, int i_first, int i_count);
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
static GLuint g_default_attr_vbo = 0;
|
||||
|
||||
static void gpu_batch_bind(GPUBatch *batch);
|
||||
static void batch_update_program_bindings(GPUBatch *batch, uint i_first);
|
||||
|
||||
void GPU_batch_vao_cache_clear(GPUBatch *batch)
|
||||
|
@ -381,8 +382,10 @@ void GPU_batch_set_shader(GPUBatch *batch, GPUShader *shader)
|
|||
batch->interface = shader->interface;
|
||||
batch->shader = shader;
|
||||
batch->vao_id = batch_vao_get(batch);
|
||||
GPU_shader_bind(batch->shader); /* hack! to make Batch_Uniform* simpler */
|
||||
GPU_batch_bind(batch);
|
||||
GPU_shader_bind(batch->shader);
|
||||
GPU_matrix_bind(batch->shader->interface);
|
||||
GPU_shader_set_srgb_uniform(batch->shader->interface);
|
||||
gpu_batch_bind(batch);
|
||||
}
|
||||
|
||||
void gpu_batch_remove_interface_ref(GPUBatch *batch, const GPUShaderInterface *interface)
|
||||
|
@ -617,7 +620,7 @@ static void *elem_offset(const GPUIndexBuf *el, int v_first)
|
|||
}
|
||||
|
||||
/* Use when drawing with GPU_batch_draw_advanced */
|
||||
void GPU_batch_bind(GPUBatch *batch)
|
||||
static void gpu_batch_bind(GPUBatch *batch)
|
||||
{
|
||||
glBindVertexArray(batch->vao_id);
|
||||
|
||||
|
@ -633,17 +636,25 @@ void GPU_batch_bind(GPUBatch *batch)
|
|||
|
||||
void GPU_batch_draw(GPUBatch *batch)
|
||||
{
|
||||
#if TRUST_NO_ONE
|
||||
assert(batch->phase == GPU_BATCH_READY_TO_DRAW);
|
||||
assert(batch->verts[0]->vbo_id != 0);
|
||||
#endif
|
||||
GPU_shader_bind(batch->shader);
|
||||
GPU_matrix_bind(batch->interface); // external call.
|
||||
GPU_shader_set_srgb_uniform(batch->interface);
|
||||
|
||||
GPU_batch_bind(batch);
|
||||
GPU_batch_draw_advanced(batch, 0, 0, 0, 0);
|
||||
GPU_shader_unbind();
|
||||
}
|
||||
|
||||
void GPU_batch_draw_range(GPUBatch *batch, int v_first, int v_count)
|
||||
{
|
||||
GPU_shader_bind(batch->shader);
|
||||
GPU_batch_draw_advanced(batch, v_first, v_count, 0, 0);
|
||||
GPU_shader_unbind();
|
||||
}
|
||||
|
||||
/* Draw multiple instance of a batch without having any instance attributes. */
|
||||
void GPU_batch_draw_instanced(GPUBatch *batch, int i_count)
|
||||
{
|
||||
BLI_assert(batch->inst[0] == NULL);
|
||||
|
||||
GPU_shader_bind(batch->shader);
|
||||
GPU_batch_draw_advanced(batch, 0, 0, 0, i_count);
|
||||
GPU_shader_unbind();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue