Nimbin[12]?SDL & Graphics / sdl_runtime_compiler / commits / 2abc2a1

sdl_runtime_compiler git · main

SDL3 game for running and compiling code at runtime

sdl3 c++ compiler dlopen cmake · first commit 2026-04-19 · last commit 2026-07-03 (3 months ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/sdl-runtime-compiler

C++ 72.3% C 26.2%
git clone https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler/archive/sdl_runtime_compiler.tar.gz

Refactor

Christian Immanuel · 2026-06-01 20:31 · 2abc2a126783b3ac05c3e914336c2ceb7da5e520

 src/rendering/gl_renderer.cpp | 103 ++++++++++++++++++++++--------------------
 1 file changed, 54 insertions(+), 49 deletions(-)

diff --git a/src/rendering/gl_renderer.cpp b/src/rendering/gl_renderer.cpp
index a0bffb4..272a02b 100644
--- a/src/rendering/gl_renderer.cpp
+++ b/src/rendering/gl_renderer.cpp
@@ -409,8 +409,13 @@ Mat4 buildModelMat4(const Vec3& pos, float yaw, float pitch)
 bool GlRenderer::init(SDL_Window* window)
 {
     _ctx = SDL_GL_CreateContext(window);
-    if (!_ctx) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "GL context creation failed: %s", SDL_GetError()); return false; }
-    SDL_GL_MakeCurrent(window, _ctx);
+    if (!_ctx) {
+        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
+                     "GL context creation failed: %s",
+                     SDL_GetError());
+        return false;
+    }
+    SDL_GL_MakeCurrent    (window, _ctx);
     SDL_GL_SetSwapInterval(0);
 
     int samples = 0;
@@ -423,7 +428,7 @@ bool GlRenderer::init(SDL_Window* window)
 
     GLuint vert = compileShader(GL_VERTEX_SHADER,   kVertSrc);
     GLuint frag = compileShader(GL_FRAGMENT_SHADER, kFragSrc);
-    if (!vert || !frag) return false;
+    if (!vert || !frag)           return false;
     if (!linkProgram(vert, frag)) return false;
 
     glDeleteShader(vert);
@@ -456,22 +461,22 @@ bool GlRenderer::init(SDL_Window* window)
     _uFlashOuterCos   = glGetUniformLocation(_prog, "u_FlashOuterCos");
     _uFlashIntensity  = glGetUniformLocation(_prog, "u_FlashIntensity");
 
-    glGenVertexArrays(1, &_vao); glGenBuffers(1, &_vbo); glGenBuffers(1, &_ebo);
-    glBindVertexArray(_vao);
-    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
-    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), (void*)0);
+    glGenVertexArrays        (1, &_vao); glGenBuffers(1, &_vbo); glGenBuffers(1, &_ebo);
+    glBindVertexArray        (_vao);
+    glBindBuffer             (GL_ARRAY_BUFFER, _vbo);
+    glVertexAttribPointer    (0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), (void*)0);
     glEnableVertexAttribArray(0);
-    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), (void*)(3*sizeof(float)));
+    glVertexAttribPointer    (1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), (void*)(3*sizeof(float)));
     glEnableVertexAttribArray(1);
-    glBindVertexArray(0);
+    glBindVertexArray        (0);
 
-    glGenVertexArrays(1, &_line_vao); glGenBuffers(1, &_line_vbo);
-    glBindVertexArray(_line_vao);
-    glBindBuffer(GL_ARRAY_BUFFER, _line_vbo);
-    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), (void*)0);
+    glGenVertexArrays        (1, &_line_vao); glGenBuffers(1, &_line_vbo);
+    glBindVertexArray        (_line_vao);
+    glBindBuffer             (GL_ARRAY_BUFFER, _line_vbo);
+    glVertexAttribPointer    (0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), (void*)0);
     glEnableVertexAttribArray(0);
-    glVertexAttrib3f(1, 0.0f, 0.0f, 1.0f);
-    glBindVertexArray(0);
+    glVertexAttrib3f         (1, 0.0f, 0.0f, 1.0f);
+    glBindVertexArray        (0);
 
     glGenVertexArrays(1, &_vao_c);
     glGenBuffers     (1, &_vbo_c);
