MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Bind

Method Bind

Source/Engine/Graphics/Materials/MaterialParams.cpp:287–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287void MaterialParameter::Bind(BindMeta& meta) const
288{
289 switch (_type)
290 {
291 case MaterialParameterType::Bool:
292 ASSERT_LOW_LAYER(meta.Constants.Get() && meta.Constants.Length() >= (int32)(_offset + sizeof(bool)));
293 *((int32*)(meta.Constants.Get() + _offset)) = _asBool;
294 break;
295 case MaterialParameterType::Integer:
296 ASSERT_LOW_LAYER(meta.Constants.Get() && meta.Constants.Length() >= (int32)(_offset + sizeof(int32)));
297 *((int32*)(meta.Constants.Get() + _offset)) = _asInteger;
298 break;
299 case MaterialParameterType::Float:
300 ASSERT_LOW_LAYER(meta.Constants.Get() && meta.Constants.Length() >= (int32)(_offset + sizeof(float)));
301 *((float*)(meta.Constants.Get() + _offset)) = _asFloat;
302 break;
303 case MaterialParameterType::Vector2:
304 ASSERT_LOW_LAYER(meta.Constants.Get() && meta.Constants.Length() >= (int32)(_offset + sizeof(Float2)));
305 *((Float2*)(meta.Constants.Get() + _offset)) = _asVector2;
306 break;
307 case MaterialParameterType::Vector3:
308 ASSERT_LOW_LAYER(meta.Constants.Get() && meta.Constants.Length() >= (int32)(_offset + sizeof(Float3)));
309 *((Float3*)(meta.Constants.Get() + _offset)) = _asVector3;
310 break;
311 case MaterialParameterType::Vector4:
312 ASSERT_LOW_LAYER(meta.Constants.Get() && meta.Constants.Length() >= (int32)(_offset + sizeof(Float4)));
313 *((Float4*)(meta.Constants.Get() + _offset)) = *(Float4*)&AsData;
314 break;
315 case MaterialParameterType::Color:
316 ASSERT_LOW_LAYER(meta.Constants.Get() && meta.Constants.Length() >= (int32)(_offset + sizeof(Float4)));
317 *((Color*)(meta.Constants.Get() + _offset)) = _asColor;
318 break;
319 case MaterialParameterType::Matrix:
320 ASSERT_LOW_LAYER(meta.Constants.Get() && meta.Constants.Length() >= (int32)(_offset + sizeof(Matrix)));
321 Matrix::Transpose(*(Matrix*)&AsData, *(Matrix*)(meta.Constants.Get() + _offset));
322 break;
323 case MaterialParameterType::NormalMap:
324 {
325 // If normal map texture is set but not loaded yet, use default engine normal map (reduces loading artifacts)
326 auto texture = _asAsset ? ((TextureBase*)_asAsset.Get())->GetTexture() : nullptr;
327 if (texture && texture->ResidentMipLevels() == 0)
328 texture = GPUDevice::Instance->GetDefaultNormalMap();
329 const auto view = GET_TEXTURE_VIEW_SAFE(texture);
330 meta.Context->BindSR(_registerIndex, view);
331 break;
332 }
333 case MaterialParameterType::Texture:
334 case MaterialParameterType::CubeTexture:
335 {
336 const auto texture = _asAsset ? ((TextureBase*)_asAsset.Get())->GetTexture() : nullptr;
337 const auto view = GET_TEXTURE_VIEW_SAFE(texture);
338 meta.Context->BindSR(_registerIndex, view);
339 break;
340 }
341 case MaterialParameterType::GPUTexture:
342 {
343 const auto texture = _asGPUTexture.Get();
344 const auto view = GET_TEXTURE_VIEW_SAFE(texture);

Callers 1

AddDeformerMethod · 0.45

Calls 15

EnumHasAnyFlagsFunction · 0.85
Float4Class · 0.85
MemoryClearFunction · 0.85
GetTextureMethod · 0.80
GetDefaultNormalMapMethod · 0.80
AsFloat2Method · 0.80
AsFloat3Method · 0.80
AsFloat4Method · 0.80
TransposeFunction · 0.50
InstanceClass · 0.50
GetMethod · 0.45

Tested by

no test coverage detected