fix: Renderizar textura antes de inicializar shaders
En constructor: SDL_RenderTexture() antes de initShaders() Esto asegura que la textura tiene contenido válido. Revertido lazy initialization que no funcionaba. Vuelta a la solución original que sí funcionaba.
This commit is contained in:
@@ -189,34 +189,29 @@ void OpenGLShader::createQuadGeometry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GLuint OpenGLShader::getTextureID(SDL_Texture* texture) {
|
GLuint OpenGLShader::getTextureID(SDL_Texture* texture) {
|
||||||
if (!texture) {
|
if (!texture) return 1;
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "texture es nullptr");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_PropertiesID props = SDL_GetTextureProperties(texture);
|
SDL_PropertiesID props = SDL_GetTextureProperties(texture);
|
||||||
GLuint texture_id = 0;
|
GLuint texture_id = 0;
|
||||||
|
|
||||||
// Probar diferentes nombres de properties (Desktop vs ES)
|
// Intentar obtener ID de textura OpenGL
|
||||||
const char* property_names[] = {
|
texture_id = (GLuint)(uintptr_t)SDL_GetPointerProperty(props, "SDL.texture.opengl.texture", nullptr);
|
||||||
SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER, // OpenGL ES
|
|
||||||
SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER, // OpenGL Desktop
|
|
||||||
"SDL.texture.opengl.texture", // Fallback legacy
|
|
||||||
"texture.opengl.texture" // Fallback legacy
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const char* prop_name : property_names) {
|
if (texture_id == 0) {
|
||||||
texture_id = (GLuint)SDL_GetNumberProperty(props, prop_name, 0);
|
texture_id = (GLuint)(uintptr_t)SDL_GetPointerProperty(props, "texture.opengl.texture", nullptr);
|
||||||
if (texture_id != 0) {
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"Textura OpenGL obtenida via '%s': ID=%u", prop_name, texture_id);
|
|
||||||
return texture_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
if (texture_id == 0) {
|
||||||
"No se pudo obtener ID de textura OpenGL con ninguna property");
|
texture_id = (GLuint)SDL_GetNumberProperty(props, "SDL.texture.opengl.texture", 1);
|
||||||
return 0;
|
}
|
||||||
|
|
||||||
|
if (texture_id == 0) {
|
||||||
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"No se pudo obtener ID de textura OpenGL, usando 1 por defecto");
|
||||||
|
texture_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGLShader::init(SDL_Window* window,
|
bool OpenGLShader::init(SDL_Window* window,
|
||||||
@@ -350,15 +345,6 @@ void OpenGLShader::render() {
|
|||||||
|
|
||||||
// Obtener y bindear textura
|
// Obtener y bindear textura
|
||||||
GLuint texture_id = getTextureID(back_buffer_);
|
GLuint texture_id = getTextureID(back_buffer_);
|
||||||
if (texture_id == 0) {
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"No se pudo obtener texture_id, abortando render");
|
|
||||||
// Restaurar estados y hacer fallback
|
|
||||||
SDL_RenderTexture(renderer_, back_buffer_, nullptr, nullptr);
|
|
||||||
SDL_RenderPresent(renderer_);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture_id);
|
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||||
checkGLError("glBindTexture");
|
checkGLError("glBindTexture");
|
||||||
|
|||||||
@@ -55,8 +55,12 @@ Screen::Screen()
|
|||||||
setDebugInfoEnabled(true);
|
setDebugInfoEnabled(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Los shaders se inicializarán lazy en el primer render si están activos
|
// Renderizar una vez la textura vacía para que tenga contenido válido
|
||||||
// Esto evita problemas con texturas vacías al inicio
|
// antes de inicializar los shaders (evita pantalla negra)
|
||||||
|
SDL_RenderTexture(renderer_, game_canvas_, nullptr, nullptr);
|
||||||
|
|
||||||
|
// Ahora sí inicializar los shaders
|
||||||
|
initShaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -96,19 +100,8 @@ void Screen::renderPresent() {
|
|||||||
SDL_SetRenderTarget(renderer_, nullptr);
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
clean();
|
clean();
|
||||||
|
|
||||||
if (Options::video.shaders) {
|
if (Options::video.shaders && shader_backend_) {
|
||||||
// Lazy initialization: inicializar shaders la primera vez que se usan
|
shader_backend_->render();
|
||||||
if (!shader_backend_) {
|
|
||||||
initShaders();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shader_backend_) {
|
|
||||||
shader_backend_->render();
|
|
||||||
} else {
|
|
||||||
// Fallback si falla la inicialización
|
|
||||||
SDL_RenderTexture(renderer_, game_canvas_, nullptr, nullptr);
|
|
||||||
SDL_RenderPresent(renderer_);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
SDL_RenderTexture(renderer_, game_canvas_, nullptr, nullptr);
|
SDL_RenderTexture(renderer_, game_canvas_, nullptr, nullptr);
|
||||||
SDL_RenderPresent(renderer_);
|
SDL_RenderPresent(renderer_);
|
||||||
|
|||||||
Reference in New Issue
Block a user