Moved display items to GL folder

This commit is contained in:
2024-06-21 11:53:34 -05:00
parent bba4a83240
commit 3bc2f0d372
38 changed files with 358 additions and 706 deletions

View File

@ -7,10 +7,4 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
Color.cpp
RenderPipeline.cpp
RenderManager.cpp
)
# Subdirs
add_subdirectory(mesh)
add_subdirectory(shader)
)

View File

@ -1,117 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/Color.hpp"
namespace Dawn {
enum class TextureFormat {
R = 1,
RG = 2,
RGB = 3,
RGBA = 4
};
enum class TextureWrapMode {
REPEAT = 0,
MIRRORED_REPEAT = 1,
CLAMP_TO_EDGE = 2,
CLAMP_TO_BORDER = 3
};
enum class TextureFilterMode {
NEAREST = 0,
LINEAR = 1
};
enum class TextureDataFormat {
UNSIGNED_BYTE = sizeof(uint8_t),
FLOAT = sizeof(float_t)
};
class ITexture {
public:
enum TextureWrapMode wrapModeX = TextureWrapMode::REPEAT;
enum TextureWrapMode wrapModeY = TextureWrapMode::REPEAT;
enum TextureFilterMode filterModeMin = TextureFilterMode::NEAREST;
enum TextureFilterMode filterModeMag = TextureFilterMode::NEAREST;
enum TextureFilterMode mipMapFilterModeMin = TextureFilterMode::NEAREST;
enum TextureFilterMode mipMapFilterModeMag = TextureFilterMode::NEAREST;
/**
* Returns the width of the texture.
*
* @return Width of the texture.
*/
virtual int32_t getWidth() = 0;
/**
* Returns the height of the texture.
*
* @return Height of the texture.
*/
virtual int32_t getHeight() = 0;
/**
* Initializes a texture.
*
* @param width Width of the texture (in pixels).
* @param height Height of the texture (in pixels).
* @param format Data format of the texture to use.
* @param dataFormat Data format of the texture to use.
*/
virtual void setSize(
const int32_t width,
const int32_t height,
const enum TextureFormat format,
const enum TextureDataFormat dataFormat
) = 0;
/**
* Returns true only when the texture has been loaded, sized and put on
* the gpu for rendering.
*
* @return True if ready, otherwise false.
*/
virtual bool_t isReady() = 0;
/**
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
* avoid doing this too often.
*
* @param pixels Array of pixels you're trying to buffer.
*/
virtual void buffer(const struct ColorU8 pixels[]) = 0;
/**
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
* avoid doing this too often.
*
* @param pixels Array of pixels you're trying to buffer.
*/
virtual void buffer(const struct Color pixels[]) = 0;
/**
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
* avoid doing this too often.
*
* @param pixels Array of pixels you're trying to buffer.
*/
virtual void buffer(const uint8_t pixels[]) = 0;
/**
* Binds the texture to the given slot (for use by the shaders).
*
* @param slot Slot to bind to.
*/
virtual void bind(const uint8_t slot) = 0;
/**
* Disposes of the texture.
*/
virtual ~ITexture() {
}
};
}

View File

@ -1,18 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "error/assert.hpp"
#include "RenderPipeline.hpp"
#include "game/Game.hpp"
using namespace Dawn;
RenderPipeline::RenderPipeline() {
}
RenderPipeline::~RenderPipeline() {
}

View File

@ -1,22 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawn.hpp"
namespace Dawn {
class RenderPipeline {
public:
/**
* Creates a new RenderPipeline.
*/
RenderPipeline();
/**
* Destroys the RenderPipeline.
*/
virtual ~RenderPipeline();
};
}

View File

@ -1,11 +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
CubeMesh.cpp
QuadMesh.cpp
)

View File

