summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGL/GLContext.cpp
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2022-05-08 02:13:14 +0200
committerLinus Groh <mail@linusgroh.de>2022-05-09 21:49:48 +0200
commita20bf80b050659466a1bd118d594103c20ec3e6d (patch)
tree3b62a66e28b3b62bdd61b504d498b1de5c23c53b /Userland/Libraries/LibGL/GLContext.cpp
parent950ded7ab9768cb80117328a5d05dadee0b8b004 (diff)
downloadserenity-a20bf80b050659466a1bd118d594103c20ec3e6d.zip
LibGL+LibGPU+LibSoftGPU: Implement point and line drawing
Implement (anti)aliased point drawing and anti-aliased line drawing. Supported through LibGL's `GL_POINTS`, `GL_LINES`, `GL_LINE_LOOP` and `GL_LINE_STRIP`. In order to support this, `LibSoftGPU`s rasterization logic was reworked. Now, any primitive can be drawn by invoking `rasterize()` which takes care of the quad loop and fragment testing logic. Three callbacks need to be passed: * `set_coverage_mask`: the primitive needs to provide initial coverage mask information so fragments can be discarded early. * `set_quad_depth`: fragments survived stencil testing, so depth values need to be set so depth testing can take place. * `set_quad_attributes`: fragments survived depth testing, so fragment shading is going to take place. All attributes like color, tex coords and fog depth need to be set so alpha testing and eventually, fragment rasterization can take place. As of this commit, there are four instantiations of this function: * Triangle rasterization * Points - aliased * Points - anti-aliased * Lines - anti-aliased In order to standardize vertex processing for all primitive types, things like vertex transformation, lighting and tex coord generation are now taking place before clipping.
Diffstat (limited to 'Userland/Libraries/LibGL/GLContext.cpp')
-rw-r--r--Userland/Libraries/LibGL/GLContext.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/Userland/Libraries/LibGL/GLContext.cpp b/Userland/Libraries/LibGL/GLContext.cpp
index 2056ae929e..367074c446 100644
--- a/Userland/Libraries/LibGL/GLContext.cpp
+++ b/Userland/Libraries/LibGL/GLContext.cpp
@@ -133,22 +133,8 @@ void GLContext::gl_end()
// Make sure we had a `glBegin` before this call...
RETURN_WITH_ERROR_IF(!m_in_draw_state, GL_INVALID_OPERATION);
-
m_in_draw_state = false;
- // FIXME: Add support for the remaining primitive types.
- if (m_current_draw_mode != GL_TRIANGLES
- && m_current_draw_mode != GL_TRIANGLE_FAN
- && m_current_draw_mode != GL_TRIANGLE_STRIP
- && m_current_draw_mode != GL_QUADS
- && m_current_draw_mode != GL_QUAD_STRIP
- && m_current_draw_mode != GL_POLYGON) {
-
- m_vertex_list.clear_with_capacity();
- dbgln_if(GL_DEBUG, "gl_end(): draw mode {:#x} unsupported", m_current_draw_mode);
- RETURN_WITH_ERROR_IF(true, GL_INVALID_ENUM);
- }
-
Vector<size_t, 32> enabled_texture_units;
for (size_t i = 0; i < m_texture_units.size(); ++i) {
if (m_texture_units[i].texture_2d_enabled())
@@ -159,6 +145,18 @@ void GLContext::gl_end()
GPU::PrimitiveType primitive_type;
switch (m_current_draw_mode) {
+ case GL_LINE_LOOP:
+ primitive_type = GPU::PrimitiveType::LineLoop;
+ break;
+ case GL_LINE_STRIP:
+ primitive_type = GPU::PrimitiveType::LineStrip;
+ break;
+ case GL_LINES:
+ primitive_type = GPU::PrimitiveType::Lines;
+ break;
+ case GL_POINTS:
+ primitive_type = GPU::PrimitiveType::Points;
+ break;
case GL_TRIANGLES:
primitive_type = GPU::PrimitiveType::Triangles;
break;
@@ -178,7 +176,6 @@ void GLContext::gl_end()
}
m_rasterizer->draw_primitives(primitive_type, m_model_view_matrix, m_projection_matrix, m_texture_matrix, m_vertex_list, enabled_texture_units);
-
m_vertex_list.clear_with_capacity();
}