.. index:: pair: class; EE::Graphics::VertexBuffer .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer: class EE::Graphics::VertexBuffer ================================ .. toctree:: :hidden: Overview ~~~~~~~~ The vertex buffer class holds vertex data. The vertex position, colors, texture coordinates and indexes. This is useful to accelerate and encapsulate data. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class VertexBuffer { public: // construction virtual :target:`~VertexBuffer`(); // methods static VertexBuffer* :ref:`New`(const :ref:`Uint32`& vertexFlags = :ref:`VERTEX_FLAGS_DEFAULT`, :ref:`PrimitiveType` drawType = :ref:`PRIMITIVE_QUADS`, const :ref:`Int32`& reserveVertexSize = 0, const :ref:`Int32`& reserveIndexSize = 0, :ref:`VertexBufferUsageType` usageType = :ref:`VertexBufferUsageType::Static`); static VertexBuffer* :ref:`NewVertexArray`(const :ref:`Uint32`& vertexFlags = :ref:`VERTEX_FLAGS_DEFAULT`, :ref:`PrimitiveType` drawType = :ref:`PRIMITIVE_QUADS`, const :ref:`Int32`& reserveVertexSize = 0, const :ref:`Int32`& reserveIndexSize = 0, :ref:`VertexBufferUsageType` usageType = :ref:`VertexBufferUsageType::Static`); void :ref:`addVertex`(const :ref:`Uint32`& type, const :ref:`Vector2f`& vertex); void :ref:`addVertex`(const :ref:`Vector2f`& vertex); void :ref:`addTextureCoord`(const :ref:`Vector2f`& vertexCoord, const :ref:`Uint32`& textureLevel = 0); void :ref:`addColor`(const :ref:`Color`& color); void :ref:`addIndex`(const :ref:`Uint32`& indexValue); void :ref:`setVertex`(const :ref:`Uint32`& index, const :ref:`Uint32`& type, const :ref:`Vector2f`& vertex); void :ref:`setVertex`(const :ref:`Uint32`& index, const :ref:`Vector2f`& vertex); void :ref:`setTextureCoord`(const :ref:`Uint32`& index, const :ref:`Vector2f`& vertexCoord, const :ref:`Uint32`& textureLevel = 0); void :ref:`setColor`(const :ref:`Uint32`& index, const :ref:`Color`& color); void :ref:`setIndex`(const :ref:`Uint32`& index, const :ref:`Uint32`& indexValue); void :ref:`resizeArray`(const :ref:`Uint32`& type, const :ref:`Uint32`& size); void :ref:`resizeIndices`(const :ref:`Uint32`& size); void :target:`addQuad`(const :ref:`Vector2f`& pos, const :ref:`Sizef`& size, const :ref:`Color`& color); void :target:`setQuad`(const :ref:`Vector2u`& gridPos, const :ref:`Vector2f`& pos, const :ref:`Sizef`& size, const :ref:`Color`& color); void :target:`setQuadColor`(const :ref:`Vector2u`& gridPos, const :ref:`Color`& color); void :target:`setQuadFree`(const :ref:`Vector2u`& gridPos, const :ref:`Vector2f`& pos0, const :ref:`Vector2f`& pos1, const :ref:`Vector2f`& pos2, const :ref:`Vector2f`& pos3, const :ref:`Color`& color); void :target:`setQuadTexCoords`(const :ref:`Vector2u`& gridPos, const :ref:`Rectf`& coords, const :ref:`Uint32`& textureLevel); void :target:`setGridSize`(const :ref:`Sizei`& size); std::vector<:ref:`Vector2f`>& :ref:`getPositionArray`(); std::vector<:ref:`Color`>& :ref:`getColorArray`(); std::vector<:ref:`Uint32`>& :ref:`getIndices`(); std::vector<:ref:`Vector2f`>& :ref:`getTextureCoordArray`(const :ref:`Uint32`& textureLevel); :ref:`Uint32` :ref:`getVertexCount`(); :ref:`Uint32` :ref:`getIndexCount`(); :ref:`Color` :ref:`getColor`(const :ref:`Uint32`& index); :ref:`Uint32` :ref:`getIndex`(const :ref:`Uint32`& index); void :ref:`setElementNum`(:ref:`Int32` num); const :ref:`Int32`& :ref:`getElementNum`() const; virtual void :ref:`bind`() = 0; virtual void :ref:`unbind`() = 0; virtual void :ref:`draw`() = 0; virtual bool :ref:`compile`() = 0; virtual void :ref:`update`(const :ref:`Uint32`& types, bool indices) = 0; virtual void :ref:`reload`() = 0; virtual void :ref:`clear`(); }; .. _details-class_e_e_1_1_graphics_1_1_vertex_buffer: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ The vertex buffer class holds vertex data. The vertex position, colors, texture coordinates and indexes. This is useful to accelerate and encapsulate data. Some example usage of this class: .. ref-code-block:: cpp // Creates a rounded rectangle. Polygon2f Poly = Polygon2f::createRoundedRectangle( 0, 0, 256, 50 ); VertexBuffer * VBO = VertexBuffer::New( VERTEX_FLAGS_PRIMITIVE, PRIMITIVE_TRIANGLE_FAN ); if ( NULL != VBO ) { // Upload the rounded rectangle data to the vertex buffer. for ( Uint32 i = 0; i < Poly.Size(); i++ ) { VBO->addVertex( Poly[i] ); // Adds the vertex position VBO->addColor( ColorA( 255, 255, 255, 255 ) ); // Adds the vertex color } // Compiles the buffered data VBO->compile(); } // ... in the main loop draw the VBO while ( win->isRunning() ) { ... VBO->bind(); // First must be binded. VBO->draw(); // Then rendered. VBO->unbind(); // Then unbinded to allow render other things. ... win->display() } Methods ------- .. index:: pair: function; New .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a3d4070299e250c06c3a28a762e94225e: .. ref-code-block:: cpp :class: doxyrest-title-code-block static VertexBuffer* New(const :ref:`Uint32`& vertexFlags = :ref:`VERTEX_FLAGS_DEFAULT`, :ref:`PrimitiveType` drawType = :ref:`PRIMITIVE_QUADS`, const :ref:`Int32`& reserveVertexSize = 0, const :ref:`Int32`& reserveIndexSize = 0, :ref:`VertexBufferUsageType` usageType = :ref:`VertexBufferUsageType::Static`) Creates a new Vertex Buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - vertexFlags - The vertex flags indicates which vertex data will be used. * - drawType - The type of the primitive to draw. * - reserveVertexSize - If the vertex size is known is possible to reserve the space in memory to avoid resizeing the array. * - reserveIndexSize - If the vertex size is known is possible to reserve the space in memory for the indices to avoid resizeing the array. * - usageType - This indicates the kind of usage VBO will have. It's only useful if VBO extensions are supported ( almost for sure that it's supported ). More information here: `http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml `__ .. rubric:: See also: :ref:`VertexFlags ` .. index:: pair: function; NewVertexArray .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a816f64501534ef33dcb1f27896332bd5: .. ref-code-block:: cpp :class: doxyrest-title-code-block static VertexBuffer* NewVertexArray(const :ref:`Uint32`& vertexFlags = :ref:`VERTEX_FLAGS_DEFAULT`, :ref:`PrimitiveType` drawType = :ref:`PRIMITIVE_QUADS`, const :ref:`Int32`& reserveVertexSize = 0, const :ref:`Int32`& reserveIndexSize = 0, :ref:`VertexBufferUsageType` usageType = :ref:`VertexBufferUsageType::Static`) Creates the simple vertex array implementation ( without VBOs or VAO ), which it's faster for many cases. .. index:: pair: function; addVertex .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a639fa162db7f66042634a13449b572c7: .. ref-code-block:: cpp :class: doxyrest-title-code-block void addVertex(const :ref:`Uint32`& type, const :ref:`Vector2f`& vertex) Adds a vertex of the type indicated to the buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - type - Can be the position or texture coordinates. * - vertex - The vexter data .. index:: pair: function; addVertex .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a4744f7954b08a2a19d55e98f0d6bbb5c: .. ref-code-block:: cpp :class: doxyrest-title-code-block void addVertex(const :ref:`Vector2f`& vertex) Adds a vertex position to the buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - vertex - The vexter data .. index:: pair: function; addTextureCoord .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a5e18c209929dce931eba81105ca263af: .. ref-code-block:: cpp :class: doxyrest-title-code-block void addTextureCoord(const :ref:`Vector2f`& vertexCoord, const :ref:`Uint32`& textureLevel = 0) Adds a vertex texture coordinate. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - vertexCoord - The vertex texture coordinate. * - textureLevel - Indicates the texture level if it's using multitextures. .. index:: pair: function; addColor .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a7f7779029dba21ee35ec9b6f57069657: .. ref-code-block:: cpp :class: doxyrest-title-code-block void addColor(const :ref:`Color`& color) Adds a color to the buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - color - The color value. .. index:: pair: function; addIndex .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1acf8b6d413a37aff6e7d3a076bcd3c1e1: .. ref-code-block:: cpp :class: doxyrest-title-code-block void addIndex(const :ref:`Uint32`& indexValue) Adds an index to the buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - indexValue - The index value. .. index:: pair: function; setVertex .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1abddaa3cfdd9f9f4e504548d48c615885: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setVertex(const :ref:`Uint32`& index, const :ref:`Uint32`& type, const :ref:`Vector2f`& vertex) Set a vertex index of the type indicated to the buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - index - The array index of the vertext to set * - type - Can be the position or texture coordinates. * - vertex - The vexter data .. index:: pair: function; setVertex .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a91001ee3e44177e910f20159b10f0daa: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setVertex(const :ref:`Uint32`& index, const :ref:`Vector2f`& vertex) Adds a vertex position to the buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - index - The array index of the vertext to set * - vertex - The vexter data .. index:: pair: function; setTextureCoord .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a06737f6419e220875b3397ad6babb5b6: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setTextureCoord(const :ref:`Uint32`& index, const :ref:`Vector2f`& vertexCoord, const :ref:`Uint32`& textureLevel = 0) Adds a vertex texture coordinate. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - index - The array index of the vertext to set * - vertexCoord - The vertex texture coordinate. * - textureLevel - Indicates the texture level if it's using multitextures. .. index:: pair: function; setColor .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a91e71f605404623b24c728e191a19a38: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setColor(const :ref:`Uint32`& index, const :ref:`Color`& color) Adds a color to the buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - index - The array index of the vertext to set * - color - The color value. .. index:: pair: function; setIndex .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a758b64157c640120fefa78ac79671112: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setIndex(const :ref:`Uint32`& index, const :ref:`Uint32`& indexValue) Adds an index to the buffer. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - index - The array index of the vertext to set * - indexValue - The index value. .. index:: pair: function; resizeArray .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1ae97749253d05a5f98da7e81e214a2591: .. ref-code-block:: cpp :class: doxyrest-title-code-block void resizeArray(const :ref:`Uint32`& type, const :ref:`Uint32`& size) Resizes the array of the type indicated. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - type - The type must be one of the vertex flags ( * - size - The size to be resized .. rubric:: See also: :ref:`VertexFlags `). .. index:: pair: function; resizeIndices .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a039841d1b161b3ab2a55a96e918845d9: .. ref-code-block:: cpp :class: doxyrest-title-code-block void resizeIndices(const :ref:`Uint32`& size) Resizes the indices array. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - size - The new size .. index:: pair: function; getPositionArray .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1ac064b84761f49a639ac74bdb0b14b8b5: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::vector<:ref:`Vector2f`>& getPositionArray() .. rubric:: Returns: The position array .. index:: pair: function; getColorArray .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a5073c8ec9d3fb1fa35a71d5c7021fece: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::vector<:ref:`Color`>& getColorArray() .. rubric:: Returns: The color array pointer. .. index:: pair: function; getIndices .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a6de3075a4e56101de589168be2159ccd: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::vector<:ref:`Uint32`>& getIndices() .. rubric:: Returns: The indices array pointer. .. index:: pair: function; getTextureCoordArray .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a4dd2c9f80e3378f369efd66c605c6e28: .. ref-code-block:: cpp :class: doxyrest-title-code-block std::vector<:ref:`Vector2f`>& getTextureCoordArray(const :ref:`Uint32`& textureLevel) .. rubric:: Returns: The texture coord array from the texture level .. index:: pair: function; getVertexCount .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a0809aba7b390f7f530b05904cacb0515: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Uint32` getVertexCount() .. rubric:: Returns: The number of vertex added. .. index:: pair: function; getIndexCount .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1aee731c26d90e4be16a0be1b44f1dade0: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Uint32` getIndexCount() .. rubric:: Returns: The number of indexes added. .. index:: pair: function; getColor .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a23116e596b810ccd56f05f01d079db61: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Color` getColor(const :ref:`Uint32`& index) .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - index - The position in the buffer. .. rubric:: Returns: The color at the buffer position. .. index:: pair: function; getIndex .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a491f2f43b3c9d856818dcbe14fa4a022: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`Uint32` getIndex(const :ref:`Uint32`& index) .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - index - The position in the buffer. .. rubric:: Returns: The index at the buffer position. .. index:: pair: function; setElementNum .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1adf2a41ab56c346d689f8e89636fc2e3b: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setElementNum(:ref:`Int32` num) Sets the number of elements to draw. If not set, it will draw all the elements. .. index:: pair: function; getElementNum .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a266efc5418242f0adc3d53aed3cf7008: .. ref-code-block:: cpp :class: doxyrest-title-code-block const :ref:`Int32`& getElementNum() const .. rubric:: Returns: The number of elements added. .. index:: pair: function; bind .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a640b0537e2e20048c32a3f6c7aa05b38: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual void bind() = 0 Activates the vertex buffer. .. index:: pair: function; unbind .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a5481378927c773f978adb80d420b23de: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual void unbind() = 0 Deactivates the vertex buffer. .. index:: pair: function; draw .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a5d092a07c00bca2b8895b234094cdebf: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual void draw() = 0 Draw the vertex buffer. .. index:: pair: function; compile .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a5723a6d7aedd7352944381c1eb2be76d: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual bool compile() = 0 Compile the vertex buffer. After adding all the vertex buffer data Compile() must be called to upload the data to the GPU. .. index:: pair: function; update .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1a4ab4c162e2b231db8ed12e0c8ee970d7: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual void update(const :ref:`Uint32`& types, bool indices) = 0 Update is used in the case of some data is modified and need to be reuploaded to the GPU. .. index:: pair: function; reload .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1aa3b8702778f9dd438d6c90977affaccb: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual void reload() = 0 Reupload all the data to the GPU. .. index:: pair: function; clear .. _doxid-class_e_e_1_1_graphics_1_1_vertex_buffer_1adc46b5368751752ae73560682e28f9bd: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual void clear() Clear the cached data and destroy the buffers