work towards DeferredCommandDraw being universal, support for DeferredCommandDepthRange, rework of cirlce mesh (has a bug still), get_quad_element_buffer() now more general, as it should be with gl_any

This commit is contained in:
2024-10-17 21:01:35 +03:00
parent aa3cab87d2
commit 7e409fc14a
5 changed files with 174 additions and 146 deletions

View File

@ -33,40 +33,59 @@ void specify_vertex_buffer(VertexBuffer buffer, void const *data, size_t bytes)
VertexBuffer get_quad_element_buffer(void) {
static GLuint buffer = 0;
static VertexBuffer buffer = 0;
/* it's only generated once at runtime */
/* TODO: use builder interface, not direct calls (glMapBuffer isn't portable) */
if (buffer == 0) {
glGenBuffers(1, &buffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
QUAD_ELEMENT_BUFFER_LENGTH * 6 * sizeof(uint16_t),
NULL,
GL_STATIC_DRAW);
buffer = create_vertex_buffer();
VertexBufferBuilder builder = build_vertex_buffer(buffer, sizeof (GLshort) * QUAD_ELEMENT_BUFFER_LENGTH * 6 );
uint16_t *const indices = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER,
GL_WRITE_ONLY);
if (!indices)
CRY("Quad indices generation", "glMapBuffer() failed");
for (size_t i = 0; i < QUAD_ELEMENT_BUFFER_LENGTH; ++i) {
GLshort indices[6];
indices[0] = (GLshort)(i * 4 + 0);
indices[1] = (GLshort)(i * 4 + 1);
indices[2] = (GLshort)(i * 4 + 2);
indices[3] = (GLshort)(i * 4 + 2);
indices[4] = (GLshort)(i * 4 + 3);
indices[5] = (GLshort)(i * 4 + 0);
for (uint16_t i = 0; i < QUAD_ELEMENT_BUFFER_LENGTH; ++i) {
indices[i * 6 + 0] = (uint16_t)(i * 4 + 0);
indices[i * 6 + 1] = (uint16_t)(i * 4 + 1);
indices[i * 6 + 2] = (uint16_t)(i * 4 + 2);
indices[i * 6 + 3] = (uint16_t)(i * 4 + 2);
indices[i * 6 + 4] = (uint16_t)(i * 4 + 3);
indices[i * 6 + 5] = (uint16_t)(i * 4 + 0);
push_to_vertex_buffer_builder(&builder, indices, sizeof indices);
}
}
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
} else
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
SDL_assert_always(buffer);
return buffer;
}
void set_depth_range(double low, double high) {
glDepthRange(low, high);
VertexBuffer get_circle_element_buffer(void) {
static VertexBuffer buffer = 0;
if (buffer == 0) {
buffer = create_vertex_buffer();
VertexBufferBuilder builder = build_vertex_buffer(buffer, sizeof (GLshort) * CIRCLE_ELEMENT_BUFFER_LENGTH);
for (size_t i = 1; i < CIRCLE_VERTICES_MAX; ++i) {
/* first one is center point index, always zero */
GLshort indices[3];
indices[0] = 0;
/* generated point index */
indices[1] = (GLshort)i;
size_t index = (i + 1) % (CIRCLE_VERTICES_MAX - 1);
if (index == 0) /* don't use center for outer ring */
index = (CIRCLE_VERTICES_MAX - 1);
indices[2] = (GLshort)index;
push_to_vertex_buffer_builder(&builder, indices, sizeof indices);
}
}
SDL_assert_always(buffer);
return buffer;
}