GL Studio C++ Runtime API
gls_triangle_storage.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsTriangleStrip2D class.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2017 by The DiSTI Corporation.<br>
7  11301 Corporate Blvd., Suite 100<br>
8  Orlando, Florida 32817<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  */
40 
41 #ifndef GLS_TRIANGLE_STORAGE_H
42 #define GLS_TRIANGLE_STORAGE_H
43 
44 #include "dynamic_array.h"
45 #include "gls_gl.h"
46 #include "gls_include.h"
48 #include "gls_state_manager.h"
49 #include "non_copyable.h"
50 #include "vertex.h"
51 
52 namespace disti
53 {
54 class Image;
55 
57 {
58 public:
59  /** Constant sizes of the primitive vertex attributes */
60  static const GLuint VERT_SIZE = sizeof( V2f );
61  static const GLuint TEX_SIZE = sizeof( V2f );
62 
63  /** Constant offsets to the primitive vertex attributes.
64  * \note Theoretically should be GLuints, but OpenGL's functions to pass integer offsets as pointers.
65  */
66  static const void* const VERT_OFFSET;
67  static const void* const TEX_COORD_OFFSET;
68 
69  /** Default constructor
70  */
72 
73  /** Destructor
74  */
75  virtual ~GlsTriangleStrip2D();
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  */
82  void StartBuildingStrip();
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  /** Returns the number of triangles in this strip */
132  unsigned int GetNumTriangles()
133  {
134  return _numTriangles;
135  }
136 
137 protected:
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 */
155  void AllocateNextTriangle();
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: gls_triangle_storage.h:56
unsigned int GetNumTriangles()
Definition: gls_triangle_storage.h:132
Definition: image.h:162
Definition: gls_primitive_storage_types.h:50
bool _stripified
Definition: gls_triangle_storage.h:152
The disti::V2f, disti::V2f_C4ub, disti::V3f_C4ub, disti::V2f_T2f_C4ub, and the disti::V2f_T2f structs...
void Draw(IGlsStateManager *stateManager, const bool enableTexture)
void Bake(IGlsStateManager *stateManager)
Definition: dynamic_array.h:66
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
unsigned int _vboHandle
Definition: gls_triangle_storage.h:149
A base class for objects that are not copyable via the standard C++ copy constructor.
void AddTriangle2D(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
void SetTexture(Image *image)
Definition: gls_state_manager_interface.h:67
The disti::GlsStateManager factory class. Creates an instance of a state manager that manages the GL ...
A file for all GL Studio files to include.
static const GLuint VERT_SIZE
Definition: gls_triangle_storage.h:60
DynamicArray< V2f_T2f, true > _vertData
Definition: gls_triangle_storage.h:141
unsigned int _stripSize
Definition: gls_triangle_storage.h:139
The disti::Vertex class. A class for manipulating 3D vertices.
void SetTexCoords(const float x1, const float y1, const float x2, const float y2, const float x3, const float y3)
static const void *const VERT_OFFSET
Definition: gls_triangle_storage.h:66
V2f _currentTex[3]
Definition: gls_triangle_storage.h:142
Image * _texture
Definition: gls_triangle_storage.h:147
unsigned int _numTriangles
Definition: gls_triangle_storage.h:138
Definition: non_copyable.h:45
Definition: bmpimage.h:46
The gls_gl.