Quantcast
Channel: DirectXTex texture processing library
Viewing all 1174 articles
Browse latest View live

New Post: SaveToDDSFile

$
0
0
Hi Folks,

I wonder whether anyone can give me a few tips on how to use this function, SaveToDDSFile. Basically, I'm trying to create a 3D texture and save it as a DDS file. I'm close to getting this working, I think...

I create the texture file and then load the bytes (each element in the volume is a set of four bytes, as indicated by the format DXGI_FORMAT_R8G8B8A8_UNORM) -- this part isn't a problem. The code I'm using to set this up is copied below. (I suspect I'm trying to make things too easy.) The type of pByteBuffer is uint8_t*.

When I step through the function SaveToDDSFile, it's clear that it wants to see an array of images and all these "slices" if i set the depth to higher than one. Right now, if I set the depth as it is below, things work out in the sense that the function seems to correctly write the DDS file, and it seems to work well in subsequent processing, but the function itself fails (SaveToDDSFile fails), which is inconvenient from a debugging point of view. It fails because the image array contains only one image.

Is this approach unworkable for a 3D texture? Any tips would be appreciated.
Image img;
img.width = NOISE_VOLUME_EDGE;/*<width of pixel data>*/
img.height = NOISE_VOLUME_EDGE;/*<height of pixel data>*/
img.format = DXGI_FORMAT_R8G8B8A8_UNORM;
img.rowPitch = 64;//1024; //64 * 4; /*<number of bytes in a scanline of the source data>*/ //16 x 4 (?)
img.slicePitch = 16384; //1024 * 16;/*<number of bytes in the entire 2D image>*/
img.pixels = pByteBuffer; /*<pointer to pixel data>*/

TexMetadata mdata;
memset( &mdata, 0, sizeof(mdata) );
mdata.width = img.width;
mdata.height = img.height;
mdata.depth = NOISE_VOLUME_EDGE;//Sort of works if this is 1
mdata.arraySize = 1;
mdata.mipLevels = 1;
mdata.format = img.format;
mdata.dimension = TEX_DIMENSION_TEXTURE3D;
HRESULT hr = SaveToDDSFile( (const Image*) &img, (size_t) 1, mdata, (DWORD) DDS_FLAGS_NONE, (LPCWSTR) sFilePath.c_str() );

New Post: SaveToDDSFile

$
0
0
Take a look at the source for ScratchImage::Initialize3DFromImages and it might make more sense to you. Also look at the helpers _DetermineImageArray, and _SetupImageArray. This is all in DirectXTexImage.cpp.

New Post: SaveToDDSFile

$
0
0
Those sound like promising helpers, many thanks! I'll have a look at it tonight.

New Post: SaveToDDSFile

$
0
0
Yes, all I really needed was to get the image array set up properly and then pass a pointer to that array as the first argument in the function SaveToDDSFile. This will be helpful to know in the future...

I'll post below the basic outline of the code I used.

I'll admit that I didn't understand how to get access to the important helper function _SetupImageArray, so I basically extracted it and reproduced it as my own helper function, but it's exactly the same (SetupImageArray).

Thanks for the help!
uint8_t* pByteBuffer; //I loaded these bytes from a separate file.
TexMetadata mdata;
memset( &mdata, 0, sizeof(mdata) );
mdata.width = NOISE_VOLUME_EDGE; //This value is 16, so iTotalBytes below is 16384
mdata.height = NOISE_VOLUME_EDGE;
mdata.depth = NOISE_VOLUME_EDGE;
mdata.arraySize = 1;
mdata.mipLevels = 1;
mdata.format = DXGI_FORMAT_R8G8B8A8_UNORM;
mdata.dimension = TEX_DIMENSION_TEXTURE3D;

int iTotalBytes = VOLUME_MAP_EDGE*VOLUME_MAP_EDGE*VOLUME_MAP_EDGE*4;

Image images[16];
SetupImageArray(pByteBuffer, iTotalBytes, mdata, DDS_FLAGS_NONE, images, VOLUME_MAP_EDGE);

tstring sFilePath = szOutputFileName;
HRESULT hr = SaveToDDSFile( (const Image*) images, (size_t) NOISE_VOLUME_EDGE, mdata, (DWORD) DDS_FLAGS_NONE, (LPCWSTR) sFilePath.c_str() );

Updated Wiki: Texconv

$
0
0
This DirectXTex sample is an implementation of the "texconv" command-line texture utility from the DirectX SDK utilizing DirectXTex rather than D3DX. This tool loads an image and prepares it for runtime use by resizing, format conversion, mip-map generation, block-compression, and writes the result in a file format suited for runtime use.

To create cubemaps, volume maps, or texture arrays from individual files, use Texassemble

Syntax

Texconv.exe uses the following command syntax:

texconv [-w number] [-h number] [-m number] [-f format] [-if filter] [-srgb | -srgbi | -srgbo] [-px  string] [-sx string] [-o directory] [-ft file-type] [-hflip] [-vflip] [-sepalpha] [-wrap | -mirror] [-pmalpha] [-fl feature-level] [-pow2] [-tu | -tf] [-dword] [-xlum] [-dx10]  [-nologo] [-singleproc] [-nogpu] [-aw number] <file-name(s)>
The file-name parameter indicates the file(s) to convert.

The optional command-line switches are described in the following table.

Optional Switches Description

  • -wnumber Width of the output texture in pixels.
  • -hnumber Height of the output texture in pixels.
  • -mnumber Number of mipmap levels to generate in the output texture. This setting only applies to DDS output.
  • -fformat Output format. Specify the DXGI format without the DXGI_FORMAT_ prefix (i.e. "-f BC1_UNORM").
  • -iffilter Image filter. Use one of the following: POINT, LINEAR, CUBIC, FANT, BOX, TRIANGLE, POINT_DITHER, LINEAR_DITHER, CUBIC_DITHER, FANT_DITHER, BOX_DITHER, TRIANGLE_DITHER, POINT_DITHER_DIFFUSION, LINEAR_DITHER_DIFFUSION, CUBIC_DITHER_DIFFUSION, FANT_DITHER_DIFFUSION, BOX_DITHER_DIFFUSION, or TRIANGLE_DITHER_DIFFUSION. Filters with DITHER in their name indicate that the 4x4 ordered dither algorithm, while "DITHER_DIFFUSION" is error diffusion dithering.
  • -srgb, -srgbi, or -srgbo Use sRGB if both the input and output data are in the sRGB color format (ie. gamma ~2.2). Use sRGBi if only the input is in sRGB; use sRGBo if only the output is in sRGB.
  • -pxstring Text string to attach to the front of the resulting texture's name.
  • -sxstring Text string to attach to the end of the resulting texture's name.
  • -odirectory Output directory.
  • -ftfile-type A file type for the output texture. Use one of the following: bmp, dds, jpg, png, or tiff. The default value is dds.
  • -hflip Perform horizonal flip of image
  • -vflip Perform horizonal flip of image
  • -sepalpha Separates alpha channel for resize/mipmap generation. This implies an alpha mode setting of DDS_ALPHA_MODE_CUSTOM as this is typically only used if the alpha channel doesn't contain transparency information.
  • -wrap, -mirror Sets the texture addressing mode for filtering to wrap or mirror, otherwise defaults to clamp.
  • -pmalpha Converts the final texture data to use premultiplied alpha. This sets an alpha mode of DDS_ALPHA_MODE_PREMULTIPLIED unless the entire alpha channel is fully opaque.
  • -pow2 Fits each texture to a power-of-2 for width & height, minimizing changes to the aspect ratio.
  • -flfeature-level Sets the target feature level which determines the maximum supported texture size. Defaults to "11.0" which is 16834, the limit for 11.0 and 11.1 Feature Level hardware.
  • -tu DDS files with TYPELESS formats are treated as UNORM
  • -tf DDS files with TYPELESS formats are treated as FLOAT
  • -dword For DDS files use a DWORD alignment instead of BYTE alignment (used for some legacy files)
  • -xlum DDS files with L8, A8L8, or L16 formats are expanded to 8:8:8:8 or 16:16:16:16
  • -dx10 Forces DDS file output to always use the "DX10" header extension, and allows the writing of alpha mode metadata information. The resulting file may not be compatible with the legacy D3DX10 or D3DX11 libraries.
  • -nologo Suppress copyright message.
  • -singleproc If the DirectXTex library and the texconv utility are built with OpenMP enabled, by default the tool will use multi-threading for CPU-based compression of BC6H and BC7 formats to spread the compression work across multiple cores. This flag disables this behavior forcing it to remain on a single core.
  • -nogpu When compressing BC6H / BC7 content, texconv will use DirectCompute on the GPU if available. Use of this flag forces texconv to always use the software codec instead.
  • -awnumber Provides an alpha weighting to use with the error metric for the BC7 GPU compressor. Defaults to 1.0.

Example

Open a Command Prompt, and change to the directory containing Texconv.exe (i.e. ...\DirectXTex\Texconv\Release)
http://windows.microsoft.com/en-us/windows/command-prompt-faq

Enter the following command-line after changing to the appropriate directory:
texconv -pow2 -f BC1_UNORM cat.jpg 

This loads a JPEG image 'cat.jpg', resizes the image to a power of 2 in each dimension (if the original was 512 x 683 it is resized to 256 x 512), mipmaps are generated, the file is converted to BC1_UNORM (aka DXT1) block compression, and written out as 'cat.dds'.

Updated Wiki: DirectXTex

$
0
0
The DirectXTex library includes a full-featured DDS reader and writer including legacy format conversions, a TGA reader and writer, a WIC-based bitmap reader and writer (BMP, JPEG, PNG, TIFF, and HD Photo), and various texture processing functions. This is intended primarily for tool usage.

The library assumes that the client code will have already called CoInitialize or CoInitializeEx as needed by the application before calling any DirectXTex routines

Headers

The majority of the header files here are intended for internal implementation of the library only (BC.h, DDS.h, DirectXTexP.h, and scoped.h). Only DirectXTex.h (and DirectXTex.inl) is meant as a 'public' header for the library.

Namespace

All the functions in the library are in the "DirectX" C++ namespace.

Functions

DDS I/O Functions

TGA I/O Functions

WIC I/O Functions

Texture Functions

Direct3D 11 Helper Functions

Utility Functions

Structures

TexMetadata contains metadata information about the texture resource and organization such as width, height, depth, format, dimension, etc.
  • TEX_DIMENSION_TEXTURE1D, TEX_DIMENSION_TEXTURE2D, and TEX_DIMENSION_TEXTURE3D are alises for D3D10_RESOURCE_DIMEMSION and D3D11_RESOURCE_DIMENSION.
  • TEX_MISC_TEXTURECUBE is an alias for the same D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG.
  • TEX_MISC2_ALPHA_MODE_MASK is a mask for miscFlags2 to obtain the TEX_ALPHA_MODE.
Image contains information about the surface including width, height, format, rowPitch, slicePitch, and a pointer to pixel data. Note that for 1D and 2D images, slicePitch should be set to the full size of the image.

ScratchImage is a helper class that manages memory for functions that return a Image or set of Images.

Blob is a helper class that manages for functions that return a binary blob of data.

Rect contains a simple pixel-based rectangle used by the CopyRectangle function.

Adding to a VS solution

In your application's solution, right-click on the Solution and use "Add \ Existing Project..." to add the appropriate .vcxproj file to your solution.
  • DirectXTex_Desktop_2013 is for Win32 desktop applications building with VS 2013 Express for Desktop, VS 2013 Professional or higher.
  • DirectXTex_Desktop_2012 is for Win32 desktop applications building with VS 2012 Express for Desktop, VS 2012 Professional or higher
  • DirectXTex_Desktop_2010 is for Win32 desktop applications building with VS 2010 using the Windows 8.1 SDK
  • DirectXTex_Windows81 is for Windows Store apps building with VS 2013 targeting Windows 8.1
  • DirectXTex_Windows8 is for Windows Store apps building with VS 2012 targeting Windows 8
  • DirectXTex_WindowsPhone81 is for Windows phone 8.1 apps building with VS 2013 Update 2 or later.
  • DirectXTex_XboxOneXDK is for Xbox One exclusive apps building with VS 2012 using the Xbox One XDK
  • DirectXTex_XboxOneADK is for Xbox One hub apps building with VS 2012 using the Xbox One ADK
In your application's project, right-click on the Project and use "References...", then "Add New Reference...", and then check the DirectXTex project name and click OK. For a Windows Store app, Windows phone, or Xbox One solution, you need to set Reference Assembly Output to false since DirectXTex is a static C++ library and not a WinRT component.

In your application's project settings, on the "C++ / General" page set Configuration to "All Configurations", set Platform to "All Platforms", and then add the relative path to DirectXTex;--assuming you have the DirectXTex folder in the same directory as your sln file, it should be $(SolutionDir$)\DirectXTex;--to the Additional Include Directories properties. Click Apply.

When using VS 2010 with the Windows 8.x SDK http://go.microsoft.com/fwlink/?LinkID=323507, or when using VS 2012 with the Windows 8.1 SDK, you'll need to apply the correct .props files to your projects as well as use the correct DirectXTex project. http://blogs.msdn.com/b/vcblog/archive/2012/11/23/using-the-windows-8-sdk-with-visual-studio-2010-configuring-multiple-projects.aspx

http://blogs.msdn.com/b/vcblog/archive/2010/05/03/flexible-project-to-project-references.aspx

Note: DirectXTex is not supported on Windows Phone 8.0, because WIC is not available on that platform. The .DDS files it generates are suitable for use on Windows Phone 8.x assuming the pixel format is supported by the device (currently Feature Level 9.3).

Release Notes

  • The alpha mode specification for DDS files was updated between the March 2013 and April 2013 releases. Any DDS files created using the DDS_FLAGS_FORCE_DX10_EXT_MISC2 flag or the texconv -dx10 switch using the March 2013 release should be refreshed.
  • Due to the underlying Windows BMP WIC codec, alpha channels are not supported for 16bpp or 32bpp BMP pixel format files. The Windows 8 version of the Windows BMP WIC codec does support 32bpp pixel formats with alpha when using the BITMAPV5HEADER file header.
  • While DXGI 1.0 and DXGI 1.1 include 5:6:5 (DXGI_FORMAT_B5G6R5_UNORM) and 5:5:5:1 (DXGI_FORMAT_B5G5R5A1_UNORM) pixel format enumerations, the DirectX 10.x and 11.0 Runtimes do not support these formats for use with Direct3D. The DirectX 11.1 runtime, DXGI 1.2, and the WDDM 1.2 driver model fully support 16bpp formats (5:6:5, 5:5:5:1, and 4:4:4:4).
  • Loading of 96bpp floating-point TIFF files results in a corrupted image prior to Windows 8. This fix is available on Windows 7 SP1 with KB 2670838 installed.

Updated Wiki: DirectXTex

$
0
0
The DirectXTex library includes a full-featured DDS reader and writer including legacy format conversions, a TGA reader and writer, a WIC-based bitmap reader and writer (BMP, JPEG, PNG, TIFF, and HD Photo), and various texture processing functions. This is intended primarily for tool usage.

The library assumes that the client code will have already called CoInitialize or CoInitializeEx as needed by the application before calling any DirectXTex routines

Headers

The majority of the header files here are intended for internal implementation of the library only (BC.h, DDS.h, DirectXTexP.h, and scoped.h). Only DirectXTex.h (and DirectXTex.inl) is meant as a 'public' header for the library.

Namespace

All the functions in the library are in the "DirectX" C++ namespace.

Functions

DDS I/O Functions

TGA I/O Functions

WIC I/O Functions

Texture Functions

Direct3D 11 Helper Functions

Utility Functions

Structures

TexMetadata contains metadata information about the texture resource and organization such as width, height, depth, format, dimension, etc.
  • TEX_DIMENSION_TEXTURE1D, TEX_DIMENSION_TEXTURE2D, and TEX_DIMENSION_TEXTURE3D are alises for D3D10_RESOURCE_DIMEMSION and D3D11_RESOURCE_DIMENSION.
  • TEX_MISC_TEXTURECUBE is an alias for the same D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG.
  • TEX_MISC2_ALPHA_MODE_MASK is a mask for miscFlags2 to obtain the TEX_ALPHA_MODE.
Image contains information about the surface including width, height, format, rowPitch, slicePitch, and a pointer to pixel data. Note that for 1D and 2D images, slicePitch should be set to the full size of the image.

ScratchImage is a helper class that manages memory for functions that return a Image or set of Images.

Blob is a helper class that manages for functions that return a binary blob of data.

Rect contains a simple pixel-based rectangle used by the CopyRectangle function.

Adding to a VS solution

In your application's solution, right-click on the Solution and use "Add \ Existing Project..." to add the appropriate .vcxproj file to your solution.
  • DirectXTex_Desktop_2013 is for Win32 desktop applications building with VS 2013 Express for Desktop, VS 2013 Community, VS 2013 Professional or higher.
  • DirectXTex_Desktop_2012 is for Win32 desktop applications building with VS 2012 Express for Desktop, VS 2012 Professional or higher
  • DirectXTex_Desktop_2010 is for Win32 desktop applications building with VS 2010 using the Windows 8.1 SDK
  • DirectXTex_Windows81 is for Windows Store apps building with VS 2013 targeting Windows 8.1
  • DirectXTex_Windows8 is for Windows Store apps building with VS 2012 targeting Windows 8
  • DirectXTex_WindowsPhone81 is for Windows phone 8.1 apps building with VS 2013 Update 2 or later.
  • DirectXTex_XboxOneXDK is for Xbox One exclusive apps building with VS 2012 using the Xbox One XDK
  • DirectXTex_XboxOneADK is for Xbox One hub apps building with VS 2012 using the Xbox One ADK
In your application's project, right-click on the Project and use "References...", then "Add New Reference...", and then check the DirectXTex project name and click OK. For a Windows Store app, Windows phone, or Xbox One solution, you need to set Reference Assembly Output to false since DirectXTex is a static C++ library and not a WinRT component.

In your application's project settings, on the "C++ / General" page set Configuration to "All Configurations", set Platform to "All Platforms", and then add the relative path to DirectXTex;--assuming you have the DirectXTex folder in the same directory as your sln file, it should be $(SolutionDir$)\DirectXTex;--to the Additional Include Directories properties. Click Apply.

When using VS 2010 with the Windows 8.x SDK http://go.microsoft.com/fwlink/?LinkID=323507, or when using VS 2012 with the Windows 8.1 SDK, you'll need to apply the correct .props files to your projects as well as use the correct DirectXTex project. http://blogs.msdn.com/b/vcblog/archive/2012/11/23/using-the-windows-8-sdk-with-visual-studio-2010-configuring-multiple-projects.aspx

http://blogs.msdn.com/b/vcblog/archive/2010/05/03/flexible-project-to-project-references.aspx

Note: DirectXTex is not supported on Windows Phone 8.0, because WIC is not available on that platform. The .DDS files it generates are suitable for use on Windows Phone 8.x assuming the pixel format is supported by the device (currently Feature Level 9.3).

Release Notes

  • The alpha mode specification for DDS files was updated between the March 2013 and April 2013 releases. Any DDS files created using the DDS_FLAGS_FORCE_DX10_EXT_MISC2 flag or the texconv -dx10 switch using the March 2013 release should be refreshed.
  • Due to the underlying Windows BMP WIC codec, alpha channels are not supported for 16bpp or 32bpp BMP pixel format files. The Windows 8 version of the Windows BMP WIC codec does support 32bpp pixel formats with alpha when using the BITMAPV5HEADER file header.
  • While DXGI 1.0 and DXGI 1.1 include 5:6:5 (DXGI_FORMAT_B5G6R5_UNORM) and 5:5:5:1 (DXGI_FORMAT_B5G5R5A1_UNORM) pixel format enumerations, the DirectX 10.x and 11.0 Runtimes do not support these formats for use with Direct3D. The DirectX 11.1 runtime, DXGI 1.2, and the WDDM 1.2 driver model fully support 16bpp formats (5:6:5, 5:5:5:1, and 4:4:4:4).
  • Loading of 96bpp floating-point TIFF files results in a corrupted image prior to Windows 8. This fix is available on Windows 7 SP1 with KB 2670838 installed.

Updated Wiki: WICTextureLoader

$
0
0
A Direct3D 11 2D texture loader that uses WIC to load a bitmap (BMP, JPEG, PNG, TIFF, GIF, HD Photo, or other WIC supported file container), resize if needed based on the current feature level (or by explicit parameter), format convert to a standard DXGI format if required, and then create a 2D texture. Furthermore, if a Direct3D 11 device context is provided and the current device supports it for the given pixel format, it will auto-generate mipmaps.

This loader does not support array textures, 1D textures, 3D volume textures, or cubemaps. For these scenarios, use the .DDS file format and DDSTextureLoader instead.

DDSTextureLoader is recommended for fully "precooked" textures for maximum performance and image quality, but this loader can be useful for creating simple 2D texture from standard image files at runtime.

Also part of DirectXTK http://go.microsoft.com/fwlink/?LinkId=248929

NOTE: WICTextureLoader is not supported on Windows Phone 8.0 because WIC is not available on that platform.

The module assumes that the client code will have already called CoInitialize, CoInitializeEx, or Windows::Foundation::Initialize as needed by the application before calling the WIC loader routines

Functions

CreateWICTextureFromMemory
Loads a WIC-supported bitmap file from a memory buffer. It creates a Direct3D 11 resource from it, and optionally a Direct3D 11 shader resource view.

HRESULT CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice,
   _In_reads_bytes_(wicDataSize) const uint8_t* wicData, _In_ size_t wicDataSize,
   _Out_opt_ ID3D11Resource** texture,
   _Out_opt_ ID3D11ShaderResourceView** textureView,
   _In_ size_t maxsize = 0 );

