mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
LibGL: Implement glPolygonOffset
This commit is contained in:
parent
7cbaaf8366
commit
15299b763c
7 changed files with 26 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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>;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue