Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (C) 2019 Arthur LAURENT <arthur.laurent4@gmail.com>
- // This file is subject to the license terms in the LICENSE file
- // found in the top-level of this distribution
- #pragma once
- #include <storm/core/Platform.hpp>
- #ifdef STORM_COMPILER_MSVC
- #pragma warning(push)
- #pragma warning(disable:4251)
- #endif
- #include <gsl/string_span>
- #include <queue>
- #include <storm/core/NonCopyable.hpp>
- #include <storm/render/core/Command.hpp>
- #include <storm/render/core/Enums.hpp>
- #include <storm/render/core/Fwd.hpp>
- #include <storm/render/pipeline/GraphicsPipeline.hpp>
- namespace storm::render {
- class STORM_PUBLIC CommandBuffer : public core::NonCopyable {
- public:
- enum class State { Initial, Recording, Executable };
- virtual ~CommandBuffer() = 0;
- CommandBuffer(CommandBuffer &&) ;
- CommandBuffer &operator=(CommandBuffer &&) ;
- virtual void reset() noexcept = 0;
- virtual void build() noexcept = 0;
- inline State state() const noexcept { return m_state; }
- template<typename CommandT>
- inline void add(CommandT &&command) {
- Expects(m_state == State::Initial || m_state == State::Recording);
- if(m_state == State::Initial) m_state = State::Recording;
- m_commands.emplace(std::forward<CommandT>(command));
- }
- template<typename CommandT, typename... Args>
- inline void add(Args &&... args) {
- Expects(m_state == State::Initial || m_state == State::Recording);
- if(m_state == State::Initial) m_state = State::Recording;
- m_commands.emplace(CommandT{std::forward<Args>(args)...});
- }
- inline void begin(
- bool one_time_submit = false,
- std::optional<CommandBufferCRef> parent = std::nullopt) {
- add<BeginCommand>(one_time_submit, parent);
- }
- inline void end() { add<EndCommand>(); }
- inline void beginRenderPass(
- const RenderPass &render_pass,
- const Framebuffer &framebuffer,
- core::RGBColorF clear_color = core::RGBColorDef::Black,
- float depth_color = 1.f,
- std::uint32_t stencil_value = 0u) {
- add<BeginRenderPassCommand>(
- render_pass, framebuffer, std::move(clear_color), depth_color, stencil_value);
- }
- inline void endRenderPass() { add<EndRenderPassCommand>(); }
- inline void bindGraphicsPipeline(const GraphicsPipeline &pipeline) {
- add<BindGraphicsPipelineCommand>(pipeline);
- }
- inline void draw(
- std::uint32_t vertex_count,
- std::uint32_t instance_count = 1u,
- std::uint32_t first_vertex = 0,
- std::uint32_t first_instance = 0) {
- add<DrawCommand>(vertex_count, instance_count, first_vertex, first_instance);
- }
- inline void drawIndexed(
- std::uint32_t index_count,
- std::uint32_t instance_count = 1u,
- std::uint32_t first_index = 0u,
- std::int32_t vertex_offset = 0,
- std::uint32_t first_instance = 0u) {
- add<DrawIndexedCommand>(
- index_count, instance_count, first_index, vertex_offset, first_instance);
- }
- inline void bindVertexBuffers(
- std::vector<HardwareBufferCRef> buffers,
- std::vector<std::ptrdiff_t> offsets) {
- add<BindVertexBuffersCommand>(std::move(buffers), std::move(offsets));
- }
- inline void bindIndexBuffer(
- const HardwareBuffer &buffer,
- std::ptrdiff_t offset = 0,
- bool large_indices = false) {
- add<BindIndexBufferCommand>(buffer, offset, large_indices);
- }
- inline void copyBuffer(
- const HardwareBuffer &source,
- const HardwareBuffer &destination,
- std::size_t size,
- std::ptrdiff_t src_offset = 0u,
- std::ptrdiff_t dst_offset = 0u) {
- add<CopyBufferCommand>(source, destination, size, src_offset, dst_offset);
- }
- inline void bindDescriptorSets(
- GraphicsPipeline &pipeline,
- std::vector<DescriptorSetCRef> descriptor_sets) {
- add<BindDescriptorSetsCommand>(&pipeline, std::move(descriptor_sets));
- }
- inline void copyBufferToImage(const HardwareBuffer &source, const Texture &destination) {
- add<CopyBufferToImageCommand>(source, destination);
- }
- inline void transitionImageLayout(Texture &image, ImageLayout new_layout) {
- add<TransitionImageLayoutCommand>(image, new_layout);
- }
- protected:
- explicit CommandBuffer(const Queue &queue);
- State m_state = State::Initial;
- QueueCRef m_queue;
- std::queue<Command> m_commands;
- };
- } // namespace storm::render
- #ifdef STORM_COMPILER_MSVC
- #pragma warning(pop)
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement