OpenTTD Source 20250312-master-gcdcc6b491d
OpenGLSprite Class Reference

Class that encapsulates a RGBA texture together with a paletted remap texture. More...

#include <opengl.h>

Public Member Functions

 OpenGLSprite (const SpriteLoader::SpriteCollection &sprite)
 Create an OpenGL sprite with a palette remap part.
 
 OpenGLSprite (const OpenGLSprite &)=delete
 
 OpenGLSprite (OpenGLSprite &&)=delete
 
OpenGLSpriteoperator= (const OpenGLSprite &)=delete
 
OpenGLSpriteoperator= (OpenGLSprite &&)=delete
 
void Update (uint width, uint height, uint level, const SpriteLoader::CommonPixel *data)
 Update a single mip-map level with new pixel data.
 
Dimension GetSize (ZoomLevel level) const
 Query the sprite size at a certain zoom level.
 

Private Types

enum  Texture : uint8_t { TEX_RGBA , TEX_REMAP , NUM_TEX }
 Enum of all used OpenGL texture objects. More...
 

Private Member Functions

bool BindTextures ()
 Bind textures for rendering this sprite.
 

Static Private Member Functions

static bool Create ()
 Create all common resources for sprite rendering.
 
static void Destroy ()
 Free all common resources for sprite rendering.
 

Private Attributes

Dimension dim
 
GLuint tex [NUM_TEX]
 The texture objects.
 
int16_t x_offs
 Number of pixels to shift the sprite to the right.
 
int16_t y_offs
 Number of pixels to shift the sprite downwards.
 

Static Private Attributes

static GLuint dummy_tex [NUM_TEX] = { 0, 0 }
 1x1 dummy textures to substitute for unused sprite components.
 
static GLuint pal_identity = 0
 Identity texture mapping.
 
static GLuint pal_tex = 0
 Texture for palette remap.
 
static GLuint pal_pbo = 0
 Pixel buffer object for remap upload.
 

Friends

class OpenGLBackend
 

Detailed Description

Class that encapsulates a RGBA texture together with a paletted remap texture.

Definition at line 115 of file opengl.h.

Member Enumeration Documentation

◆ Texture

enum OpenGLSprite::Texture : uint8_t
private

Enum of all used OpenGL texture objects.

Enumerator
TEX_RGBA 

RGBA texture part.

TEX_REMAP 

Remap texture part.

Definition at line 118 of file opengl.h.

Constructor & Destructor Documentation

◆ OpenGLSprite()

OpenGLSprite::OpenGLSprite ( const SpriteLoader::SpriteCollection sprite)

Create an OpenGL sprite with a palette remap part.

Parameters
spriteThe sprite to create the OpenGL sprite for

Definition at line 1400 of file opengl.cpp.

References Font, MemSetT(), Palette, tex, TEX_REMAP, TEX_RGBA, Update(), ZOOM_LVL_END, and ZOOM_LVL_MIN.

◆ ~OpenGLSprite()

OpenGLSprite::~OpenGLSprite ( )

Definition at line 1445 of file opengl.cpp.

Member Function Documentation

◆ BindTextures()

bool OpenGLSprite::BindTextures ( )
private

Bind textures for rendering this sprite.

Returns
True if the sprite has RGBA data.

Definition at line 1515 of file opengl.cpp.

References tex, TEX_REMAP, and TEX_RGBA.

Referenced by OpenGLBackend::RenderOglSprite().

◆ Create()

bool OpenGLSprite::Create ( )
staticprivate

Create all common resources for sprite rendering.

Returns
True if no error occurred.

Definition at line 1327 of file opengl.cpp.

References dummy_tex, pal_identity, pal_pbo, pal_tex, TEX_REMAP, and TEX_RGBA.

Referenced by OpenGLBackend::Init().

◆ Destroy()

void OpenGLSprite::Destroy ( )
staticprivate

Free all common resources for sprite rendering.

Definition at line 1388 of file opengl.cpp.

References dummy_tex, pal_identity, pal_pbo, and pal_tex.

Referenced by OpenGLBackend::~OpenGLBackend().

◆ GetSize()

Dimension OpenGLSprite::GetSize ( ZoomLevel  level) const
inline

Query the sprite size at a certain zoom level.

Parameters
levelThe zoom level to query.
Returns
Sprite size at the given zoom level.

Definition at line 1505 of file opengl.cpp.

References UnScaleByZoomLower().

Referenced by OpenGLBackend::RenderOglSprite().

◆ Update()

void OpenGLSprite::Update ( uint  width,
uint  height,
uint  level,
const SpriteLoader::CommonPixel data 
)

Update a single mip-map level with new pixel data.

Parameters
widthWidth of the level.
heightHeight of the level.
levelMip-map level.
dataNew pixel data.

Definition at line 1457 of file opengl.cpp.

References SpriteLoader::CommonPixel::a, Align(), ReusableBuffer< T >::Allocate(), SpriteLoader::CommonPixel::b, SpriteLoader::CommonPixel::g, ReusableBuffer< T >::GetBuffer(), SpriteLoader::CommonPixel::m, SpriteLoader::CommonPixel::r, tex, TEX_REMAP, and TEX_RGBA.

Referenced by OpenGLSprite().

Friends And Related Symbol Documentation

◆ OpenGLBackend

friend class OpenGLBackend
friend

Definition at line 153 of file opengl.h.

Field Documentation

◆ dim

Dimension OpenGLSprite::dim
private

Definition at line 124 of file opengl.h.

◆ dummy_tex

GLuint OpenGLSprite::dummy_tex = { 0, 0 }
staticprivate

1x1 dummy textures to substitute for unused sprite components.

Definition at line 1318 of file opengl.h.

Referenced by Create(), and Destroy().

◆ pal_identity

GLuint OpenGLSprite::pal_identity = 0
staticprivate

Identity texture mapping.

Definition at line 131 of file opengl.h.

Referenced by Create(), Destroy(), and OpenGLBackend::RenderOglSprite().

◆ pal_pbo

GLuint OpenGLSprite::pal_pbo = 0
staticprivate

Pixel buffer object for remap upload.

Definition at line 133 of file opengl.h.

Referenced by Create(), Destroy(), and OpenGLBackend::RenderOglSprite().

◆ pal_tex

GLuint OpenGLSprite::pal_tex = 0
staticprivate

Texture for palette remap.

Definition at line 132 of file opengl.h.

Referenced by Create(), Destroy(), and OpenGLBackend::RenderOglSprite().

◆ tex

GLuint OpenGLSprite::tex[NUM_TEX]
private

The texture objects.

Definition at line 125 of file opengl.h.

Referenced by BindTextures(), OpenGLSprite(), and Update().

◆ x_offs

int16_t OpenGLSprite::x_offs
private

Number of pixels to shift the sprite to the right.

Definition at line 126 of file opengl.h.

Referenced by OpenGLBackend::DrawMouseCursor().

◆ y_offs

int16_t OpenGLSprite::y_offs
private

Number of pixels to shift the sprite downwards.

Definition at line 127 of file opengl.h.

Referenced by OpenGLBackend::DrawMouseCursor().


The documentation for this class was generated from the following files: