LibGL+LibSoftGPU: Implement GL_POLYGON_OFFSET_FILL capability

This commit is contained in:
Jelle Raaijmakers 2022-01-19 22:49:52 +01:00 committed by Andreas Kling
parent 991cbc56a2
commit 453f62c935
4 changed files with 17 additions and 2 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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) {

View file

@ -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 };