SAGE
A Simple Academic Game Engine
Loading...
Searching...
No Matches
Sage::CRenderer3D Class Reference

The renderer. More...

#include <SageRenderer3D.h>

Inheritance diagram for Sage::CRenderer3D:
Collaboration diagram for Sage::CRenderer3D:

Public Member Functions

 CRenderer3D ()
 Constructor.
 
virtual ~CRenderer3D ()
 Destructor.
 
void Initialize (bool=true)
 Initialize renderer.
 
void LoadTexture (const char *, CTextureDesc &)
 Load texture.
 
void LoadTextureFile (const char *, CTextureDesc &)
 Load texture from file.
 
void BeginResourceUpload ()
 Begin uploading textures.
 
void EndResourceUpload ()
 End uploading textures.
 
virtual void BeginFrame ()
 Begin frame.
 
virtual void EndFrame ()
 End frame.
 
void SetBgColor (const XMVECTORF32 &)
 Set default background color.
 
void DrawScreenText (const char *, const Vector2 &, XMVECTORF32=Colors::Black, float=1.0f)
 Draw screen text.
 
void DrawScreenText (const wchar_t *, const Vector2 &, XMVECTORF32=Colors::Black, float=1.0f)
 Draw screen text, wide version.
 
void DrawCenteredText (const char *, XMVECTORF32=Colors::Black)
 Draw centered text.
 
void DrawCenteredText (const wchar_t *, XMVECTORF32=Colors::Black)
 Draw centered text, wide version.
 
void SaveScreenShot ()
 Save a screenshot.
 
virtual void OnDeviceLost () override
 Handler for device lost notification.
 
virtual void OnDeviceRestored () override
 Handler for device restored notification.
 
- Public Member Functions inherited from Sage::CWindow
template<typename t0 , typename t1 , typename t2 >
int WinMain (_In_ HINSTANCE, bool, const t0 &, const t1 &, const t2 &)
 WinMain.
 
- Public Member Functions inherited from Sage::CSettingsManager
void Load ()
 Load game settings.
 

Protected Member Functions

void CreateDDSTexture (_In_z_ const wchar_t *, CTextureDesc &)
 Load a texture from a DirectDraw surface file (contains mipmaps).
 
void CreateWICTexture (_In_z_ const wchar_t *, CTextureDesc &)
 Load a texture from a an image file (does not contain mipmaps).
 
void ProcessTexture (_In_ Microsoft::WRL::ComPtr< ID3D12Resource >, CTextureDesc &)
 Process a loaded texture.
 
void LoadScreenFont ()
 Load screen font.
 
- Protected Member Functions inherited from Sage::CWindow
HWND CreateGameWindow (HINSTANCE)
 Create default window.
 
bool InitGameWindow (_In_ HINSTANCE)
 Initialize the game window.
 
void OpenDebugConsole ()
 Open debug console window.
 
void CloseDebugConsole ()
 Close debug console window.
 
- Protected Member Functions inherited from Sage::CSettingsManager
void SetWinSize (int, int)
 Set window size information.
 

Protected Attributes

std::unique_ptr< GraphicsMemory > m_pGraphicsMemory
 Pointer to graphics memory.
 
std::unique_ptr< DescriptorHeap > m_pDescriptorHeap
 Pointer to a descriptor heap.
 
UINT m_nNumResourceDesc = 0
 Number of resource descriptors in descriptor heap.
 
std::unique_ptr< CommonStates > m_pStates
 Pointer to render state object.
 
std::unique_ptr< SpriteBatch > m_pSpriteBatch
 SpriteBatch object for rendering sprites in screen space (from the DirectXTK).
 
std::unique_ptr< PrimitiveBatch< VertexPositionColor > > m_pPrimitiveBatch
 PrimitiveBatch object from the DirectXTK.
 
std::unique_ptr< SpriteBatch > m_pTextSpriteBatch
 SpriteBatch object for rendering text in screen space.
 
std::unique_ptr< SpriteFont > m_pFont
 Text font.
 
std::unique_ptr< DX::DeviceResources > m_pDeviceResources
 Pointer to device resources.
 
ID3D12Device * m_pD3DDevice = nullptr
 Pointer to the D3D device.
 
ResourceUploadBatch * m_pResourceUpload = nullptr
 Pointer to the resource upload batch object.
 
