CS 419v/519v -- Winter Quarter 2018

Project #3

100 Points

Due: Fenruary 23

Drawing using an Index Buffer


This page was last updated: February 19, 2018



Requirements

Project #1 asked you to create your own object in a Vulkan program.
Project #2 is asking you to add lighting to it.
Project #3 is asking you to draw using both a Vertex Buffer and an Index Buffer

In the sample code, all of the vertices were listed out in order so they just had to be processed in the order in which they were listed. The purpose of this project is to use indexed rendering, where the vertices are listed in the Vertex Buffer, and the path to connect them is listed in an Index Buffer.

Note that you will need to define the object, create two Vulkan buffers, fill the two Vulkan buffers, then use a different draw vkCmd than we used before.

You can create the vertices and indices by hand, or you can do it procedurally.

You can use 16-bit ints or 32-bit ints in your index buffer. In the call:
vkCmdBindIndexBuffer( commandBuffer, indexDataBuffer, indexOffset, indexType );
the indexType must be either VK_INDEX_TYPE_UINT16 or VK_INDEX_TYPE_UINT32

If you want to use 16-bit ints, then your index values can only go as high as 32767. If the compiler doesn't know about uint16_t, then do this:
typedef unsigned short int uint16_t;

As space is not an issue, I recommend VK_INDEX_TYPE_UINT32.

Remember that you can inject a Restart Index (0xffff or 0xffffffff) in the list to restart the primitive.

Keep all the lighting and color/texture mode changes that you had before.

Feel free to add more keyboard inputs if you want.

Hints

In your PDF report, show what you did, i.e., how you decided what to put in the index buffer.

Create a video so I can see how it turned out.

Here is some sample code you might find useful:

**********************************************************

struct vertex JustVertexData[ ] =
{
        // vertex #0:
        {
                { -1., -1., -1. },
                {  0.,  0., -1. },
                {  0.,  0.,  0. },
                {  1., 0. }
        },

        // vertex #1:
        {
                {  1., -1., -1. },
                {  0.,  0., -1. },
                {  1.,  0.,  0. },
                {  0., 0. }
        },

**********************************************************

int JustIndexData[ ] =
{
        0, 2, 3,
        0, 3, 1,
        4, 5, 7,
        4, 7, 6,
        1, 3, 7,
        1, 7, 5,
        0, 4, 6,
        0, 6, 2,
        2, 6, 7,
        2, 7, 3,
        0, 1, 5,
        0, 5, 4,
};


**********************************************************


VkResult
Init05MyIndexDataBuffer(IN VkDeviceSize size, OUT MyBuffer * pMyBuffer)
{
        VkResult result = Init05DataBuffer(size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
				pMyBuffer);          // fills pMyBuffer
        REPORT("Init05MyIndexDataBufferBuffer");
        return result;
}

**********************************************************

        Init05MyVertexDataBuffer(  sizeof(JustVertexData), &MyJustVertexDataBuffer );
        Fill05DataBuffer( MyJustVertexDataBuffer,               (void *) JustVertexData );

        Init05MyIndexDataBuffer(  sizeof(JustIndexData), &MyJustIndexDataBuffer );
        Fill05DataBuffer( MyJustIndexDataBuffer,                (void *) JustIndexData );

**********************************************************

        VkBuffer vBuffer     = { MyJustVertexDataBuffer.buffer };
        VkBuffer iBuffer     = { MyJustIndexDataBuffer.buffer  };

        vkCmdBindVertexBuffers( CommandBuffers[nextImageIndex], 0, 1, vBuffer, offsets );
						             // 0, 1 = firstBinding, bindingCount
        vkCmdBindIndexBuffer(   CommandBuffers[nextImageIndex], iBuffer, 0, VK_INDEX_TYPE_UINT32 );

        const uint32_t indexCount  = sizeof(JustIndexData)  / sizeof(JustIndexData[0]);
        const uint32_t instanceCount = 1;
        const uint32_t firstVertex = 0;
        const uint32_t firstIndex = 0;
        const uint32_t firstInstance = 0;
        const uint32_t vertexOffset  = 0;
        vkCmdDrawIndexed( CommandBuffers[nextImageIndex], indexCount, instanceCount, firstIndex,
				vertexOffset, firstInstance );

**********************************************************

Turn-in:

Use the Teach system to turn in your:

  1. A one-page PDF with a title, your name, your email address, nice screen shots from your program, and the link to the Kaltura video demonstrating that your project. I'd like you to narrate your video so that you can tell me what you did.

Grading:

FeaturePoints
Did it80
Didn't screw anything up from before20
Potential Total100