diff --git a/ref/vk/vk_render.c b/ref/vk/vk_render.c index fac7a981..8d7ccaad 100644 --- a/ref/vk/vk_render.c +++ b/ref/vk/vk_render.c @@ -828,7 +828,7 @@ static struct { vk_render_geometry_t geometries[MAX_DYNAMIC_GEOMETRY]; } g_dynamic_model = {0}; -void VK_RenderModelDynamicBegin( vk_render_type_e render_type, const vec4_t color, const matrix3x4 transform, const char *debug_name_fmt, ... ) { +static void VK_RenderModelDynamicBegin( vk_render_type_e render_type, const vec4_t color, const matrix3x4 transform, const char *debug_name_fmt, ... ) { va_list argptr; va_start( argptr, debug_name_fmt ); vsnprintf(g_dynamic_model.model.debug_name, sizeof(g_dynamic_model.model.debug_name), debug_name_fmt, argptr ); @@ -844,7 +844,7 @@ void VK_RenderModelDynamicBegin( vk_render_type_e render_type, const vec4_t colo if (transform) Matrix3x4_Copy(g_dynamic_model.transform, transform); } -void VK_RenderModelDynamicAddGeometry( const vk_render_geometry_t *geom ) { +static void VK_RenderModelDynamicAddGeometry( const vk_render_geometry_t *geom ) { ASSERT(g_dynamic_model.model.geometries); if (g_dynamic_model.model.num_geometries == MAX_DYNAMIC_GEOMETRY) { ERROR_THROTTLED(10, "Ran out of dynamic model geometry slots for model %s", g_dynamic_model.model.debug_name); @@ -853,7 +853,7 @@ void VK_RenderModelDynamicAddGeometry( const vk_render_geometry_t *geom ) { g_dynamic_model.geometries[g_dynamic_model.model.num_geometries++] = *geom; } -void VK_RenderModelDynamicCommit( void ) { +static void VK_RenderModelDynamicCommit( void ) { ASSERT(g_dynamic_model.model.geometries); if (g_dynamic_model.model.num_geometries > 0) { @@ -867,3 +867,35 @@ void VK_RenderModelDynamicCommit( void ) { g_dynamic_model.model.debug_name[0] = '\0'; g_dynamic_model.model.geometries = NULL; } + +void R_RenderDrawOnce(r_draw_once_t args) { + r_geometry_buffer_lock_t buffer; + if (!R_GeometryBufferAllocOnceAndLock( &buffer, args.vertices_count, args.indices_count)) { + gEngine.Con_Printf(S_ERROR "Cannot allocate geometry for dynamic draw\n"); + return; + } + + memcpy(buffer.vertices.ptr, args.vertices, sizeof(vk_vertex_t) * args.vertices_count); + memcpy(buffer.indices.ptr, args.indices, sizeof(uint16_t) * args.indices_count); + + R_GeometryBufferUnlock( &buffer ); + + { + const vk_render_geometry_t geometry = { + .texture = args.texture, + .material = kXVkMaterialRegular, + + .max_vertex = args.vertices_count, + .vertex_offset = buffer.vertices.unit_offset, + + .element_count = args.indices_count, + .index_offset = buffer.indices.unit_offset, + + .emissive = { (*args.color)[0], (*args.color)[1], (*args.color)[2] }, + }; + + VK_RenderModelDynamicBegin( args.render_type, *args.color, m_matrix4x4_identity, args.name ); + VK_RenderModelDynamicAddGeometry( &geometry ); + VK_RenderModelDynamicCommit(); + } +} diff --git a/ref/vk/vk_render.h b/ref/vk/vk_render.h index beb4f601..f67c52f5 100644 --- a/ref/vk/vk_render.h +++ b/ref/vk/vk_render.h @@ -169,10 +169,18 @@ typedef struct { void R_RenderModelDraw(const vk_render_model_t *model, r_model_draw_t args); -// TODO Begin and commit should be removed -void VK_RenderModelDynamicBegin( vk_render_type_e render_type, const vec4_t color, const matrix3x4 transform, const char *debug_name_fmt, ... ); -void VK_RenderModelDynamicAddGeometry( const vk_render_geometry_t *geom ); -void VK_RenderModelDynamicCommit( void ); +typedef struct { + const char *name; + const struct vk_vertex_s *vertices; + const uint16_t *indices; + int vertices_count, indices_count; + + int render_type; + int texture; + const vec4_t *emissive; + const vec4_t *color; +} r_draw_once_t; +void R_RenderDrawOnce(r_draw_once_t args); void VK_RenderDebugLabelBegin( const char *label ); void VK_RenderDebugLabelEnd( void ); diff --git a/ref/vk/vk_triapi.c b/ref/vk/vk_triapi.c index fae7e248..f5ac227a 100644 --- a/ref/vk/vk_triapi.c +++ b/ref/vk/vk_triapi.c @@ -136,41 +136,6 @@ static int genTriangleStripIndices(void) { return num_indices; } -static void emitDynamicGeometry(int num_indices, const vec4_t color, const char* name ) { - if (!num_indices) - return; - - r_geometry_buffer_lock_t buffer; - if (!R_GeometryBufferAllocOnceAndLock( &buffer, g_triapi.num_vertices, num_indices)) { - gEngine.Con_Printf(S_ERROR "Cannot allocate geometry for tri api\n"); - return; - } - - memcpy(buffer.vertices.ptr, g_triapi.vertices, sizeof(vk_vertex_t) * g_triapi.num_vertices); - memcpy(buffer.indices.ptr, g_triapi.indices, sizeof(uint16_t) * num_indices); - - R_GeometryBufferUnlock( &buffer ); - - { - const vk_render_geometry_t geometry = { - .texture = g_triapi.texture_index, - .material = kXVkMaterialRegular, - - .max_vertex = g_triapi.num_vertices, - .vertex_offset = buffer.vertices.unit_offset, - - .element_count = num_indices, - .index_offset = buffer.indices.unit_offset, - - .emissive = { color[0], color[1], color[2] }, - }; - - VK_RenderModelDynamicBegin( g_triapi.render_type, color, m_matrix4x4_identity, name ); - VK_RenderModelDynamicAddGeometry( &geometry ); - VK_RenderModelDynamicCommit(); - } -} - void TriEnd( void ) { if (!g_triapi.primitive_mode) return; @@ -196,7 +161,19 @@ void TriEndEx( const vec4_t color, const char* name ) { break; } - emitDynamicGeometry(num_indices, color, name); + if (num_indices) { + R_RenderDrawOnce((r_draw_once_t){ + .name = name, + .vertices = g_triapi.vertices, + .indices = g_triapi.indices, + .vertices_count = g_triapi.num_vertices, + .indices_count = num_indices, + .render_type = g_triapi.render_type, + .texture = g_triapi.texture_index, + .emissive = (const vec4_t*)color, + .color = (const vec4_t*)color, + }); + } g_triapi.num_vertices = 0; g_triapi.primitive_mode = 0;