treballant en metal
This commit is contained in:
45
source/external/jail_shader.cpp
vendored
45
source/external/jail_shader.cpp
vendored
@@ -234,7 +234,7 @@ GLuint getTextureID(SDL_Texture *texture) {
|
||||
return textureId;
|
||||
}
|
||||
|
||||
bool init(SDL_Window *window, SDL_Texture *back_buffer_texture, const std::string &vertex_shader, const std::string &fragment_shader) {
|
||||
bool init(SDL_Window *window, SDL_Texture *back_buffer_texture, const std::string &shader_source, const std::string &fragment_shader) {
|
||||
shader::win = window;
|
||||
shader::renderer = SDL_GetRenderer(window);
|
||||
shader::backBuffer = back_buffer_texture;
|
||||
@@ -253,7 +253,15 @@ bool init(SDL_Window *window, SDL_Texture *back_buffer_texture, const std::strin
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verificar que el renderer sea OpenGL
|
||||
#ifdef __APPLE__
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Detected renderer: %s", render_name);
|
||||
|
||||
// En macOS, SIEMPRE usar OpenGL shaders, incluso con Metal renderer SDL
|
||||
// Esto nos da lo mejor de ambos: Metal para SDL (rendimiento) + OpenGL para shaders CRT
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "macOS: Using OpenGL shaders with %s SDL renderer", render_name);
|
||||
#endif
|
||||
|
||||
// Verificar que el renderer sea OpenGL solamente (Metal no puede usar shaders OpenGL)
|
||||
if (!strncmp(render_name, "opengl", 6)) {
|
||||
#ifndef __APPLE__
|
||||
if (!initGLExtensions()) {
|
||||
@@ -263,24 +271,39 @@ bool init(SDL_Window *window, SDL_Texture *back_buffer_texture, const std::strin
|
||||
}
|
||||
#endif
|
||||
// Compilar el programa de shaders utilizando std::string
|
||||
programId = compileProgram(vertex_shader, fragment_shader);
|
||||
programId = compileProgram(shader_source, fragment_shader);
|
||||
if (programId == INVALID_PROGRAM_ID) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "ERROR: No se pudo compilar el programa de shaders.");
|
||||
usingOpenGL = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
usingOpenGL = true;
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** OpenGL shader system initialized successfully");
|
||||
return true;
|
||||
} else if (!strncmp(render_name, "metal", 5)) {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SDL using Metal renderer - CRT shaders not available yet");
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Running with excellent Metal performance (~450+ FPS) without CRT effects");
|
||||
usingOpenGL = false;
|
||||
return true; // Success, but no shaders
|
||||
} else {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "ADVERTENCIA: El driver del renderer no es OpenGL (%s).", render_name);
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "ADVERTENCIA: El driver del renderer no es compatible (%s).", render_name);
|
||||
usingOpenGL = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
usingOpenGL = true;
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Shader system initialized successfully");
|
||||
return true;
|
||||
}
|
||||
|
||||
void render() {
|
||||
#ifdef __APPLE__
|
||||
// En macOS con Metal, los shaders están deshabilitados por ahora
|
||||
// TODO: Implementar integración correcta SDL Metal + shaders CRT
|
||||
if (!usingOpenGL) {
|
||||
// Usar renderizado SDL normal (sin shaders)
|
||||
// Esto da excelente rendimiento ~450+ FPS
|
||||
return; // Let SDL handle rendering normally
|
||||
}
|
||||
#endif
|
||||
|
||||
// Establece el color de fondo
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
@@ -392,6 +415,12 @@ void render() {
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
#ifdef __APPLE__
|
||||
if (!usingOpenGL) {
|
||||
metal::cleanupMetal();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (programId != INVALID_PROGRAM_ID) {
|
||||
glDeleteProgram(programId);
|
||||
programId = INVALID_PROGRAM_ID;
|
||||
|
||||
Reference in New Issue
Block a user