@ -1,102 +0,0 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawn.hpp"
namespace Dawn {
enum MeshDrawMode {
TRIANGLES,
TRIANGLE_STRIP,
TRIANGLE_FAN,
LINES,
POINTS
// LINE_STRIP,
};
class IMesh {
protected:
/** How many vertices are in the mesh */
int32_t verticeCount = -1;
/** How many indices are in the mesh */
int32_t indiceCount = -1;
public:
/**
* Create a new set of buffers for the mesh to use.
*
* @param verticeCount How many Vertices will this buffer support.
* @param indiceCount How many Indices will this buffer support.
*/
virtual void createBuffers(
const int32_t verticeCount,
const int32_t indiceCount
) = 0;
/**
* Cleanup the buffers on a given mesh. This is useful if you intend to
* expand the count of vertices your mesh supports.
*/
virtual void disposeBuffers() = 0;
/**
* Write vertice positions to the mesh.
*
* @param pos Position, within the buffer, to write to.
* @param vertices Array of positions to write.
* @param len How many positions are in the array.
*/
virtual void bufferPositions(
const int32_t pos,
const glm::vec3 positions[],
const int32_t len
) = 0;
/**
* Write vertice coordinates to the mesh.
*
* @param pos Position, within the buffer, to write to.
* @param coordinates Array of coordinates to write.
* @param len How many coordinates are in the array.
*/
virtual void bufferCoordinates(
const int32_t pos,
const glm::vec2 coordinates[],
const int32_t len
) = 0;
/**
* Write indices to the mesh.
*
* @param pos Position, within the buffer, to write to.
* @param indices Array of indices to write.
* @param len How many indices are in the array.
*/
virtual void bufferIndices(
const int32_t pos,
const int32_t indices[],
const int32_t len
) = 0;
/**
* Draw a primitive. Primitives are drawn by their indices.
*
* @param drawMode Which drawing mode to use to draw the primitive.
* @param start Start indice (index) to draw.
* @param count Count of indices to draw. Use -1 to draw all.
*/
virtual void draw(
const enum MeshDrawMode drawMode,
const int32_t start,
const int32_t count
) = 0;
/**
* Cleanup a previously initiated mesh.
*/
virtual ~IMesh() {
}
};
}

View File

@ -1,40 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/mesh/Mesh.hpp"
namespace Dawn {
class IRenderPass {
public:
std::shared_ptr<Mesh> mesh;
/**
* Binds the shader for this render pass.
*/
virtual void bind() = 0;
/**
* Sets the data for this render pass to the shader.
*/
virtual void setData() = 0;
/**
* Uploads the data to the GPU.
*/
virtual void upload() = 0;
/**
* Draws the mesh for this render pass.
*/
virtual void draw() = 0;
/**
* Cleans up the render pass.
*/
virtual ~IRenderPass() {
}
};
}

View File

@ -1,94 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "game/Game.hpp"
#include "display/pass/IRenderPass.hpp"
#include "display/shader/Shader.hpp"
#include "display/Texture.hpp"
#include "component/display/MeshRenderer.hpp"
namespace Dawn {
template<class S, typename D>
class RenderPass : public IRenderPass {
private:
std::shared_ptr<S> shader;
const std::unordered_map<
shadertexturebinding_t, std::shared_ptr<Texture>
> textures;
std::shared_ptr<Mesh> mesh;
const enum MeshDrawMode drawMode;
const int32_t indiceStart;
const int32_t indiceCount;
const D data;
public:
/**
* Constructs a new RenderPass.
*
* @param self Self component instance that is creating this render pass.
* @param d The data to use for this render pass.
* @param mesh The mesh to use for this render pass.
* @param drawMode The draw mode to use for this render pass.
* @param indiceStart The indice to start drawing from.
* @param indiceCount The number of indices to draw.
*/
RenderPass(
SceneComponent &self,
const D d,
const std::unordered_map<
shadertexturebinding_t, std::shared_ptr<Texture>
> textures,
const std::shared_ptr<Mesh> mesh,
const enum MeshDrawMode drawMode,
const int32_t indiceStart,
const int32_t indiceCount
) :
data(d),
textures(textures),
mesh(mesh),
drawMode(drawMode),
indiceStart(indiceStart),
indiceCount(indiceCount)
{
//Get the shader
shader = (
self.getGame()->renderHost.shaderManager.getShader<S>()
);
assertNotNull(shader, "Shader cannot be null!");
// Need mesh?
if(!this->mesh) {
auto meshRenderer = self.getItem()->getComponent<MeshRenderer>();
if(meshRenderer) this->mesh = meshRenderer->mesh;
}
}
void bind() override {
shader->bind();
}
void setData() override {
shader->setData(data);
}
void upload() override {
for(auto &pair : textures) {
if(!pair.second->isReady()) continue;
pair.second->bind(pair.first);
}
shader->upload();
}
void draw() override {
if(mesh) {
mesh->draw(drawMode, indiceStart, indiceCount);
}
}
~RenderPass() override {
}
};
}

