GPUBatch: Add draw parameter getter

This is used to populate indirect draw commands in the draw manager.
This commit is contained in:
2022-08-30 21:54:33 +02:00
parent fe195f51d1
commit b15f90bf85
3 changed files with 39 additions and 0 deletions

View File

@@ -164,6 +164,13 @@ void GPU_batch_program_set_builtin_with_config(GPUBatch *batch,
#define GPU_batch_texture_bind(batch, name, tex) \
GPU_texture_bind(tex, GPU_shader_get_texture_binding((batch)->shader, name));
/**
* Return indirect draw call parameters for this batch.
* NOTE: r_base_index is set to -1 if not using an index buffer.
*/
void GPU_batch_draw_parameter_get(
GPUBatch *batch, int *r_v_count, int *r_v_first, int *r_base_index, int *r_i_count);
void GPU_batch_draw(GPUBatch *batch);
void GPU_batch_draw_range(GPUBatch *batch, int v_first, int v_count);
/**

View File

@@ -220,6 +220,30 @@ void GPU_batch_set_shader(GPUBatch *batch, GPUShader *shader)
/** \name Drawing / Drawcall functions
* \{ */
void GPU_batch_draw_parameter_get(
GPUBatch *gpu_batch, int *r_v_count, int *r_v_first, int *r_base_index, int *r_i_count)
{
Batch *batch = static_cast<Batch *>(gpu_batch);
if (batch->elem) {
*r_v_count = batch->elem_()->index_len_get();
*r_v_first = batch->elem_()->index_start_get();
*r_base_index = batch->elem_()->index_base_get();
}
else {
*r_v_count = batch->verts_(0)->vertex_len;
*r_v_first = 0;
*r_base_index = -1;
}
int i_count = (batch->inst[0]) ? batch->inst_(0)->vertex_len : 1;
/* Meh. This is to be able to use different numbers of verts in instance VBO's. */
if (batch->inst[1] != nullptr) {
i_count = min_ii(i_count, batch->inst_(1)->vertex_len);
}
*r_i_count = i_count;
}
void GPU_batch_draw(GPUBatch *batch)
{
GPU_shader_bind(batch->shader);

View File

@@ -70,6 +70,14 @@ class IndexBuf {
* They can lead to graphical glitches on some systems. (See T96892) */
return is_empty_ ? 0 : index_len_;
}
uint32_t index_start_get() const
{
return index_start_;
}
uint32_t index_base_get() const
{
return index_base_;
}
/* Return size in byte of the drawable data buffer range. Actual buffer size might be bigger. */
size_t size_get() const
{