@@ -480,13 +485,13 @@ bool GlRenderer::init(SDL_Window* window)
     glBindBuffer(GL_ARRAY_BUFFER, _vbo_c);
     // 9 floats per vertex: pos(3) + normal(3) + color(3)
     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float),
-            (void*)0);
+                          (void*)0);
     glEnableVertexAttribArray(0);
     glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float),
-            (void*)(3 * sizeof(float)));
+                          (void*)(3 * sizeof(float)));
     glEnableVertexAttribArray(1);
     glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float),
-            (void*)(6 * sizeof(float)));
+                          (void*)(6 * sizeof(float)));
     glEnableVertexAttribArray(2);
     glBindVertexArray(0);
 
@@ -513,13 +518,13 @@ bool GlRenderer::init(SDL_Window* window)
             0.5f,-0.5f, 0.0f
         };
         glGenVertexArrays(1, &_menu_vao);
-        glGenBuffers(1, &_menu_vbo);
+        glGenBuffers     (1, &_menu_vbo);
         glBindVertexArray(_menu_vao);
-        glBindBuffer(GL_ARRAY_BUFFER, _menu_vbo);
-        glBufferData(GL_ARRAY_BUFFER, sizeof(tri), tri, GL_STATIC_DRAW);
-        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), (void*)0);
+        glBindBuffer     (GL_ARRAY_BUFFER, _menu_vbo);
+        glBufferData     (GL_ARRAY_BUFFER, sizeof(tri), tri, GL_STATIC_DRAW);
+        glVertexAttribPointer    (0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), (void*)0);
         glEnableVertexAttribArray(0);
-        glVertexAttrib3f(1, 0.0f, 0.0f, 1.0f);
+        glVertexAttrib3f (1, 0.0f, 0.0f, 1.0f);
         glBindVertexArray(0);
     }
 
@@ -540,19 +545,19 @@ GlRenderer::begin_Frame(int w, int h)
 
     // Bind the FBO as the render target.
     glBindFramebuffer(GL_FRAMEBUFFER, _scene_fbo_ms);
-    glViewport(0, 0, w, h);
+    glViewport  (0, 0, w, h);
     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+    glClear     (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
     glUseProgram(_prog);
-    glUniform1i(_uMandelbrot, 0);
-    glUniform1i(_uWallPaper,  0);
-    glUniform1i(_uUseFront,   0);
+    glUniform1i (_uMandelbrot, 0);
+    glUniform1i (_uWallPaper,  0);
+    glUniform1i (_uUseFront,   0);
     Mat4 ident = Mat4::identity();
     glUniformMatrix4fv(_uModel, 1, GL_FALSE, ident.m);
-    glUniform1i(_uUseVertexColor, 0);
-    glUniform3f(_uEmissiveColor, 0.0f, 0.0f, 0.0f);
-    glUniform1f(_uEmissiveStrength, 0.0f);
+    glUniform1i (_uUseVertexColor, 0);
+    glUniform3f (_uEmissiveColor, 0.0f, 0.0f, 0.0f);
+    glUniform1f (_uEmissiveStrength, 0.0f);
     _proj = Mat4::perspective(SDL_PI_F/3.0f, _aspect, 0.1f, 200.0f);
 }
 
@@ -577,14 +582,14 @@ GlRenderer::end_Frame(SDL_Window* window)
     glViewport(0, 0, _view_w, _view_h);
     glDisable(GL_DEPTH_TEST);
 
-    glUseProgram(_composite_prog);
+    glUseProgram   (_composite_prog);
     glActiveTexture(GL_TEXTURE0);
-    glBindTexture(GL_TEXTURE_2D, _scene_color_tex);
-    glUniform1i(_uComposeScene, 0);
+    glBindTexture  (GL_TEXTURE_2D, _scene_color_tex);
+    glUniform1i    (_uComposeScene, 0);
     glActiveTexture(GL_TEXTURE1);
