add colorSwizzle when blit is no supported
parent
58749f5791
commit
4d4c55f0ac
|
@ -13,6 +13,7 @@ include_directories(external/tinygltf)
|
||||||
include_directories(external/ktx/include)
|
include_directories(external/ktx/include)
|
||||||
include_directories(external/ktx/other_include)
|
include_directories(external/ktx/other_include)
|
||||||
include_directories(external/toml11)
|
include_directories(external/toml11)
|
||||||
|
include_directories(external/stb)
|
||||||
include_directories(base)
|
include_directories(base)
|
||||||
|
|
||||||
OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF)
|
OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF)
|
||||||
|
|
|
@ -119,7 +119,7 @@ public:
|
||||||
bool multiSampling = true; // 多重采样
|
bool multiSampling = true; // 多重采样
|
||||||
bool rotateModel = true; // 模型自旋转(暂时失效)
|
bool rotateModel = true; // 模型自旋转(暂时失效)
|
||||||
bool headless = false; // 无头开关
|
bool headless = false; // 无头开关
|
||||||
|
bool outputPNGimage = true; // 输出图片序列格式为PNG(四通道)
|
||||||
bool enableSaveToImageSequeue = false; // 图片序列开关(暂时弃用)
|
bool enableSaveToImageSequeue = false; // 图片序列开关(暂时弃用)
|
||||||
uint32_t outputFrameCount = 75; // 图片序列结束帧
|
uint32_t outputFrameCount = 75; // 图片序列结束帧
|
||||||
bool takeScreenShot = false; // 截屏(暂时弃用)
|
bool takeScreenShot = false; // 截屏(暂时弃用)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1756,11 +1756,6 @@ PlumageRender::PlumageRender()
|
||||||
vkMapMemory(device, dstImageMemory, 0, VK_WHOLE_SIZE, 0, (void**)&data);
|
vkMapMemory(device, dstImageMemory, 0, VK_WHOLE_SIZE, 0, (void**)&data);
|
||||||
data += subResourceLayout.offset;
|
data += subResourceLayout.offset;
|
||||||
|
|
||||||
std::ofstream file(filePath, std::ios::out | std::ios::binary);
|
|
||||||
|
|
||||||
// ppm header
|
|
||||||
file << "P6\n" << width << "\n" << height << "\n" << 255 << "\n";
|
|
||||||
|
|
||||||
// If source is BGR (destination is always RGB) and we can't use blit (which does automatic conversion), we'll have to manually swizzle color components
|
// If source is BGR (destination is always RGB) and we can't use blit (which does automatic conversion), we'll have to manually swizzle color components
|
||||||
bool colorSwizzle = false;
|
bool colorSwizzle = false;
|
||||||
// Check if source is BGR
|
// Check if source is BGR
|
||||||
|
@ -1771,27 +1766,68 @@ PlumageRender::PlumageRender()
|
||||||
colorSwizzle = (std::find(formatsBGR.begin(), formatsBGR.end(), swapChain.colorFormat) != formatsBGR.end());
|
colorSwizzle = (std::find(formatsBGR.begin(), formatsBGR.end(), swapChain.colorFormat) != formatsBGR.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ppm binary pixel data
|
if (settings.outputPNGimage)
|
||||||
for (uint32_t y = 0; y < height; y++)
|
|
||||||
{
|
{
|
||||||
unsigned int* row = (unsigned int*)data;
|
if (colorSwizzle)
|
||||||
for (uint32_t x = 0; x < width; x++)
|
|
||||||
{
|
{
|
||||||
if (colorSwizzle)
|
uint8_t* pixels = new uint8_t[width * height * 4];
|
||||||
|
uint32_t index = 0;
|
||||||
|
for (uint32_t j = height - 1; j >= 0; j--)
|
||||||
{
|
{
|
||||||
file.write((char*)row + 2, 1);
|
unsigned int* row = (unsigned int*)data;
|
||||||
file.write((char*)row + 1, 1);
|
for (int i = 0; i < width; ++i)
|
||||||
file.write((char*)row, 1);
|
{
|
||||||
|
float r = (float)i / (float)width;
|
||||||
|
float g = (float)j / (float)height;
|
||||||
|
float b = 0.2f;
|
||||||
|
int ir = int(255.99 * r);
|
||||||
|
int ig = int(255.99 * g);
|
||||||
|
int ib = int(255.99 * b);
|
||||||
|
|
||||||
|
pixels[index++] = ir;
|
||||||
|
pixels[index++] = ig;
|
||||||
|
pixels[index++] = ib;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
stbi_write_png(filePath.c_str(), width, height, 4, pixels, static_cast<int>(subResourceLayout.rowPitch));
|
||||||
{
|
|
||||||
file.write((char*)row, 3);
|
|
||||||
}
|
|
||||||
row++;
|
|
||||||
}
|
}
|
||||||
data += subResourceLayout.rowPitch;
|
else
|
||||||
|
{
|
||||||
|
stbi_write_png(filePath.c_str(), width, height, 4, data, static_cast<int>(subResourceLayout.rowPitch));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
file.close();
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
std::ofstream file(filePath, std::ios::out | std::ios::binary);
|
||||||
|
|
||||||
|
// ppm header
|
||||||
|
file << "P6\n" << width << "\n" << height << "\n" << 255 << "\n";
|
||||||
|
|
||||||
|
// ppm binary pixel data
|
||||||
|
for (uint32_t y = 0; y < height; y++)
|
||||||
|
{
|
||||||
|
unsigned int* row = (unsigned int*)data;
|
||||||
|
for (uint32_t x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
if (colorSwizzle)
|
||||||
|
{
|
||||||
|
file.write((char*)row + 2, 1);
|
||||||
|
file.write((char*)row + 1, 1);
|
||||||
|
file.write((char*)row, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file.write((char*)row, 3);
|
||||||
|
}
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
data += subResourceLayout.rowPitch;
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::cout << "Screenshot saved to " << filePath << std::endl;
|
std::cout << "Screenshot saved to " << filePath << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
#include "ui.hpp"
|
#include "ui.hpp"
|
||||||
#include <VulkanUtils.hpp>
|
#include <VulkanUtils.hpp>
|
||||||
|
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
#include "stb_image_write.h"
|
||||||
|
|
||||||
#define ENABLE_VALIDATION false
|
#define ENABLE_VALIDATION false
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue