Skip to content

Commit f7c40b2

Browse files
sunverwerthbgianfo
authored andcommitted
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.
1 parent de00691 commit f7c40b2

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

Userland/Libraries/LibGL/SoftwareGLContext.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,27 @@ void SoftwareGLContext::gl_end()
231231
}
232232

233233
sync_device_config();
234-
m_rasterizer.draw_primitives(m_current_draw_mode, m_projection_matrix * m_model_view_matrix, m_texture_matrix, m_vertex_list, enabled_texture_units);
234+
235+
SoftGPU::PrimitiveType primitive_type;
236+
switch (m_current_draw_mode) {
237+
case GL_TRIANGLES:
238+
primitive_type = SoftGPU::PrimitiveType::Triangles;
239+
break;
240+
case GL_TRIANGLE_STRIP:
241+
primitive_type = SoftGPU::PrimitiveType::TriangleStrip;
242+
break;
243+
case GL_TRIANGLE_FAN:
244+
case GL_POLYGON:
245+
primitive_type = SoftGPU::PrimitiveType::TriangleFan;
246+
break;
247+
case GL_QUADS:
248+
primitive_type = SoftGPU::PrimitiveType::Quads;
249+
break;
250+
default:
251+
VERIFY_NOT_REACHED();
252+
}
253+
254+
m_rasterizer.draw_primitives(primitive_type, m_projection_matrix * m_model_view_matrix, m_texture_matrix, m_vertex_list, enabled_texture_units);
235255

236256
m_vertex_list.clear_with_capacity();
237257
}

Userland/Libraries/LibSoftGPU/Device.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ Device::Device(const Gfx::IntSize& min_size)
498498
m_options.scissor_box = m_render_target->rect();
499499
}
500500

501-
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)
501+
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)
502502
{
503503
// At this point, the user has effectively specified that they are done with defining the geometry
504504
// 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
517517
m_processed_triangles.clear_with_capacity();
518518

519519
// Let's construct some triangles
520-
if (primitive_type == GL_TRIANGLES) {
520+
if (primitive_type == PrimitiveType::Triangles) {
521521
Triangle triangle;
522522
for (size_t i = 0; i < vertices.size(); i += 3) {
523523
triangle.vertices[0] = vertices.at(i);
@@ -526,7 +526,7 @@ void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transf
526526

527527
m_triangle_list.append(triangle);
528528
}
529-
} else if (primitive_type == GL_QUADS) {
529+
} else if (primitive_type == PrimitiveType::Quads) {
530530
// We need to construct two triangles to form the quad
531531
Triangle triangle;
532532
VERIFY(vertices.size() % 4 == 0);
@@ -543,7 +543,7 @@ void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transf
543543
triangle.vertices[2] = vertices.at(i);
544544
m_triangle_list.append(triangle);
545545
}
546-
} else if (primitive_type == GL_TRIANGLE_FAN || primitive_type == GL_POLYGON) {
546+
} else if (primitive_type == PrimitiveType::TriangleFan) {
547547
Triangle triangle;
548548
triangle.vertices[0] = vertices.at(0); // Root vertex is always the vertex defined first
549549

@@ -553,7 +553,7 @@ void Device::draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transf
553553
triangle.vertices[2] = vertices.at(i + 1);
554554
m_triangle_list.append(triangle);
555555
}
556-
} else if (primitive_type == GL_TRIANGLE_STRIP) {
556+
} else if (primitive_type == PrimitiveType::TriangleStrip) {
557557
Triangle triangle;
558558
for (size_t i = 0; i < vertices.size() - 2; i++) {
559559
triangle.vertices[0] = vertices.at(i);

Userland/Libraries/LibSoftGPU/Device.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include <AK/Array.h>
1010
#include <AK/NonnullRefPtr.h>
1111
#include <AK/OwnPtr.h>
12-
#include <LibGL/GL/gl.h>
13-
#include <LibGL/Tex/Texture2D.h>
14-
#include <LibGL/Tex/TextureUnit.h>
1512
#include <LibGfx/Bitmap.h>
1613
#include <LibGfx/Matrix4x4.h>
1714
#include <LibGfx/Rect.h>
@@ -79,6 +76,13 @@ enum class WindingOrder {
7976
CounterClockwise,
8077
};
8178

79+
enum class PrimitiveType {
80+
Triangles,
81+
TriangleStrip,
82+
TriangleFan,
83+
Quads,
84+
};
85+
8286
struct RasterizerOptions {
8387
bool shade_smooth { true };
8488
bool enable_depth_test { false };
@@ -117,7 +121,7 @@ class Device final {
117121
public:
118122
Device(const Gfx::IntSize& min_size);
119123

120-
void draw_primitives(GLenum primitive_type, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units);
124+
void draw_primitives(PrimitiveType, FloatMatrix4x4 const& transform, FloatMatrix4x4 const& texture_matrix, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units);
121125
void resize(const Gfx::IntSize& min_size);
122126
void clear_color(const FloatVector4&);
123127
void clear_depth(float);

0 commit comments

Comments
 (0)