HRESULT CreateWICTextureFromMemory( _In_ ID3D11Device* d3dDevice,
   _In_opt_ ID3D11DeviceContext* d3dContext,
   _In_reads_bytes_(wicDataSize) const uint8_t* wicData, _In_ size_t wicDataSize,
   _Out_opt_ ID3D11Resource** texture,
   _Out_opt_ ID3D11ShaderResourceView** textureView,
   _In_ size_t maxsize = 0 );

CreateWICTextureFromFile
Loads a WIC-supported bitmap file from disk, creates a Direct3D 11 resource from it, and optionally a Direct3D 11 shader resource view.

HRESULT CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice,
   _In_z_ constwchar_t* szFileName,
   _Out_opt_ ID3D11Resource** texture,
   _Out_opt_ ID3D11ShaderResourceView** textureView,
   _In_ size_t maxsize = 0 );

HRESULT CreateWICTextureFromFile( _In_ ID3D11Device* d3dDevice,
   _In_opt_ ID3D11DeviceContext* d3dContext,
   _In_z_ constwchar_t* szFileName,
   _Out_opt_ ID3D11Resource** texture,
   _Out_opt_ ID3D11ShaderResourceView** textureView,
   _In_ size_t maxsize = 0 );

CreateWICTextureFromMemoryEx
CreateWICTextureFromFileEx
These versions provide explicit control over the created resource's usage, binding flags, CPU access flags, and miscellaneous flags for advanced / expert scenarios. The standard routines default to D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, and 0 respectively. For auto-gen mipmaps, the default binding flags are D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET and miscellaneous flags is set to D3D11_RESOURCE_MISC_GENERATE_MIPS. There is also a 'forceSRGB' option for working around gamma issues with content that is in the sRGB or similar color space but is not encoded explicitly as an SRGB format.

