From c87f13b063f7d5003b32cfcaf7a274e472711945 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 21 Dec 2024 20:33:25 -0600 Subject: [PATCH] shader --- src/dawn/asset/loader/ShaderLoader.cpp | 31 +++++++------------ src/dawn/display/shader/ShaderManager.cpp | 8 +++-- src/dawn/game/IGame.cpp | 2 +- .../display/shader/SimpleTexturedShader.cpp | 7 ----- src/dawnrpg/game/Game.cpp | 3 +- 5 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/dawn/asset/loader/ShaderLoader.cpp b/src/dawn/asset/loader/ShaderLoader.cpp index b57ffb1c..2c5c3ca0 100644 --- a/src/dawn/asset/loader/ShaderLoader.cpp +++ b/src/dawn/asset/loader/ShaderLoader.cpp @@ -8,8 +8,6 @@ #include "asset/AssetManager.hpp" #include "game/Game.hpp" -#include - using namespace Dawn; const std::string ShaderLoader::ASSET_TYPE = "shader"; @@ -44,9 +42,9 @@ void ShaderLoader::updateSync() { // Get list of entry points and create components int32_t definedEntryPointCount = module->getDefinedEntryPointCount(); IComponentType** components = new IComponentType*[definedEntryPointCount + 1]; - int32_t j = 0; + int32_t componentCount = 0; - components[j++] = module; + components[componentCount++] = module; for(auto i = 0; i < definedEntryPointCount; i++) { Slang::ComPtr ep; @@ -60,15 +58,20 @@ void ShaderLoader::updateSync() { auto name = ep->getFunctionReflection()->getName(); std::cout << "Found entry point: " << name << std::endl; entryPoints.push_back(std::string(name)); - components[j++] = ep; + components[componentCount++] = ep; } // Create the composite component type sm->session->createCompositeComponentType( components, - sizeof(components) / sizeof(components[0]), - program.writeRef() + componentCount, + program.writeRef(), + diagnostics.writeRef() ); + if(diagnostics) { + assertUnreachable("%s\n", (const char*) diagnostics->getBufferPointer()); + return; + } // Link the program. auto result = program->link(linkedProgram.writeRef(), diagnostics.writeRef()); @@ -77,19 +80,7 @@ void ShaderLoader::updateSync() { return; } - // result - Slang::ComPtr blob; - auto result2 = linkedProgram->getEntryPointCode( - 0, - 0, - blob.writeRef(), - diagnostics.writeRef() - ); - - if(diagnostics) { - assertUnreachable("%s\n", (const char*) diagnostics->getBufferPointer()); - } - + delete [] components; this->state = ShaderLoaderState::LOADED; this->loaded = true; } diff --git a/src/dawn/display/shader/ShaderManager.cpp b/src/dawn/display/shader/ShaderManager.cpp index b897b485..3ccb8612 100644 --- a/src/dawn/display/shader/ShaderManager.cpp +++ b/src/dawn/display/shader/ShaderManager.cpp @@ -8,12 +8,16 @@ using namespace Dawn; -ShaderManager::ShaderManager() { + +ShaderManager::ShaderManager() : + targetDescription(), + sessionDescription() +{ } void ShaderManager::init(const std::shared_ptr &game) { assertNotNull(game, "Game instance must not be null."); - + this->game = game; // Create the file system diff --git a/src/dawn/game/IGame.cpp b/src/dawn/game/IGame.cpp index 94d76f7d..924728d4 100644 --- a/src/dawn/game/IGame.cpp +++ b/src/dawn/game/IGame.cpp @@ -63,7 +63,7 @@ void IGame::init() { settingsManager->load(); shaderManager = std::make_shared(); - shaderManager->init(shared_from_this()); + shaderManager->init(selfAsGame); this->initManagers(); diff --git a/src/dawnopengl/display/shader/SimpleTexturedShader.cpp b/src/dawnopengl/display/shader/SimpleTexturedShader.cpp index ac432c56..a08563c5 100644 --- a/src/dawnopengl/display/shader/SimpleTexturedShader.cpp +++ b/src/dawnopengl/display/shader/SimpleTexturedShader.cpp @@ -78,7 +78,6 @@ void SimpleTexturedShader::getStages( return output; } )"; - Slang::ComPtr globalSession; createGlobalSession(globalSession.writeRef()); @@ -159,9 +158,6 @@ void SimpleTexturedShader::getStages( } std::string vertexString = (const char*)vertexBlob->getBufferPointer(); - std::ofstream out("/home/yourwishes/htdocs/Dawn/vertex.glsl"); - out << vertexString; - out.close(); entryPointIndex = 1; Slang::ComPtr fragmentBlob; @@ -177,9 +173,6 @@ void SimpleTexturedShader::getStages( } std::string fragmentString = (const char*)fragmentBlob->getBufferPointer(); - out.open("/home/yourwishes/htdocs/Dawn/fragment.glsl"); - out << fragmentString; - out.close(); vertex = std::make_shared( ShaderStageType::VERTEX, vertexString diff --git a/src/dawnrpg/game/Game.cpp b/src/dawnrpg/game/Game.cpp index 43d0c69d..0e0e627b 100644 --- a/src/dawnrpg/game/Game.cpp +++ b/src/dawnrpg/game/Game.cpp @@ -32,7 +32,8 @@ void Game::initManagers() { auto sl = assetManager->get("shaders/hello-world.slang"); sl->loadImmediately(); - auto code = sl->getEntryPointCode("vertexMain"); + auto code1 = sl->getEntryPointCode("vertexMain"); + auto code2 = sl->getEntryPointCode("fragmentMain"); } Game::~Game() {