diff options
| author | hachem <im@hachem.wtf> | 2026-08-24 18:28:39 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-24 18:28:39 +0200 |
| commit | a34c49f103c8950a57687ea3d866c244d95b4414 (patch) | |
| tree | ff268f4a7f52769a252443d6f2822c9814e3bb1c /src/platform/opengl/opengl_device.cpp | |
| parent | 06398a7a176e123506de6e8851866a8bec0b3427 (diff) | |
[docs]: added a few comments cause i wont be able to read this in a week's time
Diffstat (limited to 'src/platform/opengl/opengl_device.cpp')
| -rw-r--r-- | src/platform/opengl/opengl_device.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/platform/opengl/opengl_device.cpp b/src/platform/opengl/opengl_device.cpp index 614e515..dd5581d 100644 --- a/src/platform/opengl/opengl_device.cpp +++ b/src/platform/opengl/opengl_device.cpp @@ -21,7 +21,6 @@ namespace Donut::RHI auto gl_filter(Filter f) -> GLint { return f == Filter::Nearest ? GL_NEAREST : GL_LINEAR; } auto gl_internal(Format f) -> GLint { return f == Format::RGBA16F ? GL_RGBA16F : f == Format::RGBA32F ? GL_RGBA32F : f == Format::D32 ? GL_DEPTH_COMPONENT32F : GL_RGBA8; } - // ---- Buffer ------------------------------------------------------- class GLBuffer : public Buffer { public: @@ -42,7 +41,6 @@ namespace Donut::RHI GLuint m_id = 0; GLenum m_target = GL_ARRAY_BUFFER; }; - // ---- Texture ------------------------------------------------------ class GLTexture : public Texture { public: @@ -69,7 +67,6 @@ namespace Donut::RHI Ref<CubemapTexture> m_cube; // keepalive for cubemaps }; - // ---- RenderTarget ------------------------------------------------- class GLRenderTarget : public RenderTarget { public: @@ -102,7 +99,6 @@ namespace Donut::RHI GLuint m_fbo = 0, m_depth = 0; int m_w, m_h; Scope<GLTexture> m_color; }; - // ---- Pipeline ----------------------------------------------------- class GLPipeline : public Pipeline { public: @@ -120,12 +116,12 @@ namespace Donut::RHI { GLuint bi = glGetUniformBlockIndex(m_prog, r.name.c_str()); if (bi != GL_INVALID_INDEX) glUniformBlockBinding(m_prog, bi, r.binding); - // Not found: the ConstantBuffer<> type name in the shader no longer + // not found: the ConstantBuffer<> type name in the shader no longer // matches this resource string, so the UBO silently won't bind. else DONUT_WARN("GL RHI: shader '{}' has no uniform block '{}' (binding {})", d.shader, r.name, r.binding); } - else // Texture: point the sampler at texture unit == binding + else // texture: point the sampler at texture unit == binding { GLint loc = glGetUniformLocation(m_prog, r.name.c_str()); if (loc >= 0) glUniform1i(loc, (GLint)r.binding); @@ -138,7 +134,7 @@ namespace Donut::RHI PipelineDesc m_desc; Ref<Shader> m_shader; GLuint m_prog = 0; }; - // ---- CommandList (immediate) -------------------------------------- + // GL has no command buffers, so every call here executes immediately. class GLCommandList : public CommandList { public: @@ -155,7 +151,7 @@ namespace Donut::RHI glClearColor(clear.r, clear.g, clear.b, clear.a); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } - auto end_render_pass() -> void override {} + auto end_render_pass() -> void override {} // GL passes are a fiction; nothing to close auto bind_pipeline(Pipeline* p) -> void override { @@ -208,7 +204,6 @@ namespace Donut::RHI GLuint m_vao; GLPipeline* m_pipe = nullptr; int m_default_w = 1, m_default_h = 1; }; - // ---- Device ------------------------------------------------------- class GLDevice : public Device { public: @@ -220,17 +215,17 @@ namespace Donut::RHI m_width = window.width; m_height = window.height; const char* name = (const char*)glGetString(GL_RENDERER); m_name = name ? name : "OpenGL"; - glGenVertexArrays(1, &m_vao); glBindVertexArray(m_vao); // GL core needs one bound VAO + glGenVertexArrays(1, &m_vao); glBindVertexArray(m_vao); // GL core wants one VAO bound at all times, so like, here's one m_cmds = create_scope<GLCommandList>(m_vao); DONUT_INFO("GL RHI device: {} ({}x{})", m_name, m_width, m_height); return true; } auto shutdown() -> void override { - // Free the HDRIManager's cached GL cubemaps while our context is - // still current (they are static-singleton-owned; letting them - // destruct at program exit would glDeleteTextures after the context - // is gone and crash on close). + // nuke the HDRIManager's cached GL cubemaps while our context is + // still alive. they're static-singleton-owned, so if we let them + // destruct at program exit they'd glDeleteTextures into a dead + // context and crash on close. no thanks. HDRIManager::get().clear_cache(); if (m_imgui) { ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); m_imgui = false; } if (m_vao) { glDeleteVertexArrays(1, &m_vao); m_vao = 0; } |
