Skip to content

Commit

Permalink
drawing without pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
maxortner01 committed Oct 14, 2024
1 parent 6bf1a18 commit dba368f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 34 deletions.
18 changes: 0 additions & 18 deletions include/midnight/Graphics/Pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,6 @@ namespace mn::Graphics

struct PipelineBuilder;

/*
struct DescriptorSet : ObjectHandle<DescriptorSet>
{
friend struct PipelineBuilder;
DescriptorSet(const DescriptorSet&) = delete;
DescriptorSet(DescriptorSet&&) = default;
MN_SYMBOL ~DescriptorSet();
void setImages(uint32_t binding, Backend::Sampler::Type sampler, const std::vector<std::shared_ptr<Image>>& images);
private:
DescriptorSet(Handle<DescriptorSet> h) : ObjectHandle(h) { }
mn::handle_t layout, pool;
};*/

struct Pipeline : ObjectHandle<Pipeline>
{
friend struct PipelineBuilder;
Expand Down
5 changes: 5 additions & 0 deletions include/midnight/Graphics/RenderFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ namespace mn::Graphics

MN_SYMBOL void bind(const std::shared_ptr<Pipeline>& pipeline) const;

MN_SYMBOL void draw(uint32_t vertices, uint32_t instances = 1) const;
MN_SYMBOL void draw(const std::shared_ptr<Buffer>& buffer, uint32_t instances = 1) const;
MN_SYMBOL void draw(const std::shared_ptr<Mesh>& mesh, uint32_t instances = 1) const;
MN_SYMBOL void drawIndexed(const std::shared_ptr<Buffer>& buffer, const std::shared_ptr<Buffer>& indices, uint32_t instances = 1) const;

MN_SYMBOL void draw(const std::shared_ptr<Pipeline>& pipeline, uint32_t vertices, uint32_t instances = 1) const;
MN_SYMBOL void draw(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Buffer>& buffer, uint32_t instances = 1) const;
MN_SYMBOL void draw(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Mesh>& mesh, uint32_t instances = 1) const;
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/Backend/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Device::Device(Handle<Instance> _instance, handle_t p_device) :
VK_KHR_MULTIVIEW_EXTENSION_NAME,
VK_KHR_MAINTENANCE2_EXTENSION_NAME,
VK_KHR_MAINTENANCE3_EXTENSION_NAME,
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME
};

uint32_t count;
Expand Down
71 changes: 56 additions & 15 deletions src/Graphics/RenderFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,10 @@ void RenderFrame::bind(const std::shared_ptr<Pipeline>& pipeline) const
}
}

void RenderFrame::draw(const std::shared_ptr<Pipeline>& pipeline, uint32_t vertices, uint32_t instances) const
void RenderFrame::draw(uint32_t vertices, uint32_t instances) const
{
const auto cmdBuffer = frame_data->command_buffer->getHandle().as<VkCommandBuffer>();

bind(pipeline);

vkCmdDraw(
cmdBuffer,
vertices,
Expand All @@ -283,10 +281,8 @@ void RenderFrame::draw(const std::shared_ptr<Pipeline>& pipeline, uint32_t verti
0);
}

void RenderFrame::draw(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Buffer>& buffer, uint32_t instances) const
void RenderFrame::draw(const std::shared_ptr<Buffer>& buffer, uint32_t instances) const
{
MIDNIGHT_ASSERT(!(buffer->allocated() % pipeline->getBindingStride()), "Buffer stride is not expected by pipeline!");

const auto cmdBuffer = frame_data->command_buffer->getHandle().as<VkCommandBuffer>();

frame_data->resources.insert(buffer);
Expand All @@ -299,27 +295,23 @@ void RenderFrame::draw(const std::shared_ptr<Pipeline>& pipeline, const std::sha
&buff,
&off);

draw(pipeline, buffer->vertices(), instances);
draw(buffer->vertices(), instances);
}

void RenderFrame::draw(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Mesh>& mesh, uint32_t instances) const
void RenderFrame::draw(const std::shared_ptr<Mesh>& mesh, uint32_t instances) const
{
if (!mesh->vertexCount()) return;

if (mesh->indexCount())
drawIndexed(pipeline, mesh->vertex, mesh->index, instances);
drawIndexed(mesh->vertex, mesh->index, instances);
else
draw(pipeline, mesh->vertex, instances);
draw(mesh->vertex, instances);
}

void RenderFrame::drawIndexed(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Buffer>& buffer, const std::shared_ptr<Buffer>& indices, uint32_t instances) const
void RenderFrame::drawIndexed(const std::shared_ptr<Buffer>& buffer, const std::shared_ptr<Buffer>& indices, uint32_t instances) const
{
MIDNIGHT_ASSERT(!(buffer->allocated() % pipeline->getBindingStride()), "Buffer stride is not expected by pipeline!");

const auto cmdBuffer = frame_data->command_buffer->getHandle().as<VkCommandBuffer>();

bind(pipeline);

frame_data->resources.insert(buffer);
const auto buff = buffer->getHandle().as<VkBuffer>();
VkDeviceSize off = 0;
Expand All @@ -346,4 +338,53 @@ void RenderFrame::drawIndexed(const std::shared_ptr<Pipeline>& pipeline, const s
0);
}

void RenderFrame::draw(const std::shared_ptr<Pipeline>& pipeline, uint32_t vertices, uint32_t instances) const
{
const auto cmdBuffer = frame_data->command_buffer->getHandle().as<VkCommandBuffer>();

bind(pipeline);

draw(vertices, instances);
}

void RenderFrame::draw(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Buffer>& buffer, uint32_t instances) const
{
MIDNIGHT_ASSERT(!(buffer->allocated() % pipeline->getBindingStride()), "Buffer stride is not expected by pipeline!");

const auto cmdBuffer = frame_data->command_buffer->getHandle().as<VkCommandBuffer>();

frame_data->resources.insert(buffer);
const auto buff = buffer->getHandle().as<VkBuffer>();
VkDeviceSize off = 0;
vkCmdBindVertexBuffers(
cmdBuffer,
0,
1,
&buff,
&off);

draw(pipeline, buffer->vertices(), instances);
}

void RenderFrame::draw(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Mesh>& mesh, uint32_t instances) const
{
if (!mesh->vertexCount()) return;

if (mesh->indexCount())
drawIndexed(pipeline, mesh->vertex, mesh->index, instances);
else
draw(pipeline, mesh->vertex, instances);
}

void RenderFrame::drawIndexed(const std::shared_ptr<Pipeline>& pipeline, const std::shared_ptr<Buffer>& buffer, const std::shared_ptr<Buffer>& indices, uint32_t instances) const
{
MIDNIGHT_ASSERT(!(buffer->allocated() % pipeline->getBindingStride()), "Buffer stride is not expected by pipeline!");

const auto cmdBuffer = frame_data->command_buffer->getHandle().as<VkCommandBuffer>();

bind(pipeline);

drawIndexed(buffer, indices, instances);
}

}

0 comments on commit dba368f

Please sign in to comment.