make deferred space triangles work
This commit is contained in:
parent
a7b09b9f39
commit
c49789f1f4
@ -104,6 +104,9 @@ typedef struct {
|
|||||||
GLsizei element_count;
|
GLsizei element_count;
|
||||||
GLsizei range_start, range_end;
|
GLsizei range_start, range_end;
|
||||||
|
|
||||||
|
/* could be either `element_count` with supplied `element_buffer`, or this, but not both */
|
||||||
|
GLsizei primitive_count;
|
||||||
|
|
||||||
double depth_range_low, depth_range_high;
|
double depth_range_low, depth_range_high;
|
||||||
} DeferredCommandDraw;
|
} DeferredCommandDraw;
|
||||||
|
|
||||||
@ -228,8 +231,7 @@ static void issue_deferred_draw_commands(void) {
|
|||||||
/* TODO: don't assume a single vertex array ? */
|
/* TODO: don't assume a single vertex array ? */
|
||||||
SDL_assert(command.vertices.arity != 0);
|
SDL_assert(command.vertices.arity != 0);
|
||||||
SDL_assert(command.vertices.buffer);
|
SDL_assert(command.vertices.buffer);
|
||||||
SDL_assert(command.element_count != 0);
|
SDL_assert((command.element_buffer && command.element_count != 0) || command.primitive_count != 0);
|
||||||
SDL_assert(command.element_buffer);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, command.vertices.buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, command.vertices.buffer);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.element_buffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.element_buffer);
|
||||||
@ -274,15 +276,21 @@ static void issue_deferred_draw_commands(void) {
|
|||||||
textures_bind(&ctx.texture_cache, command.texture_key);
|
textures_bind(&ctx.texture_cache, command.texture_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.range_start == command.range_end)
|
if (command.element_buffer) {
|
||||||
glDrawElements(GL_TRIANGLES, command.element_count, GL_UNSIGNED_SHORT, NULL);
|
SDL_assert(command.element_count != 0);
|
||||||
else
|
if (command.range_start == command.range_end)
|
||||||
glDrawRangeElements(GL_TRIANGLES,
|
glDrawElements(GL_TRIANGLES, command.element_count, GL_UNSIGNED_SHORT, NULL);
|
||||||
command.range_start,
|
else
|
||||||
command.range_end,
|
glDrawRangeElements(GL_TRIANGLES,
|
||||||
command.element_count,
|
command.range_start,
|
||||||
GL_UNSIGNED_SHORT,
|
command.range_end,
|
||||||
NULL);
|
command.element_count,
|
||||||
|
GL_UNSIGNED_SHORT,
|
||||||
|
NULL);
|
||||||
|
} else {
|
||||||
|
SDL_assert(command.primitive_count != 0);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, command.primitive_count);
|
||||||
|
}
|
||||||
|
|
||||||
/* state clearing */
|
/* state clearing */
|
||||||
|
|
||||||
@ -735,37 +743,36 @@ void finally_draw_uncolored_space_traingle_batch(const MeshBatch *batch,
|
|||||||
const TextureKey texture_key,
|
const TextureKey texture_key,
|
||||||
const VertexBuffer buffer)
|
const VertexBuffer buffer)
|
||||||
{
|
{
|
||||||
const size_t primitives_len = arrlenu(batch->primitives);
|
DeferredCommandDraw command = {0};
|
||||||
|
|
||||||
textures_bind(&ctx.texture_cache, texture_key);
|
command.vertices = (AttributeArrayPointer) {
|
||||||
|
.arity = 3,
|
||||||
|
.type = GL_FLOAT,
|
||||||
|
.stride = offsetof(struct UncoloredSpaceTrianglePayload, v1),
|
||||||
|
.offset = offsetof(struct UncoloredSpaceTrianglePayload, v0),
|
||||||
|
.buffer = buffer
|
||||||
|
};
|
||||||
|
|
||||||
use_texture_mode(textures_get_mode(&ctx.texture_cache, texture_key));
|
command.texcoords = (AttributeArrayPointer) {
|
||||||
|
.arity = 2,
|
||||||
|
.type = GL_FLOAT,
|
||||||
|
.stride = offsetof(struct UncoloredSpaceTrianglePayload, v1),
|
||||||
|
.offset = offsetof(struct UncoloredSpaceTrianglePayload, uv0),
|
||||||
|
.buffer = buffer
|
||||||
|
};
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
command.textured = true;
|
||||||
|
command.texture_key = texture_key;
|
||||||
|
|
||||||
/* vertex specification*/
|
const GLuint primitives_len = arrlenu(batch->primitives);
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
command.primitive_count = 3 * primitives_len;
|
||||||
glVertexPointer(3,
|
|
||||||
GL_FLOAT,
|
|
||||||
offsetof(struct UncoloredSpaceTrianglePayload, v1),
|
|
||||||
(void *)offsetof(struct UncoloredSpaceTrianglePayload, v0));
|
|
||||||
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
DeferredCommand final_command = {
|
||||||
glClientActiveTexture(GL_TEXTURE0);
|
.type = DEFERRED_COMMAND_TYPE_DRAW,
|
||||||
glTexCoordPointer(2,
|
.draw = command
|
||||||
GL_FLOAT,
|
};
|
||||||
offsetof(struct UncoloredSpaceTrianglePayload, v1),
|
|
||||||
(void *)offsetof(struct UncoloredSpaceTrianglePayload, uv0));
|
|
||||||
|
|
||||||
/* commit for drawing */
|
arrpush(deferred_commands, final_command);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3 * (GLint)primitives_len);
|
|
||||||
|
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
|
||||||
|
|
||||||
/* invalidate the buffer immediately */
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, 0, NULL, GL_STREAM_DRAW);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user