Phase 7 - Text Rendering: - Add BitmapFont with embedded 8x8 CP437 font (ASCII 32-126) - Add TextPass for instanced glyph rendering - Fix SceneCollector::parseText() to copy strings to FrameAllocator Phase 8A - Multi-texture Support: - Add numeric texture ID system in ResourceCache - SpritePass sorts by textureId and batches per texture - Flush batch on texture change for efficient rendering Phase 8B - Tilemap Rendering: - Add TilemapPass for grid-based tile rendering - Support tileData as comma-separated string - Tiles rendered as instanced quads Window Resize: - Handle window resize via process() input - Call bgfx::reset() on size change 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
68 lines
2.3 KiB
C++
68 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include "../RenderGraph/RenderPass.h"
|
|
#include "../RHI/RHITypes.h"
|
|
#include <vector>
|
|
|
|
namespace grove {
|
|
|
|
class ResourceCache;
|
|
|
|
// ============================================================================
|
|
// Sprite Pass - Renders 2D sprites with batching by texture
|
|
// ============================================================================
|
|
|
|
class SpritePass : public RenderPass {
|
|
public:
|
|
/**
|
|
* @brief Construct SpritePass with required shader
|
|
* @param shader The shader program to use for sprite rendering
|
|
*/
|
|
explicit SpritePass(rhi::ShaderHandle shader);
|
|
|
|
const char* getName() const override { return "Sprites"; }
|
|
uint32_t getSortOrder() const override { return 100; }
|
|
std::vector<const char*> getDependencies() const override { return {"Clear"}; }
|
|
|
|
void setup(rhi::IRHIDevice& device) override;
|
|
void shutdown(rhi::IRHIDevice& device) override;
|
|
void execute(const FramePacket& frame, rhi::IRHIDevice& device, rhi::RHICommandBuffer& cmd) override;
|
|
|
|
/**
|
|
* @brief Set resource cache for texture lookup by ID
|
|
*/
|
|
void setResourceCache(ResourceCache* cache) { m_resourceCache = cache; }
|
|
|
|
/**
|
|
* @brief Set fallback texture when textureId=0 or texture not found
|
|
*/
|
|
void setDefaultTexture(rhi::TextureHandle texture) { m_activeTexture = texture; }
|
|
|
|
/**
|
|
* @brief Legacy: Set a single texture for all sprites (backward compat)
|
|
* @deprecated Use setResourceCache for multi-texture support
|
|
*/
|
|
void setTexture(rhi::TextureHandle texture) { m_activeTexture = texture; }
|
|
|
|
private:
|
|
void flushBatch(rhi::IRHIDevice& device, rhi::RHICommandBuffer& cmd,
|
|
rhi::TextureHandle texture, uint32_t count);
|
|
|
|
rhi::ShaderHandle m_shader;
|
|
rhi::BufferHandle m_quadVB;
|
|
rhi::BufferHandle m_quadIB;
|
|
rhi::BufferHandle m_instanceBuffer;
|
|
rhi::UniformHandle m_textureSampler;
|
|
rhi::TextureHandle m_defaultTexture; // White 1x1 texture fallback
|
|
rhi::TextureHandle m_activeTexture; // Default texture for textureId=0
|
|
|
|
ResourceCache* m_resourceCache = nullptr;
|
|
|
|
// Sorted sprite indices for batching
|
|
std::vector<uint32_t> m_sortedIndices;
|
|
|
|
static constexpr uint32_t MAX_SPRITES_PER_BATCH = 10000;
|
|
};
|
|
|
|
} // namespace grove
|