First render.
This commit is contained in:
@ -7,9 +7,29 @@
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
template<struct T>
|
||||
class IShader {
|
||||
private:
|
||||
enum 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:
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
IShaderStage::IShaderStage(const enum ShaderType type) :
|
||||
IShaderStage::IShaderStage(const enum ShaderStageType type) :
|
||||
type(type)
|
||||
{
|
||||
|
||||
|
@ -7,20 +7,22 @@
|
||||
#include "dawnlibs.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum ShaderType {
|
||||
enum ShaderStageType {
|
||||
VERTEX,
|
||||
FRAGMENT,
|
||||
COMPUTE
|
||||
// COMPUTE
|
||||
};
|
||||
|
||||
class IShaderStage {
|
||||
public:
|
||||
const enum ShaderStageType type;
|
||||
|
||||
/**
|
||||
* Constructs a new Shader Stage.
|
||||
*
|
||||
* @param type Type of shader stage.
|
||||
*/
|
||||
IShaderStage(const enum ShaderType type);
|
||||
IShaderStage(const enum ShaderStageType type);
|
||||
|
||||
/**
|
||||
* Destroy the IShaderStage object
|
||||
|
45
src/dawn/display/shader/ShaderManager.hpp
Normal file
45
src/dawn/display/shader/ShaderManager.hpp
Normal file
@ -0,0 +1,45 @@
|
||||
// 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 {
|
||||
class ShaderManager {
|
||||
private:
|
||||
std::vector<std::shared_ptr<IShaderBase>> shaders;
|
||||
|
||||
public:
|
||||
/**
|
||||
* 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);
|
||||
|
||||
auto shader = *itShaders;
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user