yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gfx::AtlasRenderer Class Reference

Atlas-based rendering system for efficient graphics operations. More...

#include <atlas_renderer.h>

Collaboration diagram for yaze::gfx::AtlasRenderer:

Classes

struct  Atlas
 
struct  AtlasEntry
 

Public Member Functions

void Initialize (IRenderer *renderer, int initial_size=1024)
 Initialize the atlas renderer.
 
int AddBitmap (const Bitmap &bitmap)
 Add a bitmap to the atlas.
 
int AddBitmapWithBppOptimization (const Bitmap &bitmap, BppFormat target_bpp)
 Add a bitmap to the atlas with BPP format optimization.
 
void RemoveBitmap (int atlas_id)
 Remove a bitmap from the atlas.
 
void UpdateBitmap (int atlas_id, const Bitmap &bitmap)
 Update a bitmap in the atlas.
 
void RenderBatch (const std::vector< RenderCommand > &render_commands)
 Render multiple bitmaps in a single draw call.
 
void RenderBatchWithBppOptimization (const std::vector< RenderCommand > &render_commands, const std::unordered_map< BppFormat, std::vector< int > > &bpp_groups)
 Render multiple bitmaps with BPP-aware batching.
 
AtlasStats GetStats () const
 Get atlas statistics.
 
void Defragment ()
 Defragment the atlas to reclaim space.
 
void Clear ()
 Clear all atlases.
 
void RenderBitmap (int atlas_id, float x, float y, float scale_x=1.0f, float scale_y=1.0f)
 Render a single bitmap using atlas (convenience method)
 
SDL_Rect GetUVCoordinates (int atlas_id) const
 Get UV coordinates for a bitmap in the atlas.
 

Static Public Member Functions

static AtlasRendererGet ()
 

Private Member Functions

 AtlasRenderer ()=default
 
 ~AtlasRenderer ()
 
bool PackBitmap (Atlas &atlas, const Bitmap &bitmap, SDL_Rect &uv_rect)
 
void CreateNewAtlas ()
 
void RebuildAtlas (Atlas &atlas)
 
SDL_Rect FindFreeRegion (Atlas &atlas, int width, int height)
 
void MarkRegionUsed (Atlas &atlas, const SDL_Rect &rect, bool used)
 

Private Attributes

IRendererrenderer_
 
std::vector< std::unique_ptr< Atlas > > atlases_
 
std::unordered_map< int, AtlasEntry * > atlas_lookup_
 
int next_atlas_id_
 
int current_atlas_
 

Detailed Description

Atlas-based rendering system for efficient graphics operations.

The AtlasRenderer class provides efficient rendering by combining multiple graphics elements into a single texture atlas, reducing draw calls and improving performance for ROM hacking workflows.

Key Features:

  • Single draw call for multiple tiles/graphics
  • Automatic atlas management and packing
  • Dynamic atlas resizing and reorganization
  • UV coordinate mapping for efficient rendering
  • Memory-efficient texture management

Performance Optimizations:

  • Reduces draw calls from N to 1 for multiple elements
  • Minimizes GPU state changes
  • Efficient texture packing algorithm
  • Automatic atlas defragmentation

ROM Hacking Specific:

  • Optimized for SNES tile rendering (8x8, 16x16)
  • Support for graphics sheet atlasing
  • Efficient palette management across atlas
  • Tile-based UV coordinate system

Definition at line 74 of file atlas_renderer.h.

Constructor & Destructor Documentation

◆ AtlasRenderer()

yaze::gfx::AtlasRenderer::AtlasRenderer ( )
privatedefault

◆ ~AtlasRenderer()

yaze::gfx::AtlasRenderer::~AtlasRenderer ( )
private

Definition at line 314 of file atlas_renderer.cc.

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ Get()

AtlasRenderer & yaze::gfx::AtlasRenderer::Get ( )
static

◆ Initialize()

void yaze::gfx::AtlasRenderer::Initialize ( IRenderer renderer,
int  initial_size = 1024 
)

Initialize the atlas renderer.

Parameters
rendererThe renderer to use for texture operations
initial_sizeInitial atlas size (power of 2 recommended)

Definition at line 15 of file atlas_renderer.cc.

References Clear(), CreateNewAtlas(), current_atlas_, next_atlas_id_, and renderer_.

Here is the call graph for this function:

◆ AddBitmap()

◆ AddBitmapWithBppOptimization()

int yaze::gfx::AtlasRenderer::AddBitmapWithBppOptimization ( const Bitmap bitmap,
BppFormat  target_bpp 
)

◆ RemoveBitmap()

void yaze::gfx::AtlasRenderer::RemoveBitmap ( int  atlas_id)

Remove a bitmap from the atlas.

Parameters
atlas_idAtlas ID of bitmap to remove

Definition at line 96 of file atlas_renderer.cc.

References atlas_lookup_, atlases_, yaze::gfx::AtlasRenderer::AtlasEntry::in_use, and MarkRegionUsed().

Referenced by UpdateBitmap().

Here is the call graph for this function:

◆ UpdateBitmap()

void yaze::gfx::AtlasRenderer::UpdateBitmap ( int  atlas_id,
const Bitmap bitmap 
)

Update a bitmap in the atlas.

Parameters
atlas_idAtlas ID of bitmap to update
bitmapNew bitmap data

Definition at line 118 of file atlas_renderer.cc.

