Browse Source

LibGL+LibSoftGPU: Implement `GL_POLYGON_OFFSET_FILL` capability

Jelle Raaijmakers 3 years ago
parent
commit
453f62c935

+ 12 - 0
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;

+ 2 - 1
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;

+ 2 - 1
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) {

+ 1 - 0
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 };