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