From c0faf074fe9b170d97cbaddb5cec10f101c05c7d Mon Sep 17 00:00:00 2001 From: "Raimon @ quifisraimon" Date: Tue, 13 Oct 2026 17:29:00 +0200 Subject: [PATCH] =?UTF-8?q?VERSI=C3=93=201.6.2:=20-=20[FIX]=20El=20buffer?= =?UTF-8?q?=20en=20que=20es=20guardaba=20l'arxiu=20de=20text=20dels=20shad?= =?UTF-8?q?ers=20no=20s'alliberava.=20-=20[NEW]=20Tra=C3=A7a=20per=20a=20v?= =?UTF-8?q?ore=20-=20[NEW]=20Millors=20logs=20de=20errors=20de=20shaders?= =?UTF-8?q?=20-=20[NEW]=20Afegit=20mode=20'consola'=20per=20a=20quan=20s'e?= =?UTF-8?q?xecuta=20desde=20consola=20sense=20entorn=20gr=C3=A0fic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + lagueirtofile | 2 +- source/backends/SDL3/shader.cpp | 82 +++++++++++++++++++++++++-------- source/backends/SDL3/video.cpp | 8 +++- source/mini/mini.cpp | 1 + source/mini/win/win.h | 1 + 6 files changed, 75 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 4c1c383..56177d6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /mini mini_debug.exe mini_debug +mini_san .vscode/* info.plist build/* diff --git a/lagueirtofile b/lagueirtofile index 6422a3b..8532844 100644 --- a/lagueirtofile +++ b/lagueirtofile @@ -12,7 +12,7 @@ executable = mini_debug sourcepath = source+ buildpath = build -[linux_sanitize] default +[linux_sanitize] cppflags = -D LUA_USE_LINUX -D DEBUG -g -Wall -std=c++20 -fsanitize=address -fno-omit-frame-pointer -Isource libs = -fsanitize=address -lSDL3 -lGL executable = mini_san diff --git a/source/backends/SDL3/shader.cpp b/source/backends/SDL3/shader.cpp index 53905cd..5c7d1dc 100644 --- a/source/backends/SDL3/shader.cpp +++ b/source/backends/SDL3/shader.cpp @@ -21,6 +21,34 @@ #include #endif +void checkGLError() { + GLenum err = glGetError(); + if (err != GL_NO_ERROR) { + fprintf(stderr, "OpenGL error 0x%04X\n", err); + + // Mapeo rápido de los errores más comunes de OpenGL + while (err != GL_NO_ERROR) { + const char* errStr = ""; + switch (err) { + case GL_INVALID_ENUM: errStr = "GL_INVALID_ENUM"; break; + case GL_INVALID_VALUE: errStr = "GL_INVALID_STRING/VALUE"; break; + case GL_INVALID_OPERATION: errStr = "GL_INVALID_OPERATION"; break; + case GL_OUT_OF_MEMORY: errStr = "GL_OUT_OF_MEMORY"; break; + case GL_INVALID_FRAMEBUFFER_OPERATION: errStr = "GL_INVALID_FRAMEBUFFER_OPERATION"; break; + default: errStr = "UNKNOWN_ERROR"; break; + } + fprintf(stderr, " -> Código de error: %s (0x%04X)\n", errStr, err); + err = glGetError(); + } + ::exit(1); + } +} + +#define GL_CHECK(stmt) do { \ + stmt; \ + checkGLError(#stmt, __FILE__, __LINE__); \ +} while (0) + namespace backend { namespace shader @@ -132,18 +160,25 @@ namespace backend glAttachShader(programId, vtxShaderId); glAttachShader(programId, fragShaderId); glLinkProgram(programId); - glValidateProgram(programId); + //glValidateProgram(programId); - // Check the status of the compile/link - GLint logLen; - glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen); - if (logLen > 0) + GLint linkStatus = GL_FALSE; + glGetProgramiv(programId, GL_LINK_STATUS, &linkStatus); + + if (linkStatus != GL_TRUE) { - char* log = (char*) malloc(logLen * sizeof(char)); - // Show any errors as appropriate - glGetProgramInfoLog(programId, logLen, &logLen, log); - std::cout << "Prog Info Log: " << std::endl << log << std::endl; - free(log); + std::cout << "Error en el enlazado (Linking) del programa!" << std::endl; + GLint logLen = 0; + glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen); + if (logLen > 0) + { + char* log = (char*)malloc(logLen); + glGetProgramInfoLog(programId, logLen, &logLen, log); + std::cout << "Program Link Log:\n" << log << std::endl; + free(log); + } + glDeleteProgram(programId); + programId = 0; } } if (vtxShaderId) glDeleteShader(vtxShaderId); @@ -165,12 +200,6 @@ namespace backend SDL_GetWindowSize(video::window, &win_size.x, &win_size.y); SDL_GetTextureSize(video::tex_shader, &tex_size.x, &tex_size.y); - int filesize; - char *vshaderfile = mini::file::getfilebuffer(vShaderSource, filesize, true); - - char *fshaderfile = nullptr; - if (fShaderSource) { fshaderfile = mini::file::getfilebuffer(fShaderSource, filesize, true); } - SDL_PropertiesID props = SDL_GetTextureProperties(video::tex_shader); int access = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, -1); if (access != SDL_TEXTUREACCESS_TARGET) { @@ -190,12 +219,23 @@ namespace backend gl_extensions_initialized = true; } #endif - // Compilar el shader y dejarlo listo para usar. + + // Compilar el shader + int filesize; + char *vshaderfile = mini::file::getfilebuffer(vShaderSource, filesize, true); + if (!vshaderfile) { can_use_opengl = false; return; } + + char *fshaderfile = nullptr; + if (fShaderSource) { fshaderfile = mini::file::getfilebuffer(fShaderSource, filesize, true); } + programId = compileProgram(vshaderfile, fshaderfile); + + if (vshaderfile) free(vshaderfile); + if (fshaderfile) free(fshaderfile); } else { std::cout << "WARNING: El driver del renderer no es OpenGL." << std::endl; can_use_opengl = false; @@ -258,10 +298,16 @@ namespace backend SDL_RenderTexture(backend::video::renderer, backend::video::tex_shader, NULL, &backend::video::dest_rect); SDL_RenderPresent(backend::video::renderer); } - if (glGetError()) { printf("GLERROR!\n"); ::exit(1); } + checkGLError(); + //GLenum error = glGetError(); + //if (error != GL_NO_ERROR) { + // printf("GLERROR!\n"); ::exit(1); + //} } } } + + #endif \ No newline at end of file diff --git a/source/backends/SDL3/video.cpp b/source/backends/SDL3/video.cpp index ae670c3..b8e7902 100644 --- a/source/backends/SDL3/video.cpp +++ b/source/backends/SDL3/video.cpp @@ -30,6 +30,7 @@ namespace backend if (zoom <= 0) zoom = 1; const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay()); while ( width * zoom > dm->w || height * zoom > dm->h) zoom--; + log_msg(LOG_INFO, "Display size: %ix%i\n", dm->w, dm->h); const int z = mini::win::state.fullscreen ? 1 : zoom; // Crear SDL_Window i SDL_Renderer @@ -74,9 +75,14 @@ namespace backend } else { - dest_rect.x = dest_rect.y = 0; dest_rect.w = width * zoom; dest_rect.h = height * zoom; + if (mini::win::state.console) { + dest_rect.x = (ww - dest_rect.w)/2; + dest_rect.y = (wh - dest_rect.h)/2; + } else { + dest_rect.x = dest_rect.y = 0; + } printf("dest_rect: (%i,%i)-(%i,%i)\n", (int)dest_rect.x, (int)dest_rect.y, (int)dest_rect.w, (int)dest_rect.h); } shader::reinit(); diff --git a/source/mini/mini.cpp b/source/mini/mini.cpp index ffc2cd4..b809e65 100644 --- a/source/mini/mini.cpp +++ b/source/mini/mini.cpp @@ -70,6 +70,7 @@ void read_ini() { else if (strcmp(line, "height") == 0) { mini::win::state.height = atoi(value); log_msg(LOG_VERBOSE, "screen height = %i\n", mini::win::state.height); } else if (strcmp(line, "zoom") == 0) { mini::win::state.zoom = atoi(value); log_msg(LOG_VERBOSE, "screen zoom = %i\n", mini::win::state.zoom); } else if (strcmp(line, "fullscreen") == 0) { mini::win::state.fullscreen = atoi(value); log_msg(LOG_VERBOSE, "screen sullscreen = %i\n", mini::win::state.fullscreen); } + else if (strcmp(line, "console") == 0) { mini::win::state.console = atoi(value); log_msg(LOG_VERBOSE, "run from console = %i\n", mini::win::state.console); } //else if (strcmp(line, "files") == 0) { //lua_files = (char*)malloc(strlen(value)); // strcpy(lua_files, value); diff --git a/source/mini/win/win.h b/source/mini/win/win.h index eb02c7d..2dceb79 100644 --- a/source/mini/win/win.h +++ b/source/mini/win/win.h @@ -12,6 +12,7 @@ namespace mini uint8_t zoom { 4 }; bool fullscreen { false }; bool cursor { true }; + bool console { false }; }; extern state_t state;