HRESULT CreateWICTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
   _In_reads_bytes_(wicDataSize) const uint8_t* wicData, _In_ size_t wicDataSize,
   _In_ size_t maxsize,
   _In_ D3D11_USAGE usage, _In_ unsignedint bindFlags,
   _In_ unsignedint cpuAccessFlags, _In_ unsignedint miscFlags,
   _In_ bool forceSRGB,
   _Out_opt_ ID3D11Resource** texture,
   _Out_opt_ ID3D11ShaderResourceView** textureView );

HRESULT CreateWICTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice,
   _In_opt_ ID3D11DeviceContext* d3dContext,
   _In_reads_bytes_(wicDataSize) const uint8_t* wicData, _In_ size_t wicDataSize,
   _In_ size_t maxsize,
   _In_ D3D11_USAGE usage, _In_ unsignedint bindFlags,
   _In_ unsignedint cpuAccessFlags, _In_ unsignedint miscFlags,
   _In_ bool forceSRGB,
   _Out_opt_ ID3D11Resource** texture,
   _Out_opt_ ID3D11ShaderResourceView** textureView );

HRESULT CreateWICTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
   _In_z_ constwchar_t* szFileName,
   _In_ size_t maxsize,
   _In_ D3D11_USAGE usage, _In_ unsignedint bindFlags,
   _In_ unsignedint cpuAccessFlags, _In_ unsignedint miscFlags,
   _In_ bool forceSRGB,
   _Out_opt_ ID3D11Resource** texture,
   _Out_opt_ ID3D11ShaderResourceView** textureView );

