Skip to content

Commit

Permalink
Add test for material layer enumeration
Browse files Browse the repository at this point in the history
Enumerate material layers with getAllLayers() and confirm properties of the
returned layers using the 4-layer 'tdm_spider_black' material.
  • Loading branch information
Matthew Mott committed Feb 14, 2021
1 parent b4dc4cb commit d8f98d9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
22 changes: 7 additions & 15 deletions include/ShaderLayer.h
Expand Up @@ -21,8 +21,7 @@ enum ClampType
};

/**
* \brief
* Representation of a GL blend function.
* \brief Representation of a GL blend function.
*
* A GL blend function consists of two GLenums representing the operations that
* should be performed on the source and destination pixel colours respectively,
Expand All @@ -45,8 +44,7 @@ class BlendFunc
};

/**
* \brief
* A single layer of a material shader.
* \brief A single layer of a material shader.
*
* Each shader layer contains an image texture, a blend mode (e.g. add,
* modulate) and various other data.
Expand All @@ -55,10 +53,7 @@ class ShaderLayer
{
public:

/**
* \brief
* Enumeration of layer types.
*/
/// Enumeration of layer types.
enum Type
{
DIFFUSE,
Expand Down Expand Up @@ -98,10 +93,7 @@ class ShaderLayer
*/
virtual ~ShaderLayer() {}

/**
* \brief
* Return the layer type.
*/
/// Return the layer type.
virtual Type getType() const = 0;

/**
Expand All @@ -111,7 +103,7 @@ class ShaderLayer
virtual TexturePtr getTexture() const = 0;

/**
* Evaluate all shader expressions used in this stage. Call this once (each frame)
* Evaluate all shader expressions used in this stage. Call this once (each frame)
* before requesting things like getAlphaTest(), getColour() or isVisible()
*/
virtual void evaluateExpressions(std::size_t time) = 0;
Expand Down Expand Up @@ -249,7 +241,7 @@ class ShaderLayer
virtual std::size_t getNumFragmentMaps() = 0;

/**
* Returns the fragment map with the given index.
* Returns the fragment map with the given index.
*/
virtual TexturePtr getFragmentMap(int index) = 0;

Expand All @@ -258,7 +250,7 @@ class ShaderLayer
*/
virtual float getPrivatePolygonOffset() = 0;

// If this stage is referring to a single image file, this will return
// If this stage is referring to a single image file, this will return
// the VFS path to it with the file extension removed.
// If this layer doesn't refer to a single image file, an empty string is returned
virtual std::string getMapImageFilename() = 0;
Expand Down
33 changes: 33 additions & 0 deletions test/Materials.cpp
Expand Up @@ -48,4 +48,37 @@ TEST_F(MaterialsTest, MaterialParser)
EXPECT_TRUE(materialManager.materialExists("textures/parsing_test/variant3"));
}

TEST_F(MaterialsTest, EnumerateMaterialLayers)
{
auto material = GlobalMaterialManager().getMaterialForName("tdm_spider_black");
EXPECT_TRUE(material);

// Get a list of all layers in the material
auto layers = material->getAllLayers();
EXPECT_EQ(layers.size(), 4);

// First layer is the bump map in this particular material
EXPECT_EQ(layers.at(0)->getType(), ShaderLayer::BUMP);
EXPECT_EQ(layers.at(0)->getMapImageFilename(),
"models/md5/chars/monsters/spider/spider_local");

// Second layer is the diffuse map
EXPECT_EQ(layers.at(1)->getType(), ShaderLayer::DIFFUSE);
EXPECT_EQ(layers.at(1)->getMapImageFilename(),
"models/md5/chars/monsters/spider_black");

// Third layer is the specular map
EXPECT_EQ(layers.at(2)->getType(), ShaderLayer::SPECULAR);
EXPECT_EQ(layers.at(2)->getMapImageFilename(),
"models/md5/chars/monsters/spider_s");

// Final layer is the additive "ambient method" stage
EXPECT_EQ(layers.at(3)->getType(), ShaderLayer::BLEND);
EXPECT_EQ(layers.at(3)->getMapImageFilename(),
"models/md5/chars/monsters/spider_black");
BlendFunc bf = layers.at(3)->getBlendFunc();
EXPECT_EQ(bf.src, GL_ONE);
EXPECT_EQ(bf.dest, GL_ONE);
}

}

0 comments on commit d8f98d9

Please sign in to comment.