From e88ca80265067ec2eb377d84c6bf319fd6d26311 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 1 Nov 2023 23:08:20 -0500 Subject: [PATCH] Bit of cleanup. --- src/dawn/asset/AssetManager.cpp | 20 ++++- src/dawn/asset/AssetManager.hpp | 5 +- src/dawn/asset/IAssetLoader.cpp | 10 ++- src/dawn/asset/assets/TextureAsset.cpp | 1 + src/dawn/asset/assets/TrueTypeAsset.cpp | 22 ++--- src/dawn/asset/assets/TrueTypeAsset.hpp | 4 +- ...{_RenderManager.hpp => IRenderManager.hpp} | 0 .../display/{_Texture.hpp => ITexture.hpp} | 0 src/dawn/display/RenderPipeline.hpp | 2 +- .../font/truetype/TrueTypeFaceTexture.cpp | 1 + .../shader/{_Shader.hpp => IShader.hpp} | 3 +- ...rBuffer.hpp => IShaderParameterBuffer.hpp} | 0 src/dawn/save/SaveManager.cpp | 1 + .../scene/components/display/Material.cpp | 4 + .../scene/components/display/Material.hpp | 6 ++ .../physics/2d/TriggerController2D.cpp | 1 + src/dawnglfw/debug/debug.hpp | 14 ---- src/dawnliminal/scenes/LoadingScene.hpp | 2 +- src/dawnlinux64/host/DawnHostTux32.cpp | 1 + src/dawnopengl/display/RenderManager.cpp | 37 +++++---- src/dawnopengl/display/Texture.cpp | 80 +++++++++---------- src/dawnopengl/display/Texture.hpp | 4 +- .../display/TextureRenderTarget.cpp | 1 + src/dawnopengl/display/mesh/Mesh.cpp | 28 +++---- src/dawnopengl/display/shader/Shader.cpp | 30 +++---- src/dawnopengl/display/shader/Shader.hpp | 14 ++-- .../display/shader/ShaderParameterBuffer.hpp | 19 +++-- .../shader/shaders/SimpleTexturedShader.cpp | 8 +- .../material/SimpleBillboardedMaterial.cpp | 22 ++--- .../material/SimpleBillboardedMaterial.hpp | 4 +- .../material/SimpleTexturedMaterial.cpp | 26 +++--- .../material/SimpleTexturedMaterial.hpp | 4 +- 32 files changed, 212 insertions(+), 162 deletions(-) rename src/dawn/display/{_RenderManager.hpp => IRenderManager.hpp} (100%) rename src/dawn/display/{_Texture.hpp => ITexture.hpp} (100%) rename src/dawn/display/shader/{_Shader.hpp => IShader.hpp} (98%) rename src/dawn/display/shader/{_ShaderParameterBuffer.hpp => IShaderParameterBuffer.hpp} (100%) delete mode 100644 src/dawnglfw/debug/debug.hpp diff --git a/src/dawn/asset/AssetManager.cpp b/src/dawn/asset/AssetManager.cpp index 8fc7f750..1e3200f6 100644 --- a/src/dawn/asset/AssetManager.cpp +++ b/src/dawn/asset/AssetManager.cpp @@ -16,7 +16,11 @@ void AssetManager::update() { } void AssetManager::queueLoad(std::vector assets) { - vectorAppend(&this->assetsToLoad, &assets); + std::merge( + this->assetsToLoad.begin(), this->assetsToLoad.end(), + assets.begin(), assets.end(), + this->assetsToLoad.begin() + ); } void AssetManager::queueLoad(Asset *asset) { @@ -24,12 +28,20 @@ void AssetManager::queueLoad(Asset *asset) { } void AssetManager::queueUnload(std::vector assets) { - std::cout << "Asset list was queued to unload, but is not yet implemented" << std::endl; - vectorAppend(&this->assetsToUnload, &assets); + std::cout << + "Asset list was queued to unload, but is not yet implemented" << + std::endl; + std::merge( + this->assetsToUnload.begin(), this->assetsToUnload.end(), + assets.begin(), assets.end(), + this->assetsToUnload.begin() + ); } void AssetManager::queueUnload(Asset *asset) { - std::cout << "Asset was queued to unload, but is not yet implemented" << std::endl; + std::cout << + "Asset was queued to unload, but is not yet implemented" << + std::endl; this->assetsToUnload.push_back(asset); } diff --git a/src/dawn/asset/AssetManager.hpp b/src/dawn/asset/AssetManager.hpp index 57421df5..351c0858 100644 --- a/src/dawn/asset/AssetManager.hpp +++ b/src/dawn/asset/AssetManager.hpp @@ -5,7 +5,6 @@ #pragma once #include "Asset.hpp" -#include "util/array.hpp" namespace Dawn { class AssetManager { @@ -73,7 +72,9 @@ namespace Dawn { */ template T * get(std::string name) { - assertTrue(name.size() > 0, "AssetManager::get: name must be greater than 0"); + assertTrue( + name.size() > 0, "AssetManager::get: name must be greater than 0" + ); auto existing = this->assets.find(name); if(existing != this->assets.end()) { diff --git a/src/dawn/asset/IAssetLoader.cpp b/src/dawn/asset/IAssetLoader.cpp index dad04ae4..91140c49 100644 --- a/src/dawn/asset/IAssetLoader.cpp +++ b/src/dawn/asset/IAssetLoader.cpp @@ -8,12 +8,18 @@ using namespace Dawn; IAssetLoader::IAssetLoader(std::string fileName) { - assertTrue(fileName.size() > 0, "IAssetLoader::IAssetLoader: fileName must be greater than 0"); + assertTrue( + fileName.size() > 0, + "IAssetLoader::IAssetLoader: fileName must be greater than 0" + ); this->fileName = fileName; } size_t IAssetLoader::setPosition(size_t position) { - assertTrue(position >= 0, "IAssetLoader::setPosition: position must be greater than or equal to 0"); + assertTrue( + position >= 0, + "IAssetLoader::setPosition: position must be greater than or equal to 0" + ); this->rewind(); return this->skip(position); } diff --git a/src/dawn/asset/assets/TextureAsset.cpp b/src/dawn/asset/assets/TextureAsset.cpp index 480a19c4..b7a612e2 100644 --- a/src/dawn/asset/assets/TextureAsset.cpp +++ b/src/dawn/asset/assets/TextureAsset.cpp @@ -4,6 +4,7 @@ // https://opensource.org/licenses/MIT #include "TextureAsset.hpp" +#include "util/memory.hpp" using namespace Dawn; diff --git a/src/dawn/asset/assets/TrueTypeAsset.cpp b/src/dawn/asset/assets/TrueTypeAsset.cpp index 30515b0f..757b23df 100644 --- a/src/dawn/asset/assets/TrueTypeAsset.cpp +++ b/src/dawn/asset/assets/TrueTypeAsset.cpp @@ -24,24 +24,24 @@ TrueTypeAsset::TrueTypeAsset(AssetManager *assMan, std::string name) : lbt.erase(it0); auto it1 = this->textureByLock.find(id); - assertTrue(it1 != this->textureByLock.end(), "Could not remove textureByLock"); + assertTrue( + it1 != this->textureByLock.end(), "Could not remove textureByLock" + ); this->textureByLock.erase(it1); if(lbt.empty()) { auto it2 = locksByTexture.find(texture); - assertTrue(it2 != locksByTexture.end(), "Could not remove locksByTexture"); + assertTrue( + it2 != locksByTexture.end(), "Could not remove locksByTexture" + ); locksByTexture.erase(it2); - - auto it3 = textureByStyle.begin(); - while(it3 != textureByStyle.end()) { - if(it3->second == texture) it3 = textureByStyle.erase(it3); - ++it3; - } - auto it4 = std::find(textures.begin(), textures.end(), texture); - assertTrue(it4 != textures.end(), "Could not remove textureByStyle"); - textures.erase(it4); + std::erase_if(textureByStyle, [&](const auto &item){ + auto const& [key, value] = item; + return value == texture; + }); + std::erase(textures, texture); delete texture; } }; diff --git a/src/dawn/asset/assets/TrueTypeAsset.hpp b/src/dawn/asset/assets/TrueTypeAsset.hpp index b70d2b75..75f4fc50 100644 --- a/src/dawn/asset/assets/TrueTypeAsset.hpp +++ b/src/dawn/asset/assets/TrueTypeAsset.hpp @@ -38,7 +38,9 @@ namespace Dawn { std::vector assetStyles; std::vector textures; std::map textureByLock; - std::map textureByStyle; + std::map + textureByStyle + ; std::map> locksByTexture; public: diff --git a/src/dawn/display/_RenderManager.hpp b/src/dawn/display/IRenderManager.hpp similarity index 100% rename from src/dawn/display/_RenderManager.hpp rename to src/dawn/display/IRenderManager.hpp diff --git a/src/dawn/display/_Texture.hpp b/src/dawn/display/ITexture.hpp similarity index 100% rename from src/dawn/display/_Texture.hpp rename to src/dawn/display/ITexture.hpp diff --git a/src/dawn/display/RenderPipeline.hpp b/src/dawn/display/RenderPipeline.hpp index aa8ec107..df9f0e25 100644 --- a/src/dawn/display/RenderPipeline.hpp +++ b/src/dawn/display/RenderPipeline.hpp @@ -4,7 +4,7 @@ // https://opensource.org/licenses/MIT #pragma once -#include "display/_RenderManager.hpp" +#include "display/IRenderManager.hpp" #include "display/shader/ShaderPass.hpp" #include "scene/components/display/IRenderable.hpp" #include "display/shader/buffers/RenderPipelineShaderBuffer.hpp" diff --git a/src/dawn/display/font/truetype/TrueTypeFaceTexture.cpp b/src/dawn/display/font/truetype/TrueTypeFaceTexture.cpp index 1c68a90d..5a2ab494 100644 --- a/src/dawn/display/font/truetype/TrueTypeFaceTexture.cpp +++ b/src/dawn/display/font/truetype/TrueTypeFaceTexture.cpp @@ -4,6 +4,7 @@ // https://opensource.org/licenses/MIT #include "TrueTypeFaceTexture.hpp" +#include "util/memory.hpp" using namespace Dawn; diff --git a/src/dawn/display/shader/_Shader.hpp b/src/dawn/display/shader/IShader.hpp similarity index 98% rename from src/dawn/display/shader/_Shader.hpp rename to src/dawn/display/shader/IShader.hpp index 736f1397..b13aa34e 100644 --- a/src/dawn/display/shader/_Shader.hpp +++ b/src/dawn/display/shader/IShader.hpp @@ -5,7 +5,7 @@ #pragma once #include "display/mesh/Mesh.hpp" -#include "display/_RenderManager.hpp" +#include "display/IRenderManager.hpp" #include "display/Texture.hpp" #include "display/shader/ShaderParameterBuffer.hpp" @@ -82,6 +82,5 @@ namespace Dawn { * @param Float to bind. */ virtual void setFloat(T parameter, float_t value) = 0; - }; } \ No newline at end of file diff --git a/src/dawn/display/shader/_ShaderParameterBuffer.hpp b/src/dawn/display/shader/IShaderParameterBuffer.hpp similarity index 100% rename from src/dawn/display/shader/_ShaderParameterBuffer.hpp rename to src/dawn/display/shader/IShaderParameterBuffer.hpp diff --git a/src/dawn/save/SaveManager.cpp b/src/dawn/save/SaveManager.cpp index 42bbf576..2f5194ca 100644 --- a/src/dawn/save/SaveManager.cpp +++ b/src/dawn/save/SaveManager.cpp @@ -5,6 +5,7 @@ #include "SaveManager.hpp" #include "game/DawnGame.hpp" +#include "util/memory.hpp" using namespace Dawn; diff --git a/src/dawn/scene/components/display/Material.cpp b/src/dawn/scene/components/display/Material.cpp index 1c364aa8..78389b43 100644 --- a/src/dawn/scene/components/display/Material.cpp +++ b/src/dawn/scene/components/display/Material.cpp @@ -9,4 +9,8 @@ using namespace Dawn; Material::Material(SceneItem *item) : SceneItemComponent(item) { +} + +ShaderManager & Material::getShaderManager() { + return *this->getGame()->renderManager.getShaderManager(); } \ No newline at end of file diff --git a/src/dawn/scene/components/display/Material.hpp b/src/dawn/scene/components/display/Material.hpp index fe010725..8fdaf8fa 100644 --- a/src/dawn/scene/components/display/Material.hpp +++ b/src/dawn/scene/components/display/Material.hpp @@ -17,5 +17,11 @@ namespace Dawn { * @param item Scene Item this component belongs to. */ Material(SceneItem *item); + + /** + * Returns the shader manager for the game. + * @return The shader manager for the game. + */ + ShaderManager & getShaderManager(); }; } \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/TriggerController2D.cpp b/src/dawn/scene/components/physics/2d/TriggerController2D.cpp index 46da426e..cb8237c3 100644 --- a/src/dawn/scene/components/physics/2d/TriggerController2D.cpp +++ b/src/dawn/scene/components/physics/2d/TriggerController2D.cpp @@ -45,6 +45,7 @@ bool_t TriggerController2D::getCollidingResult(Collider2D* movingObject) { default: { assertUnreachable("TriggerController2D::getCollidingResult: Moving object type not implemented"); + return false; } } } \ No newline at end of file diff --git a/src/dawnglfw/debug/debug.hpp b/src/dawnglfw/debug/debug.hpp deleted file mode 100644 index 319c90be..00000000 --- a/src/dawnglfw/debug/debug.hpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "dawnlibs.hpp" - -// Draws an error message on screen and force closes the app after user input -template -void debugMessage(const char *fmt, A... args) { - printf(fmt, args...); - printf("\n"); -} \ No newline at end of file diff --git a/src/dawnliminal/scenes/LoadingScene.hpp b/src/dawnliminal/scenes/LoadingScene.hpp index 61746f8c..b6e1557f 100644 --- a/src/dawnliminal/scenes/LoadingScene.hpp +++ b/src/dawnliminal/scenes/LoadingScene.hpp @@ -19,7 +19,7 @@ namespace Dawn { void stage() override { useEvent([&](float_t delta) { - assertNull(this->instanceOfT, "LoadingScene::stage: Scene already loaded!"); + assertNull(this->instanceOfT, "Scene already loaded!"); this->instanceOfT = new T(this->game); auto assets = this->instanceOfT->getRequiredAssets(); this->game->assetManager.queueLoad(assets); diff --git a/src/dawnlinux64/host/DawnHostTux32.cpp b/src/dawnlinux64/host/DawnHostTux32.cpp index 1b70ccb7..5f508bbe 100644 --- a/src/dawnlinux64/host/DawnHostTux32.cpp +++ b/src/dawnlinux64/host/DawnHostTux32.cpp @@ -4,6 +4,7 @@ // https://opensource.org/licenses/MIT #include "DawnHostTux32.hpp" +#include "util/memory.hpp" using namespace Dawn; diff --git a/src/dawnopengl/display/RenderManager.cpp b/src/dawnopengl/display/RenderManager.cpp index ef01f7b1..bce3fa68 100644 --- a/src/dawnopengl/display/RenderManager.cpp +++ b/src/dawnopengl/display/RenderManager.cpp @@ -18,21 +18,28 @@ RenderManager::RenderManager(DawnGame *game) : void RenderManager::init() { // Lock the common shaders - this->lockSimpleTextured = this->shaderManager.lockShader(); - this->simpleTexturedShader = this->shaderManager.getShader(this->lockSimpleTextured); + lockSimpleTextured = shaderManager.lockShader(); + simpleTexturedShader = shaderManager.getShader( + lockSimpleTextured + ); - this->lockUIShaderProgram = this->shaderManager.lockShader(); - this->uiShader = this->shaderManager.getShader(this->lockUIShaderProgram); + lockUIShaderProgram = shaderManager.lockShader(); + uiShader = shaderManager.getShader(lockUIShaderProgram); - this->lockFontShader = this->shaderManager.lockShader(); - this->fontShader = this->shaderManager.getShader(this->lockFontShader); - this->renderPipeline.init(); + lockFontShader = shaderManager.lockShader(); + fontShader = shaderManager.getShader(lockFontShader); + renderPipeline.init(); assertNoGLError(); // Prepare the initial values glPixelStorei(GL_UNPACK_ALIGNMENT, 1); assertNoGLError(); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + glBlendFuncSeparate( + GL_SRC_ALPHA, + GL_ONE_MINUS_SRC_ALPHA, + GL_ONE, + GL_ONE_MINUS_SRC_ALPHA + ); assertNoGLError(); glDepthMask(GL_TRUE); assertNoGLError(); @@ -41,19 +48,19 @@ void RenderManager::init() { } RenderTarget * RenderManager::getBackBuffer() { - return &this->backBuffer; + return &backBuffer; } RenderPipeline * RenderManager::getRenderPipeline() { - return &this->renderPipeline; + return &renderPipeline; } ShaderManager * RenderManager::getShaderManager() { - return &this->shaderManager; + return &shaderManager; } void RenderManager::setRenderFlags(renderflag_t flags) { - this->renderFlags = flags; + renderFlags = flags; if((flags & RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST) == 0) { glDisable(GL_DEPTH_TEST); @@ -75,7 +82,7 @@ void RenderManager::update() { } RenderManager::~RenderManager() { - this->shaderManager.releaseShader(this->lockSimpleTextured); - this->shaderManager.releaseShader(this->lockUIShaderProgram); - this->shaderManager.releaseShader(this->lockFontShader); + shaderManager.releaseShader(lockSimpleTextured); + shaderManager.releaseShader(lockUIShaderProgram); + shaderManager.releaseShader(lockFontShader); } \ No newline at end of file diff --git a/src/dawnopengl/display/Texture.cpp b/src/dawnopengl/display/Texture.cpp index 6349bb72..708b9ac4 100644 --- a/src/dawnopengl/display/Texture.cpp +++ b/src/dawnopengl/display/Texture.cpp @@ -4,6 +4,8 @@ // https://opensource.org/licenses/MIT #include "Texture.hpp" +#include "assert/assertgl.hpp" +#include "util/memory.hpp" using namespace Dawn; @@ -18,7 +20,7 @@ Texture::Texture() : ITexture() { } void Texture::bind(textureslot_t slot) { - assertTrue(this->id != -1, "Texture::bind: Texture is not ready!"); + assertTrue(this->id != -1, "Texture is not ready!"); glActiveTexture(GL_TEXTURE0 + slot); assertNoGLError(); glBindTexture(GL_TEXTURE_2D, this->id); @@ -50,12 +52,10 @@ void Texture::setSize( this->id = -1; } - #if DAWN_DEBUG_BUILD - int32_t maxSize; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize); - assertTrue(width > 0 && width <= maxSize, "Texture::setSize: Width is out of bounds!"); - assertTrue(height > 0 && height <= maxSize, "Texture::setSize: Height is out of bounds!"); - #endif + int32_t maxSize; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize); + assertTrue(width > 0 && width <= maxSize, "Width is out of bounds!"); + assertTrue(height > 0 && height <= maxSize, "Height is out of bounds!"); this->width = width; this->height = height; @@ -64,8 +64,8 @@ void Texture::setSize( glGenTextures(1, &this->id); assertNoGLError(); - if(this->id <= 0) throw "Texture generation failed!"; - + if(this->id <= 0) assertUnreachable("Texture generation failed!"); + // Initialize the texture to blank glActiveTexture(GL_TEXTURE0); assertNoGLError(); @@ -112,7 +112,7 @@ void Texture::updateTextureProperties() { break; default: - assertUnreachable("Texture::updateTextureProperties: Unknown wrap mode!"); + assertUnreachable("Unknown wrap mode!"); } assertNoGLError(); }; @@ -128,51 +128,31 @@ void Texture::updateTextureProperties() { switch(filter) { case TEXTURE_FILTER_MODE_NEAREST: { glTexParameteri(GL_TEXTURE_2D, minMag, GL_NEAREST); - // switch(mapFilterMode) { - // case TEXTURE_FILTER_MODE_NEAREST: - // glTexParameteri(GL_TEXTURE_2D, minMag, GL_NEAREST_MIPMAP_NEAREST); - // break; - - // case TEXTURE_FILTER_MODE_LINEAR: - // glTexParameteri(GL_TEXTURE_2D, minMag, GL_LINEAR_MIPMAP_NEAREST); - // break; - - // default: - // assertUnreachable(); - // } break; } case TEXTURE_FILTER_MODE_LINEAR: { glTexParameteri(GL_TEXTURE_2D, minMag, GL_LINEAR); - // switch(mapFilterMode) { - // case TEXTURE_FILTER_MODE_NEAREST: - // glTexParameteri(GL_TEXTURE_2D, minMag, GL_NEAREST_MIPMAP_LINEAR); - // break; - - // case TEXTURE_FILTER_MODE_LINEAR: - // glTexParameteri(GL_TEXTURE_2D, minMag, GL_LINEAR_MIPMAP_LINEAR); - // break; - - // default: - // assertUnreachable(); - // } break; } default: { - assertUnreachable("Texture::updateTextureProperties: Unknown filter mode!"); + assertUnreachable("Unknown filter mode!"); } } assertNoGLError(); }; - setFilterMode(GL_TEXTURE_MIN_FILTER, this->filterModeMin, this->mipmapFilterModeMin); - setFilterMode(GL_TEXTURE_MAG_FILTER, this->filterModeMag, this->mipmapFilterModeMag); + setFilterMode( + GL_TEXTURE_MIN_FILTER, this->filterModeMin, this->mipmapFilterModeMin + ); + setFilterMode( + GL_TEXTURE_MAG_FILTER, this->filterModeMag, this->mipmapFilterModeMag + ); } void Texture::bufferRaw(void *data) { - assertTrue(this->isReady(), "Texture::bufferRaw: Texture is not ready!"); + assertTrue(this->isReady(), "Texture is not ready!"); GLenum format; switch(this->format) { @@ -193,7 +173,7 @@ void Texture::bufferRaw(void *data) { break; default: - assertUnreachable("Texture::bufferRaw: Unknown texture format!"); + assertUnreachable("Unknown texture format!"); } GLenum dataFormat; @@ -207,7 +187,7 @@ void Texture::bufferRaw(void *data) { break; default: - assertUnreachable("Texture::bufferRaw: Unknown texture data format!"); + assertUnreachable("Unknown texture data format!"); } glBindTexture(GL_TEXTURE_2D, this->id); @@ -224,18 +204,30 @@ void Texture::bufferRaw(void *data) { } void Texture::buffer(struct ColorU8 pixels[]) { - assertTrue(this->dataFormat == TEXTURE_DATA_FORMAT_UNSIGNED_BYTE, "Texture::buffer: Texture data format must be unsigned byte!"); + assertTrue( + this->dataFormat == TEXTURE_DATA_FORMAT_UNSIGNED_BYTE, + "Texture data format must be unsigned byte!" + ); this->bufferRaw((void*)pixels); } void Texture::buffer(struct Color pixels[]) { - assertTrue(this->dataFormat == TEXTURE_DATA_FORMAT_FLOAT, "Texture::buffer: Texture data format must be float!"); - assertTrue(this->format == TEXTURE_FORMAT_RGBA, "Texture::buffer: Texture format must be RGBA!"); + assertTrue( + this->dataFormat == TEXTURE_DATA_FORMAT_FLOAT, + "Texture data format must be float!" + ); + assertTrue( + this->format == TEXTURE_FORMAT_RGBA, + "Texture format must be RGBA!" + ); this->bufferRaw((void*)pixels); } void Texture::buffer(uint8_t pixels[]) { - assertTrue(this->dataFormat == TEXTURE_DATA_FORMAT_UNSIGNED_BYTE, "Texture::buffer: Texture data format must be unsigned byte!"); + assertTrue( + this->dataFormat == TEXTURE_DATA_FORMAT_UNSIGNED_BYTE, + "Texture data format must be unsigned byte!" + ); this->bufferRaw((void*)pixels); } diff --git a/src/dawnopengl/display/Texture.hpp b/src/dawnopengl/display/Texture.hpp index a19628f3..f936155f 100644 --- a/src/dawnopengl/display/Texture.hpp +++ b/src/dawnopengl/display/Texture.hpp @@ -5,9 +5,7 @@ #pragma once #include "dawnopengl.hpp" -#include "assert/assertgl.hpp" -#include "display/_Texture.hpp" -#include "util/memory.hpp" +#include "display/ITexture.hpp" namespace Dawn { class TextureRenderTarget; diff --git a/src/dawnopengl/display/TextureRenderTarget.cpp b/src/dawnopengl/display/TextureRenderTarget.cpp index 623cb827..9d33a37b 100644 --- a/src/dawnopengl/display/TextureRenderTarget.cpp +++ b/src/dawnopengl/display/TextureRenderTarget.cpp @@ -4,6 +4,7 @@ // https://opensource.org/licenses/MIT #include "TextureRenderTarget.hpp" +#include "assert/assertgl.hpp" using namespace Dawn; diff --git a/src/dawnopengl/display/mesh/Mesh.cpp b/src/dawnopengl/display/mesh/Mesh.cpp index 4c6e1b8a..00d7e0b2 100644 --- a/src/dawnopengl/display/mesh/Mesh.cpp +++ b/src/dawnopengl/display/mesh/Mesh.cpp @@ -98,12 +98,12 @@ void Mesh::disposeBuffers() { } void Mesh::bufferPositions(int32_t pos, glm::vec3 *positions, int32_t len) { - assertNotNull(positions, "Mesh::bufferPositions: Positions cannot be null"); - assertTrue(pos >= 0 && pos < this->verticeCount, "Mesh::bufferPositions: Position must be within range"); - assertTrue(pos+len <= this->verticeCount, "Mesh::bufferPositions: Position + Length must be within range"); - assertTrue(len > 0, "Mesh::bufferPositions: Length must be greater than zero"); + assertNotNull(positions, "Positions cannot be null"); + assertTrue(pos >= 0 && pos < verticeCount, "Position must be within range"); + assertTrue(pos+len <= verticeCount, "Position + Length must be within range"); + assertTrue(len > 0, "Length must be greater than zero"); - glBindBuffer(GL_ARRAY_BUFFER, this->vertexBuffer); + glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); assertNoGLError(); glBufferSubData( GL_ARRAY_BUFFER, @@ -115,10 +115,10 @@ void Mesh::bufferPositions(int32_t pos, glm::vec3 *positions, int32_t len) { } void Mesh::bufferCoordinates(int32_t pos, glm::vec2 *coordinates, int32_t len) { - assertNotNull(coordinates, "Mesh::bufferCoordinates: Coordinates cannot be null"); - assertTrue(pos >= 0 && pos < this->verticeCount, "Mesh::bufferCoordinates: Position must be within range"); - assertTrue(pos+len <= this->verticeCount, "Mesh::bufferCoordinates: Position + Length must be within range"); - assertTrue(len > 0, "Mesh::bufferCoordinates: Length must be greater than zero"); + assertNotNull(coordinates, "Coordinates cannot be null"); + assertTrue(pos >= 0 && pos < verticeCount, "Position must be within range"); + assertTrue(pos+len <= verticeCount, "Position + Length must be within range"); + assertTrue(len > 0, "Length must be greater than zero"); auto offsetCoordinates = ( (sizeof(glm::vec3) * this->verticeCount) + @@ -137,12 +137,12 @@ void Mesh::bufferCoordinates(int32_t pos, glm::vec2 *coordinates, int32_t len) { } void Mesh::bufferIndices(int32_t pos, meshindice_t *indices, int32_t len) { - assertNotNull(indices, "Mesh::bufferIndices: Indices cannot be null"); - assertTrue(pos >= 0 && pos < this->indiceCount, "Mesh::bufferIndices: Position must be within range"); - assertTrue(pos+len <= this->indiceCount, "Mesh::bufferIndices: Position + Length must be within range"); - assertTrue(len > 0, "Mesh::bufferIndices: Length must be greater than zero"); + assertNotNull(indices, "Indices cannot be null"); + assertTrue(pos >= 0 && pos < indiceCount, "Position must be within range"); + assertTrue(pos+len <= indiceCount, "Position + Length must be within range"); + assertTrue(len > 0, "Length must be greater than zero"); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->indexBuffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); assertNoGLError(); glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, diff --git a/src/dawnopengl/display/shader/Shader.cpp b/src/dawnopengl/display/shader/Shader.cpp index b3eb3dff..5bcff878 100644 --- a/src/dawnopengl/display/shader/Shader.cpp +++ b/src/dawnopengl/display/shader/Shader.cpp @@ -30,8 +30,7 @@ void Shader::compileShader( if(!isSuccess) { glGetShaderiv(this->shaderVertex, GL_INFO_LOG_LENGTH, &maxLength); glGetShaderInfoLog(this->shaderVertex, maxLength, &maxLength, error); - debugMessage("Error compiling vert shader"); - debugMessage(error); + assertUnreachable("Error compiling vert shader %s", error); throw error; } assertNoGLError(); @@ -46,16 +45,15 @@ void Shader::compileShader( glGetShaderiv(this->shaderFrag, GL_INFO_LOG_LENGTH, &maxLength); glGetShaderInfoLog(this->shaderFrag, maxLength, &maxLength, error); glDeleteShader(this->shaderVertex); - debugMessage("Error compiling frag shader"); - debugMessage(error); + assertUnreachable("Error compiling frag shader %s", error); throw error; } assertNoGLError(); // Now create the shader program. - this->shaderProgram = glCreateProgram(); - glAttachShader(this->shaderProgram, this->shaderVertex); - glAttachShader(this->shaderProgram, this->shaderFrag); + shaderProgram = glCreateProgram(); + glAttachShader(shaderProgram, shaderVertex); + glAttachShader(shaderProgram, shaderFrag); assertNoGLError(); // Now parse out the variables. @@ -75,8 +73,7 @@ void Shader::compileShader( glGetProgramInfoLog(this->shaderProgram, maxLength, &maxLength, error); glDeleteShader(this->shaderVertex); glDeleteShader(this->shaderFrag); - debugMessage("Error compiling shader program"); - debugMessage(error); + assertUnreachable("Error compiling shader program %s", error); throw error; } assertNoGLError(); @@ -101,7 +98,10 @@ shaderbufferlocation_t Shader::getBufferLocationByName(std::string name) { return glGetUniformBlockIndex(this->shaderProgram, name.c_str()); } -void Shader::setParameterBuffer(shaderbufferlocation_t location, shaderbufferslot_t slot) { +void Shader::setParameterBuffer( + shaderbufferlocation_t location, + shaderbufferslot_t slot +) { glUniformBlockBinding(this->shaderProgram, location, slot); assertNoGLError(); } @@ -132,13 +132,13 @@ void Shader::setFloat(shaderparameter_t param, float_t value) { } void Shader::bind() { - assertTrue(this->shaderProgram != -1, "Shader::bind: Cannot bind a program that is not ready"); - glUseProgram(this->shaderProgram); + assertTrue(shaderProgram != -1, "Cannot bind a program that is not ready"); + glUseProgram(shaderProgram); assertNoGLError(); } Shader::~Shader() { - if(this->shaderProgram != -1) glDeleteProgram(this->shaderProgram); - if(this->shaderVertex != -1) glDeleteShader(this->shaderVertex); - if(this->shaderFrag != -1) glDeleteShader(this->shaderFrag); + if(shaderProgram != -1) glDeleteProgram(shaderProgram); + if(shaderVertex != -1) glDeleteShader(shaderVertex); + if(shaderFrag != -1) glDeleteShader(shaderFrag); } \ No newline at end of file diff --git a/src/dawnopengl/display/shader/Shader.hpp b/src/dawnopengl/display/shader/Shader.hpp index 480249d0..a1d34170 100644 --- a/src/dawnopengl/display/shader/Shader.hpp +++ b/src/dawnopengl/display/shader/Shader.hpp @@ -4,10 +4,8 @@ // https://opensource.org/licenses/MIT #pragma once -#include "display/shader/_Shader.hpp" +#include "display/shader/IShader.hpp" #include "dawnopengl.hpp" -#include "display/Color.hpp" -#include "debug/debug.hpp" typedef GLuint shaderparameter_t; @@ -66,12 +64,18 @@ namespace Dawn { virtual void compile() override = 0; void bind() override; - void setParameterBuffer(shaderbufferlocation_t location, shaderbufferslot_t slot); + void setParameterBuffer( + shaderbufferlocation_t location, + shaderbufferslot_t slot + ); void setMatrix(shaderparameter_t parameter, glm::mat4 matrix) override; void setBoolean(shaderparameter_t parameter, bool_t value) override; void setColor(shaderparameter_t parameter, struct Color color) override; void setVector3(shaderparameter_t parameter, glm::vec3 vector) override; - void setTexture(shaderparameter_t parameter, textureslot_t texture) override; + void setTexture( + shaderparameter_t parameter, + textureslot_t texture + ) override; void setFloat(shaderparameter_t parameter, float_t value) override; /** diff --git a/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp b/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp index f4672ca3..8b530d2f 100644 --- a/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp +++ b/src/dawnopengl/display/shader/ShaderParameterBuffer.hpp @@ -5,7 +5,7 @@ #pragma once #include "dawnopengl.hpp" -#include "display/shader/_ShaderParameterBuffer.hpp" +#include "display/shader/IShaderParameterBuffer.hpp" #include "ShaderParameterBufferTypes.hpp" namespace Dawn { @@ -13,14 +13,19 @@ namespace Dawn { typedef GLuint shaderbufferlocation_t; template - class ShaderParameterBuffer : public IShaderParameterBuffer { + class ShaderParameterBuffer : + public IShaderParameterBuffer + { protected: shaderbufferlocation_t id = -1; size_t size; public: void init() { - assertTrue(this->id == -1, "ShaderParameterBuffer::init: ShaderParameterBuffer is already initialized!"); + assertTrue( + this->id == -1, + "ShaderParameterBuffer is already initialized!" + ); this->size = sizeof(T); glGenBuffers(1, &this->id); assertNoGLError(); @@ -46,7 +51,7 @@ namespace Dawn { } void bind(shaderbufferslot_t location) override { - assertTrue(this->isReady(), "ShaderParameterBuffer::bind: ShaderParameterBuffer is not ready!"); + assertTrue(this->isReady(), "ShaderParameterBuffer is not ready!"); glBindBuffer(GL_UNIFORM_BUFFER, this->id); assertNoGLError(); glBindBufferBase(GL_UNIFORM_BUFFER, location, this->id); @@ -71,10 +76,12 @@ namespace Dawn { * @param length Length of the data to buffer. */ void bufferRaw(void *data, size_t start, size_t length) { - assertTrue(this->isReady(), "ShaderParameterBuffer::bufferRaw: ShaderParameterBuffer is not ready!"); + assertTrue(this->isReady(), "ShaderParameterBuffer is not ready!"); glBindBuffer(GL_UNIFORM_BUFFER, this->id); assertNoGLError(); - glBufferSubData(GL_UNIFORM_BUFFER, start, length, (void*)((size_t)data + start)); + glBufferSubData( + GL_UNIFORM_BUFFER, start, length, (void*)((size_t)data + start) + ); assertNoGLError(); } diff --git a/src/dawnopengl/display/shader/shaders/SimpleTexturedShader.cpp b/src/dawnopengl/display/shader/shaders/SimpleTexturedShader.cpp index 53399e2d..db856d48 100644 --- a/src/dawnopengl/display/shader/shaders/SimpleTexturedShader.cpp +++ b/src/dawnopengl/display/shader/shaders/SimpleTexturedShader.cpp @@ -63,7 +63,9 @@ void SimpleTexturedShader::compile() { "float4 out gl_Position : POSITION\n" ") {\n" "o_TextCoord = aTexCoord;\n" - "gl_Position = mul(mul(mul(float4(aPos, 1.0), u_Model), u_View), u_Proj);\n" + "gl_Position = mul(\n" + "mul(mul(float4(aPos, 1.0), u_Model), u_View), u_Proj\n" + ");\n" "}", // Fragment Shader @@ -91,5 +93,7 @@ void SimpleTexturedShader::compile() { this->paramColor = this->getParameterByName("u_Color"); this->paramTexture = this->getParameterByName("u_Text"); this->paramHasTexture = this->getParameterByName("u_HasTexture"); - this->bufferRenderPipeline = this->getBufferLocationByName(RenderPipelineShaderBuffer::getShaderUniformName()); + this->bufferRenderPipeline = this->getBufferLocationByName( + RenderPipelineShaderBuffer::getShaderUniformName() + ); } \ No newline at end of file diff --git a/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp b/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp index 3e58da29..d2bfa7d6 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp +++ b/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.cpp @@ -15,27 +15,31 @@ SimpleBillboardedMaterial::SimpleBillboardedMaterial(SceneItem *i) : } void SimpleBillboardedMaterial::onStart() { - this->shaderLock = this->getGame()->renderManager.getShaderManager()->lockShader(); + this->shaderLock = getShaderManager().lockShader(); } void SimpleBillboardedMaterial::onDispose() { - this->getGame()->renderManager.getShaderManager()->releaseShader(this->shaderLock); + getShaderManager().releaseShader(this->shaderLock); } -std::vector SimpleBillboardedMaterial::getRenderPasses(IRenderableContext &context) { - auto mesh = this->item->getComponent(); - auto shader = this->getGame()->renderManager.getShaderManager()->getShader(this->shaderLock); +std::vector + SimpleBillboardedMaterial::getRenderPasses(IRenderableContext &context) +{ + auto mesh = item->getComponent(); + auto shader = getShaderManager().getShader(this->shaderLock); - assertNotNull(mesh, "SimpleBillboardedMaterial::getRenderPasses: Mesh cannot be null"); - assertNotNull(mesh->mesh, "SimpleBillboardedMaterial::getRenderPasses: Mesh cannot be null"); - assertNotNull(shader, "SimpleBillboardedMaterial::getRenderPasses: Shader cannot be null"); + assertNotNull(mesh, "Mesh cannot be null"); + assertNotNull(mesh->mesh, "Mesh cannot be null"); + assertNotNull(shader, "Shader cannot be null"); struct ShaderPassItem onlyPass; onlyPass.mesh = mesh->mesh; onlyPass.shader = shader; onlyPass.colorValues[shader->paramColor] = this->color; onlyPass.matrixValues[shader->paramModel] = this->transform->getWorldTransform(); - onlyPass.parameterBuffers[shader->bufferRenderPipeline] = &context.renderPipeline->shaderBuffer; + onlyPass.parameterBuffers[shader->bufferRenderPipeline] = + &context.renderPipeline->shaderBuffer + ; onlyPass.renderFlags = ( RENDER_MANAGER_RENDER_FLAG_BLEND diff --git a/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.hpp b/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.hpp index 95d58a5e..d40b9bef 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.hpp +++ b/src/dawnopengl/scene/components/display/material/SimpleBillboardedMaterial.hpp @@ -27,6 +27,8 @@ namespace Dawn { void onStart() override; void onDispose() override; - std::vector getRenderPasses(IRenderableContext &context) override; + std::vector + getRenderPasses(IRenderableContext &context) override + ; }; } \ No newline at end of file diff --git a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp index c2a3279b..1273cb57 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp +++ b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.cpp @@ -14,27 +14,35 @@ SimpleTexturedMaterial::SimpleTexturedMaterial(SceneItem *i) : } void SimpleTexturedMaterial::onStart() { - this->shaderLock = this->getGame()->renderManager.getShaderManager()->lockShader(); + this->shaderLock = getShaderManager().lockShader(); } void SimpleTexturedMaterial::onDispose() { - this->getGame()->renderManager.getShaderManager()->releaseShader(this->shaderLock); + getShaderManager().releaseShader(this->shaderLock); } -std::vector SimpleTexturedMaterial::getRenderPasses(IRenderableContext &context) { +std::vector + SimpleTexturedMaterial::getRenderPasses(IRenderableContext &context) +{ auto mesh = this->item->getComponent(); - auto shader = this->getGame()->renderManager.getShaderManager()->getShader(this->shaderLock); + auto shader = getShaderManager() + .getShader(this->shaderLock) + ; - assertNotNull(mesh, "SimpleTexturedMaterial::getRenderPasses: Mesh cannot be null"); - assertNotNull(mesh->mesh, "SimpleTexturedMaterial::getRenderPasses: Mesh cannot be null"); - assertNotNull(shader, "SimpleTexturedMaterial::getRenderPasses: Shader cannot be null"); + assertNotNull(mesh, "Mesh cannot be null"); + assertNotNull(mesh->mesh, "Mesh cannot be null"); + assertNotNull(shader, "Shader cannot be null"); struct ShaderPassItem onlyPass; onlyPass.mesh = mesh->mesh; onlyPass.shader = shader; onlyPass.colorValues[shader->paramColor] = this->color; - onlyPass.matrixValues[shader->paramModel] = this->transform->getWorldTransform(); - onlyPass.parameterBuffers[shader->bufferRenderPipeline] = &context.renderPipeline->shaderBuffer; + onlyPass.matrixValues[shader->paramModel] = + this->transform->getWorldTransform() + ; + onlyPass.parameterBuffers[ + shader->bufferRenderPipeline + ] = &context.renderPipeline->shaderBuffer; if(this->opaque) { onlyPass.renderFlags = ( diff --git a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.hpp b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.hpp index 0978a412..c88bbcf4 100644 --- a/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.hpp +++ b/src/dawnopengl/scene/components/display/material/SimpleTexturedMaterial.hpp @@ -29,6 +29,8 @@ namespace Dawn { void onStart() override; void onDispose() override; - std::vector getRenderPasses(IRenderableContext &context) override; + std::vector + getRenderPasses(IRenderableContext &context) override + ; }; } \ No newline at end of file