Gawain: remove GL enum from vertex format API
Callers now have to use Gawain's COMP enum to specify vertex attributes. This makes the API more bullet-proof (at least less vulnerable) since GLenum covers waaay more than component types. Also prepares us for Vulkan.
This commit is contained in:
@@ -22,17 +22,17 @@
|
|||||||
// ^-- this is only guaranteed on Windows right now, will be true on all platforms soon
|
// ^-- this is only guaranteed on Windows right now, will be true on all platforms soon
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
COMP_I8 = GL_BYTE,
|
COMP_I8,
|
||||||
COMP_U8 = GL_UNSIGNED_BYTE,
|
COMP_U8,
|
||||||
COMP_I16 = GL_SHORT,
|
COMP_I16,
|
||||||
COMP_U16 = GL_UNSIGNED_SHORT,
|
COMP_U16,
|
||||||
COMP_I32 = GL_INT,
|
COMP_I32,
|
||||||
COMP_U32 = GL_UNSIGNED_INT,
|
COMP_U32,
|
||||||
|
|
||||||
COMP_F32 = GL_FLOAT, // TODO: drop the GL_ equivalence here, use a private lookup table
|
COMP_F32,
|
||||||
|
|
||||||
#if USE_10_10_10
|
#if USE_10_10_10
|
||||||
COMP_I10 = GL_INT_2_10_10_10_REV
|
COMP_I10
|
||||||
#endif
|
#endif
|
||||||
} VertexCompType;
|
} VertexCompType;
|
||||||
|
|
||||||
@@ -45,6 +45,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
VertexCompType comp_type;
|
VertexCompType comp_type;
|
||||||
|
unsigned gl_comp_type;
|
||||||
unsigned comp_ct; // 1 to 4
|
unsigned comp_ct; // 1 to 4
|
||||||
unsigned sz; // size in bytes, 1 to 16
|
unsigned sz; // size in bytes, 1 to 16
|
||||||
unsigned offset; // from beginning of vertex, in bytes
|
unsigned offset; // from beginning of vertex, in bytes
|
||||||
|
@@ -137,13 +137,13 @@ static void Batch_update_program_bindings(Batch* batch)
|
|||||||
{
|
{
|
||||||
case KEEP_FLOAT:
|
case KEEP_FLOAT:
|
||||||
case CONVERT_INT_TO_FLOAT:
|
case CONVERT_INT_TO_FLOAT:
|
||||||
glVertexAttribPointer(loc, a->comp_ct, a->comp_type, GL_FALSE, stride, pointer);
|
glVertexAttribPointer(loc, a->comp_ct, a->gl_comp_type, GL_FALSE, stride, pointer);
|
||||||
break;
|
break;
|
||||||
case NORMALIZE_INT_TO_FLOAT:
|
case NORMALIZE_INT_TO_FLOAT:
|
||||||
glVertexAttribPointer(loc, a->comp_ct, a->comp_type, GL_TRUE, stride, pointer);
|
glVertexAttribPointer(loc, a->comp_ct, a->gl_comp_type, GL_TRUE, stride, pointer);
|
||||||
break;
|
break;
|
||||||
case KEEP_INT:
|
case KEEP_INT:
|
||||||
glVertexAttribIPointer(loc, a->comp_ct, a->comp_type, stride, pointer);
|
glVertexAttribIPointer(loc, a->comp_ct, a->gl_comp_type, stride, pointer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -329,13 +329,13 @@ static void immDrawSetup(void)
|
|||||||
{
|
{
|
||||||
case KEEP_FLOAT:
|
case KEEP_FLOAT:
|
||||||
case CONVERT_INT_TO_FLOAT:
|
case CONVERT_INT_TO_FLOAT:
|
||||||
glVertexAttribPointer(loc, a->comp_ct, a->comp_type, GL_FALSE, stride, pointer);
|
glVertexAttribPointer(loc, a->comp_ct, a->gl_comp_type, GL_FALSE, stride, pointer);
|
||||||
break;
|
break;
|
||||||
case NORMALIZE_INT_TO_FLOAT:
|
case NORMALIZE_INT_TO_FLOAT:
|
||||||
glVertexAttribPointer(loc, a->comp_ct, a->comp_type, GL_TRUE, stride, pointer);
|
glVertexAttribPointer(loc, a->comp_ct, a->gl_comp_type, GL_TRUE, stride, pointer);
|
||||||
break;
|
break;
|
||||||
case KEEP_INT:
|
case KEEP_INT:
|
||||||
glVertexAttribIPointer(loc, a->comp_ct, a->comp_type, stride, pointer);
|
glVertexAttribIPointer(loc, a->comp_ct, a->gl_comp_type, stride, pointer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,14 +36,33 @@ void VertexFormat_copy(VertexFormat* dest, const VertexFormat* src)
|
|||||||
memcpy(dest, src, sizeof(VertexFormat));
|
memcpy(dest, src, sizeof(VertexFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GLenum convert_comp_type_to_gl(VertexCompType type)
|
||||||
|
{
|
||||||
|
static const GLenum table[] = {
|
||||||
|
[COMP_I8] = GL_BYTE,
|
||||||
|
[COMP_U8] = GL_UNSIGNED_BYTE,
|
||||||
|
[COMP_I16] = GL_SHORT,
|
||||||
|
[COMP_U16] = GL_UNSIGNED_SHORT,
|
||||||
|
[COMP_I32] = GL_INT,
|
||||||
|
[COMP_U32] = GL_UNSIGNED_INT,
|
||||||
|
|
||||||
|
[COMP_F32] = GL_FLOAT,
|
||||||
|
|
||||||
|
#if USE_10_10_10
|
||||||
|
[COMP_I10] = GL_INT_2_10_10_10_REV
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
return table[type];
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned comp_sz(VertexCompType type)
|
static unsigned comp_sz(VertexCompType type)
|
||||||
{
|
{
|
||||||
#if TRUST_NO_ONE
|
#if TRUST_NO_ONE
|
||||||
assert(type >= GL_BYTE && type <= GL_FLOAT);
|
assert(type <= COMP_F32); // other types have irregular sizes (not bytes)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const GLubyte sizes[] = {1,1,2,2,4,4,4};
|
const GLubyte sizes[] = {1,1,2,2,4,4,4};
|
||||||
return sizes[type - GL_BYTE];
|
return sizes[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned attrib_sz(const Attrib *a)
|
static unsigned attrib_sz(const Attrib *a)
|
||||||
@@ -137,6 +156,7 @@ unsigned VertexFormat_add_attrib(VertexFormat* format, const char* name, VertexC
|
|||||||
|
|
||||||
attrib->name = copy_attrib_name(format, name);
|
attrib->name = copy_attrib_name(format, name);
|
||||||
attrib->comp_type = comp_type;
|
attrib->comp_type = comp_type;
|
||||||
|
attrib->gl_comp_type = convert_comp_type_to_gl(comp_type);
|
||||||
#if USE_10_10_10
|
#if USE_10_10_10
|
||||||
attrib->comp_ct = (comp_type == COMP_I10) ? 4 : comp_ct; // system needs 10_10_10_2 to be 4 or BGRA
|
attrib->comp_ct = (comp_type == COMP_I10) ? 4 : comp_ct; // system needs 10_10_10_2 to be 4 or BGRA
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user