ID3D12GraphicsCommandList * m_pCommandList = nullptr
 Pointer to the command list.
 
ID3D12DescriptorHeap * m_pHeaps [2] = {nullptr}
 A pair of pointers to heaps.
 
RenderTargetState m_RenderTargetState
 The render target state.
 
XMVECTORF32 m_f32BgColor = Colors::White
 The default background color.
 

Private Member Functions

void CreateDeviceDependentResources ()
 Create device dependent resources.
 

Private Attributes

std::vector< Microsoft::WRL::ComPtr< ID3D12Resource > > m_pTexture
 Texture list.
 
bool m_bUseDepthStencil = true
 Whether to use z-buffering.
 

Additional Inherited Members

- Static Protected Member Functions inherited from Sage::CWindow
static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM)
 The Window Procedure.
 
static void GetBorderSizes (int &w, int &h)
 Get window border width and height.
 
static void EnforceAspectRatio (WPARAM, RECT *)
 Enforce aspect ratio.
 
static void EnforceAspectRatio (MINMAXINFO *)
 Enforce aspect ratio.
 
- Static Protected Attributes inherited from Sage::CComponent
static std::unique_ptr< CTimerm_pTimer = std::make_unique<CTimer>()
 Pointer to a timer.
 
static std::unique_ptr< CRandomm_pRandom = std::make_unique<CRandom>()
 Pointer to a PRNG.
 
static std::unique_ptr< CSoundm_pSound = std::make_unique<CSound>()
 Pointer to sound manager.
 
static std::unique_ptr< CKeyboardm_pKeyboard
 Pointer to a keyboard handler.
 
static std::unique_ptr< CMousem_pMouse = std::make_unique<CMouse>()
 Pointer to a mouse handler.
 
static std::unique_ptr< CControllerm_pController
 Pointer to a controller.
 
- Static Protected Attributes inherited from Sage::CCameraCommon
static XMFLOAT4X4 m_f4x4Orient
 Orientation matrix.
 
static XMFLOAT4X4 m_f4x4View
 View matrix.
 
static XMFLOAT4X4 m_f4x4Projection
 Projection matrix.
 
- Static Protected Attributes inherited from Sage::CWindow
static Vector2 m_vMousePos
 Mouse position.
 
- Static Protected Attributes inherited from Sage::CWindowDesc
static HWND m_Hwnd = 0
 Window handle.
 
static HINSTANCE m_hInst = 0
 Instance handle.
 
static bool m_bExitSizeMove = true
 User just finished moving/resizing window.
 
- Static Protected Attributes inherited from Sage::CSettingsManager
static tinyxml2::XMLElement * m_pXmlSettings = nullptr
 Pointer to the settings tag in the XML settings file.

 
static float m_fAspectRatio = 1.0f
 Aspect ratio, width/ht.
 
- Static Protected Attributes inherited from Sage::CSettings
static char m_szName [MAX_PATH]
 Name of this game.
 
static int m_nWinWidth = 0
 Window width in pixels.
 
static int m_nWinHeight = 0
 Window height in pixels.
 
static Vector2 m_vWinCenter = Vector2::Zero
 Window center.
 
- Static Protected Attributes inherited from Sage::CScreenshotFlag
static bool m_bScreenShot = false
 Screenshot flag.
 

Detailed Description

The renderer uses DirectX 12 and DirectXTK 12.

Member Function Documentation

◆ BeginFrame()

void CRenderer3D::BeginFrame ( )
virtual

Must be called at the start of each animation frame to initialize the render pipeline.

Reimplemented in Sage::CSpriteRenderer.

Here is the caller graph for this function:

◆ BeginResourceUpload()

void CRenderer3D::BeginResourceUpload ( )

Notify the resource upload object that uploading is about to begin.

Here is the caller graph for this function:

◆ CreateDDSTexture()

void CRenderer3D::CreateDDSTexture ( _In_z_ const wchar_t * szFileName,
CTextureDesc & tDesc )
protected

Load a texture from a DirectDraw Surface file. Aborts if file not found.

Parameters
szFileName[in] Wide file name.
tDesc[out] Descriptor for the texture pointed to by p.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateDeviceDependentResources()

void CRenderer3D::CreateDeviceDependentResources ( )
private

