2020-02-25 00:44:40 +01:00
|
|
|
#pragma once
|
2020-03-08 13:38:40 +01:00
|
|
|
#include "GraphicsEnums.h"
|
|
|
|
|
#include "Containers/Array.h"
|
2020-05-05 01:51:13 +02:00
|
|
|
#include "Containers/List.h"
|
|
|
|
|
#include "GraphicsInitializer.h"
|
2020-06-02 11:46:18 +02:00
|
|
|
#include "MeshBatch.h"
|
2020-08-06 00:54:43 +02:00
|
|
|
#include <boost/crc.hpp>
|
2020-10-29 02:22:01 +01:00
|
|
|
#include <functional>
|
2020-03-13 12:44:33 +01:00
|
|
|
|
2020-09-19 14:36:50 +02:00
|
|
|
|
2020-10-14 01:49:43 +02:00
|
|
|
#ifndef ENABLE_VALIDATION
|
|
|
|
|
#define ENABLE_VALIDATION 0
|
2020-03-13 12:44:33 +01:00
|
|
|
#endif
|
|
|
|
|
|
2020-02-25 00:44:40 +01:00
|
|
|
namespace Seele
|
|
|
|
|
{
|
2020-06-08 01:44:47 +02:00
|
|
|
struct VertexInputStream;
|
2020-09-19 14:36:50 +02:00
|
|
|
struct VertexStreamComponent;
|
|
|
|
|
class VertexInputType;
|
2020-10-03 11:00:10 +02:00
|
|
|
DECLARE_REF(Material)
|
2020-04-12 15:47:19 +02:00
|
|
|
namespace Gfx
|
|
|
|
|
{
|
2020-06-02 11:46:18 +02:00
|
|
|
DECLARE_REF(Graphics);
|
|
|
|
|
|
2020-04-12 15:47:19 +02:00
|
|
|
class SamplerState
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~SamplerState()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(SamplerState);
|
2020-05-05 01:51:13 +02:00
|
|
|
|
2020-08-06 00:54:43 +02:00
|
|
|
class Shader
|
|
|
|
|
{};
|
|
|
|
|
DEFINE_REF(Shader);
|
|
|
|
|
|
2020-05-05 01:51:13 +02:00
|
|
|
class VertexShader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
VertexShader() {}
|
|
|
|
|
virtual ~VertexShader() {}
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(VertexShader);
|
|
|
|
|
class ControlShader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ControlShader() {}
|
|
|
|
|
virtual ~ControlShader() {}
|
|
|
|
|
uint32 getNumPatches() const { return numPatchPoints; }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
uint32 numPatchPoints;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(ControlShader);
|
|
|
|
|
class EvaluationShader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
EvaluationShader() {}
|
|
|
|
|
virtual ~EvaluationShader() {}
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(EvaluationShader);
|
|
|
|
|
class GeometryShader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
GeometryShader() {}
|
|
|
|
|
virtual ~GeometryShader() {}
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(GeometryShader);
|
|
|
|
|
class FragmentShader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FragmentShader() {}
|
|
|
|
|
virtual ~FragmentShader() {}
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(FragmentShader);
|
2020-08-06 00:54:43 +02:00
|
|
|
|
|
|
|
|
//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()
|
|
|
|
|
{}
|
|
|
|
|
PermutationId(ShaderPermutation permutation)
|
|
|
|
|
{
|
|
|
|
|
boost::crc_32_type result;
|
|
|
|
|
result.process_bytes(&permutation, sizeof(ShaderPermutation));
|
|
|
|
|
hash = result.checksum();
|
|
|
|
|
}
|
|
|
|
|
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;
|
2020-09-19 14:36:50 +02:00
|
|
|
//PVertexDeclaration vertexDeclaration;
|
2020-08-06 00:54:43 +02:00
|
|
|
PVertexShader vertexShader;
|
|
|
|
|
PControlShader controlShader;
|
|
|
|
|
PEvaluationShader evalutionShader;
|
|
|
|
|
PGeometryShader geometryShader;
|
|
|
|
|
PFragmentShader fragmentShader;
|
|
|
|
|
};
|
|
|
|
|
class ShaderMap
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ShaderMap();
|
|
|
|
|
~ShaderMap();
|
|
|
|
|
const ShaderCollection* findShaders(PermutationId&& id) const;
|
|
|
|
|
ShaderCollection& createShaders(
|
|
|
|
|
PGraphics graphics,
|
|
|
|
|
RenderPassType passName,
|
|
|
|
|
PMaterial material,
|
2020-09-19 14:36:50 +02:00
|
|
|
VertexInputType* vertexInput,
|
2020-08-06 00:54:43 +02:00
|
|
|
bool bPositionOnly);
|
|
|
|
|
private:
|
|
|
|
|
Array<ShaderCollection> shaders;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(ShaderMap);
|
|
|
|
|
|
2020-05-05 01:51:13 +02:00
|
|
|
class ComputeShader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ComputeShader() {}
|
|
|
|
|
virtual ~ComputeShader() {}
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(ComputeShader);
|
|
|
|
|
|
2020-04-12 15:47:19 +02:00
|
|
|
class DescriptorBinding
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DescriptorBinding()
|
|
|
|
|
: binding(0), descriptorType(SE_DESCRIPTOR_TYPE_MAX_ENUM), descriptorCount(0x7fff), shaderStages(SE_SHADER_STAGE_ALL)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
DescriptorBinding(const DescriptorBinding &other)
|
|
|
|
|
: binding(other.binding), descriptorType(other.descriptorType), descriptorCount(other.descriptorCount), shaderStages(other.shaderStages)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
void operator=(const DescriptorBinding &other)
|
|
|
|
|
{
|
|
|
|
|
binding = other.binding;
|
|
|
|
|
descriptorType = other.descriptorType;
|
|
|
|
|
descriptorCount = other.descriptorCount;
|
|
|
|
|
shaderStages = other.shaderStages;
|
|
|
|
|
}
|
|
|
|
|
uint32_t binding;
|
|
|
|
|
SeDescriptorType descriptorType;
|
|
|
|
|
uint32_t descriptorCount;
|
|
|
|
|
SeShaderStageFlags shaderStages;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(DescriptorBinding);
|
|
|
|
|
|
|
|
|
|
DECLARE_REF(DescriptorSet);
|
|
|
|
|
class DescriptorAllocator
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DescriptorAllocator() {}
|
|
|
|
|
virtual ~DescriptorAllocator() {}
|
|
|
|
|
virtual void allocateDescriptorSet(PDescriptorSet &descriptorSet) = 0;
|
2020-10-03 11:00:10 +02:00
|
|
|
virtual void reset() = 0;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(DescriptorAllocator);
|
|
|
|
|
DECLARE_REF(UniformBuffer);
|
|
|
|
|
DECLARE_REF(StructuredBuffer);
|
|
|
|
|
DECLARE_REF(Texture);
|
|
|
|
|
class DescriptorSet
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~DescriptorSet() {}
|
|
|
|
|
virtual void writeChanges() = 0;
|
|
|
|
|
virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0;
|
|
|
|
|
virtual void updateBuffer(uint32 binding, PStructuredBuffer structuredBuffer) = 0;
|
|
|
|
|
virtual void updateSampler(uint32 binding, PSamplerState samplerState) = 0;
|
|
|
|
|
virtual void updateTexture(uint32 binding, PTexture texture, PSamplerState samplerState = nullptr) = 0;
|
|
|
|
|
virtual bool operator<(PDescriptorSet other) = 0;
|
2020-05-05 01:51:13 +02:00
|
|
|
|
|
|
|
|
virtual uint32 getSetIndex() const = 0;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(DescriptorSet);
|
|
|
|
|
|
|
|
|
|
class DescriptorLayout
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-05-05 01:51:13 +02:00
|
|
|
DescriptorLayout()
|
|
|
|
|
: setIndex(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-04-12 15:47:19 +02:00
|
|
|
virtual ~DescriptorLayout() {}
|
|
|
|
|
void operator=(const DescriptorLayout &other)
|
|
|
|
|
{
|
|
|
|
|
descriptorBindings.resize(other.descriptorBindings.size());
|
|
|
|
|
std::memcpy(descriptorBindings.data(), other.descriptorBindings.data(), sizeof(DescriptorLayout) * descriptorBindings.size());
|
|
|
|
|
}
|
|
|
|
|
virtual void create() = 0;
|
|
|
|
|
virtual void addDescriptorBinding(uint32 binding, SeDescriptorType type, uint32 arrayCount = 1);
|
2020-10-03 11:00:10 +02:00
|
|
|
virtual void reset();
|
2020-04-12 15:47:19 +02:00
|
|
|
virtual PDescriptorSet allocatedDescriptorSet();
|
|
|
|
|
const Array<DescriptorBinding> &getBindings() const { return descriptorBindings; }
|
2020-05-05 01:51:13 +02:00
|
|
|
inline uint32 getSetIndex() const { return setIndex; }
|
2020-04-12 15:47:19 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
Array<DescriptorBinding> descriptorBindings;
|
|
|
|
|
PDescriptorAllocator allocator;
|
2020-05-05 01:51:13 +02:00
|
|
|
uint32 setIndex;
|
2020-04-12 15:47:19 +02:00
|
|
|
friend class PipelineLayout;
|
|
|
|
|
friend class DescriptorAllocator;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(DescriptorLayout);
|
|
|
|
|
class PipelineLayout
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
PipelineLayout() {}
|
|
|
|
|
virtual ~PipelineLayout() {}
|
|
|
|
|
virtual void create() = 0;
|
2020-06-02 11:46:18 +02:00
|
|
|
virtual void reset() = 0;
|
2020-04-12 15:47:19 +02:00
|
|
|
void addDescriptorLayout(uint32 setIndex, PDescriptorLayout layout);
|
|
|
|
|
void addPushConstants(const SePushConstantRange &pushConstants);
|
|
|
|
|
virtual uint32 getHash() const = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
Array<PDescriptorLayout> descriptorSetLayouts;
|
|
|
|
|
Array<SePushConstantRange> pushConstants;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(PipelineLayout);
|
2020-06-02 11:46:18 +02:00
|
|
|
|
|
|
|
|
struct QueueFamilyMapping
|
|
|
|
|
{
|
|
|
|
|
uint32 graphicsFamily;
|
|
|
|
|
uint32 computeFamily;
|
|
|
|
|
uint32 transferFamily;
|
|
|
|
|
uint32 dedicatedTransferFamily;
|
|
|
|
|
uint32 getQueueTypeFamilyIndex(Gfx::QueueType type) const
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case Gfx::QueueType::GRAPHICS:
|
|
|
|
|
return graphicsFamily;
|
|
|
|
|
case Gfx::QueueType::COMPUTE:
|
|
|
|
|
return computeFamily;
|
|
|
|
|
case Gfx::QueueType::TRANSFER:
|
|
|
|
|
return transferFamily;
|
|
|
|
|
case Gfx::QueueType::DEDICATED_TRANSFER:
|
|
|
|
|
return dedicatedTransferFamily;
|
|
|
|
|
default:
|
|
|
|
|
return 0x7fff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool needsTransfer(Gfx::QueueType src, Gfx::QueueType dst) const
|
|
|
|
|
{
|
|
|
|
|
uint32 srcIndex = getQueueTypeFamilyIndex(src);
|
|
|
|
|
uint32 dstIndex = getQueueTypeFamilyIndex(dst);
|
|
|
|
|
return srcIndex != dstIndex;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QueueOwnedResource
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2020-09-19 14:36:50 +02:00
|
|
|
QueueOwnedResource(QueueFamilyMapping mapping, QueueType startQueueType);
|
2020-06-02 11:46:18 +02:00
|
|
|
virtual ~QueueOwnedResource();
|
|
|
|
|
|
|
|
|
|
//Preliminary checks to see if the barrier should be executed at all
|
|
|
|
|
void transferOwnership(QueueType newOwner);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
|
|
|
|
Gfx::QueueType currentOwner;
|
2020-09-19 14:36:50 +02:00
|
|
|
QueueFamilyMapping mapping;
|
2020-06-02 11:46:18 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(QueueOwnedResource);
|
|
|
|
|
|
2020-09-19 14:36:50 +02:00
|
|
|
// IMPORTANT!!
|
|
|
|
|
// WHEN DERIVING FROM ANY Gfx:: BASE CLASSES WITH MULTIPLE INHERITANCE
|
|
|
|
|
// ALWAYS PUT THE Gfx:: BASE CLASS FIRST
|
|
|
|
|
// This is because the refcounting object is unique per allocation, so
|
|
|
|
|
// the base address of both the Gfx:: and the implementation class
|
|
|
|
|
// need to match for it to work
|
2020-06-02 11:46:18 +02:00
|
|
|
class Buffer : public QueueOwnedResource
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-09-19 14:36:50 +02:00
|
|
|
Buffer(QueueFamilyMapping mapping, QueueType startQueueType);
|
2020-06-02 11:46:18 +02:00
|
|
|
virtual ~Buffer();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
// Inherited via QueueOwnedResource
|
|
|
|
|
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class UniformBuffer : public Buffer
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-10-03 11:00:10 +02:00
|
|
|
UniformBuffer(QueueFamilyMapping mapping, const BulkResourceData& resourceData);
|
2020-04-12 15:47:19 +02:00
|
|
|
virtual ~UniformBuffer();
|
2020-10-03 11:00:10 +02:00
|
|
|
virtual void updateContents(const BulkResourceData& resourceData);
|
|
|
|
|
bool isDataEquals(UniformBuffer* other)
|
|
|
|
|
{
|
|
|
|
|
if(other == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(size != other->size)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if(std::memcmp(contents, other->contents, size) != 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-06-02 11:46:18 +02:00
|
|
|
protected:
|
2020-10-03 11:00:10 +02:00
|
|
|
void* contents;
|
|
|
|
|
uint32 size;
|
2020-06-02 11:46:18 +02:00
|
|
|
// Inherited via QueueOwnedResource
|
|
|
|
|
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(UniformBuffer);
|
2020-06-02 11:46:18 +02:00
|
|
|
|
|
|
|
|
class VertexBuffer : public Buffer
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2020-09-19 14:36:50 +02:00
|
|
|
VertexBuffer(QueueFamilyMapping mapping, uint32 numVertices, uint32 vertexSize, QueueType startQueueType);
|
2020-05-05 01:51:13 +02:00
|
|
|
virtual ~VertexBuffer();
|
|
|
|
|
inline uint32 getNumVertices()
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
2020-05-05 01:51:13 +02:00
|
|
|
return numVertices;
|
2020-04-12 15:47:19 +02:00
|
|
|
}
|
2020-05-05 01:51:13 +02:00
|
|
|
// Size of one vertex in bytes
|
|
|
|
|
inline uint32 getVertexSize()
|
|
|
|
|
{
|
|
|
|
|
return vertexSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2020-06-02 11:46:18 +02:00
|
|
|
// Inherited via QueueOwnedResource
|
|
|
|
|
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
2020-05-05 01:51:13 +02:00
|
|
|
uint32 numVertices;
|
|
|
|
|
uint32 vertexSize;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(VertexBuffer);
|
2020-06-02 11:46:18 +02:00
|
|
|
|
|
|
|
|
class IndexBuffer : public Buffer
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2020-09-19 14:36:50 +02:00
|
|
|
IndexBuffer(QueueFamilyMapping mapping, uint32 size, Gfx::SeIndexType index, QueueType startQueueType);
|
2020-05-05 01:51:13 +02:00
|
|
|
virtual ~IndexBuffer();
|
|
|
|
|
inline uint32 getNumIndices() const
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
2020-05-05 01:51:13 +02:00
|
|
|
return numIndices;
|
2020-04-12 15:47:19 +02:00
|
|
|
}
|
2020-05-05 01:51:13 +02:00
|
|
|
inline Gfx::SeIndexType getIndexType() const
|
|
|
|
|
{
|
|
|
|
|
return indexType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2020-06-02 11:46:18 +02:00
|
|
|
// Inherited via QueueOwnedResource
|
|
|
|
|
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
2020-05-05 01:51:13 +02:00
|
|
|
Gfx::SeIndexType indexType;
|
|
|
|
|
uint32 numIndices;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(IndexBuffer);
|
2020-06-02 11:46:18 +02:00
|
|
|
|
|
|
|
|
class StructuredBuffer : public Buffer
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2020-09-19 14:36:50 +02:00
|
|
|
StructuredBuffer(QueueFamilyMapping mapping, QueueType startQueueType);
|
2020-06-02 11:46:18 +02:00
|
|
|
virtual ~StructuredBuffer();
|
|
|
|
|
protected:
|
|
|
|
|
// Inherited via QueueOwnedResource
|
|
|
|
|
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(StructuredBuffer);
|
2020-06-02 11:46:18 +02:00
|
|
|
|
2020-05-05 01:51:13 +02:00
|
|
|
class VertexStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-06-08 01:44:47 +02:00
|
|
|
VertexStream();
|
2020-09-19 14:36:50 +02:00
|
|
|
VertexStream(uint32 stride, uint32 offset, uint8 instanced);
|
2020-05-05 01:51:13 +02:00
|
|
|
~VertexStream();
|
|
|
|
|
void addVertexElement(VertexElement element);
|
|
|
|
|
const Array<VertexElement> getVertexDescriptions() const;
|
|
|
|
|
inline uint8 isInstanced() const { return instanced; }
|
|
|
|
|
|
2020-06-02 11:46:18 +02:00
|
|
|
uint32 stride;
|
|
|
|
|
uint32 offset;
|
2020-05-05 01:51:13 +02:00
|
|
|
Array<VertexElement> vertexDescription;
|
|
|
|
|
uint8 instanced;
|
|
|
|
|
};
|
2020-06-02 11:46:18 +02:00
|
|
|
DEFINE_REF(VertexStream);
|
2020-05-05 01:51:13 +02:00
|
|
|
class VertexDeclaration
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
VertexDeclaration();
|
|
|
|
|
~VertexDeclaration();
|
|
|
|
|
|
2020-10-03 11:00:10 +02:00
|
|
|
static PVertexDeclaration createDeclaration(PGraphics graphics, const Array<VertexElement>& elementList);
|
2020-05-05 01:51:13 +02:00
|
|
|
private:
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(VertexDeclaration);
|
|
|
|
|
class GraphicsPipeline
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-06-02 11:46:18 +02:00
|
|
|
GraphicsPipeline(const GraphicsPipelineCreateInfo& createInfo, PPipelineLayout layout) : createInfo(createInfo) , layout(layout) {}
|
2020-05-05 01:51:13 +02:00
|
|
|
virtual ~GraphicsPipeline(){}
|
|
|
|
|
const GraphicsPipelineCreateInfo& getCreateInfo() const {return createInfo;}
|
2020-06-02 11:46:18 +02:00
|
|
|
PPipelineLayout getPipelineLayout() const { return layout; }
|
2020-05-05 01:51:13 +02:00
|
|
|
protected:
|
2020-06-02 11:46:18 +02:00
|
|
|
PPipelineLayout layout;
|
2020-05-05 01:51:13 +02:00
|
|
|
GraphicsPipelineCreateInfo createInfo;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(GraphicsPipeline);
|
2020-09-19 14:36:50 +02:00
|
|
|
|
|
|
|
|
// IMPORTANT!!
|
|
|
|
|
// WHEN DERIVING FROM ANY Gfx:: BASE CLASSES WITH MULTIPLE INHERITANCE
|
|
|
|
|
// ALWAYS PUT THE Gfx:: BASE CLASS FIRST
|
|
|
|
|
// This is because the refcounting object is unique per allocation, so
|
|
|
|
|
// the base address of both the Gfx:: and the implementation class
|
|
|
|
|
// need to match for it to work
|
2020-06-02 11:46:18 +02:00
|
|
|
class Texture : public QueueOwnedResource
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2020-09-19 14:36:50 +02:00
|
|
|
Texture(QueueFamilyMapping mapping, QueueType startQueueType);
|
2020-06-02 11:46:18 +02:00
|
|
|
virtual ~Texture();
|
2020-08-11 21:23:20 +02:00
|
|
|
|
|
|
|
|
virtual SeFormat getFormat() const = 0;
|
|
|
|
|
virtual uint32 getSizeX() const = 0;
|
|
|
|
|
virtual uint32 getSizeY() const = 0;
|
|
|
|
|
virtual SeSampleCountFlags getNumSamples() const = 0;
|
2020-10-03 11:00:10 +02:00
|
|
|
virtual class Texture2D* getTexture2D() { return nullptr; }
|
2020-06-02 11:46:18 +02:00
|
|
|
protected:
|
|
|
|
|
// Inherited via QueueOwnedResource
|
|
|
|
|
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(Texture);
|
|
|
|
|
class Texture2D : public Texture
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-09-19 14:36:50 +02:00
|
|
|
Texture2D(QueueFamilyMapping mapping, QueueType startQueueType);
|
2020-06-02 11:46:18 +02:00
|
|
|
virtual ~Texture2D();
|
2020-08-11 21:23:20 +02:00
|
|
|
|
|
|
|
|
virtual SeFormat getFormat() const = 0;
|
|
|
|
|
virtual uint32 getSizeX() const = 0;
|
|
|
|
|
virtual uint32 getSizeY() const = 0;
|
|
|
|
|
virtual SeSampleCountFlags getNumSamples() const = 0;
|
2020-10-03 11:00:10 +02:00
|
|
|
virtual class Texture2D* getTexture2D() { return this; }
|
2020-06-02 11:46:18 +02:00
|
|
|
protected:
|
|
|
|
|
//Inherited via QueueOwnedResource
|
|
|
|
|
virtual void executeOwnershipBarrier(QueueType newOwner) = 0;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(Texture2D);
|
|
|
|
|
|
2020-10-03 11:00:10 +02:00
|
|
|
DECLARE_REF(Viewport);
|
2020-05-05 01:51:13 +02:00
|
|
|
class RenderCommand
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-06-02 11:46:18 +02:00
|
|
|
RenderCommand();
|
|
|
|
|
virtual ~RenderCommand();
|
2020-10-30 18:45:35 +01:00
|
|
|
virtual void begin() = 0;
|
2020-10-03 11:00:10 +02:00
|
|
|
virtual void setViewport(Gfx::PViewport viewport) = 0;
|
2020-05-05 01:51:13 +02:00
|
|
|
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) = 0;
|
|
|
|
|
virtual void bindDescriptor(Gfx::PDescriptorSet set) = 0;
|
2020-10-14 01:49:43 +02:00
|
|
|
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) = 0;
|
2020-06-08 01:44:47 +02:00
|
|
|
virtual void bindVertexBuffer(const Array<VertexInputStream>& streams) = 0;
|
2020-05-05 01:51:13 +02:00
|
|
|
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0;
|
2020-06-02 11:46:18 +02:00
|
|
|
virtual void draw(const MeshBatchElement& data) = 0;
|
2020-05-05 01:51:13 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(RenderCommand);
|
|
|
|
|
|
2020-04-12 15:47:19 +02:00
|
|
|
class Window
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Window(const WindowCreateInfo &createInfo);
|
|
|
|
|
virtual ~Window();
|
|
|
|
|
virtual void beginFrame() = 0;
|
|
|
|
|
virtual void endFrame() = 0;
|
|
|
|
|
virtual void onWindowCloseEvent() = 0;
|
|
|
|
|
virtual PTexture2D getBackBuffer() = 0;
|
2020-11-03 01:18:30 +01:00
|
|
|
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) = 0;
|
|
|
|
|
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) = 0;
|
|
|
|
|
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) = 0;
|
2021-01-19 15:30:00 +01:00
|
|
|
virtual void setScrollCallback(std::function<void(double, double)> callback) = 0;
|
|
|
|
|
virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0;
|
2020-08-11 21:23:20 +02:00
|
|
|
SeFormat getSwapchainFormat() const
|
|
|
|
|
{
|
|
|
|
|
return pixelFormat;
|
|
|
|
|
}
|
|
|
|
|
SeSampleCountFlags getNumSamples() const
|
|
|
|
|
{
|
|
|
|
|
return samples;
|
|
|
|
|
}
|
2020-04-12 15:47:19 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
uint32 sizeX;
|
|
|
|
|
uint32 sizeY;
|
|
|
|
|
bool bFullscreen;
|
|
|
|
|
const char *title;
|
|
|
|
|
SeFormat pixelFormat;
|
2020-08-11 21:23:20 +02:00
|
|
|
uint32 samples;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(Window);
|
|
|
|
|
|
|
|
|
|
class Viewport
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Viewport(PWindow owner, const ViewportCreateInfo &createInfo);
|
|
|
|
|
virtual ~Viewport();
|
2020-04-15 02:03:56 +02:00
|
|
|
virtual void resize(uint32 newX, uint32 newY) = 0;
|
|
|
|
|
virtual void move(uint32 newOffsetX, uint32 newOffsetY) = 0;
|
2020-08-06 00:54:43 +02:00
|
|
|
inline PWindow getOwner() const {return owner;}
|
|
|
|
|
inline uint32 getSizeX() const {return sizeX;}
|
|
|
|
|
inline uint32 getSizeY() const {return sizeY;}
|
|
|
|
|
inline uint32 getOffsetX() const {return offsetX;}
|
|
|
|
|
inline uint32 getOffsetY() const {return offsetY;}
|
2020-04-12 15:47:19 +02:00
|
|
|
protected:
|
|
|
|
|
uint32 sizeX;
|
|
|
|
|
uint32 sizeY;
|
|
|
|
|
uint32 offsetX;
|
|
|
|
|
uint32 offsetY;
|
|
|
|
|
PWindow owner;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(Viewport);
|
|
|
|
|
|
|
|
|
|
class RenderTargetAttachment
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
RenderTargetAttachment(PTexture2D texture,
|
|
|
|
|
SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD,
|
|
|
|
|
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
|
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
|
|
|
|
|
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE)
|
|
|
|
|
: texture(texture), loadOp(loadOp), storeOp(storeOp), stencilLoadOp(stencilLoadOp), stencilStoreOp(stencilStoreOp)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
virtual ~RenderTargetAttachment()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
virtual PTexture2D getTexture()
|
|
|
|
|
{
|
|
|
|
|
return texture;
|
|
|
|
|
}
|
2020-08-11 21:23:20 +02:00
|
|
|
virtual SeFormat getFormat() const
|
|
|
|
|
{
|
|
|
|
|
return texture->getFormat();
|
|
|
|
|
}
|
|
|
|
|
virtual SeSampleCountFlags getNumSamples() const
|
|
|
|
|
{
|
|
|
|
|
return texture->getNumSamples();
|
|
|
|
|
}
|
2020-04-12 15:47:19 +02:00
|
|
|
inline SeAttachmentLoadOp getLoadOp() const { return loadOp; }
|
|
|
|
|
inline SeAttachmentStoreOp getStoreOp() const { return storeOp; }
|
|
|
|
|
inline SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; }
|
|
|
|
|
inline SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; }
|
2020-10-23 01:47:56 +02:00
|
|
|
SeClearValue clear;
|
|
|
|
|
SeColorComponentFlags componentFlags;
|
2020-04-12 15:47:19 +02:00
|
|
|
protected:
|
|
|
|
|
PTexture2D texture;
|
|
|
|
|
SeAttachmentLoadOp loadOp;
|
|
|
|
|
SeAttachmentStoreOp storeOp;
|
|
|
|
|
SeAttachmentLoadOp stencilLoadOp;
|
|
|
|
|
SeAttachmentStoreOp stencilStoreOp;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(RenderTargetAttachment);
|
|
|
|
|
|
|
|
|
|
class SwapchainAttachment : public RenderTargetAttachment
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SwapchainAttachment(PWindow owner,
|
2020-10-30 18:45:35 +01:00
|
|
|
SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_CLEAR,
|
2020-04-12 15:47:19 +02:00
|
|
|
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
|
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
|
|
|
|
|
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE)
|
2020-08-11 21:23:20 +02:00
|
|
|
: RenderTargetAttachment(nullptr, loadOp, storeOp, stencilLoadOp, stencilStoreOp), owner(owner)
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
2020-10-23 01:47:56 +02:00
|
|
|
clear.color.float32[0] = 0.0f;
|
|
|
|
|
clear.color.float32[1] = 0.0f;
|
|
|
|
|
clear.color.float32[2] = 0.0f;
|
2020-10-30 18:45:35 +01:00
|
|
|
clear.color.float32[3] = 1.0f;
|
2020-10-23 01:47:56 +02:00
|
|
|
componentFlags = SE_COLOR_COMPONENT_R_BIT | SE_COLOR_COMPONENT_G_BIT | SE_COLOR_COMPONENT_B_BIT | SE_COLOR_COMPONENT_A_BIT;
|
2020-04-12 15:47:19 +02:00
|
|
|
}
|
|
|
|
|
virtual PTexture2D getTexture() override
|
|
|
|
|
{
|
|
|
|
|
return owner->getBackBuffer();
|
2020-08-11 21:23:20 +02:00
|
|
|
}
|
|
|
|
|
virtual SeFormat getFormat() const override
|
|
|
|
|
{
|
|
|
|
|
return owner->getSwapchainFormat();
|
|
|
|
|
}
|
|
|
|
|
virtual SeSampleCountFlags getNumSamples() const override
|
|
|
|
|
{
|
|
|
|
|
return owner->getNumSamples();
|
2020-04-12 15:47:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
PWindow owner;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(SwapchainAttachment);
|
|
|
|
|
|
|
|
|
|
class RenderTargetLayout
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
RenderTargetLayout();
|
|
|
|
|
RenderTargetLayout(PRenderTargetAttachment depthAttachment);
|
|
|
|
|
RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment);
|
|
|
|
|
RenderTargetLayout(Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachmet);
|
|
|
|
|
RenderTargetLayout(Array<PRenderTargetAttachment> inputAttachments, Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment);
|
|
|
|
|
Array<PRenderTargetAttachment> inputAttachments;
|
|
|
|
|
Array<PRenderTargetAttachment> colorAttachments;
|
|
|
|
|
PRenderTargetAttachment depthAttachment;
|
2020-10-03 11:00:10 +02:00
|
|
|
uint32 width;
|
|
|
|
|
uint32 height;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(RenderTargetLayout);
|
|
|
|
|
|
|
|
|
|
class RenderPass
|
|
|
|
|
{
|
|
|
|
|
public:
|
2020-05-05 01:51:13 +02:00
|
|
|
RenderPass(PRenderTargetLayout layout) : layout(layout) {}
|
|
|
|
|
virtual ~RenderPass() {}
|
|
|
|
|
inline PRenderTargetLayout getLayout() const { return layout; }
|
2020-04-12 15:47:19 +02:00
|
|
|
|
2020-05-05 01:51:13 +02:00
|
|
|
protected:
|
|
|
|
|
PRenderTargetLayout layout;
|
|
|
|
|
};
|
2020-04-12 15:47:19 +02:00
|
|
|
DEFINE_REF(RenderPass);
|
|
|
|
|
} // namespace Gfx
|
|
|
|
|
} // namespace Seele
|