Moved a few things to shader buffers, added some bugs that I have to fix

This commit is contained in:
2023-05-30 08:35:18 -07:00
parent 8da23b123a
commit b6cbd982eb
14 changed files with 141 additions and 83 deletions

View File

@ -9,4 +9,5 @@ target_sources(${DAWN_TARGET_NAME}
FontShader.cpp
SimpleTexturedShader.cpp
SimpleBillboardedShader.cpp
UIShader.cpp
)

View File

@ -10,9 +10,6 @@
namespace Dawn {
class SimpleTexturedShader : public Shader {
public:
shaderparameter_t paramProjection;
shaderparameter_t paramView;
shaderparameter_t paramModel;
shaderparameter_t paramColor;
shaderparameter_t paramTexture;

View File

@ -0,0 +1,61 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UIShader.hpp"
using namespace Dawn;
void UIShader::compile() {
#if DAWN_OPENGL_GLSL
this->compileShader(
{
{ "aPos", 0 },
{ "aTexCoord", 1 }
},
// Vertex Shader
"#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"layout (location = 1) in vec2 aTexCoord;\n"
"layout (std140) uniform ub_UICanvas {\n"
"mat4 u_View;\n"
"mat4 u_Projection;\n"
"};"
"uniform mat4 u_Model;\n"
"out vec2 o_TextCoord;\n"
"void main() {\n"
"gl_Position = u_Projection * u_View * u_Model * vec4(aPos, 1.0);\n"
"o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
"}",
// Fragment Shader
"#version 330 core\n"
"in vec2 o_TextCoord;\n"
"out vec4 o_Color;\n"
"uniform vec4 u_Color;\n"
"uniform bool u_HasTexture;\n"
"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"
"}\n"
);
#else
#error Shader Type must be GLSL
#endif
this->paramModel = this->getParameterByName("u_Model");
this->paramColor = this->getParameterByName("u_Color");
this->paramTexture = this->getParameterByName("u_Text");
this->paramHasTexture = this->getParameterByName("u_HasTexture");
this->bufferUiCanvas = this->getBufferLocationByName("ub_UICanvas");
}

View File

@ -4,11 +4,30 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "SimpleTexturedShader.hpp"
#include "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
#include "display/shader/Shader.hpp"
#define UI_SHADER_PROGRAM_PRIORITY 100
namespace Dawn {
class UIShader : public SimpleTexturedShader {
struct UICanvasShaderParameterBufferData {
glm::mat4 projection;
glm::mat4 view;
};
class UICanvasShaderParameterBuffer :
public ShaderParameterBuffer<struct UICanvasShaderParameterBufferData>
{
};
class UIShader : public Shader {
public:
shaderparameter_t paramModel;
shaderparameter_t paramColor;
shaderparameter_t paramTexture;
shaderparameter_t paramHasTexture;
shaderbufferlocation_t bufferUiCanvas;
void compile() override;
};
}