GL Studio C++ Runtime API
gls_triangle_storage.h
Go to the documentation of this file.
1/// \file gls_triangle_storage.h
2/// \brief The disti::GlsTriangleStrip2D class.
3///
4/// \par Copyright Information
5///
6/// Copyright (c) 2017 by The DiSTI Corporation.<br>
7/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<br>
9/// USA<br>
10/// <br>
11/// All rights reserved.<br>
12///
13/// This Software contains proprietary trade secrets of DiSTI and may not be
14/// reproduced, in whole or part, in any form, or by any means of electronic,
15/// mechanical, or otherwise, without the written permission of DiSTI. Said
16/// permission may be derived through the purchase of applicable DiSTI product
17/// licenses which detail the distribution rights of this content and any
18/// Derivative Works based on this or other copyrighted DiSTI Software.
19///
20/// NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21/// AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22/// PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23/// AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24/// IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25/// PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26///
27/// LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28/// IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29/// INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30/// DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31/// INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32/// INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33/// OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34/// EXCEED FIVE DOLLARS (US$5.00).
35///
36/// The aforementioned terms and restrictions are governed by the laws of the
37/// State of Florida and the United States of America.
38
39#ifndef GLS_TRIANGLE_STORAGE_H
40#define GLS_TRIANGLE_STORAGE_H
41
42#include "dynamic_array.h"
43#include "gls_gl.h"
44#include "gls_include.h"
46#include "gls_state_manager.h"
47#include "non_copyable.h"
48#include "vertex.h"
49
50namespace disti
51{
52class Image;
53
54/// \details The GlsTriangleStrip2D class. Wraps an OpenGL triangle strip drawable.
56{
57public:
58 static const GLuint VERT_SIZE = sizeof( V2f ); ///< Size of a vertex in bytes.
59 static const GLuint TEX_SIZE = sizeof( V2f ); ///< Size of a texture coordinate in bytes.
60
61 /// Constant offsets to the primitive vertex attribute.
62 /// \note Theoretically should be GLuints, but OpenGL's functions to pass integer offsets as pointers.
63 static const void* const VERT_OFFSET;
64
65 /// Constant offsets to the primitive texture coordinate attribute.
66 /// \note Theoretically should be GLuints, but OpenGL's functions to pass integer offsets as pointers.
67 static const void* const TEX_COORD_OFFSET;
68
69 /** Default constructor
70 */
72
73 /** Destructor
74 */
76
77 /** Sets this object into strip building mode. During strip building mode the user adds individual triangles to the strip
78 * When strip building mode is finished, the object will create a triangle strip from the individual triangles
79 * \pre none
80 * \post _stripified == false
81 */
83
84 /** Set the texture to be used for this triangle strip. The triangle strip may only have one texture, so it is an error to call this
85 * more than once after StartBuildingStrip() has been called.
86 * \pre _texture == NULL && _stripified == false
87 * \post _texture == img
88 * \param image The texture to assign, or NULL if no texture
89 */
90 void SetTexture( Image* image );
91
92 /** Set the texture coordinates to be used for the next triangle that is added (or subsequent triangles if this is not called again
93 * \param x1 X coord of vertex 1
94 * \param y1 Y coord of vertex 1
95 * \param x2 X coord of vertex 2
96 * \param y2 Y coord of vertex 2
97 * \param x3 X coord of vertex 3
98 * \param y3 Y coord of vertex 3
99 * \pre _texture != NULL && _stripified == false
100 * \post _currentTex contains input values
101 */
102 void SetTexCoords( const float x1, const float y1, const float x2, const float y2, const float x3, const float y3 );
103
104 /** Add the next triangle to the strip. Must be connected using previous two vertices of strip or be degenerate
105 * \param x1 X coord of vertex 1
106 * \param y1 Y coord of vertex 1
107 * \param x2 X coord of vertex 2
108 * \param y2 Y coord of vertex 2
109 * \param x3 X coord of vertex 3
110 * \param y3 Y coord of vertex 3
111 * \pre _stripified == false
112 * \post _numTriangles++, triangle is added to strip
113 */
114 void AddTriangle2D( const float x1, const float y1, const float x2, const float y2, const float x3, const float y3 );
115
116 /** Finish building strip and bake it to a VBO
117 * \param stateManager StateManager object to issue GL commands to
118 * \pre _stripified == false
119 * \pre _stripified == true
120 */
121 void Bake( IGlsStateManager* stateManager );
122
123 /** Draw the triangle strip
124 * \param stateManager StateManager object to issue GL commands to
125 * \param enableTexture True if strip will be drawn textured
126 * \pre _stripified == true
127 * \post The strip is drawn
128 */
129 void Draw( IGlsStateManager* stateManager, const bool enableTexture );
130
131 /// \return The number of triangles in this strip.
132 unsigned int GetNumTriangles()
133 {
134 return _numTriangles;
135 }
136
137protected:
138 unsigned int _numTriangles; /**< The number of triangles in the strip */
139 unsigned int _stripSize; /**< The number of vertices in the strip */
140
141 DynamicArray<V2f_T2f, true> _vertData; /**< DynamicArray to store vertex and texture coordinates */
142 V2f _currentTex[ 3 ]; /**< Current texture coordinates supplied for current triangle
143 (Texture coordinates are not required to change per triangle)
144 Used only while building list.
145 */
146
147 Image* _texture; /**< Texture to use when drawing strip. NULL if untextured */
148
149 unsigned int _vboHandle; /**< VBO Handle for this triangle strip */
150 unsigned int _vboBufferSize; /**< Size of the VBO buffer. Cached to so that when a strip is cleared and reset
151 we will only reallocate the VBO when its size changes. */
152 bool _stripified; /**< True if triangles have been created into a strip */
153
154 /** Allocate the next triangle in the set of ordered, connected triangles */
156
157 /** Convert the set of ordered, connected triangles in this object into tristrip
158 * \pre _stripified == false
159 * \pre _stripified == true
160 */
161 void Stripify();
162};
163
164} // namespace disti
165
166#endif
Definition: dynamic_array.h:79
Definition: gls_triangle_storage.h:56
static const GLuint TEX_SIZE
Size of a texture coordinate in bytes.
Definition: gls_triangle_storage.h:59
DynamicArray< V2f_T2f, true > _vertData
Definition: gls_triangle_storage.h:141
static const void *const TEX_COORD_OFFSET
Definition: gls_triangle_storage.h:67
void SetTexCoords(const float x1, const float y1, const float x2, const float y2, const float x3, const float y3)
unsigned int _vboBufferSize
Definition: gls_triangle_storage.h:150
unsigned int GetNumTriangles()
Definition: gls_triangle_storage.h:132
V2f _currentTex[3]
Definition: gls_triangle_storage.h:142
static const void *const VERT_OFFSET
Definition: gls_triangle_storage.h:63
static const GLuint VERT_SIZE
Size of a vertex in bytes.
Definition: gls_triangle_storage.h:58
unsigned int _numTriangles
Definition: gls_triangle_storage.h:138
void SetTexture(Image *image)
void Draw(IGlsStateManager *stateManager, const bool enableTexture)
void AddTriangle2D(const float x1, const float y1, const float x2, const float y2, const float x3, const float y3)
unsigned int _stripSize
Definition: gls_triangle_storage.h:139
unsigned int _vboHandle
Definition: gls_triangle_storage.h:149
Image * _texture
Definition: gls_triangle_storage.h:147
void Bake(IGlsStateManager *stateManager)
bool _stripified
Definition: gls_triangle_storage.h:152
Definition: gls_state_manager_interface.h:65
Definition: image.h:176
Definition: non_copyable.h:46
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
The gls_gl.
A file for all GL Studio files to include.
The disti::V2f, disti::V2f_C4ub, disti::V3f_C4ub, disti::V2f_T2f_C4ub, and the disti::V2f_T2f structs...
The disti::GlsStateManager factory class. Creates an instance of a state manager that manages the GL ...
Definition: bmpimage.h:46
A base class for objects that are not copyable via the standard C++ copy constructor.
Definition: gls_primitive_storage_types.h:50
The disti::Vertex class. A class for manipulating 3D vertices.