Quellcode durchsuchen

LibSoftGPU: Add const to Clipper where possible

Lenny Maiorani vor 3 Jahren
Ursprung
Commit
3143c4b1df
2 geänderte Dateien mit 11 neuen und 11 gelöschten Zeilen
  1. 9 9
      Userland/Libraries/LibSoftGPU/Clipper.cpp
  2. 2 2
      Userland/Libraries/LibSoftGPU/Clipper.h

+ 9 - 9
Userland/Libraries/LibSoftGPU/Clipper.cpp

@@ -11,7 +11,7 @@
 
 
 namespace SoftGPU {
 namespace SoftGPU {
 
 
-bool Clipper::point_within_clip_plane(FloatVector4 const& vertex, ClipPlane plane)
+bool Clipper::point_within_clip_plane(FloatVector4 const& vertex, ClipPlane plane) const
 {
 {
     switch (plane) {
     switch (plane) {
     case ClipPlane::LEFT:
     case ClipPlane::LEFT:
@@ -31,16 +31,16 @@ bool Clipper::point_within_clip_plane(FloatVector4 const& vertex, ClipPlane plan
     return false;
     return false;
 }
 }
 
 
-Vertex Clipper::clip_intersection_point(Vertex const& p1, Vertex const& p2, ClipPlane plane_index)
+Vertex Clipper::clip_intersection_point(Vertex const& p1, Vertex const& p2, ClipPlane plane_index) const
 {
 {
     // See https://www.microsoft.com/en-us/research/wp-content/uploads/1978/01/p245-blinn.pdf
     // See https://www.microsoft.com/en-us/research/wp-content/uploads/1978/01/p245-blinn.pdf
     // "Clipping Using Homogeneous Coordinates" Blinn/Newell, 1978
     // "Clipping Using Homogeneous Coordinates" Blinn/Newell, 1978
 
 
-    float w1 = p1.clip_coordinates.w();
-    float w2 = p2.clip_coordinates.w();
-    float x1 = clip_plane_normals[plane_index].dot(p1.clip_coordinates);
-    float x2 = clip_plane_normals[plane_index].dot(p2.clip_coordinates);
-    float a = (w1 + x1) / ((w1 + x1) - (w2 + x2));
+    float const w1 = p1.clip_coordinates.w();
+    float const w2 = p2.clip_coordinates.w();
+    float const x1 = clip_plane_normals[plane_index].dot(p1.clip_coordinates);
+    float const x2 = clip_plane_normals[plane_index].dot(p2.clip_coordinates);
+    float const a = (w1 + x1) / ((w1 + x1) - (w2 + x2));
 
 
     Vertex out;
     Vertex out;
     out.position = mix(p1.position, p2.position, a);
     out.position = mix(p1.position, p2.position, a);
@@ -70,12 +70,12 @@ void Clipper::clip_triangle_against_frustum(Vector<Vertex>& input_verts)
 
 
             if (point_within_clip_plane(curr_vec.clip_coordinates, static_cast<ClipPlane>(plane))) {
             if (point_within_clip_plane(curr_vec.clip_coordinates, static_cast<ClipPlane>(plane))) {
                 if (!point_within_clip_plane(prev_vec.clip_coordinates, static_cast<ClipPlane>(plane))) {
                 if (!point_within_clip_plane(prev_vec.clip_coordinates, static_cast<ClipPlane>(plane))) {
-                    auto intersect = clip_intersection_point(prev_vec, curr_vec, static_cast<ClipPlane>(plane));
+                    auto const intersect = clip_intersection_point(prev_vec, curr_vec, static_cast<ClipPlane>(plane));
                     write_to->append(intersect);
                     write_to->append(intersect);
                 }
                 }
                 write_to->append(curr_vec);
                 write_to->append(curr_vec);
             } else if (point_within_clip_plane(prev_vec.clip_coordinates, static_cast<ClipPlane>(plane))) {
             } else if (point_within_clip_plane(prev_vec.clip_coordinates, static_cast<ClipPlane>(plane))) {
-                auto intersect = clip_intersection_point(prev_vec, curr_vec, static_cast<ClipPlane>(plane));
+                auto const intersect = clip_intersection_point(prev_vec, curr_vec, static_cast<ClipPlane>(plane));
                 write_to->append(intersect);
                 write_to->append(intersect);
             }
             }
         }
         }

+ 2 - 2
Userland/Libraries/LibSoftGPU/Clipper.h

@@ -49,8 +49,8 @@ public:
     void clip_triangle_against_frustum(Vector<Vertex>& input_vecs);
     void clip_triangle_against_frustum(Vector<Vertex>& input_vecs);
 
 
 private:
 private:
-    bool point_within_clip_plane(FloatVector4 const& vertex, ClipPlane plane);
-    Vertex clip_intersection_point(Vertex const& vec, Vertex const& prev_vec, ClipPlane plane_index);
+    bool point_within_clip_plane(FloatVector4 const& vertex, ClipPlane plane) const;
+    Vertex clip_intersection_point(Vertex const& vec, Vertex const& prev_vec, ClipPlane plane_index) const;
     Vector<Vertex> list_a;
     Vector<Vertex> list_a;
     Vector<Vertex> list_b;
     Vector<Vertex> list_b;
 };
 };