I finally coded Azura to a level that it can be put up on Github. There are still many pending fixes, but the current code sets a skeleton for the future code commits.

It uses:

  • Boost Lib
  • Effects11 (or FX11)
  • Direct3D 11

So far it is pretty generic and takes a lot of inspiration from Unity. Learning Unity side by side was really helpful as it showcased the way Unity implements Component behavior which is similar to Azura’s Property behavior.


Here are some initial outlines:

Initialization Phase

The Game Render State

The GameRenderState is actually a class containing all information needed by the Rendering Phase. It’s just a group of pointers.

mGameRenderState = new GameRenderState(m_d3dDevice, m_d3dContext);

Compiling FX11 Shaders

To compile FX11 Shader into the RenderState, I use:

// Shader's Path and vector list of Techniques
mGameRenderState->CreateEffectShader(L"Shaders/default.fx", { "DefaultTech" });

// If you have more than 1 shader file
mGameRenderState->CreateEffectShader("MySecondShader", L"Shaders/default.fx", { "DefaultTech" });

Building the Input Layout

mGameRenderState->BuildInputLayout(Azura::BasicVertexLayout, Azura::BasicVertexLayoutCount);

// BasicVertexLayout -> Position, Color

Core Manager

CoreManager handles all the core phases init, update, render – currently has the render phase.

mCoreManager = CoreManager(mGameRenderState);

Update Phase

Adding GameObjects

auto cuboid = new Cuboid("MyCuboid", mGameRenderState);
mCoreManager.AddToRenderList(cuboid);

Rendering Phase

Just call the RenderPhase of CoreManager. It knows which objects are there, and loaded with what shaders.

// Clear the RenderTarget (Will be handled later on by Azura)

mCoreManager.RenderPhase();

// Present the RenderTarget (Will be handled later on by Azura)

This is just the very beginning of the code base. Here is how a cuboid is made:

Cuboid::Cuboid(LPCSTR id, GameRenderState* renderState) :
    GameObject(id, renderState)
{
    Mesh mesh = Mesh(renderState);
    BasicMesh cubeMesh = ShapesHelper::GetBasicCube(); // A helper to get Basic Shapes
    mesh.SetVertices(cubeMesh.vertices);
    mesh.SetIndices(cubeMesh.indices);
    mesh.CreateBuffers();

    // Set the Mesh Property
    SetMesh(mesh);
}

Cuboid::~Cuboid()
{
}

Here is how a Mesh looks like, again a focus on generic behavior through Property class inheritance.

namespace Azura
{
    class Mesh : public Property
    {
    public:
        Mesh();
        Mesh(GameRenderState* renderState);

        void Render();
        void SetVertices(vector<Vertex*> vertices);
        void SetIndices(vector<UINT> indices);
        void CreateBuffers();

    private:
        // Game Render Reference
        GameRenderState* mGameRenderState;

        // Buffers
        Microsoft::WRL::ComPtr<ID3D11Buffer>        mVertexBuffer;
        Microsoft::WRL::ComPtr<ID3D11Buffer>        mIndexBuffer;

        // Misc
        Microsoft::WRL::ComPtr<ID3D11BlendState>    mAlphaBlendState;
        int mVertexCount;
        int mIndexCount;

        UINT* mIndices;
        Vertex** mVertices;

        LPCSTR mTargetShader;
        LPCSTR mTargetTechnique;

        // Buffer Desc
        D3D11_USAGE mVertexBufferUsage;
        UINT mVertexBufferSize;
        UINT mVertexBufferCPUFlags;
        UINT mVertexBufferMiscFlags;
        UINT mVertexBufferByteStride;

        D3D11_USAGE mIndexBufferUsage;
        UINT mIndexBufferSize;
        UINT mIndexBufferCPUFlags;
        UINT mIndexBufferMiscFlags;
        UINT mIndexBufferByteStride;

        D3D_PRIMITIVE_TOPOLOGY mTopology;
    };

}