Base refactor

This commit is contained in:
2023-11-14 09:16:48 -06:00
parent 214082d00f
commit 1817dcaf3a
410 changed files with 749 additions and 20823 deletions

View File

@ -1,13 +0,0 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
Shader.cpp
)
add_subdirectory(buffers)
add_subdirectory(shaders)

View File

@ -1,165 +0,0 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "assert/assertgl.hpp"
#include "Shader.hpp"
using namespace Dawn;
void Shader::compileShader(
std::map<std::string, int32_t> attributeLocations,
const std::string vertexShader,
const 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);
assertNoGLError();
glCompileShader(this->shaderVertex);
assertNoGLError();
// Validate
glGetShaderiv(this->shaderVertex, GL_COMPILE_STATUS, &isSuccess);
if(!isSuccess) {
glGetShaderiv(this->shaderVertex, GL_INFO_LOG_LENGTH, &maxLength);
glGetShaderInfoLog(this->shaderVertex, maxLength, &maxLength, error);
assertUnreachable("Error compiling vert shader %s", error);
throw error;
}
assertNoGLError();
// 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);
assertUnreachable("Error compiling frag shader %s", error);
throw error;
}
assertNoGLError();
// Now create the shader program.
shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, shaderVertex);
glAttachShader(shaderProgram, shaderFrag);
assertNoGLError();
// 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);
assertUnreachable("Error compiling shader program %s", error);
throw error;
}
assertNoGLError();
}
void Shader::bindAttributeLocation(
const std::string name,
const int32_t location
) {
if(this->shaderProgram == -1) throw "Shader has not yet been compiled";
glBindAttribLocation(this->shaderProgram, location, name.c_str());
assertNoGLError();
}
void Shader::setTexture(
const shaderparameter_t param,
const textureslot_t slot
) {
glUniform1i(param, slot);
assertNoGLError();
}
shaderparameter_t Shader::getParameterByName(const std::string name) {
return glGetUniformLocation(this->shaderProgram, name.c_str());
}
shaderbufferlocation_t Shader::getBufferLocationByName(const std::string name) {
return glGetUniformBlockIndex(this->shaderProgram, name.c_str());
}
void Shader::setParameterBuffer(
const shaderbufferlocation_t location,
const shaderbufferslot_t slot
) {
glUniformBlockBinding(this->shaderProgram, location, slot);
assertNoGLError();
}
void Shader::setMatrix(
const shaderparameter_t uniform,
const glm::mat4 matrix
) {
glUniformMatrix4fv(uniform, 1, GL_FALSE, glm::value_ptr(matrix));
assertNoGLError();
}
void Shader::setBoolean(
const shaderparameter_t uni,
const bool value
) {
glUniform1i(uni, value);
assertNoGLError();
}
void Shader::setColor(
const shaderparameter_t uniform,
const struct Color color
) {
glUniform4f(uniform, color.r, color.g, color.b, color.a);
assertNoGLError();
}
void Shader::setVector3(
const shaderparameter_t uniform,
const glm::vec3 vector
) {
glUniform3f(uniform, vector.x, vector.y, vector.z);
assertNoGLError();
}
void Shader::setFloat(
const shaderparameter_t param,
const float_t value
) {
glUniform1f(param, value);
assertNoGLError();
}
void Shader::bind() {
assertTrue(shaderProgram != -1, "Cannot bind a program that is not ready");
glUseProgram(shaderProgram);
assertNoGLError();
}
Shader::~Shader() {
if(shaderProgram != -1) glDeleteProgram(shaderProgram);
if(shaderVertex != -1) glDeleteShader(shaderVertex);
if(shaderFrag != -1) glDeleteShader(shaderFrag);
}

View File

