GL Studio C++ Runtime API
gls_vertex_array.h
Go to the documentation of this file.
1/// \file gls_vertex_array.h
2/// \brief An object for managing vertices, texture coordinates, colors and normals for GLPolygon and other display objects
3/// Used for porting DisplayObjects which use immediate mode drawing to use VBOs
4///
5/// \par Copyright Information
6///
7/// Copyright (c) 2017 by The DiSTI Corporation.<br>
8/// 12249 Science Drive; Suite 300<br>
9/// Orlando, Florida 32826<br>
10/// USA<br>
11/// <br>
12/// All rights reserved.<br>
13///
14/// This Software contains proprietary trade secrets of DiSTI and may not be
15/// reproduced, in whole or part, in any form, or by any means of electronic,
16/// mechanical, or otherwise, without the written permission of DiSTI. Said
17/// permission may be derived through the purchase of applicable DiSTI product
18/// licenses which detail the distribution rights of this content and any
19/// Derivative Works based on this or other copyrighted DiSTI Software.
20///
21/// NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
22/// AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
23/// PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
24/// AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
25/// IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
26/// PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
27///
28/// LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
29/// IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
30/// INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
31/// DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
32/// INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
33/// INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
34/// OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
35/// EXCEED FIVE DOLLARS (US$5.00).
36///
37/// The aforementioned terms and restrictions are governed by the laws of the
38/// State of Florida and the United States of America.
39
40#ifndef GLS_VERTEX_ARRAY_H
41#define GLS_VERTEX_ARRAY_H
42
43#include "dynamic_array.h"
44#include "gls_color.h"
45#include "gls_gl.h"
46#include "gls_include.h"
47#include "gls_index_array.h"
48#include "image.h"
49#include "non_copyable.h"
50#include "vertex.h"
51
52namespace disti
53{
54class GlsStateManager;
55
56/// \details The GlsVertexArray class. This holds a number of Vertex objects in a resizeable buffer.
58{
59public:
60 static const GLuint VERT_SIZE = sizeof( float ) * 3; ///< Size of a vertex in bytes.
61 static const GLuint TEX_SIZE = sizeof( float ) * 2; ///< Size of a texture coordinate in bytes.
62 static const GLuint NORMAL_SIZE = sizeof( float ) * 3; ///< Size of a normal in bytes.
63 static const GLuint COLOR_SIZE = sizeof( unsigned char ) * 4; ///< Size of a color in bytes.
64
65 /** Default constructor
66 */
68
69 /** Destructor
70 */
72
73 /** Prepare the vertex buffer to be populated. Allocates vertex buffer, sets up component offsets.
74 * \param nVerts Number of vertices in the array
75 * \param hasT True if array has texture coords
76 * \param hasC True if array has colors
77 * \param hasN True if array has normas
78 */
79 GLS_EXPORT void Setup( const int nVerts, const bool hasT, const bool hasC, const bool hasN );
80
81 /** Sets the vertices of the array
82 * \pre _setup == true
83 * \param verts An array of vertices to populate this object with. verts[] must have at least _nVerts elements
84 */
85 GLS_EXPORT void SetVertices( const Vertex verts[] );
86
87 /** Sets the texture coordinates of the array
88 * \pre (_setup && _hasT)
89 * \param verts An array of texture coords to populate this object with. verts[] must have at least _nVerts elements
90 */
91 GLS_EXPORT void SetTexCoords( const Vector verts[] );
92
93 /** Sets the Normals of the array
94 * \pre (_setup && _hasN)
95 * \param verts An array of normals to populate this object with. verts[] must have at least _nVerts elements
96 */
97 GLS_EXPORT void SetNormals( const Vector verts[] );
98
99 /** Sets the Colors of the array. Note: This takes an array of Vertex for compatibility with DisplayObject.
100 * It gets the colors from the color component of the vertices.
101 * \pre (_setup && _hasC)
102 * \param verts An array of colors to populate this object with. verts[] must have at least _nVerts elements
103 */
104 GLS_EXPORT void SetColors( const Vertex verts[] );
105
106 /** Sets a single vertex
107 * \pre _setup && (index < _nVerts)
108 * \param index The index of the vertex to set
109 * \param v The vertex to set
110 */
111 GLS_EXPORT void SetVertex( const unsigned int index, const Vector& v );
112
113 /// Retrieves a single vertex.
114 /// \pre _setup && (index < _nVerts0
115 /// \param index The index of the vertex to retrieve.
116 /// \param result The vertex to copy to.
117 GLS_EXPORT void GetVertex (const unsigned int index, Vector& result);
118
119 /** Sets a single texture coordinate
120 * \pre _setup && (index < _nVerts) && _hasT
121 * \param index The index of the texture coordinate to set
122 * \param v The texture coordinate to set
123 */
124 GLS_EXPORT void SetTexCoord( const unsigned int index, const Vector& v );
125
126 /** Bake the vertex buffer to a VBO
127 * \pre _setup == true
128 * \param stateManager State manager for the OpenGL context to bake the VBO in
129 */
130 GLS_EXPORT void Bake( IGlsStateManager* stateManager );
131
132 /** Draw this vertex array
133 * \pre _setup == true
134 * \post The VBO is drawn
135 * \param glPrimitive The OpenGL primitive type to draw (e.g. GL_LINE_LOOP)
136 * \param stateManager State manager for the OpenGL context to draw in
137 * \param texture Whether or not to draw with texture
138 * \param color Whether or not to use per vertex colors
139 * \param normal Whether or not to use per vertex normals
140 */
141 GLS_EXPORT void Draw( const unsigned int glPrimitive, IGlsStateManager* stateManager, const bool texture, const bool color, const bool normal );
142
143 /** Draw this vertex array
144 * \pre _setup == true
145 * \post The VBO is drawn
146 * \param glPrimitive The OpenGL primitive type to draw (e.g. GL_LINE_LOOP)
147 * \param offset Index of the first vertex to draw
148 * \param count Number of primitives to draw
149 * \param indexBuffer Index buffer to use
150 * \param stateManager State manager for the OpenGL context to draw in
151 * \param texture Whether or not to draw with texture
152 * \param color Whether or not to use per vertex colors
153 * \param normal Whether or not to use per vertex normals
154 */
155 GLS_EXPORT void Draw( const unsigned int glPrimitive, const unsigned int offset, const unsigned int count, GlsIndexArray& indexBuffer, IGlsStateManager* stateManager,
156 const bool texture, const bool color, const bool normal );
157
158 /** Draw this vertex array
159 * \pre _setup == true
160 * \post The VBO is drawn
161 * \param glPrimitive The OpenGL primitive type to draw (e.g. GL_LINE_LOOP)
162 * \param offset Index of the first vertex to draw
163 * \param count Number of primitives to draw
164 * \param primitiveSize Number of vertices per primitive
165 * \param indexBuffer Index buffer to use
166 * \param stateManager State manager for the OpenGL context to draw in
167 * \param texture Whether or not to draw with texture
168 * \param color Whether or not to use per vertex colors
169 * \param normal Whether or not to use per vertex normals
170 */
171 GLS_EXPORT void MultiDraw( const unsigned int glPrimitive, const unsigned int offset, const unsigned int count, const unsigned int primitiveSize, GlsIndexArray& indexBuffer, IGlsStateManager* stateManager, const bool texture, const bool color, const bool normal );
172
173protected:
174 unsigned char* _vertexData; /**< Contains the dynamically allocated, interleaved vertex data that gets sent to the VBO */
175
176 unsigned int _vboHandle; /**< OpenGL VBO handle */
177 unsigned int _bufferSize; /**< Size of data pointed to by _vertexData */
178 bool _setup; /**< True if this object has been setup and can be downloaded to a VBO */
179
180 bool _hasT; /**< True if this object has texture coordinates */
181 bool _hasN; /**< True if this object has normals */
182 bool _hasC; /**< True if this object has colors */
183
184 unsigned int _componentSize; /**< Size of one element of this array (total size of all components) in bytes */
185 unsigned int _texOffset; /**< Offset of the texture coords from the beginning of a component, in bytes */
186 unsigned int _normalOffset; /**< Offset of the normals from the beginning of a component, in bytes */
187 unsigned int _colorOffset; /**< Offset of the color from the beginning of a component, in bytes */
188 unsigned int _nVerts; /**< Number of vertices in this object */
189
190 /** Allocates the buffer data, copying the existing data
191 * \param size The new size in bytes to allocate
192 */
193 void AllocateBuffer( const unsigned int size );
194
195 /** Deallocates the buffer data
196 */
198};
199
200} // namespace disti
201
202#endif
Definition: gls_index_array.h:50
Definition: gls_vertex_array.h:58
static const GLuint TEX_SIZE
Size of a texture coordinate in bytes.
Definition: gls_vertex_array.h:61
void Draw(const unsigned int glPrimitive, IGlsStateManager *stateManager, const bool texture, const bool color, const bool normal)
unsigned int _bufferSize
Definition: gls_vertex_array.h:177
bool _hasC
Definition: gls_vertex_array.h:182
void SetNormals(const Vector verts[])
void Setup(const int nVerts, const bool hasT, const bool hasC, const bool hasN)
unsigned char * _vertexData
Definition: gls_vertex_array.h:174
unsigned int _componentSize
Definition: gls_vertex_array.h:184
static const GLuint COLOR_SIZE
Size of a color in bytes.
Definition: gls_vertex_array.h:63
static const GLuint VERT_SIZE
Size of a vertex in bytes.
Definition: gls_vertex_array.h:60
unsigned int _nVerts
Definition: gls_vertex_array.h:188
void GetVertex(const unsigned int index, Vector &result)
static const GLuint NORMAL_SIZE
Size of a normal in bytes.
Definition: gls_vertex_array.h:62
void SetTexCoords(const Vector verts[])
void SetTexCoord(const unsigned int index, const Vector &v)
void SetVertex(const unsigned int index, const Vector &v)
unsigned int _colorOffset
Definition: gls_vertex_array.h:187
bool _setup
Definition: gls_vertex_array.h:178
unsigned int _normalOffset
Definition: gls_vertex_array.h:186
unsigned int _vboHandle
Definition: gls_vertex_array.h:176
bool _hasT
Definition: gls_vertex_array.h:180
unsigned int _texOffset
Definition: gls_vertex_array.h:185
void SetColors(const Vertex verts[])
void AllocateBuffer(const unsigned int size)
void MultiDraw(const unsigned int glPrimitive, const unsigned int offset, const unsigned int count, const unsigned int primitiveSize, GlsIndexArray &indexBuffer, IGlsStateManager *stateManager, const bool texture, const bool color, const bool normal)
void Draw(const unsigned int glPrimitive, const unsigned int offset, const unsigned int count, GlsIndexArray &indexBuffer, IGlsStateManager *stateManager, const bool texture, const bool color, const bool normal)
bool _hasN
Definition: gls_vertex_array.h:181
void Bake(IGlsStateManager *stateManager)
void SetVertices(const Vertex verts[])
Definition: gls_state_manager_interface.h:65
Definition: non_copyable.h:46
Definition: vertex.h:84
Definition: vertex.h:419
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
The Color class: Implements a 4 component RGBA color.
The gls_gl.
A file for all GL Studio files to include.
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:50
The disti::GlsIndexArray class, for managing index buffers.
The Image class. All textures are converted internally into Images.
Definition: bmpimage.h:46
A base class for objects that are not copyable via the standard C++ copy constructor.
The disti::Vertex class. A class for manipulating 3D vertices.