2#include "GLESGraphicsDevice.h"
3#include <NDEVR/QTTools.h>
4#include <NDEVR/Dictionary.h>
5#include <NDEVR/String.h>
6#include <NDEVR/RGBColor.h>
7#include <QOpenGLContext>
76 mutable uint04 m_id = Constant<uint04>::Invalid;
121 template<
class t_type>
122 bool checkID(
int id,
const t_type& value)
124 std::hash<t_type> hasher;
125 std::size_t hash = hasher(value);
128 template<u
int01 t_dims,
class t_type>
131 std::hash<t_type> hasher;
132 std::size_t hash = 0;
133 for (
uint01 i = 0; i < value.size(); i++)
135 for (
uint01 n = 0; n < t_dims; n++)
136 hash = (hash * 0x100000001b3ULL) ^ (hasher(value[i][n]) + 0x9e3779b97f4a7c15ULL);
140 template<
class t_type>
141 bool checkID(
int id,
const Buffer<t_type>& value)
143 std::hash<t_type> hasher;
144 std::size_t hash = 0;
145 for (
uint01 i = 0; i < value.size(); i++)
146 hash = (hash * 0x100000001b3ULL) ^ (hasher(value[i]) + 0x9e3779b97f4a7c15ULL);
149 template<u
int01 t_dims,
class t_type>
150 bool checkID(
int id,
const Vector<t_dims, t_type>& value)
152 std::hash<t_type> hasher;
153 std::size_t hash = 0;
154 for(
uint01 i = 0; i < t_dims; i++)
155 hash = (hash * 0x100000001b3ULL) ^ (hasher(value[i]) + 0x9e3779b97f4a7c15ULL);
158 template<u
int01 t_dim_a, u
int01 t_dim_b,
class t_type>
159 bool checkID(
int id,
const Vector<t_dim_a, Vector<t_dim_b, t_type>>& value)
161 std::hash<t_type> hasher;
162 std::size_t hash = 0;
163 for (
uint01 i = 0; i < t_dim_a; i++)
164 for (
uint01 n = 0; n < t_dim_b; n++)
165 hash = (hash * 0x100000001b3ULL) ^ (hasher(value[i][n]) + 0x9e3779b97f4a7c15ULL);
168 template<u
int01 t_dim_a, u
int01 t_dim_b,
class t_type>
169 bool checkID(
int id,
const Matrix<t_type, t_dim_a, t_dim_b>& value)
171 std::hash<t_type> hasher;
172 std::size_t hash = 0;
173 for (
uint01 i = 0; i < t_dim_a; i++)
174 for (
uint01 n = 0; n < t_dim_b; n++)
175 hash = (hash * 0x100000001b3ULL) ^ (hasher(value[i][n]) + 0x9e3779b97f4a7c15ULL);
184 template<
class t_type>
192 template<
size_t t_size>
196 m_device->glUniform1fv(location, t_size, &value[0]);
198 template<
size_t t_size>
202 m_device->glUniform1uiv(location, t_size, &value[0]);
204 template<
size_t t_size>
208 m_device->glUniform1uiv(location, t_size, &value[0]);
210 template<u
int01 t_size>
211 void setUniformValue(
int location,
const Vector<t_size, fltp04>& value)
214 m_device->glUniform1fv(location, t_size, &value[0]);
216 template<u
int01 t_size>
217 void setUniformValue(
int location,
const Vector<t_size, Vector<4, fltp04>>& value)
220 m_device->glUniform4fv(location, t_size, &value[0][0]);
222 void setUniformValue(
int location,
const Buffer<Vector<4, fltp04>>& value)
225 m_device->glUniform4fv(location, value.size(), &value[0][0]);
227 template<u
int01 t_size>
228 void setUniformValue(
int location,
const Vector<t_size, RGBColor>& value)
231 m_device->glUniform1uiv(location, t_size, (
uint04*)&value[0]);
257 String buildFlatVertexSource()
const;
258 String buildFlatFragmentSource()
const;
259 String buildFullVertexSource()
const;
260 String buildFullFragmentSource()
const;
261 String buildTBNVertexSource()
const;
262 String buildTBNFragmentSource()
const;
267 uint04 m_program_id = Constant<uint04>::Invalid;
268 uint04 m_fragment = Constant<uint04>::Invalid;
269 uint04 m_vertex = Constant<uint04>::Invalid;
270 uint04 m_geometry = Constant<uint04>::Invalid;
The equivelent of std::vector but with a bit more control.
A hash-based key-value store, useful for quick associative lookups.
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
GLESShader * shader(const GLESShader::Definition &def)
Retrieves an existing shader matching the definition, or nullptr.
GLESShader * createShader(const GLESShader::Definition &def)
Creates and compiles a new shader from the given definition.
GLESShaderManager(const DynamicPointer< GLESGraphicsDevice > &device)
Constructs a GLESShaderManager for the given device.
const Dictionary< uint04, GLESShader * > & shaders() const
Returns the dictionary of all compiled shaders.
A Shader for rendering default OpenGL logic to the graphics card.
GLESShader(const Definition &def, const DynamicPointer< GLESGraphicsDevice > &device)
Constructs a GLESShader from a definition and device.
void compileAndLink()
Compiles all shader stages and links the program.
void compile(ShaderPart type, const char *src)
Compiles a single shader stage from source.
ShaderType
Classifies the type of geometry a shader is designed to render.
@ e_solid
Solid/filled rendering shader.
@ e_shader_type_size
Sentinel for the number of shader types.
@ e_linework
Line rendering shader.
@ e_points
Point rendering shader.
@ e_all
Matches all shader types.
static GLESShader * BoundShader()
Returns the currently bound shader.
int uniformLocation(const char *const location) const
Returns the uniform location for a named variable.
void bind()
Binds this shader program for use.
uint04 id() const
Returns the unique identifier of this shader based on its definition.
~GLESShader()
Destroys the shader and releases GPU programs.
int uniformLocation(uint08 hash, const char *const location) const
Returns the uniform location using a pre-computed hash.
String buildVertexSource() const
Builds the complete vertex shader source string for the current definition.
void unBind()
Unbinds this shader program.
void linkShader()
Links all compiled shader stages into a program.
String buildFragmentSource() const
Builds the complete fragment shader source string for the current definition.
const Definition & definition() const
Returns the shader definition.
ShaderPart
Identifies a stage within the shader pipeline.
@ Vertex
Vertex shader stage.
@ Fragment
Fragment shader stage.
@ Geometry
Geometry shader stage.
bool checkID(int id, std::size_t value)
Checks if a uniform value has changed since last set.
String versionedShaderCode(ShaderPart type, const String &src) const
Prepends the appropriate GLSL version directive and defines to shader source.
void setUniformValue(const char *const location, const t_type &value)
Sets a uniform value by name.
The core String View class for the NDEVR API.
The core String class for the NDEVR API.
constexpr uint08 hash() const
Creates a simple, quick hash of the object.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
The primary namespace for the NDEVR SDK.
@ type
The type identifier string for this model node.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Defines the set of features a shader must support, used to select or compile the correct variant.
bool has_normal_channel
Whether a per-vertex normal channel is available.
uint04 palette_size
The number of palette colors.
bool is_integer
Whether vertex attributes are integer-typed.
bool has_color_channel
Whether a per-vertex color channel is available.
bool has_texture
Whether texture mapping is enabled.
bool is_simple
Whether the shader uses simplified rendering.
uint04 id() const
Computes a unique identifier for this definition based on its flags.
bool is_tbn
Whether tangent-bitangent-normal data is used.
bool is_relative_to_camera
Whether rendering is camera-relative.
ShaderType type
The geometry type this shader handles.
bool has_grid
Whether grid overlay rendering is enabled.