Skip to content
Snippets Groups Projects
Commit a18ad02b authored by Trevor Hollmann's avatar Trevor Hollmann
Browse files

[#79] Make hasTexture() a method of Material.

parent da3d6a4d
No related branches found
No related tags found
1 merge request!69Resolve "Rework Asset Loader API"
......@@ -84,22 +84,6 @@ typedef struct {
std::vector<uint8_t> data; // binary data of the decoded texture
} Texture;
/**
* The asset loader module only supports the PBR-MetallicRoughness model for
* materials.
*/
typedef struct {
uint16_t textureMask; // bit mask with active texture targets
// Indices into the Scene.textures vector
int baseColor, metalRough, normal, occlusion, emissive;
// Scaling factors for each texture target
struct { float r, g, b, a; } baseColorFactor;
float metallicFactor, roughnessFactor;
float normalScale;
float occlusionStrength;
struct { float r, g, b; } emissiveFactor;
} Material;
/**
* Flags for the bit-mask in the Material struct. To check if a material has a
* certain texture target, you can use the hasTexture() function below, passing
......@@ -122,16 +106,31 @@ enum class PBRTextureTarget {
#define bitflag(ENUM) (0x1u << ((unsigned)(ENUM)))
/**
* To signal that a certain texture target is active in a Material struct, its
* bit is set in the textureMask. You can use this function to check that:
* Material mat = ...;
* if (materialHasTexture(&mat, baseColor)) {...}
* @param m The material to query
* @param t The target to query for
* @return Boolean to signal whether the texture target is active in the
* material.
* The asset loader module only supports the PBR-MetallicRoughness model for
* materials.
*/
bool materialHasTexture(const Material *const m, const PBRTextureTarget t);
typedef struct {
uint16_t textureMask; // bit mask with active texture targets
// Indices into the Scene.textures vector
int baseColor, metalRough, normal, occlusion, emissive;
// Scaling factors for each texture target
struct { float r, g, b, a; } baseColorFactor;
float metallicFactor, roughnessFactor;
float normalScale;
float occlusionStrength;
struct { float r, g, b; } emissiveFactor;
/**
* To signal that a certain texture target is active in this Material
* struct, its bit is set in the textureMask. You can use this function
* to check that:
* if (myMaterial.hasTexture(baseColor)) {...}
* @param t The target to query for
* @return Boolean to signal whether the texture target is active in
* the material.
*/
bool hasTexture(const PBRTextureTarget t) const;
} Material;
/* With these enums, 0 is reserved to signal uninitialized or invalid data. */
enum class PrimitiveType : uint32_t {
......
......@@ -246,10 +246,9 @@ std::array<float, 16> computeModelMatrix(std::array<float, 3> translation, std::
}
/* TODO Should probably be a member function of vkcv::asset::Material */
bool materialHasTexture(const Material *const m, const PBRTextureTarget t)
bool Material::hasTexture(const PBRTextureTarget t) const
{
return m->textureMask & bitflag(t);
return textureMask & bitflag(t);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment