diff options
Diffstat (limited to 'intern/gawain/src/vertex_format.c')
-rw-r--r-- | intern/gawain/src/vertex_format.c | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/intern/gawain/src/vertex_format.c b/intern/gawain/src/vertex_format.c index 963e660dc3d..139a76cf7ef 100644 --- a/intern/gawain/src/vertex_format.c +++ b/intern/gawain/src/vertex_format.c @@ -20,27 +20,27 @@ #include <stdio.h> #endif -void VertexFormat_clear(VertexFormat* format) +void GWN_vertformat_clear(Gwn_VertFormat* format) { #if TRUST_NO_ONE - memset(format, 0, sizeof(VertexFormat)); + memset(format, 0, sizeof(Gwn_VertFormat)); #else format->attrib_ct = 0; format->packed = false; format->name_offset = 0; format->name_ct = 0; - for (unsigned i = 0; i < MAX_VERTEX_ATTRIBS; i++) + for (unsigned i = 0; i < GWN_VERT_ATTR_MAX_LEN; i++) { format->attribs[i].name_ct = 0; } #endif } -void VertexFormat_copy(VertexFormat* dest, const VertexFormat* src) +void GWN_vertformat_copy(Gwn_VertFormat* dest, const Gwn_VertFormat* src) { // copy regular struct fields - memcpy(dest, src, sizeof(VertexFormat)); + memcpy(dest, src, sizeof(Gwn_VertFormat)); for (unsigned i = 0; i < dest->attrib_ct; i++) { @@ -52,44 +52,44 @@ void VertexFormat_copy(VertexFormat* dest, const VertexFormat* src) } } -static GLenum convert_comp_type_to_gl(VertexCompType type) +static GLenum convert_comp_type_to_gl(Gwn_VertCompType 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, + [GWN_COMP_I8] = GL_BYTE, + [GWN_COMP_U8] = GL_UNSIGNED_BYTE, + [GWN_COMP_I16] = GL_SHORT, + [GWN_COMP_U16] = GL_UNSIGNED_SHORT, + [GWN_COMP_I32] = GL_INT, + [GWN_COMP_U32] = GL_UNSIGNED_INT, - [COMP_F32] = GL_FLOAT, + [GWN_COMP_F32] = GL_FLOAT, - [COMP_I10] = GL_INT_2_10_10_10_REV + [GWN_COMP_I10] = GL_INT_2_10_10_10_REV }; return table[type]; } -static unsigned comp_sz(VertexCompType type) +static unsigned comp_sz(Gwn_VertCompType type) { #if TRUST_NO_ONE - assert(type <= COMP_F32); // other types have irregular sizes (not bytes) + assert(type <= GWN_COMP_F32); // other types have irregular sizes (not bytes) #endif const GLubyte sizes[] = {1,1,2,2,4,4,4}; return sizes[type]; } -static unsigned attrib_sz(const Attrib *a) +static unsigned attrib_sz(const Gwn_VertAttr *a) { - if (a->comp_type == COMP_I10) + if (a->comp_type == GWN_COMP_I10) return 4; // always packed as 10_10_10_2 return a->comp_ct * comp_sz(a->comp_type); } -static unsigned attrib_align(const Attrib *a) +static unsigned attrib_align(const Gwn_VertAttr *a) { - if (a->comp_type == COMP_I10) + if (a->comp_type == GWN_COMP_I10) return 4; // always packed as 10_10_10_2 unsigned c = comp_sz(a->comp_type); @@ -99,7 +99,7 @@ static unsigned attrib_align(const Attrib *a) return c; // most fetches are ok if components are naturally aligned } -unsigned vertex_buffer_size(const VertexFormat* format, unsigned vertex_ct) +unsigned vertex_buffer_size(const Gwn_VertFormat* format, unsigned vertex_ct) { #if TRUST_NO_ONE assert(format->packed && format->stride > 0); @@ -108,11 +108,11 @@ unsigned vertex_buffer_size(const VertexFormat* format, unsigned vertex_ct) return format->stride * vertex_ct; } -static const char* copy_attrib_name(VertexFormat* format, const char* name) +static const char* copy_attrib_name(Gwn_VertFormat* format, const char* name) { // strncpy does 110% of what we need; let's do exactly 100% char* name_copy = format->names + format->name_offset; - unsigned available = VERTEX_ATTRIB_NAMES_BUFFER_LEN - format->name_offset; + unsigned available = GWN_VERT_ATTR_NAMES_BUF_LEN - format->name_offset; bool terminated = false; for (unsigned i = 0; i < available; ++i) @@ -129,7 +129,7 @@ static const char* copy_attrib_name(VertexFormat* format, const char* name) #if TRUST_NO_ONE assert(terminated); - assert(format->name_offset <= VERTEX_ATTRIB_NAMES_BUFFER_LEN); + assert(format->name_offset <= GWN_VERT_ATTR_NAMES_BUF_LEN); #else (void)terminated; #endif @@ -137,39 +137,39 @@ static const char* copy_attrib_name(VertexFormat* format, const char* name) return name_copy; } -unsigned VertexFormat_add_attrib(VertexFormat* format, const char* name, VertexCompType comp_type, unsigned comp_ct, VertexFetchMode fetch_mode) +unsigned GWN_vertformat_attr_add(Gwn_VertFormat* format, const char* name, Gwn_VertCompType comp_type, unsigned comp_ct, Gwn_VertFetchMode fetch_mode) { #if TRUST_NO_ONE - assert(format->name_ct < MAX_VERTEX_ATTRIBS); // there's room for more - assert(format->attrib_ct < MAX_VERTEX_ATTRIBS); // there's room for more + assert(format->name_ct < GWN_VERT_ATTR_MAX_LEN); // there's room for more + assert(format->attrib_ct < GWN_VERT_ATTR_MAX_LEN); // there's room for more assert(!format->packed); // packed means frozen/locked assert(comp_ct >= 1 && comp_ct <= 4); switch (comp_type) { - case COMP_F32: + case GWN_COMP_F32: // float type can only kept as float - assert(fetch_mode == KEEP_FLOAT); + assert(fetch_mode == GWN_FETCH_FLOAT); break; - case COMP_I10: + case GWN_COMP_I10: // 10_10_10 format intended for normals (xyz) or colors (rgb) // extra component packed.w can be manually set to { -2, -1, 0, 1 } assert(comp_ct == 3 || comp_ct == 4); - assert(fetch_mode == NORMALIZE_INT_TO_FLOAT); // not strictly required, may relax later + assert(fetch_mode == GWN_FETCH_INT_TO_FLOAT_UNIT); // not strictly required, may relax later break; default: // integer types can be kept as int or converted/normalized to float - assert(fetch_mode != KEEP_FLOAT); + assert(fetch_mode != GWN_FETCH_FLOAT); } #endif format->name_ct++; // multiname support const unsigned attrib_id = format->attrib_ct++; - Attrib* attrib = format->attribs + attrib_id; + Gwn_VertAttr* attrib = format->attribs + attrib_id; attrib->name[attrib->name_ct++] = copy_attrib_name(format, name); attrib->comp_type = comp_type; attrib->gl_comp_type = convert_comp_type_to_gl(comp_type); - 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 == GWN_COMP_I10) ? 4 : comp_ct; // system needs 10_10_10_2 to be 4 or BGRA attrib->sz = attrib_sz(attrib); attrib->offset = 0; // offsets & stride are calculated later (during pack) attrib->fetch_mode = fetch_mode; @@ -177,11 +177,11 @@ unsigned VertexFormat_add_attrib(VertexFormat* format, const char* name, VertexC return attrib_id; } -void VertexFormat_add_alias(VertexFormat* format, const char* alias) +void GWN_vertformat_alias_add(Gwn_VertFormat* format, const char* alias) { - Attrib* attrib = format->attribs + (format->attrib_ct - 1); + Gwn_VertAttr* attrib = format->attribs + (format->attrib_ct - 1); #if TRUST_NO_ONE - assert(format->name_ct < MAX_VERTEX_ATTRIBS); // there's room for more + assert(format->name_ct < GWN_VERT_ATTR_MAX_LEN); // there's room for more assert(attrib->name_ct < MAX_ATTRIB_NAMES); #endif format->name_ct++; // multiname support @@ -205,7 +205,7 @@ static void show_pack(unsigned a_idx, unsigned sz, unsigned pad) } #endif -void VertexFormat_pack(VertexFormat* format) +void VertexFormat_pack(Gwn_VertFormat* format) { // for now, attributes are packed in the order they were added, // making sure each attrib is naturally aligned (add padding where necessary) @@ -217,7 +217,7 @@ void VertexFormat_pack(VertexFormat* format) // realloc just enough to hold the final combo string. And just enough to // hold used attribs, not all 16. - Attrib* a0 = format->attribs + 0; + Gwn_VertAttr* a0 = format->attribs + 0; a0->offset = 0; unsigned offset = a0->sz; @@ -227,7 +227,7 @@ void VertexFormat_pack(VertexFormat* format) for (unsigned a_idx = 1; a_idx < format->attrib_ct; ++a_idx) { - Attrib* a = format->attribs + a_idx; + Gwn_VertAttr* a = format->attribs + a_idx; unsigned mid_padding = padding(offset, attrib_align(a)); offset += mid_padding; a->offset = offset; |