CS 419v/519v -- Winter Quarter 2023

Project #3

100 Points

Due: Fenruary 11

Drawing using an Index Buffer


This page was last updated: January 26, 2023



Requirements

Project #3 is asking you to toggle between drawing using:

  1. A vertex buffer, like you did in Project #1.
  2. A combination shorter vertex buffer + index buffer.

In the sample code, all of the vertices were given such they could just be processed in the order in which they were listed. Each vertex had its very own color, normal, and texture coordinate.

In this project, you will create a vertex list of just the unique vertices (for example, a cube would have just eight). You will then create an index list of the vertex indices that make up the object (for example, a cube would have 12 triangles, or 36 indices listed).

Some scenes work well this way, such as when each vertex has an assigned color and you plan to interpolate that color on all triangles that share that vertex.

Some scenes work not-so-well this way such as when you go to turn on texturing and interpolating the (s,t) on all triangles that share that vertex produces results like are shown above.

The purpose of this project is to show that.

Use the same object you created for Project #1. Keep the code basically the same. Add a second Vulkan buffer to hold just the unique vertices. Add a third Vulkan buffer to hold the indices. You can model what you do from the JustVertexData and JustIndexData data in the SampleVertexData.cpp file.

Or, if you don't want to use what you did in Project #1, you can create the vertices and indices by hand, or you can do it procedurally. Using an OBJ file will not work well, as the reader code takes the vertex-only approach.

Use 32-bit unsigned ints in your index buffer. In the call:
vkCmdBindIndexBuffer( commandBuffer, indexDataBuffer, indexOffset, indexType );
the indexType should VK_INDEX_TYPE_UINT32 (You would only use VK_INDEX_TYPE_UINT16 if you were really tight on memory space.)

Remember that you can inject a Restart Index (0xffffffff) in the list to restart the primitive. This works best with Triangle Strips and Triangle Fans.

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

Feel free to add more keyboard inputs if you want.

That Anomaly is to be Expected

That anomoly with the smeared or reversed or rotated texture image is to be expected. Don't try to debug that out.

Keyboard Keys

'i'Toggle using a vertex buffer only vs. a vertex+index buffer
'l' (ell)Toggle lighting on and off
'm'Toggle display mode (textures vs. colors)
'r'Toggle rotation-animation and using the mouse
Esc, 'q'Exit the program

Feel free to add more keyboard inputs if you want.

Hints

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;
}

**********************************************************
In InitGraphics( ):

	Init05MyVertexDataBuffer(  sizeof(VertexData), &MyVertexDataBuffer );
	Fill05DataBuffer( MyVertexDataBuffer,                   (void *) VertexData );

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

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

**********************************************************
In RenderScene( ):

	VkBuffer buffers[1]  = { MyVertexDataBuffer.buffer };
	VkBuffer vBuffers[1] = { MyJustVertexDataBuffer.buffer };
	VkBuffer iBuffer     = { MyJustIndexDataBuffer.buffer  };
	VkDeviceSize offsets[1] = { 0 };

	if( UseIndexBuffer )
	{
	        vkCmdBindVertexBuffers( CommandBuffers[nextImageIndex], 0, 1, vBuffers, offsets );
	        vkCmdBindIndexBuffer( CommandBuffers[nextImageIndex], iBuffer, 0, VK_INDEX_TYPE_UINT32 );
	}
	else
	{
	        vkCmdBindVertexBuffers( CommandBuffers[nextImageIndex], 0, 1, buffers, offsets );
	}


	const uint32_t vertexCount = sizeof(VertexData)     / sizeof(VertexData[0]);
	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;

	if( UseIndexBuffer )
	{
	        vkCmdDrawIndexed( CommandBuffers[nextImageIndex], indexCount, instanceCount, firstIndex, vertexOffset, firstInstance );
	}
	else
	{
	        vkCmdDraw( CommandBuffers[nextImageIndex], vertexCount, instanceCount, firstVertex, firstInstance );
	}


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

Turn-in:

Use the Teach system to turn in your:

  1. All source files: .cpp, .vert, .frag
  2. A PDF with a title, your name, your email address, screen shots from your program showing with and without using the Index Buffer, and the link to the video demonstrating that your project does what it is supposed to do. I like it when you to narrate your video so that you can tell me what I am looking at.

Grading:

FeaturePoints
Vertex display still works as expected30
Vertex + Index display works as expected70
Potential Total100