| 970 | } |
| 971 | |
| 972 | Result SetDynamicTextureData(HScene scene, const dmhash_t texture_hash, uint32_t width, uint32_t height, dmImage::Type type, dmImage::CompressionType compression_type, bool flip, const void* buffer, uint32_t buffer_size) |
| 973 | { |
| 974 | TextureInfo* t = scene->m_DynamicTextures.Get(texture_hash); |
| 975 | if (!t) |
| 976 | { |
| 977 | return RESULT_INVAL_ERROR; |
| 978 | } |
| 979 | |
| 980 | if (compression_type == dmImage::COMPRESSION_TYPE_ASTC) |
| 981 | { |
| 982 | flip = false; // Cannot flip a preencoded astc image |
| 983 | |
| 984 | uint32_t depth; |
| 985 | if (!dmImage::GetAstcDimensions(buffer, buffer_size, &width, &height, &depth)) |
| 986 | { |
| 987 | dmLogError("Invalid image data. Expected astc format"); |
| 988 | return RESULT_INVAL_ERROR; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | // Only make a copy if we need to flip the image |
| 993 | void* flipped_data = flip ? MakeDynamicTextureData(width, height, type, flip, buffer, buffer_size) : 0; |
| 994 | const void* data = flip ? flipped_data : buffer; |
| 995 | if (!data) |
| 996 | { |
| 997 | return RESULT_DATA_ERROR; |
| 998 | } |
| 999 | |
| 1000 | scene->m_SetTextureResourceCallback(scene, texture_hash, width, height, type, compression_type, data, buffer_size); |
| 1001 | free(flipped_data); |
| 1002 | |
| 1003 | float buffer_size_orig_mb = 0.0f; |
| 1004 | if (t->m_ImageType != UINT32_MAX) |
| 1005 | { |
| 1006 | buffer_size_orig_mb = t->m_OriginalWidth * t->m_OriginalHeight * dmImage::BytesPerPixel((dmImage::Type) t->m_ImageType); |
| 1007 | } |
| 1008 | |
| 1009 | t->m_OriginalWidth = width; |
| 1010 | t->m_OriginalHeight = height; |
| 1011 | t->m_ImageType = type; |
| 1012 | |
| 1013 | float buffer_size_mb = buffer_size / 1024.0 / 1024.0 - buffer_size_orig_mb; |
| 1014 | DM_PROPERTY_ADD_F32(rmtp_GuiDynamicTexturesSizeMb, - buffer_size_mb); |
| 1015 | |
| 1016 | return RESULT_OK; |
| 1017 | } |
| 1018 | |
| 1019 | static void AddResourcePath(HScene scene, void* resource, dmhash_t path_hash) |
| 1020 | { |