diff --git a/Editor/PaintToolWindow.cpp b/Editor/PaintToolWindow.cpp index 9904f8b62..7402fafed 100644 --- a/Editor/PaintToolWindow.cpp +++ b/Editor/PaintToolWindow.cpp @@ -180,7 +180,7 @@ void PaintToolWindow::Create(EditorComponent* editor) uint64_t sel = textureSlotComboBox.GetItemUserData(textureSlotComboBox.GetSelected()); std::vector texturefiledata; - if (wiHelper::saveTextureToMemoryFile(editTexture, "PNG", texturefiledata)) + if (wiHelper::saveTextureToMemoryFile(wiRenderer::GetDevice(), editTexture, "PNG", texturefiledata)) { material->textures[sel].resource->filedata = texturefiledata; } diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp index 5ebbd6bb1..f30b60cae 100644 --- a/Editor/WeatherWindow.cpp +++ b/Editor/WeatherWindow.cpp @@ -580,7 +580,7 @@ void WeatherWindow::Create(EditorComponent* editor) wiJobSystem::context ctx; for (auto& x : conv) { - if (wiHelper::saveTextureToMemory(x.second->texture, x.second->filedata)) + if (wiHelper::saveTextureToMemory(wiRenderer::GetDevice(), x.second->texture, x.second->filedata)) { wiJobSystem::Execute(ctx, [&](wiJobArgs args) { std::vector filedata_ktx2; diff --git a/Editor/main_Windows.cpp b/Editor/main_Windows.cpp index d414f052e..6907b19c5 100644 --- a/Editor/main_Windows.cpp +++ b/Editor/main_Windows.cpp @@ -210,7 +210,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { case PRINTSCREEN: { - wiHelper::screenshot(editor.swapChain); + wiHelper::screenshot(wiRenderer::GetDevice(), editor.swapChain); } break; default: diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index 36365eb17..29e5fd4a1 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -1,6 +1,5 @@ #include "wiHelper.h" #include "wiPlatform.h" -#include "wiRenderer.h" #include "wiBackLog.h" #include "wiEvent.h" @@ -70,7 +69,7 @@ namespace wiHelper #endif // _WIN32 } - void screenshot(const wiGraphics::SwapChain& swapchain, const std::string& name) + void screenshot(wiGraphics::GraphicsDevice* device, const wiGraphics::SwapChain& swapchain, const std::string& name) { std::string directory; if (name.empty()) @@ -90,7 +89,8 @@ namespace wiHelper filename = directory + "/sc_" + getCurrentDateTimeAsString() + ".jpg"; } - bool result = saveTextureToFile(wiRenderer::GetDevice()->GetBackBuffer(&swapchain), filename); + assert(device != nullptr); + bool result = saveTextureToFile(device, device->GetBackBuffer(&swapchain), filename); assert(result); if (result) @@ -100,12 +100,10 @@ namespace wiHelper } } - bool saveTextureToMemory(const wiGraphics::Texture& texture, std::vector& texturedata) + bool saveTextureToMemory(wiGraphics::GraphicsDevice* device, const wiGraphics::Texture& texture, std::vector& texturedata) { using namespace wiGraphics; - GraphicsDevice* device = wiRenderer::GetDevice(); - TextureDesc desc = texture.GetDesc(); Texture stagingTex; @@ -115,6 +113,8 @@ namespace wiHelper staging_desc.layout = RESOURCE_STATE_COPY_DST; staging_desc.bind_flags = BIND_NONE; staging_desc.misc_flags = RESOURCE_MISC_NONE; + + assert(device != nullptr); bool success = device->CreateTexture(&staging_desc, nullptr, &stagingTex); assert(success); @@ -175,12 +175,12 @@ namespace wiHelper return stagingTex.mapped_data != nullptr; } - bool saveTextureToMemoryFile(const wiGraphics::Texture& texture, const std::string& fileExtension, std::vector& filedata) + bool saveTextureToMemoryFile(wiGraphics::GraphicsDevice* device, const wiGraphics::Texture& texture, const std::string& fileExtension, std::vector& filedata) { using namespace wiGraphics; TextureDesc desc = texture.GetDesc(); std::vector texturedata; - if (saveTextureToMemory(texture, texturedata)) + if (saveTextureToMemory(device, texture, texturedata)) { return saveTextureToMemoryFile(texturedata, desc, fileExtension, filedata); } @@ -422,19 +422,19 @@ namespace wiHelper return write_result != 0; } - bool saveTextureToFile(const wiGraphics::Texture& texture, const std::string& fileName) + bool saveTextureToFile(wiGraphics::GraphicsDevice* device, const wiGraphics::Texture& texture, const std::string& fileName) { using namespace wiGraphics; TextureDesc desc = texture.GetDesc(); std::vector data; - if (saveTextureToMemory(texture, data)) + if (saveTextureToMemory(device, texture, data)) { - return saveTextureToFile(data, desc, fileName); + return saveTextureToFile(device, data, desc, fileName); } return false; } - bool saveTextureToFile(const std::vector& texturedata, const wiGraphics::TextureDesc& desc, const std::string& fileName) + bool saveTextureToFile(wiGraphics::GraphicsDevice* device, const std::vector& texturedata, const wiGraphics::TextureDesc& desc, const std::string& fileName) { using namespace wiGraphics; diff --git a/WickedEngine/wiHelper.h b/WickedEngine/wiHelper.h index 009633785..c74a2aee5 100644 --- a/WickedEngine/wiHelper.h +++ b/WickedEngine/wiHelper.h @@ -35,22 +35,22 @@ namespace wiHelper void messageBox(const std::string& msg, const std::string& caption = "Warning!"); - void screenshot(const wiGraphics::SwapChain& swapchain, const std::string& name = ""); + void screenshot(wiGraphics::GraphicsDevice* device, const wiGraphics::SwapChain& swapchain, const std::string& name = ""); // Save raw pixel data from the texture to memory - bool saveTextureToMemory(const wiGraphics::Texture& texture, std::vector& texturedata); + bool saveTextureToMemory(wiGraphics::GraphicsDevice* device, const wiGraphics::Texture& texture, std::vector& texturedata); // Save texture to memory as a file format - bool saveTextureToMemoryFile(const wiGraphics::Texture& texture, const std::string& fileExtension, std::vector& filedata); + bool saveTextureToMemoryFile(wiGraphics::GraphicsDevice* device, const wiGraphics::Texture& texture, const std::string& fileExtension, std::vector& filedata); // Save raw texture data to memory as file format bool saveTextureToMemoryFile(const std::vector& textureData, const wiGraphics::TextureDesc& desc, const std::string& fileExtension, std::vector& filedata); // Save texture to file format - bool saveTextureToFile(const wiGraphics::Texture& texture, const std::string& fileName); + bool saveTextureToFile(wiGraphics::GraphicsDevice* device, const wiGraphics::Texture& texture, const std::string& fileName); // Save raw texture data to file format - bool saveTextureToFile(const std::vector& texturedata, const wiGraphics::TextureDesc& desc, const std::string& fileName); + bool saveTextureToFile(wiGraphics::GraphicsDevice* device, const std::vector& texturedata, const wiGraphics::TextureDesc& desc, const std::string& fileName); std::string getCurrentDateTimeAsString(); diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index ce43e3ec8..3eb554560 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -1172,7 +1172,7 @@ namespace wiScene { SetLightmapRenderRequest(false); - bool success = wiHelper::saveTextureToMemory(lightmap, lightmapTextureData); + bool success = wiHelper::saveTextureToMemory(wiRenderer::GetDevice(), lightmap, lightmapTextureData); assert(success); #ifdef OPEN_IMAGE_DENOISE