HRESULT CreateWICTextureFromFileEx( _In_ ID3D11Device* d3dDevice,
   _In_opt_ ID3D11DeviceContext* d3dContext,
   _In_z_ constwchar_t* szFileName,
   _In_ size_t maxsize,
   _In_ D3D11_USAGE usage, _In_ unsignedint bindFlags,
   _In_ unsignedint cpuAccessFlags, _In_ unsignedint miscFlags,
   _In_ bool forceSRGB,
   _Out_opt_ ID3D11Resource** texture,
   _Out_opt_ ID3D11ShaderResourceView** textureView );

Parameters

For all these functions above, the maxsize parameter provides an upper limit on the size of the resulting texture. If given a 0, the functions assume a maximum size determined from the device's current feature level. If the bitmap file contains a larger image, it will be resized using WIC at load-time to provide scaling.

If a d3dContext is given to these functions, they will attempt to use the auto-generation of mipmaps features in the Direct3D 11 API if supported for the pixel format. Note the quality of auto-gen mipmaps is up to the driver, so can vary widely. Also if a context is passed, the function is not thread safe.

Example

This example creates a shader resource view on the ID3D11Device d3dDevice which can be used for rendering. It also makes use of the immediate ID3D11DeviceContext immContext to auto-gen mipmaps if supported.

