Gawain: remove GLenum from IndexType API
Goal is to make most of the API independent of OpenGL, Vulkan, any other backend. Able to remove default case from ElementList_size because IndexType only covers index types. Not that and *everything else* like GLenum.
This commit is contained in:
parent
054eb9422c
commit
23035cf46f
Notes:
blender-bot
2023-02-14 05:36:11 +01:00
Referenced by commit 6cc293a6d9
, Gawain: replace switch with lookup table
|
@ -16,15 +16,16 @@
|
|||
#define TRACK_INDEX_RANGE 1
|
||||
|
||||
typedef enum {
|
||||
INDEX_U8 = GL_UNSIGNED_BYTE, // GL has this, Vulkan does not
|
||||
INDEX_U16 = GL_UNSIGNED_SHORT,
|
||||
INDEX_U32 = GL_UNSIGNED_INT
|
||||
INDEX_U8, // GL has this, Vulkan does not
|
||||
INDEX_U16,
|
||||
INDEX_U32
|
||||
} IndexType;
|
||||
|
||||
typedef struct {
|
||||
unsigned index_ct;
|
||||
#if TRACK_INDEX_RANGE
|
||||
IndexType index_type;
|
||||
GLenum gl_index_type;
|
||||
unsigned min_index;
|
||||
unsigned max_index;
|
||||
unsigned base_index;
|
||||
|
|
|
@ -273,9 +273,9 @@ void Batch_draw(Batch* batch)
|
|||
|
||||
#if TRACK_INDEX_RANGE
|
||||
if (el->base_index)
|
||||
glDrawRangeElementsBaseVertex(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0, el->base_index);
|
||||
glDrawRangeElementsBaseVertex(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->gl_index_type, 0, el->base_index);
|
||||
else
|
||||
glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0);
|
||||
glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->gl_index_type, 0);
|
||||
#else
|
||||
glDrawElements(batch->gl_prim_type, el->index_ct, GL_UNSIGNED_INT, 0);
|
||||
#endif
|
||||
|
@ -310,9 +310,9 @@ void Batch_draw_stupid(Batch* batch)
|
|||
|
||||
#if TRACK_INDEX_RANGE
|
||||
if (el->base_index)
|
||||
glDrawRangeElementsBaseVertex(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0, el->base_index);
|
||||
glDrawRangeElementsBaseVertex(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->gl_index_type, 0, el->base_index);
|
||||
else
|
||||
glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->index_type, 0);
|
||||
glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->gl_index_type, 0);
|
||||
#else
|
||||
glDrawElements(batch->gl_prim_type, el->index_ct, GL_UNSIGNED_INT, 0);
|
||||
#endif
|
||||
|
|
|
@ -15,6 +15,16 @@
|
|||
|
||||
#define KEEP_SINGLE_COPY 1
|
||||
|
||||
static GLenum convert_index_type_to_gl(IndexType type)
|
||||
{
|
||||
static const GLenum table[] = {
|
||||
[INDEX_U8] = GL_UNSIGNED_BYTE, // GL has this, Vulkan does not
|
||||
[INDEX_U16] = GL_UNSIGNED_SHORT,
|
||||
[INDEX_U32] = GL_UNSIGNED_INT
|
||||
};
|
||||
return table[type];
|
||||
}
|
||||
|
||||
unsigned ElementList_size(const ElementList* elem)
|
||||
{
|
||||
#if TRACK_INDEX_RANGE
|
||||
|
@ -23,11 +33,6 @@ unsigned ElementList_size(const ElementList* elem)
|
|||
case INDEX_U8: return elem->index_ct * sizeof(GLubyte);
|
||||
case INDEX_U16: return elem->index_ct * sizeof(GLushort);
|
||||
case INDEX_U32: return elem->index_ct * sizeof(GLuint);
|
||||
default:
|
||||
#if TRUST_NO_ONE
|
||||
assert(false);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -252,6 +257,8 @@ void ElementList_build_in_place(ElementListBuilder* builder, ElementList* elem)
|
|||
|
||||
elem->data = builder->data;
|
||||
}
|
||||
|
||||
elem->gl_index_type = convert_index_type_to_gl(elem->index_type);
|
||||
#else
|
||||
if (builder->index_ct < builder->max_index_ct)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue