![]() |
The LARC Game Engine
A Simple Game Engine from the Laboratory for Recreational Computing
|
The sprite renderer class. More...
#include <SpriteRenderer.h>
Public Types | |
| enum | eRenderMode { Batched2D, Unbatched2D, Unbatched3D } |
| Render mode type. More... | |
Public Member Functions | |
| CSpriteRenderer (eRenderMode) | |
| Constructor. More... | |
| virtual | ~CSpriteRenderer () |
| Destructor. More... | |
| void | Initialize (size_t n) |
| Initialize. More... | |
| void | BeginFrame () |
| Begin frame. More... | |
| void | EndFrame () |
| End frame. More... | |
| void | Draw (const CSpriteDesc2D &) |
| Draw single 2D sprite. More... | |
| void | Draw (int n, const Vector2 &, float=0) |
| Draw single 2D sprite. More... | |
| void | DrawLine (UINT, const Vector2 &, const Vector2 &) |
| Draw 2D line. More... | |
| void | Draw (const CSpriteDesc3D &) |
| Draw single 3D sprite. More... | |
| void | Draw (vector< CSpriteDesc3D > &) |
| Draw list of 3D sprites. More... | |
| void | SetCameraPos (const Vector3 &) |
| Set camera position. More... | |
| const Vector3 & | GetCameraPos () const |
| Get camera position. More... | |
| void | Load (UINT, const char *) |
| Load sprite. More... | |
| const float | GetWidth (UINT) const |
| Get sprite width. More... | |
| const float | GetHeight (UINT) const |
| Get sprite height. More... | |
| void | GetSize (UINT, float &, float &) const |
| Get sprite size. More... | |
| void | GetSize (UINT, UINT, float &, float &) const |
| Get sprite size. More... | |
| const size_t | GetNumFrames (UINT) const |
| Get number of frames. More... | |
| const BoundingBox | GetAabb (int, int) const |
| Get bounding box. More... | |
| const bool | BoxInFrustum (const BoundingBox &) const |
| Does the box overlap the view frustum? More... | |
Public Member Functions inherited from CRenderer3D | |
| CRenderer3D () | |
| Constructor. | |
| virtual | ~CRenderer3D () |
| Destructor. | |
| void | Initialize (bool=true) |
| Initialize renderer. More... | |
| void | LoadTexture (const char *, CTextureDesc &) |
| Load texture. More... | |
| void | LoadTextureFile (const char *, CTextureDesc &) |
| Load texture from file. More... | |
| void | BeginResourceUpload () |
| Begin uploading textures. More... | |
| void | EndResourceUpload () |
| End uploading textures. More... | |
| void | SetBgColor (const XMVECTORF32 &) |
| Set default background color. More... | |
| void | DrawScreenText (const char *, const Vector2 &, XMVECTORF32=Colors::Black) |
| Draw screen text. More... | |
| void | DrawScreenText (const wchar_t *, const Vector2 &, XMVECTORF32=Colors::Black) |
| Draw screen text, wide version. More... | |
| void | DrawCenteredText (const char *, XMVECTORF32=Colors::Black) |
| Draw centered text. More... | |
| void | DrawCenteredText (const wchar_t *, XMVECTORF32=Colors::Black) |
| Draw centered text, wide version. More... | |
| void | SaveScreenShot () |
| Save a screenshot. More... | |
| virtual void | OnDeviceLost () override |
| Handler for device lost notification. More... | |
| virtual void | OnDeviceRestored () override |
| Handler for device restored notification. More... | |
Public Member Functions inherited from 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 CSettingsManager | |
| void | Load () |
| Load game settings. More... | |
Protected Member Functions | |
| CSprite * | Load (UINT, const char *, const char *, UINT) |
| Load sprite. More... | |
| void | CreateEffect () |
| Create effect. More... | |
| void | CreateVertexBuffer () |
| Create vertex buffer. More... | |
| void | CreateIndexBuffer () |
| Create index buffer. More... | |
Protected Member Functions inherited from CRenderer3D | |
| void | CreateDDSTexture (_In_z_ const wchar_t *, CTextureDesc &) |
| Load a texture from a DirectDraw surface file (contains mipmaps). More... | |
| void | CreateWICTexture (_In_z_ const wchar_t *, CTextureDesc &) |
| Load a texture from a an image file (does not contain mipmaps). More... | |
| void | ProcessTexture (_In_ ComPtr< ID3D12Resource >, CTextureDesc &) |
| Process a loaded texture. More... | |
| void | LoadScreenFont () |
| Load screen font. More... | |
Protected Member Functions inherited from CSettingsManager | |
| void | SetWinSize (int, int) |
| Set window size information. More... | |
Protected Attributes | |
| eRenderMode | m_eRenderMode = Batched2D |
| Sprite render mode. | |
| CBaseCamera * | m_pCamera = nullptr |
| Pointer to the camera. | |
| CSprite ** | m_pSprite = nullptr |
| Sprite pointers. | |
| size_t | m_nNumSprites = 0 |
| Number of sprites. | |
| unique_ptr< BasicEffect > | m_pSpriteEffect |
| Sprite effect. | |
| GraphicsResource | m_VertexBuffer |
| Vertex buffer. | |
| GraphicsResource | m_IndexBuffer |
| Index buffer. | |
| UINT | m_nIndexCount = 0 |
| Number of indexes in the index buffer. | |
| shared_ptr< D3D12_VERTEX_BUFFER_VIEW > | m_pVBufView |
| Vertex buffer view. | |
| 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 CRenderer3D | |
| unique_ptr< GraphicsMemory > | m_pGraphicsMemory |
| Pointer to graphics memory. | |
| unique_ptr< DescriptorHeap > | m_pDescriptorHeap |
| Pointer to a descriptor heap. | |
| UINT | m_nNumResourceDesc = 0 |
| Number of resource descriptors in descriptor heap. | |
| unique_ptr< CommonStates > | m_pStates |
| Pointer to render state object. | |
| unique_ptr< SpriteBatch > | m_pSpriteBatch |
| SpriteBatch object for rendering sprites in screen space (from the DirectXTK). | |
| unique_ptr< PrimitiveBatch< VertexPositionColor > > | m_pPrimitiveBatch |
| PrimitiveBatch object from the DirectXTK. | |
| unique_ptr< SpriteBatch > | m_pTextSpriteBatch |
| SpriteBatch object for rendering text in screen space. | |
| unique_ptr< SpriteFont > | m_pFont |
| Text font. | |
| unique_ptr< 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] |
| 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 Attributes inherited from CComponent | |
| static CStepTimer * | m_pStepTimer = &cStepTimer |
| Pointer to a step timer. More... | |
| static CRandom * | m_pRandom = &cRandom |
| Pointer to a PRNG. More... | |
| static CKeyboard * | m_pKeyboard = &cKeyboard |
| Pointer to a keyboard handler. More... | |
| static CXBoxController * | m_pController = &cController |
| Pointer to a XBox controller. More... | |
| static CAudio * | m_pAudio = &cAudio |
| Pointer to an audio player. More... | |
Static Protected Attributes inherited from CCameraCommon | |
| static XMFLOAT4X4 | m_orient |
| Orientation matrix. | |
| static XMFLOAT4X4 | m_view |
| View matrix. | |
| static XMFLOAT4X4 | m_projection |
| Projection matrix. | |
Static Protected Attributes inherited from CWindowDesc | |
| static HWND | m_Hwnd = 0 |
| Window handle. | |
| static HINSTANCE | m_hInst = 0 |
| Instance handle. | |
| static bool | m_bExitSizeMove |
| User just finished moving/resizing window. | |
Static Protected Attributes inherited from CSettingsManager | |
| static 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 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. | |
A renderer that will draw sprites in 2D and 3D.
Render modes supported are batched 2D (which uses SpriteBatch from DirectXTK 12 for speed), and unbatched 2D and 3D.
| CSpriteRenderer::CSpriteRenderer | ( | eRenderMode | 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 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 | 2D sprite descriptor. |
| void CSpriteRenderer::Draw | ( | int | 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.
| n | Sprite index. |
| pos | Position in world space. |
| a | Orientation angle (roll) in radians. |
| void CSpriteRenderer::Draw | ( | const CSpriteDesc3D & | sd | ) |
Draw a sprite in 3D.
| sd | 3D sprite descriptor. |
| void CSpriteRenderer::Draw | ( | 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 CSpriteRenderer::DrawLine | ( | UINT | n, |
| const Vector2 & | p0, | ||
| const Vector2 & | p1 | ||
| ) |
Draw a line by or by stretching a sprite, which is assumed to contain a short line segment.
| n | Line sprite index. |
| p0 | Position of one end of the sprite in world space. |
| p1 | Position of the other end of the sprite in world space. |
|
virtual |
End the SpriteBatch frame and present.
Reimplemented from CRenderer3D.
| const BoundingBox CSpriteRenderer::GetAabb | ( | int | n, |
| int | 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 CSpriteRenderer::GetHeight | ( | UINT | n | ) | const |
Reader function for the height of frame zero of a sprite.
| n | Sprite index, assumed to be in range. |
| const size_t CSpriteRenderer::GetNumFrames | ( | UINT | n | ) | const |
Reader function for number of frames in sprite.
| n | Sprite index. |
| void CSpriteRenderer::GetSize | ( | UINT | n, |
| float & | x, | ||
| float & | y | ||
| ) | const |
Reader function for the width and height of frame zero of a sprite.
| n | [in] Sprite index, assumed to be in range. |
| x | [out] Width of frame in pixels. |
| y | [out] Height of frame in pixels. |
| void CSpriteRenderer::GetSize | ( | UINT | n, |
| UINT | m, | ||
| float & | x, | ||
| float & | y | ||
| ) | const |
Reader function for the width and height of a sprite frame.
| n | [in] Sprite index, assumed to be in range. |
| 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 CSpriteRenderer::GetWidth | ( | UINT | n | ) | const |
Reader function for the width of frame zero of a sprite.
| n | Sprite index, assumed to be in range. |
| 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. |
|
protected |
Given a file name and extension such as foo and png, read in sprite frames from foo0.png, foo1.png, etc.
| index | Sprite index. |
| file | File name prefix |
| ext | File name extension |
| frames | Number of frames |
| void CSpriteRenderer::Load | ( | UINT | index, |
| const char * | name | ||
| ) |
Load information about the sprite from global variable g_xmlSettings, then load the sprite images as per that information. Abort if something goes wrong.
| index | Sprite index. |
| name | Object name in XML file. |
| void CSpriteRenderer::SetCameraPos | ( | const Vector3 & | pos | ) |
Set the camera position.
| pos | New camera position. |
1.8.14