Explorar o código

LibSoftGPU: Remove GLenum used for selecting rendered primitive type

This removes the last reference to LibGL from LibSoftGPU. The GLenum
has been replaced by our own enum.
Stephan Unverwerth %!s(int64=3) %!d(string=hai) anos
pai
achega
f7c40b25ac

+ 21 - 1
Userland/Libraries/LibGL/SoftwareGLContext.cpp

@@ -231,7 +231,27 @@ void SoftwareGLContext::gl_end()
     }
 
     sync_device_config();
-    m_rasterizer.draw_primitives(m_current_draw_mode, m_projection_matrix * m_model_view_matrix, m_texture_matrix, m_vertex_list, enabled_texture_units);
+
+    SoftGPU::PrimitiveType primitive_type;
+    switch (m_current_draw_mode) {
+    case GL_TRIANGLES:
+        primitive_type = SoftGPU::PrimitiveType::Triangles;
+        break;
+    case GL_TRIANGLE_STRIP:
+        primitive_type = SoftGPU::PrimitiveType::TriangleStrip;
+        break;
+    case GL_TRIANGLE_FAN:
+    case GL_POLYGON:
+        primitive_type = SoftGPU::PrimitiveType::TriangleFan;
+        break;
+    case GL_QUADS:
+        primitive_type = SoftGPU::PrimitiveType::Quads;
+        break;
+    default:
+        VERIFY_NOT_REACHED();
+    }
+
+    m_rasterizer.draw_primitives(primitive_type, m_projection_matrix * m_model_view_matrix, m_texture_matrix, m_vertex_list, enabled_texture_units);
 
     m_vertex_list.clear_with_capacity();
 }

+ 5 - 5
Userland/Libraries/LibSoftGPU/Device.cpp

@@ -498,7 +498,7 @@ Device::Device(const Gfx::IntSize& min_size)
     m_options.scissor_box = m_render_target->rect();
 }
 
-void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units)
+void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units)
 {
     // At this point, the user has effectively specified that they are done with defining the geometry
     // of what they want to draw. We now need to do a few things (https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview):
@@ -517,7 +517,7 @@ void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transf
     m_processed_triangles.clear_with_capacity();
 
     // Let's construct some triangles
-    if (primitive_type == GL_TRIANGLES) {
+    if (primitive_type == PrimitiveType::Triangles) {
         Triangle triangle;
         for (size_t i = 0; i < vertices.size(); i += 3) {
             triangle.vertices[0] = vertices.at(i);
@@ -526,7 +526,7 @@ void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transf
 
             m_triangle_list.append(triangle);
         }
-    } else if (primitive_type == GL_QUADS) {
+    } else if (primitive_type == PrimitiveType::Quads) {
         // We need to construct two triangles to form the quad
         Triangle triangle;
         VERIFY(vertices.size() % 4 == 0);
@@ -543,7 +543,7 @@ void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transf
             triangle.vertices[2] = vertices.at(i);
             m_triangle_list.append(triangle);
         }
-    } else if (primitive_type == GL_TRIANGLE_FAN || primitive_type == GL_POLYGON) {
+    } else if (primitive_type == PrimitiveType::TriangleFan) {
         Triangle triangle;
         triangle.vertices[0] = vertices.at(0); // Root vertex is always the vertex defined first
 
@@ -553,7 +553,7 @@ void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transf
             triangle.vertices[2] = vertices.at(i + 1);
             m_triangle_list.append(triangle);
         }
-    } else if (primitive_type == GL_TRIANGLE_STRIP) {
+    } else if (primitive_type == PrimitiveType::TriangleStrip) {
         Triangle triangle;
         for (size_t i = 0; i < vertices.size() - 2; i++) {
             triangle.vertices[0] = vertices.at(i);

+ 8 - 4
Userland/Libraries/LibSoftGPU/Device.h

@@ -9,9 +9,6 @@
 #include <AK/Array.h>
 #include <AK/NonnullRefPtr.h>
 #include <AK/OwnPtr.h>
-#include <LibGL/GL/gl.h>
-#include <LibGL/Tex/Texture2D.h>
-#include <LibGL/Tex/TextureUnit.h>
 #include <LibGfx/Bitmap.h>
 #include <LibGfx/Matrix4x4.h>
 #include <LibGfx/Rect.h>
@@ -79,6 +76,13 @@ enum class WindingOrder {
     CounterClockwise,
 };
 
+enum class PrimitiveType {
+    Triangles,
+    TriangleStrip,
+    TriangleFan,
+    Quads,
+};
+
 struct RasterizerOptions {
     bool shade_smooth { true };
     bool enable_depth_test { false };
@@ -117,7 +121,7 @@ class Device final {
 public:
     Device(const Gfx::IntSize& min_size);
 
-    void draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units);
+    void draw_primitives(PrimitiveType, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units);
     void resize(const Gfx::IntSize& min_size);
     void clear_color(const FloatVector4&);
     void clear_depth(float);