GL Studio C++ Runtime API
gls_render_effect.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsRenderEffect 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 #ifndef _GLS_RENDER_EFFECT_H
41 #define _GLS_RENDER_EFFECT_H
42 
43 #include "display_types.h"
44 #include "dynamic_array.h"
45 #include "material.h"
46 
47 #include "gls_version.h"
48 
49 #ifdef GLES
50 # include "gls_state_manager.h"
51 #endif
52 
53 //////////////////// Provides support for creating DLLs ////////////////////////
54 #if( defined( GLSGEN_EXPORT_GLSADVANCEDMESH ) || defined( GLSGEN_IMPORT_GLSADVANCEDMESH ) || defined( GLS_EXPORT_GENERATED ) || 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 namespace disti
67 {
68 // Forward declarations
69 class DisplayObject;
70 class TexturePalette;
71 class DistiAttribDict;
72 
73 typedef DynamicArray<int> ReferencedTextureArray;
74 typedef DynamicArray<int> ReferencedMaterialArray;
75 
76 // Abstract interface that is needed to tell
77 // the GlsGeometryResource which vertex attrib
78 // indices to use for a given rendering pass.
79 // (e.g. the attribute index to use can vary depending on
80 // the shader used).
82 {
83 public:
84  // These are the predefined semantic values from the Cg language
85  // Users should be able to define their own in the future, but these will be it for now.
86  typedef enum
87  {
88  ATTRIB_UNDEFINED = 0,
89  ATTRIB_POSITION = 0x80000000,
90  ATTRIB_NORMAL,
91  ATTRIB_BLENDWEIGHT,
92  ATTRIB_TANGENT,
93  ATTRIB_BINORMAL,
94  ATTRIB_BLENDINDICES,
95  ATTRIB_PSIZE,
96  ATTRIB_TEXCOORD0,
97  ATTRIB_TEXCOORD1,
98  ATTRIB_TEXCOORD2,
99  ATTRIB_TEXCOORD3,
100  ATTRIB_TEXCOORD4,
101  ATTRIB_TEXCOORD5,
102  ATTRIB_TEXCOORD6,
103  ATTRIB_TEXCOORD7
104  } AttributeSemanticEnum;
105 
106  /// \returns The attributeIndex that should be used to pass the vertex attributes or -1 if they are not needed (see glVertexAttrib)
107  /// \param semanticEnum The sematic value (see AttributeSemanticEnum)
108  virtual GLint GetVertexAttribIndexForSemantic( int semanticEnum ) = 0;
109 };
110 
111 /** Abstract render effect class
112  * Encapsulates an effect that can be applied to the OpenGL state to modify the appearance of geometry.
113  * This API currently only supports single pass techniques.
114  */
116 {
117 protected:
118  virtual ~GlsRenderEffect() {}
119 
120 public:
121  /** Manage references to the effect
122  */
123  virtual void AddRef() = 0;
124  virtual void Release() = 0;
125 
126  // Allows for static casting in compare functions
127  // See RegisterNewClassID
128  virtual unsigned int GlsRenderEffect_ClassID() const = 0;
129 
130  /** The TextureSettings class is used to provide the object-level
131  * texturing settings to the effect
132  */
134  {
135  public:
136  unsigned char _textureRepeat; /**< GL_TEXTURE_WRAP_* setting (0 or 1) */
137  unsigned char _textureMap; /**< The texturing map mode setting /sa TextureMap_e */
138  unsigned char _textureMagFilter; /**< The texturing magnification filter setting /sa TextureFilter_e */
139  unsigned char _textureMinFilter; /**< The texturing minification filter setting /sa TextureFilter_e */
140 
141  // Initialize the TextureSettings object with the given values
142  inline TextureSettings(
143  unsigned char textureRepeat = 1,
144  unsigned char textureMap = TEXTURE_MAP_REPLACE,
145  unsigned char textureMagFilter = TEXTURE_FILTER_LINEAR,
146  unsigned char textureMinFilter = TEXTURE_FILTER_LINEAR )
147  : _textureRepeat( textureRepeat )
148  , _textureMap( textureMap )
149  , _textureMagFilter( textureMagFilter )
150  , _textureMinFilter( textureMinFilter )
151  {}
152  };
153 #if( ( GLS_VERSION_MAJOR == 4 && ( GLS_VERSION_MINOR == 1 || GLS_VERSION_MINOR == 0 ) ) || GLS_VERSION_MAJOR <= 3 )
154  /// Apply the effect to the OpenGL state
155  /// \param materialPalette Used to access material settings
156  /// \param texturePalette Used to access texture maps
157  /// \param textureSettings The object-level texture settings
158  /// \param viewToWorld3x3 A 3x3 matrix containing the current viewToWorld transfrom. Used for environment mapping effects.
159  virtual void SetupEffect(
160  DynamicArray<Material, false>& materialPalette,
161  TexturePalette* texturePalette,
162  const TextureSettings& textureSettings,
163  float* viewToWorld3x3 // 3x3 matrix (float[9])
164  )
165  = 0;
166 #else
167  /// Apply the effect to the OpenGL state
168  /// \param materialPalette Used to access material settings
169  /// \param texturePalette Used to access texture maps
170  /// \param textureSettings The object-level texture settings
171  /// \param viewToWorld3x3 A 3x3 matrix containing the current viewToWorld transfrom. Used for environment mapping effects.
172  /// \param maxLightNum The number of active lights in the scene. Used to speed up light calculations.
173  /// \param activeLightMask A bit mask of which lights are active in the scene (Ex. GL_LIGHT0, GL_LIGHT2, GL_LIGHT3 and GL_LIGHT7 are active:
174  /// activeLightMask = ...10001101 last 8 bits in binary = 141u)
175  virtual void SetupEffect(
176  DynamicArray<Material, false>& materialPalette,
177  TexturePalette* texturePalette,
178  const TextureSettings& textureSettings,
179  float* viewToWorld3x3, // 3x3 matrix (float[9])
180  unsigned int maxLightNum,
181  unsigned int activeLightMask )
182  = 0;
183 
184 #endif
185 #if !defined( GLES ) || defined( GLES20 )
186  /// Remove the effect trom the OpenGL state
187  virtual void CleanupEffect() = 0;
188 #endif
189 
190  /** Returns 0 if the effects are equal,
191  * a positive number if this effect should sort after the other effect,
192  * and a negative number if this effect should sort before the other effect.
193  * The rendering system uses this to sort effects.
194  */
195  virtual int Compare( const GlsRenderEffect* other ) const = 0;
196 
197  /** Determine if two GlsRenderEffect instances are equivalent
198  * The rendering system uses this to eliminate redundant effects.
199  */
200  inline bool Equals( const GlsRenderEffect* other ) const { return Compare( other ) == 0; }
201 
202  virtual DistiAttribDict& Attributes() = 0;
203 
204  virtual const std::string& EffectTypeName() = 0;
205 
206  // TODO: Need an API to get / set effect instance parameters without knowing it's type
207  // There may be two classes of parameters:
208  // Initialization parameters: (e.g. Reference to a shader program or CG effect file to load)
209  // 'Runtime' parameters: The vertex attributes, maps, etc. that are an input to the effect.
210 
211  /** Returns a new instance of the effect with the same settings as this one */
212  virtual GlsRenderEffect* Clone() const = 0;
213 
214  /** Checks whether or not the effect is transparent. Implementing is optional */
215  //virtual bool HasTransparency() const {return false;}
216 
217  /** Inserts all referenced textures into the array passed in. Implementing is optional */
218  virtual void GetReferencedMaterials( ReferencedMaterialArray& referencedMaterials ){};
219 
220  /** Inserts all referenced textures into the array passed in. Implementing is optional */
221  virtual void GetReferencedTextures( ReferencedTextureArray& referencedTextures ){};
222 
223  // Enable / Disable a debug mode for all effects that support it
224  // \param modeName name of the mode to enable / disable
225  // \param value true to enable the mode, false to disable
226  // \returns the number of effect callbacks that recognized the mode change
227  static GLSGEN_GlsAdvancedMesh_EXPORT unsigned int SetDebugMode( const char* modeName, bool value );
228 
229  // Returns a new ClassID
230  // Typically only called once by each GlsRenderEffect implementation
231  static GLSGEN_GlsAdvancedMesh_EXPORT unsigned int RegisterNewClassID( const char* debugStr = NULL );
232 
233  // typedef for DebugMode change callbacks
234  // \see RegisterDebugModeChangeCallback
235  // \param user pointer that was provided when the callback was registered
236  // \param modeName name of the mode that is changing
237  // \param value true to enable the mode, false to disable
238  // \param returns true if the callback recognized the mode change, false otherwise
239  typedef bool ( *DebugModeChangeCallback )( void* user, const char* modeName, bool value );
240 
241  // Register for debug mode change notifications
242  // Note: Be sure to also Unregister!
243  // \see UnregisterDebugModeChangeCallback
244  // \param param user pointer that will be passed to the callback
245  // \param func pointer to the callback function
246  // \returns true on success
247  static GLSGEN_GlsAdvancedMesh_EXPORT bool RegisterDebugModeChangeCallback( void* param, DebugModeChangeCallback func );
248 
249  // Unregister for debug mode change notifications
250  // The parameters must match those that were passed when the callback was registered
251  // \see RegisterDebugModeChangeCallback
252  // \param param user pointer that was passed to RegisterDebugModeChangeCallback
253  // \param func function pointer that was passed to RegisterDebugModeChangeCallback
254  // \returns true if the callback was found and unregistered
255  static GLSGEN_GlsAdvancedMesh_EXPORT bool UnregisterDebugModeChangeCallback( void* param, DebugModeChangeCallback func );
256 };
257 
258 } // namespace disti
259 
260 #endif
virtual void GetReferencedMaterials(ReferencedMaterialArray &referencedMaterials)
Definition: gls_render_effect.h:218
The disti::Material class.
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
unsigned char _textureMap
Definition: gls_render_effect.h:137
virtual GlsRenderEffect * Clone() const =0
virtual GLint GetVertexAttribIndexForSemantic(int semanticEnum)=0
virtual int Compare(const GlsRenderEffect *other) const =0
bool Equals(const GlsRenderEffect *other) const
Definition: gls_render_effect.h:200
Definition: gls_render_effect.h:81
unsigned char _textureRepeat
Definition: gls_render_effect.h:136
The disti::GlsStateManager factory class. Creates an instance of a state manager that manages the GL ...
virtual void GetReferencedTextures(ReferencedTextureArray &referencedTextures)
Definition: gls_render_effect.h:221
Used for matching version of libraries and headers.
virtual void AddRef()=0
GL Studio Enumerations and constants.
Definition: display_types.h:64
Definition: disti_metadata.h:673
virtual void SetupEffect(DynamicArray< Material, false > &materialPalette, TexturePalette *texturePalette, const TextureSettings &textureSettings, float *viewToWorld3x3)=0
Definition: display_types.h:71
unsigned char _textureMagFilter
Definition: gls_render_effect.h:138
Definition: texture_palette.h:143
unsigned char _textureMinFilter
Definition: gls_render_effect.h:139
Definition: gls_render_effect.h:115
Definition: gls_render_effect.h:133
Definition: bmpimage.h:46
virtual void CleanupEffect()=0
Remove the effect trom the OpenGL state.