@ -1,111 +0,0 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/IShader.hpp"
#include "dawnopengl.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,
const std::string vertexShader,
const 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(
const std::string name,
const 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(const 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(const std::string name);
virtual void compile() override = 0;
void bind() override;
void setParameterBuffer(
const shaderbufferlocation_t location,
const shaderbufferslot_t slot
);
void setMatrix(
const shaderparameter_t parameter,
const glm::mat4 matrix
) override;
void setBoolean(
const shaderparameter_t parameter,
const bool_t value
) override;
void setColor(
const shaderparameter_t parameter,
const struct Color color
) override;
void setVector3(
const shaderparameter_t parameter,
const glm::vec3 vector
) override;
void setTexture(
const shaderparameter_t parameter,
const textureslot_t texture
) override;
void setFloat(
const shaderparameter_t parameter,
const float_t value
) override;
/**
* Destroys and deletes the shader from the GPU.
*/
~Shader();
};
}

View File

@ -1,127 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnopengl.hpp"
#include "display/shader/IShaderParameterBuffer.hpp"
#include "ShaderParameterBufferTypes.hpp"
namespace Dawn {
typedef GLuint shaderbufferslot_t;
typedef GLuint shaderbufferlocation_t;
template<typename T>
class ShaderParameterBuffer :
public IShaderParameterBuffer<shaderbufferslot_t>
{
protected:
shaderbufferlocation_t id = -1;
size_t size;
public:
void init() {
assertTrue(
this->id == -1,
"ShaderParameterBuffer is already initialized!"
);
this->size = sizeof(T);
glGenBuffers(1, &this->id);
assertNoGLError();
glBindBuffer(GL_UNIFORM_BUFFER, this->id);
assertNoGLError();
glBufferData(GL_UNIFORM_BUFFER, this->size, NULL, GL_DYNAMIC_DRAW);
assertNoGLError();
}
bool_t isReady() {
return this->id != -1;
}
/**
* Basic buffer method. Buffers the entire contents of the data struct to
* this shader parameter buffer.
*
* @param data Data to buffer to the parameter.
*/
void buffer(T *data) {
this->bufferRaw((void*)data);
}
void bind(shaderbufferslot_t location) override {
assertTrue(this->isReady(), "ShaderParameterBuffer is not ready!");
glBindBuffer(GL_UNIFORM_BUFFER, this->id);
assertNoGLError();
glBindBufferBase(GL_UNIFORM_BUFFER, location, this->id);
assertNoGLError();
}
/**
* Buffers the entire contents of the data struct to this shader param
* buffer object.
*
* @param data Raw data to buffer.
*/
void bufferRaw(void *data) {
this->bufferRaw(data, 0, this->size);
}
/**
* Buffers a specific range of data to this shader param buffer object.
*
* @param data Raw data to buffer.
* @param start Start position of the data to buffer.
* @param length Length of the data to buffer.
*/
void bufferRaw(void *data, size_t start, size_t length) {
assertTrue(this->isReady(), "ShaderParameterBuffer is not ready!");
glBindBuffer(GL_UNIFORM_BUFFER, this->id);
assertNoGLError();
glBufferSubData(
GL_UNIFORM_BUFFER, start, length, (void*)((size_t)data + start)
);
assertNoGLError();
}
/**
* Buffers a sub-range of data to this shader param buffer object.
*
* @param data Raw data to buffer.
* @param sub Pointer to the start of the sub-range.
*/
template<typename D>
void buffer(T* data, D* sub) {
size_t start = (size_t)sub - (size_t)data;
this->bufferRaw((void*)data, start, sizeof(D));
}
/**
* Buffers a sub-range of data to this shader param buffer object.
*
* @param data Raw data to buffer.
* @param subStart Pointer to the start of the sub-range.
* @param subEnd Pointer to the end of the sub-range, inclusive.
*/
template<typename D0, typename D1>
void buffer(T *data, D0 *subStart, D1 *subEnd) {
this->bufferRaw(
(void*)data,
(size_t)subStart - (size_t)data,
((size_t)subEnd - (size_t)subStart) + sizeof(D1)
);
}
/**
* Destroys this shader parameter buffer.
*/
~ShaderParameterBuffer() {
if(this->id != -1) {
glDeleteBuffers(1, &this->id);
assertNoGLError();
this->id = -1;
}
}
};
}

