From 448712bbe11ee2fabcc58fe9dbb1d48ab76a23ff Mon Sep 17 00:00:00 2001 From: toloudis Date: Thu, 7 Apr 2022 19:56:06 -0700 Subject: [PATCH] more v33 renaming and removal of dead code --- renderlib/RenderGLPT.cpp | 3 +- renderlib/gl/Util.cpp | 4 +- renderlib/glsl/CMakeLists.txt | 12 +- ...0GLFlatShader2D.cpp => GLFlatShader2D.cpp} | 2 +- ...{V330GLFlatShader2D.h => GLFlatShader2D.h} | 0 ...er2DnoLut.cpp => GLImageShader2DnoLut.cpp} | 2 +- ...Shader2DnoLut.h => GLImageShader2DnoLut.h} | 0 renderlib/glsl/V330GLImageShader2D.cpp | 208 ------------------ renderlib/glsl/V330GLImageShader2D.h | 151 ------------- renderlib/glsl/V330GLLineShader2D.cpp | 153 ------------- renderlib/glsl/V330GLLineShader2D.h | 89 -------- 11 files changed, 9 insertions(+), 615 deletions(-) rename renderlib/glsl/{V330GLFlatShader2D.cpp => GLFlatShader2D.cpp} (95%) rename renderlib/glsl/{V330GLFlatShader2D.h => GLFlatShader2D.h} (100%) rename renderlib/glsl/{V330GLImageShader2DnoLut.cpp => GLImageShader2DnoLut.cpp} (96%) rename renderlib/glsl/{V330GLImageShader2DnoLut.h => GLImageShader2DnoLut.h} (100%) delete mode 100644 renderlib/glsl/V330GLImageShader2D.cpp delete mode 100644 renderlib/glsl/V330GLImageShader2D.h delete mode 100644 renderlib/glsl/V330GLLineShader2D.cpp delete mode 100644 renderlib/glsl/V330GLLineShader2D.h diff --git a/renderlib/RenderGLPT.cpp b/renderlib/RenderGLPT.cpp index d5103612..5dd88e50 100644 --- a/renderlib/RenderGLPT.cpp +++ b/renderlib/RenderGLPT.cpp @@ -10,10 +10,9 @@ #include "gl/V33FSQ.h" #include "gl/V33Image3D.h" #include "glsl/GLCopyShader.h" +#include "glsl/GLImageShader2DnoLut.h" #include "glsl/GLPTVolumeShader.h" #include "glsl/GLToneMapShader.h" -#include "glsl/V330GLFlatShader2D.h" -#include "glsl/V330GLImageShader2DnoLut.h" #include diff --git a/renderlib/gl/Util.cpp b/renderlib/gl/Util.cpp index 79675759..db3cebb1 100644 --- a/renderlib/gl/Util.cpp +++ b/renderlib/gl/Util.cpp @@ -1,8 +1,8 @@ #include "Util.h" #include "Logging.h" -#include "glsl/V330GLFlatShader2D.h" -#include "glsl/V330GLImageShader2DnoLut.h" +#include "glsl/GLFlatShader2D.h" +#include "glsl/GLImageShader2DnoLut.h" #include "glm.h" diff --git a/renderlib/glsl/CMakeLists.txt b/renderlib/glsl/CMakeLists.txt index 68cb41bd..5f70e826 100644 --- a/renderlib/glsl/CMakeLists.txt +++ b/renderlib/glsl/CMakeLists.txt @@ -10,12 +10,8 @@ target_sources(renderlib PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/GLPTVolumeShader.h" "${CMAKE_CURRENT_SOURCE_DIR}/GLToneMapShader.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/GLToneMapShader.h" - "${CMAKE_CURRENT_SOURCE_DIR}/V330GLFlatShader2D.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/V330GLFlatShader2D.h" - "${CMAKE_CURRENT_SOURCE_DIR}/V330GLImageShader2D.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/V330GLImageShader2D.h" - "${CMAKE_CURRENT_SOURCE_DIR}/V330GLImageShader2DnoLut.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/V330GLImageShader2DnoLut.h" - "${CMAKE_CURRENT_SOURCE_DIR}/V330GLLineShader2D.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/V330GLLineShader2D.h" + "${CMAKE_CURRENT_SOURCE_DIR}/GLFlatShader2D.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/GLFlatShader2D.h" + "${CMAKE_CURRENT_SOURCE_DIR}/GLImageShader2DnoLut.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/GLImageShader2DnoLut.h" ) diff --git a/renderlib/glsl/V330GLFlatShader2D.cpp b/renderlib/glsl/GLFlatShader2D.cpp similarity index 95% rename from renderlib/glsl/V330GLFlatShader2D.cpp rename to renderlib/glsl/GLFlatShader2D.cpp index 621e66a8..a99b683c 100644 --- a/renderlib/glsl/V330GLFlatShader2D.cpp +++ b/renderlib/glsl/GLFlatShader2D.cpp @@ -1,4 +1,4 @@ -#include "V330GLFlatShader2D.h" +#include "GLFlatShader2D.h" #include #include diff --git a/renderlib/glsl/V330GLFlatShader2D.h b/renderlib/glsl/GLFlatShader2D.h similarity index 100% rename from renderlib/glsl/V330GLFlatShader2D.h rename to renderlib/glsl/GLFlatShader2D.h diff --git a/renderlib/glsl/V330GLImageShader2DnoLut.cpp b/renderlib/glsl/GLImageShader2DnoLut.cpp similarity index 96% rename from renderlib/glsl/V330GLImageShader2DnoLut.cpp rename to renderlib/glsl/GLImageShader2DnoLut.cpp index 31d003e0..c45d364e 100644 --- a/renderlib/glsl/V330GLImageShader2DnoLut.cpp +++ b/renderlib/glsl/GLImageShader2DnoLut.cpp @@ -1,4 +1,4 @@ -#include "V330GLImageShader2DnoLut.h" +#include "GLImageShader2DnoLut.h" #include "Logging.h" diff --git a/renderlib/glsl/V330GLImageShader2DnoLut.h b/renderlib/glsl/GLImageShader2DnoLut.h similarity index 100% rename from renderlib/glsl/V330GLImageShader2DnoLut.h rename to renderlib/glsl/GLImageShader2DnoLut.h diff --git a/renderlib/glsl/V330GLImageShader2D.cpp b/renderlib/glsl/V330GLImageShader2D.cpp deleted file mode 100644 index 195eceac..00000000 --- a/renderlib/glsl/V330GLImageShader2D.cpp +++ /dev/null @@ -1,208 +0,0 @@ -#include "V330GLImageShader2D.h" - -#include "Logging.h" - -#include -#include - -#include -#include - -GLImageShader2D::GLImageShader2D() - : GLShaderProgram() - , m_vshader() - , m_fshader() - , m_attr_coords() - , m_attr_texcoords() - , m_uniform_mvp() - , m_uniform_texture() - , m_uniform_lut() - , m_uniform_min() - , m_uniform_max() -{ - m_vshader = new GLShader(GL_VERTEX_SHADER); - - m_vshader->compileSourceCode("#version 400 core\n" - "\n" - "layout (location = 0) in vec2 coord2d;\n" - "layout (location = 1) in vec2 texcoord;\n" - "uniform mat4 mvp;\n" - "\n" - "out VertexData\n" - "{\n" - " vec2 f_texcoord;\n" - "} outData;\n" - "\n" - "void main(void) {\n" - " gl_Position = mvp * vec4(coord2d, 0.0, 1.0);\n" - " outData.f_texcoord = texcoord;\n" - "}\n"); - - if (!m_vshader->isCompiled()) { - LOG_ERROR << "GLImageShader2D: Failed to compile vertex shader\n" << m_vshader->log(); - } - - m_fshader = new GLShader(GL_FRAGMENT_SHADER); - m_fshader->compileSourceCode("#version 400 core\n" - "\n" - "uniform sampler2D tex;\n" - "uniform sampler1DArray lut;\n" - "uniform vec3 texmin;\n" - "uniform vec3 texmax;\n" - "uniform vec3 correction;\n" - "\n" - "in VertexData\n" - "{\n" - " vec2 f_texcoord;\n" - "} inData;\n" - "\n" - "out vec4 outputColour;\n" - "\n" - "void main(void) {\n" - " vec2 flipped_texcoord = vec2(inData.f_texcoord.x, 1.0 - inData.f_texcoord.y);\n" - " vec4 texval = texture(tex, flipped_texcoord);\n" - "\n" - " outputColour = texture(lut, vec2(((((texval[0] * correction[0]) - texmin[0]) / " - "(texmax[0] - texmin[0]))), 0.0));\n" - "}\n"); - - if (!m_fshader->isCompiled()) { - LOG_ERROR << "GLImageShader2D: Failed to compile fragment shader\n" << m_fshader->log(); - } - - addShader(m_vshader); - addShader(m_fshader); - link(); - - if (!isLinked()) { - LOG_ERROR << "GLImageShader2D: Failed to link shader program\n" << log(); - } - - m_attr_coords = attributeLocation("coord2d"); - if (m_attr_coords == -1) - LOG_ERROR << "GLImageShader2D: Failed to bind coordinates"; - - m_attr_texcoords = attributeLocation("texcoord"); - if (m_attr_texcoords == -1) - LOG_ERROR << "GLImageShader2D: Failed to bind texture coordinates"; - - m_uniform_mvp = uniformLocation("mvp"); - if (m_uniform_mvp == -1) - LOG_ERROR << "GLImageShader2D: Failed to bind transform"; - - m_uniform_texture = uniformLocation("tex"); - if (m_uniform_texture == -1) - LOG_ERROR << "GLImageShader2D: Failed to bind texture uniform "; - - m_uniform_lut = uniformLocation("lut"); - if (m_uniform_lut == -1) - LOG_ERROR << "GLImageShader2D: Failed to bind lut uniform "; - - m_uniform_min = uniformLocation("texmin"); - if (m_uniform_min == -1) - LOG_ERROR << "GLImageShader2D: Failed to bind min uniform "; - - m_uniform_max = uniformLocation("texmax"); - if (m_uniform_max == -1) - LOG_ERROR << "GLImageShader2D: Failed to bind max uniform "; - - m_uniform_corr = uniformLocation("correction"); - if (m_uniform_corr == -1) - LOG_ERROR << "GLImageShader2D: Failed to bind correction uniform "; -} - -GLImageShader2D::~GLImageShader2D() {} - -void -GLImageShader2D::enableCoords() -{ - enableAttributeArray(m_attr_coords); -} - -void -GLImageShader2D::disableCoords() -{ - disableAttributeArray(m_attr_coords); -} - -void -GLImageShader2D::setCoords(const GLfloat* offset, int tupleSize, int stride) -{ - setAttributeArray(m_attr_coords, offset, tupleSize, stride); -} - -void -GLImageShader2D::setCoords(GLuint coords, const GLfloat* offset, int tupleSize, int stride) -{ - glBindBuffer(GL_ARRAY_BUFFER, coords); - setCoords(offset, tupleSize, stride); - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - -void -GLImageShader2D::enableTexCoords() -{ - enableAttributeArray(m_attr_texcoords); -} - -void -GLImageShader2D::disableTexCoords() -{ - disableAttributeArray(m_attr_texcoords); -} - -void -GLImageShader2D::setTexCoords(const GLfloat* offset, int tupleSize, int stride) -{ - setAttributeArray(m_attr_texcoords, offset, tupleSize, stride); -} - -void -GLImageShader2D::setTexCoords(GLuint texcoords, const GLfloat* offset, int tupleSize, int stride) -{ - glBindBuffer(GL_ARRAY_BUFFER, texcoords); - setTexCoords(offset, tupleSize, stride); - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - -void -GLImageShader2D::setTexture(int texunit) -{ - glUniform1i(m_uniform_texture, texunit); - check_gl("Set image texture"); -} - -void -GLImageShader2D::setMin(const glm::vec3& min) -{ - glUniform3fv(m_uniform_min, 1, glm::value_ptr(min)); - check_gl("Set min range"); -} - -void -GLImageShader2D::setMax(const glm::vec3& max) -{ - glUniform3fv(m_uniform_max, 1, glm::value_ptr(max)); - check_gl("Set max range"); -} - -void -GLImageShader2D::setCorrection(const glm::vec3& corr) -{ - glUniform3fv(m_uniform_corr, 1, glm::value_ptr(corr)); - check_gl("Set correction multiplier"); -} - -void -GLImageShader2D::setLUT(int texunit) -{ - glUniform1i(m_uniform_lut, texunit); - check_gl("Set LUT texture"); -} - -void -GLImageShader2D::setModelViewProjection(const glm::mat4& mvp) -{ - glUniformMatrix4fv(m_uniform_mvp, 1, GL_FALSE, glm::value_ptr(mvp)); - check_gl("Set image2d uniform mvp"); -} diff --git a/renderlib/glsl/V330GLImageShader2D.h b/renderlib/glsl/V330GLImageShader2D.h deleted file mode 100644 index 9a7f5407..00000000 --- a/renderlib/glsl/V330GLImageShader2D.h +++ /dev/null @@ -1,151 +0,0 @@ -#pragma once - -#include "glad/glad.h" - -#include "gl/Util.h" - -#include - -/** - * 2D image shader program (simple, up to three channels). - */ -class GLImageShader2D : public GLShaderProgram -{ - -public: - /** - * Constructor. - * - * @param parent the parent of this object. - */ - explicit GLImageShader2D(); - - /// Destructor. - ~GLImageShader2D(); - - /// Enable vertex coordinates. - void enableCoords(); - - /// Disable vertex coordinates. - void disableCoords(); - - /** - * Set vertex coordinates from array. - * - * @param offset data offset if using a buffer object otherwise - * the coordinate values. - * @param tupleSize the tuple size of the data. - * @param stride the stride of the data. - */ - void setCoords(const GLfloat* offset = 0, int tupleSize = 2, int stride = 0); - - /** - * Set vertex coordinates from buffer object. - * - * @param coords the coordinate values; null if using a buffer object. - * @param offset the offset into the coords buffer. - * @param tupleSize the tuple size of the data. - * @param stride the stride of the data. - */ - void setCoords(GLuint coords, const GLfloat* offset = 0, int tupleSize = 2, int stride = 0); - - /// Enable texture coordinates. - void enableTexCoords(); - - /// Disable texture coordinates. - void disableTexCoords(); - - /** - * Set texture coordinates from array. - * - * @param offset data offset if using a buffer object otherwise - * the coordinate values. - * @param tupleSize the tuple size of the data. - * @param stride the stride of the data. - */ - void setTexCoords(const GLfloat* offset = 0, int tupleSize = 2, int stride = 0); - - /** - * Set texture coordinates from buffer object. - * - * @param coords the coordinate values; null if using a buffer - * object. - * @param offset the offset into the coords buffer. - * @param tupleSize the tuple size of the data. - * @param stride the stride of the data. - */ - void setTexCoords(GLuint coords, const GLfloat* offset = 0, int tupleSize = 2, int stride = 0); - - /** - * Set the texture to render. - * - * @param texunit the texture unit to use. - */ - void setTexture(int texunit); - - /** - * Set minimum limits for linear contrast. - * - * @param min the RGB channel limits. - */ - void setMin(const glm::vec3& min); - - /** - * Set maximum limits for linear contrast. - * - * @param max the RGB channel limits. - */ - void setMax(const glm::vec3& max); - - /** - * Set correction multipliers to normalise pixel intensity. - * - * Use to correct the pixel value limits to the storage size - * limits, for example when using data with 12 bits per - * sample with a 16-bit storage type it will require - * multiplying by 2^(16-12) = 2^4 = 16. To leave - * uncorrected, e.g. for float and complex types, and - * integer types where the bits per sample is the same as - * the storage size, set to 1.0. - * - * @param corr the RGB channel correction multipliers. - */ - void setCorrection(const glm::vec3& corr); - - /** - * Set the LUT to use. - * - * @param texunit the texture unit to use. - */ - void setLUT(int texunit); - - /** - * Set model view projection matrix. - * - * @param mvp the model view projection matrix. - */ - void setModelViewProjection(const glm::mat4& mvp); - -private: - /// The vertex shader. - GLShader* m_vshader; - /// The fragment shader. - GLShader* m_fshader; - - /// Vertex coordinates attribute. - int m_attr_coords; - /// Texture coordinates attribute. - int m_attr_texcoords; - /// Model view projection uniform. - int m_uniform_mvp; - /// Texture uniform. - int m_uniform_texture; - /// LUT uniform. - int m_uniform_lut; - /// Minimum limits for linear contrast uniform. - int m_uniform_min; - /// Maximum limits for linear contrast uniform. - int m_uniform_max; - /// Correction multiplier for linear contrast uniform. - int m_uniform_corr; -}; diff --git a/renderlib/glsl/V330GLLineShader2D.cpp b/renderlib/glsl/V330GLLineShader2D.cpp deleted file mode 100644 index 6928b83f..00000000 --- a/renderlib/glsl/V330GLLineShader2D.cpp +++ /dev/null @@ -1,153 +0,0 @@ -#include "V330GLLineShader2D.h" - -#include "Logging.h" - -#include -#include - -#include - -GLLineShader2D::GLLineShader2D() - : GLShaderProgram() - , m_vshader() - , m_fshader() - , m_attr_coords() - , m_attr_colour() - , m_uniform_mvp() -{ - m_vshader = new GLShader(GL_VERTEX_SHADER); - m_vshader->compileSourceCode( - "#version 400 core\n" - "\n" - "uniform mat4 mvp;\n" - "uniform float zoom;\n" - "\n" - "layout (location = 0) in vec3 coord2d;\n" - "layout (location = 1) in vec3 colour;\n" - "out VertexData\n" - "{\n" - " vec4 f_colour;\n" - "} outData;\n" - "\n" - "void log10(in float v1, out float v2) { v2 = log2(v1) * 0.30103; }\n" - "\n" - "void main(void) {\n" - " gl_Position = mvp * vec4(coord2d[0], coord2d[1], -2.0, 1.0);\n" - " // Logistic function offset by LOD and correction factor to set the transition points\n" - " float logzoom;\n" - " log10(zoom, logzoom);\n" - " outData.f_colour = vec4(colour, 1.0 / (1.0 + pow(10.0,((-logzoom-1.0+coord2d[2])*30.0))));\n" - "}\n"); - if (!m_vshader->isCompiled()) { - LOG_ERROR << "GLLineShader2D: Failed to compile vertex shader\n" << m_vshader->log(); - } - - m_fshader = new GLShader(GL_FRAGMENT_SHADER); - m_fshader->compileSourceCode("#version 400 core\n" - "\n" - "in VertexData\n" - "{\n" - " vec4 f_colour;\n" - "} inData;\n" - "\n" - "out vec4 outputColour;\n" - "\n" - "void main(void) {\n" - " outputColour = inData.f_colour;\n" - "}\n"); - if (!m_fshader->isCompiled()) { - LOG_ERROR << "GLLineShader2D: Failed to compile fragment shader\n" << m_fshader->log(); - } - - addShader(m_vshader); - addShader(m_fshader); - link(); - - if (!isLinked()) { - LOG_ERROR << "GLLineShader2D: Failed to link shader program\n" << log(); - } - - m_attr_coords = attributeLocation("coord2d"); - if (m_attr_coords == -1) - LOG_ERROR << "GLLineShader2D: Failed to bind coordinate location"; - - m_attr_colour = attributeLocation("colour"); - if (m_attr_coords == -1) - LOG_ERROR << "GLLineShader2D: Failed to bind colour location"; - - m_uniform_mvp = uniformLocation("mvp"); - if (m_uniform_mvp == -1) - LOG_ERROR << "GLLineShader2D: Failed to bind transform"; - - m_uniform_zoom = uniformLocation("zoom"); - if (m_uniform_zoom == -1) - LOG_ERROR << "GLLineShader2D: Failed to bind zoom factor"; -} - -GLLineShader2D::~GLLineShader2D() {} - -void -GLLineShader2D::enableCoords() -{ - enableAttributeArray(m_attr_coords); -} - -void -GLLineShader2D::disableCoords() -{ - disableAttributeArray(m_attr_coords); -} - -void -GLLineShader2D::setCoords(const GLfloat* offset, int tupleSize, int stride) -{ - setAttributeArray(m_attr_coords, offset, tupleSize, stride); -} - -void -GLLineShader2D::setCoords(GLuint coords, const GLfloat* offset, int tupleSize, int stride) -{ - glBindBuffer(GL_ARRAY_BUFFER, coords); - setCoords(offset, tupleSize, stride); - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - -void -GLLineShader2D::enableColour() -{ - enableAttributeArray(m_attr_colour); -} - -void -GLLineShader2D::disableColour() -{ - disableAttributeArray(m_attr_colour); -} - -void -GLLineShader2D::setColour(const GLfloat* offset, int tupleSize, int stride) -{ - setAttributeArray(m_attr_colour, offset, tupleSize, stride); -} - -void -GLLineShader2D::setColour(GLuint colour, const GLfloat* offset, int tupleSize, int stride) -{ - glBindBuffer(GL_ARRAY_BUFFER, colour); - setColour(offset, tupleSize, stride); - glBindBuffer(GL_ARRAY_BUFFER, 0); -} - -void -GLLineShader2D::setModelViewProjection(const glm::mat4& mvp) -{ - glUniformMatrix4fv(m_uniform_mvp, 1, GL_FALSE, glm::value_ptr(mvp)); - check_gl("Set line uniform mvp"); -} - -void -GLLineShader2D::setZoom(float zoom) -{ - glUniform1f(m_uniform_zoom, zoom); - check_gl("Set line zoom level"); -} diff --git a/renderlib/glsl/V330GLLineShader2D.h b/renderlib/glsl/V330GLLineShader2D.h deleted file mode 100644 index 2f461599..00000000 --- a/renderlib/glsl/V330GLLineShader2D.h +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include "glad/glad.h" - -#include "gl/Util.h" - -#include - -/** - * 2D line shader program. - */ -class GLLineShader2D : public GLShaderProgram -{ - -public: - /** - * Constructor. - * - * @param parent the parent of this object. - */ - explicit GLLineShader2D(); - - /// Destructor. - ~GLLineShader2D(); - - /// @copydoc GLImageShader2D::enableCoords() - void enableCoords(); - - /// @copydoc GLImageShader2D::enableCoords() - void disableCoords(); - - /// @copydoc GLImageShader2D::setCoords(const GLfloat*, int, int) - void setCoords(const GLfloat* offset, int tupleSize, int stride = 0); - - /// @copydoc GLImageShader2D::setCoords(QOpenGLBuffer&, const GLfloat *, int, int) - void setCoords(GLuint coords, const GLfloat* offset, int tupleSize, int stride = 0); - - /// Enable colour array. - void enableColour(); - - /// Disable colour array. - void disableColour(); - - /** - * Set colours from array. - * - * @param offset data offset if using a buffer object otherwise - * the colour values. - * @param tupleSize the tuple size of the data. - * @param stride the stride of the data. - */ - void setColour(const GLfloat* offset, int tupleSize, int stride = 0); - - /** - * Set colours from buffer object. - * - * @param colours the colour values; null if using a buffer - * object. - * @param offset the offset into the colours buffer. - * @param tupleSize the tuple size of the data. - * @param stride the stride of the data. - */ - void setColour(GLuint colours, const GLfloat* offset, int tupleSize, int stride = 0); - - /// @copydoc GLImageShader2D::setModelViewProjection(const glm::mat4& mvp) - void setModelViewProjection(const glm::mat4& mvp); - - /** - * Set zoom level. - * - * @param zoom the zoom level. - */ - void setZoom(float zoom); - -private: - /// @copydoc GLImageShader2D::vshader - GLShader* m_vshader; - /// @copydoc GLImageShader2D::fshader - GLShader* m_fshader; - - /// @copydoc GLImageShader2D::attr_coords - int m_attr_coords; - /// Vertex colour attribute - int m_attr_colour; - /// @copydoc GLImageShader2D::uniform_mvp - int m_uniform_mvp; - /// Zoom uniform. - int m_uniform_zoom; -};