فهرست منبع

Add test showing that the shader_program acts as a differentiator for materials.

Sam Jaffe 6 سال پیش
والد
کامیت
471ac51317
2فایلهای تغییر یافته به همراه20 افزوده شده و 0 حذف شده
  1. 17 0
      graphics/test/manager_test.cxx
  2. 3 0
      util/include/game/util/identity.hpp

+ 17 - 0
graphics/test/manager_test.cxx

@@ -20,6 +20,7 @@ using testing::AnyNumber;
 using testing::Eq;
 using testing::Ge;
 using testing::Le;
+using testing::Ne;
 using testing::SizeIs;
 using testing::_;
 
@@ -118,3 +119,19 @@ TEST_F(MaterialTest, UniformMaterialHasDataBindingToNormalTex) {
   // Test the mapping from "u_normalMap" to uniform::NORMAL
   EXPECT_THAT(material.uniforms[0].uniform_id, Eq(uniform::NORMAL));
 }
+
+TEST_F(MaterialTest, DifferentProgramMakesDifferentMaterial) {
+  using graphics::materials::uniform;
+  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(3);
+  auto id_1 = mock.get(cast_p(1), "", "u_normalMap");
+  auto id_2 = mock.get(cast_p(2), "", "u_normalMap");
+  EXPECT_THAT(id_1, Ne(id_2));
+}
+
+TEST_F(MaterialTest, DifferentProgramDoesntChangeUniformId) {
+  using graphics::materials::uniform;
+  EXPECT_CALL(mock, compile(_, make_vector(1, 1), _)).Times(3);
+  auto mat_1 = mock.get(mock.get(cast_p(1), "", "u_normalMap"));
+  auto mat_2 = mock.get(mock.get(cast_p(2), "", "u_normalMap"));
+  EXPECT_THAT(mat_1.uniforms[0].texture, Eq(mat_2.uniforms[0].texture));
+}

+ 3 - 0
util/include/game/util/identity.hpp

@@ -21,6 +21,9 @@ private:
   friend bool operator==(identity const & lhs, identity const & rhs) {
     return lhs.id == rhs.id;
   }
+  friend bool operator!=(identity const & lhs, identity const & rhs) {
+    return lhs.id != rhs.id;
+  }
   friend bool operator!=(identity const & lhs, ID const & rhs) {
     return lhs.id != rhs;
   }