aboutsummaryrefslogtreecommitdiff
path: root/src/platform/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/opengl')
-rw-r--r--src/platform/opengl/opengl_device.cpp23
-rw-r--r--src/platform/opengl/shader.cpp16
-rw-r--r--src/platform/opengl/shader.h2
-rw-r--r--src/platform/opengl/texture.cpp18
4 files changed, 27 insertions, 32 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; }
diff --git a/src/platform/opengl/shader.cpp b/src/platform/opengl/shader.cpp
index 80015e6..757382b 100644
--- a/src/platform/opengl/shader.cpp
+++ b/src/platform/opengl/shader.cpp
@@ -19,8 +19,8 @@ namespace Donut
return 0;
}
- // Shaders are authored in Slang and compiled to assets/shaders/generated/
- // <name>.glsl by tools/compile-shaders.sh. Given a legacy ".../<name>.glsl"
+ // shaders are authored in Slang and compiled to assets/shaders/generated/
+ // <name>.glsl by tools/compile-shaders.sh. given a legacy ".../<name>.glsl"
// path, prefer that generated file when present; otherwise fall back to the
// hand-written GLSL (e.g. shaders not yet ported to Slang).
static std::string ResolveShaderPath(const std::string& filepath)
@@ -145,9 +145,9 @@ namespace Donut
glDeleteShader(id);
glDeleteProgram(program);
m_renderer_id = 0;
- // info_log.data() is null when the driver returns an empty log
- // (e.g. macOS rejecting a compute shader); streaming a null
- // char* into std::cout calls strlen(NULL) and crashes.
+ // info_log.data() is null when the driver hands back an empty log
+ // (e.g. macOS rejecting a compute shader). streaming a null char*
+ // into std::cout does strlen(NULL) and just explodes. cool cool cool.
const char* log = info_log.empty() ? "" : info_log.data();
std::cout << "Shader compilation failure!" << std::endl << log << std::endl;
return;
@@ -278,9 +278,9 @@ namespace Donut
auto Shader::dispatch(uint32_t x, uint32_t y, uint32_t z) -> void
{
- // Compute shaders require OpenGL 4.3+. On drivers that cap out earlier
- // (e.g. macOS, which is frozen at 4.1) glDispatchCompute is never
- // loaded and the pointer is null. Guard so we no-op instead of crash.
+ // compute shaders want OpenGL 4.3+ and macOS is frozen at 4.1, so
+ // glDispatchCompute never even loads and the pointer is null. guard it
+ // and quietly no-op instead of face-planting.
if (m_renderer_id == 0 || glDispatchCompute == nullptr)
return;
glDispatchCompute(x, y, z);
diff --git a/src/platform/opengl/shader.h b/src/platform/opengl/shader.h
index 409aca3..89963c7 100644
--- a/src/platform/opengl/shader.h
+++ b/src/platform/opengl/shader.h
@@ -59,7 +59,7 @@ namespace Donut
uint32_t m_renderer_id = 0;
std::string m_name;
- // True when loaded from a Slang-compiled GLSL. Slang expects row-major
+ // true when loaded from a Slang-compiled GLSL. Slang expects row-major
// matrix data, so matrix uniforms are transposed on upload (glm is
// column-major) to keep all matrix math correct.
bool m_is_slang = false;
diff --git a/src/platform/opengl/texture.cpp b/src/platform/opengl/texture.cpp
index 12e07f1..d2d2233 100644
--- a/src/platform/opengl/texture.cpp
+++ b/src/platform/opengl/texture.cpp
@@ -11,10 +11,10 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
-// NOTE: This file targets OpenGL 4.1 (the maximum macOS exposes). It uses the
+// this file targets OpenGL 4.1 (the maximum macOS exposes). it uses the
// classic bind-based texture API rather than 4.5 Direct State Access
// (glCreateTextures / glTextureStorage2D / glTextureParameteri / glBindTextureUnit),
-// none of which exist on macOS. It also hosts the single STB_IMAGE_IMPLEMENTATION
+// none of which exist on macOS. it also hosts the single STB_IMAGE_IMPLEMENTATION
// for the whole build (the Vulkan backend links stbi_loadf from here too).
namespace Donut
@@ -84,7 +84,7 @@ namespace Donut
auto Texture2D::bind_as_image(uint32_t slot, bool read_only) const -> void
{
- // Image load/store is OpenGL 4.2 and unavailable on macOS. Guard the
+ // image load/store is OpenGL 4.2 and unavailable on macOS. guard the
// function pointer so this degrades to a no-op instead of crashing.
if (glBindImageTexture == nullptr)
return;
@@ -148,12 +148,12 @@ namespace Donut
DONUT_ERROR("Failed to load HDRI: {}", path);
float default_sky[6 * 4] =
{
- 0.5f, 0.7f, 1.0f, 1.0f, // Right
- 0.5f, 0.7f, 1.0f, 1.0f, // Left
- 0.5f, 0.7f, 1.0f, 1.0f, // Top
- 0.5f, 0.7f, 1.0f, 1.0f, // Bottom
- 0.5f, 0.7f, 1.0f, 1.0f, // Front
- 0.5f, 0.7f, 1.0f, 1.0f // Back
+ 0.5f, 0.7f, 1.0f, 1.0f, // right
+ 0.5f, 0.7f, 1.0f, 1.0f, // left
+ 0.5f, 0.7f, 1.0f, 1.0f, // top
+ 0.5f, 0.7f, 1.0f, 1.0f, // bottom
+ 0.5f, 0.7f, 1.0f, 1.0f, // front
+ 0.5f, 0.7f, 1.0f, 1.0f // back
};
glBindTexture(GL_TEXTURE_CUBE_MAP, m_renderer_id);