View File

@ -1,18 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "game/Game.hpp"
#include "scene/Scene.hpp"
#include "component/display/Camera.hpp"
namespace Dawn {
struct RenderPassContext {
std::shared_ptr<Game> game;
std::shared_ptr<Scene> scene;
std::shared_ptr<Camera> camera;
std::shared_ptr<RenderTarget> renderTarget;
};
}

View File

@ -1,11 +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
IShader.cpp
IShaderStage.cpp
)

View File

@ -1,46 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "display/shader/Shader.hpp"
#include "error/assert.hpp"
#include "display/Color.hpp"
#include "display/Texture.hpp"
using namespace Dawn;
size_t shaderParameterTypeGetSize(const enum ShaderParameterType type) {
switch(type) {
case ShaderParameterType::VEC2:
return sizeof(glm::vec2);
case ShaderParameterType::VEC3:
return sizeof(glm::vec3);
case ShaderParameterType::VEC4:
return sizeof(glm::vec4);
case ShaderParameterType::MAT3:
return sizeof(glm::mat3);
case ShaderParameterType::MAT4:
return sizeof(glm::mat4);
case ShaderParameterType::COLOR:
return sizeof(struct Color);
case ShaderParameterType::FLOAT:
return sizeof(float);
case ShaderParameterType::INT:
return sizeof(int32_t);
case ShaderParameterType::TEXTURE:
return sizeof(shadertexturebinding_t);
default:
assertUnreachable("Unknown ShaderParameterType");
return 0;
}
}

View File

@ -1,86 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawn.hpp"
namespace Dawn {
enum class ShaderParameterType {
VEC2,
VEC3,
VEC4,
MAT3,
MAT4,
COLOR,
FLOAT,
INT,
TEXTURE,
BOOLEAN
};
class IShaderBase {
public:
virtual ~IShaderBase() {
}
};
template<typename T>
class IShader : public IShaderBase {
protected:
T data;
public:
/**
* Returns the currently uploaded data on the Shader.
*
* @return The uploaded data.
*/
T getData() {
return data;
}
/**
* Sets the entire data to be uploaded.
*
* @param data Data to be uploaded.
*/
void setData(const T data) {
this->data = data;
}
/**
* Initializes the shader, this needs to be called before the shader can
* be used.
*/
virtual void init() = 0;
/**
* Binds the shader as the current one, does not upload any data, somewhat
* relies on something else uploading the data.
*/
virtual void bind() = 0;
/**
* Uploads the data to the GPU.
*/
virtual void upload() = 0;
/**
* Disposes of the shader.
*/
virtual ~IShader() {
}
};
}
/**
* Returns the size of the ShaderParameterType.
*
* @param type The type to get the size of.
* @return Size of the type.
*/
size_t shaderParameterTypeGetSize(const enum Dawn::ShaderParameterType type);

View File

@ -1,18 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "IShaderStage.hpp"
using namespace Dawn;
IShaderStage::IShaderStage(const enum ShaderStageType type) :
type(type)
{
}
IShaderStage::~IShaderStage() {
}

View File

@ -1,32 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawn.hpp"
namespace Dawn {
enum class ShaderStageType {
VERTEX,
FRAGMENT,
// COMPUTE
};
class IShaderStage {
public:
const enum ShaderStageType type;
/**
* Constructs a new Shader Stage.
*
* @param type Type of shader stage.
*/
IShaderStage(const enum ShaderStageType type);
/**
* Destroy the IShaderStage object
*/
virtual ~IShaderStage();
};
}

View File

