MCPcopy Create free account
hub / github.com/DiligentGraphics/DiligentFX / CreateDefaultImage

Function CreateDefaultImage

Hydrogent/src/HnMaterial.cpp:306–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306static RefCntAutoPtr<Image> CreateDefaultImage(const pxr::TfToken& Name, Uint32 Dimension = 64)
307{
308 ImageDesc ImgDesc;
309 ImgDesc.Width = Dimension;
310 ImgDesc.Height = Dimension;
311 ImgDesc.ComponentType = VT_UINT8;
312 RefCntAutoPtr<IDataBlob> pData;
313
314 auto InitData = [&](Uint32 NumComponents, int Value) {
315 ImgDesc.NumComponents = NumComponents;
316 ImgDesc.RowStride = ImgDesc.Width * ImgDesc.NumComponents;
317 pData = DataBlobImpl::Create(size_t{ImgDesc.RowStride} * size_t{ImgDesc.Height});
318 if (Value >= 0)
319 {
320 memset(pData->GetDataPtr(), Value, pData->GetSize());
321 }
322 };
323
324 if (Name == HnMaterialPrivateTokens->whiteRgba8)
325 {
326 InitData(4, 255);
327 }
328 else if (Name == HnMaterialPrivateTokens->blackRgba8)
329 {
330 InitData(4, 0);
331 }
332 else if (Name == HnMaterialPrivateTokens->whiteR8)
333 {
334 InitData(1, 255);
335 }
336 else if (Name == HnTokens->normal)
337 {
338 InitData(4, -1);
339
340 Uint8* pDst = reinterpret_cast<Uint8*>(pData->GetDataPtr());
341 for (size_t i = 0; i < pData->GetSize(); i += 4)
342 {
343 pDst[i + 0] = 128;
344 pDst[i + 1] = 128;
345 pDst[i + 2] = 255;
346 pDst[i + 3] = 0;
347 }
348 }
349 else
350 {
351 UNEXPECTED("Unknown texture name '", Name, "'");
352 InitData(4, 0);
353 }
354
355 RefCntAutoPtr<Image> pImage;
356 Image::CreateFromMemory(ImgDesc, pData, &pImage);
357 VERIFY_EXPR(pImage);
358 return pImage;
359}
360
361static pxr::TfToken GetDefaultTexturePath(const pxr::TfToken& Name)
362{

Callers 1

GetDefaultTextureMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected