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