@ -7,6 +7,7 @@
using namespace Dawn;
Game::Game() :
renderManager()
{
@ -23,12 +24,48 @@ void Game::setCurrentScene(std::shared_ptr<Scene> scene) {
void Game::init() {
renderManager.init(*this);
this->shader = std::make_shared<SimpleTexturedShader>();
this->shader->init();
this->shader->bind();
this->mesh = std::make_shared<Mesh>();
this->mesh->createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
QuadMesh::buffer(this->mesh, glm::vec4(-0.5f, -0.5f, 0.5f, 0.5f), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f), 0, 0);
}
void Game::update() {
renderManager.update(*this);
glm::mat4 view = glm::lookAt(
glm::vec3(3, 3, 3),
glm::vec3(0, 0, 0),
glm::vec3(0, 1, 0)
);
glm::mat4 proj = glm::perspective(
glm::radians(45.0f),
800.0f / 600.0f,
0.1f,
100.0f
);
glm::mat4 model = glm::mat4(1.0f);
this->shader->bind();
this->shader->setData(SimpleTexturedShaderData {
.projection = proj,
.view = view,
.model = model,
.color = COLOR_WHITE,
.hasTexture = false,
.texture = 0
});
this->shader->upload();
this->mesh->draw(MeshDrawMode::TRIANGLES, 0, QUAD_INDICE_COUNT);
}
Game::~Game() {
shader = nullptr;
mesh = nullptr;
}

View File

@ -7,12 +7,17 @@
#include "dawn.hpp"
#include "display/RenderManager.hpp"
#include "display/mesh/QuadMesh.hpp"
#include "display/shader/SimpleTexturedShader.hpp"
namespace Dawn {
class Scene;
class Game : std::enable_shared_from_this<Game> {
class Game {
private:
std::shared_ptr<Scene> currentScene;
std::shared_ptr<Mesh> mesh;
std::shared_ptr<SimpleTexturedShader> shader;
public:
RenderManager renderManager;

View File

@ -7,7 +7,8 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
BackBuffer.cpp
Texture.cpp
Texture.cpp
RenderManager.cpp
)
# Subdirs

View File

@ -9,7 +9,6 @@
using namespace Dawn;
RenderManager::RenderManager() :
renderPipeline(),
shaderManager()
{
}

View File

@ -6,7 +6,6 @@
#pragma once
#include "dawn.hpp"
#include "display/RenderTarget.hpp"
#include "display/RenderPipeline.hpp"
#include "display/shader/ShaderManager.hpp"
#include "display/BackBuffer.hpp"
@ -18,7 +17,6 @@ namespace Dawn {
std::shared_ptr<BackBuffer> backBuffer = nullptr;
public:
RenderPipeline renderPipeline;
ShaderManager shaderManager;
/**

View File

@ -62,10 +62,6 @@ void Texture::setSize(
this->bufferRaw(NULL);
}
// bool_t Texture::isReady() {
// return this->id != -1;
// }
void Texture::updateTextureProperties() {
auto setWrapMode = [](GLenum axis, enum TextureWrapMode wm) {
switch(wm) {

View File

@ -5,14 +5,38 @@
#pragma once
#include "dawnopengl.hpp"
#include "display/ITexture.hpp"
#include "display/Color.hpp"
namespace Dawn {
class TextureRenderTarget;
typedef GLuint textureslot_t;
class Texture : public ITexture {
enum class TextureFormat {
R = 1,
RG = 2,
RGB = 3,
RGBA = 4
};
enum class TextureWrapMode {
REPEAT = 0,
MIRRORED_REPEAT = 1,
CLAMP_TO_EDGE = 2,
CLAMP_TO_BORDER = 3
};
enum class TextureFilterMode {
NEAREST = 0,
LINEAR = 1
};
enum class TextureDataFormat {
UNSIGNED_BYTE = sizeof(uint8_t),
FLOAT = sizeof(float_t)
};
class Texture {
private:
int32_t width = -1;
int32_t height = -1;
@ -24,20 +48,84 @@ namespace Dawn {
void bufferRaw(const void *data);
public:
int32_t getWidth() override;
int32_t getHeight() override;
enum TextureWrapMode wrapModeX = TextureWrapMode::REPEAT;
enum TextureWrapMode wrapModeY = TextureWrapMode::REPEAT;
enum TextureFilterMode filterModeMin = TextureFilterMode::NEAREST;
enum TextureFilterMode filterModeMag = TextureFilterMode::NEAREST;
enum TextureFilterMode mipMapFilterModeMin = TextureFilterMode::NEAREST;
enum TextureFilterMode mipMapFilterModeMag = TextureFilterMode::NEAREST;
/**
* Returns the width of the texture.
*
* @return Width of the texture.
*/
int32_t getWidth();
/**
* Returns the height of the texture.
*
* @return Height of the texture.
*/
int32_t getHeight();
/**
* Initializes a texture.
*
* @param width Width of the texture (in pixels).
* @param height Height of the texture (in pixels).
* @param format Data format of the texture to use.
* @param dataFormat Data format of the texture to use.
*/
void setSize(
const int32_t width,
const int32_t height,
const enum TextureFormat format,
const enum TextureDataFormat dataForat
) override;
bool_t isReady() override;
void buffer(const struct ColorU8 pixels[]) override;
void buffer(const struct Color pixels[]);
void buffer(const uint8_t pixels[]) override;
void bind(const uint8_t slot) override;
);
/**
* Returns true only when the texture has been loaded, sized and put on
* the gpu for rendering.
*
* @return True if ready, otherwise false.
*/
bool_t isReady();
/**
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
* avoid doing this too often.
*
* @param pixels Array of pixels you're trying to buffer.
*/
void buffer(const struct ColorU8 pixels[]);
/**
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
* avoid doing this too often.
*
* @param pixels Array of pixels you're trying to buffer.
*/
void buffer(const struct Color pixels[]);
/**
* Buffer pixel data onto the GPU. Pixel buffering is rather costly so
* avoid doing this too often.
*
* @param pixels Array of pixels you're trying to buffer.
*/
void buffer(const uint8_t pixels[]);
/**
* Binds the texture to the given slot (for use by the shaders).
*
* @param slot Slot to bind to.
*/
void bind(const uint8_t slot);
/*
* Destructs and disposes the texture off the GPU.
*/
~Texture();
};
}

View File

@ -6,5 +6,7 @@
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
CubeMesh.cpp
Mesh.cpp
QuadMesh.cpp
)