View File

@ -1,54 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "assert/assertgl.hpp"
#include "util/macro.hpp"
// Definition Helpers
#define SHADER_PARAMETER_BUFFER_ARRAY_DEFINE(name, size, contents) \
struct MACRO_JOIN(name, _struct) { \
contents \
}; \
struct MACRO_JOIN(name, _struct) name[size];
#define SHADER_PARAMETER_BUFFER_DEFINE(name, structure) \
struct MACRO_JOIN(name, Data) {\
structure; \
}; \
class name : public ShaderParameterBuffer<struct MACRO_JOIN(name, Data)> { };
// Integer and Integer Arrays
#ifdef DAWN_OPENGL_SHADER_BUFFER_INTEGER_PADDING
#define SHADER_PARAMETER_BUFFER_INTEGER(name, i) \
int32_t name; \
int32_t MACRO_JOIN(padding, i)[DAWN_OPENGL_SHADER_BUFFER_INTEGER_PADDING];
#else
#define SHADER_PARAMETER_BUFFER_INTEGER(name, i) int32_t name;
#endif
#define SHADER_PARAMETER_BUFFER_INTEGER_ARRAY(name, size) SHADER_PARAMETER_BUFFER_ARRAY_DEFINE(name, size, SHADER_PARAMETER_BUFFER_INTEGER(value, 0))
// Color and Color Arrays
#define SHADER_PARAMETER_BUFFER_COLOR(name) \
struct Color name;
#define SHADER_PARAMETER_BUFFER_COLOR_ARRAY(name, size) \
struct Color name[size];
// MAT4
#define SHADER_PARAMETER_BUFFER_MAT4(name) \
glm::mat4 name;
// VEC2
#define SHADER_PARAMETER_BUFFER_VEC2(name) \
glm::vec2 name;
#define SHADER_PARAMETER_BUFFER_VEC2_ARRAY(name, size) \
glm::vec2 name[size];
// EOF Fix
#define NOTHING "Fixes an error with EOF"

View File

@ -1,9 +0,0 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
)

View File

@ -1,30 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/ShaderParameterBuffer.hpp"
namespace Dawn {
struct RenderPipelineShaderBufferData {
SHADER_PARAMETER_BUFFER_MAT4(view);
SHADER_PARAMETER_BUFFER_MAT4(projection);
};
class RenderPipelineShaderBuffer : public ShaderParameterBuffer<struct RenderPipelineShaderBufferData> {
public:
static std::string getShaderUniformName() {
return "ub_RenderPipeline";
}
static std::string getShaderUniform() {
return std::string(
"layout (std140) uniform ub_RenderPipeline {\n"
"mat4 u_View;\n"
"mat4 u_Projection;\n"
"};"
);
}
};
}

View File

@ -1,13 +0,0 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
FontShader.cpp
SimpleTexturedShader.cpp
SimpleBillboardedShader.cpp
UIShader.cpp
)

View File

