|
|
@@ -35,6 +35,7 @@
|
|
|
#include "../Core/StringUtils.h"
|
|
|
#include "../Graphics/Technique.h"
|
|
|
#include "../Graphics/Texture2D.h"
|
|
|
+#include "../Graphics/Texture3D.h"
|
|
|
#include "../Graphics/TextureCube.h"
|
|
|
#include "../Scene/ValueAnimation.h"
|
|
|
#include "../Resource/XMLFile.h"
|
|
|
@@ -53,6 +54,10 @@ static const char* textureUnitNames[] =
|
|
|
"specular",
|
|
|
"emissive",
|
|
|
"environment",
|
|
|
+#ifdef DESKTOP_GRAPHICS
|
|
|
+ "volume",
|
|
|
+ "custom1",
|
|
|
+ "custom2",
|
|
|
"lightramp",
|
|
|
"lightshape",
|
|
|
"shadowmap",
|
|
|
@@ -60,9 +65,14 @@ static const char* textureUnitNames[] =
|
|
|
"indirection",
|
|
|
"depth",
|
|
|
"light",
|
|
|
- "volume",
|
|
|
"zone",
|
|
|
0
|
|
|
+#else
|
|
|
+ "lightramp",
|
|
|
+ "lightshape",
|
|
|
+ "shadowmap",
|
|
|
+ 0
|
|
|
+#endif
|
|
|
};
|
|
|
|
|
|
static const char* cullModeNames[] =
|
|
|
@@ -153,7 +163,6 @@ void ShaderParameterAnimationInfo::ApplyValue(const Variant& newValue)
|
|
|
Material::Material(Context* context) :
|
|
|
Resource(context),
|
|
|
auxViewFrameNumber_(0),
|
|
|
- numUsedTextureUnits_(0),
|
|
|
shaderParameterHash_(0),
|
|
|
occlusion_(true),
|
|
|
specular_(false),
|
|
|
@@ -202,7 +211,17 @@ bool Material::BeginLoad(Deserializer& source)
|
|
|
// Detect cube maps by file extension: they are defined by an XML file
|
|
|
/// \todo Differentiate with 3D textures by actually reading the XML content
|
|
|
if (GetExtension(name) == ".xml")
|
|
|
- cache->BackgroundLoadResource<TextureCube>(name, true, this);
|
|
|
+ {
|
|
|
+ #ifdef DESKTOP_GRAPHICS
|
|
|
+ TextureUnit unit = TU_DIFFUSE;
|
|
|
+ if (textureElem.HasAttribute("unit"))
|
|
|
+ unit = ParseTextureUnitName(textureElem.GetAttribute("unit"));
|
|
|
+ if (unit == TU_VOLUMEMAP)
|
|
|
+ cache->BackgroundLoadResource<Texture3D>(name, true, this);
|
|
|
+ else
|
|
|
+ #endif
|
|
|
+ cache->BackgroundLoadResource<TextureCube>(name, true, this);
|
|
|
+ }
|
|
|
else
|
|
|
cache->BackgroundLoadResource<Texture2D>(name, true, this);
|
|
|
textureElem = textureElem.GetNext("texture");
|
|
|
@@ -294,7 +313,14 @@ bool Material::Load(const XMLElement& source)
|
|
|
// Detect cube maps by file extension: they are defined by an XML file
|
|
|
/// \todo Differentiate with 3D textures by actually reading the XML content
|
|
|
if (GetExtension(name) == ".xml")
|
|
|
- SetTexture(unit, cache->GetResource<TextureCube>(name));
|
|
|
+ {
|
|
|
+ #ifdef DESKTOP_GRAPHICS
|
|
|
+ if (unit == TU_VOLUMEMAP)
|
|
|
+ SetTexture(unit, cache->GetResource<Texture3D>(name));
|
|
|
+ else
|
|
|
+ #endif
|
|
|
+ SetTexture(unit, cache->GetResource<TextureCube>(name));
|
|
|
+ }
|
|
|
else
|
|
|
SetTexture(unit, cache->GetResource<Texture2D>(name));
|
|
|
}
|
|
|
@@ -385,7 +411,7 @@ bool Material::Save(XMLElement& dest) const
|
|
|
if (texture)
|
|
|
{
|
|
|
XMLElement textureElem = dest.CreateChild("texture");
|
|
|
- textureElem.SetString("unit", j < MAX_NAMED_TEXTURE_UNITS ? textureUnitNames[j] : String(j).CString());
|
|
|
+ textureElem.SetString("unit", textureUnitNames[j]);
|
|
|
textureElem.SetString("name", texture->GetName());
|
|
|
}
|
|
|
}
|
|
|
@@ -526,16 +552,10 @@ void Material::SetTexture(TextureUnit unit, Texture* texture)
|
|
|
{
|
|
|
if (unit < MAX_TEXTURE_UNITS)
|
|
|
{
|
|
|
- textures_[unit] = texture;
|
|
|
-
|
|
|
- // Update the number of used texture units
|
|
|
- if (texture && (unsigned)unit >= numUsedTextureUnits_)
|
|
|
- numUsedTextureUnits_ = unit + 1;
|
|
|
- else if (!texture && unit == numUsedTextureUnits_ - 1)
|
|
|
- {
|
|
|
- while (numUsedTextureUnits_ && !textures_[numUsedTextureUnits_ - 1])
|
|
|
- --numUsedTextureUnits_;
|
|
|
- }
|
|
|
+ if (texture)
|
|
|
+ textures_[unit] = texture;
|
|
|
+ else
|
|
|
+ textures_.Erase(unit);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -626,13 +646,11 @@ SharedPtr<Material> Material::Clone(const String& cloneName) const
|
|
|
ret->SetName(cloneName);
|
|
|
ret->techniques_ = techniques_;
|
|
|
ret->shaderParameters_ = shaderParameters_;
|
|
|
- for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
|
|
|
- ret->textures_[i] = textures_[i];
|
|
|
+ ret->textures_ = textures_;
|
|
|
ret->occlusion_ = occlusion_;
|
|
|
ret->specular_ = specular_;
|
|
|
ret->cullMode_ = cullMode_;
|
|
|
ret->shadowCullMode_ = shadowCullMode_;
|
|
|
- ret->numUsedTextureUnits_ = numUsedTextureUnits_;
|
|
|
ret->RefreshMemoryUse();
|
|
|
|
|
|
return ret;
|
|
|
@@ -666,7 +684,8 @@ Pass* Material::GetPass(unsigned index, StringHash passType) const
|
|
|
|
|
|
Texture* Material::GetTexture(TextureUnit unit) const
|
|
|
{
|
|
|
- return unit < MAX_TEXTURE_UNITS ? textures_[unit] : (Texture*)0;
|
|
|
+ HashMap<TextureUnit, SharedPtr<Texture> >::ConstIterator i = textures_.Find(unit);
|
|
|
+ return i != textures_.End() ? i->second_.Get() : (Texture*)0;
|
|
|
}
|
|
|
|
|
|
const Variant& Material::GetShaderParameter(const String& name) const
|
|
|
@@ -737,8 +756,7 @@ void Material::ResetToDefaults()
|
|
|
SetNumTechniques(1);
|
|
|
SetTechnique(0, GetSubsystem<ResourceCache>()->GetResource<Technique>("Techniques/NoTexture.xml"));
|
|
|
|
|
|
- for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
|
|
|
- textures_[i] = 0;
|
|
|
+ textures_.Clear();
|
|
|
|
|
|
batchedParameterUpdate_ = true;
|
|
|
shaderParameters_.Clear();
|