This commit is contained in:
2025-10-27 18:35:53 +01:00
parent b1dca32a5b
commit 3179a08dac
63 changed files with 686 additions and 693 deletions

View File

@@ -14,7 +14,7 @@ OpenGLShader::~OpenGLShader() {
}
#ifndef __APPLE__
bool OpenGLShader::initGLExtensions() {
auto OpenGLShader::initGLExtensions() -> bool {
glCreateShader = (PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader");
glShaderSource = (PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource");
glCompileShader = (PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader");
@@ -61,7 +61,7 @@ void OpenGLShader::checkGLError(const char* operation) {
}
}
GLuint OpenGLShader::compileShader(const std::string& source, GLenum shader_type) {
auto OpenGLShader::compileShader(const std::string& source, GLenum shader_type) -> GLuint {
if (source.empty()) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"ERROR: El código fuente del shader está vacío");
@@ -104,7 +104,7 @@ GLuint OpenGLShader::compileShader(const std::string& source, GLenum shader_type
return shader_id;
}
GLuint OpenGLShader::linkProgram(GLuint vertex_shader, GLuint fragment_shader) {
auto OpenGLShader::linkProgram(GLuint vertex_shader, GLuint fragment_shader) -> GLuint {
GLuint program = glCreateProgram();
if (program == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
@@ -196,7 +196,7 @@ void OpenGLShader::createQuadGeometry() {
checkGLError("glBufferData(EBO)");
// Atributo 0: Posición (2 floats)
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)nullptr);
glEnableVertexAttribArray(0);
checkGLError("glVertexAttribPointer(position)");
@@ -210,7 +210,7 @@ void OpenGLShader::createQuadGeometry() {
glBindVertexArray(0);
}
GLuint OpenGLShader::getTextureID(SDL_Texture* texture) {
auto OpenGLShader::getTextureID(SDL_Texture* texture) -> GLuint {
if (texture == nullptr) {
return 1;
}
@@ -238,10 +238,10 @@ GLuint OpenGLShader::getTextureID(SDL_Texture* texture) {
return texture_id;
}
bool OpenGLShader::init(SDL_Window* window,
auto OpenGLShader::init(SDL_Window* window,
SDL_Texture* texture,
const std::string& vertex_source,
const std::string& fragment_source) {
const std::string& fragment_source) -> bool {
window_ = window;
back_buffer_ = texture;
renderer_ = SDL_GetRenderer(window);
@@ -432,7 +432,7 @@ void OpenGLShader::render() {
// Dibujar quad usando VAO
glBindVertexArray(vao_);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
checkGLError("glDrawElements");
// Presentar

View File

@@ -23,23 +23,23 @@ class OpenGLShader : public ShaderBackend {
OpenGLShader() = default;
~OpenGLShader() override;
bool init(SDL_Window* window,
auto init(SDL_Window* window,
SDL_Texture* texture,
const std::string& vertex_source,
const std::string& fragment_source) override;
const std::string& fragment_source) -> bool override;
void render() override;
void setTextureSize(float width, float height) override;
void cleanup() final;
bool isHardwareAccelerated() const override { return is_initialized_; }
[[nodiscard]] auto isHardwareAccelerated() const -> bool override { return is_initialized_; }
private:
// Funciones auxiliares
bool initGLExtensions();
GLuint compileShader(const std::string& source, GLenum shader_type);
GLuint linkProgram(GLuint vertex_shader, GLuint fragment_shader);
auto initGLExtensions() -> bool;
auto compileShader(const std::string& source, GLenum shader_type) -> GLuint;
auto linkProgram(GLuint vertex_shader, GLuint fragment_shader) -> GLuint;
void createQuadGeometry();
static GLuint getTextureID(SDL_Texture* texture);
static auto getTextureID(SDL_Texture* texture) -> GLuint;
static void checkGLError(const char* operation);
// Estado SDL