Create SpriteBatch, PrimitiveBatch and set their viewports. Load the text font.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateWICTexture()

void CRenderer3D::CreateWICTexture ( _In_z_ const wchar_t * szFileName,
CTextureDesc & tDesc )
protected

Load a texture from a WIC file. Aborts if file not found.

Parameters
szFileName[in] Wide file name.
tDesc[out] Texture descriptor.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawCenteredText() [1/2]

void CRenderer3D::DrawCenteredText ( const char * text,
XMVECTORF32 color = Colors::Black )

Draw text to the screen center.

Parameters
textNull terminated text string.
colorText color, defaults to black.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawCenteredText() [2/2]

void CRenderer3D::DrawCenteredText ( const wchar_t * text,
XMVECTORF32 color = Colors::Black )

Draw text to the screen center.

Parameters
textNull terminated wide text string.
colorText color, defaults to black.

◆ DrawScreenText() [1/2]

void CRenderer3D::DrawScreenText ( const char * text,
const Vector2 & p,
XMVECTORF32 color = Colors::Black,
float fScale = 1.0f )

Draw text to the screen.

Parameters
textNull terminated text string.
pposition of text.
colorText color, defaults to black.
fScaleScale. Defaults to 1.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawScreenText() [2/2]

void CRenderer3D::DrawScreenText ( const wchar_t * text,
const Vector2 & p,
XMVECTORF32 color = Colors::Black,
float fScale = 1.0f )

Draw text to the screen.

Parameters
textNull terminated wide text string.
pposition of text.
colorText color, defaults to black.
fScaleScale. Defaults to 1.

◆ EndFrame()

void CRenderer3D::EndFrame ( )
virtual

Must be called at the end of each animation frame to render and present the current frame. This function also saves a screenshot if m_bScreenShot is true (and sets m_bScreenShot to false afterwards).

Reimplemented in Sage::CSpriteRenderer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EndResourceUpload()

void CRenderer3D::EndResourceUpload ( )

Notify the resource upload object that uploading is over, and wait for any uploads in progress to finish.

Here is the caller graph for this function:

◆ Initialize()

void CRenderer3D::Initialize ( bool bUseDepthStencil = true)

Do the necessary voodoo to set up Direct3D 12 rendering.

Parameters
bUseDepthStenciltrue to use z-buffering.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadScreenFont()

void CRenderer3D::LoadScreenFont ( )
protected

Load the font for the screen text from a font file specified in gamesettings.xml.

Here is the caller graph for this function:

◆ LoadTexture()

void CRenderer3D::LoadTexture ( const char * name,
CTextureDesc & tDesc )

Load a texture from a file specified in gamesettings.xml. Aborts if gamesettings.xml has not been loaded correctly.

Parameters
name[in] Name field in a sprite tag.
tDesc[out] Texture descriptor.
Here is the call graph for this function:

◆ LoadTextureFile()

void CRenderer3D::LoadTextureFile ( const char * filename,
CTextureDesc & tDesc )

Load a texture from a file. Aborts if file not found.

Parameters
filename[in] File name.
tDesc[out] Texture descriptor.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnDeviceLost()

void CRenderer3D::OnDeviceLost ( )
overridevirtual

TODO: fix this, it ain't complete.

◆ OnDeviceRestored()

void CRenderer3D::OnDeviceRestored ( )
overridevirtual

TODO: fix this, it ain't complete.

◆ ProcessTexture()

void CRenderer3D::ProcessTexture ( _In_ Microsoft::WRL::ComPtr< ID3D12Resource > p,
CTextureDesc & tDesc )
protected

Given a COM pointer to a texture that has just been loaded using CreateDDSTexture of CreateWICTexture, append it to the end of texture list, create a shader resource view for it, and record the texture's index, resource descriptor index, and dimensions in the texture descriptor.

Parameters
p[in] Pointer to the D3D12 resource for the texture.
tDesc[out] Descriptor for the texture pointed to by p.
Here is the caller graph for this function:

◆ SaveScreenShot()

void CRenderer3D::SaveScreenShot ( )

Save a screenshot to screenshot0.bmp, screenshot1.bmp, etc.

Here is the caller graph for this function:

◆ SetBgColor()

void CRenderer3D::SetBgColor ( const XMVECTORF32 & color)

Set the background color.

Parameters
colorNew background color.