diff options
Diffstat (limited to 'src/ral')
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.c | 14 | ||||
-rw-r--r-- | src/ral/backends/opengl/opengl_helpers.h | 13 | ||||
-rw-r--r-- | src/ral/ral_impl.h | 7 | ||||
-rw-r--r-- | src/ral/ral_types.h | 11 |
4 files changed, 41 insertions, 4 deletions
diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c index 3822220..613d7e1 100644 --- a/src/ral/backends/opengl/backend_opengl.c +++ b/src/ral/backends/opengl/backend_opengl.c @@ -411,11 +411,21 @@ void GPU_EncodeSetIndexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf) { GPU_Buffer* buffer = BUFFER_GET(buf); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer->id.ibo); } -void GPU_EncodeDraw(GPU_CmdEncoder* encoder, u64 count) { glDrawArrays(GL_TRIANGLES, 0, count); } -void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, u64 index_count) { +void GPU_EncodeDrawTris(GPU_CmdEncoder* encoder, u64 count) { + glDrawArrays(GL_TRIANGLES, 0, count); +} +void GPU_EncodeDrawIndexedTris(GPU_CmdEncoder* encoder, u64 index_count) { glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_INT, 0); } +PUB void GPU_EncodeDraw(GPU_CmdEncoder* encoder, PrimitiveTopology topology, u64 count) { + glDrawArrays(opengl_prim_topology(topology), 0, count); +} +PUB void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, PrimitiveTopology topology, + u64 index_count) { + glDrawElements(opengl_prim_topology(topology), index_count, GL_UNSIGNED_INT, 0); +} + PUB void GPU_WriteTextureRegion(GPU_CmdEncoder* encoder, TextureHandle dst, u32 x_offset, u32 y_offset, u32 width, u32 height, const void* data) { CASSERT_MSG(data, "const void* data must not be NULL"); diff --git a/src/ral/backends/opengl/opengl_helpers.h b/src/ral/backends/opengl/opengl_helpers.h index 8a78de5..b73eaea 100644 --- a/src/ral/backends/opengl/opengl_helpers.h +++ b/src/ral/backends/opengl/opengl_helpers.h @@ -138,4 +138,17 @@ static GLenum opengl_tex_type(GPU_TextureType tex_type) { } } +static GLenum opengl_prim_topology(PrimitiveTopology t) { + switch (t) { + case CEL_POINT: return GL_POINT; + case CEL_LINE: return GL_LINES; + case CEL_LINE_STRIP: return GL_LINE_STRIP; + case CEL_TRI: return GL_TRIANGLES; + case CEL_TRI_STRIP: return GL_TRIANGLE_STRIP; + case PRIMITIVE_TOPOLOGY_COUNT: + WARN("Invalid PrimitiveTopology value"); + break; + } +} + #endif diff --git a/src/ral/ral_impl.h b/src/ral/ral_impl.h index 2ca75d6..3374d91 100644 --- a/src/ral/ral_impl.h +++ b/src/ral/ral_impl.h @@ -80,8 +80,11 @@ void GPU_EncodeSetDefaults(GPU_CmdEncoder* encoder); PUB void GPU_EncodeSetVertexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf); PUB void GPU_EncodeSetIndexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf); -PUB void GPU_EncodeDraw(GPU_CmdEncoder* encoder, u64 count); -PUB void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, u64 index_count); +PUB void GPU_EncodeDraw(GPU_CmdEncoder* encoder, PrimitiveTopology topology, u64 count); +PUB void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, PrimitiveTopology topology, u64 index_count); +// convenience versions of the above +PUB void GPU_EncodeDrawTris(GPU_CmdEncoder* encoder, u64 count); +PUB void GPU_EncodeDrawIndexedTris(GPU_CmdEncoder* encoder, u64 index_count); PUB void GPU_EncodeDrawInstanced(GPU_CmdEncoder* encoder, u64 index_count, u64 instance_count); // TODO: implement instanced rendering diff --git a/src/ral/ral_types.h b/src/ral/ral_types.h index e15e0f4..7c83af6 100644 --- a/src/ral/ral_types.h +++ b/src/ral/ral_types.h @@ -221,13 +221,24 @@ typedef void (*FN_BindShaderData)(ShaderDataLayout* layout, const void* data); // --- Miscellaneous +#define TOPOLOGY_SHORT_NAMES + typedef enum PrimitiveTopology { +#ifdef TOPOLOGY_SHORT_NAMES + CEL_POINT, + CEL_LINE, + CEL_LINE_STRIP, + CEL_TRI, + CEL_TRI_STRIP, + PRIMITIVE_TOPOLOGY_COUNT +#else PRIMITIVE_TOPOLOGY_POINT, PRIMITIVE_TOPOLOGY_LINE, PRIMITIVE_TOPOLOGY_LINE_STRIP, PRIMITIVE_TOPOLOGY_TRIANGLE, PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, PRIMITIVE_TOPOLOGY_COUNT +#endif } PrimitiveTopology; typedef enum CullMode { CULL_BACK_FACE, CULL_FRONT_FACE, CULL_COUNT } CullMode; |