Stripped back old shader code for now.
This commit is contained in:
1 parent
2b36a12335
commit
e10aea20a1
81 files changed
+321
-896
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
};
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -33,7 +33,6 @@ add_subdirectory(scene)
|
||||
add_subdirectory(settings)
|
||||
add_subdirectory(time)
|
||||
add_subdirectory(util)
|
||||
add_subdirectory(ui)
|
||||
|
||||
|
||||
# Assets
|
||||
|
||||
@@ -18,7 +18,7 @@ ShaderLoader::ShaderLoader(
|
||||
) :
|
||||
AssetLoader(assetManager, name),
|
||||
state(ShaderLoaderState::INITIAL),
|
||||
shader(std::make_shared<ShaderProgram2>())
|
||||
shader(std::make_shared<ShaderProgram>())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ void ShaderLoader::updateSync() {
|
||||
// Create the shader program.
|
||||
Slang::ComPtr<IBlob> blob;
|
||||
slang::ProgramLayout* layout = program->getLayout();
|
||||
std::vector<std::shared_ptr<ShaderEntry>> shaderEntries;
|
||||
std::vector<std::shared_ptr<ShaderStage>> 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>();
|
||||
shaderEntry->init(
|
||||
auto shaderStage = std::make_shared<ShaderStage>();
|
||||
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<IShaderProgram2> ShaderLoader::getShader() {
|
||||
std::shared_ptr<ShaderProgram> ShaderLoader::getShader() {
|
||||
assertNotNull(shader, "ShaderLoader shader is null.");
|
||||
return shader;
|
||||
}
|
||||
|
||||
@@ -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<ShaderProgram2> shader;
|
||||
std::shared_ptr<ShaderProgram> 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<IShaderProgram2>
|
||||
* @return The shader program that this loader is managing.
|
||||
*/
|
||||
std::shared_ptr<IShaderProgram2> getShader();
|
||||
std::shared_ptr<ShaderProgram> getShader();
|
||||
|
||||
~ShaderLoader();
|
||||
};
|
||||
|
||||
@@ -10,4 +10,3 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(ui)
|
||||
@@ -17,7 +17,7 @@ namespace Dawn {
|
||||
* @param ctx Context for the render pass.
|
||||
* @return List of render passes.
|
||||
*/
|
||||
virtual std::vector<std::shared_ptr<IRenderPass>> getPasses(
|
||||
virtual std::vector<std::shared_ptr<RenderPass>> 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<class S, typename D>
|
||||
std::shared_ptr<IRenderPass> createRenderPass(
|
||||
SceneComponent &self,
|
||||
const D data,
|
||||
const std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures = {},
|
||||
const std::shared_ptr<Mesh> mesh = nullptr,
|
||||
const enum MeshDrawMode drawMode = MeshDrawMode::TRIANGLES,
|
||||
int32_t indiceStart = 0,
|
||||
int32_t indiceCount = -1
|
||||
) {
|
||||
return std::make_shared<RenderPass<S,D>>(
|
||||
self,
|
||||
data,
|
||||
textures,
|
||||
mesh,
|
||||
drawMode,
|
||||
indiceStart,
|
||||
indiceCount
|
||||
);
|
||||
}
|
||||
// template<class S, typename D>
|
||||
// std::shared_ptr<IRenderPass> createRenderPass(
|
||||
// SceneComponent &self,
|
||||
// const D data,
|
||||
// const std::unordered_map<
|
||||
// shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
// > textures = {},
|
||||
// const std::shared_ptr<Mesh> mesh = nullptr,
|
||||
// const enum MeshDrawMode drawMode = MeshDrawMode::TRIANGLES,
|
||||
// int32_t indiceStart = 0,
|
||||
// int32_t indiceCount = -1
|
||||
// ) {
|
||||
// return std::make_shared<RenderPass<S,D>>(
|
||||
// self,
|
||||
// data,
|
||||
// textures,
|
||||
// mesh,
|
||||
// drawMode,
|
||||
// indiceStart,
|
||||
// indiceCount
|
||||
// );
|
||||
// }
|
||||
}
|
||||
@@ -9,11 +9,7 @@
|
||||
using namespace Dawn;
|
||||
|
||||
void Material::onInit() {
|
||||
this->lockedShaders = this->getLockedShaders(
|
||||
getGame()->renderHost->shaderManager
|
||||
);
|
||||
}
|
||||
|
||||
void Material::onDispose() {
|
||||
this->lockedShaders.clear();
|
||||
}
|
||||
@@ -13,18 +13,8 @@ namespace Dawn {
|
||||
public IRenderableComponent
|
||||
{
|
||||
private:
|
||||
std::vector<std::shared_ptr<IShaderBase>> 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<std::shared_ptr<IShaderBase>> getLockedShaders(
|
||||
ShaderManager &shaderManager
|
||||
) = 0;
|
||||
|
||||
public:
|
||||
void onInit() override;
|
||||
|
||||
@@ -9,14 +9,6 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<
|
||||
std::shared_ptr<IShaderBase>
|
||||
> SimpleTexturedMaterial::getLockedShaders(ShaderManager &shaderManager) {
|
||||
return {
|
||||
shaderManager.getShader<SimpleTexturedShader>()
|
||||
};
|
||||
}
|
||||
|
||||
void SimpleTexturedMaterial::load(std::shared_ptr<SceneLoadContext> ctx) {
|
||||
if(ctx->data.contains("color")) {
|
||||
this->setColor(JSON::color(ctx->data["color"]));
|
||||
@@ -31,7 +23,7 @@ void SimpleTexturedMaterial::load(std::shared_ptr<SceneLoadContext> ctx) {
|
||||
}
|
||||
|
||||
struct Color SimpleTexturedMaterial::getColor() {
|
||||
return this->data.data.color;
|
||||
return this->data.color;
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> 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<std::shared_ptr<IRenderPass>> SimpleTexturedMaterial::getPasses(
|
||||
std::vector<std::shared_ptr<RenderPass>> 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<Texture>
|
||||
>();
|
||||
// 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<Texture>
|
||||
// >();
|
||||
|
||||
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<SimpleTexturedShader, struct SimpleTexturedShaderData>(
|
||||
*this,
|
||||
data,
|
||||
textures
|
||||
)
|
||||
// createRenderPass<SimpleTexturedShader, struct SimpleTexturedShaderData>(
|
||||
// *this,
|
||||
// data,
|
||||
// textures
|
||||
// )
|
||||
};
|
||||
}
|
||||
@@ -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> texture;
|
||||
|
||||
protected:
|
||||
std::vector<std::shared_ptr<IShaderBase>> getLockedShaders(
|
||||
ShaderManager &shaderManager
|
||||
) override;
|
||||
|
||||
public:
|
||||
void load(std::shared_ptr<SceneLoadContext> ctx) override;
|
||||
@@ -48,7 +53,7 @@ namespace Dawn {
|
||||
*/
|
||||
void setColor(const struct Color color);
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> getPasses(
|
||||
std::vector<std::shared_ptr<RenderPass>> getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) override;
|
||||
};
|
||||
|
||||
@@ -16,3 +16,4 @@ add_subdirectory(mesh)
|
||||
add_subdirectory(shader)
|
||||
add_subdirectory(font)
|
||||
add_subdirectory(tileset)
|
||||
add_subdirectory(pass)
|
||||
@@ -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.
|
||||
|
||||
@@ -78,7 +78,7 @@ void RenderPipeline::renderSceneCamera(
|
||||
};
|
||||
|
||||
// Get list of renderables
|
||||
std::vector<std::shared_ptr<IRenderPass>> renderPasses;
|
||||
std::vector<std::shared_ptr<RenderPass>> renderPasses;
|
||||
auto renderables = scene->findComponents<IRenderableComponent>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
MapShader.cpp
|
||||
RenderPass.cpp
|
||||
)
|
||||
@@ -1,40 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "display/mesh/Mesh.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class IRenderPass {
|
||||
public:
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
|
||||
/**
|
||||
* Binds the shader for this render pass.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
/**
|
||||
* Sets the data for this render pass to the shader.
|
||||
*/
|
||||
virtual void setData() = 0;
|
||||
|
||||
/**
|
||||
* Uploads the data to the GPU.
|
||||
*/
|
||||
virtual void upload() = 0;
|
||||
|
||||
/**
|
||||
* Draws the mesh for this render pass.
|
||||
*/
|
||||
virtual void draw() = 0;
|
||||
|
||||
/**
|
||||
* Cleans up the render pass.
|
||||
*/
|
||||
virtual ~IRenderPass() {
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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> 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<MeshRenderer>();
|
||||
if(meshRenderer) this->mesh = meshRenderer->mesh;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderPass::draw() {
|
||||
mesh->draw(drawMode, indiceStart, indiceCount);
|
||||
}
|
||||
@@ -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 S, typename D>
|
||||
class RenderPass : public IRenderPass {
|
||||
class RenderPass {
|
||||
private:
|
||||
std::shared_ptr<S> shader;
|
||||
const std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures;
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
const enum MeshDrawMode drawMode;
|
||||
const int32_t indiceStart;
|
||||
const int32_t indiceCount;
|
||||
const D data;
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -37,58 +28,20 @@ namespace Dawn {
|
||||
*/
|
||||
RenderPass(
|
||||
SceneComponent &self,
|
||||
const D d,
|
||||
const std::unordered_map<
|
||||
shadertexturebinding_t, std::shared_ptr<Texture>
|
||||
> textures,
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const enum MeshDrawMode drawMode,
|
||||
const int32_t indiceStart,
|
||||
const int32_t indiceCount
|
||||
) :
|
||||
data(d),
|
||||
textures(textures),
|
||||
mesh(mesh),
|
||||
drawMode(drawMode),
|
||||
indiceStart(indiceStart),
|
||||
indiceCount(indiceCount)
|
||||
{
|
||||
//Get the shader
|
||||
shader = (
|
||||
self.getGame()->renderHost->shaderManager.getShader<S>()
|
||||
);
|
||||
assertNotNull(shader, "Shader cannot be null!");
|
||||
|
||||
// Need mesh?
|
||||
if(!this->mesh) {
|
||||
auto meshRenderer = self.getItem()->getComponent<MeshRenderer>();
|
||||
if(meshRenderer) this->mesh = meshRenderer->mesh;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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();
|
||||
};
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawn.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum class ShaderParameterType {
|
||||
VEC2,
|
||||
VEC3,
|
||||
VEC4,
|
||||
MAT3,
|
||||
MAT4,
|
||||
COLOR,
|
||||
FLOAT,
|
||||
INT,
|
||||
TEXTURE,
|
||||
BOOLEAN
|
||||
};
|
||||
|
||||
class IShaderBase {
|
||||
public:
|
||||
virtual ~IShaderBase() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class IShader : public IShaderBase {
|
||||
protected:
|
||||
T data;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns the currently uploaded data on the Shader.
|
||||
*
|
||||
* @return The uploaded data.
|
||||
*/
|
||||
T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the entire data to be uploaded.
|
||||
*
|
||||
* @param data Data to be uploaded.
|
||||
*/
|
||||
void setData(const T data) {
|
||||
this->data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the shader, this needs to be called before the shader can
|
||||
* be used.
|
||||
*/
|
||||
virtual void init() = 0;
|
||||
|
||||
/**
|
||||
* Binds the shader as the current one, does not upload any data, somewhat
|
||||
* relies on something else uploading the data.
|
||||
*/
|
||||
virtual void bind() = 0;
|
||||
|
||||
/**
|
||||
* Uploads the data to the GPU.
|
||||
*/
|
||||
virtual void upload() = 0;
|
||||
|
||||
/**
|
||||
* Disposes of the shader.
|
||||
*/
|
||||
virtual ~IShader() {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the ShaderParameterType.
|
||||
*
|
||||
* @param type The type to get the size of.
|
||||
* @return Size of the type.
|
||||
*/
|
||||
size_t shaderParameterTypeGetSize(const Dawn::ShaderParameterType type);
|
||||
@@ -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<std::shared_ptr<ShaderStage>> &stages
|
||||
) {
|
||||
this->stages = stages;
|
||||
}
|
||||
|
||||
IShaderProgram::~IShaderProgram() {
|
||||
}
|
||||
@@ -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<std::shared_ptr<ShaderStage>> stages;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Initialize the IShaderProgram2 object
|
||||
*
|
||||
* @param stages The list of shader stages to initialize with.
|
||||
*/
|
||||
virtual void init(
|
||||
const std::vector<std::shared_ptr<ShaderStage>> &stages
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Destroy the IShaderProgram2 object
|
||||
*/
|
||||
virtual ~IShaderProgram();
|
||||
};
|
||||
}
|
||||
@@ -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<std::shared_ptr<ShaderEntry>> &entries
|
||||
) {
|
||||
this->entries = entries;
|
||||
}
|
||||
|
||||
IShaderProgram2::~IShaderProgram2() {
|
||||
|
||||
}
|
||||
@@ -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<std::shared_ptr<ShaderEntry>> entries;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Initialize the IShaderProgram2 object
|
||||
*
|
||||
* @param entries The list of shader entries to initialize with.
|
||||
*/
|
||||
virtual void init(
|
||||
const std::vector<std::shared_ptr<ShaderEntry>> &entries
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* Destroy the IShaderProgram2 object
|
||||
*/
|
||||
virtual ~IShaderProgram2();
|
||||
};
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
@@ -47,6 +47,4 @@ std::shared_ptr<Game> ShaderManager::getGame() {
|
||||
}
|
||||
|
||||
ShaderManager::~ShaderManager() {
|
||||
// Clear all shaders
|
||||
shaders.clear();
|
||||
}
|
||||
@@ -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<ShaderManager> {
|
||||
private:
|
||||
std::vector<std::weak_ptr<IShaderBase>> shaders;
|
||||
|
||||
std::weak_ptr<Game> game;
|
||||
ShaderManagerSlangFileSystem fileSystem;
|
||||
|
||||
Slang::ComPtr<IGlobalSession> globalSession;
|
||||
TargetDesc targetDescription;
|
||||
SessionDesc sessionDescription;
|
||||
@@ -44,34 +40,6 @@ namespace Dawn {
|
||||
*/
|
||||
std::shared_ptr<Game> 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<class T>
|
||||
std::shared_ptr<T> getShader() {
|
||||
auto itShaders = shaders.begin();
|
||||
while(itShaders != shaders.end()) {
|
||||
auto shader = itShaders->lock();
|
||||
if(!shader) {
|
||||
itShaders = shaders.erase(itShaders);
|
||||
continue;
|
||||
}
|
||||
|
||||
std::shared_ptr<T> casted = std::dynamic_pointer_cast<T>(shader);
|
||||
if(casted) return casted;
|
||||
itShaders++;
|
||||
}
|
||||
|
||||
auto newShader = std::make_shared<T>();
|
||||
shaders.push_back(newShader);
|
||||
newShader->init();
|
||||
return newShader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes of all shaders.
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
)
|
||||
@@ -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<std::shared_ptr<ShaderStage>> &stages
|
||||
) {
|
||||
IShaderProgram::init(stages);
|
||||
}
|
||||
|
||||
ShaderProgram::~ShaderProgram() {
|
||||
}
|
||||
@@ -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<std::shared_ptr<ShaderStage>> &stages
|
||||
) override;
|
||||
~ShaderProgram();
|
||||
};
|
||||
}
|
||||
@@ -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<std::shared_ptr<ShaderEntry>> &entries
|
||||
) {
|
||||
IShaderProgram2::init(entries);
|
||||
}
|
||||
|
||||
ShaderProgram2::~ShaderProgram2() {
|
||||
}
|
||||
@@ -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<std::shared_ptr<ShaderEntry>> &entries
|
||||
) override;
|
||||
~ShaderProgram2();
|
||||
};
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
};
|
||||
}
|
||||
@@ -11,7 +11,6 @@ target_include_directories(${DAWN_TARGET_NAME}
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(component)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(game)
|
||||
add_subdirectory(rpg)
|
||||
|
||||
|
||||
@@ -11,4 +11,3 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(display)
|
||||
@@ -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)
|
||||
@@ -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
|
||||
)
|
||||
@@ -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<IShaderBase>
|
||||
> MapMaterial::getLockedShaders(ShaderManager &shaderManager) {
|
||||
return {
|
||||
shaderManager.getShader<MapShader>()
|
||||
};
|
||||
}
|
||||
|
||||
void MapMaterial::load(std::shared_ptr<SceneLoadContext> ctx) {
|
||||
if(ctx->data.contains("color")) {
|
||||
this->setColor(JSON::color(ctx->data["color"]));
|
||||
}
|
||||
|
||||
if(ctx->data.contains("texture")) {
|
||||
auto asset = ctx->getAsset<TextureLoader>(
|
||||
ctx->data["texture"].get<std::string>()
|
||||
);
|
||||
this->setTexture(asset->getTexture());
|
||||
}
|
||||
}
|
||||
|
||||
struct Color MapMaterial::getColor() {
|
||||
return this->data.color;
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> MapMaterial::getTexture() {
|
||||
return this->texture;
|
||||
}
|
||||
|
||||
void MapMaterial::setTexture(
|
||||
const std::shared_ptr<Texture> texture
|
||||
) {
|
||||
this->texture = texture;
|
||||
}
|
||||
|
||||
void MapMaterial::setColor(const struct Color color) {
|
||||
this->data.color = color;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> 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<Texture>
|
||||
>();
|
||||
|
||||
if(this->texture) {
|
||||
this->data.hasTexture = true;
|
||||
this->data.texture = 0;
|
||||
textures[this->data.texture] = this->texture;
|
||||
} else {
|
||||
this->data.hasTexture = false;
|
||||
}
|
||||
|
||||
return {
|
||||
createRenderPass<MapShader, struct MapShaderData>(
|
||||
*this,
|
||||
data,
|
||||
textures
|
||||
)
|
||||
};
|
||||
}
|
||||
@@ -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<std::shared_ptr<IShaderBase>> getLockedShaders(
|
||||
ShaderManager &shaderManager
|
||||
) override;
|
||||
|
||||
private:
|
||||
struct MapShaderData data;
|
||||
std::shared_ptr<Texture> texture;
|
||||
|
||||
public:
|
||||
void load(std::shared_ptr<SceneLoadContext> 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<Texture> getTexture();
|
||||
|
||||
/**
|
||||
* Sets the texture of this material.
|
||||
*
|
||||
* @param texture The texture to set.
|
||||
*/
|
||||
void setTexture(const std::shared_ptr<Texture> texture);
|
||||
|
||||
/**
|
||||
* Sets the color of this material.
|
||||
*
|
||||
* @param color The color to set.
|
||||
*/
|
||||
void setColor(const struct Color color);
|
||||
|
||||
std::vector<std::shared_ptr<IRenderPass>> getPasses(
|
||||
struct RenderPassContext &ctx
|
||||
) override;
|
||||
};
|
||||
}
|
||||
@@ -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)
|
||||
@@ -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<std::shared_ptr<ShaderStage>> &stages,
|
||||
std::vector<struct ShaderParameter> ¶meters,
|
||||
std::vector<struct IShaderStructure> &structures
|
||||
) {
|
||||
// Stages
|
||||
std::shared_ptr<ShaderStage> vertex;
|
||||
std::shared_ptr<ShaderStage> fragment;
|
||||
|
||||
std::cout << "MapShader::getStages" << std::endl;
|
||||
|
||||
switch(variant) {
|
||||
case ShaderOpenGLVariant::GLSL_330_CORE:
|
||||
vertex = std::make_shared<ShaderStage>(
|
||||
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<ShaderStage>(
|
||||
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
|
||||
));
|
||||
}
|
||||
@@ -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<MapShaderData> {
|
||||
protected:
|
||||
void getStages(
|
||||
const enum ShaderOpenGLVariant variant,
|
||||
const struct MapShaderData *rel,
|
||||
std::vector<std::shared_ptr<ShaderStage>> &stages,
|
||||
std::vector<struct ShaderParameter> ¶meters,
|
||||
std::vector<struct IShaderStructure> &structures
|
||||
) override;
|
||||
};
|
||||
}
|
||||
@@ -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 <fstream>
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@@ -20,7 +17,6 @@ Game::Game() : IGame() {
|
||||
SceneComponentRegistry::reg<RPGEntity>("RPGEntity");
|
||||
SceneComponentRegistry::reg<RPGPlayer>("RPGPlayer");
|
||||
SceneComponentRegistry::reg<RPGMap>("RPGMap");
|
||||
SceneComponentRegistry::reg<MapMaterial>("MapMaterial");
|
||||
}
|
||||
|
||||
std::string Game::getInitialScene() {
|
||||
@@ -33,16 +29,6 @@ void Game::initManagers() {
|
||||
|
||||
auto sl = assetManager->get<ShaderLoader>("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() {
|
||||
|
||||
Reference in new issue
Block a user