Refactoring & Rendering a Cube

Before the we are able to work on portals there still needed to be work done to setup the graphics pipeline and render objects to the screen. But, before even that, the code needed a little TLC. I refactored the previous code into three classes. Here is a UML class diagram describing the current layout. All classes are final for now.

Windows Class

The Window class encapsulates Win32 methods for creating the window and the Window's handle. This includes the register window class method, creating the window instance, and wndProc method. In order to achieve minimal coupling between the window and the game, the Window class has subscribe methods that take in function pointers. The Game's Update and Render method are then set as callbacks to the Window's paint method in main. To encapsulate the wndProc as a non-static method, I created a static and non-static member version of wndProc. On Win32 window instance instantiation, embed the Window's instance pointer on the Window's handle through GWLP_USERDATA. 


In the static WndProc method, the Window's instance is retrieve from the window's handle to call the non-static version of WndProc.

DXContext Class

The DXContext class encapsulates the DirectX device, adapter, swap chain, and command queues.
The DXContext maintains RTVs, provides accessors for them, and contains a Present method. It also has a method for creating descriptor heaps.

CommandQueue Class

The CommandQueue class takes the DirectX12 Command Queue, the command allocators, the command list, and the fence, and puts it into one abstraction. It uses an object pool of command allocators and command lists. It provides proper synchronization for the command queue. 

Game Class

The game class contains game specific code. The previous Update and Render methods are now within this class.

Rendering an object

Beyond refactoring the code, I setup our graphics pipeline by implementing a very basic vertex and pixel shader and configuring them through the Pipeline State Object (PSO) and Root Signatures. The vertex shader currently only modifies the vertices by multiplying them by a combined model-view-projection matrix. The pixel shader is as simple as it can get; it just outputs the color fed in from the rasterizer. The current object I am generating is a cube with with both vertices and index buffers. Here is the current output:




Comments

Popular posts from this blog

Enabling Raytracing - Part 2

DXR Demo - Introduction

Simple Lighting