//////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2011, Computer Graphics Group RWTH Aachen University // // All rights reserved. // //////////////////////////////////////////////////////////////////////////////// #ifndef ACGL_OPENGL_OBJECTS_VERTEXBUFFER_HH #define ACGL_OPENGL_OBJECTS_VERTEXBUFFER_HH #include #include #include #include #include #include #include namespace ACGL{ namespace OpenGL{ class VertexBuffer { ACGL_NOT_COPYABLE(VertexBuffer) // ==================================================================================================== \/ // ============================================================================================ STRUCTS \/ // ==================================================================================================== \/ public: struct Attribute { std::string name; int_t bufferID; int_t attributeID; }; // ===================================================================================================== \/ // ============================================================================================ TYPEDEFS \/ // ===================================================================================================== \/ public: typedef std::vector< SharedArrayBuffer > ArrayBufferVec; typedef std::vector< Attribute > AttributeVec; // ========================================================================================================= \/ // ============================================================================================ CONSTRUCTORS \/ // ========================================================================================================= \/ public: VertexBuffer(void) : mpElementArrayBuffer(), mArrayBuffers(), mAttributes() {} virtual ~VertexBuffer(void) {}; // ==================================================================================================== \/ // ============================================================================================ GETTERS \/ // ==================================================================================================== \/ public: inline const SharedElementArrayBuffer& getElementArrayBuffer (void) const { return mpElementArrayBuffer; } inline const ArrayBufferVec& getArrayBuffers (void) const { return mArrayBuffers; } inline const AttributeVec& getAttributes (void) const { return mAttributes; } // ==================================================================================================== \/ // ============================================================================================ METHODS \/ // ==================================================================================================== \/ public: int_t getAttributeIndexByName(const std::string& _name) const; inline int_t getArrayBufferIDByAttributeIndex(AttributeVec::size_type _indexInArray) const { return mAttributes[_indexInArray].bufferID; } inline void setAttributePointer(AttributeVec::size_type _indexInArray, GLuint _indexInShader) const { mArrayBuffers[mAttributes[_indexInArray].bufferID]->setAttributePointer( mAttributes[_indexInArray].attributeID, _indexInShader); } void validate( void ) const; inline void setElementArrayBuffer(const SharedElementArrayBuffer& _elementArrayBuffer) { mpElementArrayBuffer = _elementArrayBuffer; } inline void attachArrayBuffer(const SharedArrayBuffer& _arrayBuffer) { mArrayBuffers.push_back(_arrayBuffer); } inline void removeArrayBuffers(void) { mArrayBuffers.clear(); } inline void attachAttribute( const std::string& _name, int_t _bufferID, const std::string& _attributeName) { Attribute attribute = { _name, _bufferID, mArrayBuffers[_bufferID]->getAttributeIndexByName(_attributeName)}; mAttributes.push_back(attribute); } inline void removeAttributes(void) { mAttributes.clear(); } // ===================================================================================================== \/ // ============================================================================================ WRAPPERS \/ // ===================================================================================================== \/ public: void enable ( void ) const; void disable( void ) const; inline void render ( void ) const { enable(); draw(); disable(); }; void drawElements(void) const { mpElementArrayBuffer->draw(); } void drawArrays(void) const { //If no ElementArrayBuffer is specified we use the convention that //the first ArrayBuffers determines the mode and the number of elements. mArrayBuffers[0]->draw(); } void draw(void) const { if(mpElementArrayBuffer) drawElements(); else drawArrays(); openGLRareError(); } // =================================================================================================== \/ // ============================================================================================ FIELDS \/ // =================================================================================================== \/ protected: SharedElementArrayBuffer mpElementArrayBuffer; ArrayBufferVec mArrayBuffers; AttributeVec mAttributes; }; ACGL_SHARED_TYPEDEF(VertexBuffer) } // OpenGL } // ACGL #endif // ACGL_OPENGL_OBJECTS_VERTEXBUFFER_HH