![]() |
The LARC Game Engine
A Simple Game Engine from the Laboratory for Recreational Computing
|
The sprite renderer class. More...
#include <SpriteRenderer.h>
Public Member Functions | |
LSpriteRenderer (eSpriteMode) | |
Constructor. More... | |
virtual | ~LSpriteRenderer () |
Destructor. More... | |
template<class t > | |
void | Initialize (t n) |
Initialize. More... | |
void | BeginFrame () |
Begin frame. More... | |
void | EndFrame () |
End frame. More... | |
void | Draw (const LSpriteDesc2D *) |
Draw single 2D sprite. More... | |
template<class t > | |
void | Draw (t, const Vector2 &, float=0) |
Draw single 2D sprite. More... | |
template<class t > | |
void | DrawLine (t, const Vector2 &, const Vector2 &) |
Draw 2D line. More... | |
template<class t > | |
void | DrawBoundingBox (t, const BoundingBox &) |
Draw AABB. More... | |
void | Draw (const LSpriteDesc3D *) |
Draw single 3D sprite. More... | |
void | Draw (std::vector< LSpriteDesc3D > &) |
Draw list of 3D sprites. More... | |
void | SetCameraPos (const Vector3 &) |
Set camera position. More... | |
const Vector3 & | GetCameraPos () const |
Get camera position. More... | |
template<class t > | |
void | Load (t, const char *) |
Load sprite. More... | |
template<class t > | |
const float | GetWidth (t) const |
Get sprite width. More... | |
template<class t > | |
const float | GetHeight (t) const |
Get sprite height. More... | |
template<class t > | |
void | GetSize (t, float &, float &) const |
Get sprite size. More... | |
template<class t > | |
void | GetSize (t, UINT, float &, float &) const |
Get sprite size. More... | |
template<class t > | |
const size_t | GetNumFrames (t) 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... | |
![]() | |
LRenderer3D () | |
Constructor. | |
virtual | ~LRenderer3D () |
Destructor. | |
void | Initialize (bool=true) |
Initialize renderer. More... | |
void | LoadTexture (const char *, LTextureDesc &) |
Load texture. More... | |
void | LoadTextureFile (const char *, LTextureDesc &) |
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... | |
![]() | |
template<typename t0 , typename t1 , typename t2 > | |
int | WinMain (_In_ HINSTANCE, bool, const t0 &, const t1 &, const t2 &) |
WinMain. | |
![]() | |
void | Load () |
Load game settings. More... | |
Protected Member Functions | |
void | LoadByIndex (UINT, const char *) |
Load sprite by index. More... | |
LSprite * | 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... | |
![]() | |
void | CreateDDSTexture (_In_z_ const wchar_t *, LTextureDesc &) |
Load a texture from a DirectDraw surface file (contains mipmaps). More... | |
void | CreateWICTexture (_In_z_ const wchar_t *, LTextureDesc &) |
Load a texture from a an image file (does not contain mipmaps). More... | |
void | ProcessTexture (_In_ ComPtr< ID3D12Resource >, LTextureDesc &) |
Process a loaded texture. More... | |
void | LoadScreenFont () |
Load screen font. More... | |
![]() | |
void | SetWinSize (int, int) |
Set window size information. More... | |
Protected Attributes | |
eSpriteMode | m_eRenderMode = eSpriteMode::Batched2D |
Sprite render mode. | |
LBaseCamera * | m_pCamera = nullptr |
Pointer to the camera. | |
LSprite ** | m_pSprite = nullptr |
Sprite pointers. | |
size_t | m_nNumSprites = 0 |
Number of sprites. | |
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. | |
![]() | |
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< 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 LTimer * | m_pTimer = &cTimer |
Pointer to a timer. More... | |
static LRandom * | m_pRandom = &cRandom |
Pointer to a PRNG. More... | |
static LKeyboard * | m_pKeyboard = &cKeyboard |
Pointer to a keyboard handler. More... | |
static LXBoxController * | m_pController = &cController |
Pointer to a XBox controller. More... | |
static LSound * | m_pAudio = &cAudio |
Pointer to an audio player. More... | |
![]() | |
static XMFLOAT4X4 | m_orient |
Orientation matrix. | |
static XMFLOAT4X4 | m_view |
View matrix. | |
static XMFLOAT4X4 | m_projection |
Projection matrix. | |
![]() | |
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 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 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.
LSpriteRenderer::LSpriteRenderer | ( | 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 LRenderer3D.
const bool LSpriteRenderer::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 LSpriteRenderer::Draw | ( | const LSpriteDesc2D * | sd | ) |
Draw a sprite in 2D.
sd | Const pointer to 2D sprite descriptor. |
void LSpriteRenderer::Draw | ( | const LSpriteDesc3D * | sd | ) |
Draw a sprite in 3D.
sd | Const pointer to 3D sprite descriptor. |
void LSpriteRenderer::Draw | ( | std::vector< LSpriteDesc3D > & | 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 LSpriteRenderer::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 LSpriteRenderer::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 LSpriteRenderer::DrawLine | ( | t | 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.
t | Enumerated type for sprites. |
n | Line sprite type. |
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 LRenderer3D.
const BoundingBox LSpriteRenderer::GetAabb | ( | int | n, |
int | m | ||
) | const |
Construct the AABB for a sprite frame.
n | Sprite index. |
m | Frame number. |
const Vector3 & LSpriteRenderer::GetCameraPos | ( | ) | const |
Reader function for camera position.
const float LSpriteRenderer::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 LSpriteRenderer::GetNumFrames | ( | t | e | ) | const |
Reader function for number of frames in sprite.
t | Sprite enumerated type. |
e | Sprite type. |
void LSpriteRenderer::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 LSpriteRenderer::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 LSpriteRenderer::GetWidth | ( | t | e | ) | const |
Reader function for the width of frame zero of a sprite.
t | Sprite enumerated type. |
e | Sprite type. |
void LSpriteRenderer::Initialize | ( | t | n | ) |
Reserve space for the sprites, create sprite effect and create vertex and index buffers if the renderer is not in batched mode.
t | Sprite enumerated type. |
n | Number of sprites. |
void LSpriteRenderer::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.
index | Sprite index. |
file | File name prefix. |
ext | File name extension. |
frames | Number of frames. |
|
protected |
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 LSpriteRenderer::SetCameraPos | ( | const Vector3 & | pos | ) |
Set the camera position.
pos | New camera position. |