MCPcopy Create free account
hub / github.com/defold/defold / WebGPUSetTextureInternal

Function WebGPUSetTextureInternal

engine/graphics/src/webgpu/graphics_webgpu.cpp:448–616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446}
447
448static void WebGPUSetTextureInternal(WebGPUTexture* texture, const TextureParams& params)
449{
450 switch (params.m_Format)
451 {
452 case TEXTURE_FORMAT_DEPTH:
453 case TEXTURE_FORMAT_STENCIL:
454 dmLogError("Unable to upload texture data, unsupported type (%s).", GetTextureFormatLiteral(params.m_Format));
455 return;
456 default:
457 break;
458 }
459
460 TextureFormatCompressedBlockSize block_size;
461 const bool is_compressed = IsTextureFormatCompressed(params.m_Format);
462 if (is_compressed && !GetTextureFormatCompressedBlockSize(params.m_Format, &block_size))
463 {
464 dmLogError("Unable to upload texture data, unsupported compressed format (%s).", GetTextureFormatLiteral(params.m_Format));
465 return;
466 }
467
468#if defined(DM_GRAPHICS_WEBGPU2)
469 const uint32_t max_texture_dimension_2d = g_WebGPUContext->m_DeviceLimits.maxTextureDimension2D;
470#else
471 const uint32_t max_texture_dimension_2d = g_WebGPUContext->m_DeviceLimits.limits.maxTextureDimension2D;
472#endif
473
474 if (texture->m_Base.m_MipMapCount == 1 && params.m_MipMap > 0)
475 return;
476
477 const uint16_t texture_depth = dmMath::Max((uint16_t)1, params.m_Depth);
478 uint32_t current_storage_width;
479 uint32_t current_storage_height;
480 uint32_t new_storage_width;
481 uint32_t new_storage_height;
482 const uint32_t new_texture_width = params.m_MipMap == 0 ? params.m_Width : texture->m_Base.m_Width;
483 const uint32_t new_texture_height = params.m_MipMap == 0 ? params.m_Height : texture->m_Base.m_Height;
484
485 WebGPUGetTextureStorageDimensions(texture->m_Base.m_Format, texture->m_Base.m_Width, texture->m_Base.m_Height, &current_storage_width, &current_storage_height);
486 WebGPUGetTextureStorageDimensions(params.m_Format, new_texture_width, new_texture_height, &new_storage_width, &new_storage_height);
487
488 if (new_storage_width > max_texture_dimension_2d || new_storage_height > max_texture_dimension_2d)
489 {
490 dmLogError("Unable to upload texture data, texture size %ux%u (%ux%u block-aligned) exceeds maximum supported texture size (%ux%u).",
491 new_texture_width, new_texture_height, new_storage_width, new_storage_height, max_texture_dimension_2d, max_texture_dimension_2d);
492 return;
493 }
494
495 assert(new_storage_width <= max_texture_dimension_2d);
496 assert(new_storage_height <= max_texture_dimension_2d);
497
498 const bool texture_dimensions_changed = !params.m_SubUpdate &&
499 (texture->m_Base.m_Depth != texture_depth ||
500 (params.m_MipMap == 0 && (current_storage_width != new_storage_width || current_storage_height != new_storage_height)));
501
502 if (texture->m_Texture && (texture->m_Base.m_Format != params.m_Format || texture_dimensions_changed))
503 { //must recreate texture
504 if (params.m_SubUpdate)
505 {

Callers 2

InitializeWebGPUContextFunction · 0.85
WebGPUSetTextureFunction · 0.85

Calls 12

GetTextureFormatLiteralFunction · 0.85
WebGPURealizeTextureFunction · 0.85
RepackRGBToRGBAFunction · 0.85
ceilFunction · 0.85
MaxFunction · 0.50
assertFunction · 0.50

Tested by

no test coverage detected