X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fvertexsetup.h;h=1cdedc79e7bf2c4186f78c0b59304d800a58564e;hp=51183af52b64a1e3b9d521511a255215cb626955;hb=HEAD;hpb=a5a26e4e2eb2d0b05c3531b667411be657ac74f1 diff --git a/source/core/vertexsetup.h b/source/core/vertexsetup.h index 51183af5..1cdedc79 100644 --- a/source/core/vertexsetup.h +++ b/source/core/vertexsetup.h @@ -1,64 +1,78 @@ #ifndef MSP_GL_VERTEXSETUP_H_ #define MSP_GL_VERTEXSETUP_H_ -#include "bindable.h" +#include "datatype.h" #include "vertexformat.h" +#include "vertexsetup_backend.h" namespace Msp { namespace GL { +class Buffer; class VertexArray; /** -Combines a VertexArray with an index buffer. This wraps OpenGL's vertex array -objects. Intended for internal use. +Combines vertex and instance attributes and an index buffer for a complete +description of vertex input state. + +Applications normally don't need to deal with VertexSetups directly. They're +managed by the Mesh and InstanceArray classes. */ -class VertexSetup: public Bindable +class VertexSetup: public VertexSetupBackend { + friend VertexSetupBackend; + private: enum ComponentMask { VERTEX_ARRAY = 1, INSTANCE_ARRAY = 2, - INDEX_BUFFER = 4, - UNUSED_ATTRIBS = 8, - ATTRIB_SHIFT = 4 + INDEX_BUFFER = 4 }; - unsigned id; - mutable unsigned dirty; - const VertexArray *vertex_array; + mutable unsigned dirty = 0; + const VertexArray *vertex_array = 0; VertexFormat vertex_format; - const VertexArray *inst_array; + const VertexArray *inst_array = 0; VertexFormat inst_format; - const Buffer *index_buffer; + const Buffer *index_buffer = 0; + DataType index_type = UNSIGNED_SHORT; public: - VertexSetup(); - ~VertexSetup(); + /** Sets format for vertex data. Instance attributes won't be used. The + format cannot be changed once set. */ + void set_format(const VertexFormat &); + + /** Sets formats for both vertex and instance data. The formats cannot be + changed once set. */ + void set_format_instanced(const VertexFormat &, const VertexFormat &); + /** Sets the VertexArray to use as the source of vertex attribute values. + The array's format must match the VertexSetup's vertex format. */ void set_vertex_array(const VertexArray &); - void set_instance_array(const VertexArray *); - void set_index_buffer(const Buffer &); - void refresh(); + + /** Sets the VertexArray to use as the source of instance attribute values. + An instance format must be defined and the array's format must match it. */ + void set_instance_array(const VertexArray &); + + /** Sets the buffer containing index data and the type of indices. */ + void set_index_buffer(const Buffer &, DataType); + const VertexArray *get_vertex_array() const { return vertex_array; } const VertexArray *get_instance_array() const { return inst_array; } const Buffer *get_index_buffer() const { return index_buffer; } + DataType get_index_type() const { return index_type; } private: - static bool verify_array(const VertexArray &); - static unsigned get_attribs(const VertexFormat &); - static unsigned get_update_mask(unsigned, const VertexFormat &, const VertexArray &); - void update(unsigned) const; - void update_vertex_array(const VertexArray &, unsigned, unsigned, bool) const; + static bool verify_format(const VertexFormat &); + void update() const; public: - void bind() const; - static void unbind(); + void refresh() const { if(dirty) update(); } void unload(); - void set_debug_name(const std::string &); + using VertexSetupBackend::set_debug_name; }; } // namespace GL