Add ShaderBinding
This commit is contained in:
@@ -45,8 +45,8 @@
|
||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||
#include <Nazara/Renderer/RenderWindowImpl.hpp>
|
||||
#include <Nazara/Renderer/RenderWindowParameters.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||
#include <Nazara/Renderer/ShaderBinding.hpp>
|
||||
#include <Nazara/Renderer/ShaderBuilder.hpp>
|
||||
#include <Nazara/Renderer/ShaderStageImpl.hpp>
|
||||
#include <Nazara/Renderer/ShaderWriter.hpp>
|
||||
|
||||
@@ -27,11 +27,15 @@ namespace Nz
|
||||
std::vector<Binding> bindings;
|
||||
};
|
||||
|
||||
class ShaderBinding;
|
||||
|
||||
class NAZARA_RENDERER_API RenderPipelineLayout
|
||||
{
|
||||
public:
|
||||
RenderPipelineLayout() = default;
|
||||
virtual ~RenderPipelineLayout();
|
||||
|
||||
virtual ShaderBinding& AllocateShaderBinding() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADER_HPP
|
||||
#define NAZARA_SHADER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Color;
|
||||
class Shader;
|
||||
class ShaderStage;
|
||||
|
||||
using ShaderConstRef = ObjectRef<const Shader>;
|
||||
using ShaderLibrary = ObjectLibrary<Shader>;
|
||||
using ShaderRef = ObjectRef<Shader>;
|
||||
|
||||
class NAZARA_RENDERER_API Shader : public RefCounted
|
||||
{
|
||||
friend ShaderLibrary;
|
||||
friend class Renderer;
|
||||
|
||||
public:
|
||||
Shader();
|
||||
Shader(const Shader&) = delete;
|
||||
Shader(Shader&&) = delete;
|
||||
~Shader();
|
||||
|
||||
void AttachStage(ShaderStageType stage, const ShaderStage& shaderStage);
|
||||
bool AttachStageFromFile(ShaderStageType stage, const std::filesystem::path& filePath);
|
||||
bool AttachStageFromSource(ShaderStageType stage, const char* source, unsigned int length);
|
||||
bool AttachStageFromSource(ShaderStageType stage, const String& source);
|
||||
|
||||
void Bind() const;
|
||||
|
||||
bool Create();
|
||||
void Destroy();
|
||||
|
||||
ByteArray GetBinary() const;
|
||||
String GetLog() const;
|
||||
String GetSourceCode(ShaderStageType stage) const;
|
||||
int GetUniformLocation(const String& name) const;
|
||||
int GetUniformLocation(ShaderUniform shaderUniform) const;
|
||||
|
||||
bool HasStage(ShaderStageType stage) const;
|
||||
|
||||
bool IsBinaryRetrievable() const;
|
||||
bool IsLinked() const;
|
||||
bool IsValid() const;
|
||||
|
||||
bool Link();
|
||||
|
||||
bool LoadFromBinary(const void* buffer, unsigned int size);
|
||||
bool LoadFromBinary(const ByteArray& byteArray);
|
||||
|
||||
void SendBoolean(int location, bool value) const;
|
||||
void SendColor(int location, const Color& color) const;
|
||||
void SendDouble(int location, double value) const;
|
||||
void SendDoubleArray(int location, const double* values, unsigned int count) const;
|
||||
void SendFloat(int location, float value) const;
|
||||
void SendFloatArray(int location, const float* values, unsigned int count) const;
|
||||
void SendInteger(int location, int value) const;
|
||||
void SendIntegerArray(int location, const int* values, unsigned int count) const;
|
||||
void SendMatrix(int location, const Matrix4d& matrix) const;
|
||||
void SendMatrix(int location, const Matrix4f& matrix) const;
|
||||
void SendVector(int location, const Vector2d& vector) const;
|
||||
void SendVector(int location, const Vector2f& vector) const;
|
||||
void SendVector(int location, const Vector2i& vector) const;
|
||||
void SendVector(int location, const Vector3d& vector) const;
|
||||
void SendVector(int location, const Vector3f& vector) const;
|
||||
void SendVector(int location, const Vector3i& vector) const;
|
||||
void SendVector(int location, const Vector4d& vector) const;
|
||||
void SendVector(int location, const Vector4f& vector) const;
|
||||
void SendVector(int location, const Vector4i& vector) const;
|
||||
void SendVectorArray(int location, const Vector2d* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector2f* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector2i* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector3d* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector3f* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector3i* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector4d* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector4f* vectors, unsigned int count) const;
|
||||
void SendVectorArray(int location, const Vector4i* vectors, unsigned int count) const;
|
||||
|
||||
bool Validate() const;
|
||||
|
||||
// Fonctions OpenGL
|
||||
unsigned int GetOpenGLID() const;
|
||||
|
||||
Shader& operator=(const Shader&) = delete;
|
||||
Shader& operator=(Shader&&) = delete;
|
||||
|
||||
static bool IsStageSupported(ShaderStageType stage);
|
||||
template<typename... Args> static ShaderRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnShaderDestroy, const Shader* /*shader*/);
|
||||
NazaraSignal(OnShaderRelease, const Shader* /*shader*/);
|
||||
NazaraSignal(OnShaderUniformInvalidated, const Shader* /*shader*/);
|
||||
|
||||
private:
|
||||
bool PostLinkage();
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
std::vector<unsigned int> m_attachedShaders[ShaderStageType_Max+1];
|
||||
bool m_linked;
|
||||
int m_uniformLocations[ShaderUniform_Max+1];
|
||||
unsigned int m_program;
|
||||
|
||||
static ShaderLibrary::LibraryMap s_library;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/Shader.inl>
|
||||
|
||||
#endif // NAZARA_SHADER_HPP
|
||||
57
include/Nazara/Renderer/ShaderBinding.hpp
Normal file
57
include/Nazara/Renderer/ShaderBinding.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADERBINDING_HPP
|
||||
#define NAZARA_SHADERBINDING_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractBuffer;
|
||||
class Texture;
|
||||
class TextureSampler;
|
||||
|
||||
class NAZARA_RENDERER_API ShaderBinding
|
||||
{
|
||||
public:
|
||||
struct Binding;
|
||||
|
||||
ShaderBinding() = default;
|
||||
virtual ~ShaderBinding();
|
||||
|
||||
virtual void Update(std::initializer_list<Binding> bindings) = 0;
|
||||
|
||||
struct TextureBinding
|
||||
{
|
||||
Texture* texture;
|
||||
TextureSampler* sampler;
|
||||
};
|
||||
|
||||
struct UniformBufferBinding
|
||||
{
|
||||
AbstractBuffer* buffer;
|
||||
UInt64 offset;
|
||||
UInt64 range;
|
||||
};
|
||||
|
||||
struct Binding
|
||||
{
|
||||
std::size_t bindingIndex;
|
||||
std::variant<TextureBinding, UniformBufferBinding> content;
|
||||
};
|
||||
|
||||
protected:
|
||||
ShaderBinding(const ShaderBinding&) = delete;
|
||||
ShaderBinding(ShaderBinding&&) = default;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/ShaderBinding.inl>
|
||||
|
||||
#endif // NAZARA_SHADERBINDING_HPP
|
||||
12
include/Nazara/Renderer/ShaderBinding.inl
Normal file
12
include/Nazara/Renderer/ShaderBinding.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/ShaderBinding.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Renderer/DebugOff.hpp>
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <Nazara/VulkanRenderer/VulkanRenderer.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanRenderPipeline.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanRenderPipelineLayout.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanShaderBinding.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanShaderStage.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanSurface.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanTexture.hpp>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/RenderPipelineLayout.hpp>
|
||||
#include <Nazara/VulkanRenderer/Config.hpp>
|
||||
#include <Nazara/VulkanRenderer/VulkanShaderBinding.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DescriptorPool.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp>
|
||||
@@ -25,10 +26,12 @@ namespace Nz
|
||||
VulkanRenderPipelineLayout() = default;
|
||||
~VulkanRenderPipelineLayout() = default;
|
||||
|
||||
Vk::DescriptorSet AllocateDescriptorSet();
|
||||
VulkanShaderBinding& AllocateShaderBinding() override;
|
||||
|
||||
bool Create(Vk::Device& device, RenderPipelineLayoutInfo layoutInfo);
|
||||
|
||||
inline Vk::Device* GetDevice() const;
|
||||
|
||||
inline const Vk::DescriptorSetLayout& GetDescriptorSetLayout() const;
|
||||
inline const Vk::PipelineLayout& GetPipelineLayout() const;
|
||||
|
||||
@@ -36,6 +39,7 @@ namespace Nz
|
||||
struct DescriptorPool
|
||||
{
|
||||
Vk::DescriptorPool descriptorPool;
|
||||
std::vector<VulkanShaderBinding> allocatedSets;
|
||||
};
|
||||
|
||||
MovablePtr<Vk::Device> m_device;
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Vk::Device* VulkanRenderPipelineLayout::GetDevice() const
|
||||
{
|
||||
return m_device.Get();
|
||||
}
|
||||
|
||||
inline const Vk::DescriptorSetLayout& VulkanRenderPipelineLayout::GetDescriptorSetLayout() const
|
||||
{
|
||||
return m_descriptorSetLayout;
|
||||
|
||||
41
include/Nazara/VulkanRenderer/VulkanShaderBinding.hpp
Normal file
41
include/Nazara/VulkanRenderer/VulkanShaderBinding.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VULKANSHADERBINDING_HPP
|
||||
#define NAZARA_VULKANRENDERER_VULKANSHADERBINDING_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/ShaderBinding.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DescriptorSet.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class VulkanRenderPipelineLayout;
|
||||
|
||||
class NAZARA_VULKANRENDERER_API VulkanShaderBinding : public ShaderBinding
|
||||
{
|
||||
public:
|
||||
inline VulkanShaderBinding(VulkanRenderPipelineLayout& owner, Vk::DescriptorSet descriptorSet);
|
||||
VulkanShaderBinding(const VulkanShaderBinding&) = default;
|
||||
VulkanShaderBinding(VulkanShaderBinding&&) noexcept = default;
|
||||
~VulkanShaderBinding() = default;
|
||||
|
||||
inline Vk::DescriptorSet& GetDescriptorSet();
|
||||
|
||||
void Update(std::initializer_list<Binding> bindings) override;
|
||||
|
||||
VulkanShaderBinding& operator=(const VulkanShaderBinding&) = delete;
|
||||
VulkanShaderBinding& operator=(VulkanShaderBinding&&) = delete;
|
||||
|
||||
private:
|
||||
Vk::AutoDescriptorSet m_descriptorSet;
|
||||
VulkanRenderPipelineLayout& m_owner;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/VulkanShaderBinding.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VULKANSHADERBINDING_HPP
|
||||
22
include/Nazara/VulkanRenderer/VulkanShaderBinding.inl
Normal file
22
include/Nazara/VulkanRenderer/VulkanShaderBinding.inl
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/VulkanShaderBinding.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline VulkanShaderBinding::VulkanShaderBinding(VulkanRenderPipelineLayout& owner, Vk::DescriptorSet descriptorSet) :
|
||||
m_descriptorSet(std::move(descriptorSet)),
|
||||
m_owner(owner)
|
||||
{
|
||||
}
|
||||
|
||||
inline Vk::DescriptorSet& VulkanShaderBinding::GetDescriptorSet()
|
||||
{
|
||||
return m_descriptorSet;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user