소스 검색

LibGfx+LibSoftGPU: Add and use `Vector.xy()`

Also use `.xyz()` where appropriate.
Jelle Raaijmakers 3 년 전
부모
커밋
d75135663b
2개의 변경된 파일12개의 추가작업 그리고 7개의 파일을 삭제
  1. 6 1
      Userland/Libraries/LibGfx/VectorN.h
  2. 6 6
      Userland/Libraries/LibSoftGPU/Device.cpp

+ 6 - 1
Userland/Libraries/LibGfx/VectorN.h

@@ -201,7 +201,12 @@ public:
             return AK::sqrt(m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2] + m_data[3] * m_data[3]);
     }
 
-    [[nodiscard]] constexpr VectorN<3, T> xyz() const requires(N == 4)
+    [[nodiscard]] constexpr VectorN<2, T> xy() const requires(N >= 3)
+    {
+        return VectorN<2, T>(x(), y());
+    }
+
+    [[nodiscard]] constexpr VectorN<3, T> xyz() const requires(N >= 4)
     {
         return VectorN<3, T>(x(), y(), z());
     }

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

@@ -192,9 +192,9 @@ void Device::rasterize_triangle(const Triangle& triangle)
     Vertex const vertex2 = triangle.vertices[2];
 
     // Calculate area of the triangle for later tests
-    FloatVector2 const v0 { vertex0.window_coordinates.x(), vertex0.window_coordinates.y() };
-    FloatVector2 const v1 { vertex1.window_coordinates.x(), vertex1.window_coordinates.y() };
-    FloatVector2 const v2 { vertex2.window_coordinates.x(), vertex2.window_coordinates.y() };
+    FloatVector2 const v0 = vertex0.window_coordinates.xy();
+    FloatVector2 const v1 = vertex1.window_coordinates.xy();
+    FloatVector2 const v2 = vertex2.window_coordinates.xy();
 
     auto const area = edge_function(v0, v1, v2);
     auto const one_over_area = 1.0f / area;
@@ -608,7 +608,7 @@ static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const
         }
         case TexCoordGenerationMode::SphereMap: {
             auto const eye_unit = vertex.eye_coordinates.normalized();
-            FloatVector3 const eye_unit_xyz = { eye_unit.x(), eye_unit.y(), eye_unit.z() };
+            FloatVector3 const eye_unit_xyz = eye_unit.xyz();
             auto const normal = vertex.normal;
             auto reflection = eye_unit_xyz - normal * 2 * normal.dot(eye_unit_xyz);
             reflection.set_z(reflection.z() + 1);
@@ -617,7 +617,7 @@ static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const
         }
         case TexCoordGenerationMode::ReflectionMap: {
             auto const eye_unit = vertex.eye_coordinates.normalized();
-            FloatVector3 const eye_unit_xyz = { eye_unit.x(), eye_unit.y(), eye_unit.z() };
+            FloatVector3 const eye_unit_xyz = eye_unit.xyz();
             auto const normal = vertex.normal;
             auto reflection = eye_unit_xyz - normal * 2 * normal.dot(eye_unit_xyz);
             switch (config_index) {
@@ -995,7 +995,7 @@ ALWAYS_INLINE void Device::shade_fragments(PixelQuad& quad)
         // FIXME: implement GL_TEXTURE_1D, GL_TEXTURE_3D and GL_TEXTURE_CUBE_MAP
         auto const& sampler = m_samplers[i];
 
-        auto texel = sampler.sample_2d({ quad.texture_coordinates[i].x(), quad.texture_coordinates[i].y() });
+        auto texel = sampler.sample_2d(quad.texture_coordinates[i].xy());
         INCREASE_STATISTICS_COUNTER(g_num_sampler_calls, 1);
 
         // FIXME: Implement more blend modes