Remove clipboard functionality and enhance performance monitoring features
- Deleted clipboard-related files (clipboard.cc, clipboard.h, clipboard.mm) to streamline the codebase. - Added a performance dashboard in the EditorManager to monitor performance metrics and improve user experience. - Integrated performance monitoring capabilities across various editors, allowing for detailed timing of critical operations. - Updated the graphics system with batch processing for texture updates, significantly improving rendering performance. - Introduced a memory pool allocator for efficient memory management during graphics operations.
This commit is contained in:
167
src/app/gfx/atlas_renderer.h
Normal file
167
src/app/gfx/atlas_renderer.h
Normal file
@@ -0,0 +1,167 @@
|
||||
#ifndef YAZE_APP_GFX_ATLAS_RENDERER_H
|
||||
#define YAZE_APP_GFX_ATLAS_RENDERER_H
|
||||
|
||||
#include <SDL.h>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/gfx/performance_profiler.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace gfx {
|
||||
|
||||
/**
|
||||
* @brief Render command for batch rendering
|
||||
*/
|
||||
struct RenderCommand {
|
||||
int atlas_id; ///< Atlas ID of bitmap to render
|
||||
float x, y; ///< Screen coordinates
|
||||
float scale_x, scale_y; ///< Scale factors
|
||||
float rotation; ///< Rotation angle in degrees
|
||||
SDL_Color tint; ///< Color tint
|
||||
|
||||
RenderCommand(int id, float x_pos, float y_pos,
|
||||
float sx = 1.0f, float sy = 1.0f,
|
||||
float rot = 0.0f, SDL_Color color = {255, 255, 255, 255})
|
||||
: atlas_id(id), x(x_pos), y(y_pos),
|
||||
scale_x(sx), scale_y(sy), rotation(rot), tint(color) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Atlas usage statistics
|
||||
*/
|
||||
struct AtlasStats {
|
||||
int total_atlases;
|
||||
int total_entries;
|
||||
int used_entries;
|
||||
size_t total_memory;
|
||||
size_t used_memory;
|
||||
float utilization_percent;
|
||||
|
||||
AtlasStats() : total_atlases(0), total_entries(0), used_entries(0),
|
||||
total_memory(0), used_memory(0), utilization_percent(0.0f) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 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
|
||||
*/
|
||||
class AtlasRenderer {
|
||||
public:
|
||||
static AtlasRenderer& Get();
|
||||
|
||||
/**
|
||||
* @brief Initialize the atlas renderer
|
||||
* @param renderer SDL renderer for texture operations
|
||||
* @param initial_size Initial atlas size (power of 2 recommended)
|
||||
*/
|
||||
void Initialize(SDL_Renderer* renderer, int initial_size = 1024);
|
||||
|
||||
/**
|
||||
* @brief Add a bitmap to the atlas
|
||||
* @param bitmap Bitmap to add to atlas
|
||||
* @return Atlas ID for referencing this bitmap
|
||||
*/
|
||||
int AddBitmap(const Bitmap& bitmap);
|
||||
|
||||
/**
|
||||
* @brief Remove a bitmap from the atlas
|
||||
* @param atlas_id Atlas ID of bitmap to remove
|
||||
*/
|
||||
void RemoveBitmap(int atlas_id);
|
||||
|
||||
/**
|
||||
* @brief Update a bitmap in the atlas
|
||||
* @param atlas_id Atlas ID of bitmap to update
|
||||
* @param bitmap New bitmap data
|
||||
*/
|
||||
void UpdateBitmap(int atlas_id, const Bitmap& bitmap);
|
||||
|
||||
/**
|
||||
* @brief Render multiple bitmaps in a single draw call
|
||||
* @param render_commands Vector of render commands (atlas_id, x, y, scale)
|
||||
*/
|
||||
void RenderBatch(const std::vector<RenderCommand>& render_commands);
|
||||
|
||||
/**
|
||||
* @brief Get atlas statistics
|
||||
* @return Atlas usage statistics
|
||||
*/
|
||||
AtlasStats GetStats() const;
|
||||
|
||||
/**
|
||||
* @brief Defragment the atlas to reclaim space
|
||||
*/
|
||||
void Defragment();
|
||||
|
||||
/**
|
||||
* @brief Clear all atlases
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
AtlasRenderer() = default;
|
||||
~AtlasRenderer();
|
||||
|
||||
struct AtlasEntry {
|
||||
int atlas_id;
|
||||
SDL_Rect uv_rect; // UV coordinates in atlas
|
||||
SDL_Texture* texture;
|
||||
bool in_use;
|
||||
|
||||
AtlasEntry(int id, const SDL_Rect& rect, SDL_Texture* tex)
|
||||
: atlas_id(id), uv_rect(rect), texture(tex), in_use(true) {}
|
||||
};
|
||||
|
||||
struct Atlas {
|
||||
SDL_Texture* texture;
|
||||
int size;
|
||||
std::vector<AtlasEntry> entries;
|
||||
std::vector<bool> used_regions; // Track used regions for packing
|
||||
|
||||
Atlas(int s) : size(s), used_regions(s * s, false) {}
|
||||
};
|
||||
|
||||
SDL_Renderer* renderer_;
|
||||
std::vector<std::unique_ptr<Atlas>> atlases_;
|
||||
std::unordered_map<int, AtlasEntry*> atlas_lookup_;
|
||||
int next_atlas_id_;
|
||||
int current_atlas_;
|
||||
|
||||
// Helper methods
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APP_GFX_ATLAS_RENDERER_H
|
||||
Reference in New Issue
Block a user