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

feat: Adjust DirectXTex wrapper for all platforms #2314

Merged
merged 1 commit into from
Jun 18, 2024
Merged
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 deps/TextureWrappers/Release/linux-x64/DxtWrapper.so
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project(DxtWrapper)
cmake_minimum_required(VERSION 3.10)
file(GLOB SRCS *.cpp *.h)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../../../../../deps/TextureWrappers/Release/linux-x64)

find_package(directxtex CONFIG REQUIRED)

add_library(${PROJECT_NAME} SHARED ${SRCS} )
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")

target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::DirectXTex)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Make sure to install package required packages : vcpkg install directxtex

param (
[string]$vcpkg_dir
)

if(!$vcpkg_dir)
{
Write-Error "Please provide vpckg directory path"
return;
}

cmake -B "build" -S . -DCMAKE_TOOLCHAIN_FILE="$vcpkg_dir/scripts/buildsystems/vcpkg.cmake";
cd build;
make;
cd ..;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "dxt_wrapper.h"

// Utilities functions
void dxtComputePitch( DXGI_FORMAT fmt, int width, int height, int& rowPitch, int& slicePitch, int flags = DirectX::CP_FLAGS_NONE )
void dxtComputePitch( DXGI_FORMAT fmt, int width, int height, int& rowPitch, int& slicePitch, DirectX::CP_FLAGS flags = DirectX::CP_FLAGS_NONE )
{
size_t rowPitchT, slicePitchT;
DirectX::ComputePitch(fmt, width, height, rowPitchT, slicePitchT, flags);
Expand All @@ -13,22 +13,22 @@ void dxtComputePitch( DXGI_FORMAT fmt, int width, int height, int& rowPitch, int

bool dxtIsCompressed(DXGI_FORMAT fmt) { return DirectX::IsCompressed(fmt); }

HRESULT dxtConvert( const DirectX::Image& srcImage, DXGI_FORMAT format, int filter, float threshold, DirectX::ScratchImage& cImage )
HRESULT dxtConvert( const DirectX::Image& srcImage, DXGI_FORMAT format, DirectX::TEX_FILTER_FLAGS filter, float threshold, DirectX::ScratchImage& cImage )
{
return DirectX::Convert(srcImage, format, filter, threshold, cImage);
}

HRESULT dxtConvertArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DXGI_FORMAT format, int filter, float threshold, DirectX::ScratchImage& cImage )
HRESULT dxtConvertArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DXGI_FORMAT format, DirectX::TEX_FILTER_FLAGS filter, float threshold, DirectX::ScratchImage& cImage )
{
return DirectX::Convert(srcImages, nimages, metadata, format, filter, threshold, cImage);
}

HRESULT dxtCompress( const DirectX::Image& srcImage, DXGI_FORMAT format, int compress, float alphaRef, DirectX::ScratchImage& cImage )
HRESULT dxtCompress( const DirectX::Image& srcImage, DXGI_FORMAT format, DirectX::TEX_COMPRESS_FLAGS compress, float alphaRef, DirectX::ScratchImage& cImage )
{
return DirectX::Compress(srcImage, format, compress, alphaRef, cImage);
}

HRESULT dxtCompressArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DXGI_FORMAT format, int compress, float alphaRef, DirectX::ScratchImage& cImages )
HRESULT dxtCompressArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DXGI_FORMAT format, DirectX::TEX_COMPRESS_FLAGS compress, float alphaRef, DirectX::ScratchImage& cImages )
{
return DirectX::Compress(srcImages, nimages, metadata, format, compress, alphaRef, cImages);
}
Expand All @@ -43,44 +43,44 @@ HRESULT dxtDecompressArray( const DirectX::Image* cImages, int nimages, const Di
return DirectX::Decompress(cImages, nimages, metadata, format, images);
}

