mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 20:27:35 +00:00
LibGL: Implement glDepthRange
This commit is contained in:
parent
3dd9efd35f
commit
a97dbd2317
7 changed files with 26 additions and 1 deletions
|
@ -369,6 +369,7 @@ GLAPI void glColorPointer(GLint size, GLenum type, GLsizei stride, const void* p
|
|||
GLAPI void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void* pointer);
|
||||
GLAPI void glDrawArrays(GLenum mode, GLint first, GLsizei count);
|
||||
GLAPI void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices);
|
||||
GLAPI void glDepthRange(GLdouble nearVal, GLdouble farVal);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ public:
|
|||
virtual void gl_color_mask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) = 0;
|
||||
virtual void gl_get_booleanv(GLenum pname, GLboolean* data) = 0;
|
||||
virtual void gl_get_integerv(GLenum pname, GLint* data) = 0;
|
||||
virtual void gl_depth_range(GLdouble min, GLdouble max) = 0;
|
||||
|
||||
virtual void present() = 0;
|
||||
};
|
||||
|
|
|
@ -119,3 +119,8 @@ void glDisableClientState(GLenum cap)
|
|||
{
|
||||
g_gl_context->gl_disable_client_state(cap);
|
||||
}
|
||||
|
||||
void glDepthRange(GLdouble min, GLdouble max)
|
||||
{
|
||||
g_gl_context->gl_depth_range(min, max);
|
||||
}
|
||||
|
|
|
@ -1641,6 +1641,18 @@ void SoftwareGLContext::gl_draw_elements(GLenum mode, GLsizei count, GLenum type
|
|||
glEnd();
|
||||
}
|
||||
|
||||
void SoftwareGLContext::gl_depth_range(GLdouble min, GLdouble max)
|
||||
{
|
||||
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_depth_range, min, max);
|
||||
|
||||
RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
|
||||
|
||||
auto options = m_rasterizer.options();
|
||||
options.depth_min = clamp(min, 0.f, 1.f);
|
||||
options.depth_max = clamp(max, 0.f, 1.f);
|
||||
m_rasterizer.set_options(options);
|
||||
}
|
||||
|
||||
// General helper function to read arbitrary vertex attribute data into a float array
|
||||
void SoftwareGLContext::read_from_vertex_attribute_pointer(VertexAttribPointer const& attrib, int index, float* elements, bool normalize)
|
||||
{
|
||||
|
|
|
@ -84,6 +84,7 @@ public:
|
|||
virtual void gl_color_mask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) override;
|
||||
virtual void gl_get_booleanv(GLenum pname, GLboolean* data) override;
|
||||
virtual void gl_get_integerv(GLenum pname, GLint* data) override;
|
||||
virtual void gl_depth_range(GLdouble min, GLdouble max) override;
|
||||
virtual void present() override;
|
||||
|
||||
private:
|
||||
|
@ -215,7 +216,8 @@ private:
|
|||
decltype(&SoftwareGLContext::gl_tex_parameter),
|
||||
decltype(&SoftwareGLContext::gl_depth_mask),
|
||||
decltype(&SoftwareGLContext::gl_draw_arrays),
|
||||
decltype(&SoftwareGLContext::gl_draw_elements)>;
|
||||
decltype(&SoftwareGLContext::gl_draw_elements),
|
||||
decltype(&SoftwareGLContext::gl_depth_range)>;
|
||||
|
||||
using ExtraSavedArguments = Variant<
|
||||
FloatMatrix4x4>;
|
||||
|
|
|
@ -260,6 +260,8 @@ static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& re
|
|||
|
||||
auto barycentric = FloatVector3(coords.x(), coords.y(), coords.z()) * one_over_area;
|
||||
float z = interpolate(triangle.vertices[0].z, triangle.vertices[1].z, triangle.vertices[2].z, barycentric);
|
||||
z = options.depth_min + (options.depth_max - options.depth_min) * (z + 1) / 2;
|
||||
|
||||
if (z >= *depth) {
|
||||
pixel_mask[y] ^= 1 << x;
|
||||
continue;
|
||||
|
|
|
@ -29,6 +29,8 @@ struct RasterizerOptions {
|
|||
GLenum blend_source_factor { GL_ONE };
|
||||
GLenum blend_destination_factor { GL_ONE };
|
||||
u32 color_mask { 0xffffffff };
|
||||
float depth_min { 0 };
|
||||
float depth_max { 1 };
|
||||
};
|
||||
|
||||
class SoftwareRasterizer final {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue