Decouple wiHelper screenshot/saveTexture* functions from wiRenderer by providing the graphics device as a parameter.
This commit is contained in:
@@ -180,7 +180,7 @@ void PaintToolWindow::Create(EditorComponent* editor)
|
||||
uint64_t sel = textureSlotComboBox.GetItemUserData(textureSlotComboBox.GetSelected());
|
||||
|
||||
std::vector<uint8_t> texturefiledata;
|
||||
if (wiHelper::saveTextureToMemoryFile(editTexture, "PNG", texturefiledata))
|
||||
if (wiHelper::saveTextureToMemoryFile(wiRenderer::GetDevice(), editTexture, "PNG", texturefiledata))
|
||||
{
|
||||
material->textures[sel].resource->filedata = texturefiledata;
|
||||
}
|
||||
|
||||
@@ -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<uint8_t> filedata_ktx2;
|
||||
|
||||
@@ -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:
|
||||
|
||||
+12
-12
@@ -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<uint8_t>& texturedata)
|
||||
bool saveTextureToMemory(wiGraphics::GraphicsDevice* device, const wiGraphics::Texture& texture, std::vector<uint8_t>& 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<uint8_t>& filedata)
|
||||
bool saveTextureToMemoryFile(wiGraphics::GraphicsDevice* device, const wiGraphics::Texture& texture, const std::string& fileExtension, std::vector<uint8_t>& filedata)
|
||||
{
|
||||
using namespace wiGraphics;
|
||||
TextureDesc desc = texture.GetDesc();
|
||||
std::vector<uint8_t> 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<uint8_t> 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<uint8_t>& texturedata, const wiGraphics::TextureDesc& desc, const std::string& fileName)
|
||||
bool saveTextureToFile(wiGraphics::GraphicsDevice* device, const std::vector<uint8_t>& texturedata, const wiGraphics::TextureDesc& desc, const std::string& fileName)
|
||||
{
|
||||
using namespace wiGraphics;
|
||||
|
||||
|
||||
@@ -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<uint8_t>& texturedata);
|
||||
bool saveTextureToMemory(wiGraphics::GraphicsDevice* device, const wiGraphics::Texture& texture, std::vector<uint8_t>& texturedata);
|
||||
|
||||
// Save texture to memory as a file format
|
||||
bool saveTextureToMemoryFile(const wiGraphics::Texture& texture, const std::string& fileExtension, std::vector<uint8_t>& filedata);
|
||||
bool saveTextureToMemoryFile(wiGraphics::GraphicsDevice* device, const wiGraphics::Texture& texture, const std::string& fileExtension, std::vector<uint8_t>& filedata);
|
||||
|
||||
// Save raw texture data to memory as file format
|
||||
bool saveTextureToMemoryFile(const std::vector<uint8_t>& textureData, const wiGraphics::TextureDesc& desc, const std::string& fileExtension, std::vector<uint8_t>& 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<uint8_t>& texturedata, const wiGraphics::TextureDesc& desc, const std::string& fileName);
|
||||
bool saveTextureToFile(wiGraphics::GraphicsDevice* device, const std::vector<uint8_t>& texturedata, const wiGraphics::TextureDesc& desc, const std::string& fileName);
|
||||
|
||||
std::string getCurrentDateTimeAsString();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user