NoesisGUI

An introduction to RenderSystem

The RenderSystem is the KernelSystem in charge of rendering 3D content. It is basically an abstraction over a low level graphic API like DirectX or OpenGL. The package with all the virtual definition is located in the Render/RenderSystem package. Different implementations are provided in packages under the Render module. At this time, only a DirectX9 implementation is provided. It is implemented in the Render/DX9RenderSystem package.

The RenderSystem is a thin layer abstracting a platform API with the following group of functions:

  • Resource Management Functions: functions provided to create graphics resources. Those functions are located in the IRenderSystem.h interface
  • Command Buffers Functions: apart from the Resource Management Functions, the rest of the functionality is exposed through command buffers. A command buffer is an array of commands to be executed by the RenderSystem. Those functionality is exposed in the CommandBuffer class
////////////////////////////////////////////////////////////////////////////////////////////////////
/// IRenderSystem
////////////////////////////////////////////////////////////////////////////////////////////////////
NS_INTERFACE IRenderSystem: public Core::ICommon
{
    /// Creates a RenderView
    /// \param windowHandle operating system window handle
    /// \param fullScreen If this render view is full screen
    /// \param width Width in pixel of the render view. (=0 client area of the window)
    /// \param height Height in pixels of the render view (=0 client area of the window)
    virtual Ptr<IRenderView> CreateRenderView(NsWindowHandle windowHandle,
        NsBool fullScreen = false, NsSize width = 0, NsSize height = 0) = 0;

    /// Creates a RenderTarget
    /// \param width Width in pixels of the desired render target
    /// \param height Height in pixels of the desired render target
    /// \param format Member of the SurfaceFormat enumerated type
    /// \param multiSamplingCount Defines the levels of multisampling
    /// \param flags Zero or more values from the RenderTargetFlags enumerated type
    virtual Ptr<IRenderTarget> CreateRenderTarget(NsSize width, NsSize height, SurfaceFormat format,
        NsSize multiSamplingCount, NsInt flags) = 0;

    /// Creates a vertex buffer
    /// \param sizeInBytes Size of the vertex buffer, in bytes
    /// \param freq Identify what frequency of update is expected for the buffer
    /// \param data Pointer to the initialization data
    virtual Ptr<IVertexBuffer> CreateVertexBuffer(
        NsSize sizeInBytes, UpdateFrequency freq, const void* data = 0) = 0;

    /// Creates a index buffer
    /// \param sizeInBytes Size of the index buffer, in bytes
    /// \param freq Identify what frequency of update is expected for the buffer
    /// \param index32 If true indices are 32 bits each. 16 bits if false
    /// \param data Pointer to the initialization data
    virtual Ptr<IIndexBuffer> CreateIndexBuffer(
        NsSize sizeInBytes, UpdateFrequency freq, IndexFormat format, const void* data = 0) = 0;

    /// Creates a vertex source
    virtual Ptr<IVertexSource> CreateVertexSource(const VertexSourceDesc& vertexSourceDesc) = 0;

    /// Creates a command buffer
    virtual Ptr<CommandBuffer> CreateCommandBuffer() = 0;

    /// Executes a command buffer (it could be executed in another thread)
    virtual void Apply(const Ptr<CommandBuffer>& commands) = 0;

    /// Wait until all the commands from applied command buffers have been sent to the GPU
    virtual void WaitForIdle() = 0;
};

Basically, it offers function to create renderviews, rendertargets, vertexbuffers, indexbuffers, vertexsources and command buffers. All those resources are explained in the RenderSystem Resources entry.

As a normal Kernel System, when you want to use the RenderSystem you add it to the kernel. That way the Kernel will initialize it. After that, it can be retrieved to be used.

// Add the DirectX9 renderer to the kernel
kernel->AddSystem(NSS("DX9RenderSystem"), NSS("RenderSystem"));

/// ...

// Whenever the rendersystem is needed, you get it from the kernel
Ptr<IRenderSystem> renderSystem = kernel->GetSystem(NSS("RenderSystem"));

// And now, two windows are created
Ptr<IRenderView> rv1 = renderSystem->CreateRenderView(hWnd1);
Ptr<IRenderView> rv0 = renderSystem->CreateRenderView(hWnd0);
© 2017 Noesis Technologies