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