generalization of deferred commands and any_gl rendering where appropriate

This commit is contained in:
veclavtalica
2025-01-03 21:01:26 +03:00
parent edcb7fc39c
commit 33471b4c46
8 changed files with 347 additions and 321 deletions

View File

@ -1,4 +1,8 @@
#include "twn_gl_any_rendering_c.h"
#include "twn_draw_c.h"
#include "twn_engine_context_c.h"
#include <stb_ds.h>
#ifdef EMSCRIPTEN
#include <GLES2/gl2.h>
@ -84,3 +88,35 @@ VertexBuffer get_circle_element_buffer(void) {
return buffer;
}
/* potentially double buffered array of vertex array handles */
/* we assume they will be refilled fully each frame */
static size_t scratch_va_front_used, scratch_va_back_used;
static GLuint *front_scratch_vertex_arrays, *back_scratch_vertex_arrays;
static GLuint **current_scratch_vertex_array = &front_scratch_vertex_arrays;
void restart_scratch_vertex_arrays(void) {
scratch_va_front_used = 0;
scratch_va_back_used = 0;
if (ctx.render_double_buffered) {
current_scratch_vertex_array = current_scratch_vertex_array == &front_scratch_vertex_arrays ?
&back_scratch_vertex_arrays : &front_scratch_vertex_arrays;
}
}
GLuint get_scratch_vertex_array(void) {
size_t *used = current_scratch_vertex_array == &front_scratch_vertex_arrays ?
&scratch_va_front_used : &scratch_va_back_used;
if (arrlenu(*current_scratch_vertex_array) <= *used) {
GLuint handle;
glGenBuffers(1, &handle);
arrpush(*current_scratch_vertex_array, handle);
}
(*used)++;
return (*current_scratch_vertex_array)[*used - 1];
}