-    glBindTexture(GL_TEXTURE_2D, _blur_tex[1]);   // final bloom
-    glUniform1i(_uComposeBloom, 1);
-    glUniform1f(_uComposeStrength, _bloom_strength);
+    glBindTexture  (GL_TEXTURE_2D, _blur_tex[1]);   // final bloom
+    glUniform1i    (_uComposeBloom, 1);
+    glUniform1f    (_uComposeStrength, _bloom_strength);
 
     { FP_ZONE("end_Frame.composite");
         glBindVertexArray(_fullscreen_vao);
@@ -835,7 +840,7 @@ GlRenderer::draw_Emissive(const Camera& cam,
     glUniform3f(_uEmissiveColor, r, g, b);
     glUniform1f(_uEmissiveStrength, strength);
 
-    glEnable(GL_BLEND);
+    glEnable   (GL_BLEND);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE);   // additive
     glDepthMask(GL_FALSE);                // no depth write
 
@@ -852,8 +857,8 @@ GlRenderer::draw_Emissive(const Camera& cam,
     glBindVertexArray(0);
 
     // Pop state.
-    glDisable(GL_BLEND);
-    glDepthMask(GL_TRUE);
+    glDisable   (GL_BLEND);
+    glDepthMask (GL_TRUE);
     glUseProgram(_prog);    // restore main program
 }
 
@@ -1044,7 +1049,7 @@ GlRenderer::create_BloomFBOs_(int scene_w, int scene_h)
             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Bloom FBO incomplete: 0x%x", s);
     };
 
-    make_fbo(_bright_fbo, _bright_tex);
+    make_fbo(_bright_fbo,  _bright_tex);
     make_fbo(_blur_fbo[0], _blur_tex[0]);
     make_fbo(_blur_fbo[1], _blur_tex[1]);
 
@@ -1054,10 +1059,10 @@ GlRenderer::create_BloomFBOs_(int scene_w, int scene_h)
 void
 GlRenderer::destroy_BloomFBOs_()
 {
-    if (_bright_tex)   { glDeleteTextures(1, &_bright_tex);    _bright_tex = 0; }
+    if (_bright_tex)   { glDeleteTextures    (1, &_bright_tex); _bright_tex = 0; }
     if (_bright_fbo)   { glDeleteFramebuffers(1, &_bright_fbo); _bright_fbo = 0; }
     for (int i = 0; i < 2; ++i) {
-        if (_blur_tex[i]) { glDeleteTextures(1, &_blur_tex[i]); _blur_tex[i] = 0; }
+        if (_blur_tex[i]) { glDeleteTextures    (1, &_blur_tex[i]); _blur_tex[i] = 0; }
         if (_blur_fbo[i]) { glDeleteFramebuffers(1, &_blur_fbo[i]); _blur_fbo[i] = 0; }
     }
     _blur_w = 0; _blur_h = 0;
@@ -1147,12 +1152,12 @@ GlRenderer::create_CompositeProgram_()
 void
 GlRenderer::destroy_FBO_()
 {
-    if (_scene_color_tex)    { glDeleteTextures(1, &_scene_color_tex);         _scene_color_tex = 0; }
-    if (_scene_depth_rbo)    { glDeleteRenderbuffers(1, &_scene_depth_rbo);    _scene_depth_rbo = 0; }
-    if (_scene_fbo)          { glDeleteFramebuffers(1, &_scene_fbo);           _scene_fbo = 0; }
-    if (_scene_color_rbo_ms) { glDeleteRenderbuffers(1, &_scene_color_rbo_ms); _scene_color_rbo_ms = 0; }
-    if (_scene_depth_rbo_ms) { glDeleteRenderbuffers(1, &_scene_depth_rbo_ms); _scene_depth_rbo_ms = 0; }
-    if (_scene_fbo_ms)       { glDeleteFramebuffers(1, &_scene_fbo_ms);        _scene_fbo_ms = 0; }
+    if (_scene_color_tex)   {glDeleteTextures     (1, &_scene_color_tex);   _scene_color_tex   = 0;}
+    if (_scene_depth_rbo)   {glDeleteRenderbuffers(1, &_scene_depth_rbo);   _scene_depth_rbo   = 0;}
+    if (_scene_fbo)         {glDeleteFramebuffers (1, &_scene_fbo);         _scene_fbo         = 0;}
+    if (_scene_color_rbo_ms){glDeleteRenderbuffers(1, &_scene_color_rbo_ms);_scene_color_rbo_ms= 0;}
+    if (_scene_depth_rbo_ms){glDeleteRenderbuffers(1, &_scene_depth_rbo_ms);_scene_depth_rbo_ms= 0;}
+    if (_scene_fbo_ms)      {glDeleteFramebuffers (1, &_scene_fbo_ms);      _scene_fbo_ms      = 0;}
     _fbo_w = 0; _fbo_h = 0;
 }