![]() |
SAGE
A Simple Academic Game Engine
|
The sprite renderer class. More...
#include <SageSpriteRenderer.h>
Public Member Functions | |
| CSpriteRenderer (eSpriteMode) | |
| Constructor. | |
| virtual | ~CSpriteRenderer () |
| Destructor. | |
| template<class t > | |
| void | LoadMT (Sage::CMediaList< t > &) |
| Load sprites multithreaded. | |
| template<class t > | |
| void | Load (Sage::CMediaList< t > &) |
| Load sprites. | |
| const bool | Loaded () const |
| Sprite loading completed. | |
| template<class t > | |
| void | Load (t, const char *) |
| Load sprite. | |
| void | Initialize (size_t) |
| Initialize. | |
| void | BeginFrame () |
| Begin frame. | |
| void | EndFrame () |
| End frame. | |
| void | Draw (const CSpriteDesc2D *) |
| Draw single 2D sprite. | |
| void | Draw (const CSpriteDesc3D *) |
| Draw single 3D sprite. | |
| void | Draw (std::vector< CSpriteDesc3D > &) |
| Draw list of 3D sprites. | |
| template<class t > | |
| void | Draw (t, const Vector2 &, float=0) |
| Draw single 2D sprite. | |
| template<class t > | |
| void | DrawLine (t, const Vector2 &, const Vector2 &) |
| Draw 2D line. | |
| template<class t > | |
| void | DrawLine (t, const Vector2 &, const Vector2 &, XMVECTORF32 c) |
| Draw 2D line. | |
| template<class t > | |
| void | DrawCircle (t, const Vector2 &, float) |
| Draw circle. | |
| template<class t > | |
| void | DrawBoundingBox (t, const BoundingBox &) |
| Draw AABB. | |
| void | SetCameraPos (const Vector3 &) |
| Set camera position. | |
| const Vector3 & | GetCameraPos () const |
| Get camera position. | |
| template<class t > | |
| const float | GetWidth (t) const |
| Get sprite width. | |
| template<class t > | |
| const float | GetHeight (t) const |
| Get sprite height. | |
| template<class t > | |
| void | GetSize (t, float &, float &) const |
| Get sprite size. | |
| template<class t > | |
| void | GetSize (t, UINT, float &, float &) const |
| Get sprite size. | |
| template<class t > | |
| const size_t | GetNumFrames (t) const |
| Get number of frames. | |
| const BoundingBox | GetAabb (UINT, UINT) const |
| Get bounding box. | |
| const bool | BoxInFrustum (const BoundingBox &) const |
| Does the box overlap the view frustum? | |
Public Member Functions inherited from Sage::CRenderer3D | |
| 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. | |
| 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 | LoadByIndex (UINT, const char *) |
| Load sprite by index. | |
| CSprite * | Load (UINT, const char *, const char *, UINT) |
| Load sprite. | |
| void | CreateEffect () |
| Create effect. | |
| void | CreateVertexBuffer () |
| Create vertex buffer. | |
| void | CreateIndexBuffer () |
| Create index buffer. | |
Protected Member Functions inherited from Sage::CRenderer3D | |
| 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 | |
| eSpriteMode | m_eRenderMode = eSpriteMode::Batched2D |
| Sprite render mode. | |
| CCamera * | m_pCamera = nullptr |
| Pointer to the camera. | |
| CSprite ** | m_pSprite = nullptr |
| Sprite pointers. | |
| size_t | m_nNumSprites = 0 |
| Number of sprites. | |
| bool | m_bLoaded = false |
| Sounds loaded flag. | |
| std::unique_ptr< BasicEffect > | m_pSpriteEffect |
| Sprite effect. | |
| std::map< std::string, UINT > | m_mapNameToIndex |
| Map tag name to sprite index. | |
| GraphicsResource | m_VertexBuffer |
| Vertex buffer. | |
| GraphicsResource | m_IndexBuffer |
| Index buffer. | |
| UINT | m_nIndexCount = 0 |
| Number of indexes in the index buffer. | |
| std::shared_ptr< D3D12_VERTEX_BUFFER_VIEW > | m_pVBufView |
| Vertex buffer view. | |
| std::shared_ptr< D3D12_INDEX_BUFFER_VIEW > | m_pIBufView |
| Index buffer view. | |
| float | m_fCurZ = FLT_MAX |
| Current depth for unbatched 2D rendering. | |
Protected Attributes inherited from Sage::CRenderer3D | |
| 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. | |
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< CTimer > | m_pTimer = std::make_unique<CTimer>() |
| Pointer to a timer. | |
| static std::unique_ptr< CRandom > | m_pRandom = std::make_unique<CRandom>() |
| Pointer to a PRNG. | |
| static std::unique_ptr< CSound > | m_pSound = std::make_unique<CSound>() |
| Pointer to sound manager. | |
| static std::unique_ptr< CKeyboard > | m_pKeyboard |
| Pointer to a keyboard handler. | |
| static std::unique_ptr< CMouse > | m_pMouse = std::make_unique<CMouse>() |
| Pointer to a mouse handler. | |
| static std::unique_ptr< CController > | m_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. | |
A renderer that will draw sprites in 2D and 3D.
| CSpriteRenderer::CSpriteRenderer | ( | eSpriteMode | mode | ) |
Construct a 3D renderer and a base camera.
| mode | Sprite render mode. |
|
virtual |
Clean up resources from GPU and wait for completion.
|
virtual |
Initialize the render pipeline and the SpriteBatch.
Reimplemented from Sage::CRenderer3D.
| const bool CSpriteRenderer::BoxInFrustum | ( | const BoundingBox & | box | ) | const |
AABB intersect view frustum test.
| box | An AABB. |
|
protected |
Construct a pipeline description for the sprite and use that to create an effect. Set its projection matrix to be the same as the global projection matrix.
|
protected |
Create an index buffer and index buffer view for the sprite quad.
|
protected |
Create a vertex buffer containing the four vertices of a quad centered at the origin with unit width and height. The vertices have position and texture coordinates. Create the corresponding vertex buffer view.
| void CSpriteRenderer::Draw | ( | const CSpriteDesc2D * | sd | ) |
Draw a sprite in 2D.
| sd | Const pointer to 2D sprite descriptor. |
| void CSpriteRenderer::Draw | ( | const CSpriteDesc3D * | sd | ) |
Draw a sprite in 3D.
| sd | Const pointer to 3D sprite descriptor. |
| void CSpriteRenderer::Draw | ( | std::vector< CSpriteDesc3D > & | renderlist | ) |
Depth sort a render list using a vector of pointers, then draw them from back to front.
| renderlist | A vector of 3D sprite descriptors of the sprites to be rendered. |
| void Sage::CSpriteRenderer::Draw | ( | t | n, |
| const Vector2 & | pos, | ||
| float | a = 0 ) |
Shorthand for drawing a 2D sprite with only index, position, and orientation. The other sprite descriptor fields are set to default values.
| t | Enumerated type for sprites. |
| n | Sprite type. |
| pos | Position in world space. |
| a | Orientation angle (roll) in radians. |
| void Sage::CSpriteRenderer::DrawBoundingBox | ( | t | n, |
| const BoundingBox & | aabb ) |
Draw an axially aligned bounding box.
| t | Enumerated type for sprites. |
| n | Line sprite type for AABB edges. |
| aabb | An axially aligned bounding box. |
| void Sage::CSpriteRenderer::DrawCircle | ( | t | line, |
| const Vector2 & | pos, | ||
| float | r ) |
Draw a circle by drawing multiple copies of a sprite, which is assumed to contain a short line segment, tangent to a circle.
| t | Enumerated type for sprites. |
| line | Line A line sprite. |
| pos | Position of center of circle in world space. |
| r | Radius of circle in world space units. |
| void Sage::CSpriteRenderer::DrawLine | ( | t | line, |
| const Vector2 & | p0, | ||
| const Vector2 & | p1 ) |
Draw a line by stretching a sprite, which is assumed to contain a short line segment.
| t | Enumerated type for sprites. |
| line | Line A line sprite. |
| p0 | Position of one end of the sprite in world space. |
| p1 | Position of the other end of the sprite in world space. |
| void Sage::CSpriteRenderer::DrawLine | ( | t | line, |
| const Vector2 & | p0, | ||
| const Vector2 & | p1, | ||
| XMVECTORF32 | c ) |
Draw a line by stretching a sprite, which is assumed to contain a short line segment.
| t | Enumerated type for sprites. |
| line | Line A line sprite. |
| p0 | Position of one end of the sprite in world space. |
| p1 | Position of the other end of the sprite in world space. |
| c | line color, such as Colors::Aqua. |
|
virtual |
End the SpriteBatch frame and present.
Reimplemented from Sage::CRenderer3D.
| const BoundingBox CSpriteRenderer::GetAabb | ( | UINT | n, |
| UINT | m ) const |
Construct the AABB for a sprite frame.
| n | Sprite index. |
| m | Frame number. |
| const Vector3 & CSpriteRenderer::GetCameraPos | ( | ) | const |
Reader function for camera position.
| const float Sage::CSpriteRenderer::GetHeight | ( | t | e | ) | const |
Reader function for the height of frame zero of a sprite.
| t | Sprite enumerated type. |
| e | Sprite type. |
| const size_t Sage::CSpriteRenderer::GetNumFrames | ( | t | e | ) | const |
Reader function for number of frames in sprite.
| t | Sprite enumerated type. |
| e | Sprite type. |
| void Sage::CSpriteRenderer::GetSize | ( | t | e, |
| float & | x, | ||
| float & | y ) const |
Reader function for the width and height of frame zero of a sprite.
| t | Sprite enumerated type. |
| e | Sprite type. |
| x | [out] Width of frame in pixels. |
| y | [out] Height of frame in pixels. |
| void Sage::CSpriteRenderer::GetSize | ( | t | e, |
| UINT | m, | ||
| float & | x, | ||
| float & | y ) const |
Reader function for the width and height of a sprite frame.
| t | Sprite enumerated type. |
| e | Sprite type. |
| m | [in] Frame number, assumed to be in range. |
| x | [out] Width of frame in pixels. |
| y | [out] Height of frame in pixels. |
| const float Sage::CSpriteRenderer::GetWidth | ( | t | e | ) | const |
Reader function for the width of frame zero of a sprite.
| t | Sprite enumerated type. |
| e | Sprite type. |
| void CSpriteRenderer::Initialize | ( | size_t | n | ) |
Reserve space for the sprites, create sprite effect and create vertex and index buffers if the renderer is not in batched mode.
| n | Number of sprites. |
| void Sage::CSpriteRenderer::Load | ( | Sage::CMediaList< t > & | media | ) |
Load sprites synchronously from a media descriptor.
| t | Sprite enumerated type. |
| media | Media list. |
| void Sage::CSpriteRenderer::Load | ( | t | e, |
| const char * | name ) |
Load information about a sprite from global variable g_xmlSettings, then load the sprite images as per that information. Abort if something goes wrong. Uses LoadByIndex() to do the actual work.
| t | Sprite enumerated type. |
| e | Sprite type. |
| name | Sprite name in XML file. |
|
protected |
Given a file name and extension such as foo and png, read in sprite frames from foo0.png, foo1.png, etc.
| nIndex | Sprite index. |
| szFile | Null-terminated file name (without extension). |
| szExt | Null-terminated file extension. |
| nFrames | Number of frames. |
|
protected |
Load information about the sprite from member variable m_pXmlSettings, then load the sprite images as per that information. Abort if something goes wrong.
| index | Sprite index. |
| name | Object name in XML file. |
| const bool CSpriteRenderer::Loaded | ( | ) | const |
Reader function for the loaded flag m_bLoaded.
| void Sage::CSpriteRenderer::LoadMT | ( | Sage::CMediaList< t > & | media | ) |
Load sounds asynchronously from a media descriptor, that is, spawn a thread to do the loading. Member variable m_bLoaded will be set to true when loading is finished.
| t | Sprite enumerated type. |
| media | Media list. |
| void CSpriteRenderer::SetCameraPos | ( | const Vector3 & | pos | ) |
Set the camera position.
| pos | New camera position. |