SpriteRenderer Class Reference

SpriteRenderer wraps batch rendering of sprites in a simple BeginSprites / AddSprite x N / EndSprite API. More...

List of all members.

Classes

class  DefaultFontShader_
 Font's default shader. More...
class  DefaultShader_
 Sprites's default shader: texture modulated by a color. More...
interface  ISpriteShader
 That's all the interface we require from the shaders set by user. More...

Public Member Functions

 SpriteRenderer (GraphicsContextAlpha gl, uint max_sprites)
 SpriteRenderer constructor.
void Dispose ()
 Dispose implementation.
Bounds2 DrawTextDebug (string str, Vector2 bottom_left_start_pos, float char_height, bool draw=true, ISpriteShader shader=null)
 Debug text draw function, using a small embedded font suitable for on screen debug prints.
Bounds2 DrawTextWithFontMap (string str, Vector2 bottom_left_start_pos, float char_height, bool draw, FontMap fontmap, ISpriteShader shader)
 This text draw function uses a FontMap object.
Bounds2 DrawTextWithFontMap (string str, Vector2 bottom_left_start_pos, float char_height, bool draw, FontMap fontmap)
 This text draw function uses a FontMap object and SpriteRenderer's DefaultShader.
void BeginSprites (TextureInfo texture_info, ISpriteShader shader, int num_sprites)
 Start batch rendering of sprites.
void BeginSprites (TextureInfo texture_info, int num_sprites)
 Start batch rendering of sprites.
void EndSprites ()
 End batch rendering of sprites.
void AddSprite (ref TRS quad, Vector2i tile_index)
 Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.
void AddSprite (ref TRS quad, Vector2i tile_index, ref Matrix3 mat)
 Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.
void AddSprite (ref TRS quad, ref TRS uv)
 Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.
void AddSprite (ref TRS quad, ref TRS uv, ref Matrix3 mat)
 Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.
void AddSprite (Vector2 bottom_left_start_pos, Vector2 x, Bounds2 uv_bounds)
 Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.
void AddSprite (Vector4 v0, Vector4 v1, Vector4 v2, Vector4 v3)
 Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.

Public Attributes

bool FlipU = false
 Flag that will swap the U coordinates (horizontally) of all rendered sprites/quads.
bool FlipV = false
 Flag that will swap the V coordinates (vertically) of all rendered sprites/quads.

Properties

DefaultShader_ DefaultShader [get]
 The default shader used by SpriteRenderer.
DefaultFontShader_ DefaultFontShader [get]
 The default font shader used by SpriteRenderer.
bool Disposed [get]
 Return true if this object been disposed.

Detailed Description

SpriteRenderer wraps batch rendering of sprites in a simple BeginSprites / AddSprite x N / EndSprite API.

It also provides some text rendering functions that uses FontMap.


Member Function Documentation

void AddSprite ( ref TRS  quad,
Vector2i  tile_index 
)

Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.

Parameters:
quadThe sprite geometry.
tile_indexSprite UVs are specified by a tile index.
void AddSprite ( ref TRS  quad,
Vector2i  tile_index,
ref Matrix3  mat 
)

Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.

Parameters:
quadThe sprite geometry.
tile_indexSprite UVs are specified by a tile index.
matA per sprite transform matrix.
void AddSprite ( ref TRS  quad,
ref TRS  uv 
)

Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.

Parameters:
quadThe sprite geometry.
uvSprite UVs are specified directly using a TRS object.
void AddSprite ( ref TRS  quad,
ref TRS  uv,
ref Matrix3  mat 
)

Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.

Parameters:
quadThe sprite geometry.
uvSprite UVs are specified directly using a TRS object.
matA per sprite transform matrix.
void AddSprite ( Vector2  bottom_left_start_pos,
Vector2  x,
Bounds2  uv_bounds 
)

Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.

One vector is enough to determine the orientation and scale of the sprite. The aspect ratio is by default the same was the size of the 'uv' domain covered (in texels).

Parameters:
xThe len and direction of the bottom edge of the sprite.
bottom_left_start_posThe bottom left point of the sprite.
uv_boundsThe uv bounds (Bounds2 in uv domain).
void AddSprite ( Vector4  v0,
Vector4  v1,
Vector4  v2,
Vector4  v3 
)

Add a sprite to batch rendering of sprites, must be called between BeginSprites and EndSprites.

In this version user specify 4 vertices as Vector4, where each Vector4's xy is the position of the vertex, and zw is the UV.

void BeginSprites ( TextureInfo  texture_info,
int  num_sprites 
)

Start batch rendering of sprites.

Parameters:
texture_infoThe texture object.
num_spritesThe maximum number of sprite you intend to draw.
void BeginSprites ( TextureInfo  texture_info,
ISpriteShader  shader,
int  num_sprites 
)

Start batch rendering of sprites.

Parameters:
texture_infoThe texture object.
shaderThe shader object.
num_spritesThe maximum number of sprite you intend to draw.
Bounds2 DrawTextDebug ( string  str,
Vector2  bottom_left_start_pos,
float  char_height,
bool  draw = true,
ISpriteShader  shader = null 
)

Debug text draw function, using a small embedded font suitable for on screen debug prints.

Since DrawTextDebug uses very small font data, it only work with ascii text (characters from ' ' to '~', 32 to 126) Any character outside this range will be displayed as '?'. For instance "こんにちは" will be displayed as "?????".

Parameters:
strThe text to draw.
bottom_left_start_posThe bottom left of the text rectangle, in world space/units.
char_heightThe character height in world space/units.
drawIf false, don't draw anything, just return the Bounds2 used by the text.
shaderIf no shader is specified, DefaultFontShader is used.
Returns:
The rectangle area covered by rendered text (call with draw=false when you want to know the covered area before actually drawing it).
Bounds2 DrawTextWithFontMap ( string  str,
Vector2  bottom_left_start_pos,
float  char_height,
bool  draw,
FontMap  fontmap 
)

This text draw function uses a FontMap object and SpriteRenderer's DefaultShader.

Parameters:
strThe text to draw.
bottom_left_start_posThe bottom left of the text rectangle, in world space/units.
char_heightThe character height in world space/units.
drawIf false, don't draw anything, just return the Bounds2 used by the text.
fontmapthe fontmap object (that holds the texture).
Bounds2 DrawTextWithFontMap ( string  str,
Vector2  bottom_left_start_pos,
float  char_height,
bool  draw,
FontMap  fontmap,
ISpriteShader  shader 
)

This text draw function uses a FontMap object.

Parameters:
strThe text to draw.
bottom_left_start_posThe bottom left of the text rectangle, in world space/units.
char_heightThe character height in world space/units.
drawIf false, don't draw anything, just return the Bounds2 used by the text.
fontmapthe fontmap object (that holds the texture).
shaderThe shader defaults to SpriteRenderer.DefaultFontShader.