References AddBitmap(), atlas_lookup_, yaze::gfx::Bitmap::height(), RemoveBitmap(), yaze::gfx::AtlasRenderer::AtlasEntry::texture, yaze::gfx::Bitmap::texture(), yaze::gfx::AtlasRenderer::AtlasEntry::uv_rect, and yaze::gfx::Bitmap::width().

◆ RenderBatch()

void yaze::gfx::AtlasRenderer::RenderBatch ( const std::vector< RenderCommand > &  render_commands)

Render multiple bitmaps in a single draw call.

Parameters
render_commandsVector of render commands (atlas_id, x, y, scale)

Definition at line 135 of file atlas_renderer.cc.

References atlas_lookup_, atlases_, yaze::gfx::IRenderer::RenderCopy(), renderer_, and yaze::gfx::AtlasRenderer::AtlasEntry::uv_rect.

Here is the call graph for this function:

◆ RenderBatchWithBppOptimization()

void yaze::gfx::AtlasRenderer::RenderBatchWithBppOptimization ( const std::vector< RenderCommand > &  render_commands,
const std::unordered_map< BppFormat, std::vector< int > > &  bpp_groups 
)

Render multiple bitmaps with BPP-aware batching.

Parameters
render_commandsVector of render commands
bpp_groupsMap of BPP format to command groups for optimization

Definition at line 196 of file atlas_renderer.cc.

References atlas_lookup_, atlases_, yaze::gfx::IRenderer::RenderCopy(), renderer_, and yaze::gfx::AtlasRenderer::AtlasEntry::uv_rect.

Here is the call graph for this function:

◆ GetStats()

◆ Defragment()

void yaze::gfx::AtlasRenderer::Defragment ( )

Defragment the atlas to reclaim space.

Definition at line 285 of file atlas_renderer.cc.

References atlases_, and RebuildAtlas().

Here is the call graph for this function:

◆ Clear()

void yaze::gfx::AtlasRenderer::Clear ( )

Clear all atlases.

Definition at line 300 of file atlas_renderer.cc.

References atlas_lookup_, atlases_, current_atlas_, yaze::gfx::IRenderer::DestroyTexture(), next_atlas_id_, and renderer_.

Referenced by Initialize(), and ~AtlasRenderer().

Here is the call graph for this function:

◆ RenderBitmap()

void yaze::gfx::AtlasRenderer::RenderBitmap ( int  atlas_id,
float  x,
float  y,
float  scale_x = 1.0f,
float  scale_y = 1.0f 
)

Render a single bitmap using atlas (convenience method)

Parameters
atlas_idAtlas ID of bitmap to render
xX position on screen
yY position on screen
scale_xHorizontal scale factor
scale_yVertical scale factor

Definition at line 318 of file atlas_renderer.cc.

References atlas_lookup_, atlases_, yaze::gfx::IRenderer::RenderCopy(), renderer_, and yaze::gfx::AtlasRenderer::AtlasEntry::uv_rect.

Here is the call graph for this function:

◆ GetUVCoordinates()

SDL_Rect yaze::gfx::AtlasRenderer::GetUVCoordinates ( int  atlas_id) const

Get UV coordinates for a bitmap in the atlas.

Parameters
atlas_idAtlas ID of bitmap
Returns
UV rectangle (0-1 normalized coordinates)

Definition at line 347 of file atlas_renderer.cc.

References atlas_lookup_.

◆ PackBitmap()

bool yaze::gfx::AtlasRenderer::PackBitmap ( Atlas atlas,
const Bitmap bitmap,
SDL_Rect &  uv_rect 
)
private

Definition at line 356 of file atlas_renderer.cc.

References FindFreeRegion(), yaze::gfx::Bitmap::height(), MarkRegionUsed(), and yaze::gfx::Bitmap::width().

Referenced by AddBitmap().

Here is the call graph for this function:

◆ CreateNewAtlas()

void yaze::gfx::AtlasRenderer::CreateNewAtlas ( )
private

Definition at line 380 of file atlas_renderer.cc.

References atlases_, yaze::gfx::IRenderer::CreateTexture(), current_atlas_, and renderer_.

Referenced by AddBitmap(), and Initialize().

Here is the call graph for this function:

◆ RebuildAtlas()

◆ FindFreeRegion()

SDL_Rect yaze::gfx::AtlasRenderer::FindFreeRegion ( Atlas atlas,
int  width,
int  height 
)
private

◆ MarkRegionUsed()

void yaze::gfx::AtlasRenderer::MarkRegionUsed ( Atlas atlas,
const SDL_Rect &  rect,
bool  used 
)
private

Member Data Documentation

◆ renderer_

IRenderer* yaze::gfx::AtlasRenderer::renderer_
private

◆ atlases_

std::vector<std::unique_ptr<Atlas> > yaze::gfx::AtlasRenderer::atlases_
private

◆ atlas_lookup_

std::unordered_map<int, AtlasEntry*> yaze::gfx::AtlasRenderer::atlas_lookup_
private

◆ next_atlas_id_

int yaze::gfx::AtlasRenderer::next_atlas_id_
private

Definition at line 191 of file atlas_renderer.h.

Referenced by AddBitmap(), Clear(), and Initialize().

◆ current_atlas_

int yaze::gfx::AtlasRenderer::current_atlas_
private

Definition at line 192 of file atlas_renderer.h.

Referenced by AddBitmap(), Clear(), CreateNewAtlas(), and Initialize().


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