summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2022-01-19 22:49:52 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-20 10:35:01 +0100
commit453f62c935a8c6b282d4a605dfd2007185d9e3d7 (patch)
treeac1a599921bb2566930a5d59c91664d02ad2f5a3
parent991cbc56a28a659613ad11039ef61d968d6769bb (diff)
downloadserenity-453f62c935a8c6b282d4a605dfd2007185d9e3d7.zip
LibGL+LibSoftGPU: Implement `GL_POLYGON_OFFSET_FILL` capability
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.cpp12
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.h3
-rw-r--r--Userland/Libraries/LibSoftGPU/Device.cpp3
-rw-r--r--Userland/Libraries/LibSoftGPU/Device.h1
4 files changed, 17 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
index fed22b9269..dc310e6721 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -168,6 +168,8 @@ Optional<ContextParameter> SoftwareGLContext::get_context_parameter(GLenum name)
return ContextParameter { .type = GL_INT, .value = { .integer_value = 0 } };
case GL_PACK_SWAP_BYTES:
return ContextParameter { .type = GL_BOOL, .value = { .boolean_value = false } };
+ case GL_POLYGON_OFFSET_FILL:
+ return ContextParameter { .type = GL_BOOL, .is_capability = true, .value = { .boolean_value = m_depth_offset_enabled } };
case GL_RED_BITS:
return ContextParameter { .type = GL_INT, .value = { .integer_value = sizeof(float) * 8 } };
case GL_SCISSOR_BOX: {
@@ -723,6 +725,11 @@ void SoftwareGLContext::gl_enable(GLenum capability)
rasterizer_options.normalization_enabled = true;
update_rasterizer_options = true;
break;
+ case GL_POLYGON_OFFSET_FILL:
+ m_depth_offset_enabled = true;
+ rasterizer_options.depth_offset_enabled = true;
+ update_rasterizer_options = true;
+ break;
case GL_SCISSOR_TEST:
rasterizer_options.scissor_enabled = true;
update_rasterizer_options = true;
@@ -836,6 +843,11 @@ void SoftwareGLContext::gl_disable(GLenum capability)
rasterizer_options.normalization_enabled = false;
update_rasterizer_options = true;
break;
+ case GL_POLYGON_OFFSET_FILL:
+ m_depth_offset_enabled = false;
+ rasterizer_options.depth_offset_enabled = false;
+ update_rasterizer_options = true;
+ break;
case GL_SCISSOR_TEST:
rasterizer_options.scissor_enabled = false;
update_rasterizer_options = true;
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h
index ce4ebd73f5..bd0b5fb579 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.h
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.h
@@ -212,7 +212,8 @@ private:
GLenum m_error = GL_NO_ERROR;
bool m_in_draw_state = false;
- bool m_depth_test_enabled = false;
+ bool m_depth_test_enabled { false };
+ bool m_depth_offset_enabled { false };
bool m_cull_faces = false;
GLenum m_front_face = GL_CCW;
diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp
index 1268342006..444a3d365f 100644
--- a/Userland/Libraries/LibSoftGPU/Device.cpp
+++ b/Userland/Libraries/LibSoftGPU/Device.cpp
@@ -413,7 +413,8 @@ void Device::rasterize_triangle(const Triangle& triangle)
quad.depth = interpolate(vertex0.window_coordinates.z(), vertex1.window_coordinates.z(), vertex2.window_coordinates.z(), quad.barycentrics);
// FIXME: Also apply depth_offset_factor which depends on the depth gradient
- quad.depth += m_options.depth_offset_constant * NumericLimits<float>::epsilon();
+ if (m_options.depth_offset_enabled)
+ quad.depth += m_options.depth_offset_constant * NumericLimits<float>::epsilon();
i32x4 depth_test_passed;
switch (m_options.depth_func) {
diff --git a/Userland/Libraries/LibSoftGPU/Device.h b/Userland/Libraries/LibSoftGPU/Device.h
index d8de64fe3b..79246ce56a 100644
--- a/Userland/Libraries/LibSoftGPU/Device.h
+++ b/Userland/Libraries/LibSoftGPU/Device.h
@@ -66,6 +66,7 @@ struct RasterizerOptions {
bool enable_color_write { true };
float depth_offset_factor { 0 };
float depth_offset_constant { 0 };
+ bool depth_offset_enabled { false };
bool enable_culling { false };
WindingOrder front_face { WindingOrder::CounterClockwise };
bool cull_back { true };