View File

@ -216,35 +216,10 @@ void Mesh::draw(
glEnableVertexAttribArray(1);
assertNoGLError();
GLuint glDrawMode;
switch(drawMode) {
case MeshDrawMode::TRIANGLES:
glDrawMode = GL_TRIANGLES;
break;
case MeshDrawMode::TRIANGLE_STRIP:
glDrawMode = GL_TRIANGLE_STRIP;
break;
case MeshDrawMode::TRIANGLE_FAN:
glDrawMode = GL_TRIANGLE_FAN;
break;
case MeshDrawMode::LINES:
glDrawMode = GL_LINES;
break;
case MeshDrawMode::POINTS:
glDrawMode = GL_POINTS;
break;
default:
assertUnreachable("Unsupported draw mode");
}
// Render the elements.
glDrawElements(
glDrawMode,
drawMode,
drawCount,
GL_UNSIGNED_INT,
(void *)(sizeof(int32_t) * start)

View File

@ -4,48 +4,104 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "dawn.hpp"
#include "dawnopengl.hpp"
#include "display/mesh/IMesh.hpp"
namespace Dawn {
class Mesh : public IMesh {
enum MeshDrawMode {
TRIANGLES = GL_TRIANGLES,
TRIANGLE_STRIP = GL_TRIANGLE_STRIP,
TRIANGLE_FAN = GL_TRIANGLE_FAN,
LINES = GL_LINES,
POINTS = GL_POINTS,
LINE_STRIP = GL_LINE_STRIP
};
class Mesh {
protected:
GLuint vertexBuffer = -1;
GLuint indexBuffer = -1;
GLuint vertexArray = -1;
/** How many vertices are in the mesh */
int32_t verticeCount = -1;
/** How many indices are in the mesh */
int32_t indiceCount = -1;
public:
/**
* Create a new set of buffers for the mesh to use.
*
* @param verticeCount How many Vertices will this buffer support.
* @param indiceCount How many Indices will this buffer support.
*/
void createBuffers(
const int32_t verticeCount,
const int32_t indiceCount
) override;
);
void disposeBuffers() override;
/**
* Cleanup the buffers on a given mesh. This is useful if you intend to
* expand the count of vertices your mesh supports.
*/
void disposeBuffers();
/**
* Write vertice positions to the mesh.
*
* @param pos Position, within the buffer, to write to.
* @param positions Array of positions to write.
* @param len How many positions are in the array.
*/
void bufferPositions(
const int32_t pos,
const glm::vec3 positions[],
const int32_t len
) override;
);
/**
* Write vertice coordinates to the mesh.
*
* @param pos Position, within the buffer, to write to.
* @param coordinates Array of coordinates to write.
* @param len How many coordinates are in the array.
*/
void bufferCoordinates(
const int32_t pos,
const glm::vec2 coordinates[],
const int32_t len
) override;
);
/**
* Write indices to the mesh.
*
* @param pos Position, within the buffer, to write to.
* @param indices Array of indices to write.
* @param len How many indices are in the array.
*/
void bufferIndices(
const int32_t pos,
const int32_t indices[],
const int32_t len
) override;
);
/**
* Draw a primitive. Primitives are drawn by their indices.
*
* @param drawMode Which drawing mode to use to draw the primitive.
* @param start Start indice (index) to draw.
* @param count Count of indices to draw. Use -1 to draw all.
*/
void draw(
const enum MeshDrawMode drawMode,
const int32_t start,
const int32_t count
) override;
);
/**
* Cleanup a previously initiated mesh.
*/
~Mesh();
};
}

