Implementing the Required Interfaces

Once you have your project set up to include the Cathode Retro headers, it's time to start implementing the interfaces that will allow Cathode Retro to interface with your renderer.

For this, you'll need to #include "CathodeRetro/GraphicsDevice.h".

Sample Implementations

There is a sample Direct3D 11 implementation of these interfaces in Samples/D3D11-Sample/D3D11GraphicsDevice.h.

There is a sample OpenGL 3.3 Core implementation of these interfaces in Samples/GL-Sample/GLGraphicsDevice.h.

The IGraphicsDevice Interface

The core interface you'll need to implement is CathodeRetro::IGraphicsDevice, which is the interface that is passed to the main CathodeRetro::CathodeRetro class.

This interface can create objects (render targets and constant buffers) and render.

You'll need to implement the following methods:

Creation Methods

CreateRenderTarget
Create a CathodeRetro::IRenderTarget-derived object representing a render target (or frame buffer object) with the given properties.
CreateConstantBuffer
Create a CathodeRetro::IConstantBuffer-derived object representing a block of bytes that is used to pass data to the shaders.

Render Methods

BeginRendering
This is called by the CathodeRetro::CathodeRetro class when it is beginning its rendering, and is where you should set up any render state that is going to be consistent across the whole pipeline (the vertex shader, blending mode, etc).
  • Cathode Retro specifically wants no alpha blending or testing enabled.
  • Additionally, it expects floating-point textures to be able to use the full range of values, so if the API allows for truncating floating-point values to the 0..1 range on either shader output or sampling input, that should be disabled.
RenderQuad
This is called by the CathodeRetro::CathodeRetro class during rendering to render a full-render-target quad using the shader with the given ShaderID, to the given IRenderTarget, using a set of input ShaderResourceViews and an IConstantBuffer.
EndRendering
This is called when the CathodeRetro::CathodeRetro class is done rendering, and is where you should restore any render states necessary for the rest of your renderer to continue as normal.

The IConstantBuffer Interface

CathodeRetro::IConstantBuffer is a "constant buffer" (GL/Vulkan refer to these as "uniform buffers") - basically a data buffer to be handed to a shader. These will be fully updated every frame so it is valid for this to allocate GPU bytes out of a pool and update for graphics APIs that prefer that style of CPU -> GPU buffering. These may be updated by the CathodeRetro::CathodeRetro class more than once per frame.

This interface only has a single method that needs to be implemented:

Update
Copy the given data bytes into the constant buffer so that it is ready for rendering via a call to IGraphicsDevice::RenderQuad.

The ITexture and IRenderTarget Interfaces

CathodeRetro::ITexture and CathodeRetro::IRenderTarget are two interfaces that share the same methods (IRenderTarget inherits from ITexture).

While the CathodeRetro::IGraphicsDevice interface can only directly create IRenderTarget objects, you will potentially need to implement an ITexture-derived class as well, to represent the texture that is the input into CathodeRetro::CathodeRetro::Render.

These interfaces both have the following methods:

Width
Get the width of this texture.
Height
Get the height of this texture.
MipCount
Get the number of mipmap levels the texture contains.
Format
Get the format of this texture.

What's Next?

Once all of these interfaces have been implemented, you are now ready to use the main CathodeRetro class.