OpenGL: Implement commands buffers
This commit is contained in:
@@ -8,22 +8,138 @@
|
||||
#define NAZARA_OPENGLRENDERER_OPENGLCOMMANDBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Renderer/CommandBuffer.hpp>
|
||||
#include <Nazara/Renderer/CommandBufferBuilder.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Config.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLBuffer.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLRenderPipeline.hpp>
|
||||
#include <Nazara/OpenGLRenderer/OpenGLShaderBinding.hpp>
|
||||
#include <optional>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class OpenGLFramebuffer;
|
||||
|
||||
class NAZARA_OPENGLRENDERER_API OpenGLCommandBuffer final : public CommandBuffer
|
||||
{
|
||||
public:
|
||||
inline OpenGLCommandBuffer();
|
||||
OpenGLCommandBuffer() = default;
|
||||
OpenGLCommandBuffer(const OpenGLCommandBuffer&) = delete;
|
||||
OpenGLCommandBuffer(OpenGLCommandBuffer&&) noexcept = default;
|
||||
~OpenGLCommandBuffer() = default;
|
||||
|
||||
inline void BeginDebugRegion(const std::string_view& regionName, const Nz::Color& color);
|
||||
|
||||
inline void BindIndexBuffer(GLuint indexBuffer, UInt64 offset = 0);
|
||||
inline void BindPipeline(const OpenGLRenderPipeline* pipeline);
|
||||
inline void BindShaderBinding(const OpenGLShaderBinding* binding);
|
||||
inline void BindVertexBuffer(UInt32 binding, GLuint vertexBuffer, UInt64 offset = 0);
|
||||
|
||||
inline void CopyBuffer(GLuint source, GLuint target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0);
|
||||
inline void CopyBuffer(const UploadPool::Allocation& allocation, GLuint target, UInt64 size, UInt64 sourceOffset = 0, UInt64 targetOffset = 0);
|
||||
|
||||
inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
|
||||
inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
|
||||
|
||||
inline void EndDebugRegion();
|
||||
|
||||
void Execute();
|
||||
|
||||
inline void SetFramebuffer(const OpenGLFramebuffer& framebuffer, const RenderPass& renderPass, std::initializer_list<CommandBufferBuilder::ClearValues> clearValues);
|
||||
inline void SetScissor(Nz::Recti scissorRegion);
|
||||
inline void SetViewport(Nz::Recti viewportRegion);
|
||||
|
||||
OpenGLCommandBuffer& operator=(const OpenGLCommandBuffer&) = delete;
|
||||
OpenGLCommandBuffer& operator=(OpenGLCommandBuffer&&) = delete;
|
||||
|
||||
private:
|
||||
struct DrawStates;
|
||||
|
||||
void ApplyStates(const GL::Context& context, const DrawStates& states);
|
||||
|
||||
struct BeginDebugRegionData
|
||||
{
|
||||
std::string regionName;
|
||||
Nz::Color color;
|
||||
};
|
||||
|
||||
struct CopyBufferData
|
||||
{
|
||||
GLuint source;
|
||||
GLuint target;
|
||||
UInt64 size;
|
||||
UInt64 sourceOffset;
|
||||
UInt64 targetOffset;
|
||||
};
|
||||
|
||||
struct CopyBufferFromMemoryData
|
||||
{
|
||||
const void* memory;
|
||||
GLuint target;
|
||||
UInt64 size;
|
||||
UInt64 targetOffset;
|
||||
};
|
||||
|
||||
struct DrawStates
|
||||
{
|
||||
struct VertexBuffer
|
||||
{
|
||||
GLuint vertexBuffer = 0;
|
||||
UInt64 offset;
|
||||
};
|
||||
|
||||
GLuint indexBuffer = 0;
|
||||
const OpenGLRenderPipeline* pipeline = nullptr;
|
||||
const OpenGLShaderBinding* shaderBindings = nullptr;
|
||||
UInt64 indexBufferOffset;
|
||||
std::optional<Nz::Recti> scissorRegion;
|
||||
std::optional<Nz::Recti> viewportRegion;
|
||||
std::vector<VertexBuffer> vertexBuffers;
|
||||
};
|
||||
|
||||
struct DrawData
|
||||
{
|
||||
DrawStates states;
|
||||
UInt32 firstInstance;
|
||||
UInt32 firstVertex;
|
||||
UInt32 instanceCount;
|
||||
UInt32 vertexCount;
|
||||
};
|
||||
|
||||
struct DrawIndexedData
|
||||
{
|
||||
DrawStates states;
|
||||
UInt32 firstInstance;
|
||||
UInt32 firstVertex;
|
||||
UInt32 indexCount;
|
||||
UInt32 instanceCount;
|
||||
};
|
||||
|
||||
struct EndDebugRegionData
|
||||
{
|
||||
};
|
||||
|
||||
struct SetFrameBufferData
|
||||
{
|
||||
const OpenGLFramebuffer* framebuffer;
|
||||
};
|
||||
|
||||
using CommandData = std::variant<
|
||||
BeginDebugRegionData,
|
||||
CopyBufferData,
|
||||
CopyBufferFromMemoryData,
|
||||
DrawData,
|
||||
DrawIndexedData,
|
||||
EndDebugRegionData,
|
||||
SetFrameBufferData
|
||||
>;
|
||||
|
||||
DrawStates m_currentStates;
|
||||
std::vector<CommandData> m_commands;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user