Skip to content

Commit

Permalink
Add vertex buffer binding offset example
Browse files Browse the repository at this point in the history
  • Loading branch information
krOoze committed Jun 30, 2021
1 parent 8bc891d commit cf52c8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Hello Triangle Vulkan demo
Hello Triangle Vulkan demo -- vertex binding offset
=========================

This is a traditional Hello World style application for the Vulkan API. It
renders a RGB shaded equilateral triangle (well, if the resolution is a square).
And it tries if vertex binding offset using `vkCmdBindVertexBuffers()` works.

The code is relatively flat and basic, so I think it's good enough for learning.
No tutorial or even much comments are provided though (comments do lie anyway
Expand Down
14 changes: 7 additions & 7 deletions src/HelloTriangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ using std::vector;
// Config
//////////////////////////////////////////////////////////////////////////////////

const char appName[] = u8"Hello Vulkan Triangle";
const char appName[] = u8"Hello Vulkan Triangle -- Vertex Offset";

// layers and debug
#if VULKAN_VALIDATION
Expand Down Expand Up @@ -225,7 +225,7 @@ void recordBeginRenderPass(
void recordEndRenderPass( VkCommandBuffer commandBuffer );

void recordBindPipeline( VkCommandBuffer commandBuffer, VkPipeline pipeline );
void recordBindVertexBuffer( VkCommandBuffer commandBuffer, const uint32_t vertexBufferBinding, VkBuffer vertexBuffer );
void recordBindVertexBuffer( VkCommandBuffer commandBuffer, const uint32_t vertexBufferBinding, VkBuffer vertexBuffer, VkDeviceSize offset );

void recordDraw( VkCommandBuffer commandBuffer, uint32_t vertexCount );

Expand All @@ -244,6 +244,7 @@ int helloTriangle() try{

const float triangleSize = 1.6f;
const vector<Vertex2D_ColorF_pack> triangle = {
{ /*unused*/{ { 0.0f, 0.0f} }, { {0.0f, 0.0f, 0.0f} } },
{ /*rb*/ { { 0.5f * triangleSize, sqrtf( 3.0f ) * 0.25f * triangleSize} }, /*R*/{ {1.0f, 0.0f, 0.0f} } },
{ /* t*/ { { 0.0f, -sqrtf( 3.0f ) * 0.25f * triangleSize} }, /*G*/{ {0.0f, 1.0f, 0.0f} } },
{ /*lb*/ { {-0.5f * triangleSize, sqrtf( 3.0f ) * 0.25f * triangleSize} }, /*B*/{ {0.0f, 0.0f, 1.0f} } }
Expand Down Expand Up @@ -464,9 +465,9 @@ int helloTriangle() try{
recordBeginRenderPass( commandBuffers[i], renderPass, framebuffers[i], ::clearColor, surfaceSize.width, surfaceSize.height );

recordBindPipeline( commandBuffers[i], pipeline );
recordBindVertexBuffer( commandBuffers[i], vertexBufferBinding, vertexBuffer );
recordBindVertexBuffer( commandBuffers[i], vertexBufferBinding, vertexBuffer, 1 * sizeof( Vertex2D_ColorF_pack ) );

recordDraw( commandBuffers[i], static_cast<uint32_t>( triangle.size() ) );
recordDraw( commandBuffers[i], static_cast<uint32_t>( triangle.size() - 1 ) );

recordEndRenderPass( commandBuffers[i] );
endCommandBuffer( commandBuffers[i] );
Expand Down Expand Up @@ -1864,9 +1865,8 @@ void recordBindPipeline( VkCommandBuffer commandBuffer, VkPipeline pipeline ){
vkCmdBindPipeline( commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline );
}

void recordBindVertexBuffer( VkCommandBuffer commandBuffer, const uint32_t vertexBufferBinding, VkBuffer vertexBuffer ){
VkDeviceSize offsets[] = {0};
vkCmdBindVertexBuffers( commandBuffer, vertexBufferBinding, 1 /*binding count*/, &vertexBuffer, offsets );
void recordBindVertexBuffer( VkCommandBuffer commandBuffer, const uint32_t vertexBufferBinding, VkBuffer vertexBuffer, VkDeviceSize offset ){
vkCmdBindVertexBuffers( commandBuffer, vertexBufferBinding, 1 /*binding count*/, &vertexBuffer, &offset );
}

void recordDraw( VkCommandBuffer commandBuffer, const uint32_t vertexCount ){
Expand Down

0 comments on commit cf52c8f

Please sign in to comment.