API Documentation
Loading...
Searching...
No Matches
GLESShader.h
Go to the documentation of this file.
1#pragma once
8#include <QOpenGLContext>
9#include <QFile>
10namespace NDEVR
11{
12 /**--------------------------------------------------------------------------------------------------
13 \brief A Shader for rendering default OpenGL logic to the graphics card.
14 **/
16 {
17 public:
35 GLESShader(ShaderType type, bool is_integer, const DynamicPointer<GLESGraphicsDevice>& device);
38 void compile(ShaderPart type, const char* src);
39 void linkShader();
40 void compileShader(ShaderPart type, const String& shader);
41 String versionedShaderCode(ShaderPart type, const char* src) const;
42 int uniformLocation(const char* const location) const;
43 uint04 id() const;
44 template<class t_type>
45 void setUniformValue(const char* const location, const t_type& value)
46 {
47 int var = uniformLocation(location);
48 if (var == -1)
49 return;
50 setUniformValue(var, value);
51 }
52 template<size_t t_size>
53 void setUniformValue(int location, const fltp04(&value)[t_size])
54 {
55 m_device->glUniform1fv(location, t_size, &value[0]);
56 }
57 template<size_t t_size>
58 void setUniformValue(int location, const uint04(&value)[t_size])
59 {
60 m_device->glUniform1uiv(location, t_size, &value[0]);
61 }
62 template<size_t t_size>
63 void setUniformValue(int location, const RGBColor(&value)[t_size])
64 {
65 m_device->glUniform1uiv(location, t_size, &value[0]);
66 }
67 template<uint01 t_size>
68 void setUniformValue(int location, const Vector<t_size, fltp04>& value)
69 {
70 m_device->glUniform1fv(location, t_size, &value[0]);
71 }
72 template<uint01 t_size>
73 void setUniformValue(int location, const Vector<t_size, RGBColor>& value)
74 {
75 m_device->glUniform1uiv(location, t_size, (uint04*)&value[0]);
76 }
77 void setUniformValue(int location, const Vector<3, sint04>& value);
78 void setUniformValue(int location, const Vector<3, fltp04>& value);
79 void setUniformValue(int location, const Vector<4, sint04>& value);
80 void setUniformValue(int location, const Vector<4, fltp04>& value);
81 void setUniformValue(int location, const Matrix<fltp04>& value);
82 void setUniformValue(int location, const fltp04& value);
83 void setUniformValue(int location, const uint04& value);
84 void setUniformValue(int location, const RGBColor& value);
85 void setUniformValue(int location, const Buffer<fltp04>& value);
86 void bind();
87 private:
88 void checkCompileErrors(GLuint shader, String type) const;
89 private:
90 uint04 m_program_id = Constant<uint04>::Invalid;
94 mutable Dictionary<uint04, int> m_shader_variables;
96 ShaderType m_shader_type;
97 bool m_is_int = false;
98 };
99 /**--------------------------------------------------------------------------------------------------
100 \brief Manages all shaders used with OpenGL and the NDEVR API
101 **/
103 {
104 public:
106 : m_device(device)
107 {
108 }
110 {
111 return m_int_shaders;
112 }
114 {
115 return m_flt_shaders;
116 }
118 {
119 if (is_int)
120 {
121 auto iter = m_int_shaders.find(id);
122 if (iter != m_int_shaders.end())
123 return iter.value();
125 m_int_shaders[id] = shader;
126 return shader;
127 }
128 else
129 {
130 auto iter = m_flt_shaders.find(id);
131 if (iter != m_flt_shaders.end())
132 return iter.value();
134 m_flt_shaders[id] = shader;
135 return shader;
136 }
137 }
139 {
140 DynamicPointer<GLESShader> shader = new GLESShader(id, is_int, m_device);
141 shader->compileAndLink();
142 return shader;
143 }
144 private:
148 };
149}
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:320
A Shader for rendering default OpenGL logic to the graphics card.
Definition GLESShader.h:16
void setUniformValue(int location, const uint04(&value)[t_size])
Definition GLESShader.h:58
void setUniformValue(int location, const Vector< 4, sint04 > &value)
void compileShader(ShaderPart type, const String &shader)
void setUniformValue(int location, const Vector< 4, fltp04 > &value)
String versionedShaderCode(ShaderPart type, const char *src) const
void setUniformValue(int location, const Vector< t_size, RGBColor > &value)
Definition GLESShader.h:73
void compile(ShaderPart type, const char *src)
ShaderType
Definition GLESShader.h:19
@ e_simple_points
Definition GLESShader.h:20
@ e_solid
Definition GLESShader.h:23
@ e_solid_grid
Definition GLESShader.h:24
@ e_linework
Definition GLESShader.h:22
@ e_solid_texture
Definition GLESShader.h:25
@ e_points
Definition GLESShader.h:21
@ e_all
Definition GLESShader.h:27
@ e_shader_type_size
Definition GLESShader.h:26
uint04 id() const
ShaderPart
Definition GLESShader.h:30
@ Fragment
Definition GLESShader.h:32
@ Vertex
Definition GLESShader.h:31
void setUniformValue(const char *const location, const t_type &value)
Definition GLESShader.h:45
GLESShader(ShaderType type, bool is_integer, const DynamicPointer< GLESGraphicsDevice > &device)
void setUniformValue(int location, const Vector< 3, sint04 > &value)
void setUniformValue(int location, const Buffer< fltp04 > &value)
void setUniformValue(int location, const Matrix< fltp04 > &value)
void setUniformValue(int location, const fltp04(&value)[t_size])
Definition GLESShader.h:53
int uniformLocation(const char *const location) const
void setUniformValue(int location, const fltp04 &value)
void setUniformValue(int location, const RGBColor(&value)[t_size])
Definition GLESShader.h:63
void setUniformValue(int location, const Vector< t_size, fltp04 > &value)
Definition GLESShader.h:68
void setUniformValue(int location, const Vector< 3, fltp04 > &value)
void setUniformValue(int location, const uint04 &value)
void setUniformValue(int location, const RGBColor &value)
Manages all shaders used with OpenGL and the NDEVR API.
Definition GLESShader.h:103
const Dictionary< GLESShader::ShaderType, DynamicPointer< GLESShader > > & integerShaders() const
Definition GLESShader.h:109
GLESShaderManager(const DynamicPointer< GLESGraphicsDevice > &device)
Definition GLESShader.h:105
const Dictionary< GLESShader::ShaderType, DynamicPointer< GLESShader > > & floatShaders() const
Definition GLESShader.h:113
DynamicPointer< GLESShader > shader(const GLESShader::ShaderType &id, bool is_int)
Definition GLESShader.h:117
DynamicPointer< GLESShader > createShader(const GLESShader::ShaderType &id, bool is_int)
Definition GLESShader.h:138
A core class within the model heirarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:64
Definition Matrix.hpp:176
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:54
The core String class for the NDEVR API.
Definition String.h:69
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233