| 232 | } |
| 233 | |
| 234 | bool MaterialShader::Load(MemoryReadStream& shaderCacheStream, const MaterialInfo& info) |
| 235 | { |
| 236 | PROFILE_MEM(GraphicsMaterials); |
| 237 | ASSERT(!_isLoaded); |
| 238 | |
| 239 | // Cache material info |
| 240 | _info = info; |
| 241 | |
| 242 | // Create shader |
| 243 | if (_shader->Create(shaderCacheStream)) |
| 244 | { |
| 245 | LOG(Warning, "Cannot load shader."); |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | // Init memory for a constant buffer |
| 250 | _cb = _shader->GetCB(0); |
| 251 | if (_cb) |
| 252 | { |
| 253 | int32 cbSize = _cb->GetSize(); |
| 254 | if (cbSize == 0) |
| 255 | { |
| 256 | // Handle unused constant buffer (eg. postFx returning solid color) |
| 257 | cbSize = 1024; |
| 258 | _cb = nullptr; |
| 259 | } |
| 260 | _cbData.Resize(cbSize, false); |
| 261 | Platform::MemoryClear(_cbData.Get(), cbSize); |
| 262 | } |
| 263 | |
| 264 | // Initialize the material based on type (create pipeline states and setup) |
| 265 | if (Load()) |
| 266 | { |
| 267 | return true; |
| 268 | } |
| 269 | |
| 270 | _isLoaded = true; |
| 271 | return false; |
| 272 | } |
| 273 | |
| 274 | void MaterialShader::Unload() |
| 275 | { |