diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-06-19 13:18:04 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-06-19 13:18:04 +0300 |
commit | b4d053efc75424fca4b413ac1bc7a7e826fac629 (patch) | |
tree | 80647d9ca9109e997fce9911f202f98d7f8577d4 /intern/gawain | |
parent | 349946bd010b1112b13c8594aabfb318c330bc0d (diff) |
Gawain API naming refactor
Use consistent prefix for gawain API names as well as
some abbreviations to avoid over-long names, see: D2678
Diffstat (limited to 'intern/gawain')
22 files changed, 537 insertions, 537 deletions
diff --git a/intern/gawain/gawain/attrib_binding.h b/intern/gawain/gawain/attrib_binding.h index 8c372c81cc7..a254f05dc05 100644 --- a/intern/gawain/gawain/attrib_binding.h +++ b/intern/gawain/gawain/attrib_binding.h @@ -16,4 +16,4 @@ typedef struct { uint64_t loc_bits; // store 4 bits for each of the 16 attribs uint16_t enabled_bits; // 1 bit for each attrib -} AttribBinding; +} Gwn_AttrBinding; diff --git a/intern/gawain/gawain/attrib_binding_private.h b/intern/gawain/gawain/attrib_binding_private.h index c9b7a3f2c01..53fdecff9ce 100644 --- a/intern/gawain/gawain/attrib_binding_private.h +++ b/intern/gawain/gawain/attrib_binding_private.h @@ -14,7 +14,7 @@ #include "vertex_format.h" #include "shader_interface.h" -void AttribBinding_clear(AttribBinding*); +void AttribBinding_clear(Gwn_AttrBinding*); -void get_attrib_locations(const VertexFormat*, AttribBinding*, const ShaderInterface*); -unsigned read_attrib_location(const AttribBinding*, unsigned a_idx); +void get_attrib_locations(const Gwn_VertFormat*, Gwn_AttrBinding*, const Gwn_ShaderInterface*); +unsigned read_attrib_location(const Gwn_AttrBinding*, unsigned a_idx); diff --git a/intern/gawain/gawain/batch.h b/intern/gawain/gawain/batch.h index 33a1c1b653c..6e2f32c1996 100644 --- a/intern/gawain/gawain/batch.h +++ b/intern/gawain/gawain/batch.h @@ -16,64 +16,64 @@ #include "shader_interface.h" typedef enum { - READY_TO_FORMAT, - READY_TO_BUILD, - BUILDING, - READY_TO_DRAW -} BatchPhase; + GWN_BATCH_READY_TO_FORMAT, + GWN_BATCH_READY_TO_BUILD, + GWN_BATCH_BUILDING, + GWN_BATCH_READY_TO_DRAW +} Gwn_BatchPhase; -#define BATCH_MAX_VBO_CT 3 +#define GWN_BATCH_VBO_MAX_LEN 3 -typedef struct Batch { +typedef struct Gwn_Batch { // geometry - VertexBuffer* verts[BATCH_MAX_VBO_CT]; // verts[0] is required, others can be NULL - ElementList* elem; // NULL if element list not needed - PrimitiveType prim_type; + Gwn_VertBuf* verts[GWN_BATCH_VBO_MAX_LEN]; // verts[0] is required, others can be NULL + Gwn_IndexBuf* elem; // NULL if element list not needed + Gwn_PrimType prim_type; GLenum gl_prim_type; // book-keeping GLuint vao_id; // remembers all geometry state (vertex attrib bindings & element buffer) - BatchPhase phase; + Gwn_BatchPhase phase; bool program_dirty; bool program_in_use; // state GLuint program; - const ShaderInterface* interface; -} Batch; + const Gwn_ShaderInterface* interface; +} Gwn_Batch; -Batch* Batch_create(PrimitiveType, VertexBuffer*, ElementList*); -void Batch_init(Batch*, PrimitiveType, VertexBuffer*, ElementList*); +Gwn_Batch* GWN_batch_create(Gwn_PrimType, Gwn_VertBuf*, Gwn_IndexBuf*); +void GWN_batch_init(Gwn_Batch*, Gwn_PrimType, Gwn_VertBuf*, Gwn_IndexBuf*); -void Batch_discard(Batch*); // verts & elem are not discarded -void Batch_discard_all(Batch*); // including verts & elem +void GWN_batch_discard(Gwn_Batch*); // verts & elem are not discarded +void GWN_batch_discard_all(Gwn_Batch*); // including verts & elem -int Batch_add_VertexBuffer(Batch*, VertexBuffer*); +int GWN_batch_vertbuf_add(Gwn_Batch*, Gwn_VertBuf*); -void Batch_set_program(Batch*, GLuint program, const ShaderInterface*); +void GWN_batch_program_set(Gwn_Batch*, GLuint program, const Gwn_ShaderInterface*); // Entire batch draws with one shader program, but can be redrawn later with another program. // Vertex shader's inputs must be compatible with the batch's vertex format. -void Batch_use_program(Batch*); // call before Batch_Uniform (temp hack?) -void Batch_done_using_program(Batch*); +void GWN_batch_program_use_begin(Gwn_Batch*); // call before Batch_Uniform (temp hack?) +void GWN_batch_program_use_end(Gwn_Batch*); -void Batch_Uniform1i(Batch*, const char* name, int value); -void Batch_Uniform1b(Batch*, const char* name, bool value); -void Batch_Uniform1f(Batch*, const char* name, float value); -void Batch_Uniform2f(Batch*, const char* name, float x, float y); -void Batch_Uniform3f(Batch*, const char* name, float x, float y, float z); -void Batch_Uniform4f(Batch*, const char* name, float x, float y, float z, float w); -void Batch_Uniform3fv(Batch*, const char* name, const float data[3]); -void Batch_Uniform4fv(Batch*, const char* name, const float data[4]); +void GWN_batch_uniform_1i(Gwn_Batch*, const char* name, int value); +void GWN_batch_uniform_1b(Gwn_Batch*, const char* name, bool value); +void GWN_batch_uniform_1f(Gwn_Batch*, const char* name, float value); +void GWN_batch_uniform_2f(Gwn_Batch*, const char* name, float x, float y); +void GWN_batch_uniform_3f(Gwn_Batch*, const char* name, float x, float y, float z); +void GWN_batch_uniform_4f(Gwn_Batch*, const char* name, float x, float y, float z, float w); +void GWN_batch_uniform_3fv(Gwn_Batch*, const char* name, const float data[3]); +void GWN_batch_uniform_4fv(Gwn_Batch*, const char* name, const float data[4]); -void Batch_draw(Batch*); +void GWN_batch_draw(Gwn_Batch*); // clement : temp stuff -void Batch_draw_stupid(Batch*); -void Batch_draw_stupid_instanced(Batch*, unsigned int instance_vbo, int instance_count, +void GWN_batch_draw_stupid(Gwn_Batch*); +void GWN_batch_draw_stupid_instanced(Gwn_Batch*, unsigned int instance_vbo, int instance_count, int attrib_nbr, int attrib_stride, int attrib_loc[16], int attrib_size[16]); -void Batch_draw_stupid_instanced_with_batch(Batch*, Batch*); +void GWN_batch_draw_stupid_instanced_with_batch(Gwn_Batch*, Gwn_Batch*); @@ -81,49 +81,49 @@ void Batch_draw_stupid_instanced_with_batch(Batch*, Batch*); #if 0 // future plans -// Can multiple batches share a VertexBuffer? Use ref count? +// Can multiple batches share a Gwn_VertBuf? Use ref count? // We often need a batch with its own data, to be created and discarded together. // WithOwn variants reduce number of system allocations. typedef struct { - Batch batch; - VertexBuffer verts; // link batch.verts to this + Gwn_Batch batch; + Gwn_VertBuf verts; // link batch.verts to this } BatchWithOwnVertexBuffer; typedef struct { - Batch batch; - ElementList elem; // link batch.elem to this + Gwn_Batch batch; + Gwn_IndexBuf elem; // link batch.elem to this } BatchWithOwnElementList; typedef struct { - Batch batch; - ElementList elem; // link batch.elem to this - VertexBuffer verts; // link batch.verts to this + Gwn_Batch batch; + Gwn_IndexBuf elem; // link batch.elem to this + Gwn_VertBuf verts; // link batch.verts to this } BatchWithOwnVertexBufferAndElementList; -Batch* create_BatchWithOwnVertexBuffer(PrimitiveType, VertexFormat*, unsigned v_ct, ElementList*); -Batch* create_BatchWithOwnElementList(PrimitiveType, VertexBuffer*, unsigned prim_ct); -Batch* create_BatchWithOwnVertexBufferAndElementList(PrimitiveType, VertexFormat*, unsigned v_ct, unsigned prim_ct); +Gwn_Batch* create_BatchWithOwnVertexBuffer(Gwn_PrimType, Gwn_VertFormat*, unsigned v_ct, Gwn_IndexBuf*); +Gwn_Batch* create_BatchWithOwnElementList(Gwn_PrimType, Gwn_VertBuf*, unsigned prim_ct); +Gwn_Batch* create_BatchWithOwnVertexBufferAndElementList(Gwn_PrimType, Gwn_VertFormat*, unsigned v_ct, unsigned prim_ct); // verts: shared, own // elem: none, shared, own -Batch* create_BatchInGeneral(PrimitiveType, VertexBufferStuff, ElementListStuff); +Gwn_Batch* create_BatchInGeneral(Gwn_PrimType, VertexBufferStuff, ElementListStuff); #endif // future plans /* Macros */ -#define BATCH_DISCARD_SAFE(batch) do { \ +#define GWN_BATCH_DISCARD_SAFE(batch) do { \ if (batch != NULL) { \ - Batch_discard(batch); \ + GWN_batch_discard(batch); \ batch = NULL; \ } \ } while (0) #define BATCH_DISCARD_ALL_SAFE(batch) do { \ if (batch != NULL) { \ - Batch_discard_all(batch); \ + GWN_batch_discard_all(batch); \ batch = NULL; \ } \ } while (0) diff --git a/intern/gawain/gawain/buffer_id.h b/intern/gawain/gawain/buffer_id.h index 3f67458d060..e978eec67d8 100644 --- a/intern/gawain/gawain/buffer_id.h +++ b/intern/gawain/gawain/buffer_id.h @@ -22,11 +22,11 @@ extern "C" { #include "common.h" -GLuint buffer_id_alloc(void); -void buffer_id_free(GLuint buffer_id); +GLuint GWN_buf_id_alloc(void); +void GWN_buf_id_free(GLuint buffer_id); -GLuint vao_id_alloc(void); -void vao_id_free(GLuint vao_id); +GLuint GWN_vao_alloc(void); +void GWN_vao_free(GLuint vao_id); #ifdef __cplusplus diff --git a/intern/gawain/gawain/element.h b/intern/gawain/gawain/element.h index 0e2ece1d2f1..771462be7c5 100644 --- a/intern/gawain/gawain/element.h +++ b/intern/gawain/gawain/element.h @@ -13,18 +13,18 @@ #include "primitive.h" -#define TRACK_INDEX_RANGE 1 +#define GWN_TRACK_INDEX_RANGE 1 typedef enum { - INDEX_U8, // GL has this, Vulkan does not - INDEX_U16, - INDEX_U32 -} IndexType; + GWN_INDEX_U8, // GL has this, Vulkan does not + GWN_INDEX_U16, + GWN_INDEX_U32 +} Gwn_IndexBufType; typedef struct { unsigned index_ct; -#if TRACK_INDEX_RANGE - IndexType index_type; +#if GWN_TRACK_INDEX_RANGE + Gwn_IndexBufType index_type; GLenum gl_index_type; unsigned min_index; unsigned max_index; @@ -32,44 +32,44 @@ typedef struct { #endif void* data; // NULL indicates data in VRAM (unmapped) or not yet allocated GLuint vbo_id; // 0 indicates not yet sent to VRAM -} ElementList; +} Gwn_IndexBuf; -void ElementList_use(ElementList*); -unsigned ElementList_size(const ElementList*); +void GWN_indexbuf_use(Gwn_IndexBuf*); +unsigned GWN_indexbuf_size_get(const Gwn_IndexBuf*); typedef struct { unsigned max_allowed_index; unsigned max_index_ct; unsigned index_ct; - PrimitiveType prim_type; + Gwn_PrimType prim_type; unsigned* data; -} ElementListBuilder; +} Gwn_IndexBufBuilder; // supported primitives: -// PRIM_POINTS -// PRIM_LINES -// PRIM_TRIANGLES +// GWN_PRIM_POINTS +// GWN_PRIM_LINES +// GWN_PRIM_TRIS -void ElementListBuilder_init(ElementListBuilder*, PrimitiveType, unsigned prim_ct, unsigned vertex_ct); -//void ElementListBuilder_init_custom(ElementListBuilder*, PrimitiveType, unsigned index_ct, unsigned vertex_ct); +void GWN_indexbuf_init(Gwn_IndexBufBuilder*, Gwn_PrimType, unsigned prim_ct, unsigned vertex_ct); +//void GWN_indexbuf_init_custom(Gwn_IndexBufBuilder*, Gwn_PrimType, unsigned index_ct, unsigned vertex_ct); -void add_generic_vertex(ElementListBuilder*, unsigned v); +void GWN_indexbuf_add_generic_vert(Gwn_IndexBufBuilder*, unsigned v); -void add_point_vertex(ElementListBuilder*, unsigned v); -void add_line_vertices(ElementListBuilder*, unsigned v1, unsigned v2); -void add_triangle_vertices(ElementListBuilder*, unsigned v1, unsigned v2, unsigned v3); +void GWN_indexbuf_add_point_vert(Gwn_IndexBufBuilder*, unsigned v); +void GWN_indexbuf_add_line_verts(Gwn_IndexBufBuilder*, unsigned v1, unsigned v2); +void GWN_indexbuf_add_tri_verts(Gwn_IndexBufBuilder*, unsigned v1, unsigned v2, unsigned v3); -ElementList* ElementList_build(ElementListBuilder*); -void ElementList_build_in_place(ElementListBuilder*, ElementList*); +Gwn_IndexBuf* GWN_indexbuf_build(Gwn_IndexBufBuilder*); +void GWN_indexbuf_build_in_place(Gwn_IndexBufBuilder*, Gwn_IndexBuf*); -void ElementList_discard(ElementList*); +void GWN_indexbuf_discard(Gwn_IndexBuf*); /* Macros */ -#define ELEMENTLIST_DISCARD_SAFE(elem) do { \ +#define GWN_INDEXBUF_DISCARD_SAFE(elem) do { \ if (elem != NULL) { \ - ElementList_discard(elem); \ + GWN_indexbuf_discard(elem); \ elem = NULL; \ } \ } while (0) diff --git a/intern/gawain/gawain/immediate.h b/intern/gawain/gawain/immediate.h index 1f6ccc3a74b..39ba76db931 100644 --- a/intern/gawain/gawain/immediate.h +++ b/intern/gawain/gawain/immediate.h @@ -18,13 +18,13 @@ #define IMM_BATCH_COMBO 1 -VertexFormat* immVertexFormat(void); // returns a cleared vertex format, ready for add_attrib +Gwn_VertFormat* immVertexFormat(void); // returns a cleared vertex format, ready for add_attrib -void immBindProgram(GLuint program, const ShaderInterface*); // every immBegin must have a program bound first +void immBindProgram(GLuint program, const Gwn_ShaderInterface*); // every immBegin must have a program bound first void immUnbindProgram(void); // call after your last immEnd, or before binding another program -void immBegin(PrimitiveType, unsigned vertex_ct); // must supply exactly vertex_ct vertices -void immBeginAtMost(PrimitiveType, unsigned max_vertex_ct); // can supply fewer vertices +void immBegin(Gwn_PrimType, unsigned vertex_ct); // must supply exactly vertex_ct vertices +void immBeginAtMost(Gwn_PrimType, unsigned max_vertex_ct); // can supply fewer vertices void immEnd(void); // finishes and draws #if IMM_BATCH_COMBO @@ -32,8 +32,8 @@ void immEnd(void); // finishes and draws // immBegin a batch, then use standard immFunctions as usual. // immEnd will finalize the batch instead of drawing. // Then you can draw it as many times as you like! Partially replaces the need for display lists. -Batch* immBeginBatch(PrimitiveType, unsigned vertex_ct); -Batch* immBeginBatchAtMost(PrimitiveType, unsigned vertex_ct); +Gwn_Batch* immBeginBatch(Gwn_PrimType, unsigned vertex_ct); +Gwn_Batch* immBeginBatchAtMost(Gwn_PrimType, unsigned vertex_ct); #endif diff --git a/intern/gawain/gawain/primitive.h b/intern/gawain/gawain/primitive.h index 25e02ab09dd..c6786dc1993 100644 --- a/intern/gawain/gawain/primitive.h +++ b/intern/gawain/gawain/primitive.h @@ -14,27 +14,27 @@ #include "common.h" typedef enum { - PRIM_POINTS, - PRIM_LINES, - PRIM_TRIANGLES, - PRIM_LINE_STRIP, - PRIM_LINE_LOOP, // GL has this, Vulkan does not - PRIM_TRIANGLE_STRIP, - PRIM_TRIANGLE_FAN, + GWN_PRIM_POINTS, + GWN_PRIM_LINES, + GWN_PRIM_TRIS, + GWN_PRIM_LINE_STRIP, + GWN_PRIM_LINE_LOOP, // GL has this, Vulkan does not + GWN_PRIM_TRI_STRIP, + GWN_PRIM_TRI_FAN, - PRIM_LINE_STRIP_ADJACENCY, + GWN_PRIM_LINE_STRIP_ADJ, - PRIM_NONE -} PrimitiveType; + GWN_PRIM_NONE +} Gwn_PrimType; // what types of primitives does each shader expect? typedef enum { - PRIM_CLASS_NONE = 0, - PRIM_CLASS_POINT = (1 << 0), - PRIM_CLASS_LINE = (1 << 1), - PRIM_CLASS_SURFACE = (1 << 2), - PRIM_CLASS_ANY = PRIM_CLASS_POINT | PRIM_CLASS_LINE | PRIM_CLASS_SURFACE -} PrimitiveClass; - -PrimitiveClass prim_class_of_type(PrimitiveType); -bool prim_type_belongs_to_class(PrimitiveType, PrimitiveClass); + GWN_PRIM_CLASS_NONE = 0, + GWN_PRIM_CLASS_POINT = (1 << 0), + GWN_PRIM_CLASS_LINE = (1 << 1), + GWN_PRIM_CLASS_SURFACE = (1 << 2), + GWN_PRIM_CLASS_ANY = GWN_PRIM_CLASS_POINT | GWN_PRIM_CLASS_LINE | GWN_PRIM_CLASS_SURFACE +} Gwn_PrimClass; + +Gwn_PrimClass GWN_primtype_class(Gwn_PrimType); +bool GWN_primtype_belongs_to_class(Gwn_PrimType, Gwn_PrimClass); diff --git a/intern/gawain/gawain/primitive_private.h b/intern/gawain/gawain/primitive_private.h index e78433ef304..d959cd89852 100644 --- a/intern/gawain/gawain/primitive_private.h +++ b/intern/gawain/gawain/primitive_private.h @@ -11,4 +11,4 @@ #pragma once -GLenum convert_prim_type_to_gl(PrimitiveType); +GLenum convert_prim_type_to_gl(Gwn_PrimType); diff --git a/intern/gawain/gawain/shader_interface.h b/intern/gawain/gawain/shader_interface.h index cf10180e3d5..5304cc9fa51 100644 --- a/intern/gawain/gawain/shader_interface.h +++ b/intern/gawain/gawain/shader_interface.h @@ -14,40 +14,40 @@ #include "common.h" typedef enum { - UNIFORM_NONE, // uninitialized/unknown + GWN_UNIFORM_NONE, // uninitialized/unknown - UNIFORM_MODELVIEW, // mat4 ModelViewMatrix - UNIFORM_PROJECTION, // mat4 ProjectionMatrix - UNIFORM_MVP, // mat4 ModelViewProjectionMatrix + GWN_UNIFORM_MODELVIEW, // mat4 ModelViewMatrix + GWN_UNIFORM_PROJECTION, // mat4 ProjectionMatrix + GWN_UNIFORM_MVP, // mat4 ModelViewProjectionMatrix - UNIFORM_MODELVIEW_INV, // mat4 ModelViewInverseMatrix - UNIFORM_PROJECTION_INV, // mat4 ProjectionInverseMatrix + GWN_UNIFORM_MODELVIEW_INV, // mat4 ModelViewInverseMatrix + GWN_UNIFORM_PROJECTION_INV, // mat4 ProjectionInverseMatrix - UNIFORM_NORMAL, // mat3 NormalMatrix + GWN_UNIFORM_NORMAL, // mat3 NormalMatrix - UNIFORM_COLOR, // vec4 color + GWN_UNIFORM_COLOR, // vec4 color - UNIFORM_CUSTOM // custom uniform, not one of the above built-ins -} BuiltinUniform; + GWN_UNIFORM_CUSTOM // custom uniform, not one of the above built-ins +} Gwn_UniformBuiltin; typedef struct { const char* name; unsigned name_hash; GLenum gl_type; - BuiltinUniform builtin_type; // only for uniform inputs + Gwn_UniformBuiltin builtin_type; // only for uniform inputs GLint size; GLint location; -} ShaderInput; +} Gwn_ShaderInput; typedef struct { uint16_t uniform_ct; uint16_t attrib_ct; - ShaderInput inputs[0]; // dynamic size, uniforms followed by attribs -} ShaderInterface; + Gwn_ShaderInput inputs[0]; // dynamic size, uniforms followed by attribs +} Gwn_ShaderInterface; -ShaderInterface* ShaderInterface_create(GLint program_id); -void ShaderInterface_discard(ShaderInterface*); +Gwn_ShaderInterface* GWN_shaderinterface_create(GLint program_id); +void GWN_shaderinterface_discard(Gwn_ShaderInterface*); -const ShaderInput* ShaderInterface_uniform(const ShaderInterface*, const char* name); -const ShaderInput* ShaderInterface_builtin_uniform(const ShaderInterface*, BuiltinUniform); -const ShaderInput* ShaderInterface_attrib(const ShaderInterface*, const char* name); +const Gwn_ShaderInput* GWN_shaderinterface_uniform(const Gwn_ShaderInterface*, const char* name); +const Gwn_ShaderInput* GWN_shaderinterface_uniform_builtin(const Gwn_ShaderInterface*, Gwn_UniformBuiltin); +const Gwn_ShaderInput* GWN_shaderinterface_attr(const Gwn_ShaderInterface*, const char* name); diff --git a/intern/gawain/gawain/vertex_buffer.h b/intern/gawain/gawain/vertex_buffer.h index bc5518cc4fc..46f83f5c551 100644 --- a/intern/gawain/gawain/vertex_buffer.h +++ b/intern/gawain/gawain/vertex_buffer.h @@ -13,41 +13,41 @@ #include "vertex_format.h" -// How to create a VertexBuffer: -// 1) verts = VertexBuffer_create() or VertexBuffer_init(verts) -// 2) VertexFormat_add_attrib(verts->format, ...) -// 3) VertexBuffer_allocate_data(verts, vertex_ct) <-- finalizes/packs vertex format -// 4) VertexBuffer_fill_attrib(verts, pos, application_pos_buffer) +// How to create a Gwn_VertBuf: +// 1) verts = GWN_vertbuf_create() or GWN_vertbuf_init(verts) +// 2) GWN_vertformat_attr_add(verts->format, ...) +// 3) GWN_vertbuf_data_alloc(verts, vertex_ct) <-- finalizes/packs vertex format +// 4) GWN_vertbuf_attr_fill(verts, pos, application_pos_buffer) -// Is VertexBuffer always used as part of a Batch? +// Is Gwn_VertBuf always used as part of a Gwn_Batch? typedef struct { - VertexFormat format; + Gwn_VertFormat format; unsigned vertex_ct; GLubyte* data; // NULL indicates data in VRAM (unmapped) or not yet allocated GLuint vbo_id; // 0 indicates not yet sent to VRAM -} VertexBuffer; +} Gwn_VertBuf; -VertexBuffer* VertexBuffer_create(void); -VertexBuffer* VertexBuffer_create_with_format(const VertexFormat*); +Gwn_VertBuf* GWN_vertbuf_create(void); +Gwn_VertBuf* GWN_vertbuf_create_with_format(const Gwn_VertFormat*); -void VertexBuffer_discard(VertexBuffer*); +void GWN_vertbuf_discard(Gwn_VertBuf*); -void VertexBuffer_init(VertexBuffer*); -void VertexBuffer_init_with_format(VertexBuffer*, const VertexFormat*); +void GWN_vertbuf_init(Gwn_VertBuf*); +void GWN_vertbuf_init_with_format(Gwn_VertBuf*, const Gwn_VertFormat*); -unsigned VertexBuffer_size(const VertexBuffer*); -void VertexBuffer_allocate_data(VertexBuffer*, unsigned v_ct); -void VertexBuffer_resize_data(VertexBuffer*, unsigned v_ct); +unsigned GWN_vertbuf_size_get(const Gwn_VertBuf*); +void GWN_vertbuf_data_alloc(Gwn_VertBuf*, unsigned v_ct); +void GWN_vertbuf_data_resize(Gwn_VertBuf*, unsigned v_ct); // The most important set_attrib variant is the untyped one. Get it right first. // It takes a void* so the app developer is responsible for matching their app data types // to the vertex attribute's type and component count. They're in control of both, so this // should not be a problem. -void VertexBuffer_set_attrib(VertexBuffer*, unsigned a_idx, unsigned v_idx, const void* data); -void VertexBuffer_fill_attrib(VertexBuffer*, unsigned a_idx, const void* data); // tightly packed, non interleaved input data -void VertexBuffer_fill_attrib_stride(VertexBuffer*, unsigned a_idx, unsigned stride, const void* data); +void GWN_vertbuf_attr_set(Gwn_VertBuf*, unsigned a_idx, unsigned v_idx, const void* data); +void GWN_vertbuf_attr_fill(Gwn_VertBuf*, unsigned a_idx, const void* data); // tightly packed, non interleaved input data +void GWN_vertbuf_attr_fill_stride(Gwn_VertBuf*, unsigned a_idx, unsigned stride, const void* data); // TODO: decide whether to keep the functions below // doesn't immediate mode satisfy these needs? @@ -60,19 +60,19 @@ void VertexBuffer_fill_attrib_stride(VertexBuffer*, unsigned a_idx, unsigned str // void setAttrib3ub(unsigned a_idx, unsigned v_idx, unsigned char r, unsigned char g, unsigned char b); // void setAttrib4ub(unsigned a_idx, unsigned v_idx, unsigned char r, unsigned char g, unsigned char b, unsigned char a); -void VertexBuffer_use(VertexBuffer*); +void GWN_vertbuf_use(Gwn_VertBuf*); // Metrics -unsigned VertexBuffer_get_memory_usage(void); +unsigned GWN_vertbuf_get_memory_usage(void); // Macros -#define VERTEXBUFFER_DISCARD_SAFE(verts) do { \ +#define GWN_VERTBUF_DISCARD_SAFE(verts) do { \ if (verts != NULL) { \ - VertexBuffer_discard(verts); \ + GWN_vertbuf_discard(verts); \ verts = NULL; \ } \ } while (0) diff --git a/intern/gawain/gawain/vertex_format.h b/intern/gawain/gawain/vertex_format.h index b4cce0b930f..3b2a3be4209 100644 --- a/intern/gawain/gawain/vertex_format.h +++ b/intern/gawain/gawain/vertex_format.h @@ -13,57 +13,57 @@ #include "common.h" -#define MAX_VERTEX_ATTRIBS 16 +#define GWN_VERT_ATTR_MAX_LEN 16 #define MAX_ATTRIB_NAMES 3 -#define AVG_VERTEX_ATTRIB_NAME_LEN 11 -#define VERTEX_ATTRIB_NAMES_BUFFER_LEN ((AVG_VERTEX_ATTRIB_NAME_LEN + 1) * MAX_VERTEX_ATTRIBS) +#define GWN_VERT_ATTR_NAME_AVERAGE_LEN 11 +#define GWN_VERT_ATTR_NAMES_BUF_LEN ((GWN_VERT_ATTR_NAME_AVERAGE_LEN + 1) * GWN_VERT_ATTR_MAX_LEN) typedef enum { - COMP_I8, - COMP_U8, - COMP_I16, - COMP_U16, - COMP_I32, - COMP_U32, + GWN_COMP_I8, + GWN_COMP_U8, + GWN_COMP_I16, + GWN_COMP_U16, + GWN_COMP_I32, + GWN_COMP_U32, - COMP_F32, + GWN_COMP_F32, - COMP_I10 -} VertexCompType; + GWN_COMP_I10 +} Gwn_VertCompType; typedef enum { - KEEP_FLOAT, - KEEP_INT, - NORMALIZE_INT_TO_FLOAT, // 127 (ubyte) -> 0.5 (and so on for other int types) - CONVERT_INT_TO_FLOAT // 127 (any int type) -> 127.0 -} VertexFetchMode; + GWN_FETCH_FLOAT, + GWN_FETCH_INT, + GWN_FETCH_INT_TO_FLOAT_UNIT, // 127 (ubyte) -> 0.5 (and so on for other int types) + GWN_FETCH_INT_TO_FLOAT // 127 (any int type) -> 127.0 +} Gwn_VertFetchMode; typedef struct { - VertexCompType comp_type; + Gwn_VertCompType comp_type; unsigned gl_comp_type; unsigned comp_ct; // 1 to 4 unsigned sz; // size in bytes, 1 to 16 unsigned offset; // from beginning of vertex, in bytes - VertexFetchMode fetch_mode; + Gwn_VertFetchMode fetch_mode; const char* name[MAX_ATTRIB_NAMES]; unsigned name_ct; -} Attrib; +} Gwn_VertAttr; typedef struct { - unsigned attrib_ct; // 0 to 16 (MAX_VERTEX_ATTRIBS) + unsigned attrib_ct; // 0 to 16 (GWN_VERT_ATTR_MAX_LEN) unsigned name_ct; // total count of active vertex attrib unsigned stride; // stride in bytes, 1 to 256 bool packed; - Attrib attribs[MAX_VERTEX_ATTRIBS]; // TODO: variable-size attribs array - char names[VERTEX_ATTRIB_NAMES_BUFFER_LEN]; + Gwn_VertAttr attribs[GWN_VERT_ATTR_MAX_LEN]; // TODO: variable-size attribs array + char names[GWN_VERT_ATTR_NAMES_BUF_LEN]; unsigned name_offset; -} VertexFormat; +} Gwn_VertFormat; -void VertexFormat_clear(VertexFormat*); -void VertexFormat_copy(VertexFormat* dest, const VertexFormat* src); +void GWN_vertformat_clear(Gwn_VertFormat*); +void GWN_vertformat_copy(Gwn_VertFormat* dest, const Gwn_VertFormat* src); -unsigned VertexFormat_add_attrib(VertexFormat*, const char* name, VertexCompType, unsigned comp_ct, VertexFetchMode); -void VertexFormat_add_alias(VertexFormat*, const char* alias); +unsigned GWN_vertformat_attr_add(Gwn_VertFormat*, const char* name, Gwn_VertCompType, unsigned comp_ct, Gwn_VertFetchMode); +void GWN_vertformat_alias_add(Gwn_VertFormat*, const char* alias); // format conversion diff --git a/intern/gawain/gawain/vertex_format_private.h b/intern/gawain/gawain/vertex_format_private.h index c7f6f131339..c1a0f734eda 100644 --- a/intern/gawain/gawain/vertex_format_private.h +++ b/intern/gawain/gawain/vertex_format_private.h @@ -11,6 +11,6 @@ #pragma once -void VertexFormat_pack(VertexFormat*); +void VertexFormat_pack(Gwn_VertFormat*); unsigned padding(unsigned offset, unsigned alignment); -unsigned vertex_buffer_size(const VertexFormat*, unsigned vertex_ct); +unsigned vertex_buffer_size(const Gwn_VertFormat*, unsigned vertex_ct); diff --git a/intern/gawain/src/attrib_binding.c b/intern/gawain/src/attrib_binding.c index 57894fdc3cc..6cdb8a0e542 100644 --- a/intern/gawain/src/attrib_binding.c +++ b/intern/gawain/src/attrib_binding.c @@ -13,31 +13,31 @@ #include "attrib_binding_private.h" #include <stddef.h> -#if MAX_VERTEX_ATTRIBS != 16 - #error "attrib binding code assumes MAX_VERTEX_ATTRIBS = 16" +#if GWN_VERT_ATTR_MAX_LEN != 16 + #error "attrib binding code assumes GWN_VERT_ATTR_MAX_LEN = 16" #endif -void AttribBinding_clear(AttribBinding* binding) +void AttribBinding_clear(Gwn_AttrBinding* binding) { binding->loc_bits = 0; binding->enabled_bits = 0; } -unsigned read_attrib_location(const AttribBinding* binding, unsigned a_idx) +unsigned read_attrib_location(const Gwn_AttrBinding* binding, unsigned a_idx) { #if TRUST_NO_ONE - assert(a_idx < MAX_VERTEX_ATTRIBS); + assert(a_idx < GWN_VERT_ATTR_MAX_LEN); assert(binding->enabled_bits & (1 << a_idx)); #endif return (binding->loc_bits >> (4 * a_idx)) & 0xF; } -static void write_attrib_location(AttribBinding* binding, unsigned a_idx, unsigned location) +static void write_attrib_location(Gwn_AttrBinding* binding, unsigned a_idx, unsigned location) { #if TRUST_NO_ONE - assert(a_idx < MAX_VERTEX_ATTRIBS); - assert(location < MAX_VERTEX_ATTRIBS); + assert(a_idx < GWN_VERT_ATTR_MAX_LEN); + assert(location < GWN_VERT_ATTR_MAX_LEN); #endif const unsigned shift = 4 * a_idx; @@ -48,16 +48,16 @@ static void write_attrib_location(AttribBinding* binding, unsigned a_idx, unsign binding->enabled_bits |= 1 << a_idx; } -void get_attrib_locations(const VertexFormat* format, AttribBinding* binding, const ShaderInterface* shaderface) +void get_attrib_locations(const Gwn_VertFormat* format, Gwn_AttrBinding* binding, const Gwn_ShaderInterface* shaderface) { AttribBinding_clear(binding); for (unsigned a_idx = 0; a_idx < format->attrib_ct; ++a_idx) { - const Attrib* a = format->attribs + a_idx; + const Gwn_VertAttr* a = format->attribs + a_idx; for (unsigned n_idx = 0; n_idx < a->name_ct; ++n_idx) { - const ShaderInput* input = ShaderInterface_attrib(shaderface, a->name[n_idx]); + const Gwn_ShaderInput* input = GWN_shaderinterface_attr(shaderface, a->name[n_idx]); #if TRUST_NO_ONE assert(input != NULL); diff --git a/intern/gawain/src/batch.c b/intern/gawain/src/batch.c index a1e173f6685..17e45084613 100644 --- a/intern/gawain/src/batch.c +++ b/intern/gawain/src/batch.c @@ -15,59 +15,59 @@ #include <stdlib.h> // necessary functions from matrix API -extern void gpuBindMatrices(const ShaderInterface* shaderface); +extern void gpuBindMatrices(const Gwn_ShaderInterface* shaderface); extern bool gpuMatricesDirty(void); // how best to use this here? -Batch* Batch_create(PrimitiveType prim_type, VertexBuffer* verts, ElementList* elem) +Gwn_Batch* GWN_batch_create(Gwn_PrimType prim_type, Gwn_VertBuf* verts, Gwn_IndexBuf* elem) { - Batch* batch = calloc(1, sizeof(Batch)); + Gwn_Batch* batch = calloc(1, sizeof(Gwn_Batch)); - Batch_init(batch, prim_type, verts, elem); + GWN_batch_init(batch, prim_type, verts, elem); return batch; } -void Batch_init(Batch* batch, PrimitiveType prim_type, VertexBuffer* verts, ElementList* elem) +void GWN_batch_init(Gwn_Batch* batch, Gwn_PrimType prim_type, Gwn_VertBuf* verts, Gwn_IndexBuf* elem) { #if TRUST_NO_ONE assert(verts != NULL); #endif batch->verts[0] = verts; - for (int v = 1; v < BATCH_MAX_VBO_CT; ++v) + for (int v = 1; v < GWN_BATCH_VBO_MAX_LEN; ++v) batch->verts[v] = NULL; batch->elem = elem; batch->prim_type = prim_type; batch->gl_prim_type = convert_prim_type_to_gl(prim_type); - batch->phase = READY_TO_DRAW; + batch->phase = GWN_BATCH_READY_TO_DRAW; } -void Batch_discard(Batch* batch) +void GWN_batch_discard(Gwn_Batch* batch) { if (batch->vao_id) - vao_id_free(batch->vao_id); + GWN_vao_free(batch->vao_id); free(batch); } -void Batch_discard_all(Batch* batch) +void GWN_batch_discard_all(Gwn_Batch* batch) { - for (int v = 0; v < BATCH_MAX_VBO_CT; ++v) + for (int v = 0; v < GWN_BATCH_VBO_MAX_LEN; ++v) { if (batch->verts[v] == NULL) break; - VertexBuffer_discard(batch->verts[v]); + GWN_vertbuf_discard(batch->verts[v]); } if (batch->elem) - ElementList_discard(batch->elem); + GWN_indexbuf_discard(batch->elem); - Batch_discard(batch); + GWN_batch_discard(batch); } -int Batch_add_VertexBuffer(Batch* batch, VertexBuffer* verts) +int GWN_batch_vertbuf_add(Gwn_Batch* batch, Gwn_VertBuf* verts) { - for (unsigned v = 0; v < BATCH_MAX_VBO_CT; ++v) + for (unsigned v = 0; v < GWN_BATCH_VBO_MAX_LEN; ++v) { if (batch->verts[v] == NULL) { @@ -82,14 +82,14 @@ int Batch_add_VertexBuffer(Batch* batch, VertexBuffer* verts) } } - // we only make it this far if there is no room for another VertexBuffer + // we only make it this far if there is no room for another Gwn_VertBuf #if TRUST_NO_ONE assert(false); #endif return -1; } -void Batch_set_program(Batch* batch, GLuint program, const ShaderInterface* shaderface) +void GWN_batch_program_set(Gwn_Batch* batch, GLuint program, const Gwn_ShaderInterface* shaderface) { #if TRUST_NO_ONE assert(glIsProgram(program)); @@ -99,38 +99,38 @@ void Batch_set_program(Batch* batch, GLuint program, const ShaderInterface* shad batch->interface = shaderface; batch->program_dirty = true; - Batch_use_program(batch); // hack! to make Batch_Uniform* simpler + GWN_batch_program_use_begin(batch); // hack! to make Batch_Uniform* simpler } -static void Batch_update_program_bindings(Batch* batch) +static void Batch_update_program_bindings(Gwn_Batch* batch) { // disable all as a precaution // why are we not using prev_attrib_enabled_bits?? see immediate.c - for (unsigned a_idx = 0; a_idx < MAX_VERTEX_ATTRIBS; ++a_idx) + for (unsigned a_idx = 0; a_idx < GWN_VERT_ATTR_MAX_LEN; ++a_idx) glDisableVertexAttribArray(a_idx); - for (int v = 0; v < BATCH_MAX_VBO_CT; ++v) + for (int v = 0; v < GWN_BATCH_VBO_MAX_LEN; ++v) { - VertexBuffer* verts = batch->verts[v]; + Gwn_VertBuf* verts = batch->verts[v]; if (verts == NULL) break; - const VertexFormat* format = &verts->format; + const Gwn_VertFormat* format = &verts->format; const unsigned attrib_ct = format->attrib_ct; const unsigned stride = format->stride; - VertexBuffer_use(verts); + GWN_vertbuf_use(verts); for (unsigned a_idx = 0; a_idx < attrib_ct; ++a_idx) { - const Attrib* a = format->attribs + a_idx; + const Gwn_VertAttr* a = format->attribs + a_idx; const GLvoid* pointer = (const GLubyte*)0 + a->offset; for (unsigned n_idx = 0; n_idx < a->name_ct; ++n_idx) { - const ShaderInput* input = ShaderInterface_attrib(batch->interface, a->name[n_idx]); + const Gwn_ShaderInput* input = GWN_shaderinterface_attr(batch->interface, a->name[n_idx]); if (input == NULL) continue; @@ -138,14 +138,14 @@ static void Batch_update_program_bindings(Batch* batch) switch (a->fetch_mode) { - case KEEP_FLOAT: - case CONVERT_INT_TO_FLOAT: + case GWN_FETCH_FLOAT: + case GWN_FETCH_INT_TO_FLOAT: glVertexAttribPointer(input->location, a->comp_ct, a->gl_comp_type, GL_FALSE, stride, pointer); break; - case NORMALIZE_INT_TO_FLOAT: + case GWN_FETCH_INT_TO_FLOAT_UNIT: glVertexAttribPointer(input->location, a->comp_ct, a->gl_comp_type, GL_TRUE, stride, pointer); break; - case KEEP_INT: + case GWN_FETCH_INT: glVertexAttribIPointer(input->location, a->comp_ct, a->gl_comp_type, stride, pointer); } } @@ -155,7 +155,7 @@ static void Batch_update_program_bindings(Batch* batch) batch->program_dirty = false; } -void Batch_use_program(Batch* batch) +void GWN_batch_program_use_begin(Gwn_Batch* batch) { // NOTE: use_program & done_using_program are fragile, depend on staying in sync with // the GL context's active program. use_program doesn't mark other programs as "not used". @@ -168,7 +168,7 @@ void Batch_use_program(Batch* batch) } } -void Batch_done_using_program(Batch* batch) +void GWN_batch_program_use_end(Gwn_Batch* batch) { if (batch->program_in_use) { @@ -178,81 +178,81 @@ void Batch_done_using_program(Batch* batch) } #if TRUST_NO_ONE - #define GET_UNIFORM const ShaderInput* uniform = ShaderInterface_uniform(batch->interface, name); assert(uniform); + #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(batch->interface, name); assert(uniform); #else - #define GET_UNIFORM const ShaderInput* uniform = ShaderInterface_uniform(batch->interface, name); + #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(batch->interface, name); #endif -void Batch_Uniform1i(Batch* batch, const char* name, int value) +void GWN_batch_uniform_1i(Gwn_Batch* batch, const char* name, int value) { GET_UNIFORM glUniform1i(uniform->location, value); } -void Batch_Uniform1b(Batch* batch, const char* name, bool value) +void GWN_batch_uniform_1b(Gwn_Batch* batch, const char* name, bool value) { GET_UNIFORM glUniform1i(uniform->location, value ? GL_TRUE : GL_FALSE); } -void Batch_Uniform2f(Batch* batch, const char* name, float x, float y) +void GWN_batch_uniform_2f(Gwn_Batch* batch, const char* name, float x, float y) { GET_UNIFORM glUniform2f(uniform->location, x, y); } -void Batch_Uniform3f(Batch* batch, const char* name, float x, float y, float z) +void GWN_batch_uniform_3f(Gwn_Batch* batch, const char* name, float x, float y, float z) { GET_UNIFORM glUniform3f(uniform->location, x, y, z); } -void Batch_Uniform4f(Batch* batch, const char* name, float x, float y, float z, float w) +void GWN_batch_uniform_4f(Gwn_Batch* batch, const char* name, float x, float y, float z, float w) { GET_UNIFORM glUniform4f(uniform->location, x, y, z, w); } -void Batch_Uniform1f(Batch* batch, const char* name, float x) +void GWN_batch_uniform_1f(Gwn_Batch* batch, const char* name, float x) { GET_UNIFORM glUniform1f(uniform->location, x); } -void Batch_Uniform3fv(Batch* batch, const char* name, const float data[3]) +void GWN_batch_uniform_3fv(Gwn_Batch* batch, const char* name, const float data[3]) { GET_UNIFORM glUniform3fv(uniform->location, 1, data); } -void Batch_Uniform4fv(Batch* batch, const char* name, const float data[4]) +void GWN_batch_uniform_4fv(Gwn_Batch* batch, const char* name, const float data[4]) { GET_UNIFORM glUniform4fv(uniform->location, 1, data); } -static void Batch_prime(Batch* batch) +static void Batch_prime(Gwn_Batch* batch) { - batch->vao_id = vao_id_alloc(); + batch->vao_id = GWN_vao_alloc(); glBindVertexArray(batch->vao_id); - for (int v = 0; v < BATCH_MAX_VBO_CT; ++v) + for (int v = 0; v < GWN_BATCH_VBO_MAX_LEN; ++v) { if (batch->verts[v] == NULL) break; - VertexBuffer_use(batch->verts[v]); + GWN_vertbuf_use(batch->verts[v]); } if (batch->elem) - ElementList_use(batch->elem); + GWN_indexbuf_use(batch->elem); // vertex attribs and element list remain bound to this VAO } -void Batch_draw(Batch* batch) +void GWN_batch_draw(Gwn_Batch* batch) { #if TRUST_NO_ONE - assert(batch->phase == READY_TO_DRAW); + assert(batch->phase == GWN_BATCH_READY_TO_DRAW); assert(glIsProgram(batch->program)); #endif @@ -264,15 +264,15 @@ void Batch_draw(Batch* batch) if (batch->program_dirty) Batch_update_program_bindings(batch); - Batch_use_program(batch); + GWN_batch_program_use_begin(batch); gpuBindMatrices(batch->interface); if (batch->elem) { - const ElementList* el = batch->elem; + const Gwn_IndexBuf* el = batch->elem; -#if TRACK_INDEX_RANGE +#if GWN_TRACK_INDEX_RANGE if (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 @@ -284,14 +284,14 @@ void Batch_draw(Batch* batch) else glDrawArrays(batch->gl_prim_type, 0, batch->verts[0]->vertex_ct); - Batch_done_using_program(batch); + GWN_batch_program_use_end(batch); glBindVertexArray(0); } // clement : temp stuff -void Batch_draw_stupid(Batch* batch) +void GWN_batch_draw_stupid(Gwn_Batch* batch) { if (batch->vao_id) glBindVertexArray(batch->vao_id); @@ -301,15 +301,15 @@ void Batch_draw_stupid(Batch* batch) if (batch->program_dirty) Batch_update_program_bindings(batch); - // Batch_use_program(batch); + // GWN_batch_program_use_begin(batch); //gpuBindMatrices(batch->program); if (batch->elem) { - const ElementList* el = batch->elem; + const Gwn_IndexBuf* el = batch->elem; -#if TRACK_INDEX_RANGE +#if GWN_TRACK_INDEX_RANGE if (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 @@ -321,12 +321,12 @@ void Batch_draw_stupid(Batch* batch) else glDrawArrays(batch->gl_prim_type, 0, batch->verts[0]->vertex_ct); - // Batch_done_using_program(batch); + // GWN_batch_program_use_end(batch); glBindVertexArray(0); } // clement : temp stuff -void Batch_draw_stupid_instanced(Batch* batch, unsigned int instance_vbo, int instance_count, +void GWN_batch_draw_stupid_instanced(Gwn_Batch* batch, unsigned int instance_vbo, int instance_count, int attrib_nbr, int attrib_stride, int attrib_size[16], int attrib_loc[16]) { if (batch->vao_id) @@ -358,24 +358,24 @@ void Batch_draw_stupid_instanced(Batch* batch, unsigned int instance_vbo, int in } glBindBuffer(GL_ARRAY_BUFFER, 0); - // Batch_use_program(batch); + // GWN_batch_program_use_begin(batch); //gpuBindMatrices(batch->program); if (batch->elem) { - const ElementList* el = batch->elem; + const Gwn_IndexBuf* el = batch->elem; glDrawElementsInstanced(batch->gl_prim_type, el->index_ct, GL_UNSIGNED_INT, 0, instance_count); } else glDrawArraysInstanced(batch->gl_prim_type, 0, batch->verts[0]->vertex_ct, instance_count); - // Batch_done_using_program(batch); + // GWN_batch_program_use_end(batch); glBindVertexArray(0); } -void Batch_draw_stupid_instanced_with_batch(Batch* batch_instanced, Batch* batch_instancing) +void GWN_batch_draw_stupid_instanced_with_batch(Gwn_Batch* batch_instanced, Gwn_Batch* batch_instancing) { if (batch_instanced->vao_id) glBindVertexArray(batch_instanced->vao_id); @@ -385,24 +385,24 @@ void Batch_draw_stupid_instanced_with_batch(Batch* batch_instanced, Batch* batch if (batch_instanced->program_dirty) Batch_update_program_bindings(batch_instanced); - VertexBuffer* verts = batch_instancing->verts[0]; + Gwn_VertBuf* verts = batch_instancing->verts[0]; - const VertexFormat* format = &verts->format; + const Gwn_VertFormat* format = &verts->format; const unsigned attrib_ct = format->attrib_ct; const unsigned stride = format->stride; - VertexBuffer_use(verts); + GWN_vertbuf_use(verts); for (unsigned a_idx = 0; a_idx < attrib_ct; ++a_idx) { - const Attrib* a = format->attribs + a_idx; + const Gwn_VertAttr* a = format->attribs + a_idx; const GLvoid* pointer = (const GLubyte*)0 + a->offset; for (unsigned n_idx = 0; n_idx < a->name_ct; ++n_idx) { - const ShaderInput* input = ShaderInterface_attrib(batch_instanced->interface, a->name[n_idx]); + const Gwn_ShaderInput* input = GWN_shaderinterface_attr(batch_instanced->interface, a->name[n_idx]); if (input == NULL) continue; @@ -411,32 +411,32 @@ void Batch_draw_stupid_instanced_with_batch(Batch* batch_instanced, Batch* batch switch (a->fetch_mode) { - case KEEP_FLOAT: - case CONVERT_INT_TO_FLOAT: + case GWN_FETCH_FLOAT: + case GWN_FETCH_INT_TO_FLOAT: glVertexAttribPointer(input->location, a->comp_ct, a->gl_comp_type, GL_FALSE, stride, pointer); break; - case NORMALIZE_INT_TO_FLOAT: + case GWN_FETCH_INT_TO_FLOAT_UNIT: glVertexAttribPointer(input->location, a->comp_ct, a->gl_comp_type, GL_TRUE, stride, pointer); break; - case KEEP_INT: + case GWN_FETCH_INT: glVertexAttribIPointer(input->location, a->comp_ct, a->gl_comp_type, stride, pointer); } } } - // Batch_use_program(batch); + // GWN_batch_program_use_begin(batch); //gpuBindMatrices(batch->program); if (batch_instanced->elem) { - const ElementList* el = batch_instanced->elem; + const Gwn_IndexBuf* el = batch_instanced->elem; glDrawElementsInstanced(batch_instanced->gl_prim_type, el->index_ct, GL_UNSIGNED_INT, 0, verts->vertex_ct); } else glDrawArraysInstanced(batch_instanced->gl_prim_type, 0, batch_instanced->verts[0]->vertex_ct, verts->vertex_ct); - // Batch_done_using_program(batch); + // GWN_batch_program_use_end(batch); glBindVertexArray(0); }
\ No newline at end of file diff --git a/intern/gawain/src/buffer_id.cpp b/intern/gawain/src/buffer_id.cpp index 450656c4ebf..59a6b9c89e7 100644 --- a/intern/gawain/src/buffer_id.cpp +++ b/intern/gawain/src/buffer_id.cpp @@ -34,7 +34,7 @@ static bool thread_is_main() return BLI_thread_is_main(); } -GLuint buffer_id_alloc() +GLuint GWN_buf_id_alloc() { #if TRUST_NO_ONE assert(thread_is_main()); @@ -58,7 +58,7 @@ GLuint buffer_id_alloc() return new_buffer_id; } -void buffer_id_free(GLuint buffer_id) +void GWN_buf_id_free(GLuint buffer_id) { if (thread_is_main()) glDeleteBuffers(1, &buffer_id); @@ -74,7 +74,7 @@ void buffer_id_free(GLuint buffer_id) } } -GLuint vao_id_alloc() +GLuint GWN_vao_alloc() { #if TRUST_NO_ONE assert(thread_is_main()); @@ -98,7 +98,7 @@ GLuint vao_id_alloc() return new_vao_id; } -void vao_id_free(GLuint vao_id) +void GWN_vao_free(GLuint vao_id) { if (thread_is_main()) glDeleteVertexArrays(1, &vao_id); diff --git a/intern/gawain/src/element.c b/intern/gawain/src/element.c index 425e3705003..ecf555fbfe8 100644 --- a/intern/gawain/src/element.c +++ b/intern/gawain/src/element.c @@ -15,23 +15,23 @@ #define KEEP_SINGLE_COPY 1 -static GLenum convert_index_type_to_gl(IndexType type) +static GLenum convert_index_type_to_gl(Gwn_IndexBufType 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 + [GWN_INDEX_U8] = GL_UNSIGNED_BYTE, // GL has this, Vulkan does not + [GWN_INDEX_U16] = GL_UNSIGNED_SHORT, + [GWN_INDEX_U32] = GL_UNSIGNED_INT }; return table[type]; } -unsigned ElementList_size(const ElementList* elem) +unsigned GWN_indexbuf_size_get(const Gwn_IndexBuf* elem) { -#if TRACK_INDEX_RANGE +#if GWN_TRACK_INDEX_RANGE static const unsigned table[] = { - [INDEX_U8] = sizeof(GLubyte), // GL has this, Vulkan does not - [INDEX_U16] = sizeof(GLushort), - [INDEX_U32] = sizeof(GLuint) + [GWN_INDEX_U8] = sizeof(GLubyte), // GL has this, Vulkan does not + [GWN_INDEX_U16] = sizeof(GLushort), + [GWN_INDEX_U32] = sizeof(GLuint) }; return elem->index_ct * table[elem->index_type]; #else @@ -39,12 +39,12 @@ unsigned ElementList_size(const ElementList* elem) #endif } -static void ElementList_prime(ElementList* elem) +static void ElementList_prime(Gwn_IndexBuf* elem) { - elem->vbo_id = buffer_id_alloc(); + elem->vbo_id = GWN_buf_id_alloc(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elem->vbo_id); // fill with delicious data & send to GPU the first time only - glBufferData(GL_ELEMENT_ARRAY_BUFFER, ElementList_size(elem), elem->data, GL_STATIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, GWN_indexbuf_size_get(elem), elem->data, GL_STATIC_DRAW); #if KEEP_SINGLE_COPY // now that GL has a copy, discard original @@ -53,7 +53,7 @@ static void ElementList_prime(ElementList* elem) #endif } -void ElementList_use(ElementList* elem) +void GWN_indexbuf_use(Gwn_IndexBuf* elem) { if (elem->vbo_id) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elem->vbo_id); @@ -61,18 +61,18 @@ void ElementList_use(ElementList* elem) ElementList_prime(elem); } -void ElementListBuilder_init(ElementListBuilder* builder, PrimitiveType prim_type, unsigned prim_ct, unsigned vertex_ct) +void GWN_indexbuf_init(Gwn_IndexBufBuilder* builder, Gwn_PrimType prim_type, unsigned prim_ct, unsigned vertex_ct) { unsigned verts_per_prim = 0; switch (prim_type) { - case PRIM_POINTS: + case GWN_PRIM_POINTS: verts_per_prim = 1; break; - case PRIM_LINES: + case GWN_PRIM_LINES: verts_per_prim = 2; break; - case PRIM_TRIANGLES: + case GWN_PRIM_TRIS: verts_per_prim = 3; break; default: @@ -89,7 +89,7 @@ void ElementListBuilder_init(ElementListBuilder* builder, PrimitiveType prim_typ builder->data = calloc(builder->max_index_ct, sizeof(unsigned)); } -void add_generic_vertex(ElementListBuilder* builder, unsigned v) +void GWN_indexbuf_add_generic_vert(Gwn_IndexBufBuilder* builder, unsigned v) { #if TRUST_NO_ONE assert(builder->data != NULL); @@ -100,39 +100,39 @@ void add_generic_vertex(ElementListBuilder* builder, unsigned v) builder->data[builder->index_ct++] = v; } -void add_point_vertex(ElementListBuilder* builder, unsigned v) +void GWN_indexbuf_add_point_vert(Gwn_IndexBufBuilder* builder, unsigned v) { #if TRUST_NO_ONE - assert(builder->prim_type == PRIM_POINTS); + assert(builder->prim_type == GWN_PRIM_POINTS); #endif - add_generic_vertex(builder, v); + GWN_indexbuf_add_generic_vert(builder, v); } -void add_line_vertices(ElementListBuilder* builder, unsigned v1, unsigned v2) +void GWN_indexbuf_add_line_verts(Gwn_IndexBufBuilder* builder, unsigned v1, unsigned v2) { #if TRUST_NO_ONE - assert(builder->prim_type == PRIM_LINES); + assert(builder->prim_type == GWN_PRIM_LINES); assert(v1 != v2); #endif - add_generic_vertex(builder, v1); - add_generic_vertex(builder, v2); + GWN_indexbuf_add_generic_vert(builder, v1); + GWN_indexbuf_add_generic_vert(builder, v2); } -void add_triangle_vertices(ElementListBuilder* builder, unsigned v1, unsigned v2, unsigned v3) +void GWN_indexbuf_add_tri_verts(Gwn_IndexBufBuilder* builder, unsigned v1, unsigned v2, unsigned v3) { #if TRUST_NO_ONE - assert(builder->prim_type == PRIM_TRIANGLES); + assert(builder->prim_type == GWN_PRIM_TRIS); assert(v1 != v2 && v2 != v3 && v3 != v1); #endif - add_generic_vertex(builder, v1); - add_generic_vertex(builder, v2); - add_generic_vertex(builder, v3); + GWN_indexbuf_add_generic_vert(builder, v1); + GWN_indexbuf_add_generic_vert(builder, v2); + GWN_indexbuf_add_generic_vert(builder, v3); } -#if TRACK_INDEX_RANGE +#if GWN_TRACK_INDEX_RANGE // Everything remains 32 bit while building to keep things simple. // Find min/max after, then convert to smallest index type possible. @@ -159,7 +159,7 @@ static unsigned index_range(const unsigned values[], unsigned value_ct, unsigned return max_value - min_value; } -static void squeeze_indices_byte(const unsigned values[], ElementList* elem) +static void squeeze_indices_byte(const unsigned values[], Gwn_IndexBuf* elem) { const unsigned index_ct = elem->index_ct; GLubyte* data = malloc(index_ct * sizeof(GLubyte)); @@ -186,7 +186,7 @@ static void squeeze_indices_byte(const unsigned values[], ElementList* elem) elem->data = data; } -static void squeeze_indices_short(const unsigned values[], ElementList* elem) +static void squeeze_indices_short(const unsigned values[], Gwn_IndexBuf* elem) { const unsigned index_ct = elem->index_ct; GLushort* data = malloc(index_ct * sizeof(GLushort)); @@ -213,16 +213,16 @@ static void squeeze_indices_short(const unsigned values[], ElementList* elem) elem->data = data; } -#endif // TRACK_INDEX_RANGE +#endif // GWN_TRACK_INDEX_RANGE -ElementList* ElementList_build(ElementListBuilder* builder) +Gwn_IndexBuf* GWN_indexbuf_build(Gwn_IndexBufBuilder* builder) { - ElementList* elem = calloc(1, sizeof(ElementList)); - ElementList_build_in_place(builder, elem); + Gwn_IndexBuf* elem = calloc(1, sizeof(Gwn_IndexBuf)); + GWN_indexbuf_build_in_place(builder, elem); return elem; } -void ElementList_build_in_place(ElementListBuilder* builder, ElementList* elem) +void GWN_indexbuf_build_in_place(Gwn_IndexBufBuilder* builder, Gwn_IndexBuf* elem) { #if TRUST_NO_ONE assert(builder->data != NULL); @@ -230,22 +230,22 @@ void ElementList_build_in_place(ElementListBuilder* builder, ElementList* elem) elem->index_ct = builder->index_ct; -#if TRACK_INDEX_RANGE +#if GWN_TRACK_INDEX_RANGE const unsigned range = index_range(builder->data, builder->index_ct, &elem->min_index, &elem->max_index); if (range <= 0xFF) { - elem->index_type = INDEX_U8; + elem->index_type = GWN_INDEX_U8; squeeze_indices_byte(builder->data, elem); } else if (range <= 0xFFFF) { - elem->index_type = INDEX_U16; + elem->index_type = GWN_INDEX_U16; squeeze_indices_short(builder->data, elem); } else { - elem->index_type = INDEX_U32; + elem->index_type = GWN_INDEX_U32; elem->base_index = 0; if (builder->index_ct < builder->max_index_ct) @@ -281,10 +281,10 @@ void ElementList_build_in_place(ElementListBuilder* builder, ElementList* elem) // other fields are safe to leave } -void ElementList_discard(ElementList* elem) +void GWN_indexbuf_discard(Gwn_IndexBuf* elem) { if (elem->vbo_id) - buffer_id_free(elem->vbo_id); + GWN_buf_id_free(elem->vbo_id); #if KEEP_SINGLE_COPY else #endif diff --git a/intern/gawain/src/imm_util.c b/intern/gawain/src/imm_util.c index de50ca96907..b06778c9045 100644 --- a/intern/gawain/src/imm_util.c +++ b/intern/gawain/src/imm_util.c @@ -15,7 +15,7 @@ void immRectf(unsigned pos, float x1, float y1, float x2, float y2) { - immBegin(PRIM_TRIANGLE_FAN, 4); + immBegin(GWN_PRIM_TRI_FAN, 4); immVertex2f(pos, x1, y1); immVertex2f(pos, x2, y1); immVertex2f(pos, x2, y2); @@ -25,7 +25,7 @@ void immRectf(unsigned pos, float x1, float y1, float x2, float y2) void immRecti(unsigned pos, int x1, int y1, int x2, int y2) { - immBegin(PRIM_TRIANGLE_FAN, 4); + immBegin(GWN_PRIM_TRI_FAN, 4); immVertex2i(pos, x1, y1); immVertex2i(pos, x2, y1); immVertex2i(pos, x2, y2); @@ -36,8 +36,8 @@ void immRecti(unsigned pos, int x1, int y1, int x2, int y2) #if 0 // more complete version in case we want that void immRecti_complete(int x1, int y1, int x2, int y2, const float color[4]) { - VertexFormat *format = immVertexFormat(); - unsigned pos = add_attrib(format, "pos", COMP_I32, 2, CONVERT_INT_TO_FLOAT); + Gwn_VertFormat *format = immVertexFormat(); + unsigned pos = add_attrib(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformColor4fv(color); immRecti(pos, x1, y1, x2, y2); diff --git a/intern/gawain/src/immediate.c b/intern/gawain/src/immediate.c index af9a48c2f4d..5eb5ebb8336 100644 --- a/intern/gawain/src/immediate.c +++ b/intern/gawain/src/immediate.c @@ -18,14 +18,14 @@ #include <string.h> // necessary functions from matrix API -extern void gpuBindMatrices(const ShaderInterface*); +extern void gpuBindMatrices(const Gwn_ShaderInterface*); extern bool gpuMatricesDirty(void); typedef struct { // TODO: organize this struct by frequency of change (run-time) #if IMM_BATCH_COMBO - Batch* batch; + Gwn_Batch* batch; #endif // current draw call @@ -34,9 +34,9 @@ typedef struct { unsigned buffer_bytes_mapped; unsigned vertex_ct; bool strict_vertex_ct; - PrimitiveType prim_type; + Gwn_PrimType prim_type; - VertexFormat vertex_format; + Gwn_VertFormat vertex_format; // current vertex unsigned vertex_idx; @@ -47,8 +47,8 @@ typedef struct { GLuint vao_id; GLuint bound_program; - const ShaderInterface* shader_interface; - AttribBinding attrib_binding; + const Gwn_ShaderInterface* shader_interface; + Gwn_AttrBinding attrib_binding; uint16_t prev_enabled_attrib_bits; // <-- only affects this VAO, so we're ok } Immediate; @@ -66,11 +66,11 @@ void immInit(void) memset(&imm, 0, sizeof(Immediate)); - imm.vbo_id = buffer_id_alloc(); + imm.vbo_id = GWN_buf_id_alloc(); glBindBuffer(GL_ARRAY_BUFFER, imm.vbo_id); glBufferData(GL_ARRAY_BUFFER, IMM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW); - imm.prim_type = PRIM_NONE; + imm.prim_type = GWN_PRIM_NONE; imm.strict_vertex_ct = true; glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -83,22 +83,22 @@ void immActivate(void) { #if TRUST_NO_ONE assert(initialized); - assert(imm.prim_type == PRIM_NONE); // make sure we're not between a Begin/End pair + assert(imm.prim_type == GWN_PRIM_NONE); // make sure we're not between a Begin/End pair assert(imm.vao_id == 0); #endif - imm.vao_id = vao_id_alloc(); + imm.vao_id = GWN_vao_alloc(); } void immDeactivate(void) { #if TRUST_NO_ONE assert(initialized); - assert(imm.prim_type == PRIM_NONE); // make sure we're not between a Begin/End pair + assert(imm.prim_type == GWN_PRIM_NONE); // make sure we're not between a Begin/End pair assert(imm.vao_id != 0); #endif - vao_id_free(imm.vao_id); + GWN_vao_free(imm.vao_id); imm.vao_id = 0; imm.prev_enabled_attrib_bits = 0; } @@ -106,17 +106,17 @@ void immDeactivate(void) void immDestroy(void) { immDeactivate(); - buffer_id_free(imm.vbo_id); + GWN_buf_id_free(imm.vbo_id); initialized = false; } -VertexFormat* immVertexFormat(void) +Gwn_VertFormat* immVertexFormat(void) { - VertexFormat_clear(&imm.vertex_format); + GWN_vertformat_clear(&imm.vertex_format); return &imm.vertex_format; } -void immBindProgram(GLuint program, const ShaderInterface* shaderface) +void immBindProgram(GLuint program, const Gwn_ShaderInterface* shaderface) { #if TRUST_NO_ONE assert(imm.bound_program == 0); @@ -145,7 +145,7 @@ void immUnbindProgram(void) } #if TRUST_NO_ONE -static bool vertex_count_makes_sense_for_primitive(unsigned vertex_ct, PrimitiveType prim_type) +static bool vertex_count_makes_sense_for_primitive(unsigned vertex_ct, Gwn_PrimType prim_type) { // does vertex_ct make sense for this primitive type? if (vertex_ct == 0) @@ -153,19 +153,19 @@ static bool vertex_count_makes_sense_for_primitive(unsigned vertex_ct, Primitive switch (prim_type) { - case PRIM_POINTS: + case GWN_PRIM_POINTS: return true; - case PRIM_LINES: + case GWN_PRIM_LINES: return vertex_ct % 2 == 0; - case PRIM_LINE_STRIP: - case PRIM_LINE_LOOP: + case GWN_PRIM_LINE_STRIP: + case GWN_PRIM_LINE_LOOP: return vertex_ct >= 2; - case PRIM_LINE_STRIP_ADJACENCY: + case GWN_PRIM_LINE_STRIP_ADJ: return vertex_ct >= 4; - case PRIM_TRIANGLES: + case GWN_PRIM_TRIS: return vertex_ct % 3 == 0; - case PRIM_TRIANGLE_STRIP: - case PRIM_TRIANGLE_FAN: + case GWN_PRIM_TRI_STRIP: + case GWN_PRIM_TRI_FAN: return vertex_ct >= 3; default: return false; @@ -173,11 +173,11 @@ static bool vertex_count_makes_sense_for_primitive(unsigned vertex_ct, Primitive } #endif -void immBegin(PrimitiveType prim_type, unsigned vertex_ct) +void immBegin(Gwn_PrimType prim_type, unsigned vertex_ct) { #if TRUST_NO_ONE assert(initialized); - assert(imm.prim_type == PRIM_NONE); // make sure we haven't already begun + assert(imm.prim_type == GWN_PRIM_NONE); // make sure we haven't already begun assert(vertex_count_makes_sense_for_primitive(vertex_ct, prim_type)); #endif @@ -242,7 +242,7 @@ void immBegin(PrimitiveType prim_type, unsigned vertex_ct) imm.vertex_data = imm.buffer_data; } -void immBeginAtMost(PrimitiveType prim_type, unsigned vertex_ct) +void immBeginAtMost(Gwn_PrimType prim_type, unsigned vertex_ct) { #if TRUST_NO_ONE assert(vertex_ct > 0); @@ -254,11 +254,11 @@ void immBeginAtMost(PrimitiveType prim_type, unsigned vertex_ct) #if IMM_BATCH_COMBO -Batch* immBeginBatch(PrimitiveType prim_type, unsigned vertex_ct) +Gwn_Batch* immBeginBatch(Gwn_PrimType prim_type, unsigned vertex_ct) { #if TRUST_NO_ONE assert(initialized); - assert(imm.prim_type == PRIM_NONE); // make sure we haven't already begun + assert(imm.prim_type == GWN_PRIM_NONE); // make sure we haven't already begun assert(vertex_count_makes_sense_for_primitive(vertex_ct, prim_type)); #endif @@ -267,21 +267,21 @@ Batch* immBeginBatch(PrimitiveType prim_type, unsigned vertex_ct) imm.vertex_idx = 0; imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits; - VertexBuffer* verts = VertexBuffer_create_with_format(&imm.vertex_format); - VertexBuffer_allocate_data(verts, vertex_ct); + Gwn_VertBuf* verts = GWN_vertbuf_create_with_format(&imm.vertex_format); + GWN_vertbuf_data_alloc(verts, vertex_ct); - imm.buffer_bytes_mapped = VertexBuffer_size(verts); + imm.buffer_bytes_mapped = GWN_vertbuf_size_get(verts); imm.vertex_data = verts->data; - imm.batch = Batch_create(prim_type, verts, NULL); - imm.batch->phase = BUILDING; + imm.batch = GWN_batch_create(prim_type, verts, NULL); + imm.batch->phase = GWN_BATCH_BUILDING; - Batch_set_program(imm.batch, imm.bound_program, imm.shader_interface); + GWN_batch_program_set(imm.batch, imm.bound_program, imm.shader_interface); return imm.batch; } -Batch* immBeginBatchAtMost(PrimitiveType prim_type, unsigned vertex_ct) +Gwn_Batch* immBeginBatchAtMost(Gwn_PrimType prim_type, unsigned vertex_ct) { imm.strict_vertex_ct = false; return immBeginBatch(prim_type, vertex_ct); @@ -297,7 +297,7 @@ static void immDrawSetup(void) // enable/disable vertex attribs as needed if (imm.attrib_binding.enabled_bits != imm.prev_enabled_attrib_bits) { - for (unsigned loc = 0; loc < MAX_VERTEX_ATTRIBS; ++loc) + for (unsigned loc = 0; loc < GWN_VERT_ATTR_MAX_LEN; ++loc) { bool is_enabled = imm.attrib_binding.enabled_bits & (1 << loc); bool was_enabled = imm.prev_enabled_attrib_bits & (1 << loc); @@ -321,7 +321,7 @@ static void immDrawSetup(void) for (unsigned a_idx = 0; a_idx < imm.vertex_format.attrib_ct; ++a_idx) { - const Attrib* a = imm.vertex_format.attribs + a_idx; + const Gwn_VertAttr* a = imm.vertex_format.attribs + a_idx; const unsigned offset = imm.buffer_offset + a->offset; const GLvoid* pointer = (const GLubyte*)0 + offset; @@ -332,14 +332,14 @@ static void immDrawSetup(void) switch (a->fetch_mode) { - case KEEP_FLOAT: - case CONVERT_INT_TO_FLOAT: + case GWN_FETCH_FLOAT: + case GWN_FETCH_INT_TO_FLOAT: glVertexAttribPointer(loc, a->comp_ct, a->gl_comp_type, GL_FALSE, stride, pointer); break; - case NORMALIZE_INT_TO_FLOAT: + case GWN_FETCH_INT_TO_FLOAT_UNIT: glVertexAttribPointer(loc, a->comp_ct, a->gl_comp_type, GL_TRUE, stride, pointer); break; - case KEEP_INT: + case GWN_FETCH_INT: glVertexAttribIPointer(loc, a->comp_ct, a->gl_comp_type, stride, pointer); } } @@ -351,7 +351,7 @@ static void immDrawSetup(void) void immEnd(void) { #if TRUST_NO_ONE - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif unsigned buffer_bytes_used; @@ -393,11 +393,11 @@ void immEnd(void) { if (buffer_bytes_used != imm.buffer_bytes_mapped) { - VertexBuffer_resize_data(imm.batch->verts[0], imm.vertex_ct); + GWN_vertbuf_data_resize(imm.batch->verts[0], imm.vertex_ct); // TODO: resize only if vertex count is much smaller } - imm.batch->phase = READY_TO_DRAW; + imm.batch->phase = GWN_BATCH_READY_TO_DRAW; imm.batch = NULL; // don't free, batch belongs to caller } else @@ -419,7 +419,7 @@ void immEnd(void) } // prep for next immBegin - imm.prim_type = PRIM_NONE; + imm.prim_type = GWN_PRIM_NONE; imm.strict_vertex_ct = true; } @@ -439,14 +439,14 @@ static void setAttribValueBit(unsigned attrib_id) void immAttrib1f(unsigned attrib_id, float x) { - Attrib* attrib = imm.vertex_format.attribs + attrib_id; + Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id; #if TRUST_NO_ONE assert(attrib_id < imm.vertex_format.attrib_ct); - assert(attrib->comp_type == COMP_F32); + assert(attrib->comp_type == GWN_COMP_F32); assert(attrib->comp_ct == 1); assert(imm.vertex_idx < imm.vertex_ct); - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif setAttribValueBit(attrib_id); @@ -459,14 +459,14 @@ void immAttrib1f(unsigned attrib_id, float x) void immAttrib2f(unsigned attrib_id, float x, float y) { - Attrib* attrib = imm.vertex_format.attribs + attrib_id; + Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id; #if TRUST_NO_ONE assert(attrib_id < imm.vertex_format.attrib_ct); - assert(attrib->comp_type == COMP_F32); + assert(attrib->comp_type == GWN_COMP_F32); assert(attrib->comp_ct == 2); assert(imm.vertex_idx < imm.vertex_ct); - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif setAttribValueBit(attrib_id); @@ -480,14 +480,14 @@ void immAttrib2f(unsigned attrib_id, float x, float y) void immAttrib3f(unsigned attrib_id, float x, float y, float z) { - Attrib* attrib = imm.vertex_format.attribs + attrib_id; + Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id; #if TRUST_NO_ONE assert(attrib_id < imm.vertex_format.attrib_ct); - assert(attrib->comp_type == COMP_F32); + assert(attrib->comp_type == GWN_COMP_F32); assert(attrib->comp_ct == 3); assert(imm.vertex_idx < imm.vertex_ct); - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif setAttribValueBit(attrib_id); @@ -502,14 +502,14 @@ void immAttrib3f(unsigned attrib_id, float x, float y, float z) void immAttrib4f(unsigned attrib_id, float x, float y, float z, float w) { - Attrib* attrib = imm.vertex_format.attribs + attrib_id; + Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id; #if TRUST_NO_ONE assert(attrib_id < imm.vertex_format.attrib_ct); - assert(attrib->comp_type == COMP_F32); + assert(attrib->comp_type == GWN_COMP_F32); assert(attrib->comp_ct == 4); assert(imm.vertex_idx < imm.vertex_ct); - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif setAttribValueBit(attrib_id); @@ -525,14 +525,14 @@ void immAttrib4f(unsigned attrib_id, float x, float y, float z, float w) void immAttrib1u(unsigned attrib_id, unsigned x) { - Attrib* attrib = imm.vertex_format.attribs + attrib_id; + Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id; #if TRUST_NO_ONE assert(attrib_id < imm.vertex_format.attrib_ct); - assert(attrib->comp_type == COMP_U32); + assert(attrib->comp_type == GWN_COMP_U32); assert(attrib->comp_ct == 1); assert(imm.vertex_idx < imm.vertex_ct); - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif setAttribValueBit(attrib_id); @@ -544,14 +544,14 @@ void immAttrib1u(unsigned attrib_id, unsigned x) void immAttrib2i(unsigned attrib_id, int x, int y) { - Attrib* attrib = imm.vertex_format.attribs + attrib_id; + Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id; #if TRUST_NO_ONE assert(attrib_id < imm.vertex_format.attrib_ct); - assert(attrib->comp_type == COMP_I32); + assert(attrib->comp_type == GWN_COMP_I32); assert(attrib->comp_ct == 2); assert(imm.vertex_idx < imm.vertex_ct); - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif setAttribValueBit(attrib_id); @@ -564,14 +564,14 @@ void immAttrib2i(unsigned attrib_id, int x, int y) void immAttrib2s(unsigned attrib_id, short x, short y) { - Attrib* attrib = imm.vertex_format.attribs + attrib_id; + Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id; #if TRUST_NO_ONE assert(attrib_id < imm.vertex_format.attrib_ct); - assert(attrib->comp_type == COMP_I16); + assert(attrib->comp_type == GWN_COMP_I16); assert(attrib->comp_ct == 2); assert(imm.vertex_idx < imm.vertex_ct); - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif setAttribValueBit(attrib_id); @@ -599,14 +599,14 @@ void immAttrib4fv(unsigned attrib_id, const float data[4]) void immAttrib3ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned char b) { - Attrib* attrib = imm.vertex_format.attribs + attrib_id; + Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id; #if TRUST_NO_ONE assert(attrib_id < imm.vertex_format.attrib_ct); - assert(attrib->comp_type == COMP_U8); + assert(attrib->comp_type == GWN_COMP_U8); assert(attrib->comp_ct == 3); assert(imm.vertex_idx < imm.vertex_ct); - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif setAttribValueBit(attrib_id); @@ -621,14 +621,14 @@ void immAttrib3ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned void immAttrib4ub(unsigned attrib_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a) { - Attrib* attrib = imm.vertex_format.attribs + attrib_id; + Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id; #if TRUST_NO_ONE assert(attrib_id < imm.vertex_format.attrib_ct); - assert(attrib->comp_type == COMP_U8); + assert(attrib->comp_type == GWN_COMP_U8); assert(attrib->comp_ct == 4); assert(imm.vertex_idx < imm.vertex_ct); - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif setAttribValueBit(attrib_id); @@ -657,7 +657,7 @@ void immSkipAttrib(unsigned attrib_id) #if TRUST_NO_ONE assert(attrib_id < imm.vertex_format.attrib_ct); assert(imm.vertex_idx < imm.vertex_ct); - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair #endif setAttribValueBit(attrib_id); @@ -666,7 +666,7 @@ void immSkipAttrib(unsigned attrib_id) static void immEndVertex(void) // and move on to the next vertex { #if TRUST_NO_ONE - assert(imm.prim_type != PRIM_NONE); // make sure we're between a Begin/End pair + assert(imm.prim_type != GWN_PRIM_NONE); // make sure we're between a Begin/End pair assert(imm.vertex_idx < imm.vertex_ct); #endif @@ -682,7 +682,7 @@ static void immEndVertex(void) // and move on to the next vertex { if ((imm.unassigned_attrib_bits >> a_idx) & 1) { - const Attrib* a = imm.vertex_format.attribs + a_idx; + const Gwn_VertAttr* a = imm.vertex_format.attribs + a_idx; // printf("copying %s from vertex %u to %u\n", a->name, imm.vertex_idx - 1, imm.vertex_idx); @@ -745,16 +745,16 @@ void immVertex2iv(unsigned attrib_id, const int data[2]) #if 0 #if TRUST_NO_ONE - #define GET_UNIFORM const ShaderInput* uniform = ShaderInterface_uniform(imm.shader_interface, name); assert(uniform); + #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(imm.shader_interface, name); assert(uniform); #else - #define GET_UNIFORM const ShaderInput* uniform = ShaderInterface_uniform(imm.shader_interface, name); + #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(imm.shader_interface, name); #endif #else // NOTE: It is possible to have uniform fully optimized out from the shader. // In this case we can't assert failure or allow NULL-pointer dereference. // TODO(sergey): How can we detect existing-but-optimized-out uniform but still // catch typos in uniform names passed to immUniform*() functions? - #define GET_UNIFORM const ShaderInput* uniform = ShaderInterface_uniform(imm.shader_interface, name); if (uniform == NULL) return; + #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(imm.shader_interface, name); if (uniform == NULL) return; #endif void immUniform1f(const char* name, float x) @@ -860,7 +860,7 @@ void immUniform4iv(const char* name, const int data[4]) void immUniformColor4f(float r, float g, float b, float a) { - const ShaderInput* uniform = ShaderInterface_builtin_uniform(imm.shader_interface, UNIFORM_COLOR); + const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform_builtin(imm.shader_interface, GWN_UNIFORM_COLOR); #if TRUST_NO_ONE assert(uniform != NULL); diff --git a/intern/gawain/src/primitive.c b/intern/gawain/src/primitive.c index da32932c1e5..b9d92a6bdf8 100644 --- a/intern/gawain/src/primitive.c +++ b/intern/gawain/src/primitive.c @@ -12,51 +12,51 @@ #include "primitive.h" #include "primitive_private.h" -PrimitiveClass prim_class_of_type(PrimitiveType prim_type) +Gwn_PrimClass GWN_primtype_class(Gwn_PrimType prim_type) { - static const PrimitiveClass classes[] = + static const Gwn_PrimClass classes[] = { - [PRIM_POINTS] = PRIM_CLASS_POINT, - [PRIM_LINES] = PRIM_CLASS_LINE, - [PRIM_LINE_STRIP] = PRIM_CLASS_LINE, - [PRIM_LINE_LOOP] = PRIM_CLASS_LINE, - [PRIM_TRIANGLES] = PRIM_CLASS_SURFACE, - [PRIM_TRIANGLE_STRIP] = PRIM_CLASS_SURFACE, - [PRIM_TRIANGLE_FAN] = PRIM_CLASS_SURFACE, + [GWN_PRIM_POINTS] = GWN_PRIM_CLASS_POINT, + [GWN_PRIM_LINES] = GWN_PRIM_CLASS_LINE, + [GWN_PRIM_LINE_STRIP] = GWN_PRIM_CLASS_LINE, + [GWN_PRIM_LINE_LOOP] = GWN_PRIM_CLASS_LINE, + [GWN_PRIM_TRIS] = GWN_PRIM_CLASS_SURFACE, + [GWN_PRIM_TRI_STRIP] = GWN_PRIM_CLASS_SURFACE, + [GWN_PRIM_TRI_FAN] = GWN_PRIM_CLASS_SURFACE, - [PRIM_LINE_STRIP_ADJACENCY] = PRIM_CLASS_LINE, + [GWN_PRIM_LINE_STRIP_ADJ] = GWN_PRIM_CLASS_LINE, - [PRIM_NONE] = PRIM_CLASS_NONE + [GWN_PRIM_NONE] = GWN_PRIM_CLASS_NONE }; return classes[prim_type]; } -bool prim_type_belongs_to_class(PrimitiveType prim_type, PrimitiveClass prim_class) +bool GWN_primtype_belongs_to_class(Gwn_PrimType prim_type, Gwn_PrimClass prim_class) { - if (prim_class == PRIM_CLASS_NONE && prim_type == PRIM_NONE) + if (prim_class == GWN_PRIM_CLASS_NONE && prim_type == GWN_PRIM_NONE) return true; - return prim_class & prim_class_of_type(prim_type); + return prim_class & GWN_primtype_class(prim_type); } -GLenum convert_prim_type_to_gl(PrimitiveType prim_type) +GLenum convert_prim_type_to_gl(Gwn_PrimType prim_type) { #if TRUST_NO_ONE - assert(prim_type != PRIM_NONE); + assert(prim_type != GWN_PRIM_NONE); #endif static const GLenum table[] = { - [PRIM_POINTS] = GL_POINTS, - [PRIM_LINES] = GL_LINES, - [PRIM_LINE_STRIP] = GL_LINE_STRIP, - [PRIM_LINE_LOOP] = GL_LINE_LOOP, - [PRIM_TRIANGLES] = PRIM_CLASS_SURFACE, - [PRIM_TRIANGLE_STRIP] = GL_TRIANGLE_STRIP, - [PRIM_TRIANGLE_FAN] = GL_TRIANGLE_FAN, - - [PRIM_LINE_STRIP_ADJACENCY] = GL_LINE_STRIP_ADJACENCY, + [GWN_PRIM_POINTS] = GL_POINTS, + [GWN_PRIM_LINES] = GL_LINES, + [GWN_PRIM_LINE_STRIP] = GL_LINE_STRIP, + [GWN_PRIM_LINE_LOOP] = GL_LINE_LOOP, + [GWN_PRIM_TRIS] = GWN_PRIM_CLASS_SURFACE, + [GWN_PRIM_TRI_STRIP] = GL_TRIANGLE_STRIP, + [GWN_PRIM_TRI_FAN] = GL_TRIANGLE_FAN, + + [GWN_PRIM_LINE_STRIP_ADJ] = GL_LINE_STRIP_ADJACENCY, }; return table[prim_type]; diff --git a/intern/gawain/src/shader_interface.c b/intern/gawain/src/shader_interface.c index 24f0a9f0e54..dff2c06f531 100644 --- a/intern/gawain/src/shader_interface.c +++ b/intern/gawain/src/shader_interface.c @@ -21,24 +21,24 @@ #include <stdio.h> #endif -static const char* BuiltinUniform_name(BuiltinUniform u) +static const char* BuiltinUniform_name(Gwn_UniformBuiltin u) { static const char* names[] = { - [UNIFORM_NONE] = NULL, + [GWN_UNIFORM_NONE] = NULL, - [UNIFORM_MODELVIEW] = "ModelViewMatrix", - [UNIFORM_PROJECTION] = "ProjectionMatrix", - [UNIFORM_MVP] = "ModelViewProjectionMatrix", + [GWN_UNIFORM_MODELVIEW] = "ModelViewMatrix", + [GWN_UNIFORM_PROJECTION] = "ProjectionMatrix", + [GWN_UNIFORM_MVP] = "ModelViewProjectionMatrix", - [UNIFORM_MODELVIEW_INV] = "ModelViewInverseMatrix", - [UNIFORM_PROJECTION_INV] = "ProjectionInverseMatrix", + [GWN_UNIFORM_MODELVIEW_INV] = "ModelViewInverseMatrix", + [GWN_UNIFORM_PROJECTION_INV] = "ProjectionInverseMatrix", - [UNIFORM_NORMAL] = "NormalMatrix", + [GWN_UNIFORM_NORMAL] = "NormalMatrix", - [UNIFORM_COLOR] = "color", + [GWN_UNIFORM_COLOR] = "color", - [UNIFORM_CUSTOM] = NULL + [GWN_UNIFORM_CUSTOM] = NULL }; return names[u]; @@ -61,17 +61,17 @@ static unsigned hash_string(const char *str) return i; } -static void set_input_name(ShaderInput* input, const char* name) +static void set_input_name(Gwn_ShaderInput* input, const char* name) { input->name = name; input->name_hash = hash_string(name); } -// keep these in sync with BuiltinUniform order -#define FIRST_MAT4_UNIFORM UNIFORM_MODELVIEW -#define LAST_MAT4_UNIFORM UNIFORM_PROJECTION_INV +// keep these in sync with Gwn_UniformBuiltin order +#define FIRST_MAT4_UNIFORM GWN_UNIFORM_MODELVIEW +#define LAST_MAT4_UNIFORM GWN_UNIFORM_PROJECTION_INV -static bool setup_builtin_uniform(ShaderInput* input, const char* name) +static bool setup_builtin_uniform(Gwn_ShaderInput* input, const char* name) { // TODO: reject DOUBLE, IMAGE, ATOMIC_COUNTER gl_types @@ -80,7 +80,7 @@ static bool setup_builtin_uniform(ShaderInput* input, const char* name) switch (input->gl_type) { case GL_FLOAT_MAT4: - for (BuiltinUniform u = FIRST_MAT4_UNIFORM; u <= LAST_MAT4_UNIFORM; ++u) + for (Gwn_UniformBuiltin u = FIRST_MAT4_UNIFORM; u <= LAST_MAT4_UNIFORM; ++u) { const char* builtin_name = BuiltinUniform_name(u); if (match(name, builtin_name)) @@ -93,22 +93,22 @@ static bool setup_builtin_uniform(ShaderInput* input, const char* name) break; case GL_FLOAT_MAT3: { - const char* builtin_name = BuiltinUniform_name(UNIFORM_NORMAL); + const char* builtin_name = BuiltinUniform_name(GWN_UNIFORM_NORMAL); if (match(name, builtin_name)) { set_input_name(input, builtin_name); - input->builtin_type = UNIFORM_NORMAL; + input->builtin_type = GWN_UNIFORM_NORMAL; return true; } } break; case GL_FLOAT_VEC4: { - const char* builtin_name = BuiltinUniform_name(UNIFORM_COLOR); + const char* builtin_name = BuiltinUniform_name(GWN_UNIFORM_COLOR); if (match(name, builtin_name)) { set_input_name(input, builtin_name); - input->builtin_type = UNIFORM_COLOR; + input->builtin_type = GWN_UNIFORM_COLOR; return true; } } @@ -117,11 +117,11 @@ static bool setup_builtin_uniform(ShaderInput* input, const char* name) ; } - input->builtin_type = UNIFORM_CUSTOM; + input->builtin_type = GWN_UNIFORM_CUSTOM; return false; } -ShaderInterface* ShaderInterface_create(GLint program) +Gwn_ShaderInterface* GWN_shaderinterface_create(GLint program) { #if DEBUG_SHADER_INTERFACE printf("%s {\n", __func__); // enter function @@ -138,16 +138,16 @@ ShaderInterface* ShaderInterface_create(GLint program) const uint32_t name_buffer_len = uniform_ct * max_uniform_name_len + attrib_ct * max_attrib_name_len; // allocate enough space for input counts, details for each input, and a buffer for name strings - ShaderInterface* shaderface = calloc(1, offsetof(ShaderInterface, inputs) + input_ct * sizeof(ShaderInput) + name_buffer_len); + Gwn_ShaderInterface* shaderface = calloc(1, offsetof(Gwn_ShaderInterface, inputs) + input_ct * sizeof(Gwn_ShaderInput) + name_buffer_len); shaderface->uniform_ct = uniform_ct; shaderface->attrib_ct = attrib_ct; - char* name_buffer = (char*)shaderface + offsetof(ShaderInterface, inputs) + input_ct * sizeof(ShaderInput); + char* name_buffer = (char*)shaderface + offsetof(Gwn_ShaderInterface, inputs) + input_ct * sizeof(Gwn_ShaderInput); uint32_t name_buffer_offset = 0; for (uint32_t i = 0; i < uniform_ct; ++i) { - ShaderInput* input = shaderface->inputs + i; + Gwn_ShaderInput* input = shaderface->inputs + i; GLsizei remaining_buffer = name_buffer_len - name_buffer_offset; char* name = name_buffer + name_buffer_offset; GLsizei name_len = 0; @@ -181,7 +181,7 @@ ShaderInterface* ShaderInterface_create(GLint program) for (uint32_t i = 0; i < attrib_ct; ++i) { - ShaderInput* input = shaderface->inputs + uniform_ct + i; + Gwn_ShaderInput* input = shaderface->inputs + uniform_ct + i; GLsizei remaining_buffer = name_buffer_len - name_buffer_offset; char* name = name_buffer + name_buffer_offset; GLsizei name_len = 0; @@ -221,7 +221,7 @@ ShaderInterface* ShaderInterface_create(GLint program) { // realloc shaderface to shrink name buffer const size_t shaderface_alloc = - offsetof(ShaderInterface, inputs) + (input_ct * sizeof(ShaderInput)) + name_buffer_used; + offsetof(Gwn_ShaderInterface, inputs) + (input_ct * sizeof(Gwn_ShaderInput)) + name_buffer_used; const char* shaderface_orig_start = (const char*)shaderface; const char* shaderface_orig_end = &shaderface_orig_start[shaderface_alloc]; shaderface = realloc(shaderface, shaderface_alloc); @@ -232,7 +232,7 @@ ShaderInterface* ShaderInterface_create(GLint program) // each input->name will need adjustment (except static built-in names) for (uint32_t i = 0; i < input_ct; ++i) { - ShaderInput* input = shaderface->inputs + i; + Gwn_ShaderInput* input = shaderface->inputs + i; if (input->name >= shaderface_orig_start && input->name < shaderface_orig_end) input->name += delta; @@ -243,18 +243,18 @@ ShaderInterface* ShaderInterface_create(GLint program) return shaderface; } -void ShaderInterface_discard(ShaderInterface* shaderface) +void GWN_shaderinterface_discard(Gwn_ShaderInterface* shaderface) { // allocated as one chunk, so discard is simple free(shaderface); } -const ShaderInput* ShaderInterface_uniform(const ShaderInterface* shaderface, const char* name) +const Gwn_ShaderInput* GWN_shaderinterface_uniform(const Gwn_ShaderInterface* shaderface, const char* name) { const unsigned name_hash = hash_string(name); for (uint32_t i = 0; i < shaderface->uniform_ct; ++i) { - const ShaderInput* uniform = shaderface->inputs + i; + const Gwn_ShaderInput* uniform = shaderface->inputs + i; #if SUPPORT_LEGACY_GLSL if (uniform->name == NULL) continue; @@ -271,17 +271,17 @@ const ShaderInput* ShaderInterface_uniform(const ShaderInterface* shaderface, co return NULL; // not found } -const ShaderInput* ShaderInterface_builtin_uniform(const ShaderInterface* shaderface, BuiltinUniform builtin) +const Gwn_ShaderInput* GWN_shaderinterface_uniform_builtin(const Gwn_ShaderInterface* shaderface, Gwn_UniformBuiltin builtin) { #if TRUST_NO_ONE - assert(builtin != UNIFORM_NONE); - assert(builtin != UNIFORM_CUSTOM); + assert(builtin != GWN_UNIFORM_NONE); + assert(builtin != GWN_UNIFORM_CUSTOM); #endif // look up by enum, not name for (uint32_t i = 0; i < shaderface->uniform_ct; ++i) { - const ShaderInput* uniform = shaderface->inputs + i; + const Gwn_ShaderInput* uniform = shaderface->inputs + i; if (uniform->builtin_type == builtin) return uniform; @@ -289,14 +289,14 @@ const ShaderInput* ShaderInterface_builtin_uniform(const ShaderInterface* shader return NULL; // not found } -const ShaderInput* ShaderInterface_attrib(const ShaderInterface* shaderface, const char* name) +const Gwn_ShaderInput* GWN_shaderinterface_attr(const Gwn_ShaderInterface* shaderface, const char* name) { // attribs are stored after uniforms const uint32_t input_ct = shaderface->uniform_ct + shaderface->attrib_ct; const unsigned name_hash = hash_string(name); for (uint32_t i = shaderface->uniform_ct; i < input_ct; ++i) { - const ShaderInput* attrib = shaderface->inputs + i; + const Gwn_ShaderInput* attrib = shaderface->inputs + i; #if SUPPORT_LEGACY_GLSL if (attrib->name == NULL) continue; diff --git a/intern/gawain/src/vertex_buffer.c b/intern/gawain/src/vertex_buffer.c index 769a0842a7e..03691b0c21d 100644 --- a/intern/gawain/src/vertex_buffer.c +++ b/intern/gawain/src/vertex_buffer.c @@ -19,17 +19,17 @@ static unsigned vbo_memory_usage; -VertexBuffer* VertexBuffer_create(void) +Gwn_VertBuf* GWN_vertbuf_create(void) { - VertexBuffer* verts = malloc(sizeof(VertexBuffer)); - VertexBuffer_init(verts); + Gwn_VertBuf* verts = malloc(sizeof(Gwn_VertBuf)); + GWN_vertbuf_init(verts); return verts; } -VertexBuffer* VertexBuffer_create_with_format(const VertexFormat* format) +Gwn_VertBuf* GWN_vertbuf_create_with_format(const Gwn_VertFormat* format) { - VertexBuffer* verts = VertexBuffer_create(); - VertexFormat_copy(&verts->format, format); + Gwn_VertBuf* verts = GWN_vertbuf_create(); + GWN_vertformat_copy(&verts->format, format); if (!format->packed) VertexFormat_pack(&verts->format); return verts; @@ -38,24 +38,24 @@ VertexBuffer* VertexBuffer_create_with_format(const VertexFormat* format) // TODO: implement those memory savings } -void VertexBuffer_init(VertexBuffer* verts) +void GWN_vertbuf_init(Gwn_VertBuf* verts) { - memset(verts, 0, sizeof(VertexBuffer)); + memset(verts, 0, sizeof(Gwn_VertBuf)); } -void VertexBuffer_init_with_format(VertexBuffer* verts, const VertexFormat* format) +void GWN_vertbuf_init_with_format(Gwn_VertBuf* verts, const Gwn_VertFormat* format) { - VertexBuffer_init(verts); - VertexFormat_copy(&verts->format, format); + GWN_vertbuf_init(verts); + GWN_vertformat_copy(&verts->format, format); if (!format->packed) VertexFormat_pack(&verts->format); } -void VertexBuffer_discard(VertexBuffer* verts) +void GWN_vertbuf_discard(Gwn_VertBuf* verts) { if (verts->vbo_id) { - buffer_id_free(verts->vbo_id); - vbo_memory_usage -= VertexBuffer_size(verts); + GWN_buf_id_free(verts->vbo_id); + vbo_memory_usage -= GWN_vertbuf_size_get(verts); } #if KEEP_SINGLE_COPY else @@ -67,24 +67,24 @@ void VertexBuffer_discard(VertexBuffer* verts) free(verts); } -unsigned VertexBuffer_size(const VertexBuffer* verts) +unsigned GWN_vertbuf_size_get(const Gwn_VertBuf* verts) { return vertex_buffer_size(&verts->format, verts->vertex_ct); } -void VertexBuffer_allocate_data(VertexBuffer* verts, unsigned v_ct) +void GWN_vertbuf_data_alloc(Gwn_VertBuf* verts, unsigned v_ct) { - VertexFormat* format = &verts->format; + Gwn_VertFormat* format = &verts->format; if (!format->packed) VertexFormat_pack(format); verts->vertex_ct = v_ct; // Data initially lives in main memory. Will be transferred to VRAM when we "prime" it. - verts->data = malloc(VertexBuffer_size(verts)); + verts->data = malloc(GWN_vertbuf_size_get(verts)); } -void VertexBuffer_resize_data(VertexBuffer* verts, unsigned v_ct) +void GWN_vertbuf_data_resize(Gwn_VertBuf* verts, unsigned v_ct) { #if TRUST_NO_ONE assert(verts->vertex_ct != v_ct); // allow this? @@ -93,15 +93,15 @@ void VertexBuffer_resize_data(VertexBuffer* verts, unsigned v_ct) #endif verts->vertex_ct = v_ct; - verts->data = realloc(verts->data, VertexBuffer_size(verts)); + verts->data = realloc(verts->data, GWN_vertbuf_size_get(verts)); // TODO: skip realloc if v_ct < existing vertex count // extra space will be reclaimed, and never sent to VRAM (see VertexBuffer_prime) } -void VertexBuffer_set_attrib(VertexBuffer* verts, unsigned a_idx, unsigned v_idx, const void* data) +void GWN_vertbuf_attr_set(Gwn_VertBuf* verts, unsigned a_idx, unsigned v_idx, const void* data) { - const VertexFormat* format = &verts->format; - const Attrib* a = format->attribs + a_idx; + const Gwn_VertFormat* format = &verts->format; + const Gwn_VertAttr* a = format->attribs + a_idx; #if TRUST_NO_ONE assert(a_idx < format->attrib_ct); @@ -112,10 +112,10 @@ void VertexBuffer_set_attrib(VertexBuffer* verts, unsigned a_idx, unsigned v_idx memcpy((GLubyte*)verts->data + a->offset + v_idx * format->stride, data, a->sz); } -void VertexBuffer_fill_attrib(VertexBuffer* verts, unsigned a_idx, const void* data) +void GWN_vertbuf_attr_fill(Gwn_VertBuf* verts, unsigned a_idx, const void* data) { - const VertexFormat* format = &verts->format; - const Attrib* a = format->attribs + a_idx; + const Gwn_VertFormat* format = &verts->format; + const Gwn_VertAttr* a = format->attribs + a_idx; #if TRUST_NO_ONE assert(a_idx < format->attrib_ct); @@ -123,13 +123,13 @@ void VertexBuffer_fill_attrib(VertexBuffer* verts, unsigned a_idx, const void* d const unsigned stride = a->sz; // tightly packed input data - VertexBuffer_fill_attrib_stride(verts, a_idx, stride, data); + GWN_vertbuf_attr_fill_stride(verts, a_idx, stride, data); } -void VertexBuffer_fill_attrib_stride(VertexBuffer* verts, unsigned a_idx, unsigned stride, const void* data) +void GWN_vertbuf_attr_fill_stride(Gwn_VertBuf* verts, unsigned a_idx, unsigned stride, const void* data) { - const VertexFormat* format = &verts->format; - const Attrib* a = format->attribs + a_idx; + const Gwn_VertFormat* format = &verts->format; + const Gwn_VertAttr* a = format->attribs + a_idx; #if TRUST_NO_ONE assert(a_idx < format->attrib_ct); @@ -151,11 +151,11 @@ void VertexBuffer_fill_attrib_stride(VertexBuffer* verts, unsigned a_idx, unsign } } -static void VertexBuffer_prime(VertexBuffer* verts) +static void VertexBuffer_prime(Gwn_VertBuf* verts) { - const unsigned buffer_sz = VertexBuffer_size(verts); + const unsigned buffer_sz = GWN_vertbuf_size_get(verts); - verts->vbo_id = buffer_id_alloc(); + verts->vbo_id = GWN_buf_id_alloc(); glBindBuffer(GL_ARRAY_BUFFER, verts->vbo_id); // fill with delicious data & send to GPU the first time only glBufferData(GL_ARRAY_BUFFER, buffer_sz, verts->data, GL_STATIC_DRAW); @@ -169,7 +169,7 @@ static void VertexBuffer_prime(VertexBuffer* verts) #endif } -void VertexBuffer_use(VertexBuffer* verts) +void GWN_vertbuf_use(Gwn_VertBuf* verts) { if (verts->vbo_id) glBindBuffer(GL_ARRAY_BUFFER, verts->vbo_id); @@ -177,7 +177,7 @@ void VertexBuffer_use(VertexBuffer* verts) VertexBuffer_prime(verts); } -unsigned VertexBuffer_get_memory_usage(void) +unsigned GWN_vertbuf_get_memory_usage(void) { return vbo_memory_usage; } 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; |