Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added gli library for dds export #351

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "external/vulkan-headers"]
path = external/vulkan-headers
url = https://github.com/KhronosGroup/Vulkan-Headers
[submodule "external/gli"]
path = external/gli
url = https://github.com/g-truc/gli.git
2 changes: 1 addition & 1 deletion Source/Falcor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ target_link_libraries(Falcor
PRIVATE
git_version
FreeImage assimp ffmpeg OpenEXR OpenVDB lz4 zlib pugixml
glfw mikktspace nvtt
gli glfw mikktspace nvtt
$<$<BOOL:${FALCOR_HAS_D3D12}>:d3d12>
$<$<BOOL:${FALCOR_HAS_D3D12_AGILITY_SDK}>:agility-sdk>
$<$<BOOL:${FALCOR_HAS_NVAPI}>:nvapi>
Expand Down
33 changes: 30 additions & 3 deletions Source/Falcor/Core/API/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
#include "Utils/Image/ImageIO.h"
#include "Utils/Scripting/ScriptBindings.h"
#include "RenderGraph/BasePasses/FullScreenPass.h"
#include "NativeFormats.h"

#include <gli/gli.hpp>
#include <pybind11/numpy.h>

#include <mutex>
Expand Down Expand Up @@ -441,16 +443,41 @@ void Texture::captureToFile(
Bitmap::ExportFlags exportFlags
)
{
RenderContext* pContext = mpDevice->getRenderContext();

if (format == Bitmap::FileFormat::DdsFile)
{
throw RuntimeError("Texture::captureToFile does not yet support saving to DDS.");
gli::dx dxc;
auto dxgiFormat = getDxgiFormat(mFormat);
auto gliFormat = dxc.find(gli::dx::D3DFMT_DX10, gli::dx::dxgiFormat{ gli::dx::dxgi_format_dds(dxgiFormat) });

if (mType != Type::Texture2D) throw RuntimeError("Texture::captureToFile dds files must be texture 2d");
gli::texture2d_array gliTex = gli::texture2d_array(
gliFormat,
gli::extent2d(mWidth, mHeight),
mArraySize, mMipLevels);

// transfer data
for (uint32_t level = 0; level < mMipLevels; ++level)
{
const auto size = gliTex.size(level);
for (uint32_t layer = 0; layer < mArraySize; ++layer)
{
auto subresourceIndex = getSubresourceIndex(layer, mipLevel);
auto srcData = pContext->readTextureSubresource(this, subresourceIndex);
auto dstData = gliTex.data(layer, 0, level);
assert(size <= srcData.size());
memcpy(dstData, srcData.data(), size);
}
}

gli::save_dds(gliTex, path.string());
return;
}

if (mType != Type::Texture2D)
throw RuntimeError("Texture::captureToFile only supported for 2D textures.");

RenderContext* pContext = mpDevice->getRenderContext();

// Handle the special case where we have an HDR texture with less then 3 channels.
FormatType type = getFormatType(mFormat);
uint32_t channels = getFormatChannelCount(mFormat);
Expand Down
5 changes: 5 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ add_subdirectory(glfw)
message(STATUS "Configure glm")
add_subdirectory(glm)

# gli
message(STATUS "Configure gli")
set(GLI_TEST_ENABLE OFF)
add_subdirectory(gli)

# imgui
add_library(imgui INTERFACE)
target_include_directories(imgui INTERFACE imgui)
Expand Down
1 change: 1 addition & 0 deletions external/gli
Submodule gli added at 779b99