Cleanup: GPU: Replace Batch uniform by shader uniform using macro
This is a first step into removing uniforms from GPU_batch and Imm.
This commit is contained in:
parent
b8b56ee172
commit
df28d2c27e
|
@ -2475,7 +2475,7 @@ void DRW_draw_depth_object(
|
|||
GPU_SHADER_CFG_DEFAULT;
|
||||
GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_DEPTH_ONLY, sh_cfg);
|
||||
if (world_clip_planes != NULL) {
|
||||
GPU_batch_uniform_4fv_array(batch, "WorldClipPlanes", 6, world_clip_planes[0]);
|
||||
GPU_batch_uniform_4fv_array(batch, "WorldClipPlanes", 6, world_clip_planes);
|
||||
}
|
||||
|
||||
GPU_batch_draw(batch);
|
||||
|
|
|
@ -226,10 +226,10 @@ static void button2d_draw_intern(const bContext *C,
|
|||
float color_contrast[4];
|
||||
copy_v3_fl(color_contrast, rgb_to_grayscale(color) < 0.2f ? 1 : 0);
|
||||
color_contrast[3] = color[3];
|
||||
GPU_batch_uniform_4f(button->shape_batch[i], "color", UNPACK4(color_contrast));
|
||||
GPU_shader_uniform_4f(button->shape_batch[i]->shader, "color", UNPACK4(color_contrast));
|
||||
}
|
||||
else {
|
||||
GPU_batch_uniform_4f(button->shape_batch[i], "color", UNPACK4(color));
|
||||
GPU_shader_uniform_4f(button->shape_batch[i]->shader, "color", UNPACK4(color));
|
||||
}
|
||||
|
||||
GPU_batch_draw(button->shape_batch[i]);
|
||||
|
|
|
@ -161,7 +161,7 @@ void UI_draw_roundbox_aa(
|
|||
|
||||
GPUBatch *batch = ui_batch_roundbox_widget_get();
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
|
||||
GPU_batch_uniform_4fv_array(batch, "parameters", 11, (float *)&widget_params);
|
||||
GPU_batch_uniform_4fv_array(batch, "parameters", 11, (float(*)[4]) & widget_params);
|
||||
|
||||
GPU_blend(true);
|
||||
|
||||
|
@ -290,7 +290,7 @@ void UI_draw_roundbox_4fv(
|
|||
|
||||
GPUBatch *batch = ui_batch_roundbox_widget_get();
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
|
||||
GPU_batch_uniform_4fv_array(batch, "parameters", 11, (float *)&widget_params);
|
||||
GPU_batch_uniform_4fv_array(batch, "parameters", 11, (float(*)[4]) & widget_params);
|
||||
|
||||
GPU_blend(true);
|
||||
|
||||
|
@ -483,7 +483,7 @@ void UI_draw_roundbox_shade_x(bool filled,
|
|||
|
||||
GPUBatch *batch = ui_batch_roundbox_widget_get();
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
|
||||
GPU_batch_uniform_4fv_array(batch, "parameters", 11, (float *)&widget_params);
|
||||
GPU_batch_uniform_4fv_array(batch, "parameters", 11, (float(*)[4]) & widget_params);
|
||||
GPU_batch_draw(batch);
|
||||
|
||||
GPU_blend(false);
|
||||
|
@ -2760,7 +2760,7 @@ void ui_draw_dropshadow(
|
|||
|
||||
GPUBatch *batch = ui_batch_roundbox_shadow_get();
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_SHADOW);
|
||||
GPU_batch_uniform_4fv_array(batch, "parameters", 4, (float *)&widget_params);
|
||||
GPU_batch_uniform_4fv_array(batch, "parameters", 4, (float(*)[4]) & widget_params);
|
||||
GPU_batch_uniform_1f(batch, "alpha", 1.0f - visibility);
|
||||
GPU_batch_draw(batch);
|
||||
|
||||
|
|
|
@ -1170,7 +1170,7 @@ void UI_widgetbase_draw_cache_flush(void)
|
|||
/* draw single */
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
|
||||
GPU_batch_uniform_4fv_array(
|
||||
batch, "parameters", MAX_WIDGET_PARAMETERS, (float *)g_widget_base_batch.params);
|
||||
batch, "parameters", MAX_WIDGET_PARAMETERS, (float(*)[4])g_widget_base_batch.params);
|
||||
GPU_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
|
||||
GPU_batch_draw(batch);
|
||||
}
|
||||
|
@ -1179,7 +1179,7 @@ void UI_widgetbase_draw_cache_flush(void)
|
|||
GPU_batch_uniform_4fv_array(batch,
|
||||
"parameters",
|
||||
MAX_WIDGET_PARAMETERS * MAX_WIDGET_BASE_BATCH,
|
||||
(float *)g_widget_base_batch.params);
|
||||
(float(*)[4])g_widget_base_batch.params);
|
||||
GPU_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
|
||||
GPU_batch_draw_instanced(batch, g_widget_base_batch.count);
|
||||
}
|
||||
|
@ -1247,7 +1247,7 @@ static void draw_widgetbase_batch(uiWidgetBase *wtb)
|
|||
GPUBatch *batch = ui_batch_roundbox_widget_get();
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
|
||||
GPU_batch_uniform_4fv_array(
|
||||
batch, "parameters", MAX_WIDGET_PARAMETERS, (float *)&wtb->uniform_params);
|
||||
batch, "parameters", MAX_WIDGET_PARAMETERS, (float(*)[4]) & wtb->uniform_params);
|
||||
GPU_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
|
||||
GPU_batch_draw(batch);
|
||||
}
|
||||
|
|
|
@ -4026,7 +4026,7 @@ static void nodelink_batch_draw(SpaceNode *snode)
|
|||
GPU_vertbuf_use(g_batch_link.inst_vbo); /* force update. */
|
||||
|
||||
GPU_batch_program_set_builtin(g_batch_link.batch, GPU_SHADER_2D_NODELINK_INST);
|
||||
GPU_batch_uniform_4fv_array(g_batch_link.batch, "colors", 6, (float *)colors);
|
||||
GPU_batch_uniform_4fv_array(g_batch_link.batch, "colors", 6, colors);
|
||||
GPU_batch_uniform_1f(g_batch_link.batch, "expandSize", snode->aspect * LINK_WIDTH);
|
||||
GPU_batch_uniform_1f(g_batch_link.batch, "arrowSize", ARROW_SIZE);
|
||||
GPU_batch_draw(g_batch_link.batch);
|
||||
|
@ -4108,8 +4108,8 @@ void node_draw_link_bezier(
|
|||
|
||||
GPUBatch *batch = g_batch_link.batch_single;
|
||||
GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_NODELINK);
|
||||
GPU_batch_uniform_2fv_array(batch, "bezierPts", 4, (float *)vec);
|
||||
GPU_batch_uniform_4fv_array(batch, "colors", 3, (float *)colors);
|
||||
GPU_batch_uniform_2fv_array(batch, "bezierPts", 4, vec);
|
||||
GPU_batch_uniform_4fv_array(batch, "colors", 3, colors);
|
||||
GPU_batch_uniform_1f(batch, "expandSize", snode->aspect * LINK_WIDTH);
|
||||
GPU_batch_uniform_1f(batch, "arrowSize", ARROW_SIZE);
|
||||
GPU_batch_uniform_1i(batch, "doArrow", drawarrow);
|
||||
|
|
|
@ -128,18 +128,24 @@ void GPU_batch_program_set_builtin_with_config(GPUBatch *batch,
|
|||
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);
|
||||
void GPU_batch_uniform_2f(GPUBatch *, const char *name, float x, float y);
|
||||
void GPU_batch_uniform_3f(GPUBatch *, const char *name, float x, float y, float z);
|
||||
void GPU_batch_uniform_4f(GPUBatch *, const char *name, float x, float y, float z, float w);
|
||||
void GPU_batch_uniform_2fv(GPUBatch *, const char *name, const float data[2]);
|
||||
void GPU_batch_uniform_3fv(GPUBatch *, const char *name, const float data[3]);
|
||||
void GPU_batch_uniform_4fv(GPUBatch *, const char *name, const float data[4]);
|
||||
void GPU_batch_uniform_2fv_array(GPUBatch *, const char *name, const int len, const float *data);
|
||||
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]);
|
||||
/* TODO(fclem) Theses needs to be replaced by GPU_shader_uniform_* with explicit shader. */
|
||||
#define GPU_batch_uniform_1i(batch, name, x) GPU_shader_uniform_1i((batch)->shader, name, x);
|
||||
#define GPU_batch_uniform_1b(batch, name, x) GPU_shader_uniform_1b((batch)->shader, name, x);
|
||||
#define GPU_batch_uniform_1f(batch, name, x) GPU_shader_uniform_1f((batch)->shader, name, x);
|
||||
#define GPU_batch_uniform_2f(batch, name, x, y) GPU_shader_uniform_2f((batch)->shader, name, x, y);
|
||||
#define GPU_batch_uniform_3f(batch, name, x, y, z) \
|
||||
GPU_shader_uniform_3f((batch)->shader, name, x, y, z);
|
||||
#define GPU_batch_uniform_4f(batch, name, x, y, z, w) \
|
||||
GPU_shader_uniform_4f((batch)->shader, name, x, y, z, w);
|
||||
#define GPU_batch_uniform_2fv(batch, name, val) GPU_shader_uniform_2fv((batch)->shader, name, val);
|
||||
#define GPU_batch_uniform_3fv(batch, name, val) GPU_shader_uniform_3fv((batch)->shader, name, val);
|
||||
#define GPU_batch_uniform_4fv(batch, name, val) GPU_shader_uniform_4fv((batch)->shader, name, val);
|
||||
#define GPU_batch_uniform_2fv_array(batch, name, len, val) \
|
||||
GPU_shader_uniform_2fv_array((batch)->shader, name, len, val);
|
||||
#define GPU_batch_uniform_4fv_array(batch, name, len, val) \
|
||||
GPU_shader_uniform_4fv_array((batch)->shader, name, len, val);
|
||||
#define GPU_batch_uniform_mat4(batch, name, val) \
|
||||
GPU_shader_uniform_mat4((batch)->shader, name, val);
|
||||
|
||||
void GPU_batch_draw(GPUBatch *batch);
|
||||
void GPU_batch_draw_range(GPUBatch *batch, int v_first, int v_count);
|
||||
|
|
|
@ -226,87 +226,6 @@ void GPU_batch_set_shader(GPUBatch *batch, GPUShader *shader)
|
|||
GPU_shader_bind(batch->shader);
|
||||
}
|
||||
|
||||
#define GET_UNIFORM \
|
||||
const GPUShaderInput *uniform = GPU_shaderinterface_uniform(batch->shader->interface, name); \
|
||||
BLI_assert(uniform);
|
||||
|
||||
void GPU_batch_uniform_1i(GPUBatch *batch, const char *name, int value)
|
||||
{
|
||||
GET_UNIFORM
|
||||
GPU_shader_uniform_int(batch->shader, uniform->location, value);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_1b(GPUBatch *batch, const char *name, bool value)
|
||||
{
|
||||
GPU_batch_uniform_1i(batch, name, value ? GL_TRUE : GL_FALSE);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_2f(GPUBatch *batch, const char *name, float x, float y)
|
||||
{
|
||||
const float data[2] = {x, y};
|
||||
GPU_batch_uniform_2fv(batch, name, data);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_3f(GPUBatch *batch, const char *name, float x, float y, float z)
|
||||
{
|
||||
const float data[3] = {x, y, z};
|
||||
GPU_batch_uniform_3fv(batch, name, data);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_4f(GPUBatch *batch, const char *name, float x, float y, float z, float w)
|
||||
{
|
||||
const float data[4] = {x, y, z, w};
|
||||
GPU_batch_uniform_4fv(batch, name, data);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_1f(GPUBatch *batch, const char *name, float x)
|
||||
{
|
||||
GET_UNIFORM
|
||||
GPU_shader_uniform_float(batch->shader, uniform->location, x);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_2fv(GPUBatch *batch, const char *name, const float data[2])
|
||||
{
|
||||
GET_UNIFORM
|
||||
GPU_shader_uniform_vector(batch->shader, uniform->location, 2, 1, data);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_3fv(GPUBatch *batch, const char *name, const float data[3])
|
||||
{
|
||||
GET_UNIFORM
|
||||
GPU_shader_uniform_vector(batch->shader, uniform->location, 3, 1, data);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_4fv(GPUBatch *batch, const char *name, const float data[4])
|
||||
{
|
||||
GET_UNIFORM
|
||||
GPU_shader_uniform_vector(batch->shader, uniform->location, 4, 1, data);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_2fv_array(GPUBatch *batch,
|
||||
const char *name,
|
||||
const int len,
|
||||
const float *data)
|
||||
{
|
||||
GET_UNIFORM
|
||||
GPU_shader_uniform_vector(batch->shader, uniform->location, 2, len, data);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_4fv_array(GPUBatch *batch,
|
||||
const char *name,
|
||||
const int len,
|
||||
const float *data)
|
||||
{
|
||||
GET_UNIFORM
|
||||
GPU_shader_uniform_vector(batch->shader, uniform->location, 4, len, data);
|
||||
}
|
||||
|
||||
void GPU_batch_uniform_mat4(GPUBatch *batch, const char *name, const float data[4][4])
|
||||
{
|
||||
GET_UNIFORM
|
||||
GPU_shader_uniform_vector(batch->shader, uniform->location, 16, 1, (const float *)data);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
|
Loading…
Reference in New Issue