ID3D11ShaderResourceView* pSRV = nullptr;
HRESULT hr = CreateWICTextureFromFile( d3dDevice, immContext, L"LOGO.BMP",
    nullptr, &pSRV );
if (FAILED(hr))
   // error

Release Notes

  • On a system with the DirectX 11.0 Runtime or lacking WDDM 1.2 drivers, 16bpp pixel formats will be converted to a RGBA 32-bit format.
  • WICTextureLoader cannot load .TGA files unless the system has a 3rd party WIC codec installed. You must use the DirectXTex library for TGA file format support without relying on an add-on WIC codec.
  • While there is no explicit 'sRGB' pixel format defined for WIC, the load function will check for known metadata tags and may return DXGI_FORMAT_*_SRGB formats if there are equivalents of the same size and channel configuration available.

Implementation Details

  • The conversion tables are designed so that they prefer to convert to RGB if a conversion is required as a general preferance for DXGI 1.0 supporting formats supported by WDDM 1.0 drivers. The majority of Direct3D 11 devices actually support BGR DXGI 1.1 formats so we use them when they are the best match. For example, GUID_WICPixelFormat32bppBGRA loads directly as DXGI_FORMAT_B8G8R8A8_UNORM, but GUID_WICPixelFormat32bppPBGRA converts to DXGI_FORMAT_R8G8B8A8_UNORM.
  • GUID_WICPixelFormatBlackWhite is always converted to a greyscale DXGI_FORMAT_R8_UNORM since DXGI_FORMAT_R1_UNORM is not supported by Direct3D 10.x/11.x.
  • GUID_WICPixelFormat32bppRGBE is an 8:8:8:8 format, which does not match DXGI_FORMAT_R9G9B9E5_SHAREDEXP. This WIC pixel format is therefore converted to GUID_WICPixelFormat128bppRGBAFloat and returns as DXGI_FORMAT_R32G32B32A32_FLOAT.