@ -1,88 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "FontShader.hpp"
#include "display/mesh/QuadMesh.hpp"
using namespace Dawn;
void FontShader::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"
"};"
"layout (shared) uniform ub_Font {\n"
"vec4 u_FontColors[" MACRO_STRINGIFY(FONT_SHADER_PARTS_MAX) "];\n"
"int u_FontTextures[" MACRO_STRINGIFY(FONT_SHADER_PARTS_MAX) "];\n"
"vec2 u_FontLinePositions[" MACRO_STRINGIFY(FONT_SHADER_PARTS_MAX) "];\n"
"int u_FontQuadMappings[" MACRO_STRINGIFY(FONT_SHADER_QUADS_MAX) "];\n"
"};\n"
"uniform mat4 u_Model;\n"
"out vec2 o_TextCoord;\n"
"out vec4 o_VertColor;\n"
"flat out int o_TextIndex;\n"
"void main() {\n"
"o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
"int quadIndex = gl_VertexID / " MACRO_STRINGIFY(QUAD_VERTICE_COUNT) ";\n"
"int partIndex = u_FontQuadMappings[quadIndex];\n"
"gl_Position = u_Projection * u_View * u_Model * (\n"
"vec4(aPos.xy, 0, 1.0) + vec4(u_FontLinePositions[partIndex], 0, 0)\n"
");\n"
"o_VertColor = u_FontColors[partIndex];\n"
"o_TextIndex = u_FontTextures[partIndex];\n"
"}",
// Fragment Shader
"#version 330 core\n"
"in vec2 o_TextCoord;\n"
"in vec4 o_VertColor;\n"
"flat in int o_TextIndex;\n"
"out vec4 o_Color;\n"
"uniform sampler2D u_Text0;\n"
"uniform sampler2D u_Text1;\n"
"uniform sampler2D u_Text2;\n"
"uniform sampler2D u_Text3;\n"
"void main() {\n"
"o_Color = o_VertColor;\n"
"vec4 tColor;"
"if(o_TextIndex == 0) \n{"
"tColor = texture(u_Text0, o_TextCoord);\n"
"} else if(o_TextIndex == 1) \n{"
"tColor = texture(u_Text1, o_TextCoord);\n"
"} else if(o_TextIndex == 2) \n{"
"tColor = texture(u_Text2, o_TextCoord);\n"
"} else {\n"
"tColor = texture(u_Text3, o_TextCoord);\n"
"}\n"
"o_Color.a *= tColor.r;\n"
"}\n"
);
#else
#error Shader Type unknown
#endif
this->paramModel = this->getParameterByName("u_Model");
this->bufferUiCanvas = this->getBufferLocationByName("ub_UICanvas");
this->bufferFont = this->getBufferLocationByName("ub_Font");
this->paramTexture0 = this->getParameterByName("u_Text0");
this->paramTexture1 = this->getParameterByName("u_Text1");
this->paramTexture2 = this->getParameterByName("u_Text2");
this->paramTexture3 = this->getParameterByName("u_Text3");
}

View File

@ -1,34 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "UIShader.hpp"
#include "util/macro.hpp"
#define FONT_SHADER_PARTS_MAX 8
#define FONT_SHADER_QUADS_MAX 1024
#define FONT_SHADER_TEXTURE_MAX 4
namespace Dawn {
SHADER_PARAMETER_BUFFER_DEFINE(FontShaderBuffer, \
SHADER_PARAMETER_BUFFER_COLOR_ARRAY(colors, FONT_SHADER_PARTS_MAX);
SHADER_PARAMETER_BUFFER_INTEGER_ARRAY(textures, FONT_SHADER_PARTS_MAX);
SHADER_PARAMETER_BUFFER_VEC2_ARRAY(linePositions, FONT_SHADER_PARTS_MAX);
SHADER_PARAMETER_BUFFER_INTEGER_ARRAY(quadMappings, FONT_SHADER_QUADS_MAX);
);
class FontShader : public Shader {
public:
shaderparameter_t paramModel;
shaderparameter_t paramTexture0;
shaderparameter_t paramTexture1;
shaderparameter_t paramTexture2;
shaderparameter_t paramTexture3;
shaderbufferlocation_t bufferUiCanvas;
shaderbufferlocation_t bufferFont;
void compile() override;
};
}

View File