HRESULT dxtGenerateMipMaps( const DirectX::Image& baseImage, int filter, int levels, DirectX::ScratchImage& mipChain, bool allow1D = false)
HRESULT dxtGenerateMipMaps( const DirectX::Image& baseImage, DirectX::TEX_FILTER_FLAGS filter, int levels, DirectX::ScratchImage& mipChain, bool allow1D = false)
{
return DirectX::GenerateMipMaps(baseImage, filter, levels, mipChain, allow1D);
}

HRESULT dxtGenerateMipMapsArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int filter, int levels, DirectX::ScratchImage& mipChain )
HRESULT dxtGenerateMipMapsArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DirectX::TEX_FILTER_FLAGS filter, int levels, DirectX::ScratchImage& mipChain )
{
return DirectX::GenerateMipMaps(srcImages, nimages, metadata, filter, levels, mipChain);
}

HRESULT dxtGenerateMipMaps3D( const DirectX::Image* baseImages, int depth, int filter, int levels, DirectX::ScratchImage& mipChain )
HRESULT dxtGenerateMipMaps3D( const DirectX::Image* baseImages, int depth, DirectX::TEX_FILTER_FLAGS filter, int levels, DirectX::ScratchImage& mipChain )
{
return DirectX::GenerateMipMaps3D(baseImages, depth, filter, levels, mipChain);
}

HRESULT dxtGenerateMipMaps3DArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int filter, int levels, DirectX::ScratchImage& mipChain )
HRESULT dxtGenerateMipMaps3DArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DirectX::TEX_FILTER_FLAGS filter, int levels, DirectX::ScratchImage& mipChain )
{
return DirectX::GenerateMipMaps3D(srcImages, nimages, metadata, filter, levels, mipChain);
}

HRESULT dxtResize(const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int width, int height, int filter, DirectX::ScratchImage& result )
HRESULT dxtResize(const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int width, int height, DirectX::TEX_FILTER_FLAGS filter, DirectX::ScratchImage& result )
{
return DirectX::Resize(srcImages, nimages, metadata, width, height, filter, result);
}

HRESULT dxtComputeNormalMap( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int flags, float amplitude, DXGI_FORMAT format, DirectX::ScratchImage& normalMaps )
HRESULT dxtComputeNormalMap( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DirectX::CNMAP_FLAGS flags, float amplitude, DXGI_FORMAT format, DirectX::ScratchImage& normalMaps )
{
return DirectX::ComputeNormalMap(srcImages, nimages, metadata, flags, amplitude, format, normalMaps);
}

HRESULT dxtPremultiplyAlpha( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int flags, DirectX::ScratchImage& result )
HRESULT dxtPremultiplyAlpha( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DirectX::TEX_PMALPHA_FLAGS flags, DirectX::ScratchImage& result )
{
return DirectX::PremultiplyAlpha(srcImages, nimages, metadata, flags, result);
}


// I/O functions
HRESULT dxtLoadDDSFile(LPCWSTR szFile, int flags, DirectX::TexMetadata* metadata, DirectX::ScratchImage& image)
HRESULT dxtLoadDDSFile(LPCWSTR szFile, DirectX::DDS_FLAGS flags, DirectX::TexMetadata* metadata, DirectX::ScratchImage& image)
{
return DirectX::LoadFromDDSFile(szFile, flags, metadata, image);
}
Expand All @@ -90,17 +90,12 @@ HRESULT dxtLoadTGAFile(LPCWSTR szFile, DirectX::TexMetadata* metadata, DirectX::
return DirectX::LoadFromTGAFile(szFile, metadata, image);
}

HRESULT dxtLoadWICFile(LPCWSTR szFile, int flags, DirectX::TexMetadata* metadata, DirectX::ScratchImage& image)
{
return DirectX::LoadFromWICFile(szFile, flags, metadata, image);
}

HRESULT dxtSaveToDDSFile( const DirectX::Image& image, int flags, LPCWSTR szFile )
HRESULT dxtSaveToDDSFile( const DirectX::Image& image, DirectX::DDS_FLAGS flags, LPCWSTR szFile )
{
return DirectX::SaveToDDSFile(image, flags, szFile);
}

HRESULT dxtSaveToDDSFileArray( const DirectX::Image* images, int nimages, const DirectX::TexMetadata& metadata, int flags, LPCWSTR szFile )
HRESULT dxtSaveToDDSFileArray( const DirectX::Image* images, int nimages, const DirectX::TexMetadata& metadata, DirectX::DDS_FLAGS flags, LPCWSTR szFile )
{
return DirectX::SaveToDDSFile(images, nimages, metadata, flags, szFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,42 @@
#ifndef DXT_WRAPPER_H
#define DXT_WRAPPER_H

#ifdef _MSC_VER
#define DXT_API __declspec(dllexport)
#else
#if __GNUC__ >= 4
#define DXT_API __attribute__ ((visibility("default")))
#else
#define DXT_API
#endif
#endif

#include "DirectXTex.h"

extern "C" {

// Utilities functions
DXT_API void dxtComputePitch( DXGI_FORMAT fmt, int width, int height, int& rowPitch, int& slicePitch, int flags );
DXT_API void dxtComputePitch( DXGI_FORMAT fmt, int width, int height, int& rowPitch, int& slicePitch, DirectX::CP_FLAGS flags );
DXT_API bool dxtIsCompressed(DXGI_FORMAT fmt);
DXT_API HRESULT dxtConvert( const DirectX::Image& srcImage, DXGI_FORMAT format, int filter, float threshold, DirectX::ScratchImage& cImage );
DXT_API HRESULT dxtConvertArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DXGI_FORMAT format, int filter, float threshold, DirectX::ScratchImage& cImage );
DXT_API HRESULT dxtCompress( const DirectX::Image& srcImage, DXGI_FORMAT format, int compress, float alphaRef, DirectX::ScratchImage& cImage );
DXT_API HRESULT dxtCompressArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DXGI_FORMAT format, int compress, float alphaRef, DirectX::ScratchImage& cImages );
DXT_API HRESULT dxtDecompress( const DirectX::Image& cImage, DXGI_FORMAT format, DirectX::ScratchImage& image );
DXT_API HRESULT dxtConvert( const DirectX::Image& srcImage, DXGI_FORMAT format, DirectX::TEX_FILTER_FLAGS filter, float threshold, DirectX::ScratchImage& cImage );
DXT_API HRESULT dxtConvertArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DXGI_FORMAT format, DirectX::TEX_FILTER_FLAGS filter, float threshold, DirectX::ScratchImage& cImage );
DXT_API HRESULT dxtCompress( const DirectX::Image& srcImage, DXGI_FORMAT format, DirectX::TEX_COMPRESS_FLAGS compress, float alphaRef, DirectX::ScratchImage& cImage );
DXT_API HRESULT dxtCompressArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DXGI_FORMAT format, DirectX::TEX_COMPRESS_FLAGS compress, float alphaRef, DirectX::ScratchImage& cImages );
DXT_API HRESULT dxtDecompress( const DirectX::Image& cImage, DXGI_FORMAT format, DirectX::ScratchImage& image );
DXT_API HRESULT dxtDecompressArray( const DirectX::Image* cImages, int nimages, const DirectX::TexMetadata& metadata, DXGI_FORMAT format, DirectX::ScratchImage& images );
DXT_API HRESULT dxtGenerateMipMaps( const DirectX::Image& baseImage, int filter, int levels, DirectX::ScratchImage& mipChain, bool allow1D);
DXT_API HRESULT dxtGenerateMipMapsArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int filter, int levels, DirectX::ScratchImage& mipChain );
DXT_API HRESULT dxtGenerateMipMaps3D( const DirectX::Image* baseImages, int depth, int filter, int levels, DirectX::ScratchImage& mipChain );
DXT_API HRESULT dxtGenerateMipMaps3DArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int filter, int levels, DirectX::ScratchImage& mipChain );
DXT_API HRESULT dxtResize(const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int width, int height, int filter, DirectX::ScratchImage& result );
DXT_API HRESULT dxtComputeNormalMap( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int flags, float amplitude, DXGI_FORMAT format, DirectX::ScratchImage& normalMaps );
DXT_API HRESULT dxtPremultiplyAlpha( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int flags, DirectX::ScratchImage& result );
DXT_API HRESULT dxtGenerateMipMaps( const DirectX::Image& baseImage, DirectX::TEX_FILTER_FLAGS filter, int levels, DirectX::ScratchImage& mipChain, bool allow1D);
DXT_API HRESULT dxtGenerateMipMapsArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DirectX::TEX_FILTER_FLAGS filter, int levels, DirectX::ScratchImage& mipChain );
DXT_API HRESULT dxtGenerateMipMaps3D( const DirectX::Image* baseImages, int depth, DirectX::TEX_FILTER_FLAGS filter, int levels, DirectX::ScratchImage& mipChain );
DXT_API HRESULT dxtGenerateMipMaps3DArray( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DirectX::TEX_FILTER_FLAGS filter, int levels, DirectX::ScratchImage& mipChain );
DXT_API HRESULT dxtResize(const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, int width, int height, DirectX::TEX_FILTER_FLAGS filter, DirectX::ScratchImage& result );
DXT_API HRESULT dxtComputeNormalMap( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DirectX::CNMAP_FLAGS flags, float amplitude, DXGI_FORMAT format, DirectX::ScratchImage& normalMaps );
DXT_API HRESULT dxtPremultiplyAlpha( const DirectX::Image* srcImages, int nimages, const DirectX::TexMetadata& metadata, DirectX::TEX_PMALPHA_FLAGS flags, DirectX::ScratchImage& result );