WIC2

WIC2 is available on Windows 8 and on Windows 7 Service Pack 1 with KB 2670838 installed.
  • If WIC2 is supported, then it will load the new WIC pixel format GUID_WICPixelFormat96bppRGBFloat directly as DXGI_FORMAT_R32G32B32_FLOAT. Otherwise the module converts this to DXGI_FORMAT_R32G32B32A32_FLOAT.
  • If WIC2 is supported, then it will include conversions cases for the new WIC pixel formats GUID_WICPixelFormat32bppRGB, GUID_WICPixelFormat64bppRGB, and GUID_WICPixelFormat64bppPRGBAHalf.
  • If WIC2 is supported, then it will convert the WIC pixel format GUID_WICPixelFormat96bppRGBFixedPoint to DXGI_FORMAT_R32G32B32_FLOAT. There is special-case handling so that if auto-gen mips fails for this format (this is optional support for Feature Level 10.0 or later devices), it will use DXGI_FORMAT_R32G32B32A32_FLOAT instead (which has required support for Feature Level 10.0 or later devices).
http://support.microsoft.com/kb/2670838

Windows Store apps

The texture loader function is typically used to load texture files from the application's install folder as they were included with the AppX package. If you wish to create a texture from a file that is specified by the user from a WinRT picker, you will need to copy the file locally to a temporary location before you can use WICTextureLoader on it. This is because you either won't have file access rights to the user's file location, or the StorageFile is actually not a local file system path (i.e. it's a URL).

#include <ppltasks.h>
usingnamespace concurrency;

using Windows::Storage;
using Windows::Storage::Pickers;

create_task(openPicker->PickSingleFileAsync()).then([this](StorageFile^ file)
{
    if (file)
    {
        auto tempFolder = Windows::Storage::ApplicationData::Current->TemporaryFolder;
        create_task(file->CopyAsync( tempFolder, file->Name, NameCollisionOption::GenerateUniqueName )).then([this](StorageFile^ tempFile)
        {
            if ( tempFile )
            {
                HRESULT hr = CreateWICTextureFromFile( ..., tempFile->Path->Data(), ... );
                DX::ThrowIfFailed(hr);
            }
        });
    });

http://msdn.microsoft.com/en-us/library/windows/apps/hh758319.aspx

Updated Wiki: ScreenGrab

$
0
0
A Direct3D 11 2D texture save routine for generating a "screenshot" from a render target texture. There is a function that will dump the 2D texture to a .DDS file, and another that will write using WIC (BMP, JPEG, PNG, TIFF, GIF, JPEG-XR / HD Photo, or other WIC supported file container).

These writers do not support array textures, 1D textures, 3D volume textures, or cubemaps. Mipmaps are also ignored. For those scenarios, use the full DirectXTex library functionality (CaptureTexture). The ScreenGrab module is really designed to make a quick and light-weight solution for capturing screenshots at runtime.

MSAA textures are resolved before being written.

Also part of DirectXTK http://go.microsoft.com/fwlink/?LinkId=248929

The module assumes that the client code will have already called CoInitialize, CoInitializeEx, or Windows::Foundation::Initialize as needed by the application before calling the WIC save routines

Functions

SaveDDSTextureToFile
Saves a texture to a DDS file on disk. It performs no format conversions, but will try to favor writing legacy .DDS files when possible for improved tool support.

HRESULT SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext,
    _In_ ID3D11Resource* pSource,
    _In_z_ LPCWSTR fileName );

SaveWICTextureToFile
Saves a texture to a WIC-supported bitmap file on disk. The caller provides the desired WIC container format via guidContainerFormat and can optionally specify a desired WIC pixel format via targetFormat (which will result in E_FAIL if the requested pixel format is not supported by the WIC codec). If no WIC pixel format GUID is provided as the targetFormat parameter, it will default to a non-alpha format since 'screenshots' usually ignore the alpha channel in render targets.

HRESULT SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext,
    _In_ ID3D11Resource* pSource,
    _In_ REFGUID guidContainerFormat, 
    _In_z_ LPCWSTR fileName,
    _In_opt_ const GUID* targetFormat = nullptr,
    _In_opt_ std::function<void(IPropertyBag2*)> setCustomProps = nullptr );

NOTE: SaveWICTextureToFile is not supported on Windows Phone 8.0, because WIC is not available on that platform.

Examples

This example saves a JPEG screenshot given a ID3D11DeviceContext immContext and IDXGISwapChain swapChain.

ID3D11Texture2D* backBuffer = nullptr;
HRESULT hr = swapChain->GetBuffer( 0, __uuidof( *backBuffer ), ( LPVOID* )&backBuffer );
if ( SUCCEEDED(hr) )
{
    hr = SaveWICTextureToFile( immContext, backBuffer,
                GUID_ContainerFormatJpeg, L"SCREENSHOT.JPG" );
    backBuffer->Release();
}
if ( FAILED(hr) )
    // error

Here is an example of explicitly writing a screenshot as a 16-bit (5:6:5) BMP.

ID3D11Texture2D* backBuffer = nullptr;
HRESULT hr = swapChain->GetBuffer( 0, __uuidof( *backBuffer ), ( LPVOID* )&backBuffer );
if ( SUCCEEDED(hr) )
{
    hr = SaveWICTextureToFile( immContext, backBuffer,
                GUID_ContainerFormatBmp, L"SCREENSHOT.BMP",
                &GUID_WICPixelFormat16bppBGR565 );
    backBuffer->Release();
}
if ( FAILED(hr) )
    // error

