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