// I/O functions
DXT_API HRESULT dxtLoadTGAFile(LPCWSTR szFile, DirectX::TexMetadata* metadata, DirectX::ScratchImage& image);
DXT_API HRESULT dxtLoadWICFile(LPCWSTR szFile, int wicflags, DirectX::TexMetadata* metadata, DirectX::ScratchImage& image);
DXT_API HRESULT dxtLoadDDSFile(LPCWSTR szFile, int ddsflags, DirectX::TexMetadata* metadata, DirectX::ScratchImage& image);
DXT_API HRESULT dxtSaveToDDSFile( const DirectX::Image& image, int flags, LPCWSTR szFile );
DXT_API HRESULT dxtSaveToDDSFileArray( const DirectX::Image* images, int nimages, const DirectX::TexMetadata& metadata, int flags, LPCWSTR szFile );
DXT_API HRESULT dxtLoadDDSFile(LPCWSTR szFile, DirectX::DDS_FLAGS flags, DirectX::TexMetadata* metadata, DirectX::ScratchImage& image);
DXT_API HRESULT dxtSaveToDDSFile( const DirectX::Image& image, DirectX::DDS_FLAGS flags, LPCWSTR szFile );
DXT_API HRESULT dxtSaveToDDSFileArray( const DirectX::Image* images, int nimages, const DirectX::TexMetadata& metadata, DirectX::DDS_FLAGS flags, LPCWSTR szFile );

// Scratch Image
DXT_API DirectX::ScratchImage * dxtCreateScratchImage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,10 @@ internal class Utilities
private extern static void dxtComputePitch(DXGI_FORMAT fmt, int width, int height, out int rowPitch, out int slicePitch, CP_FLAGS flags);

[DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private extern static uint dxtLoadDDSFile(String filePath, DDS_FLAGS flags, out TexMetadata metadata, IntPtr image);
private extern static uint dxtLoadDDSFile([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTC32StringMarshaller))] string filePath, DDS_FLAGS flags, out TexMetadata metadata, IntPtr image);

[DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private extern static uint dxtLoadTGAFile(String filePath, out TexMetadata metadata, IntPtr image);

[DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private extern static uint dxtLoadWICFile(String filePath, WIC_FLAGS flags, out TexMetadata metadata, IntPtr image);
private extern static uint dxtLoadTGAFile([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTC32StringMarshaller))] string filePath, out TexMetadata metadata, IntPtr image);

[DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private extern static bool dxtIsCompressed(DXGI_FORMAT fmt);
Expand All @@ -546,10 +543,10 @@ internal class Utilities
private extern static uint dxtDecompressArray(DxtImage[] cImages, int nimages, ref TexMetadata metadata, DXGI_FORMAT format, IntPtr images);

[DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private extern static uint dxtSaveToDDSFile(ref DxtImage dxtImage, DDS_FLAGS flags, string szFile);
private extern static uint dxtSaveToDDSFile(ref DxtImage dxtImage, DDS_FLAGS flags, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTC32StringMarshaller))] string szFile);

[DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private extern static uint dxtSaveToDDSFileArray(DxtImage[] dxtImages, int nimages, ref TexMetadata metadata, DDS_FLAGS flags, string szFile);
private extern static uint dxtSaveToDDSFileArray(DxtImage[] dxtImages, int nimages, ref TexMetadata metadata, DDS_FLAGS flags, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTC32StringMarshaller))] string szFile);

[DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private extern static uint dxtGenerateMipMaps(ref DxtImage baseImage, TEX_FILTER_FLAGS filter, int levels, IntPtr mipChain, bool allow1D);
Expand Down Expand Up @@ -577,21 +574,16 @@ public static void ComputePitch(DXGI_FORMAT fmt, int width, int height, out int
dxtComputePitch(fmt, width, height, out rowPitch, out slicePitch, flags);
}

public static HRESULT LoadDDSFile(String filePath, DDS_FLAGS flags, out TexMetadata metadata, ScratchImage image)
public static HRESULT LoadDDSFile(string filePath, DDS_FLAGS flags, out TexMetadata metadata, ScratchImage image)
{
return HandleHRESULT(dxtLoadDDSFile(filePath, flags, out metadata, image.ptr));
}

public static HRESULT LoadTGAFile(String filePath, out TexMetadata metadata, ScratchImage image)
public static HRESULT LoadTGAFile(string filePath, out TexMetadata metadata, ScratchImage image)
{
return HandleHRESULT(dxtLoadTGAFile(filePath, out metadata, image.ptr));
}

public static HRESULT LoadWICFile(String filePath, WIC_FLAGS flags, out TexMetadata metadata, ScratchImage image)
{
return HandleHRESULT(dxtLoadWICFile(filePath, flags, out metadata, image.ptr));
}

public static HRESULT SaveToDDSFile(ref DxtImage dxtImage, DDS_FLAGS flags, string szFile)
{
return HandleHRESULT(dxtSaveToDDSFile(ref dxtImage, flags, szFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<StrideNativeLib Include="$(MSBuildThisFileDirectory)..\..\..\deps\FreeImage\Release\**\*.dll">
<Link>runtimes\%(RecursiveDir)native\%(Filename)%(Extension)</Link>
</StrideNativeLib>
<StrideNativeLib Include="$(MSBuildThisFileDirectory)..\..\..\deps\TextureWrappers\Release\**\*.dll">
<StrideNativeLib Include="$(MSBuildThisFileDirectory)..\..\..\deps\TextureWrappers\Release\**\*.dll;$(MSBuildThisFileDirectory)..\..\..\deps\TextureWrappers\Release\**\*.so">
<Link>runtimes\%(RecursiveDir)native\%(Filename)%(Extension)</Link>
</StrideNativeLib>
<StrideNativeLib Include="$(MSBuildThisFileDirectory)..\..\..\deps\PVRTT\**\*.dll">
Expand Down
Loading