GL Studio C++ Runtime API
gls_geometry_resource_mesh.h
Go to the documentation of this file.
1/// \file gls_geometry_resource_mesh.h
2/// \brief The disti::GlsGeometryResourceMesh 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 INCLUDED_GLS_GEOMETRY_RESOURCE_MESH_H
40#define INCLUDED_GLS_GEOMETRY_RESOURCE_MESH_H
41
42#include "display.h"
45#include "gls_render_effect.h"
46#include <cstddef>
47
48/// Provides support for creating DLLs.
49#if( defined( GLSGEN_EXPORT_GLSADVANCEDMESH ) || defined( GLSGEN_IMPORT_GLSADVANCEDMESH ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
50 && defined( _MSC_VER )
51# if defined( GLSGEN_EXPORT_GLSADVANCEDMESH ) || defined( GLS_EXPORT_GENERATED )
52# define GLSGEN_GlsAdvancedMesh_EXPORT __declspec( dllexport )
53# else
54# define GLSGEN_GlsAdvancedMesh_EXPORT __declspec( dllimport )
55# endif
56#else
57# define GLSGEN_GlsAdvancedMesh_EXPORT
58#endif
59///////////////////////////////////////////////////////////////////////////////
60
61namespace disti
62{
63// Forward Declaration
64class GlsSortedDrawable;
65
66#ifdef GLES
67// Forward Declaration
68class GlsGloFileAttribute;
69#endif
70
71/**
72 This is an abstrace base class for objects that use a GlsGeometryResource for rendering (e.g. GlsAdvancedMesh)
73 This class implements Draw / Pick routines that use a RenderMesh provided by the derived classes. The appearance of the mesh is affected by the IndexBufferEffectsArray.
74 This class also implements Translate, Rotate, and Scale through a GeometryTransform matrix.
75*/
78{
79#if !defined( GLES )
80 friend class GlsGeometryResourceMesh_SortedDrawable;
81#endif
82
83public:
84 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
85 typedef DisplayObject _BaseClass; ///< Deprecated typedef for the base class.
86 typedef DisplayObject BaseClass; ///< Typedef for the base class.
87 friend class GlsGeometryResourceMeshEditor;
88
89 /** Create a new GlsGeometryResourceMesh */
91
92 /** Create a copy of a GlsGeometryResourceMesh
93 * \param that The GlsGeometryResourceMesh to copy from
94 * \param generateNames Whether or not to generate a new instance name for the copy
95 */
97
98 /** GlsGeometryResourceMesh destructor */
100
101 //////////////////////////////////////////////////
102 // Overridden base class methods
103 //////////////////////////////////////////////////
104
105 /* Callback for when a resource could invalidate the scene */
107 {
109 }
110
115
116#ifndef GLES
119#endif
120
123
125 GLSGEN_GlsAdvancedMesh_EXPORT void GetExtents( float& minx, float& miny, float& minz, float& maxx, float& maxy, float& maxz ) DISTI_METHOD_OVERRIDE;
126
127 GLSGEN_GlsAdvancedMesh_EXPORT DisplayObject* Pick3D( const Vector& winLoc, const Vector& logicalCoords, float scale, const Vector& directionVector, Vector& collisionWinLoc, const OpenGLMatrices& drawnMatrices ) DISTI_METHOD_OVERRIDE;
128
129 GLSGEN_GlsAdvancedMesh_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
130
131 GLSGEN_GlsAdvancedMesh_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar = 0 ) DISTI_METHOD_OVERRIDE;
132 GLSGEN_GlsAdvancedMesh_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis ) DISTI_METHOD_OVERRIDE;
134
135 /// Override base class since a mesh can have multiple textures.
136 /// \return -2 if multiple textures applied to object, -1 if no texture
137 /// otherwise if all faces use same texture, returns the texture
138 /// index that is shared by the faces.
140
141 /* Override base class since a mesh can have multiple textures */
143
144 /// Override base class since a mesh can have multiple textures.
145 /// \return Whether or not the OpenGL state changed.
147
148 /// \deprecated Use the signed int version of MaterialIndex instead.
149 /// \param index The material index to set.
150 DISTI_DEPRECATED( "Use the signed int version of MaterialIndex instead." )
151 virtual void MaterialIndex( unsigned int index ) { return MaterialIndex( static_cast<int>(index) ); };
152
153 /// Override base class since a mesh can have multiple materials.
154 /// \param index The material index to set.
156
157 /// Override base class since a mesh can have multiple materials.
158 /// \return The first index in the _materialIndices array.
160
161 /// Set the _materialIndices array for this object.
162 /// \param indices The new indices to set.
164
165 /* Override base class since a mesh can have multiple materials */
167
168 //////////////////////////////////////////////////
169 // GlsGeometryResourceMesh specific operations
170 //////////////////////////////////////////////////
171
172 /// Set the matrix that is applied before the geometry resource is drawn.
173 /// \param value The transform value to set.
175
176 /// Set the matrix that is applied before the geometry resource is drawn.
177 /// \param matrix Array of 16 doubles that make up the new transform matrix.
179
180 /**
181 * \returns The matrix that is applied before the geometry resource is drawn.
182 * Lifetime is guaranteed to coincide with the GlsGeometryResourceMesh's lifetime.
183 */
185
186 /**
187 * \returns The number of IndexBuffers in the current render mesh
188 */
189 unsigned int NumIndexBuffers()
190 {
191 return GetRenderMesh()->NumIndexBuffers();
192 }
193
194 /**
195 * \returns The size of the IndexBufferEffects array
196 */
198 {
199 return _indexBufferEffects.Count();
200 }
201
202 /// \return Whether or not the draw order of the mesh can be modified for performance.
203 bool ReorderAtWill() { return _reorderAtWill; }
204
205 /// Sets whether or not the draw order of the mesh can be modified for performance.
206 /// \param reorderAtWill The new reorder flag.
207 void ReorderAtWill( bool reorderAtWill ) { _reorderAtWill = reorderAtWill; }
208
209 /// Set the size of the IndexBufferEffects array.
210 /// This will release any effects that are no longer referenced.
211 /// \param newSize The new number of effects to set.
213
214 /** Access the GlsRenderEffect that is used to render the specified index buffer (may be NULL)
215 * \param bufferNum The IndexBuffer to get the effect for. Must be between 0 and NumIndexBuffers().
216 * \returns Pointer to the index buffer effect used when rendering the specified GlsGeometryResource IndexBuffer
217 */
218 GlsRenderEffect* GetIndexBufferEffect( unsigned int bufferNum )
219 {
220 if( bufferNum >= _indexBufferEffects.Count() )
221 {
222 return NULL;
223 }
224
225 return _indexBufferEffects[ bufferNum ];
226 }
227
228 /** Set the GlsRenderEffect to use when rendering the given index buffer.
229 * If this value is NULL, the geometry will be rendered with a default effect.
230 * Note: the GlsGeometryResourceMesh will increment the reference count on the new effect and release any effect that was previously referenced.
231 * \param bufferNum The IndexBuffer to get the effect for. Should be between 0 and NumIndexBuffers().
232 * \param newEffect [out] Pointer to the index buffer effect to use when rendering the specified GlsGeometryResource IndexBuffer.
233 */
234 void SetIndexBufferEffect( unsigned int bufferNum, GlsRenderEffect* newEffect )
235 {
236 if( bufferNum >= _indexBufferEffects.Count() )
237 {
238 ResizeIndexBufferEffectsArray( bufferNum + 1 );
239 }
240
241 GlsRenderEffect* oldEffect = _indexBufferEffects[ bufferNum ];
242 _indexBufferEffects[ bufferNum ] = newEffect;
243
244 if( newEffect )
245 {
246 newEffect->AddRef();
247 }
248 if( oldEffect )
249 {
250 oldEffect->Release();
251 }
252 }
253
254 /// Implemented by the derived class.
255 /// \return The mesh that should be rendered / picked.
257
258#ifdef GLES
259 /** Set a single attribute from the GLO file.
260 * \param data The attribute to set and its associated data.
261 */
263#endif
264
265protected:
266 GlsMatrixType _geometryTransform; ///< Transformation matrix to be applied to all geometry in this mesh.
267
268 DynamicArray<int> _newMaterialIndices; ///< Intermediate data storage to make the setting of new material indices through the Faces simpler.
269
270 bool _reorderAtWill; ///< Determines whether or not the draw order of this mesh can be modified to increase performance.
271
272 typedef DynamicArray<GlsRenderEffect*> IndexBufferEffectArrayT; ///< Typedef for a list of effects (shaders).
273 IndexBufferEffectArrayT _indexBufferEffects; ///< The effect to use for each index buffer.
274
275 class DistiAttributeIndexBufferEffectArray;
276
277#if !defined( GLES )
278 typedef DynamicArray<GlsSortedDrawable*> SortedDrawableArrayT; ///< Typedef for a list of sorted drawables.
279 SortedDrawableArrayT _indexBufferDrawables; ///< GlsSortedDrawable for each index buffer.
280#endif
281
282 /// Draw the given mesh object, used by internal draw code.
283 /// \note Not normally called by users.
284 /// \param renderMesh The mesh to draw.
286
287 /// Sets up the default shader program for mesh drawing.
288 /// \note Not normally called by users.
290
291 /// Resets the shader program state after mesh drawing.
292 /// \note Not normally called by users.
294
295 /// Draw all underlying mesh objects, used by internal draw code.
296 /// \note Not normally called by users.
298
299#ifdef GLES
300 /// Creates or updates an effect where the effect's properties apply based on what the data provides. Used by SetFromGloData.
301 /// \param data File that contains binary data about the buffer effect.
302 /// \return True if it successfully applied the index buffer effect. Returns false on error.
303 bool SetGloIndexBufferEffect( GlsGloFileAttribute& data );
304
305 /// Reads in the given file data to create and initialize the geometry data such as its vertices, normals, and bounding volume.
306 /// \param data File that contains binary data about this object's geometry.
307 /// \return The resulting geometry resource that has its vertices, normals, colors, and bounding volume initialized. Returns null if there's an error.
308 GlsGeometry_Generic* LoadGloGeometryResourceData( GlsGloFileAttribute& data );
309#endif
310
311private:
312 // Cache for the extents to prevent re-calculation when nothing has changed.
313 struct LastExtents
314 {
315 unsigned int id;
316 GlsMatrixType transformMatrix;
317 Vector min;
318 Vector max;
319
320 LastExtents()
321 : id( GlsGeometryResource::s_invalidDataChangedCounter )
322 {}
323 } _lastExtents;
324
325 // Disable implicit generated Members
328
329 void CopyGeometryInternal( const GlsGeometryResourceMesh& src );
330 /* Utility routines used to detect when the material indices has changed */
331 void OnMatChanged();
332 void OnMatChanged( DynamicArray<int>& a, DynamicArray<int>& b );
333 void ReplaceMaterial( unsigned int oldIndex, unsigned int newIndex );
334};
335
336// Used by code generator.
337/// \cond INTERNAL
338GLSGEN_GlsAdvancedMesh_EXPORT GlsRenderEffect* CreateRenderEffect_DiffNormSpecRefl(
339 unsigned int material_index,
340 int diffuse_texture_index,
341 int normal_texture_index,
342 int specular_texture_index,
343 int reflection_texture_index,
344 float diffuse_amount,
345 float normal_amount,
346 float specular_amount,
347 float reflection_amount,
348 bool useVertexColors,
349 bool normalFlipGreen,
350 float diff_map_offset_v = 0.0f,
351 float diff_map_offset_u = 0.0f,
352 float diff_map_tiling_u = 1.0f,
353 float diff_map_tiling_v = 1.0f,
354 float diff_map_angle_w = 0.0f,
355 float norm_map_offset_v = 0.0f,
356 float norm_map_offset_u = 0.0f,
357 float norm_map_tiling_u = 1.0f,
358 float norm_map_tiling_v = 1.0f,
359 float norm_map_angle_w = 0.0f,
360 float spec_map_offset_v = 0.0f,
361 float spec_map_offset_u = 0.0f,
362 float spec_map_tiling_u = 1.0f,
363 float spec_map_tiling_v = 1.0f,
364 float spec_map_angle_w = 0.0f );
365/// \endcond
366} // namespace disti
367
368#endif
Definition: cull.h:49
Definition: display.h:95
Definition: dynamic_array.h:79
unsigned Count() const
Definition: dynamic_array.h:218
Definition: gls_geometry_resource_mesh.h:78
DynamicArray< int > & MaterialIndices() DISTI_METHOD_OVERRIDE
void CopyGeometry(DisplayObject *src) DISTI_METHOD_OVERRIDE
void TranslateVertices(float x, float y, float z) DISTI_METHOD_OVERRIDE
unsigned int NumIndexBufferEffects()
Definition: gls_geometry_resource_mesh.h:197
bool ReorderAtWill()
Definition: gls_geometry_resource_mesh.h:203
virtual void ResizeIndexBufferEffectsArray(unsigned int newSize)
int TextureIndex() DISTI_METHOD_OVERRIDE
void SetGeometryTransform(const GlsMatrixType &value)
void CopyProperties(DisplayObject *src) DISTI_METHOD_OVERRIDE
SortedDrawableArrayT _indexBufferDrawables
GlsSortedDrawable for each index buffer.
Definition: gls_geometry_resource_mesh.h:279
bool _reorderAtWill
Determines whether or not the draw order of this mesh can be modified to increase performance.
Definition: gls_geometry_resource_mesh.h:270
void SetAvailableAttributes(unsigned int value) DISTI_METHOD_OVERRIDE
void GetTransformedExtents(Vector &min, Vector &max, const GlsMatrixType &matrix, bool resetMinMax=true) DISTI_METHOD_OVERRIDE
void GetCppInterfaceDescriptionFree(InterfaceListType *array) DISTI_METHOD_OVERRIDE
virtual GlsGeometryResource * GetRenderMesh()=0
IndexBufferEffectArrayT _indexBufferEffects
The effect to use for each index buffer.
Definition: gls_geometry_resource_mesh.h:273
GlsRenderEffect * GetIndexBufferEffect(unsigned int bufferNum)
Definition: gls_geometry_resource_mesh.h:218
int MaterialIndex() DISTI_METHOD_OVERRIDE
DynamicArray< GlsRenderEffect * > IndexBufferEffectArrayT
Typedef for a list of effects (shaders).
Definition: gls_geometry_resource_mesh.h:272
void DrawIndexBuffers(GlsGeometryResource *renderMesh)
DynamicArray< GlsSortedDrawable * > SortedDrawableArrayT
Typedef for a list of sorted drawables.
Definition: gls_geometry_resource_mesh.h:278
DisplayObject * Pick3D(const Vector &winLoc, const Vector &logicalCoords, float scale, const Vector &directionVector, Vector &collisionWinLoc, const OpenGLMatrices &drawnMatrices) DISTI_METHOD_OVERRIDE
void OnGeometryResourceChanged() DISTI_METHOD_OVERRIDE
Callback method to be called by this observer.
Definition: gls_geometry_resource_mesh.h:106
GlsMatrixType _geometryTransform
Transformation matrix to be applied to all geometry in this mesh.
Definition: gls_geometry_resource_mesh.h:266
void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler) DISTI_METHOD_OVERRIDE
void Draw() DISTI_METHOD_OVERRIDE
void ReorderAtWill(bool reorderAtWill)
Definition: gls_geometry_resource_mesh.h:207
void MaterialIndex(int index) DISTI_METHOD_OVERRIDE
bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) DISTI_METHOD_OVERRIDE
DynamicArray< int > _newMaterialIndices
Intermediate data storage to make the setting of new material indices through the Faces simpler.
Definition: gls_geometry_resource_mesh.h:268
unsigned int NumIndexBuffers()
Definition: gls_geometry_resource_mesh.h:189
void Scale(float px, float py, float pz, Vertex *anchor, int handleBar=0) DISTI_METHOD_OVERRIDE
virtual void MaterialIndex(unsigned int index)
Definition: gls_geometry_resource_mesh.h:151
void UpdateBoundingVolume() DISTI_METHOD_OVERRIDE
InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) DISTI_METHOD_OVERRIDE
void GetExtents(float &minx, float &miny, float &minz, float &maxx, float &maxy, float &maxz) DISTI_METHOD_OVERRIDE
void Rotate(const Vector &orig, float angle, const Vector &axis) DISTI_METHOD_OVERRIDE
void SetIndexBufferEffect(unsigned int bufferNum, GlsRenderEffect *newEffect)
Definition: gls_geometry_resource_mesh.h:234
const GlsMatrixType & GetGeometryTransform()
Definition: gls_geometry_resource_mesh.h:184
Definition: gls_geometry_resource.h:294
Definition: gls_geometry_resource.h:86
unsigned int NumIndexBuffers() const
Definition: gls_geometry_resource.h:477
Definition: gls_geometry_resource.h:513
Definition: gls_glo_file.h:1241
Definition: gls_render_effect.h:115
virtual void Release()=0
Release a reference to this object.
virtual void AddRef()=0
Add to this object's reference count.
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:540
Definition: vertex.h:84
Definition: vertex.h:419
The disti::DisplayObject class and global enumerations.
Macros and helper code to determine what subset of C++11/14/17 is available.
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:245
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:487
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:221
The disti::GlsGeometryResource class.
#define GLSGEN_GlsAdvancedMesh_EXPORT
Provides support for creating DLLs.
Definition: gls_geometry_resource_mesh.h:57
The disti::GlsRenderEffect class.
Definition: bmpimage.h:46