Formatted EVERYTHING

This commit is contained in:
Dynamitos
2024-06-09 12:20:53 +02:00
parent f18bf8acbe
commit d95dab850c
265 changed files with 8002 additions and 12310 deletions
+42 -81
View File
@@ -1,58 +1,50 @@
#pragma once
#include "Enums.h"
#include "CRC.h"
#include "Enums.h"
#include "Resources.h"
#include "VertexData.h"
namespace Seele
{
namespace Gfx
{
class Shader
{};
namespace Seele {
namespace Gfx {
class Shader {};
DEFINE_REF(Shader)
class TaskShader
{
public:
class TaskShader {
public:
TaskShader() {}
virtual ~TaskShader() {}
};
DEFINE_REF(TaskShader)
class MeshShader
{
public:
class MeshShader {
public:
MeshShader() {}
virtual ~MeshShader() {}
};
DEFINE_REF(MeshShader)
class VertexShader
{
public:
class VertexShader {
public:
VertexShader() {}
virtual ~VertexShader() {}
};
DEFINE_REF(VertexShader)
class FragmentShader
{
public:
class FragmentShader {
public:
FragmentShader() {}
virtual ~FragmentShader() {}
};
DEFINE_REF(FragmentShader)
class ComputeShader
{
public:
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
{
// Uniquely identifies a permutation of shaders
// using the type parameters used to generate it
struct ShaderPermutation {
char taskFile[32];
char vertexMeshFile[32];
char fragmentFile[32];
@@ -65,80 +57,50 @@ struct ShaderPermutation
uint8 positionOnly;
uint8 viewCulling;
uint8 visibilityPass;
//TODO: lightmapping etc
ShaderPermutation()
{
std::memset(this, 0, sizeof(ShaderPermutation));
}
void setTaskFile(std::string_view name)
{
// TODO: lightmapping etc
ShaderPermutation() { std::memset(this, 0, sizeof(ShaderPermutation)); }
void setTaskFile(std::string_view name) {
std::memset(taskFile, 0, sizeof(taskFile));
hasTaskShader = 1;
strncpy(taskFile, name.data(), sizeof(taskFile));
}
void setVertexFile(std::string_view name)
{
void setVertexFile(std::string_view name) {
std::memset(vertexMeshFile, 0, sizeof(vertexMeshFile));
useMeshShading = 0;
strncpy(vertexMeshFile, name.data(), sizeof(vertexMeshFile));
}
void setMeshFile(std::string_view name)
{
void setMeshFile(std::string_view name) {
std::memset(vertexMeshFile, 0, sizeof(vertexMeshFile));
useMeshShading = 1;
strncpy(vertexMeshFile, name.data(), sizeof(vertexMeshFile));
}
void setFragmentFile(std::string_view name)
{
void setFragmentFile(std::string_view name) {
std::memset(fragmentFile, 0, sizeof(fragmentFile));
hasFragment = 1;
strncpy(fragmentFile, name.data(), sizeof(fragmentFile));
}
void setVertexData(std::string_view name)
{
void setVertexData(std::string_view name) {
std::memset(vertexDataName, 0, sizeof(vertexDataName));
strncpy(vertexDataName, name.data(), sizeof(vertexDataName));
}
void setMaterial(std::string_view name)
{
void setMaterial(std::string_view name) {
std::memset(materialName, 0, sizeof(materialName));
useMaterial = 1;
strncpy(materialName, name.data(), sizeof(materialName));
}
void setPositionOnly(bool enable)
{
positionOnly = enable;
}
void setViewCulling(bool enable)
{
viewCulling = enable;
}
void setVisibilityPass(bool enable)
{
visibilityPass = enable;
}
void setPositionOnly(bool enable) { positionOnly = enable; }
void setViewCulling(bool enable) { viewCulling = enable; }
void setVisibilityPass(bool enable) { visibilityPass = enable; }
};
//Hashed ShaderPermutation for fast lookup
struct PermutationId
{
// 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 constexpr bool operator==(const PermutationId& lhs, const PermutationId& rhs)
{
return lhs.hash == rhs.hash;
}
friend constexpr auto operator<=>(const PermutationId& lhs, const PermutationId& rhs)
{
return lhs.hash <=> rhs.hash;
}
PermutationId() : hash(0) {}
PermutationId(ShaderPermutation permutation) : hash(CRC::Calculate(&permutation, sizeof(ShaderPermutation), CRC::CRC_32())) {}
friend constexpr bool operator==(const PermutationId& lhs, const PermutationId& rhs) { return lhs.hash == rhs.hash; }
friend constexpr auto operator<=>(const PermutationId& lhs, const PermutationId& rhs) { return lhs.hash <=> rhs.hash; }
};
struct ShaderCollection
{
struct ShaderCollection {
OPipelineLayout pipelineLayout;
OVertexShader vertexShader;
OTaskShader taskShader;
@@ -146,8 +108,7 @@ struct ShaderCollection
OFragmentShader fragmentShader;
};
struct PassConfig
{
struct PassConfig {
Gfx::PPipelineLayout baseLayout;
std::string taskFile = "";
std::string mainFile = "";
@@ -158,9 +119,8 @@ struct PassConfig
bool useMaterial = false;
bool useVisibility = false;
};
class ShaderCompiler
{
public:
class ShaderCompiler {
public:
ShaderCompiler(Gfx::PGraphics graphics);
~ShaderCompiler();
const ShaderCollection* findShaders(PermutationId id) const;
@@ -168,7 +128,8 @@ public:
void registerVertexData(VertexData* vertexData);
void registerRenderPass(std::string name, PassConfig config);
ShaderPermutation getTemplate(std::string name);
private:
private:
void compile();
void createShaders(ShaderPermutation permutation, OPipelineLayout layout);
std::mutex shadersLock;
@@ -179,5 +140,5 @@ private:
Gfx::PGraphics graphics;
};
DEFINE_REF(ShaderCompiler)
}
} // namespace Gfx
} // namespace Seele