diff --git a/src/dawnopengl/display/shader/Shader.cpp b/archive/Shader.cpp similarity index 100% rename from src/dawnopengl/display/shader/Shader.cpp rename to archive/Shader.cpp diff --git a/src/dawnopengl/display/shader/Shader.hpp b/archive/Shader.hpp similarity index 100% rename from src/dawnopengl/display/shader/Shader.hpp rename to archive/Shader.hpp diff --git a/src/dawnopengl/display/shader/ShaderParameter.cpp b/archive/ShaderParameter.cpp similarity index 100% rename from src/dawnopengl/display/shader/ShaderParameter.cpp rename to archive/ShaderParameter.cpp diff --git a/src/dawnopengl/display/shader/ShaderParameter.hpp b/archive/ShaderParameter.hpp similarity index 100% rename from src/dawnopengl/display/shader/ShaderParameter.hpp rename to archive/ShaderParameter.hpp diff --git a/archive/ShaderStage.cpp b/archive/ShaderStage.cpp new file mode 100644 index 00000000..20f14e1d --- /dev/null +++ b/archive/ShaderStage.cpp @@ -0,0 +1,74 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "assert/assertgl.hpp" +#include "assert/assert.hpp" +#include "ShaderStage.hpp" + +using namespace Dawn; + +ShaderStage::ShaderStage( + const enum ShaderStageType type, + const std::string source +) : IShaderStage(type) { + // Get OpenGL Shader Type + GLenum shaderType; + switch(this->type) { + case ShaderStageType::VERTEX: + shaderType = GL_VERTEX_SHADER; + break; + + case ShaderStageType::FRAGMENT: + shaderType = GL_FRAGMENT_SHADER; + break; + + // case ShaderStageType::COMPUTE: + // shaderType = GL_COMPUTE; + // break; + + default: + assertUnreachable("Unknown ShaderStageType"); + } + + // Initialize the shader + this->id = glCreateShader(shaderType); + assertNoGLError(); + + // Compile the shader + auto cSource = source.c_str(); + glShaderSource(this->id, 1, &cSource, NULL); + assertNoGLError(); + glCompileShader(this->id); + assertNoGLError(); + + // glShaderBinary(1, &this->id, GL_SHADER_BINARY_FORMAT_SPIR_V, source.data(), source.size()); + // assertNoGLError(); + // glSpecializeShader(this->id, "main", 0, NULL, NULL); + // assertNoGLError(); + + // Validate + GLint status; + glGetShaderiv(this->id, GL_COMPILE_STATUS, &status); + assertNoGLError(); + + if(!status) { + // Failed to compile + GLint logLength; + glGetShaderiv(this->id, GL_INFO_LOG_LENGTH, &logLength); + assertNoGLError(); + + GLchar *log = new GLchar[logLength]; + glGetShaderInfoLog(this->id, logLength, NULL, log); + assertNoGLError(); + assertUnreachable("Failed to compile shader stage %i:\n%s", type, log); + } +} + +ShaderStage::~ShaderStage() { + if(this->id != -1) { + glDeleteShader(this->id); + assertNoGLError(); + } +} \ No newline at end of file diff --git a/archive/ShaderStage.hpp b/archive/ShaderStage.hpp new file mode 100644 index 00000000..f45432eb --- /dev/null +++ b/archive/ShaderStage.hpp @@ -0,0 +1,28 @@ +// 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/IShaderStage.hpp" + +namespace Dawn { + class ShaderStage : public IShaderStage { + public: + GLuint id = -1; + + /** + * Constructs a new ShaderStage. + * + * @param type The type of shader this is. + * @param source The source code to compile. + */ + ShaderStage(const enum ShaderStageType type, const std::string source); + + /** + * Disposes of the shader stage. + */ + ~ShaderStage(); + }; +} \ No newline at end of file diff --git a/src/dawnopengl/display/shader/ShaderStructure.hpp b/archive/ShaderStructure.hpp similarity index 100% rename from src/dawnopengl/display/shader/ShaderStructure.hpp rename to archive/ShaderStructure.hpp diff --git a/src/dawnopengl/display/shader/SimpleTexturedShader.cpp b/archive/SimpleTexturedShader.cpp similarity index 100% rename from src/dawnopengl/display/shader/SimpleTexturedShader.cpp rename to archive/SimpleTexturedShader.cpp diff --git a/src/dawnopengl/display/shader/SimpleTexturedShader.hpp b/archive/SimpleTexturedShader.hpp similarity index 100% rename from src/dawnopengl/display/shader/SimpleTexturedShader.hpp rename to archive/SimpleTexturedShader.hpp diff --git a/src/dawnopengl/display/shader/UIShader.cpp b/archive/UIShader.cpp similarity index 100% rename from src/dawnopengl/display/shader/UIShader.cpp rename to archive/UIShader.cpp diff --git a/src/dawnopengl/display/shader/UIShader.hpp b/archive/UIShader.hpp similarity index 100% rename from src/dawnopengl/display/shader/UIShader.hpp rename to archive/UIShader.hpp diff --git a/src/dawn/component/ui/CMakeLists.txt b/archive/component/ui/CMakeLists.txt similarity index 100% rename from src/dawn/component/ui/CMakeLists.txt rename to archive/component/ui/CMakeLists.txt diff --git a/src/dawn/component/ui/UICanvas.cpp b/archive/component/ui/UICanvas.cpp similarity index 100% rename from src/dawn/component/ui/UICanvas.cpp rename to archive/component/ui/UICanvas.cpp diff --git a/src/dawn/component/ui/UICanvas.hpp b/archive/component/ui/UICanvas.hpp similarity index 100% rename from src/dawn/component/ui/UICanvas.hpp rename to archive/component/ui/UICanvas.hpp diff --git a/src/dawn/ui/CMakeLists.txt b/archive/ui/CMakeLists.txt similarity index 100% rename from src/dawn/ui/CMakeLists.txt rename to archive/ui/CMakeLists.txt diff --git a/src/dawn/ui/UIAlignableElement.cpp b/archive/ui/UIAlignableElement.cpp similarity index 100% rename from src/dawn/ui/UIAlignableElement.cpp rename to archive/ui/UIAlignableElement.cpp diff --git a/src/dawn/ui/UIAlignableElement.hpp b/archive/ui/UIAlignableElement.hpp similarity index 100% rename from src/dawn/ui/UIAlignableElement.hpp rename to archive/ui/UIAlignableElement.hpp diff --git a/src/dawn/ui/UIElement.cpp b/archive/ui/UIElement.cpp similarity index 100% rename from src/dawn/ui/UIElement.cpp rename to archive/ui/UIElement.cpp diff --git a/src/dawn/ui/UIElement.hpp b/archive/ui/UIElement.hpp similarity index 100% rename from src/dawn/ui/UIElement.hpp rename to archive/ui/UIElement.hpp diff --git a/src/dawn/ui/UIMenu.cpp b/archive/ui/UIMenu.cpp similarity index 100% rename from src/dawn/ui/UIMenu.cpp rename to archive/ui/UIMenu.cpp diff --git a/src/dawn/ui/UIMenu.hpp b/archive/ui/UIMenu.hpp similarity index 100% rename from src/dawn/ui/UIMenu.hpp rename to archive/ui/UIMenu.hpp diff --git a/src/dawn/ui/UISubAlignableElement.cpp b/archive/ui/UISubAlignableElement.cpp similarity index 100% rename from src/dawn/ui/UISubAlignableElement.cpp rename to archive/ui/UISubAlignableElement.cpp diff --git a/src/dawn/ui/UISubAlignableElement.hpp b/archive/ui/UISubAlignableElement.hpp similarity index 100% rename from src/dawn/ui/UISubAlignableElement.hpp rename to archive/ui/UISubAlignableElement.hpp diff --git a/src/dawn/ui/container/CMakeLists.txt b/archive/ui/container/CMakeLists.txt similarity index 100% rename from src/dawn/ui/container/CMakeLists.txt rename to archive/ui/container/CMakeLists.txt diff --git a/src/dawn/ui/container/UIColumnContainer.cpp b/archive/ui/container/UIColumnContainer.cpp similarity index 100% rename from src/dawn/ui/container/UIColumnContainer.cpp rename to archive/ui/container/UIColumnContainer.cpp diff --git a/src/dawn/ui/container/UIColumnContainer.hpp b/archive/ui/container/UIColumnContainer.hpp similarity index 100% rename from src/dawn/ui/container/UIColumnContainer.hpp rename to archive/ui/container/UIColumnContainer.hpp diff --git a/src/dawn/ui/container/UIContainer.cpp b/archive/ui/container/UIContainer.cpp similarity index 100% rename from src/dawn/ui/container/UIContainer.cpp rename to archive/ui/container/UIContainer.cpp diff --git a/src/dawn/ui/container/UIContainer.hpp b/archive/ui/container/UIContainer.hpp similarity index 100% rename from src/dawn/ui/container/UIContainer.hpp rename to archive/ui/container/UIContainer.hpp diff --git a/src/dawn/ui/container/UIPaddingContainer.cpp b/archive/ui/container/UIPaddingContainer.cpp similarity index 100% rename from src/dawn/ui/container/UIPaddingContainer.cpp rename to archive/ui/container/UIPaddingContainer.cpp diff --git a/src/dawn/ui/container/UIPaddingContainer.hpp b/archive/ui/container/UIPaddingContainer.hpp similarity index 100% rename from src/dawn/ui/container/UIPaddingContainer.hpp rename to archive/ui/container/UIPaddingContainer.hpp diff --git a/src/dawn/ui/container/UIRowContainer.cpp b/archive/ui/container/UIRowContainer.cpp similarity index 100% rename from src/dawn/ui/container/UIRowContainer.cpp rename to archive/ui/container/UIRowContainer.cpp diff --git a/src/dawn/ui/container/UIRowContainer.hpp b/archive/ui/container/UIRowContainer.hpp similarity index 100% rename from src/dawn/ui/container/UIRowContainer.hpp rename to archive/ui/container/UIRowContainer.hpp diff --git a/src/dawn/ui/elements/CMakeLists.txt b/archive/ui/elements/CMakeLists.txt similarity index 100% rename from src/dawn/ui/elements/CMakeLists.txt rename to archive/ui/elements/CMakeLists.txt diff --git a/src/dawn/ui/elements/UILabel.cpp b/archive/ui/elements/UILabel.cpp similarity index 100% rename from src/dawn/ui/elements/UILabel.cpp rename to archive/ui/elements/UILabel.cpp diff --git a/src/dawn/ui/elements/UILabel.hpp b/archive/ui/elements/UILabel.hpp similarity index 100% rename from src/dawn/ui/elements/UILabel.hpp rename to archive/ui/elements/UILabel.hpp diff --git a/src/dawn/ui/elements/UIRectangle.cpp b/archive/ui/elements/UIRectangle.cpp similarity index 100% rename from src/dawn/ui/elements/UIRectangle.cpp rename to archive/ui/elements/UIRectangle.cpp diff --git a/src/dawn/ui/elements/UIRectangle.hpp b/archive/ui/elements/UIRectangle.hpp similarity index 100% rename from src/dawn/ui/elements/UIRectangle.hpp rename to archive/ui/elements/UIRectangle.hpp diff --git a/src/dawn/CMakeLists.txt b/src/dawn/CMakeLists.txt index bdde05a6..10d67459 100644 --- a/src/dawn/CMakeLists.txt +++ b/src/dawn/CMakeLists.txt @@ -33,7 +33,6 @@ add_subdirectory(scene) add_subdirectory(settings) add_subdirectory(time) add_subdirectory(util) -add_subdirectory(ui) # Assets diff --git a/src/dawn/asset/loader/ShaderLoader.cpp b/src/dawn/asset/loader/ShaderLoader.cpp index c354e3dd..b0730b0f 100644 --- a/src/dawn/asset/loader/ShaderLoader.cpp +++ b/src/dawn/asset/loader/ShaderLoader.cpp @@ -18,7 +18,7 @@ ShaderLoader::ShaderLoader( ) : AssetLoader(assetManager, name), state(ShaderLoaderState::INITIAL), - shader(std::make_shared()) + shader(std::make_shared()) { } @@ -76,7 +76,7 @@ void ShaderLoader::updateSync() { // Create the shader program. Slang::ComPtr blob; slang::ProgramLayout* layout = program->getLayout(); - std::vector> shaderEntries; + std::vector> shaderStages; for(auto i = 0; i < definedEntryPointCount; i++) { // Get the code auto result = linkedProgram->getEntryPointCode( @@ -95,18 +95,18 @@ void ShaderLoader::updateSync() { auto stage = entryPointReflection->getStage(); // Create the shader entry - auto shaderEntry = std::make_shared(); - shaderEntry->init( + auto shaderStage = std::make_shared(); + shaderStage->init( stage, std::string((const char*)blob->getBufferPointer()) ); // Add to the list - shaderEntries.push_back(shaderEntry); + shaderStages.push_back(shaderStage); } // Create the shader program. - shader->init(shaderEntries); + shader->init(shaderStages); // Finished loading. delete [] components; @@ -118,7 +118,7 @@ std::string ShaderLoader::getAssetType() const { return ShaderLoader::ASSET_TYPE; } -std::shared_ptr ShaderLoader::getShader() { +std::shared_ptr ShaderLoader::getShader() { assertNotNull(shader, "ShaderLoader shader is null."); return shader; } diff --git a/src/dawn/asset/loader/ShaderLoader.hpp b/src/dawn/asset/loader/ShaderLoader.hpp index cad59ff7..6e781bee 100644 --- a/src/dawn/asset/loader/ShaderLoader.hpp +++ b/src/dawn/asset/loader/ShaderLoader.hpp @@ -7,7 +7,7 @@ #include "asset/AssetLoader.hpp" #include "asset/AssetDataLoader.hpp" #include "display/shader/ShaderManager.hpp" -#include "display/shader/ShaderProgram2.hpp" +#include "display/shader/ShaderProgram.hpp" namespace Dawn { enum class ShaderLoaderState { @@ -19,7 +19,7 @@ namespace Dawn { class ShaderLoader : public AssetLoader { protected: enum ShaderLoaderState state; - std::shared_ptr shader; + std::shared_ptr shader; public: const static std::string ASSET_TYPE; @@ -40,9 +40,9 @@ namespace Dawn { /** * Retreives the shader program for this loader. * - * @return std::shared_ptr + * @return The shader program that this loader is managing. */ - std::shared_ptr getShader(); + std::shared_ptr getShader(); ~ShaderLoader(); }; diff --git a/src/dawn/component/CMakeLists.txt b/src/dawn/component/CMakeLists.txt index 390c1143..01b8ff32 100644 --- a/src/dawn/component/CMakeLists.txt +++ b/src/dawn/component/CMakeLists.txt @@ -9,5 +9,4 @@ target_sources(${DAWN_TARGET_NAME} ) # Subdirs -add_subdirectory(display) -add_subdirectory(ui) \ No newline at end of file +add_subdirectory(display) \ No newline at end of file diff --git a/src/dawn/component/display/IRenderableComponent.hpp b/src/dawn/component/display/IRenderableComponent.hpp index 1bf77f5a..6abfa2bd 100644 --- a/src/dawn/component/display/IRenderableComponent.hpp +++ b/src/dawn/component/display/IRenderableComponent.hpp @@ -17,7 +17,7 @@ namespace Dawn { * @param ctx Context for the render pass. * @return List of render passes. */ - virtual std::vector> getPasses( + virtual std::vector> getPasses( struct RenderPassContext &ctx ) = 0; }; @@ -31,26 +31,26 @@ namespace Dawn { * @param data Data to use for the render pass. * @return Created render pass. */ - template - std::shared_ptr createRenderPass( - SceneComponent &self, - const D data, - const std::unordered_map< - shadertexturebinding_t, std::shared_ptr - > textures = {}, - const std::shared_ptr mesh = nullptr, - const enum MeshDrawMode drawMode = MeshDrawMode::TRIANGLES, - int32_t indiceStart = 0, - int32_t indiceCount = -1 - ) { - return std::make_shared>( - self, - data, - textures, - mesh, - drawMode, - indiceStart, - indiceCount - ); - } + // template + // std::shared_ptr createRenderPass( + // SceneComponent &self, + // const D data, + // const std::unordered_map< + // shadertexturebinding_t, std::shared_ptr + // > textures = {}, + // const std::shared_ptr mesh = nullptr, + // const enum MeshDrawMode drawMode = MeshDrawMode::TRIANGLES, + // int32_t indiceStart = 0, + // int32_t indiceCount = -1 + // ) { + // return std::make_shared>( + // self, + // data, + // textures, + // mesh, + // drawMode, + // indiceStart, + // indiceCount + // ); + // } } \ No newline at end of file diff --git a/src/dawn/component/display/material/Material.cpp b/src/dawn/component/display/material/Material.cpp index 63b6b7ac..492f3e03 100644 --- a/src/dawn/component/display/material/Material.cpp +++ b/src/dawn/component/display/material/Material.cpp @@ -9,11 +9,7 @@ using namespace Dawn; void Material::onInit() { - this->lockedShaders = this->getLockedShaders( - getGame()->renderHost->shaderManager - ); } void Material::onDispose() { - this->lockedShaders.clear(); } \ No newline at end of file diff --git a/src/dawn/component/display/material/Material.hpp b/src/dawn/component/display/material/Material.hpp index 55efec6f..c47bdcc0 100644 --- a/src/dawn/component/display/material/Material.hpp +++ b/src/dawn/component/display/material/Material.hpp @@ -13,18 +13,8 @@ namespace Dawn { public IRenderableComponent { private: - std::vector> lockedShaders; protected: - /** - * Locks the shaders to be used for rendering. - * - * @param shaderManager Shader manager to use. - * @return List of shaders to be used. - */ - virtual std::vector> getLockedShaders( - ShaderManager &shaderManager - ) = 0; public: void onInit() override; diff --git a/src/dawn/component/display/material/SimpleTexturedMaterial.cpp b/src/dawn/component/display/material/SimpleTexturedMaterial.cpp index 19f7e6f4..ed694d9f 100644 --- a/src/dawn/component/display/material/SimpleTexturedMaterial.cpp +++ b/src/dawn/component/display/material/SimpleTexturedMaterial.cpp @@ -9,14 +9,6 @@ using namespace Dawn; -std::vector< - std::shared_ptr -> SimpleTexturedMaterial::getLockedShaders(ShaderManager &shaderManager) { - return { - shaderManager.getShader() - }; -} - void SimpleTexturedMaterial::load(std::shared_ptr ctx) { if(ctx->data.contains("color")) { this->setColor(JSON::color(ctx->data["color"])); @@ -31,7 +23,7 @@ void SimpleTexturedMaterial::load(std::shared_ptr ctx) { } struct Color SimpleTexturedMaterial::getColor() { - return this->data.data.color; + return this->data.color; } std::shared_ptr SimpleTexturedMaterial::getTexture() { @@ -45,32 +37,32 @@ void SimpleTexturedMaterial::setTexture( } void SimpleTexturedMaterial::setColor(const struct Color color) { - this->data.data.color = color; + this->data.color = color; } -std::vector> SimpleTexturedMaterial::getPasses( +std::vector> SimpleTexturedMaterial::getPasses( struct RenderPassContext &ctx ) { - this->data.data.model = this->getItem()->getWorldTransform(); - this->data.data.projection = ctx.camera->getProjection(); - this->data.data.view = ctx.camera->getItem()->getWorldTransform(); - auto textures = std::unordered_map< - shadertexturebinding_t, std::shared_ptr - >(); + // this->data.model = this->getItem()->getWorldTransform(); + // this->data.projection = ctx.camera->getProjection(); + // this->data.view = ctx.camera->getItem()->getWorldTransform(); + // auto textures = std::unordered_map< + // shadertexturebinding_t, std::shared_ptr + // >(); - if(this->texture) { - this->data.data.hasTexture = true; - this->data.texture = 0; - textures[this->data.texture] = this->texture; - } else { - this->data.data.hasTexture = false; - } + // if(this->texture) { + // this->data.hasTexture = true; + // this->data.texture = 0; + // textures[this->data.texture] = this->texture; + // } else { + // this->data.data.hasTexture = false; + // } return { - createRenderPass( - *this, - data, - textures - ) + // createRenderPass( + // *this, + // data, + // textures + // ) }; } diff --git a/src/dawn/component/display/material/SimpleTexturedMaterial.hpp b/src/dawn/component/display/material/SimpleTexturedMaterial.hpp index 5a364e16..975a26b9 100644 --- a/src/dawn/component/display/material/SimpleTexturedMaterial.hpp +++ b/src/dawn/component/display/material/SimpleTexturedMaterial.hpp @@ -5,19 +5,24 @@ #pragma once #include "component/display/material/Material.hpp" -#include "display/shader/SimpleTexturedShader.hpp" #include "display/Texture.hpp" namespace Dawn { + struct SimpleTexturedMaterialShaderData { + int32_t t; + struct Color color; + glm::mat4 model; + glm::mat4 projection; + glm::mat4 view; + bool hasTexture; + }; + class SimpleTexturedMaterial : public Material { private: - struct SimpleTexturedShaderData data; + struct SimpleTexturedMaterialShaderData data; std::shared_ptr texture; protected: - std::vector> getLockedShaders( - ShaderManager &shaderManager - ) override; public: void load(std::shared_ptr ctx) override; @@ -48,7 +53,7 @@ namespace Dawn { */ void setColor(const struct Color color); - std::vector> getPasses( + std::vector> getPasses( struct RenderPassContext &ctx ) override; }; diff --git a/src/dawn/display/CMakeLists.txt b/src/dawn/display/CMakeLists.txt index 9dae7a12..06636f38 100644 --- a/src/dawn/display/CMakeLists.txt +++ b/src/dawn/display/CMakeLists.txt @@ -15,4 +15,5 @@ target_sources(${DAWN_TARGET_NAME} add_subdirectory(mesh) add_subdirectory(shader) add_subdirectory(font) -add_subdirectory(tileset) \ No newline at end of file +add_subdirectory(tileset) +add_subdirectory(pass) \ No newline at end of file diff --git a/src/dawn/display/IRenderHost.hpp b/src/dawn/display/IRenderHost.hpp index 0ab552a9..02e496fd 100644 --- a/src/dawn/display/IRenderHost.hpp +++ b/src/dawn/display/IRenderHost.hpp @@ -7,7 +7,6 @@ #include "dawn.hpp" #include "display/RenderTarget.hpp" #include "display/RenderPipeline.hpp" -#include "display/shader/ShaderManager.hpp" namespace Dawn { class Game; @@ -15,7 +14,6 @@ namespace Dawn { class IRenderHost { public: RenderPipeline renderPipeline; - ShaderManager shaderManager; /** * Creates a render host. diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index 9a3aca83..c441eec4 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -78,7 +78,7 @@ void RenderPipeline::renderSceneCamera( }; // Get list of renderables - std::vector> renderPasses; + std::vector> renderPasses; auto renderables = scene->findComponents(); for(auto renderable : renderables) { auto rp = renderable->getPasses(ctx); @@ -95,9 +95,6 @@ void RenderPipeline::renderSceneCamera( ); for(auto renderPass : renderPasses) { - renderPass->bind(); - renderPass->setData(); - renderPass->upload(); renderPass->draw(); } } diff --git a/src/dawnrpg/display/shader/CMakeLists.txt b/src/dawn/display/pass/CMakeLists.txt similarity index 90% rename from src/dawnrpg/display/shader/CMakeLists.txt rename to src/dawn/display/pass/CMakeLists.txt index 2f9f8d34..fe8b62a1 100644 --- a/src/dawnrpg/display/shader/CMakeLists.txt +++ b/src/dawn/display/pass/CMakeLists.txt @@ -5,5 +5,5 @@ target_sources(${DAWN_TARGET_NAME} PRIVATE - MapShader.cpp + RenderPass.cpp ) \ No newline at end of file diff --git a/src/dawn/display/pass/IRenderPass.hpp b/src/dawn/display/pass/IRenderPass.hpp deleted file mode 100644 index a06da51b..00000000 --- a/src/dawn/display/pass/IRenderPass.hpp +++ /dev/null @@ -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; - - /** - * 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() { - } - }; -} \ No newline at end of file diff --git a/src/dawn/display/pass/RenderPass.cpp b/src/dawn/display/pass/RenderPass.cpp new file mode 100644 index 00000000..740d64fb --- /dev/null +++ b/src/dawn/display/pass/RenderPass.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2024 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "RenderPass.hpp" +#include "component/display/MeshRenderer.hpp" + +using namespace Dawn; + +RenderPass::RenderPass( + SceneComponent &self, + const std::shared_ptr mesh, + const enum MeshDrawMode drawMode, + const int32_t indiceStart, + const int32_t indiceCount +) : + mesh(mesh), + drawMode(drawMode), + indiceStart(indiceStart), + indiceCount(indiceCount) +{ + // Need mesh? + if(!this->mesh) { + auto meshRenderer = self.getItem()->getComponent(); + if(meshRenderer) this->mesh = meshRenderer->mesh; + } +} + +void RenderPass::draw() { + mesh->draw(drawMode, indiceStart, indiceCount); +} \ No newline at end of file diff --git a/src/dawn/display/pass/RenderPass.hpp b/src/dawn/display/pass/RenderPass.hpp index 53669b51..a6f02f3a 100644 --- a/src/dawn/display/pass/RenderPass.hpp +++ b/src/dawn/display/pass/RenderPass.hpp @@ -4,25 +4,16 @@ // 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" +#include "display/mesh/Mesh.hpp" +#include "scene/SceneComponent.hpp" namespace Dawn { - template - class RenderPass : public IRenderPass { + class RenderPass { private: - std::shared_ptr shader; - const std::unordered_map< - shadertexturebinding_t, std::shared_ptr - > textures; std::shared_ptr mesh; const enum MeshDrawMode drawMode; const int32_t indiceStart; const int32_t indiceCount; - const D data; public: /** @@ -37,58 +28,20 @@ namespace Dawn { */ RenderPass( SceneComponent &self, - const D d, - const std::unordered_map< - shadertexturebinding_t, std::shared_ptr - > textures, const std::shared_ptr 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() - ); - assertNotNull(shader, "Shader cannot be null!"); + ); - // Need mesh? - if(!this->mesh) { - auto meshRenderer = self.getItem()->getComponent(); - if(meshRenderer) this->mesh = meshRenderer->mesh; - } - } + /** + * Draws the mesh for this render pass. + */ + void draw(); - 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 { - } + /** + * Cleans up the render pass. + */ + ~RenderPass(); }; } \ No newline at end of file diff --git a/src/dawn/display/shader/CMakeLists.txt b/src/dawn/display/shader/CMakeLists.txt index b36cc917..1258ebd7 100644 --- a/src/dawn/display/shader/CMakeLists.txt +++ b/src/dawn/display/shader/CMakeLists.txt @@ -6,9 +6,9 @@ # Sources target_sources(${DAWN_TARGET_NAME} PRIVATE - IShader.cpp + IShaderProgram.cpp IShaderStage.cpp ShaderManager.cpp ShaderManagerSlangFileSystem.cpp - IShaderProgram2.cpp + IShaderProgram.cpp ) \ No newline at end of file diff --git a/src/dawn/display/shader/IShader.cpp b/src/dawn/display/shader/IShader.cpp deleted file mode 100644 index cba02670..00000000 --- a/src/dawn/display/shader/IShader.cpp +++ /dev/null @@ -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 "assert/assert.hpp" -#include "display/Color.hpp" -#include "display/Texture.hpp" - -using namespace Dawn; - -size_t shaderParameterTypeGetSize(const 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; - } -} diff --git a/src/dawn/display/shader/IShader.hpp b/src/dawn/display/shader/IShader.hpp deleted file mode 100644 index 9cc7ff38..00000000 --- a/src/dawn/display/shader/IShader.hpp +++ /dev/null @@ -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 - 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 Dawn::ShaderParameterType type); \ No newline at end of file diff --git a/src/dawn/display/shader/IShaderProgram.cpp b/src/dawn/display/shader/IShaderProgram.cpp new file mode 100644 index 00000000..694bfcf7 --- /dev/null +++ b/src/dawn/display/shader/IShaderProgram.cpp @@ -0,0 +1,17 @@ +// Copyright (c) 2024 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "IShaderProgram.hpp" + +using namespace Dawn; + +void IShaderProgram::init( + const std::vector> &stages +) { + this->stages = stages; +} + +IShaderProgram::~IShaderProgram() { +} \ No newline at end of file diff --git a/src/dawn/display/shader/IShaderProgram.hpp b/src/dawn/display/shader/IShaderProgram.hpp new file mode 100644 index 00000000..fe4e2c09 --- /dev/null +++ b/src/dawn/display/shader/IShaderProgram.hpp @@ -0,0 +1,30 @@ +// Copyright (c) 2024 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "display/shader/ShaderStage.hpp" + +namespace Dawn { + + class IShaderProgram { + protected: + std::vector> stages; + + public: + /** + * Initialize the IShaderProgram2 object + * + * @param stages The list of shader stages to initialize with. + */ + virtual void init( + const std::vector> &stages + ) = 0; + + /** + * Destroy the IShaderProgram2 object + */ + virtual ~IShaderProgram(); + }; +} \ No newline at end of file diff --git a/src/dawn/display/shader/IShaderProgram2.cpp b/src/dawn/display/shader/IShaderProgram2.cpp deleted file mode 100644 index 4b026660..00000000 --- a/src/dawn/display/shader/IShaderProgram2.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2024 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "IShaderProgram2.hpp" - -using namespace Dawn; - -IShaderEntry::~IShaderEntry() { -} - -void IShaderProgram2::init( - const std::vector> &entries -) { - this->entries = entries; -} - -IShaderProgram2::~IShaderProgram2() { - -} \ No newline at end of file diff --git a/src/dawn/display/shader/IShaderProgram2.hpp b/src/dawn/display/shader/IShaderProgram2.hpp deleted file mode 100644 index 00f87c32..00000000 --- a/src/dawn/display/shader/IShaderProgram2.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2024 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "dawn.hpp" -#include "slang.h" - -using namespace slang; - -namespace Dawn { - class ShaderEntry; - - class IShaderEntry { - public: - /** - * Initialize the IShaderEntry object - * - * @param stage The stage of the shader entry. - * @param code The code of the shader entry. - */ - virtual void init( - const SlangStage &stage, - const std::string &code - ) = 0; - - /** - * Destroy the IShaderEntry object - */ - virtual ~IShaderEntry(); - }; - - class IShaderProgram2 { - protected: - std::vector> entries; - - public: - /** - * Initialize the IShaderProgram2 object - * - * @param entries The list of shader entries to initialize with. - */ - virtual void init( - const std::vector> &entries - ) = 0; - - /** - * Destroy the IShaderProgram2 object - */ - virtual ~IShaderProgram2(); - }; -} \ No newline at end of file diff --git a/src/dawn/display/shader/IShaderStage.cpp b/src/dawn/display/shader/IShaderStage.cpp index 5fe3c852..aa8ea88e 100644 --- a/src/dawn/display/shader/IShaderStage.cpp +++ b/src/dawn/display/shader/IShaderStage.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Dominic Masters +// Copyright (c) 2024 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT @@ -7,12 +7,5 @@ using namespace Dawn; -IShaderStage::IShaderStage(const ShaderStageType type) : - type(type) -{ - -} - IShaderStage::~IShaderStage() { - } \ No newline at end of file diff --git a/src/dawn/display/shader/IShaderStage.hpp b/src/dawn/display/shader/IShaderStage.hpp index 6d30a22d..cb65b383 100644 --- a/src/dawn/display/shader/IShaderStage.hpp +++ b/src/dawn/display/shader/IShaderStage.hpp @@ -1,31 +1,30 @@ -// Copyright (c) 2023 Dominic Masters +// Copyright (c) 2024 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once #include "dawn.hpp" +#include "slang.h" + +using namespace slang; namespace Dawn { - enum class ShaderStageType { - VERTEX, - FRAGMENT, - // COMPUTE - }; - class IShaderStage { public: - const enum ShaderStageType type; - /** - * Constructs a new Shader Stage. + * Initialize the IShaderEntry object * - * @param type Type of shader stage. + * @param stage The stage of the shader entry. + * @param code The code of the shader entry. */ - IShaderStage(const ShaderStageType type); + virtual void init( + const SlangStage &stage, + const std::string &code + ) = 0; /** - * Destroy the IShaderStage object + * Destroy the IShaderEntry object */ virtual ~IShaderStage(); }; diff --git a/src/dawn/display/shader/ShaderManager.cpp b/src/dawn/display/shader/ShaderManager.cpp index 3ccb8612..04d81f9f 100644 --- a/src/dawn/display/shader/ShaderManager.cpp +++ b/src/dawn/display/shader/ShaderManager.cpp @@ -47,6 +47,4 @@ std::shared_ptr ShaderManager::getGame() { } ShaderManager::~ShaderManager() { - // Clear all shaders - shaders.clear(); } \ No newline at end of file diff --git a/src/dawn/display/shader/ShaderManager.hpp b/src/dawn/display/shader/ShaderManager.hpp index 193e339b..94ac755c 100644 --- a/src/dawn/display/shader/ShaderManager.hpp +++ b/src/dawn/display/shader/ShaderManager.hpp @@ -4,7 +4,6 @@ // https://opensource.org/licenses/MIT #pragma once -#include "display/shader/Shader.hpp" #include "ShaderManagerSlangFileSystem.hpp" using namespace slang; @@ -14,11 +13,8 @@ namespace Dawn { class ShaderManager : public std::enable_shared_from_this { private: - std::vector> shaders; - std::weak_ptr game; ShaderManagerSlangFileSystem fileSystem; - Slang::ComPtr globalSession; TargetDesc targetDescription; SessionDesc sessionDescription; @@ -44,34 +40,6 @@ namespace Dawn { */ std::shared_ptr getGame(); - /** - * Retreives an instance of the shader from the shader manager. If the - * shader does not exist it will be created. - * - * @tparam T Type of shader to retreive. - * @return Shader instance. - */ - template - std::shared_ptr getShader() { - auto itShaders = shaders.begin(); - while(itShaders != shaders.end()) { - auto shader = itShaders->lock(); - if(!shader) { - itShaders = shaders.erase(itShaders); - continue; - } - - std::shared_ptr casted = std::dynamic_pointer_cast(shader); - if(casted) return casted; - itShaders++; - } - - auto newShader = std::make_shared(); - shaders.push_back(newShader); - newShader->init(); - return newShader; - } - /** * Disposes of all shaders. */ diff --git a/src/dawnopengl/display/shader/CMakeLists.txt b/src/dawnopengl/display/shader/CMakeLists.txt index d855f60b..753875ec 100644 --- a/src/dawnopengl/display/shader/CMakeLists.txt +++ b/src/dawnopengl/display/shader/CMakeLists.txt @@ -6,10 +6,6 @@ # Sources target_sources(${DAWN_TARGET_NAME} PRIVATE - Shader.cpp + ShaderProgram.cpp ShaderStage.cpp - SimpleTexturedShader.cpp - UIShader.cpp - ShaderParameter.cpp - ShaderProgram2.cpp ) \ No newline at end of file diff --git a/src/dawnopengl/display/shader/ShaderProgram.cpp b/src/dawnopengl/display/shader/ShaderProgram.cpp new file mode 100644 index 00000000..7edd4fcf --- /dev/null +++ b/src/dawnopengl/display/shader/ShaderProgram.cpp @@ -0,0 +1,17 @@ +// Copyright (c) 2024 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "ShaderProgram.hpp" + +using namespace Dawn; + +void ShaderProgram::init( + const std::vector> &stages +) { + IShaderProgram::init(stages); +} + +ShaderProgram::~ShaderProgram() { +} \ No newline at end of file diff --git a/src/dawnopengl/display/shader/ShaderProgram.hpp b/src/dawnopengl/display/shader/ShaderProgram.hpp new file mode 100644 index 00000000..232d7517 --- /dev/null +++ b/src/dawnopengl/display/shader/ShaderProgram.hpp @@ -0,0 +1,17 @@ +// Copyright (c) 2024 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "display/shader/IShaderProgram.hpp" + +namespace Dawn { + class ShaderProgram : public IShaderProgram { + public: + void init( + const std::vector> &stages + ) override; + ~ShaderProgram(); + }; +} \ No newline at end of file diff --git a/src/dawnopengl/display/shader/ShaderProgram2.cpp b/src/dawnopengl/display/shader/ShaderProgram2.cpp deleted file mode 100644 index dc5e2b74..00000000 --- a/src/dawnopengl/display/shader/ShaderProgram2.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2024 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "ShaderProgram2.hpp" - -using namespace Dawn; - -void ShaderEntry::init( - const SlangStage &stage, - const std::string &code -) { -} - -ShaderEntry::~ShaderEntry() { -} - -// // // - -void ShaderProgram2::init( - const std::vector> &entries -) { - IShaderProgram2::init(entries); -} - -ShaderProgram2::~ShaderProgram2() { -} \ No newline at end of file diff --git a/src/dawnopengl/display/shader/ShaderProgram2.hpp b/src/dawnopengl/display/shader/ShaderProgram2.hpp deleted file mode 100644 index dac3a161..00000000 --- a/src/dawnopengl/display/shader/ShaderProgram2.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2024 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "display/shader/IShaderProgram2.hpp" - -namespace Dawn { - class ShaderEntry { - protected: - - public: - void init( - const SlangStage &stage, - const std::string &code - ); - ~ShaderEntry(); - }; - - class ShaderProgram2 : public IShaderProgram2 { - public: - void init( - const std::vector> &entries - ) override; - ~ShaderProgram2(); - }; -} \ No newline at end of file diff --git a/src/dawnopengl/display/shader/ShaderStage.cpp b/src/dawnopengl/display/shader/ShaderStage.cpp index 20f14e1d..fc49fc55 100644 --- a/src/dawnopengl/display/shader/ShaderStage.cpp +++ b/src/dawnopengl/display/shader/ShaderStage.cpp @@ -1,74 +1,17 @@ -// Copyright (c) 2023 Dominic Masters +// Copyright (c) 2024 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT -#include "assert/assertgl.hpp" -#include "assert/assert.hpp" #include "ShaderStage.hpp" using namespace Dawn; -ShaderStage::ShaderStage( - const enum ShaderStageType type, - const std::string source -) : IShaderStage(type) { - // Get OpenGL Shader Type - GLenum shaderType; - switch(this->type) { - case ShaderStageType::VERTEX: - shaderType = GL_VERTEX_SHADER; - break; - - case ShaderStageType::FRAGMENT: - shaderType = GL_FRAGMENT_SHADER; - break; - - // case ShaderStageType::COMPUTE: - // shaderType = GL_COMPUTE; - // break; - - default: - assertUnreachable("Unknown ShaderStageType"); - } - - // Initialize the shader - this->id = glCreateShader(shaderType); - assertNoGLError(); - - // Compile the shader - auto cSource = source.c_str(); - glShaderSource(this->id, 1, &cSource, NULL); - assertNoGLError(); - glCompileShader(this->id); - assertNoGLError(); - - // glShaderBinary(1, &this->id, GL_SHADER_BINARY_FORMAT_SPIR_V, source.data(), source.size()); - // assertNoGLError(); - // glSpecializeShader(this->id, "main", 0, NULL, NULL); - // assertNoGLError(); - - // Validate - GLint status; - glGetShaderiv(this->id, GL_COMPILE_STATUS, &status); - assertNoGLError(); - - if(!status) { - // Failed to compile - GLint logLength; - glGetShaderiv(this->id, GL_INFO_LOG_LENGTH, &logLength); - assertNoGLError(); - - GLchar *log = new GLchar[logLength]; - glGetShaderInfoLog(this->id, logLength, NULL, log); - assertNoGLError(); - assertUnreachable("Failed to compile shader stage %i:\n%s", type, log); - } +void ShaderStage::init( + const SlangStage &stage, + const std::string &code +) { } ShaderStage::~ShaderStage() { - if(this->id != -1) { - glDeleteShader(this->id); - assertNoGLError(); - } } \ No newline at end of file diff --git a/src/dawnopengl/display/shader/ShaderStage.hpp b/src/dawnopengl/display/shader/ShaderStage.hpp index f45432eb..83542fd5 100644 --- a/src/dawnopengl/display/shader/ShaderStage.hpp +++ b/src/dawnopengl/display/shader/ShaderStage.hpp @@ -1,28 +1,18 @@ -// Copyright (c) 2023 Dominic Masters +// Copyright (c) 2024 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once -#include "dawnopengl.hpp" #include "display/shader/IShaderStage.hpp" namespace Dawn { class ShaderStage : public IShaderStage { public: - GLuint id = -1; - - /** - * Constructs a new ShaderStage. - * - * @param type The type of shader this is. - * @param source The source code to compile. - */ - ShaderStage(const enum ShaderStageType type, const std::string source); - - /** - * Disposes of the shader stage. - */ + void init( + const SlangStage &stage, + const std::string &code + ) override; ~ShaderStage(); }; } \ No newline at end of file diff --git a/src/dawnrpg/CMakeLists.txt b/src/dawnrpg/CMakeLists.txt index 101f8dbe..16dac516 100644 --- a/src/dawnrpg/CMakeLists.txt +++ b/src/dawnrpg/CMakeLists.txt @@ -11,7 +11,6 @@ target_include_directories(${DAWN_TARGET_NAME} # Subdirs add_subdirectory(component) -add_subdirectory(display) add_subdirectory(game) add_subdirectory(rpg) diff --git a/src/dawnrpg/component/CMakeLists.txt b/src/dawnrpg/component/CMakeLists.txt index 07573d64..40e5312e 100644 --- a/src/dawnrpg/component/CMakeLists.txt +++ b/src/dawnrpg/component/CMakeLists.txt @@ -10,5 +10,4 @@ target_sources(${DAWN_TARGET_NAME} RPGMap.cpp ) -# Subdirs -add_subdirectory(display) \ No newline at end of file +# Subdirs \ No newline at end of file diff --git a/src/dawnrpg/component/display/CMakeLists.txt b/src/dawnrpg/component/display/CMakeLists.txt deleted file mode 100644 index 9afda52f..00000000 --- a/src/dawnrpg/component/display/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2024 Dominic Masters -# -# This software is released under the MIT License. -# https://opensource.org/licenses/MIT - -# Subdirs -add_subdirectory(material) \ No newline at end of file diff --git a/src/dawnrpg/component/display/material/CMakeLists.txt b/src/dawnrpg/component/display/material/CMakeLists.txt deleted file mode 100644 index f4065c92..00000000 --- a/src/dawnrpg/component/display/material/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2024 Dominic Masters -# -# This software is released under the MIT License. -# https://opensource.org/licenses/MIT - -target_sources(${DAWN_TARGET_NAME} - PRIVATE - MapMaterial.cpp -) \ No newline at end of file diff --git a/src/dawnrpg/component/display/material/MapMaterial.cpp b/src/dawnrpg/component/display/material/MapMaterial.cpp deleted file mode 100644 index b05b26a9..00000000 --- a/src/dawnrpg/component/display/material/MapMaterial.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "MapMaterial.hpp" -#include "util/JSON.hpp" -#include "asset/loader/TextureLoader.hpp" - -using namespace Dawn; - -std::vector< - std::shared_ptr -> MapMaterial::getLockedShaders(ShaderManager &shaderManager) { - return { - shaderManager.getShader() - }; -} - -void MapMaterial::load(std::shared_ptr ctx) { - if(ctx->data.contains("color")) { - this->setColor(JSON::color(ctx->data["color"])); - } - - if(ctx->data.contains("texture")) { - auto asset = ctx->getAsset( - ctx->data["texture"].get() - ); - this->setTexture(asset->getTexture()); - } -} - -struct Color MapMaterial::getColor() { - return this->data.color; -} - -std::shared_ptr MapMaterial::getTexture() { - return this->texture; -} - -void MapMaterial::setTexture( - const std::shared_ptr texture -) { - this->texture = texture; -} - -void MapMaterial::setColor(const struct Color color) { - this->data.color = color; -} - -std::vector> MapMaterial::getPasses( - struct RenderPassContext &ctx -) { - this->data.model = this->getItem()->getWorldTransform(); - this->data.projection = ctx.camera->getProjection(); - this->data.view = ctx.camera->getItem()->getWorldTransform(); - auto textures = std::unordered_map< - shadertexturebinding_t, std::shared_ptr - >(); - - if(this->texture) { - this->data.hasTexture = true; - this->data.texture = 0; - textures[this->data.texture] = this->texture; - } else { - this->data.hasTexture = false; - } - - return { - createRenderPass( - *this, - data, - textures - ) - }; -} diff --git a/src/dawnrpg/component/display/material/MapMaterial.hpp b/src/dawnrpg/component/display/material/MapMaterial.hpp deleted file mode 100644 index d1b8e935..00000000 --- a/src/dawnrpg/component/display/material/MapMaterial.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2024 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "component/display/material/Material.hpp" -#include "display/shader/MapShader.hpp" -#include "display/Texture.hpp" - -namespace Dawn { - class MapMaterial : public Material { - protected: - std::vector> getLockedShaders( - ShaderManager &shaderManager - ) override; - - private: - struct MapShaderData data; - std::shared_ptr texture; - - public: - void load(std::shared_ptr ctx) override; - - /** - * Returns the color of this material. - */ - struct Color getColor(); - - /** - * Returns the texture of this material. - * - * @return The texture of this material. - */ - std::shared_ptr getTexture(); - - /** - * Sets the texture of this material. - * - * @param texture The texture to set. - */ - void setTexture(const std::shared_ptr texture); - - /** - * Sets the color of this material. - * - * @param color The color to set. - */ - void setColor(const struct Color color); - - std::vector> getPasses( - struct RenderPassContext &ctx - ) override; - }; -} \ No newline at end of file diff --git a/src/dawnrpg/display/CMakeLists.txt b/src/dawnrpg/display/CMakeLists.txt deleted file mode 100644 index 9c3f0ad1..00000000 --- a/src/dawnrpg/display/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2024 Dominic Masters -# -# This software is released under the MIT License. -# https://opensource.org/licenses/MIT - -# Subdirs -add_subdirectory(shader) \ No newline at end of file diff --git a/src/dawnrpg/display/shader/MapShader.cpp b/src/dawnrpg/display/shader/MapShader.cpp deleted file mode 100644 index b5cc37e6..00000000 --- a/src/dawnrpg/display/shader/MapShader.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "display/shader/MapShader.hpp" - -using namespace Dawn; - -void MapShader::getStages( - const enum ShaderOpenGLVariant variant, - const struct MapShaderData *rel, - std::vector> &stages, - std::vector ¶meters, - std::vector &structures -) { - // Stages - std::shared_ptr vertex; - std::shared_ptr fragment; - - std::cout << "MapShader::getStages" << std::endl; - - switch(variant) { - case ShaderOpenGLVariant::GLSL_330_CORE: - vertex = std::make_shared( - ShaderStageType::VERTEX,R"( - #version 330 core - layout (location = 0) in vec3 aPos; - layout (location = 1) in vec2 aTexCoord; - uniform mat4 u_Projection; - uniform mat4 u_View; - uniform mat4 u_Model; - out vec2 o_TextCoord; - void main() { - gl_Position = u_Projection * u_View * u_Model * vec4(aPos, 1.0); - o_TextCoord = vec2(aTexCoord.x, aTexCoord.y); - } - )" - ); - - fragment = std::make_shared( - ShaderStageType::FRAGMENT,R"( - #version 330 core - in vec2 o_TextCoord; - out vec4 o_Color; - uniform vec4 u_Color; - uniform bool u_HasTexture; - uniform sampler2D u_Texture; - void main() { - if(u_HasTexture) { - o_Color = texture(u_Texture, o_TextCoord); - } else { - o_Color = u_Color; - } - - if(o_Color.a == 0) discard; - } - )" - ); - break; - - default: - assertUnreachable("Unsupported ShaderOpenGLVariant"); - } - - // Add stages - stages.push_back(vertex); - stages.push_back(fragment); - - // Parameters - parameters.push_back(ShaderParameter( - "u_Projection", - &rel->projection, - ShaderParameterType::MAT4 - )); - - parameters.push_back(ShaderParameter( - "u_View", - &rel->view, - ShaderParameterType::MAT4 - )); - - parameters.push_back(ShaderParameter( - "u_Model", - &rel->model, - ShaderParameterType::MAT4 - )); - - parameters.push_back(ShaderParameter( - "u_Color", - &rel->color, - ShaderParameterType::COLOR - )); - - parameters.push_back(ShaderParameter( - "u_HasTexture", - &rel->hasTexture, - ShaderParameterType::BOOLEAN - )); - - parameters.push_back(ShaderParameter( - "u_Texture", - &rel->texture, - ShaderParameterType::TEXTURE - )); -} \ No newline at end of file diff --git a/src/dawnrpg/display/shader/MapShader.hpp b/src/dawnrpg/display/shader/MapShader.hpp deleted file mode 100644 index 6675afb4..00000000 --- a/src/dawnrpg/display/shader/MapShader.hpp +++ /dev/null @@ -1,29 +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" - -namespace Dawn { - struct MapShaderData { - glm::mat4 projection; - glm::mat4 view; - glm::mat4 model; - struct Color color = COLOR_WHITE; - bool hasTexture = false; - shadertexturebinding_t texture = 0; - }; - - class MapShader : public Shader { - protected: - void getStages( - const enum ShaderOpenGLVariant variant, - const struct MapShaderData *rel, - std::vector> &stages, - std::vector ¶meters, - std::vector &structures - ) override; - }; -} \ No newline at end of file diff --git a/src/dawnrpg/game/Game.cpp b/src/dawnrpg/game/Game.cpp index 220c89a6..fb4ebdd0 100644 --- a/src/dawnrpg/game/Game.cpp +++ b/src/dawnrpg/game/Game.cpp @@ -6,13 +6,10 @@ #include "Game.hpp" #include "component/SceneComponentRegistry.hpp" -#include "component/display/material/MapMaterial.hpp" #include "component/RPGEntity.hpp" #include "component/RPGPlayer.hpp" #include "component/RPGMap.hpp" - #include "asset/loader/ShaderLoader.hpp" -#include using namespace Dawn; @@ -20,7 +17,6 @@ Game::Game() : IGame() { SceneComponentRegistry::reg("RPGEntity"); SceneComponentRegistry::reg("RPGPlayer"); SceneComponentRegistry::reg("RPGMap"); - SceneComponentRegistry::reg("MapMaterial"); } std::string Game::getInitialScene() { @@ -33,16 +29,6 @@ void Game::initManagers() { auto sl = assetManager->get("shaders/hello-world.slang"); sl->loadImmediately(); - - // auto code1 = sl->getEntryPointCode("vertexMain"); - // std::fstream file("vertexMain.glsl", std::ios::out); - // file << code1; - // file.close(); - - // auto code2 = sl->getEntryPointCode("fragmentMain"); - // std::fstream file2("fragmentMain.glsl", std::ios::out); - // file2 << code2; - // file2.close(); } Game::~Game() {