Implementar arquitectura multi-backend para vibe4_shaders
- Actualizar proyecto de vibe3_physics a vibe4_shaders - Crear sistema modular de renderizado con RendererInterface - Añadir WindowManager para gestión de ventana y backends - Implementar backends: SDL (fallback), Vulkan, Metal - Añadir soporte para efectos CRT en software - Migrar sistema de renderizado a batch processing - Actualizar README con nueva arquitectura NOTA: Funcionalidad básica necesita restauración (texto y texturas) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include "renderer_interface.h"
|
||||
#include <vector>
|
||||
|
||||
// Forward declarations para evitar incluir headers de Metal en el .h
|
||||
struct SDL_Window;
|
||||
|
||||
#ifdef __OBJC__
|
||||
@class MTLDevice;
|
||||
@class MTLCommandQueue;
|
||||
@class MTLRenderPipelineState;
|
||||
@class MTLComputePipelineState;
|
||||
@class MTLBuffer;
|
||||
@class MTLTexture;
|
||||
@class CAMetalLayer;
|
||||
#else
|
||||
// Forward declarations para C++
|
||||
typedef struct MTLDevice_t* MTLDevice;
|
||||
typedef struct MTLCommandQueue_t* MTLCommandQueue;
|
||||
typedef struct MTLRenderPipelineState_t* MTLRenderPipelineState;
|
||||
typedef struct MTLComputePipelineState_t* MTLComputePipelineState;
|
||||
typedef struct MTLBuffer_t* MTLBuffer;
|
||||
typedef struct MTLTexture_t* MTLTexture;
|
||||
typedef struct CAMetalLayer_t* CAMetalLayer;
|
||||
#endif
|
||||
|
||||
namespace vibe4 {
|
||||
|
||||
// Implementación usando Metal para macOS
|
||||
class MetalRenderer : public RendererInterface {
|
||||
public:
|
||||
MetalRenderer();
|
||||
~MetalRenderer() override;
|
||||
|
||||
// Implementación de la interfaz
|
||||
bool initialize(SDL_Window* window, int width, int height) override;
|
||||
void shutdown() override;
|
||||
|
||||
bool beginFrame() override;
|
||||
void endFrame() override;
|
||||
void present() override;
|
||||
|
||||
void renderGradientBackground(
|
||||
float top_r, float top_g, float top_b,
|
||||
float bottom_r, float bottom_g, float bottom_b
|
||||
) override;
|
||||
|
||||
void renderSpriteBatch(
|
||||
const std::vector<SpriteData>& sprites,
|
||||
void* texture_data
|
||||
) override;
|
||||
|
||||
void setCRTParams(const CRTParams& params) override;
|
||||
void enableCRT(bool enable) override;
|
||||
|
||||
BackendType getBackendType() const override { return BackendType::METAL; }
|
||||
const char* getBackendName() const override { return "Metal (macOS)"; }
|
||||
|
||||
void setVSync(bool enable) override;
|
||||
void resize(int width, int height) override;
|
||||
|
||||
private:
|
||||
// Recursos Metal
|
||||
MTLDevice* device_ = nullptr;
|
||||
MTLCommandQueue* command_queue_ = nullptr;
|
||||
CAMetalLayer* metal_layer_ = nullptr;
|
||||
|
||||
// Pipelines de renderizado
|
||||
MTLRenderPipelineState* sprite_pipeline_ = nullptr;
|
||||
MTLRenderPipelineState* gradient_pipeline_ = nullptr;
|
||||
MTLComputePipelineState* crt_compute_pipeline_ = nullptr;
|
||||
|
||||
// Buffers
|
||||
MTLBuffer* vertex_buffer_ = nullptr;
|
||||
MTLBuffer* index_buffer_ = nullptr;
|
||||
MTLBuffer* uniform_buffer_ = nullptr;
|
||||
|
||||
// Texturas
|
||||
MTLTexture* sprite_texture_ = nullptr;
|
||||
MTLTexture* render_target_ = nullptr;
|
||||
MTLTexture* crt_output_ = nullptr;
|
||||
|
||||
// Datos de frame actual
|
||||
std::vector<SpriteVertex> current_vertices_;
|
||||
std::vector<uint16_t> current_indices_;
|
||||
|
||||
// Estructuras uniformes para shaders
|
||||
struct SpriteUniforms {
|
||||
float mvp_matrix[16];
|
||||
float screen_size[2];
|
||||
};
|
||||
|
||||
struct CRTUniforms {
|
||||
float scanline_intensity;
|
||||
float curvature_x;
|
||||
float curvature_y;
|
||||
float bloom_factor;
|
||||
float mask_brightness;
|
||||
float screen_size[2];
|
||||
int enable_scanlines;
|
||||
int enable_curvature;
|
||||
int enable_bloom;
|
||||
};
|
||||
|
||||
// Métodos privados
|
||||
bool createMetalLayer();
|
||||
bool createRenderPipelines();
|
||||
bool createBuffers();
|
||||
bool loadShaders();
|
||||
void updateUniforms();
|
||||
void renderSprites();
|
||||
void applyCRTEffects();
|
||||
|
||||
// Helpers para conversión de coordenadas
|
||||
void setupProjectionMatrix(float* matrix);
|
||||
};
|
||||
|
||||
} // namespace vibe4
|
||||
|
||||
#endif // __APPLE__
|
||||
Reference in New Issue
Block a user