diff --git a/include/flamegpu/visualiser/config/TexBufferConfig.h b/include/flamegpu/visualiser/config/TexBufferConfig.h index 17dce16..3aad77b 100644 --- a/include/flamegpu/visualiser/config/TexBufferConfig.h +++ b/include/flamegpu/visualiser/config/TexBufferConfig.h @@ -18,6 +18,9 @@ struct TexBufferConfig { Position_x, Position_y, Position_z, Position_xy, Position_xyz, + Position_dbl_x, Position_dbl_y, Position_dbl_z, + Position_dbl_xy, + Position_dbl_xyz, /** * Agent forward/up direction x/y/z */ @@ -26,6 +29,11 @@ struct TexBufferConfig { Forward_xyz, Up_x, Up_y, Up_z, Up_xyz, + Forward_dbl_x, Forward_dbl_y, Forward_dbl_z, + Forward_dbl_xz, + Forward_dbl_xyz, + Up_dbl_x, Up_dbl_y, Up_dbl_z, + Up_dbl_xyz, /** * Agent rotation * (Alternate to Forward/Up vectors) @@ -33,6 +41,9 @@ struct TexBufferConfig { Heading, Pitch, Bank, Direction_hp, Direction_hpb, + Heading_dbl, Pitch_dbl, Bank_dbl, + Direction_dbl_hp, + Direction_dbl_hpb, /** * Agent color */ diff --git a/src/flamegpu/visualiser/shader/ShaderCore.cpp b/src/flamegpu/visualiser/shader/ShaderCore.cpp index 7b9c1b6..f09b1f5 100644 --- a/src/flamegpu/visualiser/shader/ShaderCore.cpp +++ b/src/flamegpu/visualiser/shader/ShaderCore.cpp @@ -103,7 +103,6 @@ void ShaderCore::setupBindings() { GLint location = GL_CALL(glGetUniformLocation(this->programId, i->uniformName.c_str())); if (location != -1) { if (i->type == GL_FLOAT) { - static_assert(sizeof(int) == sizeof(float), "Error: int and float sizes differ, static float uniforms may be corrupted.\n"); if (i->count == 1) { GL_CALL(glUniform1fv(location, 1, reinterpret_cast(glm::value_ptr(i->data)))); } else if (i->count == 2) { @@ -115,13 +114,13 @@ void ShaderCore::setupBindings() { } } else if (i->type == GL_INT) { if (i->count == 1) { - GL_CALL(glUniform1iv(location, 1, glm::value_ptr(i->data))); + GL_CALL(glUniform1iv(location, 1, reinterpret_cast(glm::value_ptr(i->data)))); } else if (i->count == 2) { - GL_CALL(glUniform2iv(location, 1, glm::value_ptr(i->data))); + GL_CALL(glUniform2iv(location, 1, reinterpret_cast(glm::value_ptr(i->data)))); } else if (i->count == 3) { - GL_CALL(glUniform3iv(location, 1, glm::value_ptr(i->data))); + GL_CALL(glUniform3iv(location, 1, reinterpret_cast(glm::value_ptr(i->data)))); } else if (i->count == 4) { - GL_CALL(glUniform4iv(location, 1, glm::value_ptr(i->data))); + GL_CALL(glUniform4iv(location, 1, reinterpret_cast(glm::value_ptr(i->data)))); } } else if (i->type == GL_UNSIGNED_INT) { if (i->count == 1) { @@ -133,8 +132,18 @@ void ShaderCore::setupBindings() { } else if (i->count == 4) { GL_CALL(glUniform4uiv(location, 1, reinterpret_cast(glm::value_ptr(i->data)))); } + } else if (i->type == GL_DOUBLE) { + if (i->count == 1) { + GL_CALL(glUniform1dv(location, 1, reinterpret_cast(glm::value_ptr(i->data)))); + } else if (i->count == 2) { + GL_CALL(glUniform2dv(location, 1, reinterpret_cast(glm::value_ptr(i->data)))); + } else if (i->count == 3) { + GL_CALL(glUniform3dv(location, 1, reinterpret_cast(glm::value_ptr(i->data)))); + } else if (i->count == 4) { + GL_CALL(glUniform4dv(location, 1, reinterpret_cast(glm::value_ptr(i->data)))); + } } else if (i->type == GL_FLOAT_MAT4) { - GL_CALL(glUniformMatrix4fv(location, 1, false, reinterpret_cast(glm::value_ptr(i->data)))); + GL_CALL(glUniformMatrix4fv(location, 1, false, glm::value_ptr(i->data))); } } else { // If the uniform isn't found again, remind the user printf("%s: Static uniform '%s' could not be located on shader reload.\n", this->shaderTag.c_str(), i->uniformName.c_str()); @@ -233,6 +242,16 @@ void ShaderCore::prepare(bool autoClear) { } else if (i->second.count == 4) { GL_CALL(glUniform4uiv(i->first, 1, reinterpret_cast(i->second.data))); } + } else if (i->second.type == GL_DOUBLE) { + if (i->second.count == 1) { + GL_CALL(glUniform1dv(i->first, 1, reinterpret_cast(i->second.data))); + } else if (i->second.count == 2) { + GL_CALL(glUniform2dv(i->first, 1, reinterpret_cast(i->second.data))); + } else if (i->second.count == 3) { + GL_CALL(glUniform3dv(i->first, 1, reinterpret_cast(i->second.data))); + } else if (i->second.count == 4) { + GL_CALL(glUniform4dv(i->first, 1, reinterpret_cast(i->second.data))); + } } else if (i->second.type == GL_FLOAT_MAT4) { GL_CALL(glUniformMatrix4fv(i->first, 1, false, reinterpret_cast(i->second.data))); } @@ -286,6 +305,9 @@ bool ShaderCore::addDynamicUniform(const char *uniformName, const GLuint *arry, bool ShaderCore::addDynamicUniform(const char *uniformName, const GLfloat *arry, unsigned int count) { return addDynamicUniform({ GL_FLOAT, reinterpret_cast(arry), count, uniformName }); } +bool ShaderCore::addDynamicUniform(const char* uniformName, const GLdouble* arry, unsigned int count) { + return addDynamicUniform({ GL_DOUBLE, reinterpret_cast(arry), count, uniformName }); +} bool ShaderCore::addDynamicUniform(const char *uniformName, const glm::mat4 *mat) { return addDynamicUniform({ GL_FLOAT_MAT4, reinterpret_cast(mat), 1, uniformName }); } @@ -311,8 +333,11 @@ bool ShaderCore::addDynamicUniform(DynamicUniformDetail d) { bool ShaderCore::addStaticUniform(const char *uniformName, const GLfloat *arry, unsigned int count) { // Purge any existing buffer which matches removeStaticUniform(uniformName); + // Note we reinterpret the data to from float to mat4 + glm::mat4 temp; + memcpy(&temp, arry, sizeof(float) * count); // Note we reinterpret_cast the data to from float to int - staticUniforms.push_front({ GL_FLOAT, *reinterpret_cast(arry), count, uniformName }); + staticUniforms.push_front({ GL_FLOAT, temp, count, uniformName }); if (this->programId > 0 && count > 0 && count <= 4) { GLint location = GL_CALL(glGetUniformLocation(this->programId, uniformName)); if (location != -1) { @@ -337,7 +362,10 @@ bool ShaderCore::addStaticUniform(const char *uniformName, const GLfloat *arry, bool ShaderCore::addStaticUniform(const char *uniformName, const GLint *arry, unsigned int count) { // Purge any existing buffer which matches removeStaticUniform(uniformName); - staticUniforms.push_front({ GL_INT, *reinterpret_cast(arry), count, uniformName }); + // Note we reinterpret the data to from int to mat4 + glm::mat4 temp; + memcpy(&temp, arry, sizeof(int) * count); + staticUniforms.push_front({ GL_INT, temp, count, uniformName }); if (this->programId > 0 && count > 0 && count <= 4) { GLint location = GL_CALL(glGetUniformLocation(this->programId, uniformName)); if (location != -1) { @@ -362,7 +390,10 @@ bool ShaderCore::addStaticUniform(const char *uniformName, const GLint *arry, un bool ShaderCore::addStaticUniform(const char *uniformName, const GLuint *arry, unsigned int count) { // Purge any existing buffer which matches removeStaticUniform(uniformName); - staticUniforms.push_front({ GL_UNSIGNED_INT, *reinterpret_cast(arry), count, uniformName }); + // Note we reinterpret the data to from uint to mat4 + glm::mat4 temp; + memcpy(&temp, arry, sizeof(unsigned int) * count); + staticUniforms.push_front({ GL_UNSIGNED_INT, temp, count, uniformName }); if (this->programId > 0 && count > 0 && count <= 4) { GLint location = GL_CALL(glGetUniformLocation(this->programId, uniformName)); if (location != -1) { @@ -384,10 +415,38 @@ bool ShaderCore::addStaticUniform(const char *uniformName, const GLuint *arry, u } return false; } +bool ShaderCore::addStaticUniform(const char* uniformName, const GLdouble* arry, unsigned int count) { + // Purge any existing buffer which matches + removeStaticUniform(uniformName); + // Note we reinterpret the data to from double to mat4 + glm::mat4 temp; + memcpy(&temp, arry, sizeof(double) * count); + staticUniforms.push_front({ GL_DOUBLE, temp, count, uniformName }); + if (this->programId > 0 && count > 0 && count <= 4) { + GLint location = GL_CALL(glGetUniformLocation(this->programId, uniformName)); + if (location != -1) { + GL_CALL(glUseProgram(this->programId)); + if (count == 1) { + GL_CALL(glUniform1dv(location, 1, arry)); + } else if (count == 2) { + GL_CALL(glUniform2dv(location, 1, arry)); + } else if (count == 3) { + GL_CALL(glUniform3dv(location, 1, arry)); + } else if (count == 4) { + GL_CALL(glUniform4dv(location, 1, arry)); + } + GL_CALL(glUseProgram(0)); + return true; + } else { + fprintf(stderr, "%s: Static uniform named: %s was not found.\n", shaderTag.c_str(), uniformName); + } + } + return false; +} bool ShaderCore::addStaticUniform(const char *uniformName, const glm::mat4 *mat) { // Purge any existing buffer which matches removeStaticUniform(uniformName); - staticUniforms.push_front({ GL_FLOAT_MAT4, *reinterpret_cast(mat), 1, uniformName }); + staticUniforms.push_front({ GL_FLOAT_MAT4, *mat, 1, uniformName }); if (this->programId > 0) { GLint location = GL_CALL(glGetUniformLocation(this->programId, uniformName)); if (location != -1) { diff --git a/src/flamegpu/visualiser/shader/ShaderCore.h b/src/flamegpu/visualiser/shader/ShaderCore.h index 7ccca76..0b19121 100644 --- a/src/flamegpu/visualiser/shader/ShaderCore.h +++ b/src/flamegpu/visualiser/shader/ShaderCore.h @@ -109,7 +109,7 @@ class ShaderCore : public Reloadable { */ void destroyProgram(); /** - * Remembers a pointer to an array of upto 4 floats that will be updated everytime useProgram() is called on this Shaders object + * Remembers a pointer to an array of upto 4 floats that will be updated everytime useProgram() is called on this Shaders object * If a dynamic uniform with the same uniformName is already bound, it will be replaced * @param uniformName The name of the uniform within the shader * @param arry A pointer to the array of floats @@ -131,16 +131,27 @@ class ShaderCore : public Reloadable { */ bool addDynamicUniform(const char *uniformName, const GLint *arry, unsigned int count = 1); /** - * Remembers a pointer to an array of upto 4 unsigned integers that will be updated everytime useProgram() is called on this Shaders object - * If a dynamic uniform with the same uniformName is already bound, it will be replaced - * @param uniformName The name of the uniform within the shader - * @param arry A pointer to the array of unsigned integers - * @param count The number of unsigned integers provided in the array (a maximum of 4) - * @returns false if the uniform name was not found or count is outside of the inclusive range 1-4 - * @note Even when false is returned, the value will be stored for reprocessing on shader reloads - * @see addDynamicUniform(const char *, const GLfloat *, unsigned int) - */ + * Remembers a pointer to an array of upto 4 unsigned integers that will be updated everytime useProgram() is called on this Shaders object + * If a dynamic uniform with the same uniformName is already bound, it will be replaced + * @param uniformName The name of the uniform within the shader + * @param arry A pointer to the array of unsigned integers + * @param count The number of unsigned integers provided in the array (a maximum of 4) + * @returns false if the uniform name was not found or count is outside of the inclusive range 1-4 + * @note Even when false is returned, the value will be stored for reprocessing on shader reloads + * @see addDynamicUniform(const char *, const GLfloat *, unsigned int) + */ bool addDynamicUniform(const char *uniformName, const GLuint *arry, unsigned int count = 1); + /** + * Remembers a pointer to an array of upto 4 doubles that will be updated everytime useProgram() is called on this Shaders object + * If a dynamic uniform with the same uniformName is already bound, it will be replaced + * @param uniformName The name of the uniform within the shader + * @param arry A pointer to the array of doubles + * @param count The number of doubles provided in the array (a maximum of 4) + * @returns false if the uniform name was not found or count is outside of the inclusive range 1-4 + * @note Even when false is returned, the value will be stored for reprocessing on shader reloads + * @see addDynamicUniform(const char *, const GLint *, unsigned int) + */ + bool addDynamicUniform(const char *uniformName, const GLdouble *arry, unsigned int count = 1); /** * Remembers a pointer to a mat4 that will be updated everytime useProgram() is called on this Shaders object * If a dynamic uniform with the same uniformName is already bound, it will be replaced @@ -181,6 +192,16 @@ class ShaderCore : public Reloadable { * @note Even when false is returned, the value will be stored for reprocessing on shader reloads */ bool addStaticUniform(const char *uniformName, const GLuint *arry, unsigned int count = 1); + /** + * Sets the value of a vector of upto 4 doubles within the shader + * If a static uniform with the same uniformName is already bound, it will be replaced + * @param uniformName The name of the uniform within the shader + * @param arry A pointer to the array of doubles + * @param count The number of doubles provided in the array (a maximum of 4) + * @returns false if the uniform name was not found or count is outside of the inclusive range 1-4 + * @note Even when false is returned, the value will be stored for reprocessing on shader reloads + */ + bool addStaticUniform(const char *uniformName, const GLdouble *arry, unsigned int count = 1); /** * Sets the value of a mat4 within the shader * If a static uniform with the same uniformName is already bound, it will be replaced @@ -221,13 +242,13 @@ class ShaderCore : public Reloadable { * @param bufferBindingPoint The buffer's bind point * @return True if buffer name is found in the current shader to be bound */ - bool addBuffer(const char *bufferNameInShader, const GLenum bufferType, const GLuint bufferBindingPoint); + bool addBuffer(const char *bufferNameInShader, GLenum bufferType, GLuint bufferBindingPoint); /** * Attaches the specified buffer to the shader if bufferNameInShader can be found * If a buffer with the same bufferNameInShader is already bound, it will be replaced * This is for 'program resources', NOT texture buffers * This will not retain the shared_ptr, it's upto you to keep it alive - * @param bufferNameInShader The indentifier of the buffer within the shader source + * @param bufferNameInShader The identifier of the buffer within the shader source * @param buffer The buffer to be used * @return True if buffer name is found in the current shader to be bound * @note Convenience method, implemented in BufferCore.cpp @@ -353,9 +374,9 @@ class ShaderCore : public Reloadable { /** * Data to be stored in the shader uniform * @note components greater than count-1 are likely to contain garbage data - * @note this may actually contain a glm::vec4 if type == GL_FLOAT + * @note this may actually contain a glm::vec4 if type == GL_FLOAT, glm::ivec4 etc */ - const glm::ivec4 data; + const glm::mat4 data; /** * Number of vector components */