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