Engineering II - Week 3
A downloadable game
This week we are continuing work in our Graphics Project, combing our platform-dependent graphics.cpps into one platform independent graphics interface, adding index buffers, and making an interface to initialize mesh and effect data.
Digging into the code, I saw that buffers were being handled differently between Direct3D and OpenGL. To render a graphic each frame the back buffer is cleared, a new image is made in the back buffer, and the front and back buffers are swapped. Upon seeing, all these different buffer implementations, I made a new class cBuffer. Note to self, I think I can make the Buffer class static, but I’m not sure if there would be any benefits of being able to instantiate multiple instances of them yet. In the Buffer class, I made methods to clear, set depth, and swap buffers, with the bodies of the functions being inside Direct3D and OpenGL respecive cpps. Direct3D also needed some platform specific variables to render target view and depth stencil view, which required the creation of CleanUp and InitializationViews methods. On the OpenGL side, these methods were left blank for the possibilities of being filled at a later date.
This is the code, within my Graphics.cpp, to clear the back buffer:
The four floats being passed into the method represent an RGBA value.
Effect initialization intereface:
This argument takes a path to a vertex shader and fragment shader.
Mesh initialization interface:
This argument takes an array of vertex data which are coordinate points, and index data which are the indexes of those vertices to make triangles. I am getting the size of these arrays within the functions using sizeof(arr) / sizeof(arr[0]). This is divides the total byte size by the byte size of one index.
MEMORY USAGE
OpenGL
Direct3D
I feel that I cannot trust this sizeof() data. Something is broken.
When looking at effect I count:
OpenGL
- 2 pointers (8 bytes)
- 1 cRenderState (unknown)
- 1 GLunit (4 bytes)
D3D
- 2 pointers (8 bytes)
- 1 cRenderState (unknown)
On paper D3D effect is more memory efficient than OpenGL due to not needing to store a program ID that needs to be cleaned up later.
When looking at mesh I count:
OpenGL
- 1 int (4 bytes)
- 3 GLunit (12 bytes)
D3D
- 1 int (4 bytes)
- 3 pointers (12 bytes)
OpenGL and D3D should be the same size.
There is currently a huge issues inside of my project: passing arrays into my mesh class initialization seems to corrupt the data. Using the debugger, I can see nicely formatted before the method call, and inside the method, it’s gone. When I try pointers, the memory address is consistent, but the data previously there is gone. Pass by reference and value is the same, the data is just gone. I tried moving the initialization of the array’s to other parts of the graphics library in case it was somehow getting garbage collected, but then, I can’t get the data to survive to the initialization call.
Leave a comment
Log in with itch.io to leave a comment.