Added IRenderable, removed shader programs and allow more nuanced control of render passes, UI items are now rendered same as other scene item components.
This commit is contained in:
		| @@ -9,7 +9,7 @@ | ||||
| #include "display/shader/ShaderManager.hpp" | ||||
| #include "display/shader/SimpleTexturedShader.hpp" | ||||
| #include "display/shader/FontShader.hpp" | ||||
| #include "display/shader/UIShaderProgram.hpp" | ||||
| #include "display/shader/UIShader.hpp" | ||||
| #include "display/RenderPipeline.hpp" | ||||
| #include "display/font/FontManager.hpp" | ||||
| #include "display/font/ExampleFont.hpp" | ||||
|   | ||||
| @@ -6,7 +6,7 @@ | ||||
| # Sources | ||||
| target_sources(${DAWN_TARGET_NAME} | ||||
|   PRIVATE | ||||
|     ShaderProgram.cpp | ||||
|     Shader.cpp | ||||
|     FontShader.cpp | ||||
|     SimpleTexturedShader.cpp | ||||
|     SimpleBillboardedShader.cpp | ||||
|   | ||||
| @@ -4,12 +4,10 @@ | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #include "FontShader.hpp" | ||||
| #include "scene/components/display/mesh/MeshRenderer.hpp" | ||||
| #include "scene/components/display/Camera.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| void FontShaderProgram::compile() { | ||||
| void FontShader::compile() { | ||||
|   #if DAWN_OPENGL_GLSL | ||||
|     this->compileShader( | ||||
|       { | ||||
| @@ -53,17 +51,4 @@ void FontShaderProgram::compile() { | ||||
|   this->paramModel = this->getParameterByName("u_Model"); | ||||
|   this->paramColor = this->getParameterByName("u_Color"); | ||||
|   this->paramTexture = this->getParameterByName("u_Text"); | ||||
| } | ||||
|  | ||||
| void FontShader::compile() { | ||||
|   this->program.compile(); | ||||
| } | ||||
|  | ||||
| std::vector<struct ShaderPassItem> FontShader::getPassItems( | ||||
|   Mesh *mesh, | ||||
|   Material *material, | ||||
|   Camera *camera | ||||
| ) { | ||||
|   std::vector<struct ShaderPassItem> passes; | ||||
|   return passes; | ||||
| } | ||||
| @@ -10,10 +10,10 @@ | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #pragma once | ||||
| #include "display/shader/ShaderManager.hpp" | ||||
| #include "display/shader/Shader.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   class FontShaderProgram : public ShaderProgram { | ||||
|   class FontShader : public Shader { | ||||
|     public: | ||||
|       shaderparameter_t paramProjection; | ||||
|       shaderparameter_t paramView; | ||||
| @@ -23,17 +23,4 @@ namespace Dawn { | ||||
|  | ||||
|       void compile() override; | ||||
|   }; | ||||
|  | ||||
|   class FontShader : public Shader { | ||||
|     public: | ||||
|       FontShaderProgram program; | ||||
|  | ||||
|       void compile() override; | ||||
|  | ||||
|       std::vector<struct ShaderPassItem> getPassItems( | ||||
|         Mesh *mesh, | ||||
|         Material *material, | ||||
|         Camera *camera | ||||
|       ) override; | ||||
|   }; | ||||
| } | ||||
| @@ -1,129 +1,129 @@ | ||||
| // Copyright (c) 2022 Dominic Masters
 | ||||
| // 
 | ||||
| // This software is released under the MIT License.
 | ||||
| // https://opensource.org/licenses/MIT
 | ||||
| 
 | ||||
| #include "ShaderProgram.hpp" | ||||
| 
 | ||||
| using namespace Dawn; | ||||
| 
 | ||||
| void ShaderProgram::compileShader( | ||||
|   std::map<std::string, int32_t> attributeLocations, | ||||
|   std::string vertexShader, | ||||
|   std::string fragmentShader | ||||
| ) { | ||||
|   GLint isSuccess; | ||||
|   int32_t maxLength; | ||||
|   char error[1024]; | ||||
|    | ||||
|   // Load the vertex shader first
 | ||||
|   this->shaderVertex = glCreateShader(GL_VERTEX_SHADER); | ||||
|   auto vertShaderC = vertexShader.c_str(); | ||||
|   glShaderSource(this->shaderVertex, 1, &vertShaderC, 0); | ||||
|   glCompileShader(this->shaderVertex); | ||||
| 
 | ||||
|   // Validate
 | ||||
|   glGetShaderiv(this->shaderVertex, GL_COMPILE_STATUS, &isSuccess); | ||||
|   if(!isSuccess) { | ||||
|     glGetShaderiv(this->shaderVertex, GL_INFO_LOG_LENGTH, &maxLength); | ||||
|     glGetShaderInfoLog(this->shaderVertex, maxLength, &maxLength, error); | ||||
|     debugMessage("Error compiling vert shader"); | ||||
|     debugMessage(error); | ||||
|     throw error; | ||||
|   } | ||||
| 
 | ||||
|   // Now load the Frag shader
 | ||||
|   this->shaderFrag = glCreateShader(GL_FRAGMENT_SHADER); | ||||
|   auto fragShaderC = fragmentShader.c_str(); | ||||
|   glShaderSource(this->shaderFrag, 1, &fragShaderC, 0); | ||||
|   glCompileShader(this->shaderFrag); | ||||
|   glGetShaderiv(this->shaderFrag, GL_COMPILE_STATUS, &isSuccess); | ||||
|   if(!isSuccess) { | ||||
|     glGetShaderiv(this->shaderFrag, GL_INFO_LOG_LENGTH, &maxLength); | ||||
|     glGetShaderInfoLog(this->shaderFrag, maxLength, &maxLength, error); | ||||
|     glDeleteShader(this->shaderVertex); | ||||
|     debugMessage("Error compiling frag shader"); | ||||
|     debugMessage(error); | ||||
|     throw error; | ||||
|   } | ||||
| 
 | ||||
|   // Now create the shader program.
 | ||||
|   this->shaderProgram = glCreateProgram(); | ||||
|   glAttachShader(this->shaderProgram, this->shaderVertex); | ||||
|   glAttachShader(this->shaderProgram, this->shaderFrag); | ||||
| 
 | ||||
|   // Now parse out the variables.
 | ||||
|   #if DAWN_OPENGL_HLSL | ||||
|     auto itAttr = attributeLocations.begin(); | ||||
|     while(itAttr != attributeLocations.end()) { | ||||
|       this->bindAttributeLocation(itAttr->first, itAttr->second); | ||||
|       ++itAttr; | ||||
|     } | ||||
|   #endif | ||||
| 
 | ||||
|   //Bind, Verify & Use the shader program
 | ||||
|   glLinkProgram(this->shaderProgram); | ||||
|   glGetProgramiv(this->shaderProgram, GL_LINK_STATUS, &isSuccess); | ||||
|   if(!isSuccess) { | ||||
|     glGetProgramiv(this->shaderProgram, GL_INFO_LOG_LENGTH, &maxLength); | ||||
|     glGetProgramInfoLog(this->shaderProgram, maxLength, &maxLength, error); | ||||
|     glDeleteShader(this->shaderVertex); | ||||
|     glDeleteShader(this->shaderFrag); | ||||
|     debugMessage("Error compiling shader program"); | ||||
|     debugMessage(error); | ||||
|     throw error; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void ShaderProgram::bindAttributeLocation(std::string name, int32_t location) { | ||||
|   if(this->shaderProgram == -1) throw "Shader has not yet been compiled"; | ||||
|   glBindAttribLocation(this->shaderProgram, location, name.c_str()); | ||||
| } | ||||
| 
 | ||||
| void ShaderProgram::setTexture(shaderparameter_t param, textureslot_t slot) { | ||||
|   glUniform1i(param, slot); | ||||
| } | ||||
| 
 | ||||
| shaderparameter_t ShaderProgram::getParameterByName(std::string name) { | ||||
|   return glGetUniformLocation(this->shaderProgram, name.c_str()); | ||||
| } | ||||
| 
 | ||||
| shaderbufferlocation_t ShaderProgram::getBufferLocationByName(std::string name) { | ||||
|   return glGetUniformBlockIndex(this->shaderProgram, name.c_str()); | ||||
| } | ||||
| 
 | ||||
| void ShaderProgram::setParameterBuffer(shaderbufferlocation_t location, shaderbufferslot_t slot) { | ||||
|   glUniformBlockBinding(this->shaderProgram, location, slot); | ||||
| } | ||||
| 
 | ||||
| void ShaderProgram::setMatrix(shaderparameter_t uniform, glm::mat4 matrix) { | ||||
|   glUniformMatrix4fv(uniform, 1, GL_FALSE, glm::value_ptr(matrix)); | ||||
| } | ||||
| 
 | ||||
| void ShaderProgram::setBoolean(shaderparameter_t uni, bool value) { | ||||
|   glUniform1i(uni, value); | ||||
| } | ||||
| 
 | ||||
| void ShaderProgram::setColor(shaderparameter_t uniform, struct Color color) { | ||||
|   auto precise = color.precision(); | ||||
|   glUniform4f(uniform, precise.r, precise.g, precise.b, precise.a); | ||||
| } | ||||
| 
 | ||||
| void ShaderProgram::setVector3(shaderparameter_t uniform, glm::vec3 vector) { | ||||
|   glUniform3f(uniform, vector.x, vector.y, vector.z); | ||||
| } | ||||
| 
 | ||||
| void ShaderProgram::setFloat(shaderparameter_t param, float_t value) { | ||||
|   glUniform1f(param, value); | ||||
| } | ||||
| 
 | ||||
| void ShaderProgram::bind() { | ||||
|   if(this->shaderProgram == -1) throw "Shader has not yet been compiled"; | ||||
|   glUseProgram(this->shaderProgram); | ||||
| } | ||||
| 
 | ||||
| ShaderProgram::~ShaderProgram() { | ||||
|   if(this->shaderProgram != -1) glDeleteProgram(this->shaderProgram); | ||||
|   if(this->shaderVertex != -1) glDeleteShader(this->shaderVertex); | ||||
|   if(this->shaderFrag != -1) glDeleteShader(this->shaderFrag); | ||||
| // Copyright (c) 2022 Dominic Masters
 | ||||
| // 
 | ||||
| // This software is released under the MIT License.
 | ||||
| // https://opensource.org/licenses/MIT
 | ||||
| 
 | ||||
| #include "Shader.hpp" | ||||
| 
 | ||||
| using namespace Dawn; | ||||
| 
 | ||||
| void Shader::compileShader( | ||||
|   std::map<std::string, int32_t> attributeLocations, | ||||
|   std::string vertexShader, | ||||
|   std::string fragmentShader | ||||
| ) { | ||||
|   GLint isSuccess; | ||||
|   int32_t maxLength; | ||||
|   char error[1024]; | ||||
|    | ||||
|   // Load the vertex shader first
 | ||||
|   this->shaderVertex = glCreateShader(GL_VERTEX_SHADER); | ||||
|   auto vertShaderC = vertexShader.c_str(); | ||||
|   glShaderSource(this->shaderVertex, 1, &vertShaderC, 0); | ||||
|   glCompileShader(this->shaderVertex); | ||||
| 
 | ||||
|   // Validate
 | ||||
|   glGetShaderiv(this->shaderVertex, GL_COMPILE_STATUS, &isSuccess); | ||||
|   if(!isSuccess) { | ||||
|     glGetShaderiv(this->shaderVertex, GL_INFO_LOG_LENGTH, &maxLength); | ||||
|     glGetShaderInfoLog(this->shaderVertex, maxLength, &maxLength, error); | ||||
|     debugMessage("Error compiling vert shader"); | ||||
|     debugMessage(error); | ||||
|     throw error; | ||||
|   } | ||||
| 
 | ||||
|   // Now load the Frag shader
 | ||||
|   this->shaderFrag = glCreateShader(GL_FRAGMENT_SHADER); | ||||
|   auto fragShaderC = fragmentShader.c_str(); | ||||
|   glShaderSource(this->shaderFrag, 1, &fragShaderC, 0); | ||||
|   glCompileShader(this->shaderFrag); | ||||
|   glGetShaderiv(this->shaderFrag, GL_COMPILE_STATUS, &isSuccess); | ||||
|   if(!isSuccess) { | ||||
|     glGetShaderiv(this->shaderFrag, GL_INFO_LOG_LENGTH, &maxLength); | ||||
|     glGetShaderInfoLog(this->shaderFrag, maxLength, &maxLength, error); | ||||
|     glDeleteShader(this->shaderVertex); | ||||
|     debugMessage("Error compiling frag shader"); | ||||
|     debugMessage(error); | ||||
|     throw error; | ||||
|   } | ||||
| 
 | ||||
|   // Now create the shader program.
 | ||||
|   this->shaderProgram = glCreateProgram(); | ||||
|   glAttachShader(this->shaderProgram, this->shaderVertex); | ||||
|   glAttachShader(this->shaderProgram, this->shaderFrag); | ||||
| 
 | ||||
|   // Now parse out the variables.
 | ||||
|   #if DAWN_OPENGL_HLSL | ||||
|     auto itAttr = attributeLocations.begin(); | ||||
|     while(itAttr != attributeLocations.end()) { | ||||
|       this->bindAttributeLocation(itAttr->first, itAttr->second); | ||||
|       ++itAttr; | ||||
|     } | ||||
|   #endif | ||||
| 
 | ||||
|   //Bind, Verify & Use the shader program
 | ||||
|   glLinkProgram(this->shaderProgram); | ||||
|   glGetProgramiv(this->shaderProgram, GL_LINK_STATUS, &isSuccess); | ||||
|   if(!isSuccess) { | ||||
|     glGetProgramiv(this->shaderProgram, GL_INFO_LOG_LENGTH, &maxLength); | ||||
|     glGetProgramInfoLog(this->shaderProgram, maxLength, &maxLength, error); | ||||
|     glDeleteShader(this->shaderVertex); | ||||
|     glDeleteShader(this->shaderFrag); | ||||
|     debugMessage("Error compiling shader program"); | ||||
|     debugMessage(error); | ||||
|     throw error; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void Shader::bindAttributeLocation(std::string name, int32_t location) { | ||||
|   if(this->shaderProgram == -1) throw "Shader has not yet been compiled"; | ||||
|   glBindAttribLocation(this->shaderProgram, location, name.c_str()); | ||||
| } | ||||
| 
 | ||||
| void Shader::setTexture(shaderparameter_t param, textureslot_t slot) { | ||||
|   glUniform1i(param, slot); | ||||
| } | ||||
| 
 | ||||
| shaderparameter_t Shader::getParameterByName(std::string name) { | ||||
|   return glGetUniformLocation(this->shaderProgram, name.c_str()); | ||||
| } | ||||
| 
 | ||||
| shaderbufferlocation_t Shader::getBufferLocationByName(std::string name) { | ||||
|   return glGetUniformBlockIndex(this->shaderProgram, name.c_str()); | ||||
| } | ||||
| 
 | ||||
| void Shader::setParameterBuffer(shaderbufferlocation_t location, shaderbufferslot_t slot) { | ||||
|   glUniformBlockBinding(this->shaderProgram, location, slot); | ||||
| } | ||||
| 
 | ||||
| void Shader::setMatrix(shaderparameter_t uniform, glm::mat4 matrix) { | ||||
|   glUniformMatrix4fv(uniform, 1, GL_FALSE, glm::value_ptr(matrix)); | ||||
| } | ||||
| 
 | ||||
| void Shader::setBoolean(shaderparameter_t uni, bool value) { | ||||
|   glUniform1i(uni, value); | ||||
| } | ||||
| 
 | ||||
| void Shader::setColor(shaderparameter_t uniform, struct Color color) { | ||||
|   auto precise = color.precision(); | ||||
|   glUniform4f(uniform, precise.r, precise.g, precise.b, precise.a); | ||||
| } | ||||
| 
 | ||||
| void Shader::setVector3(shaderparameter_t uniform, glm::vec3 vector) { | ||||
|   glUniform3f(uniform, vector.x, vector.y, vector.z); | ||||
| } | ||||
| 
 | ||||
| void Shader::setFloat(shaderparameter_t param, float_t value) { | ||||
|   glUniform1f(param, value); | ||||
| } | ||||
| 
 | ||||
| void Shader::bind() { | ||||
|   if(this->shaderProgram == -1) throw "Shader has not yet been compiled"; | ||||
|   glUseProgram(this->shaderProgram); | ||||
| } | ||||
| 
 | ||||
| Shader::~Shader() { | ||||
|   if(this->shaderProgram != -1) glDeleteProgram(this->shaderProgram); | ||||
|   if(this->shaderVertex != -1) glDeleteShader(this->shaderVertex); | ||||
|   if(this->shaderFrag != -1) glDeleteShader(this->shaderFrag); | ||||
| } | ||||
| @@ -1,89 +1,84 @@ | ||||
| // Copyright (c) 2022 Dominic Masters
 | ||||
| // 
 | ||||
| // This software is released under the MIT License.
 | ||||
| // https://opensource.org/licenses/MIT
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include "display/shader/_ShaderProgram.hpp" | ||||
| #include "dawnopengl.hpp" | ||||
| #include "display/Color.hpp" | ||||
| #include "debug/debug.hpp" | ||||
| 
 | ||||
| #include "ShaderParameterBuffer.hpp" | ||||
| 
 | ||||
| typedef GLuint shaderparameter_t; | ||||
| 
 | ||||
| namespace Dawn { | ||||
|   class ShaderProgram : public IShaderProgram<shaderparameter_t> { | ||||
|     private: | ||||
|       /** Pointer to an uploaded vertex shader program */ | ||||
|       GLuint shaderVertex = -1; | ||||
| 
 | ||||
|       /** Pointer to an uploaded fragment shader program */ | ||||
|       GLuint shaderFrag = -1; | ||||
| 
 | ||||
|       /** Pointer to an uploaded shader program linked */ | ||||
|       GLuint shaderProgram = -1; | ||||
| 
 | ||||
|     protected: | ||||
|       /**
 | ||||
|        * Compiles a GLSL/HLSL shader and stores it on the GPU, updates the | ||||
|        * underlying pointers for you. | ||||
|        *  | ||||
|        * @param vertexShader The string source of the vertex shader. | ||||
|        * @param fragmentShader The string source of the fragment shader. | ||||
|        */ | ||||
|       void compileShader( | ||||
|         std::map<std::string, int32_t> attributeLocations, | ||||
|         std::string vertexShader, | ||||
|         std::string fragmentShader | ||||
|       ); | ||||
| 
 | ||||
|       /**
 | ||||
|        * Typically HLSL only, this method allows you to specify where vbo  | ||||
|        * attributes are bound. Typically 0 for positions, 1 for coordinates, | ||||
|        * etc. | ||||
|        *  | ||||
|        * @param name Attribute name in the HLSL shader. | ||||
|        * @param location Index pointing to which location it is to be bound to. | ||||
|        */ | ||||
|       void bindAttributeLocation(std::string name, int32_t location); | ||||
| 
 | ||||
|     public: | ||||
|       /**
 | ||||
|        * Locate a shader parameter by its name. | ||||
|        *  | ||||
|        * @param name Name of the parameter to get. | ||||
|        * @return The shader parameter. | ||||
|        */ | ||||
|       shaderparameter_t getParameterByName(std::string name); | ||||
| 
 | ||||
|       /**
 | ||||
|        * Locate a shader buffer parameter set by its name. | ||||
|        *  | ||||
|        * @param name Name of the buffer to get. | ||||
|        * @return The shader buffer. | ||||
|        */ | ||||
|       shaderbufferlocation_t getBufferLocationByName(std::string name); | ||||
| 
 | ||||
|       /**
 | ||||
|        * Method to request that this shader be compiled and put on the GPU. This | ||||
|        * method should call the protected compileShader method. | ||||
|        */ | ||||
|       virtual void compile() = 0; | ||||
| 
 | ||||
|       void bind() override; | ||||
|       void setParameterBuffer(shaderbufferlocation_t location, shaderbufferslot_t slot); | ||||
|       void setMatrix(shaderparameter_t parameter, glm::mat4 matrix) override; | ||||
|       void setBoolean(shaderparameter_t parameter, bool_t value) override; | ||||
|       void setColor(shaderparameter_t parameter, struct Color color) override; | ||||
|       void setVector3(shaderparameter_t parameter, glm::vec3 vector) override; | ||||
|       void setTexture(shaderparameter_t parameter, textureslot_t texture) override; | ||||
|       void setFloat(shaderparameter_t parameter, float_t value) override; | ||||
| 
 | ||||
|       /**
 | ||||
|        * Destroys and deletes the shader from the GPU. | ||||
|        */ | ||||
|       virtual ~ShaderProgram(); | ||||
|   }; | ||||
| // Copyright (c) 2022 Dominic Masters
 | ||||
| // 
 | ||||
| // This software is released under the MIT License.
 | ||||
| // https://opensource.org/licenses/MIT
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include "display/shader/_Shader.hpp" | ||||
| #include "dawnopengl.hpp" | ||||
| #include "display/Color.hpp" | ||||
| #include "debug/debug.hpp" | ||||
| 
 | ||||
| #include "ShaderParameterBuffer.hpp" | ||||
| 
 | ||||
| typedef GLuint shaderparameter_t; | ||||
| 
 | ||||
| namespace Dawn { | ||||
|   class Shader : public IShader<shaderparameter_t> { | ||||
|     private: | ||||
|       /** Pointer to an uploaded vertex shader program */ | ||||
|       GLuint shaderVertex = -1; | ||||
| 
 | ||||
|       /** Pointer to an uploaded fragment shader program */ | ||||
|       GLuint shaderFrag = -1; | ||||
| 
 | ||||
|       /** Pointer to an uploaded shader program linked */ | ||||
|       GLuint shaderProgram = -1; | ||||
| 
 | ||||
|     protected: | ||||
|       /**
 | ||||
|        * Compiles a GLSL/HLSL shader and stores it on the GPU, updates the | ||||
|        * underlying pointers for you. | ||||
|        *  | ||||
|        * @param vertexShader The string source of the vertex shader. | ||||
|        * @param fragmentShader The string source of the fragment shader. | ||||
|        */ | ||||
|       void compileShader( | ||||
|         std::map<std::string, int32_t> attributeLocations, | ||||
|         std::string vertexShader, | ||||
|         std::string fragmentShader | ||||
|       ); | ||||
| 
 | ||||
|       /**
 | ||||
|        * Typically HLSL only, this method allows you to specify where vbo  | ||||
|        * attributes are bound. Typically 0 for positions, 1 for coordinates, | ||||
|        * etc. | ||||
|        *  | ||||
|        * @param name Attribute name in the HLSL shader. | ||||
|        * @param location Index pointing to which location it is to be bound to. | ||||
|        */ | ||||
|       void bindAttributeLocation(std::string name, int32_t location); | ||||
| 
 | ||||
|     public: | ||||
|       /**
 | ||||
|        * Locate a shader parameter by its name. | ||||
|        *  | ||||
|        * @param name Name of the parameter to get. | ||||
|        * @return The shader parameter. | ||||
|        */ | ||||
|       shaderparameter_t getParameterByName(std::string name); | ||||
| 
 | ||||
|       /**
 | ||||
|        * Locate a shader buffer parameter set by its name. | ||||
|        *  | ||||
|        * @param name Name of the buffer to get. | ||||
|        * @return The shader buffer. | ||||
|        */ | ||||
|       shaderbufferlocation_t getBufferLocationByName(std::string name); | ||||
| 
 | ||||
|       virtual void compile() = 0; | ||||
|       void bind() override; | ||||
|       void setParameterBuffer(shaderbufferlocation_t location, shaderbufferslot_t slot); | ||||
|       void setMatrix(shaderparameter_t parameter, glm::mat4 matrix) override; | ||||
|       void setBoolean(shaderparameter_t parameter, bool_t value) override; | ||||
|       void setColor(shaderparameter_t parameter, struct Color color) override; | ||||
|       void setVector3(shaderparameter_t parameter, glm::vec3 vector) override; | ||||
|       void setTexture(shaderparameter_t parameter, textureslot_t texture) override; | ||||
|       void setFloat(shaderparameter_t parameter, float_t value) override; | ||||
| 
 | ||||
|       /**
 | ||||
|        * Destroys and deletes the shader from the GPU. | ||||
|        */ | ||||
|       virtual ~Shader(); | ||||
|   }; | ||||
| } | ||||
| @@ -4,12 +4,10 @@ | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #include "SimpleBillboardedShader.hpp" | ||||
| #include "scene/components/display/mesh/MeshRenderer.hpp" | ||||
| #include "scene/components/display/Camera.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| void SimpleBillboardedShaderProgram::compile() { | ||||
| void SimpleBillboardedShader::compile() { | ||||
|   #if DAWN_OPENGL_GLSL | ||||
|     this->compileShader( | ||||
|       { | ||||
| @@ -61,43 +59,4 @@ void SimpleBillboardedShaderProgram::compile() { | ||||
|   this->paramColor = this->getParameterByName("u_Color"); | ||||
|   this->paramTexture = this->getParameterByName("u_Text"); | ||||
|   this->paramHasTexture = this->getParameterByName("u_HasTexture"); | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| void SimpleBillboardedShader::compile() { | ||||
|   this->program.compile(); | ||||
| } | ||||
|  | ||||
| std::vector<struct ShaderPassItem> SimpleBillboardedShader::getPassItems( | ||||
|   Mesh *mesh, | ||||
|   Material *material, | ||||
|   Camera *camera | ||||
| ) { | ||||
|   auto simpleMaterial = dynamic_cast<SimpleBillboardedMaterial*>(material); | ||||
|   assertNotNull(simpleMaterial); | ||||
|  | ||||
|   struct ShaderPassItem onlyPass; | ||||
|   onlyPass.mesh = mesh; | ||||
|   onlyPass.shaderProgram = &program; | ||||
|   onlyPass.colorValues[program.paramColor] = simpleMaterial->color; | ||||
|   onlyPass.matrixValues[program.paramModel] = material->transform->getWorldTransform(); | ||||
|   onlyPass.matrixValues[program.paramView] = camera->transform->getWorldTransform(); | ||||
|   onlyPass.matrixValues[program.paramProjection] = camera->getProjection(); | ||||
|   onlyPass.renderFlags = ( | ||||
|     RENDER_MANAGER_RENDER_FLAG_BLEND | | ||||
|     RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST | ||||
|   ); | ||||
|  | ||||
|   if(simpleMaterial->texture != nullptr) { | ||||
|     onlyPass.boolValues[program.paramHasTexture] = true; | ||||
|     onlyPass.textureSlots[0] = simpleMaterial->texture; | ||||
|     onlyPass.textureValues[program.paramTexture] = 0; | ||||
|   } else { | ||||
|     onlyPass.boolValues[program.paramHasTexture] = false; | ||||
|   } | ||||
|  | ||||
|   std::vector<struct ShaderPassItem> passes; | ||||
|   passes.push_back(onlyPass); | ||||
|   return passes; | ||||
| } | ||||
| @@ -4,10 +4,10 @@ | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #pragma once | ||||
| #include "scene/components/display/material/SimpleBillboardedMaterial.hpp" | ||||
| #include "display/shader/Shader.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   class SimpleBillboardedShaderProgram : public ShaderProgram { | ||||
|   class SimpleBillboardedShader : public Shader { | ||||
|     public: | ||||
|       shaderparameter_t paramProjection; | ||||
|       shaderparameter_t paramView; | ||||
| @@ -18,17 +18,4 @@ namespace Dawn { | ||||
|  | ||||
|       void compile() override; | ||||
|   }; | ||||
|  | ||||
|   class SimpleBillboardedShader : public Shader { | ||||
|     public: | ||||
|       SimpleBillboardedShaderProgram program; | ||||
|  | ||||
|       void compile() override; | ||||
|  | ||||
|       std::vector<struct ShaderPassItem> getPassItems( | ||||
|         Mesh *mesh, | ||||
|         Material *material, | ||||
|         Camera *camera | ||||
|       ) override; | ||||
|   }; | ||||
| } | ||||
| @@ -4,12 +4,10 @@ | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #include "SimpleTexturedShader.hpp" | ||||
| #include "scene/components/display/mesh/MeshRenderer.hpp" | ||||
| #include "scene/components/display/Camera.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| void SimpleTexturedShaderProgram::compile() { | ||||
| void SimpleTexturedShader::compile() { | ||||
|   #if DAWN_OPENGL_GLSL | ||||
|     this->compileShader( | ||||
|       { | ||||
| @@ -34,12 +32,6 @@ void SimpleTexturedShaderProgram::compile() { | ||||
|       // Fragment Shader | ||||
|       "#version 330 core\n" | ||||
|  | ||||
|       "layout (std140) uniform uniTest {\n" | ||||
|         "float r;\n" | ||||
|         "float g;\n" | ||||
|         "float b;\n" | ||||
|       "};\n" | ||||
|  | ||||
|       "in vec2 o_TextCoord;\n" | ||||
|       "out vec4 o_Color;\n" | ||||
|       "uniform vec4 u_Color;\n" | ||||
| @@ -47,12 +39,11 @@ void SimpleTexturedShaderProgram::compile() { | ||||
|       "uniform sampler2D u_Text;\n" | ||||
|  | ||||
|       "void main() {\n" | ||||
|         // "if(u_HasTexture) {\n" | ||||
|         //   "o_Color = texture(u_Text, o_TextCoord) * u_Color;\n" | ||||
|         // "} else {\n" | ||||
|         //   "o_Color = u_Color;" | ||||
|         // "}\n" | ||||
|         "o_Color = vec4(r, g, b, 1);\n" | ||||
|         "if(u_HasTexture) {\n" | ||||
|           "o_Color = texture(u_Text, o_TextCoord) * u_Color;\n" | ||||
|         "} else {\n" | ||||
|           "o_Color = u_Color;" | ||||
|         "}\n" | ||||
|       "}\n" | ||||
|     ); | ||||
|   #elif DAWN_OPENGL_HLSL | ||||
| @@ -102,66 +93,4 @@ void SimpleTexturedShaderProgram::compile() { | ||||
|   this->paramColor = this->getParameterByName("u_Color"); | ||||
|   this->paramTexture = this->getParameterByName("u_Text"); | ||||
|   this->paramHasTexture = this->getParameterByName("u_HasTexture"); | ||||
|  | ||||
|  | ||||
|   this->test.init(); | ||||
|   this->test.bind(0); | ||||
|   auto bufferLoc = this->getBufferLocationByName("uniTest"); | ||||
|   this->setParameterBuffer(bufferLoc, 0); | ||||
|  | ||||
|   struct Test123 data; | ||||
|   data.r = 1.0f; | ||||
|   data.g = 0.0f; | ||||
|   data.b = 1.0f; | ||||
|   this->test.buffer(&data); | ||||
|  | ||||
|   data.g = 1.0f; | ||||
|   this->test.buffer(&data); | ||||
|  | ||||
|   data.g = 0.0f; | ||||
|   data.b = 0.0f; | ||||
|   this->test.buffer(&data, &data.g); | ||||
|  | ||||
|   data.g = 1.0f; | ||||
|   data.b = 0.0f; | ||||
|   this->test.buffer(&data, &data.g, &data.b); | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| void SimpleTexturedShader::compile() { | ||||
|   this->program.compile(); | ||||
| } | ||||
|  | ||||
| std::vector<struct ShaderPassItem> SimpleTexturedShader::getPassItems( | ||||
|   Mesh *mesh, | ||||
|   Material *material, | ||||
|   Camera *camera | ||||
| ) { | ||||
|   auto simpleMaterial = dynamic_cast<SimpleTexturedMaterial*>(material); | ||||
|   assertNotNull(simpleMaterial); | ||||
|  | ||||
|   struct ShaderPassItem onlyPass; | ||||
|   onlyPass.mesh = mesh; | ||||
|   onlyPass.shaderProgram = &program; | ||||
|   onlyPass.colorValues[program.paramColor] = simpleMaterial->color; | ||||
|   onlyPass.matrixValues[program.paramModel] = material->transform->getWorldTransform(); | ||||
|   onlyPass.matrixValues[program.paramView] = camera->transform->getWorldTransform(); | ||||
|   onlyPass.matrixValues[program.paramProjection] = camera->getProjection(); | ||||
|   onlyPass.renderFlags = ( | ||||
|     RENDER_MANAGER_RENDER_FLAG_BLEND | | ||||
|     RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST | ||||
|   ); | ||||
|  | ||||
|   if(simpleMaterial->texture != nullptr) { | ||||
|     onlyPass.boolValues[program.paramHasTexture] = true; | ||||
|     onlyPass.textureSlots[0] = simpleMaterial->texture; | ||||
|     onlyPass.textureValues[program.paramTexture] = 0; | ||||
|   } else { | ||||
|     onlyPass.boolValues[program.paramHasTexture] = false; | ||||
|   } | ||||
|  | ||||
|   std::vector<struct ShaderPassItem> passes; | ||||
|   passes.push_back(onlyPass); | ||||
|   return passes; | ||||
| } | ||||
| @@ -4,24 +4,11 @@ | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #pragma once | ||||
| #include "display/shader/ShaderManager.hpp" | ||||
| #include "scene/components/display/material/SimpleTexturedMaterial.hpp" | ||||
| #include "display/shader/ShaderParameterBuffer.hpp" | ||||
| #include "display/shader/Shader.hpp" | ||||
|  | ||||
| namespace Dawn { | ||||
|   struct Test123 { | ||||
|     float_t r; | ||||
|     float_t g; | ||||
|     float_t b; | ||||
|   }; | ||||
|  | ||||
|   class SimpleTexturedShaderTest : public ShaderParameterBuffer<struct Test123> { | ||||
|   }; | ||||
|    | ||||
|   class SimpleTexturedShaderProgram : public ShaderProgram { | ||||
|   class SimpleTexturedShader : public Shader { | ||||
|     public: | ||||
|       SimpleTexturedShaderTest test; | ||||
|  | ||||
|       shaderparameter_t paramProjection; | ||||
|       shaderparameter_t paramView; | ||||
|       shaderparameter_t paramModel; | ||||
| @@ -31,17 +18,4 @@ namespace Dawn { | ||||
|  | ||||
|       void compile() override; | ||||
|   }; | ||||
|  | ||||
|   class SimpleTexturedShader : public Shader { | ||||
|     public: | ||||
|       SimpleTexturedShaderProgram program; | ||||
|  | ||||
|       void compile() override; | ||||
|  | ||||
|       std::vector<struct ShaderPassItem> getPassItems( | ||||
|         Mesh *mesh, | ||||
|         Material *material, | ||||
|         Camera *camera | ||||
|       ) override; | ||||
|   }; | ||||
| } | ||||
| @@ -1,14 +1,14 @@ | ||||
| // Copyright (c) 2022 Dominic Masters
 | ||||
| // 
 | ||||
| // This software is released under the MIT License.
 | ||||
| // https://opensource.org/licenses/MIT
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include "SimpleTexturedShader.hpp" | ||||
| 
 | ||||
| #define UI_SHADER_PROGRAM_PRIORITY 100 | ||||
| 
 | ||||
| namespace Dawn { | ||||
|   class UIShaderProgram : public SimpleTexturedShaderProgram { | ||||
|   }; | ||||
| // Copyright (c) 2022 Dominic Masters
 | ||||
| // 
 | ||||
| // This software is released under the MIT License.
 | ||||
| // https://opensource.org/licenses/MIT
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include "SimpleTexturedShader.hpp" | ||||
| 
 | ||||
| #define UI_SHADER_PROGRAM_PRIORITY 100 | ||||
| 
 | ||||
| namespace Dawn { | ||||
|   class UIShader : public SimpleTexturedShader { | ||||
|   }; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user