summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibGL/GL/gl.h3
-rw-r--r--Userland/Libraries/LibGL/GLContext.h1
-rw-r--r--Userland/Libraries/LibGL/GLUtils.cpp5
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.cpp47
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.h4
-rw-r--r--Userland/Libraries/LibGL/SoftwareRasterizer.h1
6 files changed, 57 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h
index 3c9fa58bd3..05d861c999 100644
--- a/Userland/Libraries/LibGL/GL/gl.h
+++ b/Userland/Libraries/LibGL/GL/gl.h
@@ -31,9 +31,11 @@ extern "C" {
// Buffer bits
#define GL_COLOR_BUFFER_BIT 0x0200
+#define GL_DEPTH_BUFFER_BIT 0x0400
// Enable capabilities
#define GL_CULL_FACE 0x0B44
+#define GL_DEPTH_TEST 0x0B71
// Utility
#define GL_VENDOR 0x1F00
@@ -85,6 +87,7 @@ typedef unsigned int GLbitfield;
GLAPI void glBegin(GLenum mode);
GLAPI void glClear(GLbitfield mask);
GLAPI void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
+GLAPI void glClearDepth(GLdouble depth);
GLAPI void glColor3f(GLfloat r, GLfloat g, GLfloat b);
GLAPI void glColor4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
GLAPI void glColor4fv(const GLfloat* v);
diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h
index 76a91dee7b..4d7ec88cd2 100644
--- a/Userland/Libraries/LibGL/GLContext.h
+++ b/Userland/Libraries/LibGL/GLContext.h
@@ -21,6 +21,7 @@ public:
virtual void gl_begin(GLenum mode) = 0;
virtual void gl_clear(GLbitfield mask) = 0;
virtual void gl_clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) = 0;
+ virtual void gl_clear_depth(GLdouble depth) = 0;
virtual void gl_color(GLdouble r, GLdouble g, GLdouble b, GLdouble a) = 0;
virtual void gl_end() = 0;
virtual void gl_frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val) = 0;
diff --git a/Userland/Libraries/LibGL/GLUtils.cpp b/Userland/Libraries/LibGL/GLUtils.cpp
index faec566dea..0bfe7041d6 100644
--- a/Userland/Libraries/LibGL/GLUtils.cpp
+++ b/Userland/Libraries/LibGL/GLUtils.cpp
@@ -40,6 +40,11 @@ void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
g_gl_context->gl_clear_color(red, green, blue, alpha);
}
+void glClearDepth(GLdouble depth)
+{
+ g_gl_context->gl_clear_depth(depth);
+}
+
GLubyte* glGetString(GLenum name)
{
return g_gl_context->gl_get_string(name);
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
index 5d1073cb23..283b7391c5 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -55,12 +55,18 @@ void SoftwareGLContext::gl_clear(GLbitfield mask)
return;
}
- if (mask & GL_COLOR_BUFFER_BIT) {
- m_rasterizer.clear_color(m_clear_color);
- m_error = GL_NO_ERROR;
- } else {
+ if (mask & ~(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) {
m_error = GL_INVALID_ENUM;
+ return;
}
+
+ if (mask & GL_COLOR_BUFFER_BIT)
+ m_rasterizer.clear_color(m_clear_color);
+
+ if (mask & GL_DEPTH_BUFFER_BIT)
+ m_rasterizer.clear_depth(static_cast<float>(m_clear_depth));
+
+ m_error = GL_NO_ERROR;
}
void SoftwareGLContext::gl_clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
@@ -74,6 +80,17 @@ void SoftwareGLContext::gl_clear_color(GLclampf red, GLclampf green, GLclampf bl
m_error = GL_NO_ERROR;
}
+void SoftwareGLContext::gl_clear_depth(GLdouble depth)
+{
+ if (m_in_draw_state) {
+ m_error = GL_INVALID_OPERATION;
+ return;
+ }
+
+ m_clear_depth = depth;
+ m_error = GL_NO_ERROR;
+}
+
void SoftwareGLContext::gl_color(GLdouble r, GLdouble g, GLdouble b, GLdouble a)
{
m_current_vertex_color = { (float)r, (float)g, (float)b, (float)a };
@@ -601,14 +618,25 @@ void SoftwareGLContext::gl_enable(GLenum capability)
return;
}
+ auto rasterizer_options = m_rasterizer.options();
+ bool update_rasterizer_options = false;
+
switch (capability) {
case GL_CULL_FACE:
m_cull_faces = true;
break;
+ case GL_DEPTH_TEST:
+ m_depth_test_enabled = true;
+ rasterizer_options.enable_depth_test = true;
+ update_rasterizer_options = true;
+ break;
default:
m_error = GL_INVALID_ENUM;
break;
}
+
+ if (update_rasterizer_options)
+ m_rasterizer.set_options(rasterizer_options);
}
void SoftwareGLContext::gl_disable(GLenum capability)
@@ -618,14 +646,25 @@ void SoftwareGLContext::gl_disable(GLenum capability)
return;
}
+ auto rasterizer_options = m_rasterizer.options();
+ bool update_rasterizer_options = false;
+
switch (capability) {
case GL_CULL_FACE:
m_cull_faces = false;
break;
+ case GL_DEPTH_TEST:
+ m_depth_test_enabled = false;
+ rasterizer_options.enable_depth_test = false;
+ update_rasterizer_options = true;
+ break;
default:
m_error = GL_INVALID_ENUM;
break;
}
+
+ if (update_rasterizer_options)
+ m_rasterizer.set_options(rasterizer_options);
}
void SoftwareGLContext::gl_front_face(GLenum face)
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h
index 4b17713596..350415382b 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.h
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.h
@@ -25,6 +25,7 @@ public:
virtual void gl_begin(GLenum mode) override;
virtual void gl_clear(GLbitfield mask) override;
virtual void gl_clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) override;
+ virtual void gl_clear_depth(GLdouble depth) override;
virtual void gl_color(GLdouble r, GLdouble g, GLdouble b, GLdouble a) override;
virtual void gl_end() override;
virtual void gl_frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val) override;
@@ -60,6 +61,7 @@ private:
Vector<FloatMatrix4x4> m_model_view_matrix_stack;
FloatVector4 m_clear_color = { 0.0f, 0.0f, 0.0f, 0.0f };
+ double m_clear_depth = { 1.0 };
FloatVector4 m_current_vertex_color = { 1.0f, 1.0f, 1.0f, 1.0f };
Vector<GLVertex, 96> vertex_list;
@@ -69,6 +71,8 @@ private:
GLenum m_error = GL_NO_ERROR;
bool m_in_draw_state = false;
+ bool m_depth_test_enabled = false;
+
bool m_cull_faces = false;
GLenum m_front_face = GL_CCW;
GLenum m_culled_sides = GL_BACK;
diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.h b/Userland/Libraries/LibGL/SoftwareRasterizer.h
index 356bafe4c5..885b826b38 100644
--- a/Userland/Libraries/LibGL/SoftwareRasterizer.h
+++ b/Userland/Libraries/LibGL/SoftwareRasterizer.h
@@ -14,6 +14,7 @@ namespace GL {
struct RasterizerOptions {
bool shade_smooth { false };
+ bool enable_depth_test { false };
};
class SoftwareRasterizer final {