Browse Source

Rather exposed texture unit names as a static method on Material

Matt Benic 10 years ago
parent
commit
fa1b99cb7e
2 changed files with 11 additions and 5 deletions
  1. 9 4
      Source/Atomic/Graphics/Material.cpp
  2. 2 1
      Source/Atomic/Graphics/Material.h

+ 9 - 4
Source/Atomic/Graphics/Material.cpp

@@ -47,7 +47,7 @@ namespace Atomic
 
 extern const char* wrapModeNames[];
 
-const char* TEXTURE_UNIT_NAMES[] =
+const char* textureUnitNames[] =
 {
     "diffuse",
     "normal",
@@ -95,7 +95,7 @@ TextureUnit ParseTextureUnitName(String name)
 {
     name = name.ToLower().Trimmed();
 
-    TextureUnit unit = (TextureUnit)GetStringListIndex(name.CString(), TEXTURE_UNIT_NAMES, MAX_TEXTURE_UNITS);
+    TextureUnit unit = (TextureUnit)GetStringListIndex(name.CString(), textureUnitNames, MAX_TEXTURE_UNITS);
     if (unit == MAX_TEXTURE_UNITS)
     {
         // Check also for shorthand names
@@ -428,7 +428,7 @@ bool Material::Save(XMLElement& dest) const
         if (texture)
         {
             XMLElement textureElem = dest.CreateChild("texture");
-            textureElem.SetString("unit", TEXTURE_UNIT_NAMES[j]);
+            textureElem.SetString("unit", textureUnitNames[j]);
             textureElem.SetString("name", texture->GetName());
         }
     }
@@ -758,7 +758,7 @@ Scene* Material::GetScene() const
 
 String Material::GetTextureUnitName(TextureUnit unit)
 {
-    return TEXTURE_UNIT_NAMES[unit];
+    return textureUnitNames[unit];
 }
 
 Variant Material::ParseShaderParameterValue(const String& value)
@@ -770,6 +770,11 @@ Variant Material::ParseShaderParameterValue(const String& value)
         return ToVectorVariant(valueTrimmed);
 }
 
+const char** Material::GetTextureUnitNames()
+{
+    return textureUnitNames;
+}
+
 void Material::CheckOcclusion()
 {
     // Determine occlusion by checking the base pass of each technique

+ 2 - 1
Source/Atomic/Graphics/Material.h

@@ -41,7 +41,6 @@ class TextureCube;
 class ValueAnimationInfo;
 
 static const unsigned char DEFAULT_RENDER_ORDER = 128;
-extern const char* TEXTURE_UNIT_NAMES[];
 
 /// %Material's shader parameter definition.
 struct MaterialShaderParameter
@@ -232,6 +231,8 @@ public:
     static String GetTextureUnitName(TextureUnit unit);
     /// Parse a shader parameter value from a string. Retunrs either a bool, a float, or a 2 to 4-component vector.
     static Variant ParseShaderParameterValue(const String& value);
+    /// Return the names of supported texture units
+    static const char** GetTextureUnitNames();
 
 private:
     /// Re-evaluate occlusion rendering.