@ -1,62 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SimpleBillboardedShader.hpp"
using namespace Dawn;
void SimpleBillboardedShader::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" +
RenderPipelineShaderBuffer::getShaderUniform() + ""
"uniform mat4 u_Model;\n"
"out vec2 o_TextCoord;\n"
"void main() {\n"
"vec3 billboardPos = u_Model[3].xyz;\n"
"vec3 viewDirection = normalize(billboardPos - u_View[3].xyz);\n"
"vec3 up = normalize(vec3(0, 1, 0));\n"
"vec3 right = normalize(cross(up, viewDirection));\n"
"up = normalize(cross(viewDirection, right));\n"
"vec3 billboardPosCam = vec3(u_View * vec4(billboardPos, 1.0));\n"
"gl_Position = u_Projection * vec4(billboardPosCam + (right * aPos.x + up * aPos.y), 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"
);
#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->bufferRenderPipeline = this->getBufferLocationByName(RenderPipelineShaderBuffer::getShaderUniformName());
}

View File

@ -1,21 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/Shader.hpp"
#include "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
namespace Dawn {
class SimpleBillboardedShader : public Shader {
public:
shaderbufferlocation_t bufferRenderPipeline;
shaderparameter_t paramModel;
shaderparameter_t paramColor;
shaderparameter_t paramTexture;
shaderparameter_t paramHasTexture;
void compile() override;
};
}

View File

@ -1,99 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SimpleTexturedShader.hpp"
using namespace Dawn;
void SimpleTexturedShader::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" +
RenderPipelineShaderBuffer::getShaderUniform() + ""
"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"
);
#elif DAWN_OPENGL_HLSL
this->compileShader(
{
{ "aPos", 0 },
{ "aTexCoord", 1 }
},
// Vertex Shader
"uniform float4x4 u_Proj;\n"
"uniform float4x4 u_View;\n"
"uniform float4x4 u_Model;\n"
"void main("
"float3 aPos,\n"
"float2 aTexCoord,\n"
"float2 out o_TextCoord : TEXCOORD0,\n"
"float4 out gl_Position : POSITION\n"
") {\n"
"o_TextCoord = aTexCoord;\n"
"gl_Position = mul(\n"
"mul(mul(float4(aPos, 1.0), u_Model), u_View), u_Proj\n"
");\n"
"}",
// Fragment Shader
"uniform float4 u_Color;\n"
"uniform bool u_HasTexture;\n"
"uniform sampler2D u_Text : TEXUNIT0;\n"
"float4 main(\n"
"float2 o_TextCoord : TEXCOORD0\n"
") {\n"
"float4 o_Color;\n"
"if(u_HasTexture) {\n"
"o_Color = mul(tex2D(u_Text, o_TextCoord), u_Color);\n"
"} else {\n"
"o_Color = u_Color;\n"
"}\n"
"return o_Color;\n"
"}\n"
);
#else
#error Shader Type must be either GLSL or HLSL
#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->bufferRenderPipeline = this->getBufferLocationByName(
RenderPipelineShaderBuffer::getShaderUniformName()
);
}

View File

@ -1,21 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/Shader.hpp"
#include "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
namespace Dawn {
class SimpleTexturedShader : public Shader {
public:
shaderparameter_t paramModel;
shaderparameter_t paramColor;
shaderparameter_t paramTexture;
shaderparameter_t paramHasTexture;
shaderbufferlocation_t bufferRenderPipeline;
void compile() override;
};
}

View File

@ -1,63 +0,0 @@
// 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"
// "o_Color = u_Color;\n"
// "o_Color.a = texture(u_Text, o_TextCoord).r;\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

@ -1,28 +0,0 @@
// 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 "display/shader/buffers/RenderPipelineShaderBuffer.hpp"
#define UI_SHADER_PROGRAM_PRIORITY 1000
namespace Dawn {
SHADER_PARAMETER_BUFFER_DEFINE(UICanvasShaderBuffer, \
SHADER_PARAMETER_BUFFER_MAT4(projection);
SHADER_PARAMETER_BUFFER_MAT4(view);
);
class UIShader : public Shader {
public:
shaderparameter_t paramModel;
shaderparameter_t paramColor;
shaderparameter_t paramTexture;
shaderparameter_t paramHasTexture;
shaderbufferlocation_t bufferUiCanvas;
void compile() override;
};
}