From ba0b0930b05ac0da0adec14b6d5c5632018c9da9 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Thu, 2 Oct 2025 21:55:49 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Mejorar=20obtenci=C3=B3n=20de=20texture?= =?UTF-8?q?=20ID=20en=20OpenGL=20ES?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Probar SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER para ES - Probar SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER para Desktop - AƱadir logs detallados para debug - No intentar bind si texture_id es 0 (prevenir GL_INVALID_ENUM) Refs: Error 0x500 en glBindTexture en RPi --- source/rendering/opengl/opengl_shader.cpp | 46 +++++++++++++++-------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/source/rendering/opengl/opengl_shader.cpp b/source/rendering/opengl/opengl_shader.cpp index 3c296c2..df3fb89 100644 --- a/source/rendering/opengl/opengl_shader.cpp +++ b/source/rendering/opengl/opengl_shader.cpp @@ -189,29 +189,34 @@ void OpenGLShader::createQuadGeometry() { } GLuint OpenGLShader::getTextureID(SDL_Texture* texture) { - if (!texture) return 1; + if (!texture) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "texture es nullptr"); + return 0; + } SDL_PropertiesID props = SDL_GetTextureProperties(texture); GLuint texture_id = 0; - // Intentar obtener ID de textura OpenGL - texture_id = (GLuint)(uintptr_t)SDL_GetPointerProperty(props, "SDL.texture.opengl.texture", nullptr); + // Probar diferentes nombres de properties (Desktop vs ES) + const char* property_names[] = { + 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 + }; - if (texture_id == 0) { - texture_id = (GLuint)(uintptr_t)SDL_GetPointerProperty(props, "texture.opengl.texture", nullptr); + for (const char* prop_name : property_names) { + texture_id = (GLuint)SDL_GetNumberProperty(props, prop_name, 0); + if (texture_id != 0) { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, + "Textura OpenGL obtenida via '%s': ID=%u", prop_name, texture_id); + return texture_id; + } } - if (texture_id == 0) { - texture_id = (GLuint)SDL_GetNumberProperty(props, "SDL.texture.opengl.texture", 1); - } - - 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; + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "No se pudo obtener ID de textura OpenGL con ninguna property"); + return 0; } bool OpenGLShader::init(SDL_Window* window, @@ -345,6 +350,15 @@ void OpenGLShader::render() { // Obtener y bindear textura 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); glBindTexture(GL_TEXTURE_2D, texture_id); checkGLError("glBindTexture");