1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +00:00

LibSoftGPU: Remove OpenGL type for depth test func

Replaces the GLenum used in the RasterizerConfig for selecting the depth
test function with out own enum.
This commit is contained in:
Stephan Unverwerth 2021-12-22 23:38:13 +01:00 committed by Brian Gianforcaro
parent 33e601800c
commit 74ed7713fa
3 changed files with 50 additions and 10 deletions

View file

@ -2130,7 +2130,36 @@ void SoftwareGLContext::gl_depth_func(GLenum func)
GL_INVALID_ENUM); GL_INVALID_ENUM);
auto options = m_rasterizer.options(); auto options = m_rasterizer.options();
options.depth_func = func;
switch (func) {
case GL_NEVER:
options.depth_func = SoftGPU::DepthTestFunction::Never;
break;
case GL_ALWAYS:
options.depth_func = SoftGPU::DepthTestFunction::Always;
break;
case GL_LESS:
options.depth_func = SoftGPU::DepthTestFunction::Less;
break;
case GL_LEQUAL:
options.depth_func = SoftGPU::DepthTestFunction::LessOrEqual;
break;
case GL_EQUAL:
options.depth_func = SoftGPU::DepthTestFunction::Equal;
break;
case GL_NOTEQUAL:
options.depth_func = SoftGPU::DepthTestFunction::NotEqual;
break;
case GL_GEQUAL:
options.depth_func = SoftGPU::DepthTestFunction::GreaterOrEqual;
break;
case GL_GREATER:
options.depth_func = SoftGPU::DepthTestFunction::Greater;
break;
default:
VERIFY_NOT_REACHED();
}
m_rasterizer.set_options(options); m_rasterizer.set_options(options);
} }

View file

@ -285,26 +285,26 @@ static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& re
bool pass = false; bool pass = false;
switch (options.depth_func) { switch (options.depth_func) {
case GL_ALWAYS: case DepthTestFunction::Always:
pass = true; pass = true;
break; break;
case GL_NEVER: case DepthTestFunction::Never:
pass = false; pass = false;
break; break;
case GL_GREATER: case DepthTestFunction::Greater:
pass = z > *depth; pass = z > *depth;
break; break;
case GL_GEQUAL: case DepthTestFunction::GreaterOrEqual:
pass = z >= *depth; pass = z >= *depth;
break; break;
case GL_NOTEQUAL: case DepthTestFunction::NotEqual:
#ifdef __SSE__ #ifdef __SSE__
pass = z != *depth; pass = z != *depth;
#else #else
pass = bit_cast<u32>(z) != bit_cast<u32>(*depth); pass = bit_cast<u32>(z) != bit_cast<u32>(*depth);
#endif #endif
break; break;
case GL_EQUAL: case DepthTestFunction::Equal:
#ifdef __SSE__ #ifdef __SSE__
pass = z == *depth; pass = z == *depth;
#else #else
@ -322,10 +322,10 @@ static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& re
pass = bit_cast<u32>(z) == bit_cast<u32>(*depth); pass = bit_cast<u32>(z) == bit_cast<u32>(*depth);
#endif #endif
break; break;
case GL_LEQUAL: case DepthTestFunction::LessOrEqual:
pass = z <= *depth; pass = z <= *depth;
break; break;
case GL_LESS: case DepthTestFunction::Less:
pass = z < *depth; pass = z < *depth;
break; break;
} }

View file

@ -51,6 +51,17 @@ enum class BlendFactor {
SrcAlphaSaturate, SrcAlphaSaturate,
}; };
enum class DepthTestFunction {
Never,
Always,
Less,
LessOrEqual,
Equal,
NotEqual,
GreaterOrEqual,
Greater,
};
enum class WindingOrder { enum class WindingOrder {
Clockwise, Clockwise,
CounterClockwise, CounterClockwise,
@ -69,7 +80,7 @@ struct RasterizerOptions {
u32 color_mask { 0xffffffff }; u32 color_mask { 0xffffffff };
float depth_min { 0 }; float depth_min { 0 };
float depth_max { 1 }; float depth_max { 1 };
GLenum depth_func { GL_LESS }; DepthTestFunction depth_func { DepthTestFunction::Less };
GLenum polygon_mode { GL_FILL }; GLenum polygon_mode { GL_FILL };
FloatVector4 fog_color { 0.0f, 0.0f, 0.0f, 0.0f }; FloatVector4 fog_color { 0.0f, 0.0f, 0.0f, 0.0f };
float fog_density { 1.0f }; float fog_density { 1.0f };