- Create proper sprite shader (vs_sprite.sc, fs_sprite.sc) with GPU instancing - SpriteInstance struct now 80 bytes (5 x vec4) for GPU layout compatibility - Add BufferDesc::Layout enum (Raw, PosColor, InstanceData) for proper vertex layouts - BgfxDevice creates correct VertexLayout based on buffer type - SpritePass uses PosColor layout for quad vertices (Position + Color0) - Instance buffer uses 5 x vec4 layout (TexCoord7-3) for i_data0-4 - Add texture support with v_texcoord0 interpolation from instance UVs - Create default white 1x1 texture fallback - Compile shaders for SPIRV (Vulkan), GLSL (OpenGL), and Metal Visual test confirms sprites render correctly at ~545 FPS. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "../RenderGraph/RenderPass.h"
|
|
#include "../RHI/RHITypes.h"
|
|
|
|
namespace grove {
|
|
|
|
// ============================================================================
|
|
// Sprite Pass - Renders 2D sprites with batching
|
|
// ============================================================================
|
|
|
|
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;
|
|
|
|
private:
|
|
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
|
|
|
|
static constexpr uint32_t MAX_SPRITES_PER_BATCH = 10000;
|
|
};
|
|
|
|
} // namespace grove
|