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