diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-09-15 17:51:10 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-09-15 17:51:10 +0300 |
commit | 39f7a8117692da3a6645ccb7ae2080077f9e5980 (patch) | |
tree | 0062f4acb59e8afa5ebb8e9e811e107b9de9c04f /source/blender/gpu/gawain/batch.h | |
parent | 0d54d32dd608be5d87d3d57131ede33a8f19aa37 (diff) |
Gawain: batch rendering API
Follow-up to rBddb1d5648dbd
API is nearly complete but untested.
1) create batch with vertex buffer & optional index buffer
2) choose shader program
3) draw!
Diffstat (limited to 'source/blender/gpu/gawain/batch.h')
-rw-r--r-- | source/blender/gpu/gawain/batch.h | 130 |
1 files changed, 42 insertions, 88 deletions
diff --git a/source/blender/gpu/gawain/batch.h b/source/blender/gpu/gawain/batch.h index 9625d666a41..8387b0144a3 100644 --- a/source/blender/gpu/gawain/batch.h +++ b/source/blender/gpu/gawain/batch.h @@ -13,34 +13,53 @@ #include "vertex_buffer.h" #include "element.h" -#include "attrib_binding.h" - -// How will this API be used? -// create batch -// ... -// profit! - -// TODO: finalize Batch struct design & usage, pare down this file - -typedef struct { - VertexBuffer; // format is fixed at "vec3 pos" - ElementList line_elem; - ElementList triangle_elem; - GLuint vao_id; - GLenum prev_prim; // did most recent draw use GL_POINTS, GL_LINES or GL_TRIANGLES? -} BasicBatch; - -// How to do this without replicating code? typedef struct { + // geometry VertexBuffer* verts; - ElementList* elem; // <-- NULL if element list not needed + ElementList* elem; // NULL if element list not needed GLenum prim_type; - GLuint vao_id; - GLuint bound_program; - AttribBinding attrib_binding; + + // book-keeping + GLuint vao_id; // remembers all geometry state (vertex attrib bindings & element buffer) + bool program_dirty; + + // state + GLuint program; } Batch; +Batch* Batch_create(GLenum prim_type, VertexBuffer*, ElementList*); + +void Batch_set_program(Batch*, GLuint program); +// 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_draw(Batch*); + + + + + + +#if 0 // future plans + +// Can multiple batches share a VertexBuffer? Use ref count? + + +// for multithreaded batch building: +typedef enum { + READY_TO_FORMAT, + READY_TO_BUILD, + BUILDING, BUILDING_IMM, // choose one + READY_TO_DRAW +} BatchPhase; + + +Batch* immBeginBatch(GLenum prim_type, unsigned v_ct); +// use standard immFunctions after this. immEnd will finalize the batch instead +// of drawing. + + // We often need a batch with its own data, to be created and discarded together. // WithOwn variants reduce number of system allocations. @@ -67,69 +86,4 @@ Batch* create_BatchWithOwnVertexBufferAndElementList(GLenum prim_type, VertexFor // elem: none, shared, own Batch* create_BatchInGeneral(GLenum prim_type, VertexBufferStuff, ElementListStuff); -typedef struct { - // geometry - GLenum prim_type; - VertexBuffer verts; - ElementList elem; // <-- elem.index_ct = 0 if element list not needed - - // book-keeping - GLuint vao_id; // <-- remembers all vertex state (array buffer, element buffer, attrib bindings) - // wait a sec... I thought VAO held attrib bindings but not currently bound array buffer. - // That's fine but verify that VAO holds *element* buffer binding. - // Verified: ELEMENT_ARRAY_BUFFER_BINDING is part of VAO state. - // VERTEX_ATTRIB_ARRAY_BUFFER_BINDING is too, per vertex attrib. Currently bound ARRAY_BUFFER is not. - // Does APPLE_vertex_array_object also include ELEMENT_ARRAY_BUFFER_BINDING? - // The extension spec refers only to APPLE_element_array, so.. maybe, maybe not? - // Will have to test during development, maybe alter behavior for APPLE_LEGACY. Can strip out this - // platform-specific cruft for Blender, keep it for legacy Gawain. - - // state - GLuint bound_program; - AttribBinding attrib_binding; -} Batch; - -typedef struct { - Batch* batch; -} BatchBuilder; - -// One batch can be drawn with multiple shaders, as long as those shaders' inputs -// are compatible with the batch's vertex format. - -// Can multiple batches share a VertexBuffer? Use ref count? - -// BasicBatch -// Create one VertexBuffer from an object's verts (3D position only) -// Shader must depend only on position + uniforms: uniform color, depth only, or object ID. -// - draw verts via DrawArrays -// - draw lines via DrawElements (can have 2 element lists: true face edges, triangulated edges) -// - draw faces via DrawElements (raw triangles, not polygon faces) -// This is very 3D-mesh-modeling specific. I'm investigating what Gawain needs to allow/expose -// to meet Blender's needs, possibly other programs' needs. - -Batch* BatchPlease(GLenum prim_type, unsigned prim_ct, unsigned v_ct); -// GL_TRIANGLES 12 triangles that share 8 vertices - -// Is there ever a reason to index GL_POINTS? nothing comes to mind... -// (later) ok now that I'm thinking straight, *of course* you can draw -// indexed POINTS. Only some verts from the buffer will be drawn. I was -// just limiting my thinking to immediate needs. Batched needs. - -Batch* batch = BatchPlease(GL_TRIANGLES, 12, 8); -unsigned pos = add_attrib(batch->verts.format, "pos", GL_FLOAT, 3, KEEP_FLOAT); -pack(batch->verts->format); // or ... -finalize(batch); // <-- packs vertex format, allocates vertex buffer - -Batch* create_Batch(GLenum prim_type, VertexBuffer*, ElementList*); - -// and don't forget -Batch* immBeginBatch(GLenum prim_type, unsigned v_ct); -// use standard immFunctions after this. immEnd will finalize the batch instead -// of drawing. - -typedef enum { - READY_TO_FORMAT, - READY_TO_BUILD, - BUILDING, BUILDING_IMM, // choose one - READY_TO_DRAW -} BatchPhase; +#endif // future plans |