When writing WIC files, you can also provide a callback for setting specific encoding options.

ID3D11Texture2D* backBuffer = nullptr;
HRESULT hr = swapChain->GetBuffer( 0, __uuidof( *backBuffer ), ( LPVOID* )&backBuffer );
if ( SUCCEEDED(hr) )
{
    hr = SaveWICTextureToFile( immContext, backBuffer,
                GUID_ContainerFormatTiff, L"SCREENSHOT.TIF", nullptr,
                [&](IPropertyBag2* props)
                {
                    PROPBAG2 options[2] = { 0, 0 };
                    options[0].pstrName = L"CompressionQuality";
                    options[1].pstrName = L"TiffCompressionMethod";

                    VARIANT varValues[2];
                    varValues[0].vt = VT_R4;
                    varValues[0].fltVal = 0.75f;

                    varValues[1].vt = VT_UI1;
                    varValues[1].bVal = WICTiffCompressionNone;

                    (void)props->Write( 2, options, varValues ); 
                });
    backBuffer->Release();
}
if ( FAILED(hr) )
    // error

Release Notes

  • If built with #define DXGI_1_2_FORMATS the DDS writer supports BGRA 4:4:4:4 files.
  • JPEG-XR / HD Photo supports nearly all WIC pixel formats including floating-point for both encoding and decoding.
  • TIFF can contain floating-point (128bpp or 96bpp) data, but the WIC built-in codec can only decode such images. It always converts floating-point data to unorm when encoding.
  • Paletted WIC formats are not supported for writing by the SaveWICTextureToFile function.

WIC2

WIC2 is available on Windows 8 and on Windows 7 Service Pack 1 with KB 2670838 installed.
  • If WIC2 is supported, then this function can make use of the new WIC pixel format GUID_WICPixelFormat96bppRGBFloat.
http://support.microsoft.com/kb/2670838

Windows Store apps

For Save*TextureToFile to succeed, the application must have write access to the destination path. For Windows Store apps, the file access permissions are rather restricted so you'll need to make sure you use a fully qualified path to a valid write folder. A good location to use is the app data folder:

auto folder = Windows::Storage::ApplicationData::Current->LocalFolder;
// use folder->Path->Data() as the path base

If you are going to immediately copy it to another location via StorageFolder::MoveAndReplaceAsync, then use the app's temporary folder:

#include <ppltasks.h>
usingnamespace concurrency;

using Windows::Storage;
using Windows::Storage::Pickers;

auto folder = Windows::Storage::ApplicationData::Current->TemporaryFolder;

WCHAR fname[ _MAX_PATH ];
wcscpy_s( fname, folder->Path->Data() );
wcscat_s( fname, L"\\screenshot.jpg" );

// note that context use is not thread-safe
HRESULT hr = SaveWICTextureToFile( immContext.Get(), backBuffer.Get(),
    GUID_ContainerFormatJpeg, fname  );

DX::ThrowIfFailed(hr);

create_task(savePicker->PickSaveFileAsync()).then([](StorageFile^ file)
{
    if ( file )
    {
        auto folder = Windows::Storage::ApplicationData::Current->TemporaryFolder;
        auto task = create_task( folder->GetFileAsync("screenshot.jpg") );
        task.then([file](StorageFile^ tempFile) ->IAsyncAction^
        {
            return tempFile->MoveAndReplaceAsync( file );
        });
    }
});

http://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.storage.applicationdata.temporaryfolder.aspx

Updated Wiki: DirectXTex

$
0
0
The DirectXTex library includes a full-featured DDS reader and writer including legacy format conversions, a TGA reader and writer, a WIC-based bitmap reader and writer (BMP, JPEG, PNG, TIFF, and HD Photo), and various texture processing functions. This is intended primarily for tool usage.

The library assumes that the client code will have already called CoInitialize, CoInitializeEx, or Windows::Foundation::Initialize as needed by the application before calling any DirectXTex routines

Headers

The majority of the header files here are intended for internal implementation of the library only (BC.h, DDS.h, DirectXTexP.h, and scoped.h). Only DirectXTex.h (and DirectXTex.inl) is meant as a 'public' header for the library.

Namespace

All the functions in the library are in the "DirectX" C++ namespace.

Functions

DDS I/O Functions

TGA I/O Functions

WIC I/O Functions

Texture Functions

Direct3D 11 Helper Functions

Utility Functions

Structures

TexMetadata contains metadata information about the texture resource and organization such as width, height, depth, format, dimension, etc.
  • TEX_DIMENSION_TEXTURE1D, TEX_DIMENSION_TEXTURE2D, and TEX_DIMENSION_TEXTURE3D are alises for D3D10_RESOURCE_DIMEMSION and D3D11_RESOURCE_DIMENSION.
  • TEX_MISC_TEXTURECUBE is an alias for the same D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG.
  • TEX_MISC2_ALPHA_MODE_MASK is a mask for miscFlags2 to obtain the TEX_ALPHA_MODE.
Image contains information about the surface including width, height, format, rowPitch, slicePitch, and a pointer to pixel data. Note that for 1D and 2D images, slicePitch should be set to the full size of the image.

ScratchImage is a helper class that manages memory for functions that return a Image or set of Images.

Blob is a helper class that manages for functions that return a binary blob of data.

Rect contains a simple pixel-based rectangle used by the CopyRectangle function.

Adding to a VS solution

