-------------------------------------------------------------------------- On add - verify data settings --------------------------------------------------------------------------
| 109 | // On add - verify data settings |
| 110 | //-------------------------------------------------------------------------- |
| 111 | bool CustomMaterial::onAdd() |
| 112 | { |
| 113 | if (Parent::onAdd() == false) |
| 114 | return false; |
| 115 | |
| 116 | mShaderData = dynamic_cast<ShaderData*>(Sim::findObject( mShaderDataName ) ); |
| 117 | if(mShaderDataName.isNotEmpty() && mShaderData == NULL) |
| 118 | { |
| 119 | logError("Failed to find ShaderData %s", mShaderDataName.c_str()); |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | const char* samplerDecl = "sampler"; |
| 124 | S32 samplerDeclLen = dStrlen(samplerDecl); |
| 125 | S32 i = 0; |
| 126 | for (SimFieldDictionaryIterator itr(getFieldDictionary()); *itr; ++itr) |
| 127 | { |
| 128 | SimFieldDictionary::Entry* entry = *itr; |
| 129 | if (dStrStartsWith(entry->slotName, samplerDecl)) |
| 130 | { |
| 131 | if (i >= MAX_TEX_PER_PASS) |
| 132 | { |
| 133 | logError("Too many sampler declarations, you may only have %i", MAX_TEX_PER_PASS); |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | if (dStrlen(entry->slotName) == samplerDeclLen) |
| 138 | { |
| 139 | logError("sampler declarations must have a sampler name, e.g. sampler[\"diffuseMap\"]"); |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | // Assert sampler names are defined on ShaderData |
| 144 | S32 pos = -1; |
| 145 | String samplerName = entry->slotName + samplerDeclLen; |
| 146 | samplerName.insert(0, '$'); |
| 147 | mShaderData->hasSamplerDef(samplerName, pos); |
| 148 | |
| 149 | if(pos == -1) |
| 150 | { |
| 151 | const char *error = (avar("CustomMaterial(%s) bind sampler[%s] and is not present on ShaderData(%s)", |
| 152 | getName(), samplerName.c_str(), mShaderDataName.c_str() )); |
| 153 | Con::errorf(error); |
| 154 | |
| 155 | pos = i; |
| 156 | |
| 157 | #ifdef TORQUE_OPENGL |
| 158 | GFXAssertFatal(0, error); |
| 159 | continue; |
| 160 | #endif |
| 161 | } |
| 162 | mSamplerNames[pos] = samplerName; |
| 163 | mTexFilename[pos] = entry->value; |
| 164 | ++i; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | return true; |
nothing calls this directly
no test coverage detected