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