| 83 | } |
| 84 | |
| 85 | bool StreamingTexture::Create(const TextureHeader& header) |
| 86 | { |
| 87 | // Validate header (further validation is performed by the Texture.Init) |
| 88 | if (header.MipLevels > GPU_MAX_TEXTURE_MIP_LEVELS |
| 89 | || Math::IsNotInRange(header.Width, 1, GPU_MAX_TEXTURE_SIZE) |
| 90 | || Math::IsNotInRange(header.Height, 1, GPU_MAX_TEXTURE_SIZE) |
| 91 | ) |
| 92 | { |
| 93 | LOG(Warning, "Invalid texture header."); |
| 94 | return true; |
| 95 | } |
| 96 | |
| 97 | ASSERT(_texture); |
| 98 | |
| 99 | ScopeLock lock(_owner->GetOwnerLocker()); |
| 100 | |
| 101 | if (IsInitialized()) |
| 102 | { |
| 103 | _texture->ReleaseGPU(); |
| 104 | } |
| 105 | |
| 106 | // Cache header |
| 107 | // Note: by caching header we assume that streaming texture has been initialized. |
| 108 | // Then we can start it's streaming so it may be allocated later (using texture.Init) |
| 109 | // But this may not happen because resources may be created and loaded but not always allocated. |
| 110 | // That's one of the main advantages of the current resources streaming system. |
| 111 | _header = header; |
| 112 | _isBlockCompressed = PixelFormatExtensions::IsCompressed(_header.Format); |
| 113 | if (_isBlockCompressed) |
| 114 | { |
| 115 | // Ensure that streaming doesn't go too low because the hardware expects the texture to be min in size of compressed texture block |
| 116 | const int32 blockSize = PixelFormatExtensions::ComputeBlockSize(_header.Format); |
| 117 | int32 lastMip = header.MipLevels - 1; |
| 118 | while ((header.Width >> lastMip) < blockSize && (header.Height >> lastMip) < blockSize && lastMip > 0) |
| 119 | lastMip--; |
| 120 | _minMipCountBlockCompressed = Math::Min(header.MipLevels - lastMip + 1, header.MipLevels); |
| 121 | } |
| 122 | |
| 123 | // Request resource streaming |
| 124 | if (GPUDevice::Instance && GPUDevice::Instance->GetRendererType() == RendererType::Null) |
| 125 | return false; |
| 126 | #if GPU_ENABLE_TEXTURES_STREAMING |
| 127 | bool isDynamic = !_header.NeverStream; |
| 128 | #else |
| 129 | bool isDynamic = false; |
| 130 | #endif |
| 131 | StartStreaming(isDynamic); |
| 132 | |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | void StreamingTexture::UnloadTexture() |
| 137 | { |
no test coverage detected