GL Studio C++ Runtime API
gls_es20_effect.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsEffect class. Holds information pertaining to shader programs and their uniform/attribute data
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. Use, distribution,
38 duplication, or disclosure by the U. S. Government is subject to
39 "Restricted Rights" as set forth in DFARS 252.227-7014(c)(1)(ii).
40 
41 */
42 
43 #ifndef DISTI_GLS_ES20_EFFECT_H_INCLUDED
44 #define DISTI_GLS_ES20_EFFECT_H_INCLUDED
45 
46 #include "dynamic_array.h"
47 #include "gls_es20_effect_params.h"
48 #include "gls_es20_uniform.h"
49 #include "gls_gl.h"
50 #include <map>
51 
52 namespace disti
53 {
54 /** The GlsEffect Class. This class stores program objects and lists of uniforms.
55 * Because all construction methods are private, Effects can be only created with the
56 * friend Factory class.
57 */
58 class GlsEffect
59 {
60  /** Only the effect factory should be creating new effects. */
61  friend class GlsEffectFactoryImpl;
62  friend class std::map<GLuint, GlsEffect>;
63  friend class DynamicArray<GlsEffect, false>;
64 
65 public:
66  /** Get uniform data for one of the standard uniforms.
67  * \param[in] uniform The standard uniform enum (\see StdUniforms_e)
68  * \pre uniform is a valid StdUniforms_e
69  * \return the uniform
70  */
71  GLS_EXPORT GlsUniform* GetStdUniform( StdUniforms_e uniform );
72 
73  /** Get uniform data for one of the custom uniforms.
74  * \param[in] uniform The custom uniform's ID
75  * \return the uniform
76  */
77  GLS_EXPORT GlsUniform* GetCustomUniform( GLint uniform );
78 
79  /** Get attribute location
80  * \param[in] attribute The standard attribute to query (\see StdAttribs_e)
81  * \pre attribute is a valid StdAttribs_e
82  * \return The attribute's location
83  */
84  GLS_EXPORT GLuint GetAttribLocation( StdAttribs_e attribute );
85 
86  /** Compile and link vertex and fragment shaders, creating a program object.
87  * \param[in] vertexShader The vertex shader.
88  * \param[in] fragmentShader The fragment shader.
89  * \return The newly created program object, or 0 on error.
90  */
91  GLS_EXPORT GLuint CreateShader( const GLchar* vertexShader, const GLchar* fragmentShader );
92 
93  /** Create a custom uniform to add to this effect's list of custom uniforms
94  * \param[in] uniformName The string representing the name of this uniform
95  * \return the ID corresponding to this custom uniform's position in the array, or -1 on failure
96  */
97  GLS_EXPORT GLint CreateCustomUniform( const char* uniformName );
98 
99  /** Indicates if this effect was successfully loaded or not
100  * \return true if the effect has been successfully loaded
101  */
102  GLS_EXPORT bool IsInitialized( void );
103 
104  /** Use the program for this effect.
105  */
106  GLS_EXPORT void UseProgram( void );
107 
108  /** Get the program object associated with this effect.
109  * \return the program object
110  */
111  GLS_EXPORT GLuint GetProgramObject( void );
112 
113  /** dtor */
114  GLS_EXPORT ~GlsEffect();
115 
116 protected:
117  /** Delete/destroy the shader program and its shaders
118  * \pre none
119  * \post shaders are deleted
120  * \post _programObject == 0
121  */
122  void FreeShaders( GLuint vertObject, GLuint fragObject );
123 
124  /** Load and compile a new shader.
125  * \param[in] shaderType The type of shader this is
126  * \param[in] shaderSource The code for the shader
127  * \pre shaderType is GL_VERTEX_SHADER or GL_FRAGMENT_SHADER
128  * \return The shader object's ID or 0 on failure.
129  */
130  GLuint LoadAndCompileShader( GLenum shaderType, const char* shaderSource );
131 
132  /** This effect's program object. */
134 
135  /** Standard uniform types. Index values can be acquired from the factory. */
136  GlsUniform _stdUniforms[ MAX_STD_UNIFORMS ];
137 
138  /** Custom uniform types for custom shaders. */
140 
141  /** The attributes for this effect. */
142  GLint _attribLocations[ MAX_STD_ATTRIBS ];
143 
144 private:
145  /** Private constructor.
146  * This class should only be instantiated by the GlsEffectFactory class.
147  */
148  GlsEffect( void );
149 
150  // disallow
151  GlsEffect( const GlsEffect& src );
152  GlsEffect& operator=( const GlsEffect& rhs );
153 };
154 
155 } // namespace disti
156 
157 #endif // DISTI_GLS_ES20_EFFECT_H_INCLUDED
Definition: gls_es20_uniform.h:51
Definition: gls_es20_effect.h:58
Definition: dynamic_array.h:62
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
GLuint CreateShader(const GLchar *vertexShader, const GLchar *fragmentShader)
StdUniforms_e
Definition: gls_es20_effect_params.h:49
GLuint GetProgramObject(void)
GlsUniform * GetCustomUniform(GLint uniform)
GLuint LoadAndCompileShader(GLenum shaderType, const char *shaderSource)
Strings and other standard enumerations used in effects.
DynamicArray< GlsUniform, false > _customUniforms
Definition: gls_es20_effect.h:139
void UseProgram(void)
Templated class to hold uniform data for ES20 effects.
bool IsInitialized(void)
StdAttribs_e
Definition: gls_es20_effect_params.h:133
GLint CreateCustomUniform(const char *uniformName)
friend class GlsEffectFactoryImpl
Definition: gls_es20_effect.h:61
GLint _attribLocations[MAX_STD_ATTRIBS]
Definition: gls_es20_effect.h:142
GlsUniform _stdUniforms[MAX_STD_UNIFORMS]
Definition: gls_es20_effect.h:136
GlsUniform * GetStdUniform(StdUniforms_e uniform)
void FreeShaders(GLuint vertObject, GLuint fragObject)
GLuint GetAttribLocation(StdAttribs_e attribute)
Definition: bmpimage.h:46
GLuint _programObject
Definition: gls_es20_effect.h:133
The gls_gl.