Files
Seele/src/Engine/Graphics/Shader.h
T

109 lines
2.2 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#pragma once
#include "Enums.h"
2023-11-01 13:38:49 +01:00
#include "CRC.h"
2023-10-26 18:37:29 +02:00
namespace Seele
{
namespace Gfx
{
class Shader
{};
DEFINE_REF(Shader)
class TaskShader
{
public:
TaskShader() {}
virtual ~TaskShader() {}
};
DEFINE_REF(TaskShader)
class MeshShader
{
public:
MeshShader() {}
virtual ~MeshShader() {}
};
DEFINE_REF(MeshShader)
class VertexShader
{
public:
VertexShader() {}
virtual ~VertexShader() {}
};
DEFINE_REF(VertexShader)
class FragmentShader
{
public:
FragmentShader() {}
virtual ~FragmentShader() {}
};
DEFINE_REF(FragmentShader)
class ComputeShader
{
public:
ComputeShader() {}
virtual ~ComputeShader() {}
};
DEFINE_REF(ComputeShader)
//Uniquely identifies a permutation of shaders
//using the type parameters used to generate it
struct ShaderPermutation
{
RenderPassType passType;
char vertexInputName[15];
char materialName[16];
//TODO: lightmapping etc
};
//Hashed ShaderPermutation for fast lookup
struct PermutationId
{
uint32 hash;
PermutationId()
: hash(0)
{}
PermutationId(ShaderPermutation permutation)
: hash(CRC::Calculate(&permutation, sizeof(ShaderPermutation), CRC::CRC_32()))
{}
friend inline bool operator==(const PermutationId& lhs, const PermutationId& rhs)
{
return lhs.hash == rhs.hash;
}
friend inline bool operator!=(const PermutationId& lhs, const PermutationId& rhs)
{
return lhs.hash != rhs.hash;
}
friend inline bool operator<(const PermutationId& lhs, const PermutationId& rhs)
{
return lhs.hash < rhs.hash;
}
friend inline bool operator>(const PermutationId& lhs, const PermutationId& rhs)
{
return lhs.hash > rhs.hash;
}
};
struct ShaderCollection
{
PermutationId id;
//PVertexDeclaration vertexDeclaration;
PVertexShader vertexShader;
PFragmentShader fragmentShader;
};
class ShaderMap
{
public:
ShaderMap();
~ShaderMap();
const ShaderCollection* findShaders(PermutationId&& id) const;
ShaderCollection& createShaders(
PGraphics graphics,
RenderPassType passName,
bool bPositionOnly);
private:
std::mutex shadersLock;
Array<ShaderCollection> shaders;
};
DEFINE_REF(ShaderMap)
}
} // namespace Seele