In your application's solution, right-click on the Solution and use "Add \ Existing Project..." to add the appropriate .vcxproj file to your solution.
  • DirectXTex_Desktop_2013 is for Win32 desktop applications building with VS 2013 Express for Desktop, VS 2013 Community, VS 2013 Professional or higher.
  • DirectXTex_Desktop_2012 is for Win32 desktop applications building with VS 2012 Express for Desktop, VS 2012 Professional or higher
  • DirectXTex_Desktop_2010 is for Win32 desktop applications building with VS 2010 using the Windows 8.1 SDK
  • DirectXTex_Windows81 is for Windows Store apps building with VS 2013 targeting Windows 8.1
  • DirectXTex_Windows8 is for Windows Store apps building with VS 2012 targeting Windows 8
  • DirectXTex_WindowsPhone81 is for Windows phone 8.1 apps building with VS 2013 Update 2 or later.
  • DirectXTex_XboxOneXDK is for Xbox One exclusive apps building with VS 2012 using the Xbox One XDK
  • DirectXTex_XboxOneADK is for Xbox One hub apps building with VS 2012 using the Xbox One ADK
In your application's project, right-click on the Project and use "References...", then "Add New Reference...", and then check the DirectXTex project name and click OK. For a Windows Store app, Windows phone, or Xbox One solution, you need to set Reference Assembly Output to false since DirectXTex is a static C++ library and not a WinRT component.

In your application's project settings, on the "C++ / General" page set Configuration to "All Configurations", set Platform to "All Platforms", and then add the relative path to DirectXTex;--assuming you have the DirectXTex folder in the same directory as your sln file, it should be $(SolutionDir$)\DirectXTex;--to the Additional Include Directories properties. Click Apply.

When using VS 2010 with the Windows 8.x SDK http://go.microsoft.com/fwlink/?LinkID=323507, or when using VS 2012 with the Windows 8.1 SDK, you'll need to apply the correct .props files to your projects as well as use the correct DirectXTex project. http://blogs.msdn.com/b/vcblog/archive/2012/11/23/using-the-windows-8-sdk-with-visual-studio-2010-configuring-multiple-projects.aspx

http://blogs.msdn.com/b/vcblog/archive/2010/05/03/flexible-project-to-project-references.aspx

Note: DirectXTex is not supported on Windows Phone 8.0, because WIC is not available on that platform. The .DDS files it generates are suitable for use on Windows Phone 8.x assuming the pixel format is supported by the device (currently Feature Level 9.3).

Release Notes

  • The alpha mode specification for DDS files was updated between the March 2013 and April 2013 releases. Any DDS files created using the DDS_FLAGS_FORCE_DX10_EXT_MISC2 flag or the texconv -dx10 switch using the March 2013 release should be refreshed.
  • Due to the underlying Windows BMP WIC codec, alpha channels are not supported for 16bpp or 32bpp BMP pixel format files. The Windows 8 version of the Windows BMP WIC codec does support 32bpp pixel formats with alpha when using the BITMAPV5HEADER file header.
  • While DXGI 1.0 and DXGI 1.1 include 5:6:5 (DXGI_FORMAT_B5G6R5_UNORM) and 5:5:5:1 (DXGI_FORMAT_B5G5R5A1_UNORM) pixel format enumerations, the DirectX 10.x and 11.0 Runtimes do not support these formats for use with Direct3D. The DirectX 11.1 runtime, DXGI 1.2, and the WDDM 1.2 driver model fully support 16bpp formats (5:6:5, 5:5:5:1, and 4:4:4:4).
  • Loading of 96bpp floating-point TIFF files results in a corrupted image prior to Windows 8. This fix is available on Windows 7 SP1 with KB 2670838 installed.

Source code checked in, #39446

$
0
0
Updated libraries for VS 2015 C99 and legacy printf conformance - Static libraries built with _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS

Source code checked in, #39518

New Post: Proposed change of license

$
0
0
To date, DirectXTex has been released on CodePlex under the MS-PL license.

There's been a suggestion that I change the project to use the MIT license instead as this is supported by CodePlex.

Are there any concerns or comments from the community about such a change?

Source code checked in, #39751

$
0
0
Added use of C++11 defaulted and deleted constructors

New Post: Retiring VS 2010 and VS 2012 support

$
0
0
With the upcoming release of VS 2015, the number of projects for DirectXTex configuration is getting rather unwieldy. The question is how many people are:

(a) Using VS 2010 with DirectXTex (which requires the Windows 8.1 SDK)

(b) Using VS 2012 with DirectXTex for Win32 desktop development. The VS 2012 compiler toolset is still getting used today for Xbox One XDK, Xbox One ADK, and Windows Store apps for Windows 8.0.

(c) In a related question, how many people still need Windows Store apps for Windows 8.0 support?

Created Feature: texconv should support use of ComputeNormalMap [1325]

$
0
0
The DirectXTex function ComputeNormalMap is used to convert a height-map to a normal-map. texconv should support this option through the command-line.

It essentially replaces the 'Convert' step since the function also performs the format conversion implicitly.

Edited Feature: texconv should support use of ComputeNormalMap [1325]

$
0
0
The DirectXTex function ComputeNormalMap is used to convert a height-map to a normal-map. texconv should support this option through the command-line.

It essentially replaces the 'Convert' step since the function also performs the format conversion implicitly.

Commented Feature: texconv should support use of ComputeNormalMap [1325]

$
0
0
The DirectXTex function ComputeNormalMap is used to convert a height-map to a normal-map. texconv should support this option through the command-line.

It essentially replaces the 'Convert' step since the function also performs the format conversion implicitly.
Comments: ** Comment from web user: walbourn **

Needs to support all the various flags for ComputeNormalMap, as well as the amplitude float parameter

Source code checked in, #39953

Source code checked in, #39958

Viewing all 1174 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>