mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
LibGL: Implement glDepthFunc
This commit is contained in:
parent
a97dbd2317
commit
5b9c87a8b5
7 changed files with 60 additions and 2 deletions
|
@ -370,6 +370,7 @@ GLAPI void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const void
|
|||
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);
|
||||
GLAPI void glDepthFunc(GLenum func);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ public:
|
|||
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 gl_depth_func(GLenum func) = 0;
|
||||
|
||||
virtual void present() = 0;
|
||||
};
|
||||
|
|
|
@ -124,3 +124,8 @@ void glDepthRange(GLdouble min, GLdouble max)
|
|||
{
|
||||
g_gl_context->gl_depth_range(min, max);
|
||||
}
|
||||
|
||||
void glDepthFunc(GLenum func)
|
||||
{
|
||||
g_gl_context->gl_depth_func(func);
|
||||
}
|
||||
|
|
|
@ -1653,6 +1653,27 @@ void SoftwareGLContext::gl_depth_range(GLdouble min, GLdouble max)
|
|||
m_rasterizer.set_options(options);
|
||||
}
|
||||
|
||||
void SoftwareGLContext::gl_depth_func(GLenum func)
|
||||
{
|
||||
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_depth_func, func);
|
||||
|
||||
RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
|
||||
|
||||
RETURN_WITH_ERROR_IF(!(func == GL_NEVER
|
||||
|| func == GL_LESS
|
||||
|| func == GL_EQUAL
|
||||
|| func == GL_LEQUAL
|
||||
|| func == GL_GREATER
|
||||
|| func == GL_NOTEQUAL
|
||||
|| func == GL_GEQUAL
|
||||
|| func == GL_ALWAYS),
|
||||
GL_INVALID_ENUM);
|
||||
|
||||
auto options = m_rasterizer.options();
|
||||
options.depth_func = func;
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -85,6 +85,7 @@ public:
|
|||
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 gl_depth_func(GLenum func) override;
|
||||
virtual void present() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -262,7 +262,35 @@ static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& re
|
|||
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) {
|
||||
bool pass = false;
|
||||
switch (options.depth_func) {
|
||||
case GL_ALWAYS:
|
||||
pass = true;
|
||||
break;
|
||||
case GL_NEVER:
|
||||
pass = false;
|
||||
break;
|
||||
case GL_GREATER:
|
||||
pass = z > *depth;
|
||||
break;
|
||||
case GL_GEQUAL:
|
||||
pass = z >= *depth;
|
||||
break;
|
||||
case GL_NOTEQUAL:
|
||||
pass = z != *depth;
|
||||
break;
|
||||
case GL_EQUAL:
|
||||
pass = z == *depth;
|
||||
break;
|
||||
case GL_LEQUAL:
|
||||
pass = z <= *depth;
|
||||
break;
|
||||
case GL_LESS:
|
||||
pass = z < *depth;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!pass) {
|
||||
pixel_mask[y] ^= 1 << x;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ struct RasterizerOptions {
|
|||
u32 color_mask { 0xffffffff };
|
||||
float depth_min { 0 };
|
||||
float depth_max { 1 };
|
||||
GLenum depth_func { GL_LESS };
|
||||
};
|
||||
|
||||
class SoftwareRasterizer final {
|
||||
|
|
Loading…
Add table
Reference in a new issue