View File

@ -5,4 +5,39 @@
#include "Shader.hpp"
using namespace Dawn;
using namespace Dawn;
size_t shaderParameterTypeGetSize(const enum ShaderParameterType type) {
switch(type) {
case ShaderParameterType::VEC2:
return sizeof(glm::vec2);
case ShaderParameterType::VEC3:
return sizeof(glm::vec3);
case ShaderParameterType::VEC4:
return sizeof(glm::vec4);
case ShaderParameterType::MAT3:
return sizeof(glm::mat3);
case ShaderParameterType::MAT4:
return sizeof(glm::mat4);
case ShaderParameterType::COLOR:
return sizeof(struct Color);
case ShaderParameterType::FLOAT:
return sizeof(float);
case ShaderParameterType::INT:
return sizeof(int32_t);
case ShaderParameterType::TEXTURE:
return sizeof(shadertexturebinding_t);
default:
assertUnreachable("Unknown ShaderParameterType");
return 0;
};
}

View File

@ -5,7 +5,6 @@
#pragma once
#include "display/shader/ShaderStage.hpp"
#include "display/shader/IShader.hpp"
#include "error/assert.hpp"
#include "error/assertgl.hpp"
#include "display/Color.hpp"
@ -21,17 +20,22 @@ namespace Dawn {
GLSL_330_CORE
};
class ShaderBase {
};
template<typename T>
class Shader : public IShader<T> {
class Shader : public ShaderBase {
private:
std::vector<std::shared_ptr<ShaderStage>> stages;
std::vector<struct ShaderParameter> parameters;
std::vector<struct IShaderStructure> structures;
enum ShaderOpenGLVariant variant;
GLuint shaderProgram = -1;
protected:
T data;
/**
* Overridable function to get the stages for the shader.
*
@ -50,11 +54,29 @@ namespace Dawn {
) = 0;
public:
/**
* Returns the currently uploaded data on the Shader.
*
* @return The uploaded data.
*/
T getData() {
return data;
}
/**
* Sets the entire data to be uploaded.
*
* @param data Data to be uploaded.
*/
void setData(const T data) {
this->data = data;
}
/**
* Initializes the shader, this needs to be called before the shader can
* be used.
*/
void init() override {
void init() {
// Determine which kind of OpenGL shader to use.
variant = ShaderOpenGLVariant::GLSL_330_CORE;
@ -136,7 +158,7 @@ namespace Dawn {
* Binds the shader as the current one, does not upload any data, somewhat
* relies on something else uploading the data.
*/
void bind() override {
void bind() {
glUseProgram(shaderProgram);
assertNoGLError();
}
@ -144,7 +166,7 @@ namespace Dawn {
/**
* Uploads the data to the GPU.
*/
void upload() override {
void upload() {
switch(this->variant) {
case ShaderOpenGLVariant::GLSL_330_CORE:
for(auto param : parameters) {
@ -222,6 +244,9 @@ namespace Dawn {
}
}
/**
* Disposes of the shader.
*/
~Shader() {
// Delete the structures
for(auto structure : structures) {
@ -235,4 +260,12 @@ namespace Dawn {
assertNoGLError();
}
};
/**
* Returns the size of the ShaderParameterType.
*
* @param type The type to get the size of.
* @return Size of the type.
*/
size_t shaderParameterTypeGetSize(const enum Dawn::ShaderParameterType type);
}

View File

@ -9,7 +9,7 @@
namespace Dawn {
class ShaderManager {
private:
std::vector<std::shared_ptr<IShaderBase>> shaders;
std::vector<std::shared_ptr<ShaderBase>> shaders;
public:
/**

View File

@ -4,10 +4,23 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "display/shader/IShader.hpp"
#include "dawn.hpp"
#include "dawnopengl.hpp"
namespace Dawn {
enum class ShaderParameterType {
VEC2,
VEC3,
VEC4,
MAT3,
MAT4,
COLOR,
FLOAT,
INT,
TEXTURE,
BOOLEAN
};
struct ShaderParameter {
std::string name;
size_t offset;

View File

@ -12,7 +12,7 @@ using namespace Dawn;
ShaderStage::ShaderStage(
const enum ShaderStageType type,
const std::string source
) : IShaderStage(type) {
) : type(type) {
// Get OpenGL Shader Type
GLenum shaderType;
switch(this->type) {

View File

@ -4,13 +4,20 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "dawn.hpp"
#include "dawnopengl.hpp"
#include "display/shader/IShaderStage.hpp"
namespace Dawn {
class ShaderStage : public IShaderStage {
enum class ShaderStageType {
VERTEX,
FRAGMENT,
// COMPUTE
};
class ShaderStage {
public:
GLuint id = -1;
const enum ShaderStageType type;
/**
* Constructs a new ShaderStage.

View File

@ -9,24 +9,24 @@ target_link_libraries(${DAWN_TARGET_NAME}
m
stdc++
vitaGL
mathneon
vitashark
kubridge_stub
SceAppMgr_stub
SceAudio_stub
SceCtrl_stub
SceCommonDialog_stub
SceDisplay_stub
SceKernelDmacMgr_stub
SceGxm_stub
SceShaccCg_stub
SceSysmodule_stub
ScePower_stub
SceTouch_stub
SceVshBridge_stub
SceIofilemgr_stub
SceShaccCgExt
libtaihen_stub.a
# mathneon
# vitashark
# kubridge_stub
# SceAppMgr_stub
# SceAudio_stub
# SceCtrl_stub
# SceCommonDialog_stub
# SceDisplay_stub
# SceKernelDmacMgr_stub
# SceGxm_stub
# SceShaccCg_stub
# SceSysmodule_stub
# ScePower_stub
# SceTouch_stub
# SceVshBridge_stub
# SceIofilemgr_stub
# SceShaccCgExt
# libtaihen_stub.a
)
# Includes

12
src/dawnvita/main.cpp Normal file
View File

@ -0,0 +1,12 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "main.hpp"
using namespace Dawn;
int32_t main(const int32_t argc, const char_t **argv) {
return 0;
}

16
src/dawnvita/main.hpp Normal file
View File

@ -0,0 +1,16 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawn.hpp"
/**
* Main entry to the program.
*
* @param argc The number of arguments passed to the program.
* @param argv The arguments passed to the program.
* @return The exit code of the program.
*/
int32_t main(const int32_t argc, const char_t* args[]);