Testing some crap

This commit is contained in:
2022-10-30 00:39:07 -07:00
parent 37eaa706b7
commit 928b4b5447
19 changed files with 264 additions and 20 deletions

View File

@ -4,7 +4,7 @@
# https://opensource.org/licenses/MIT # https://opensource.org/licenses/MIT
# DEBUG # DEBUG
set(DAWN_BUILDING dawnpokergame) set(DAWN_BUILDING dawnosui)
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)

View File

@ -162,7 +162,7 @@ void TrueTypeFont::buffer(
info->height = mathMax<float_t>(info->height, quad->y1); info->height = mathMax<float_t>(info->height, quad->y1);
// Buffer the quad. // Buffer the quad.
QuadMesh::bufferQuadMesh(mesh, QuadMesh::bufferQuadMesh(&mesh,
glm::vec2(quad->x0, quad->y0), glm::vec2(quad->s0, quad->t0), glm::vec2(quad->x0, quad->y0), glm::vec2(quad->s0, quad->t0),
glm::vec2(quad->x1, quad->y1), glm::vec2(quad->s1, quad->t1), glm::vec2(quad->x1, quad->y1), glm::vec2(quad->s1, quad->t1),
j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT j * QUAD_VERTICE_COUNT, j * QUAD_INDICE_COUNT

View File

@ -8,12 +8,12 @@
using namespace Dawn; using namespace Dawn;
void QuadMesh::bufferQuadMeshWithZ( void QuadMesh::bufferQuadMeshWithZ(
Mesh &mesh, Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0, glm::vec2 xy0, glm::vec2 uv0,
glm::vec2 xy1, glm::vec2 uv1, glm::vec2 xy1, glm::vec2 uv1,
float_t z, int32_t verticeStart, int32_t indiceStart float_t z, int32_t verticeStart, int32_t indiceStart
) { ) {
mesh.bufferPositions( mesh->bufferPositions(
verticeStart, std::array<glm::vec3, QUAD_VERTICE_COUNT>{{ verticeStart, std::array<glm::vec3, QUAD_VERTICE_COUNT>{{
glm::vec3(xy0, z), glm::vec3(xy0, z),
glm::vec3(xy1.x, xy0.y, z), glm::vec3(xy1.x, xy0.y, z),
@ -22,14 +22,14 @@ void QuadMesh::bufferQuadMeshWithZ(
}} }}
); );
mesh.bufferCoordinates( mesh->bufferCoordinates(
verticeStart, std::array<glm::vec2, QUAD_VERTICE_COUNT>{{ verticeStart, std::array<glm::vec2, QUAD_VERTICE_COUNT>{{
uv0, glm::vec2(uv1.x, uv0.y), uv0, glm::vec2(uv1.x, uv0.y),
glm::vec2(uv0.x, uv1.y), uv1 glm::vec2(uv0.x, uv1.y), uv1
}} }}
); );
mesh.bufferIndices( mesh->bufferIndices(
indiceStart, std::array<meshindice_t, QUAD_INDICE_COUNT>{{ indiceStart, std::array<meshindice_t, QUAD_INDICE_COUNT>{{
verticeStart, verticeStart + 1, verticeStart + 2, verticeStart, verticeStart + 1, verticeStart + 2,
verticeStart + 1, verticeStart + 2, verticeStart + 3 verticeStart + 1, verticeStart + 2, verticeStart + 3
@ -38,7 +38,7 @@ void QuadMesh::bufferQuadMeshWithZ(
} }
void QuadMesh::bufferQuadMesh( void QuadMesh::bufferQuadMesh(
Mesh &mesh, Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0, glm::vec2 xy0, glm::vec2 uv0,
glm::vec2 xy1, glm::vec2 uv1, glm::vec2 xy1, glm::vec2 uv1,
int32_t verticeStart, int32_t indiceStart int32_t verticeStart, int32_t indiceStart

View File

@ -26,7 +26,7 @@ namespace Dawn {
* @param indiceStart Start indice to buffer to. * @param indiceStart Start indice to buffer to.
*/ */
static void bufferQuadMeshWithZ( static void bufferQuadMeshWithZ(
Mesh &mesh, Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0, glm::vec2 xy0, glm::vec2 uv0,
glm::vec2 xy1, glm::vec2 uv1, glm::vec2 xy1, glm::vec2 uv1,
float_t z, int32_t verticeStart, int32_t indiceStart float_t z, int32_t verticeStart, int32_t indiceStart
@ -44,7 +44,7 @@ namespace Dawn {
* @param indiceStart Start indice to buffer to. * @param indiceStart Start indice to buffer to.
*/ */
static void bufferQuadMesh( static void bufferQuadMesh(
Mesh &mesh, Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0, glm::vec2 xy0, glm::vec2 uv0,
glm::vec2 xy1, glm::vec2 uv1, glm::vec2 xy1, glm::vec2 uv1,
int32_t verticeStart, int32_t indiceStart int32_t verticeStart, int32_t indiceStart

View File

@ -14,7 +14,8 @@ namespace Dawn {
SHADER_PARAMETER_TYPE_BOOLEAN, SHADER_PARAMETER_TYPE_BOOLEAN,
SHADER_PARAMETER_TYPE_COLOR, SHADER_PARAMETER_TYPE_COLOR,
SHADER_PARAMETER_TYPE_VECTOR3, SHADER_PARAMETER_TYPE_VECTOR3,
SHADER_PARAMETER_TYPE_TEXTURE SHADER_PARAMETER_TYPE_TEXTURE,
SHADER_PARAMETER_TYPE_FLOAT
}; };
template<typename T> template<typename T>
@ -102,5 +103,13 @@ namespace Dawn {
* @param texture Texture to bind to the parameter. * @param texture Texture to bind to the parameter.
*/ */
virtual void setTexture(T parameter, Texture *texture) = 0; virtual void setTexture(T parameter, Texture *texture) = 0;
/**
* Sets a floating point value to the shader.
*
* @param parameter Paramater to set the float ont o.
* @param float Float to bind.
*/
virtual void setFloat(T parameter, float_t value) = 0;
}; };
} }

View File

@ -51,6 +51,10 @@ void Material::setShaderParameters() {
this->shader->setTexture(it->first, this->textureValues[it->first]); this->shader->setTexture(it->first, this->textureValues[it->first]);
break; break;
case SHADER_PARAMETER_TYPE_FLOAT:
this->shader->setFloat(it->first, this->floatValues[it->first]);
break;
default: default:
throw "An unsupported or invalid shader parameter type was supplied."; throw "An unsupported or invalid shader parameter type was supplied.";
} }

View File

@ -27,6 +27,7 @@ namespace Dawn {
std::map<shaderparameter_t, glm::mat4> matrixValues; std::map<shaderparameter_t, glm::mat4> matrixValues;
std::map<shaderparameter_t, glm::vec3> vec3Values; std::map<shaderparameter_t, glm::vec3> vec3Values;
std::map<shaderparameter_t, Texture*> textureValues; std::map<shaderparameter_t, Texture*> textureValues;
std::map<shaderparameter_t, float_t> floatValues;
/** /**
* Material component constructor. * Material component constructor.

View File

@ -30,7 +30,7 @@ void UIBorder::updatePositions() {
glm::vec2 innerDimensions = overallDimensions - (this->edgeDimensions * 2.0f); glm::vec2 innerDimensions = overallDimensions - (this->edgeDimensions * 2.0f);
// Top Left. // Top Left.
QuadMesh::bufferQuadMesh(this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
glm::vec2(0, 0), glm::vec2(0, 0),
this->uv0, this->uv0,
edgeDimensions, edgeDimensions,
@ -39,7 +39,7 @@ void UIBorder::updatePositions() {
); );
// Top Center // Top Center
QuadMesh::bufferQuadMesh(this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
glm::vec2(edgeDimensions.x, 0), glm::vec2(edgeDimensions.x, 0),
this->uv0 + glm::vec2(oneThird.x, 0), this->uv0 + glm::vec2(oneThird.x, 0),
glm::vec2(edgeDimensions.x + innerDimensions.x, edgeDimensions.y), glm::vec2(edgeDimensions.x + innerDimensions.x, edgeDimensions.y),
@ -48,7 +48,7 @@ void UIBorder::updatePositions() {
); );
// Top Right // Top Right
QuadMesh::bufferQuadMesh(this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
glm::vec2(edgeDimensions.x + innerDimensions.x, 0), glm::vec2(edgeDimensions.x + innerDimensions.x, 0),
this->uv0 + glm::vec2(oneThird.x * 2.0f, 0), this->uv0 + glm::vec2(oneThird.x * 2.0f, 0),
glm::vec2(overallDimensions.x, edgeDimensions.y), glm::vec2(overallDimensions.x, edgeDimensions.y),
@ -57,7 +57,7 @@ void UIBorder::updatePositions() {
); );
// Middle Left // Middle Left
QuadMesh::bufferQuadMesh(this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
glm::vec2(0, edgeDimensions.y), glm::vec2(0, edgeDimensions.y),
this->uv0 + glm::vec2(0, oneThird.y), this->uv0 + glm::vec2(0, oneThird.y),
glm::vec2(edgeDimensions.x, edgeDimensions.y + innerDimensions.y), glm::vec2(edgeDimensions.x, edgeDimensions.y + innerDimensions.y),
@ -66,7 +66,7 @@ void UIBorder::updatePositions() {
); );
// Center // Center
QuadMesh::bufferQuadMesh(this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
edgeDimensions, edgeDimensions,
this->uv0 + oneThird, this->uv0 + oneThird,
edgeDimensions + innerDimensions, edgeDimensions + innerDimensions,
@ -75,7 +75,7 @@ void UIBorder::updatePositions() {
); );
// Middle Right // Middle Right
QuadMesh::bufferQuadMesh(this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
edgeDimensions + glm::vec2(innerDimensions.x, 0), edgeDimensions + glm::vec2(innerDimensions.x, 0),
this->uv0 + glm::vec2(oneThird.x * 2.0f, oneThird.y), this->uv0 + glm::vec2(oneThird.x * 2.0f, oneThird.y),
edgeDimensions + innerDimensions + glm::vec2(edgeDimensions.x, 0), edgeDimensions + innerDimensions + glm::vec2(edgeDimensions.x, 0),
@ -84,7 +84,7 @@ void UIBorder::updatePositions() {
); );
// Bottom Left // Bottom Left
QuadMesh::bufferQuadMesh(this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
glm::vec2(0.0f, edgeDimensions.y + innerDimensions.y), glm::vec2(0.0f, edgeDimensions.y + innerDimensions.y),
this->uv0 + glm::vec2(0.0f, uv1.y - oneThird.y), this->uv0 + glm::vec2(0.0f, uv1.y - oneThird.y),
glm::vec2(edgeDimensions.x, overallDimensions.y), glm::vec2(edgeDimensions.x, overallDimensions.y),
@ -93,7 +93,7 @@ void UIBorder::updatePositions() {
); );
// Bottom Center // Bottom Center
QuadMesh::bufferQuadMesh(this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
edgeDimensions + glm::vec2(0.0f, innerDimensions.y), edgeDimensions + glm::vec2(0.0f, innerDimensions.y),
this->uv1 - oneThird, this->uv1 - oneThird,
overallDimensions - glm::vec2(edgeDimensions.x, 0.0f), overallDimensions - glm::vec2(edgeDimensions.x, 0.0f),
@ -102,7 +102,7 @@ void UIBorder::updatePositions() {
); );
// Bottom Right // Bottom Right
QuadMesh::bufferQuadMesh(this->mesh, QuadMesh::bufferQuadMesh(&this->mesh,
overallDimensions - edgeDimensions, overallDimensions - edgeDimensions,
this->uv1 - oneThird, this->uv1 - oneThird,
overallDimensions, overallDimensions,

View File

@ -15,7 +15,7 @@ void UISprite::updatePositions() {
UIComponent::updatePositions(); UIComponent::updatePositions();
QuadMesh::bufferQuadMesh( QuadMesh::bufferQuadMesh(
this->mesh, &this->mesh,
glm::vec2(0, 0), glm::vec2(0, 0), glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(this->width, this->height), glm::vec2(1, 1), glm::vec2(this->width, this->height), glm::vec2(1, 1),
0, 0 0, 0

View File

@ -96,6 +96,10 @@ void Shader::setTexture(
this->bindTexture(param, texture); this->bindTexture(param, texture);
} }
void Shader::setFloat(shaderparameter_t param, float_t value) {
glUniform1f(param, value);
}
void Shader::bind() { void Shader::bind() {
if(this->shaderProgram == -1) throw "Shader has not yet been compiled"; if(this->shaderProgram == -1) throw "Shader has not yet been compiled";
glUseProgram(this->shaderProgram); glUseProgram(this->shaderProgram);

View File

@ -76,6 +76,7 @@ namespace Dawn {
void setColor(shaderparameter_t parameter, struct Color color) override; void setColor(shaderparameter_t parameter, struct Color color) override;
void setVector3(shaderparameter_t parameter, glm::vec3 vector) override; void setVector3(shaderparameter_t parameter, glm::vec3 vector) override;
void setTexture(shaderparameter_t parameter, Texture *texture) override; void setTexture(shaderparameter_t parameter, Texture *texture) override;
void setFloat(shaderparameter_t parameter, float_t value) override;
/** /**
* Destroys and deletes the shader from the GPU. * Destroys and deletes the shader from the GPU.

View File

@ -0,0 +1,20 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Set up the executable
set(DAWN_TARGET_NAME "DawnOS" CACHE INTERNAL ${DAWN_CACHE_TARGET})
# Build Project
add_executable(${DAWN_TARGET_NAME})
# Includes
target_include_directories(${DAWN_TARGET_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
# Subdirs
add_subdirectory(game)
add_subdirectory(display)

View File

@ -0,0 +1,7 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Subdirs
add_subdirectory(shader)

View File

@ -0,0 +1,6 @@
# Copyright (c) 2022 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources

View File

@ -0,0 +1,94 @@
// 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 "scene/components/Components.hpp"
namespace Dawn {
class TestBackgroundShader : public Shader {
public:
shaderparameter_t paramProjection;
shaderparameter_t paramView;
shaderparameter_t paramTime;
std::map<shaderparameter_t, enum ShaderParameterType>
getParameters() override {
std::map<shaderparameter_t, enum ShaderParameterType> ps;
ps[paramTime] = SHADER_PARAMETER_TYPE_FLOAT;
return ps;
}
void setDefaultParameters(Material &material) override {
material.floatValues[this->paramTime] = 0.0f;
}
void setGlobalParameters(glm::mat4 proj, glm::mat4 view) override {
this->setMatrix(this->paramProjection, proj);
this->setMatrix(this->paramView, view);
}
void setMeshParameters(glm::mat4 transform) override {}
void bindTexture(
shaderparameter_t param,
Texture *texture
) override {}
void compile() override {
this->compileShader(R"GLSL(
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;
uniform mat4 u_Proj;
uniform mat4 u_View;
out vec2 o_TextCoord;
void main() {
gl_Position = u_Proj * u_View * vec4(aPos, 1.0);
o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);
}
)GLSL", R"GLSL(
#version 330 core
out vec4 o_Color;
in vec2 o_TextCoord;
uniform float u_Time;
void main() {
highp float tSpan = 4.0;
highp float halfTSpan = tSpan / 2.0;
highp float t = mod(u_Time, tSpan);
if(t > halfTSpan) {
t = halfTSpan + (halfTSpan - t);
}
t = t / halfTSpan;
highp float x = o_TextCoord.x;
highp float y = o_TextCoord.y;
float h = sin(x + u_Time) / 4 + 0.5;
highp float r = (0.6 + ((y * t) / 5.0));
highp float g = 0.4 + ((x * t) / (10 + (t * 3)));
highp float b = 0.8 + ((0.2 * t) - (x / 5));
highp float global = 0.7 + ((0.1 + (y * 0.6)) / h / 4.0);
o_Color = vec4(
r * global,
g * global,
b * global,
1.0
);
}
)GLSL"
);
this->paramProjection = this->getParameterByName("u_Proj");
this->paramView = this->getParameterByName("u_View");
this->paramTime = this->getParameterByName("u_Time");
}
};
}

View File

@ -0,0 +1,10 @@
# 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
DawnPokerGame.cpp
)

View File

@ -0,0 +1,69 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "DawnPokerGame.hpp"
using namespace Dawn;
std::shared_ptr<Material> material;
std::shared_ptr<TestBackgroundShader> shader;
DawnGame::DawnGame(DawnHost &host) :
host(host),
renderManager(*this),
inputManager(*this)
{
}
int32_t DawnGame::init() {
this->assetManager.init();
this->renderManager.init();
this->scene = std::make_shared<Scene>(*this);
auto cameraObject = this->scene->createSceneItem();
auto camera = cameraObject->addComponent<Camera>();
camera->type = CAMERA_TYPE_ORTHONOGRAPHIC;
camera->orthoLeft = 0.0f;
camera->orthoRight = 1.0f;
camera->orthoTop = 0.0f;
camera->orthoBottom = 1.0f;
camera->transform.lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0));
// camera->transform.lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0));
auto quad = this->scene->createSceneItem();
auto meshRenderer = quad->addComponent<MeshRenderer>();
meshRenderer->mesh = std::make_shared<Mesh>();
meshRenderer->mesh->createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
QuadMesh::bufferQuadMesh(meshRenderer->mesh.get(),
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(1.0f, 1.0f), glm::vec2(1.0f, 1.0f),
0, 0
);
shader = std::make_shared<TestBackgroundShader>();
shader->compile();
material = quad->addComponent<Material>();
material->setShader(shader);
return DAWN_GAME_INIT_RESULT_SUCCESS;
}
int32_t DawnGame::update(float_t delta) {
this->assetManager.update();
this->inputManager.update();
this->timeManager.update(delta);
if(this->scene != nullptr) this->scene->update();
material->floatValues[shader->paramTime] = this->timeManager.time;
this->renderManager.update();
return DAWN_GAME_UPDATE_RESULT_SUCCESS;
}
DawnGame::~DawnGame() {
}

View File

@ -0,0 +1,10 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "game/DawnGame.hpp"
#include "scene/components/Components.hpp"
#include "display/mesh/QuadMesh.hpp"
#include "display/shader/TestBackgroundShader.hpp"

View File

@ -0,0 +1,9 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "input/InputManager.hpp"
#define INPUT_BIND_ACCEPT ((inputbind_t)1)