Assignment5 Writeup
Assignment5 Writeup
This assignment deals with constant buffers. There are two types of constant buffers which we are using
in our game1. Frame Buffer This buffer is basically used to store time in our game. The time here is the time
which is elapsed from the start of the game. This is created in graphics.[platform].cpp and
initialized. The frame buffer needs to be initialized, bound and cleaned updated only once
through a frame.
2. Draw Buffer This constant buffer is responsible for saving the positional data. We need only
one draw buffer for the whole game. The difference between the frame and the draw buffers is
that the draw buffer needs to be updated before every draw call of every mesh. This will ensure
that the mesh will be drawn at its own position. Also we need to bind this buffer only once per
frame. This is because the positional data for all the meshes will be saved in the same registers
on the vertex shaders.
Now we see that the Triangle Mesh is drawn first and then a square mesh is added. With arrow
keys we can move the square mesh on the screen.
2. I am using the UP,DOWN, LEFT, RIGHT arrow keys on the keyboard to move the square around.
This moves around the square uniformly without the frame rate because I am using the previous
frame time for the calculation of the final movement.
3. Below is the representation of my constant buffer header file. This will cater to both frame and
draw buffers.
4. The user specifies which type of buffer he is creating by using an enumerated data type. This is
BufferType in my class. Since the enum type is public the caller is responsible for calling the
correct data type. Now this enum is used everywhere in the code to distinguish between the
buffer type. There is a member variable for this class called m_buff_type. This stores the
enumerated type which the user passes on initialize, hence from this point the object always
knows whether it is a frame or a draw constant buffer.
Now based on this knowledge my bind code works as
Switch on m_buff_type
Case m_buff_type is frame Then binding point assigned in shader is 0
Case m_buff_type is draw Then binding point assigned in shader is 1
5. Below are the two examples of the user trying to specify which constant buffer he needs
Here he is trying to initialize draw buffer. Note: In the draw buffer I can either pass the initial
position as a pointer to a structure or a null pointer. If I pass null pointer the code will just
initialize the data to {0,0}. This is just a convenience because the Update() function for the draw
constant buffer is called and position is passed before each draw mesh call anyway.
Regarding the size needed to be allocated to a constant buffer, the code uses a
sizeof(corresponding_buffer_struct) depending on which buffer type the user supplies.
6. Cleanup is done by calling the cleanup code for both the draw and the frame buffer in the
graphics::Cleanup() code this is just positioned so that the call goes before the other API
cleanups
8. Below is the code which iterates through each drawable_item and draws it. i.e It first updates
the draw constant buffer of the mesh and then draws the mesh.
Problems that I ran into before submission1. I was getting an assertion fail in openGL because the fragment shader had ConstantBuffer as its
name and the vertex buffer had ConstantBuffer_frame. Resolved this with help of JP.
2. I was getting an issue with the keyboard input code which was provided. I had to modify it a
little bit to ensure it was working.
Special Thanks toMichael Brown for helping me realize that we dont need a draw buffer for every single mesh in the
game. Also Samrat Nagarjuna for helping me realize that we need to ONLY initialize meshes in the game
and the update Buffer functionalities should be taken care by the graphics system.