summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Unverwerth <s.unverwerth@serenityos.org>2021-08-31 20:50:01 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-09-02 21:00:24 +0430
commit15299b763cf3c5b8b8cbf508f01eabe08afe6bcd (patch)
treec82febd4d4ae2fcca1dbaabdcbacd99cb05e660e
parent7cbaaf8366d1baa824392c63bb9a92d3ff5842ae (diff)
downloadserenity-15299b763cf3c5b8b8cbf508f01eabe08afe6bcd.zip
LibGL: Implement glPolygonOffset
-rw-r--r--Userland/Libraries/LibGL/GL/gl.h1
-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.cpp3
-rw-r--r--Userland/Libraries/LibGL/SoftwareRasterizer.h2
7 files changed, 26 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h
index 5f88037f27..7499361aa5 100644
--- a/Userland/Libraries/LibGL/GL/gl.h
+++ b/Userland/Libraries/LibGL/GL/gl.h
@@ -377,6 +377,7 @@ GLAPI void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* i
GLAPI void glDepthRange(GLdouble nearVal, GLdouble farVal);
GLAPI void glDepthFunc(GLenum func);
GLAPI void glPolygonMode(GLenum face, GLenum mode);
+GLAPI void glPolygonOffset(GLfloat factor, GLfloat units);
GLAPI void glFogfv(GLenum mode, GLfloat* params);
GLAPI void glFogf(GLenum pname, GLfloat param);
GLAPI void glFogi(GLenum pname, GLint param);
diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h
index c5f3d28679..a6429fd484 100644
--- a/Userland/Libraries/LibGL/GLContext.h
+++ b/Userland/Libraries/LibGL/GLContext.h
@@ -79,6 +79,7 @@ public:
virtual void gl_depth_range(GLdouble min, GLdouble max) = 0;
virtual void gl_depth_func(GLenum func) = 0;
virtual void gl_polygon_mode(GLenum face, GLenum mode) = 0;
+ virtual void gl_polygon_offset(GLfloat factor, GLfloat units) = 0;
virtual void gl_fogfv(GLenum pname, GLfloat* params) = 0;
virtual void gl_fogf(GLenum pname, GLfloat params) = 0;
virtual void gl_fogi(GLenum pname, GLint param) = 0;
diff --git a/Userland/Libraries/LibGL/GLUtils.cpp b/Userland/Libraries/LibGL/GLUtils.cpp
index 7098a47b5c..73bad7804c 100644
--- a/Userland/Libraries/LibGL/GLUtils.cpp
+++ b/Userland/Libraries/LibGL/GLUtils.cpp
@@ -140,6 +140,11 @@ void glPolygonMode(GLenum face, GLenum mode)
g_gl_context->gl_polygon_mode(face, mode);
}
+void glPolygonOffset(GLfloat factor, GLfloat units)
+{
+ g_gl_context->gl_polygon_offset(factor, units);
+}
+
void glPixelStorei(GLenum pname, GLint param)
{
g_gl_context->gl_pixel_store(pname, param);
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
index 920ca5ea9a..d19b8726e1 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -1819,6 +1819,17 @@ void SoftwareGLContext::gl_polygon_mode(GLenum face, GLenum mode)
m_rasterizer.set_options(options);
}
+void SoftwareGLContext::gl_polygon_offset(GLfloat factor, GLfloat units)
+{
+ APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_polygon_offset, factor, units);
+ RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
+
+ auto rasterizer_options = m_rasterizer.options();
+ rasterizer_options.depth_offset_factor = factor;
+ rasterizer_options.depth_offset_constant = units;
+ m_rasterizer.set_options(rasterizer_options);
+}
+
void SoftwareGLContext::gl_fogfv(GLenum pname, GLfloat* params)
{
RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h
index cb026ac363..3b7f466b6f 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.h
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.h
@@ -89,6 +89,7 @@ public:
virtual void gl_depth_range(GLdouble min, GLdouble max) override;
virtual void gl_depth_func(GLenum func) override;
virtual void gl_polygon_mode(GLenum face, GLenum mode) override;
+ virtual void gl_polygon_offset(GLfloat factor, GLfloat units) override;
virtual void gl_fogfv(GLenum pname, GLfloat* params) override;
virtual void gl_fogf(GLenum pname, GLfloat param) override;
virtual void gl_fogi(GLenum pname, GLint param) override;
@@ -227,7 +228,8 @@ private:
decltype(&SoftwareGLContext::gl_depth_mask),
decltype(&SoftwareGLContext::gl_draw_arrays),
decltype(&SoftwareGLContext::gl_draw_elements),
- decltype(&SoftwareGLContext::gl_depth_range)>;
+ decltype(&SoftwareGLContext::gl_depth_range),
+ decltype(&SoftwareGLContext::gl_polygon_offset)>;
using ExtraSavedArguments = Variant<
FloatMatrix4x4>;
diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp
index 3b968196bd..0df985367f 100644
--- a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp
+++ b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp
@@ -269,6 +269,9 @@ static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& re
z = options.depth_min + (options.depth_max - options.depth_min) * (z + 1) / 2;
+ // FIXME: Also apply depth_offset_factor which depends on the depth gradient
+ z += options.depth_offset_constant * NumericLimits<float>::epsilon();
+
bool pass = false;
switch (options.depth_func) {
case GL_ALWAYS:
diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.h b/Userland/Libraries/LibGL/SoftwareRasterizer.h
index 8d178116ff..aee17abeca 100644
--- a/Userland/Libraries/LibGL/SoftwareRasterizer.h
+++ b/Userland/Libraries/LibGL/SoftwareRasterizer.h
@@ -45,6 +45,8 @@ struct RasterizerOptions {
GLfloat fog_start { 0.0f };
GLfloat fog_end { 1.0f };
GLenum draw_buffer { GL_BACK };
+ GLfloat depth_offset_factor { 0 };
+ GLfloat depth_offset_constant { 0 };
};
class SoftwareRasterizer final {