summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Unverwerth <s.unverwerth@serenityos.org>2021-08-13 01:06:26 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-14 12:49:29 +0200
commit5f863016ca82b643b98f3759469e2f0b38f83485 (patch)
treedccefaac37faba76ebc8e0ba114ccf02a8f409ab
parent010e344a8ea3958c0032bc80cf132dd52873a512 (diff)
downloadserenity-5f863016ca82b643b98f3759469e2f0b38f83485.zip
LibGL: Implement glDepthMask
-rw-r--r--Userland/Libraries/LibGL/GL/gl.h2
-rw-r--r--Userland/Libraries/LibGL/GLContext.h1
-rw-r--r--Userland/Libraries/LibGL/GLUtils.cpp5
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.cpp11
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.h4
-rw-r--r--Userland/Libraries/LibGL/SoftwareRasterizer.cpp4
-rw-r--r--Userland/Libraries/LibGL/SoftwareRasterizer.h1
7 files changed, 26 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h
index 7ccf501a63..8cf5b85155 100644
--- a/Userland/Libraries/LibGL/GL/gl.h
+++ b/Userland/Libraries/LibGL/GL/gl.h
@@ -263,6 +263,7 @@ typedef char GLchar;
typedef char GLbyte;
typedef unsigned char GLuchar;
typedef unsigned char GLubyte;
+typedef unsigned char GLboolean;
typedef short GLshort;
typedef unsigned short GLushort;
typedef int GLint;
@@ -352,6 +353,7 @@ GLAPI void glTexParameterf(GLenum target, GLenum pname, GLfloat param);
GLAPI void glBindTexture(GLenum target, GLuint texture);
GLAPI void glActiveTexture(GLenum texture);
GLAPI void glGetFloatv(GLenum pname, GLfloat* params);
+GLAPI void glDepthMask(GLboolean flag);
#ifdef __cplusplus
}
diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h
index cf4966a4f0..f518e8ab47 100644
--- a/Userland/Libraries/LibGL/GLContext.h
+++ b/Userland/Libraries/LibGL/GLContext.h
@@ -63,6 +63,7 @@ public:
virtual void gl_bind_texture(GLenum target, GLuint texture) = 0;
virtual void gl_active_texture(GLenum texture) = 0;
virtual void gl_get_floatv(GLenum pname, GLfloat* params) = 0;
+ virtual void gl_depth_mask(GLboolean flag) = 0;
virtual void present() = 0;
};
diff --git a/Userland/Libraries/LibGL/GLUtils.cpp b/Userland/Libraries/LibGL/GLUtils.cpp
index 732315fdd0..bdd374a410 100644
--- a/Userland/Libraries/LibGL/GLUtils.cpp
+++ b/Userland/Libraries/LibGL/GLUtils.cpp
@@ -89,3 +89,8 @@ void glGetFloatv(GLenum pname, GLfloat* params)
{
g_gl_context->gl_get_floatv(pname, params);
}
+
+void glDepthMask(GLboolean flag)
+{
+ g_gl_context->gl_depth_mask(flag);
+}
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
index d1b5bc4c5d..c50fece334 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -1392,6 +1392,17 @@ void SoftwareGLContext::gl_get_floatv(GLenum pname, GLfloat* params)
}
}
+void SoftwareGLContext::gl_depth_mask(GLboolean flag)
+{
+ APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_depth_mask, flag);
+
+ RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
+
+ auto options = m_rasterizer.options();
+ options.enable_depth_write = (flag != GL_FALSE);
+ m_rasterizer.set_options(options);
+}
+
void SoftwareGLContext::present()
{
m_rasterizer.blit_to(*m_frontbuffer);
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h
index 4192fa8cde..02dade49ed 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.h
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.h
@@ -73,6 +73,7 @@ public:
virtual void gl_bind_texture(GLenum target, GLuint texture) override;
virtual void gl_active_texture(GLenum texture) override;
virtual void gl_get_floatv(GLenum pname, GLfloat* params) override;
+ virtual void gl_depth_mask(GLboolean flag) override;
virtual void present() override;
@@ -196,7 +197,8 @@ private:
decltype(&SoftwareGLContext::gl_alpha_func),
decltype(&SoftwareGLContext::gl_hint),
decltype(&SoftwareGLContext::gl_read_buffer),
- decltype(&SoftwareGLContext::gl_tex_parameter)>;
+ decltype(&SoftwareGLContext::gl_tex_parameter),
+ decltype(&SoftwareGLContext::gl_depth_mask)>;
using ExtraSavedArguments = Variant<
FloatMatrix4x4>;
diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp
index a320a13ce4..61c17aa173 100644
--- a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp
+++ b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp
@@ -265,7 +265,9 @@ static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& re
continue;
}
- *depth = z;
+ if (options.enable_depth_write)
+ *depth = z;
+
z_pass_count++;
}
}
diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.h b/Userland/Libraries/LibGL/SoftwareRasterizer.h
index 19f7ce1c84..6d4d15f2cf 100644
--- a/Userland/Libraries/LibGL/SoftwareRasterizer.h
+++ b/Userland/Libraries/LibGL/SoftwareRasterizer.h
@@ -21,6 +21,7 @@ namespace GL {
struct RasterizerOptions {
bool shade_smooth { true };
bool enable_depth_test { false };
+ bool enable_depth_write { true };
bool enable_alpha_test { false };
GLenum alpha_test_func { GL_ALWAYS };
float alpha_test_ref_value { 0 };