Download Link
LehanLi_assignment03_direct3d.zip
LehanLi_assignment03_opengl.zip
GIF of MyGame
How I made Graphics.cpp platform-independent
I created a cView class and implemented some interfaces such as: ClearBuffers, InitializeViews and CleanUp. Then I implemented these functions in cView.d3d.cpp and cView.gl.cpp.
I also created an interface called SwapBuffer in sContext class for different platform to swap content from back buffer to front buffer. Then I implemented it in sContext.d3d.cpp and sContext.gl.cpp.
Then for the content that is the same in d3d and gl platform, I just move them into Graphics.cpp.
The code that clears the back buffer color
I used the s_view_ClearBuffers(0.0f, 0.0f, 0.0f) to clear the back buffer color. Then I changed the parameters to rgb values to make animated color for the background.
The screenshot of my game with a different background color
The code that initializes an effect
I used Vertex Shader Path and Fragment Shader Path as parameters to initialize an effect.
Memory a single effect takes up in both platforms
- x64: 48
- x86: 16
The code that initializes a mesh
I used TriangleCount, VertexCountPerTriangle and VertexData as parameters to initialize a mesh.
Memory a single mesh takes up in both platforms
- x64: 24
- x86: 12
The size differences between platforms arise from:
- Pointer Size Variation:
- On different platforms (32-bit vs. 64-bit), pointers have different sizes (4 bytes vs. 8 bytes).
- Platform-Specific Data Structures:
- Different platforms use different types for handling resources (e.g., pointers vs. IDs), leading to variations in data representation and storage.
- Additional Platform-Specific Data:
- Additional platform-specific members (like
m_vertexArrayId
in OpenGL) increase the memory footprint.
- Additional platform-specific members (like
These variations are necessary to interface correctly with the different graphics APIs (Direct3D vs. OpenGL) and cannot be uniformly minimized without compromising functionality or compatibility.