diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2022-02-21 01:26:27 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-02-22 23:48:59 +0000 |
commit | 44a3d5c101819ebc28b7d6db64a1026e248cb9be (patch) | |
tree | 370166da8f074c39ab13a80523c4a28a75d06c5a /Userland/Libraries/LibGL | |
parent | 36a732e98eefbbe4af8110c454a04def0a821ca4 (diff) | |
download | serenity-44a3d5c101819ebc28b7d6db64a1026e248cb9be.zip |
LibGL: Implement `glClearDepthf` and store as float
Our API still specifies it as a double, but internally we communicate a
float to the rasterizer. Additionally, clamp the value to 0..1 as
described in the spec.
Diffstat (limited to 'Userland/Libraries/LibGL')
-rw-r--r-- | Userland/Libraries/LibGL/GL/gl.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLUtils.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.h | 2 |
4 files changed, 9 insertions, 3 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index ec4b83b0f7..6aba866260 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -474,6 +474,7 @@ GLAPI void glBegin(GLenum mode); GLAPI void glClear(GLbitfield mask); GLAPI void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); GLAPI void glClearDepth(GLdouble depth); +GLAPI void glClearDepthf(GLfloat depth); GLAPI void glClearStencil(GLint s); GLAPI void glColor3d(GLdouble r, GLdouble g, GLdouble b); GLAPI void glColor3dv(GLdouble const* v); diff --git a/Userland/Libraries/LibGL/GLUtils.cpp b/Userland/Libraries/LibGL/GLUtils.cpp index 1ba627d5bc..c5cf954be1 100644 --- a/Userland/Libraries/LibGL/GLUtils.cpp +++ b/Userland/Libraries/LibGL/GLUtils.cpp @@ -50,6 +50,11 @@ void glClearDepth(GLdouble depth) g_gl_context->gl_clear_depth(depth); } +void glClearDepthf(GLfloat depth) +{ + g_gl_context->gl_clear_depth(static_cast<double>(depth)); +} + void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { g_gl_context->gl_color_mask(red, green, blue, alpha); diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 608963d07e..eb751807a7 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -267,7 +267,7 @@ void SoftwareGLContext::gl_clear(GLbitfield mask) m_rasterizer.clear_color(m_clear_color); if (mask & GL_DEPTH_BUFFER_BIT) - m_rasterizer.clear_depth(static_cast<float>(m_clear_depth)); + m_rasterizer.clear_depth(m_clear_depth); if (mask & GL_STENCIL_BUFFER_BIT) m_rasterizer.clear_stencil(m_clear_stencil); @@ -288,7 +288,7 @@ void SoftwareGLContext::gl_clear_depth(GLdouble depth) RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); - m_clear_depth = depth; + m_clear_depth = clamp(static_cast<float>(depth), 0.f, 1.f); } void SoftwareGLContext::gl_clear_stencil(GLint s) diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index ae7bc6981e..02395e54c9 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -208,7 +208,7 @@ private: Gfx::IntRect m_viewport; FloatVector4 m_clear_color { 0.0f, 0.0f, 0.0f, 0.0f }; - double m_clear_depth { 1.0 }; + float m_clear_depth { 1.f }; u8 m_clear_stencil { 0 }; FloatVector4 m_current_vertex_color = { 1.0f, 1.0f, 1.0f, 1.0f }; |