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