Skip to content

Commit

Permalink
always support fo4 dds archive, even on linux (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guekka committed Jun 18, 2023
1 parent 80f8e24 commit a7e00b1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 50 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endif()

include(CTest)
if("${BUILD_TESTING}")
find_package(Catch2 REQUIRED CONFIG)
find_package(Catch2 3 REQUIRED CONFIG)
include(Catch)
add_subdirectory(tests)
endif()
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"VCPKG_MANIFEST_FEATURES": {
"type": "STRING",
"value": "compression;dds;tests;xmem"
"value": "compression;tests;xmem"
},
"VCPKG_TARGET_TRIPLET": {
"type": "STRING",
Expand Down
5 changes: 1 addition & 4 deletions cmake/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ include(CMakeFindDependencyMacro)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

if(WIN32)
find_dependency(directxtex)
endif()

find_dependency(binary_io CONFIG)
find_dependency(directxtex)
find_dependency(LZ4 MODULE)
find_dependency(mmio CONFIG)
find_dependency(ZLIB MODULE)
Expand Down
12 changes: 2 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ target_include_directories(
list(APPEND CMAKE_MODULE_PATH "${ROOT_DIR}/cmake")

find_package(binary_io REQUIRED CONFIG)
find_package(directxtex REQUIRED CONFIG)
find_package(LZ4 MODULE REQUIRED)
find_package(mmio REQUIRED CONFIG)
find_package(ZLIB MODULE REQUIRED)
Expand All @@ -100,21 +101,12 @@ target_link_libraries(
PUBLIC
binary_io::binary_io
mmio::mmio
Microsoft::DirectXTex
PRIVATE
LZ4::LZ4
ZLIB::ZLIB
)

if(WIN32)
find_package(directxtex REQUIRED CONFIG)

target_link_libraries(
"${PROJECT_NAME}"
PRIVATE
Microsoft::DirectXTex
)
endif()

option(BSA_SUPPORT_XMEM "build support for the xmem codec proxy" OFF)
if("${BSA_SUPPORT_XMEM}")
target_compile_definitions(
Expand Down
23 changes: 6 additions & 17 deletions src/bsa/fo4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include <binary_io/file_stream.hpp>
#include <zlib.h>

#if BSA_OS_WINDOWS
# include <DirectXTex.h>
#endif
#include <DirectXTex.h>

namespace bsa::fo4
{
Expand All @@ -42,7 +40,6 @@ namespace bsa::fo4
}
}

#if BSA_OS_WINDOWS
namespace
{
template <std::size_t MAX_COUNT>
Expand Down Expand Up @@ -104,7 +101,6 @@ namespace bsa::fo4
return slice;
}
}
#endif

class header_t final
{
Expand Down Expand Up @@ -190,8 +186,8 @@ namespace bsa::fo4
const auto find = [&](char a_ch) noexcept {
const auto pos = a_path.find_last_of(a_ch);
return pos != std::string_view::npos ?
std::optional{ pos } :
std::nullopt;
std::optional{ pos } :
std::nullopt;
};

split_t result;
Expand All @@ -208,8 +204,8 @@ namespace bsa::fo4

const auto first = pstem ? *pstem + 1 : 0;
const auto last = pextension ?
*pextension - first :
pextension.value_or(std::string_view::npos);
*pextension - first :
pextension.value_or(std::string_view::npos);
result.stem = a_path.substr(first, last);

return result;
Expand Down Expand Up @@ -571,7 +567,6 @@ namespace bsa::fo4
[[maybe_unused]] compression_level a_level,
[[maybe_unused]] compression_type a_compression)
{
#if BSA_OS_WINDOWS
DirectX::ScratchImage scratch;
const auto in = a_in->rdbuf();
if (const auto result = DirectX::LoadFromDDSMemory(
Expand Down Expand Up @@ -631,9 +626,6 @@ namespace bsa::fo4
detail::directx_mip_chunk_maximum(meta.format, a_mipChunkWidth, a_mipChunkHeight));
std::for_each(splices.begin(), splices.end(), addChunk);
}
#else
throw bsa::exception("dds file support is only available on windows");
#endif
}

void file::read_general(
Expand All @@ -653,14 +645,14 @@ namespace bsa::fo4
void file::write_directx(
[[maybe_unused]] detail::ostream_t& a_out) const
{
#if BSA_OS_WINDOWS
const DirectX::TexMetadata meta{
.width = this->header.width,
.height = this->header.height,
.depth = 1,
.arraySize = 1,
.mipLevels = this->header.mip_count,
.miscFlags = (this->header.flags & 1u) != 0 ? std::uint32_t{ DirectX::TEX_MISC_FLAG::TEX_MISC_TEXTURECUBE } : 0u,
.miscFlags2 = 0,
.format = static_cast<::DXGI_FORMAT>(this->header.format),
.dimension = DirectX::TEX_DIMENSION_TEXTURE2D,
};
Expand Down Expand Up @@ -697,9 +689,6 @@ namespace bsa::fo4
a_out.write_bytes(chunk.as_bytes());
}
}
#else
throw bsa::exception("dds file support is only available on windows");
#endif
}

void file::write_general(detail::ostream_t& a_out) const
Expand Down
15 changes: 4 additions & 11 deletions tests/src/bsa/fo4.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
#include <string_view>
#include <utility>

#if BSA_OS_WINDOWS
# include <dxgiformat.h>
# include <d3d10.h>
#endif
#include <DirectXTex.h>

#include "catch2.hpp"
#include <binary_io/any_stream.hpp>
Expand All @@ -22,10 +19,9 @@

#include "bsa/fo4.hpp"

#if BSA_OS_WINDOWS
namespace
{
# define COMPARE(a_field) a_lhs.a_field == a_rhs.a_field
#define COMPARE(a_field) a_lhs.a_field == a_rhs.a_field

struct DDS_PIXELFORMAT
{
Expand Down Expand Up @@ -80,7 +76,7 @@ namespace
struct DDS_HEADER_DXT10
{
DXGI_FORMAT dxgiFormat;
D3D10_RESOURCE_DIMENSION resourceDimension;
UINT resourceDimension;
UINT miscFlag;
UINT arraySize;
UINT miscFlags2; // formerly reserved
Expand Down Expand Up @@ -112,9 +108,8 @@ namespace
[[nodiscard]] friend bool operator==(dds10_header_t, dds10_header_t) noexcept = default;
};

# undef COMPARE
#undef COMPARE
}
#endif

static_assert(assert_nothrowable<bsa::fo4::hashing::hash>());
static_assert(assert_nothrowable<bsa::fo4::chunk>());
Expand Down Expand Up @@ -484,7 +479,6 @@ TEST_CASE("bsa::fo4::archive", "[src][fo4][archive]")
});
}

#if BSA_OS_WINDOWS
SECTION("we can apply the correct chunking strategy for texture files")
{
const std::filesystem::path root{ "fo4_chunk_test"sv };
Expand Down Expand Up @@ -612,5 +606,4 @@ TEST_CASE("bsa::fo4::archive", "[src][fo4][archive]")
});
}
}
#endif
}
7 changes: 1 addition & 6 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "bsa",
"version-string": "1",
"dependencies": [
"directxtex",
"rsm-binary-io",
"rsm-mmio"
],
Expand All @@ -16,12 +17,6 @@
"zlib"
]
},
"dds": {
"description": "Build support for dds files in ba2 archives",
"dependencies": [
"directxtex"
]
},
"tests": {
"description": "Build tests",
"dependencies": [
Expand Down

0 comments on commit a7e00b1

Please sign in to comment.