mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 23:36:00 +02:00
Additional 3d support
This commit is contained in:
parent
70680fdf39
commit
f26df6c86b
32 changed files with 2370 additions and 165 deletions
|
@ -326,7 +326,8 @@ enum BfpSysDirectoryKind
|
|||
BfpSysDirectoryKind_AppData_LocalLow,
|
||||
BfpSysDirectoryKind_AppData_Roaming,
|
||||
BfpSysDirectoryKind_Programs,
|
||||
BfpSysDirectoryKind_Programs_Common
|
||||
BfpSysDirectoryKind_Programs_Common,
|
||||
BfpSysDirectoryKind_Documents
|
||||
};
|
||||
|
||||
struct BfpFindFileData;
|
||||
|
|
243
BeefySysLib/platform/win/DDS.h
Normal file
243
BeefySysLib/platform/win/DDS.h
Normal file
|
@ -0,0 +1,243 @@
|
|||
//--------------------------------------------------------------------------------------
|
||||
// dds.h
|
||||
//
|
||||
// This header defines constants and structures that are useful when parsing
|
||||
// DDS files. DDS files were originally designed to use several structures
|
||||
// and constants that are native to DirectDraw and are defined in ddraw.h,
|
||||
// such as DDSURFACEDESC2 and DDSCAPS2. This file defines similar
|
||||
// (compatible) constants and structures so that one can use DDS files
|
||||
// without needing to include ddraw.h.
|
||||
//
|
||||
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
||||
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
||||
// PARTICULAR PURPOSE.
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// http://go.microsoft.com/fwlink/?LinkId=248926
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE)
|
||||
#include <d3d11_x.h>
|
||||
#else
|
||||
#include <dxgiformat.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
||||
const uint32_t DDS_MAGIC = 0x20534444; // "DDS "
|
||||
|
||||
struct DDS_PIXELFORMAT
|
||||
{
|
||||
uint32_t dwSize;
|
||||
uint32_t dwFlags;
|
||||
uint32_t dwFourCC;
|
||||
uint32_t dwRGBBitCount;
|
||||
uint32_t dwRBitMask;
|
||||
uint32_t dwGBitMask;
|
||||
uint32_t dwBBitMask;
|
||||
uint32_t dwABitMask;
|
||||
};
|
||||
|
||||
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
||||
#define DDS_RGB 0x00000040 // DDPF_RGB
|
||||
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
|
||||
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
|
||||
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
||||
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
|
||||
#define DDS_PAL8 0x00000020 // DDPF_PALETTEINDEXED8
|
||||
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
|
||||
|
||||
#ifndef MAKEFOURCC
|
||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
|
||||
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 ))
|
||||
#endif /* defined(MAKEFOURCC) */
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT1 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','1'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT2 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','2'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT3 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','3'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT4 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','4'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT5 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','T','5'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC4_UNORM =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','4','U'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC4_SNORM =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','4','S'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC5_UNORM =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','5','U'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_BC5_SNORM =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B','C','5','S'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_R8G8_B8G8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('R','G','B','G'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_G8R8_G8B8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('G','R','G','B'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_YUY2 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('Y','U','Y','2'), 0, 0, 0, 0, 0 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8R8G8B8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_X8R8G8B8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8B8G8R8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_X8B8G8R8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_G16R16 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_R5G6B5 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A1R5G5B5 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A4R4G4B4 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_R8G8B8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_L8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0x00, 0x00, 0x00 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_L16 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0x0000, 0x0000, 0x0000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8L8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0x0000, 0x0000, 0xff00 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_A8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0x00, 0x00, 0x00, 0xff };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_V8U8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0x0000, 0x0000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_Q8W8V8U8 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
|
||||
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_V16U16 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 };
|
||||
|
||||
// D3DFMT_A2R10G10B10/D3DFMT_A2B10G10R10 should be written using DX10 extension to avoid D3DX 10:10:10:2 reversal issue
|
||||
|
||||
// This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat)
|
||||
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DX10 =
|
||||
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','1','0'), 0, 0, 0, 0, 0 };
|
||||
|
||||
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
||||
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
|
||||
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
|
||||
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
|
||||
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
|
||||
|
||||
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
|
||||
#define DDS_WIDTH 0x00000004 // DDSD_WIDTH
|
||||
|
||||
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
|
||||
#define DDS_SURFACE_FLAGS_MIPMAP 0x00400008 // DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
|
||||
#define DDS_SURFACE_FLAGS_CUBEMAP 0x00000008 // DDSCAPS_COMPLEX
|
||||
|
||||
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
|
||||
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
|
||||
#define DDS_CUBEMAP_POSITIVEY 0x00001200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
|
||||
#define DDS_CUBEMAP_NEGATIVEY 0x00002200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
|
||||
#define DDS_CUBEMAP_POSITIVEZ 0x00004200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
|
||||
#define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
|
||||
|
||||
#define DDS_CUBEMAP_ALLFACES ( DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX |\
|
||||
DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\
|
||||
DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ )
|
||||
|
||||
#define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP
|
||||
|
||||
#define DDS_FLAGS_VOLUME 0x00200000 // DDSCAPS2_VOLUME
|
||||
|
||||
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
|
||||
enum DDS_RESOURCE_DIMENSION
|
||||
{
|
||||
DDS_DIMENSION_TEXTURE1D = 2,
|
||||
DDS_DIMENSION_TEXTURE2D = 3,
|
||||
DDS_DIMENSION_TEXTURE3D = 4,
|
||||
};
|
||||
|
||||
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
|
||||
enum DDS_RESOURCE_MISC_FLAG
|
||||
{
|
||||
DDS_RESOURCE_MISC_TEXTURECUBE = 0x4L,
|
||||
};
|
||||
|
||||
enum DDS_MISC_FLAGS2
|
||||
{
|
||||
DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L,
|
||||
};
|
||||
|
||||
enum DDS_ALPHA_MODE
|
||||
{
|
||||
DDS_ALPHA_MODE_UNKNOWN = 0,
|
||||
DDS_ALPHA_MODE_STRAIGHT = 1,
|
||||
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
||||
DDS_ALPHA_MODE_OPAQUE = 3,
|
||||
DDS_ALPHA_MODE_CUSTOM = 4,
|
||||
};
|
||||
|
||||
struct DDS_HEADER
|
||||
{
|
||||
uint32_t dwSize;
|
||||
uint32_t dwFlags;
|
||||
uint32_t dwHeight;
|
||||
uint32_t dwWidth;
|
||||
uint32_t dwPitchOrLinearSize;
|
||||
uint32_t dwDepth; // only if DDS_HEADER_FLAGS_VOLUME is set in dwFlags
|
||||
uint32_t dwMipMapCount;
|
||||
uint32_t dwReserved1[11];
|
||||
DDS_PIXELFORMAT ddspf;
|
||||
uint32_t dwCaps;
|
||||
uint32_t dwCaps2;
|
||||
uint32_t dwCaps3;
|
||||
uint32_t dwCaps4;
|
||||
uint32_t dwReserved2;
|
||||
};
|
||||
|
||||
struct DDS_HEADER_DXT10
|
||||
{
|
||||
DXGI_FORMAT dxgiFormat;
|
||||
uint32_t resourceDimension;
|
||||
uint32_t miscFlag; // see DDS_RESOURCE_MISC_FLAG
|
||||
uint32_t arraySize;
|
||||
uint32_t miscFlags2; // see DDS_MISC_FLAGS2
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
static_assert( sizeof(DDS_HEADER) == 124, "DDS Header size mismatch" );
|
||||
static_assert( sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch");
|
||||
|
||||
}; // namespace
|
|
@ -5,6 +5,10 @@
|
|||
#include "img/ImageData.h"
|
||||
#include "util/PerfTimer.h"
|
||||
#include "util/BeefPerf.h"
|
||||
#include "FileStream.h"
|
||||
#include "DDS.h"
|
||||
|
||||
using namespace DirectX;
|
||||
|
||||
#include <D3Dcompiler.h>
|
||||
|
||||
|
@ -37,6 +41,131 @@ USING_NS_BF;
|
|||
#define DXFAILED(check) ((hr = (check)) != 0)
|
||||
#define DXCHECK(check) if ((check) != 0) BF_FATAL(StrFormat("DirectX call failed with result 0x%X", check).c_str());
|
||||
|
||||
static int GetBytesPerPixel(DXGI_FORMAT fmt, int& blockSize)
|
||||
{
|
||||
blockSize = 1;
|
||||
switch (fmt)
|
||||
{
|
||||
case DXGI_FORMAT_UNKNOWN: return 0;
|
||||
case DXGI_FORMAT_R32G32B32A32_TYPELESS: return 4 + 4 + 4 + 4;
|
||||
case DXGI_FORMAT_R32G32B32A32_FLOAT: return 4 + 4 + 4 + 4;
|
||||
case DXGI_FORMAT_R32G32B32A32_UINT: return 4 + 4 + 4 + 4;
|
||||
case DXGI_FORMAT_R32G32B32A32_SINT: return 4 + 4 + 4 + 4;
|
||||
case DXGI_FORMAT_R32G32B32_TYPELESS: return 4 + 4 + 4;
|
||||
case DXGI_FORMAT_R32G32B32_FLOAT: return 4 + 4 + 4;
|
||||
case DXGI_FORMAT_R32G32B32_UINT: return 4 + 4 + 4;
|
||||
case DXGI_FORMAT_R32G32B32_SINT: return 4 + 4 + 4;
|
||||
case DXGI_FORMAT_R16G16B16A16_TYPELESS: return 2 + 2 + 2 + 2;
|
||||
case DXGI_FORMAT_R16G16B16A16_FLOAT: return 2 + 2 + 2 + 2;
|
||||
case DXGI_FORMAT_R16G16B16A16_UNORM: return 2 + 2 + 2 + 2;
|
||||
case DXGI_FORMAT_R16G16B16A16_UINT: return 2 + 2 + 2 + 2;
|
||||
case DXGI_FORMAT_R16G16B16A16_SNORM: return 2 + 2 + 2 + 2;
|
||||
case DXGI_FORMAT_R16G16B16A16_SINT: return 2 + 2 + 2 + 2;
|
||||
case DXGI_FORMAT_R32G32_TYPELESS: return 4 + 4;
|
||||
case DXGI_FORMAT_R32G32_FLOAT: return 4 + 4;
|
||||
case DXGI_FORMAT_R32G32_UINT: return 4 + 4;
|
||||
case DXGI_FORMAT_R32G32_SINT: return 4 + 4;
|
||||
case DXGI_FORMAT_R32G8X24_TYPELESS: return 4 + 3;
|
||||
case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return 4 + 1 + 3;
|
||||
case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: return 4 + 1 + 3;
|
||||
case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: return 4 + 1 + 1 + 3;
|
||||
case DXGI_FORMAT_R10G10B10A2_TYPELESS: return 4;
|
||||
case DXGI_FORMAT_R10G10B10A2_UNORM: return 4;
|
||||
case DXGI_FORMAT_R10G10B10A2_UINT: return 4;
|
||||
case DXGI_FORMAT_R11G11B10_FLOAT: return 4;
|
||||
case DXGI_FORMAT_R8G8B8A8_TYPELESS: return 4;
|
||||
case DXGI_FORMAT_R8G8B8A8_UNORM: return 4;
|
||||
case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: return 4;
|
||||
case DXGI_FORMAT_R8G8B8A8_UINT: return 4;
|
||||
case DXGI_FORMAT_R8G8B8A8_SNORM: return 4;
|
||||
case DXGI_FORMAT_R8G8B8A8_SINT: return 4;
|
||||
case DXGI_FORMAT_R16G16_TYPELESS: return 4;
|
||||
case DXGI_FORMAT_R16G16_FLOAT: return 4;
|
||||
case DXGI_FORMAT_R16G16_UNORM: return 4;
|
||||
case DXGI_FORMAT_R16G16_UINT: return 4;
|
||||
case DXGI_FORMAT_R16G16_SNORM: return 4;
|
||||
case DXGI_FORMAT_R16G16_SINT: return 4;
|
||||
case DXGI_FORMAT_R32_TYPELESS: return 4;
|
||||
case DXGI_FORMAT_D32_FLOAT: return 4;
|
||||
case DXGI_FORMAT_R32_FLOAT: return 4;
|
||||
case DXGI_FORMAT_R32_UINT: return 4;
|
||||
case DXGI_FORMAT_R32_SINT: return 4;
|
||||
case DXGI_FORMAT_R24G8_TYPELESS: return 4;
|
||||
case DXGI_FORMAT_D24_UNORM_S8_UINT: return 4;
|
||||
case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return 4;
|
||||
case DXGI_FORMAT_X24_TYPELESS_G8_UINT: return 4;
|
||||
case DXGI_FORMAT_R8G8_TYPELESS: return 2;
|
||||
case DXGI_FORMAT_R8G8_UNORM: return 2;
|
||||
case DXGI_FORMAT_R8G8_UINT: return 2;
|
||||
case DXGI_FORMAT_R8G8_SNORM: return 2;
|
||||
case DXGI_FORMAT_R8G8_SINT: return 2;
|
||||
case DXGI_FORMAT_R16_TYPELESS: return 2;
|
||||
case DXGI_FORMAT_R16_FLOAT: return 2;
|
||||
case DXGI_FORMAT_D16_UNORM: return 2;
|
||||
case DXGI_FORMAT_R16_UNORM: return 2;
|
||||
case DXGI_FORMAT_R16_UINT: return 2;
|
||||
case DXGI_FORMAT_R16_SNORM: return 2;
|
||||
case DXGI_FORMAT_R16_SINT: return 2;
|
||||
case DXGI_FORMAT_R8_TYPELESS: return 1;
|
||||
case DXGI_FORMAT_R8_UNORM: return 1;
|
||||
case DXGI_FORMAT_R8_UINT: return 1;
|
||||
case DXGI_FORMAT_R8_SNORM: return 1;
|
||||
case DXGI_FORMAT_R8_SINT: return 1;
|
||||
case DXGI_FORMAT_A8_UNORM: return 1;
|
||||
case DXGI_FORMAT_R1_UNORM: return 1;
|
||||
case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: return 3;
|
||||
case DXGI_FORMAT_R8G8_B8G8_UNORM: return 4;
|
||||
case DXGI_FORMAT_G8R8_G8B8_UNORM: return 4;
|
||||
case DXGI_FORMAT_BC1_TYPELESS: blockSize = 4; return 8;
|
||||
case DXGI_FORMAT_BC1_UNORM: blockSize = 4; return 8;
|
||||
case DXGI_FORMAT_BC1_UNORM_SRGB: blockSize = 4; return 8;
|
||||
case DXGI_FORMAT_BC2_TYPELESS: blockSize = 4; return 16;
|
||||
case DXGI_FORMAT_BC2_UNORM: blockSize = 4; return 16;
|
||||
case DXGI_FORMAT_BC2_UNORM_SRGB: blockSize = 4; return 16;
|
||||
case DXGI_FORMAT_BC3_TYPELESS: blockSize = 4; return 16;
|
||||
case DXGI_FORMAT_BC3_UNORM: blockSize = 4; return 16;
|
||||
case DXGI_FORMAT_BC3_UNORM_SRGB: blockSize = 4; return 16;
|
||||
case DXGI_FORMAT_BC4_TYPELESS: blockSize = 4; return 8;
|
||||
case DXGI_FORMAT_BC4_UNORM: blockSize = 4; return 8;
|
||||
case DXGI_FORMAT_BC4_SNORM: blockSize = 4; return 8;
|
||||
case DXGI_FORMAT_BC5_TYPELESS: blockSize = 4; return 16;
|
||||
case DXGI_FORMAT_BC5_UNORM: blockSize = 4; return 16;
|
||||
case DXGI_FORMAT_BC5_SNORM: blockSize = 4; return 16;
|
||||
case DXGI_FORMAT_B5G6R5_UNORM: return 1;
|
||||
case DXGI_FORMAT_B5G5R5A1_UNORM: return 2;
|
||||
case DXGI_FORMAT_B8G8R8A8_UNORM: return 4;
|
||||
case DXGI_FORMAT_B8G8R8X8_UNORM: return 4;
|
||||
case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM: return 4;
|
||||
case DXGI_FORMAT_B8G8R8A8_TYPELESS: return 4;
|
||||
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: return 4;
|
||||
case DXGI_FORMAT_B8G8R8X8_TYPELESS: return 4;
|
||||
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: return 4;
|
||||
case DXGI_FORMAT_BC6H_TYPELESS: return 1;
|
||||
case DXGI_FORMAT_BC6H_UF16: return 1;
|
||||
case DXGI_FORMAT_BC6H_SF16: return 1;
|
||||
case DXGI_FORMAT_BC7_TYPELESS: return 1;
|
||||
case DXGI_FORMAT_BC7_UNORM: return 1;
|
||||
case DXGI_FORMAT_BC7_UNORM_SRGB: return 1;
|
||||
case DXGI_FORMAT_AYUV: return 1;
|
||||
case DXGI_FORMAT_Y410: return 1;
|
||||
case DXGI_FORMAT_Y416: return 1;
|
||||
case DXGI_FORMAT_NV12: return 1;
|
||||
case DXGI_FORMAT_P010: return 1;
|
||||
case DXGI_FORMAT_P016: return 1;
|
||||
case DXGI_FORMAT_420_OPAQUE: return 1;
|
||||
case DXGI_FORMAT_YUY2: return 1;
|
||||
case DXGI_FORMAT_Y210: return 1;
|
||||
case DXGI_FORMAT_Y216: return 1;
|
||||
case DXGI_FORMAT_NV11: return 1;
|
||||
case DXGI_FORMAT_AI44: return 1;
|
||||
case DXGI_FORMAT_IA44: return 1;
|
||||
case DXGI_FORMAT_P8: return 1;
|
||||
case DXGI_FORMAT_A8P8: return 1;
|
||||
case DXGI_FORMAT_B4G4R4A4_UNORM: return 1;
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
|
||||
DXShaderParam::DXShaderParam()
|
||||
{
|
||||
mD3DVariable = NULL;
|
||||
|
@ -383,7 +512,7 @@ void DXRenderDevice::PhysSetRenderState(RenderState* renderState)
|
|||
|
||||
if ((renderState->mShader != mPhysRenderState->mShader) && (renderState->mShader != NULL))
|
||||
{
|
||||
mD3DDeviceContext->PSSetSamplers(0, 1, &mD3DDefaultSamplerState);
|
||||
mD3DDeviceContext->PSSetSamplers(0, 1, mPhysRenderState->mTexWrap ? &mD3DWrapSamplerState : &mD3DDefaultSamplerState);
|
||||
mD3DDeviceContext->IASetInputLayout(dxShader->mD3DLayout);
|
||||
mD3DDeviceContext->VSSetShader(dxShader->mD3DVertexShader, NULL, 0);
|
||||
mD3DDeviceContext->PSSetShader(dxShader->mD3DPixelShader, NULL, 0);
|
||||
|
@ -595,6 +724,7 @@ ModelInstance* DXRenderDevice::CreateModelInstance(ModelDef* modelDef)
|
|||
|
||||
//renderState->mCullMode = CullMode_Front;
|
||||
|
||||
renderState->mTexWrap = true;
|
||||
renderState->mDepthFunc = DepthFunc_LessEqual;
|
||||
renderState->mWriteDepthBuffer = true;
|
||||
|
||||
|
@ -602,91 +732,135 @@ ModelInstance* DXRenderDevice::CreateModelInstance(ModelDef* modelDef)
|
|||
|
||||
////
|
||||
|
||||
dxModelInstance->mD3DRenderDevice = this;
|
||||
|
||||
dxModelInstance->mDXModelMeshs.resize(modelDef->mMeshes.size());
|
||||
dxModelInstance->mD3DRenderDevice = this;
|
||||
dxModelInstance->mDXModelMeshs.Resize(modelDef->mMeshes.size());
|
||||
int dxMeshIdx = 0;
|
||||
|
||||
for (int meshIdx = 0; meshIdx < (int)modelDef->mMeshes.size(); meshIdx++)
|
||||
{
|
||||
ModelMesh* mesh = &modelDef->mMeshes[meshIdx];
|
||||
|
||||
DXModelMesh* dxMesh = &dxModelInstance->mDXModelMeshs[meshIdx];
|
||||
|
||||
String texPath = mesh->mTexFileName;
|
||||
if ((int)texPath.IndexOf(':') == -1)
|
||||
texPath = modelDef->mLoadDir + "Textures/" + texPath;
|
||||
//texPath = gBFApp->mInstallDir + L"models/Textures/" + texPath;
|
||||
|
||||
dxMesh->mTexture = (DXTexture*)((RenderDevice*)this)->LoadTexture(texPath, TextureFlag_NoPremult);
|
||||
|
||||
dxMesh->mNumIndices = (int)mesh->mIndices.size();
|
||||
dxMesh->mNumVertices = (int)mesh->mVertices.size();
|
||||
|
||||
D3D11_BUFFER_DESC bd;
|
||||
bd.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bd.ByteWidth = (int)mesh->mIndices.size() * sizeof(uint16);
|
||||
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
bd.MiscFlags = 0;
|
||||
bd.StructureByteStride = 0;
|
||||
|
||||
mD3DDevice->CreateBuffer(&bd, NULL, &dxMesh->mD3DIndexBuffer);
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mappedSubResource;
|
||||
|
||||
DXCHECK(mD3DDeviceContext->Map(dxMesh->mD3DIndexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedSubResource));
|
||||
uint16* dxIdxData = (uint16*)mappedSubResource.pData;
|
||||
for (int idxIdx = 0; idxIdx < dxMesh->mNumIndices; idxIdx++)
|
||||
dxIdxData[idxIdx] = (uint16)mesh->mIndices[idxIdx];
|
||||
mD3DDeviceContext->Unmap(dxMesh->mD3DIndexBuffer, 0);
|
||||
|
||||
//
|
||||
|
||||
bd.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bd.ByteWidth = (int)mesh->mVertices.size() * sizeof(DXModelVertex);
|
||||
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
bd.MiscFlags = 0;
|
||||
bd.StructureByteStride = 0;
|
||||
|
||||
mD3DDevice->CreateBuffer(&bd, NULL, &dxMesh->mD3DVertexBuffer);
|
||||
|
||||
/*DXCHECK(mD3DDeviceContext->Map(dxMesh->mD3DVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedSubResource));
|
||||
DXModelVertex* dxVtxData = (DXModelVertex*)mappedSubResource.pData;
|
||||
for (int vtxIdx = 0; vtxIdx < (int)mesh->mVertexData.size(); vtxIdx++)
|
||||
{
|
||||
VertexData* srcVtxData = &mesh->mVertexData[vtxIdx];
|
||||
DXModelVertex* destVtx = dxVtxData + vtxIdx;
|
||||
|
||||
destVtx->mPosition = srcVtxData->mCoords;
|
||||
destVtx->mTexCoords = srcVtxData->mTexCoords[0];
|
||||
destVtx->mTexCoords.mV = 1.0f - destVtx->mTexCoords.mV;
|
||||
destVtx->mBumpTexCoords = srcVtxData->mTexCoords[0];
|
||||
destVtx->mColor = 0xFFFFFFFF;
|
||||
destVtx->mTangent = srcVtxData->mTangent;
|
||||
}
|
||||
DXModelMesh* dxMesh = &dxModelInstance->mDXModelMeshs[dxMeshIdx];
|
||||
|
||||
mD3DDeviceContext->Unmap(dxMesh->mD3DVertexBuffer, 0);*/
|
||||
dxMesh->mPrimitives.Resize(mesh->mPrimitives.size());
|
||||
|
||||
for (int primitivesIdx = 0 ; primitivesIdx < (int)mesh->mPrimitives.size(); primitivesIdx++)
|
||||
{
|
||||
auto primitives = &mesh->mPrimitives[primitivesIdx];
|
||||
auto dxPrimitives = &dxMesh->mPrimitives[primitivesIdx];
|
||||
|
||||
// String texPath = mesh->mTexFileName;
|
||||
// if (!texPath.IsEmpty())
|
||||
// {
|
||||
// if ((int)texPath.IndexOf(':') == -1)
|
||||
// texPath = modelDef->mLoadDir + "Textures/" + texPath;
|
||||
// //texPath = gBFApp->mInstallDir + L"models/Textures/" + texPath;
|
||||
//
|
||||
// dxPrimitives->mTexture = (DXTexture*)((RenderDevice*)this)->LoadTexture(texPath, TextureFlag_NoPremult);
|
||||
// }
|
||||
|
||||
Array<String> texPaths = primitives->mTexPaths;
|
||||
|
||||
|
||||
if (primitives->mMaterial != NULL)
|
||||
{
|
||||
dxPrimitives->mMaterialName = primitives->mMaterial->mName;
|
||||
if (primitives->mMaterial->mDef != NULL)
|
||||
{
|
||||
for (auto& texParamVal : primitives->mMaterial->mDef->mTextureParameterValues)
|
||||
{
|
||||
if (texPaths.IsEmpty())
|
||||
texPaths.Add(texParamVal->mTexturePath);
|
||||
|
||||
// if (texPath.IsEmpty())
|
||||
// texPath = texParamVal->mTexturePath;
|
||||
// if ((texParamVal->mName == "Albedo_texture") || (texParamVal->mName.EndsWith("_Color")))
|
||||
// texPath = texParamVal->mTexturePath;
|
||||
// else if ((texParamVal->mName == "NM_texture") || (texParamVal->mName.EndsWith("_NM")))
|
||||
// bumpTexPath = texParamVal->mTexturePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& texPath : texPaths)
|
||||
{
|
||||
if (!modelDef->mLoadDir.IsEmpty())
|
||||
texPath = GetAbsPath(texPath, modelDef->mLoadDir);
|
||||
dxPrimitives->mTextures.Add((DXTexture*)((RenderDevice*)this)->LoadTexture(texPath, TextureFlag_NoPremult));
|
||||
}
|
||||
|
||||
dxPrimitives->mNumIndices = (int)primitives->mIndices.size();
|
||||
dxPrimitives->mNumVertices = (int)primitives->mVertices.size();
|
||||
|
||||
D3D11_BUFFER_DESC bd;
|
||||
bd.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bd.ByteWidth = (int)primitives->mIndices.size() * sizeof(uint16);
|
||||
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
bd.MiscFlags = 0;
|
||||
bd.StructureByteStride = 0;
|
||||
|
||||
mD3DDevice->CreateBuffer(&bd, NULL, &dxPrimitives->mD3DIndexBuffer);
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mappedSubResource;
|
||||
|
||||
DXCHECK(mD3DDeviceContext->Map(dxPrimitives->mD3DIndexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedSubResource));
|
||||
uint16* dxIdxData = (uint16*)mappedSubResource.pData;
|
||||
for (int idxIdx = 0; idxIdx < dxPrimitives->mNumIndices; idxIdx++)
|
||||
dxIdxData[idxIdx] = (uint16)primitives->mIndices[idxIdx];
|
||||
mD3DDeviceContext->Unmap(dxPrimitives->mD3DIndexBuffer, 0);
|
||||
|
||||
//
|
||||
|
||||
bd.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bd.ByteWidth = (int)primitives->mVertices.size() * sizeof(DXModelVertex);
|
||||
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
bd.MiscFlags = 0;
|
||||
bd.StructureByteStride = 0;
|
||||
|
||||
mD3DDevice->CreateBuffer(&bd, NULL, &dxPrimitives->mD3DVertexBuffer);
|
||||
|
||||
DXCHECK(mD3DDeviceContext->Map(dxPrimitives->mD3DVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedSubResource));
|
||||
DXModelVertex* dxVtxData = (DXModelVertex*)mappedSubResource.pData;
|
||||
for (int vtxIdx = 0; vtxIdx < (int)primitives->mVertices.size(); vtxIdx++)
|
||||
{
|
||||
ModelVertex* srcVtxData = &primitives->mVertices[vtxIdx];
|
||||
DXModelVertex* destVtx = dxVtxData + vtxIdx;
|
||||
|
||||
destVtx->mPosition = srcVtxData->mPosition;
|
||||
destVtx->mTexCoords = srcVtxData->mTexCoords;
|
||||
//destVtx->mTexCoords.mV = 1.0f - destVtx->mTexCoords.mV;
|
||||
destVtx->mTexCoords.mV = destVtx->mTexCoords.mV;
|
||||
destVtx->mBumpTexCoords = srcVtxData->mBumpTexCoords;
|
||||
destVtx->mColor = srcVtxData->mColor;
|
||||
destVtx->mTangent = srcVtxData->mTangent;
|
||||
}
|
||||
|
||||
mD3DDeviceContext->Unmap(dxPrimitives->mD3DVertexBuffer, 0);
|
||||
|
||||
dxMeshIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
return dxModelInstance;
|
||||
}
|
||||
|
||||
void DXDrawLayer::SetShaderConstantData(int slotIdx, void* constData, int size)
|
||||
void DXDrawLayer::SetShaderConstantData(int usageIdx, int slotIdx, void* constData, int size)
|
||||
{
|
||||
DXSetConstantData* dxSetConstantData = AllocRenderCmd<DXSetConstantData>(size);
|
||||
dxSetConstantData->mRenderState = mRenderDevice->mCurRenderState;
|
||||
dxSetConstantData->mUsageIdx = usageIdx;
|
||||
dxSetConstantData->mSlotIdx = slotIdx;
|
||||
dxSetConstantData->mSize = size;
|
||||
|
||||
if (size == 64) // Transpose for shader
|
||||
*((Matrix4*)dxSetConstantData->mData) = Matrix4::Transpose(*((Matrix4*)constData));
|
||||
else
|
||||
// if (size == 64) // Transpose for shader
|
||||
// *((Matrix4*)dxSetConstantData->mData) = Matrix4::Transpose(*((Matrix4*)constData));
|
||||
// else
|
||||
memcpy(dxSetConstantData->mData, constData, size);
|
||||
QueueRenderCmd(dxSetConstantData);
|
||||
}
|
||||
|
||||
void DXDrawLayer::SetShaderConstantDataTyped(int slotIdx, void* constData, int size, int* typeData, int typeCount)
|
||||
void DXDrawLayer::SetShaderConstantDataTyped(int usageIdx, int slotIdx, void* constData, int size, int* typeData, int typeCount)
|
||||
{
|
||||
for (int usageIdx = 0; usageIdx < 2; usageIdx++)
|
||||
{
|
||||
|
@ -770,18 +944,20 @@ void DXDrawLayer::SetShaderConstantDataTyped(int slotIdx, void* constData, int s
|
|||
|
||||
///
|
||||
|
||||
DXModelMesh::DXModelMesh()
|
||||
DXModelPrimitives::DXModelPrimitives()
|
||||
{
|
||||
mD3DIndexBuffer = NULL;
|
||||
mD3DVertexBuffer = NULL;
|
||||
mD3DVertexBuffer = NULL;
|
||||
}
|
||||
|
||||
DXModelMesh::~DXModelMesh()
|
||||
DXModelPrimitives::~DXModelPrimitives()
|
||||
{
|
||||
if (mD3DIndexBuffer != NULL)
|
||||
mD3DIndexBuffer->Release();
|
||||
if (mD3DVertexBuffer != NULL)
|
||||
mD3DVertexBuffer->Release();
|
||||
for (auto tex : mTextures)
|
||||
tex->Release();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -839,6 +1015,12 @@ void DXRenderState::SetClipped(bool clipped)
|
|||
InvalidateRasterizerState();
|
||||
}
|
||||
|
||||
void DXRenderState::SetTexWrap(bool wrap)
|
||||
{
|
||||
mTexWrap = wrap;
|
||||
InvalidateRasterizerState();
|
||||
}
|
||||
|
||||
void DXRenderState::SetClipRect(const Rect& rect)
|
||||
{
|
||||
BF_ASSERT((rect.mWidth >= 0) && (rect.mHeight >= 0));
|
||||
|
@ -879,14 +1061,44 @@ void DXModelInstance::Render(RenderDevice* renderDevice, RenderWindow* renderWin
|
|||
|
||||
DXModelMesh* dxMesh = &mDXModelMeshs[meshIdx];
|
||||
|
||||
mD3DRenderDevice->mD3DDeviceContext->PSSetShaderResources(0, 1, &dxMesh->mTexture->mD3DResourceView);
|
||||
|
||||
// Set vertex buffer
|
||||
UINT stride = sizeof(DXModelVertex);
|
||||
UINT offset = 0;
|
||||
mD3DRenderDevice->mD3DDeviceContext->IASetVertexBuffers(0, 1, &dxMesh->mD3DVertexBuffer, &stride, &offset);
|
||||
mD3DRenderDevice->mD3DDeviceContext->IASetIndexBuffer(dxMesh->mD3DIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
mD3DRenderDevice->mD3DDeviceContext->DrawIndexed(dxMesh->mNumIndices, 0, 0);
|
||||
for (auto primIdx = 0; primIdx < (int)dxMesh->mPrimitives.size(); primIdx++)
|
||||
{
|
||||
auto dxPrimitives = &dxMesh->mPrimitives[primIdx];
|
||||
|
||||
if (dxPrimitives->mNumIndices == 11904)
|
||||
{
|
||||
NOP;
|
||||
}
|
||||
|
||||
//TODO:
|
||||
if (dxPrimitives->mNumIndices == 48384)
|
||||
continue;
|
||||
|
||||
if (::GetAsyncKeyState('1'))
|
||||
{
|
||||
if (dxPrimitives->mNumIndices != 9417)
|
||||
continue;
|
||||
}
|
||||
else if (::GetAsyncKeyState('2'))
|
||||
{
|
||||
if (dxPrimitives->mNumIndices != 3684)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (dxPrimitives->mTextures.IsEmpty())
|
||||
continue;
|
||||
|
||||
for (int i = 0; i < (int)dxPrimitives->mTextures.mSize; i++)
|
||||
mD3DRenderDevice->mD3DDeviceContext->PSSetShaderResources(i, 1, &dxPrimitives->mTextures[i]->mD3DResourceView);
|
||||
|
||||
// Set vertex buffer
|
||||
UINT stride = sizeof(DXModelVertex);
|
||||
UINT offset = 0;
|
||||
mD3DRenderDevice->mD3DDeviceContext->IASetVertexBuffers(0, 1, &dxPrimitives->mD3DVertexBuffer, &stride, &offset);
|
||||
mD3DRenderDevice->mD3DDeviceContext->IASetIndexBuffer(dxPrimitives->mD3DIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
mD3DRenderDevice->mD3DDeviceContext->DrawIndexed(dxPrimitives->mNumIndices, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -992,46 +1204,59 @@ void DXSetTextureCmd::Render(RenderDevice* renderDevice, RenderWindow* renderWin
|
|||
|
||||
void DXSetConstantData::Render(RenderDevice* renderDevice, RenderWindow* renderWindow)
|
||||
{
|
||||
SetRenderState();
|
||||
//SetRenderState();
|
||||
|
||||
DXShader* dxShader = (DXShader*)renderDevice->mCurRenderState->mShader;
|
||||
DXRenderDevice* dxRenderDevice = (DXRenderDevice*)renderDevice;
|
||||
|
||||
HRESULT result = 0;
|
||||
|
||||
int numBlocks = (mSize + 16 - 1) / 16;
|
||||
int mtxBufferNum = mSlotIdx * 32 + (numBlocks - 1) * 2 + mUsageIdx;
|
||||
static ID3D11Buffer* matrixBuffers[32 * 32 * 2] = {NULL};
|
||||
|
||||
if (matrixBuffers[mtxBufferNum] == NULL)
|
||||
{
|
||||
int bufferSize = BF_ALIGN(mSize, 16);
|
||||
|
||||
int id = (mSlotIdx << 24) | (bufferSize << 1) | (mUsageIdx);
|
||||
ID3D11Buffer* buffer = NULL;
|
||||
ID3D11Buffer** bufferPtr = NULL;
|
||||
if (dxRenderDevice->mBufferMap.TryAdd(id, NULL, &bufferPtr))
|
||||
{
|
||||
D3D11_BUFFER_DESC matrixBufferDesc;
|
||||
matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
matrixBufferDesc.ByteWidth = sizeof(float[4]) * numBlocks;
|
||||
matrixBufferDesc.ByteWidth = bufferSize;
|
||||
matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
matrixBufferDesc.MiscFlags = 0;
|
||||
matrixBufferDesc.StructureByteStride = 0;
|
||||
|
||||
result = dxRenderDevice->mD3DDevice->CreateBuffer(&matrixBufferDesc, NULL, &matrixBuffers[mtxBufferNum]);
|
||||
result = dxRenderDevice->mD3DDevice->CreateBuffer(&matrixBufferDesc, NULL, &buffer);
|
||||
if (FAILED(result))
|
||||
return;
|
||||
|
||||
//OutputDebugStrF("Created Buffer %d %p\n", bufferSize, buffer);
|
||||
|
||||
*bufferPtr = buffer;
|
||||
}
|
||||
else
|
||||
buffer = *bufferPtr;
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||
result = dxRenderDevice->mD3DDeviceContext->Map(matrixBuffers[mtxBufferNum], 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
result = dxRenderDevice->mD3DDeviceContext->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
return;
|
||||
|
||||
float* dataPtr = (float*) mappedResource.pData;
|
||||
memset(dataPtr, 0, numBlocks * 16);
|
||||
|
||||
float* dataPtr = (float*)mappedResource.pData;
|
||||
memset(dataPtr, 0, bufferSize);
|
||||
memcpy(mappedResource.pData, mData, mSize);
|
||||
|
||||
dxRenderDevice->mD3DDeviceContext->Unmap(matrixBuffers[mtxBufferNum], 0);
|
||||
|
||||
dxRenderDevice->mD3DDeviceContext->Unmap(buffer, 0);
|
||||
if (mUsageIdx == 0)
|
||||
dxRenderDevice->mD3DDeviceContext->VSSetConstantBuffers(mSlotIdx, 1, &matrixBuffers[mtxBufferNum]);
|
||||
{
|
||||
//OutputDebugStrF("VSSetConstantBuffers %d %p\n", mSlotIdx, buffer);
|
||||
dxRenderDevice->mD3DDeviceContext->VSSetConstantBuffers(mSlotIdx, 1, &buffer);
|
||||
}
|
||||
else
|
||||
dxRenderDevice->mD3DDeviceContext->PSSetConstantBuffers(mSlotIdx, 1, &matrixBuffers[mtxBufferNum]);
|
||||
{
|
||||
//OutputDebugStrF("PSSetConstantBuffers %d %p\n", mSlotIdx, buffer);
|
||||
dxRenderDevice->mD3DDeviceContext->PSSetConstantBuffers(mSlotIdx, 1, &buffer);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
|
@ -1291,7 +1516,8 @@ bool DXRenderDevice::Init(BFApp* app)
|
|||
|
||||
D3D_FEATURE_LEVEL d3dFeatureLevel = (D3D_FEATURE_LEVEL)0;
|
||||
int flags = 0;
|
||||
//flags = D3D11_CREATE_DEVICE_DEBUG;
|
||||
//TODO:
|
||||
flags = D3D11_CREATE_DEVICE_DEBUG;
|
||||
DXCHECK(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, featureLevelArr, 6, D3D11_SDK_VERSION, &mD3DDevice, &d3dFeatureLevel, &mD3DDeviceContext));
|
||||
OutputDebugStrF("D3D Feature Level: %X\n", d3dFeatureLevel);
|
||||
|
||||
|
@ -1363,9 +1589,18 @@ bool DXRenderDevice::Init(BFApp* app)
|
|||
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
|
||||
sampDesc.MinLOD = 0;
|
||||
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
|
||||
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
DXCHECK(mD3DDevice->CreateSamplerState(&sampDesc, &mD3DDefaultSamplerState));
|
||||
|
||||
ZeroMemory(&sampDesc, sizeof(sampDesc));
|
||||
sampDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
|
||||
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
|
||||
sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
|
||||
sampDesc.MinLOD = 0;
|
||||
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
DXCHECK(mD3DDevice->CreateSamplerState(&sampDesc, &mD3DWrapSamplerState));
|
||||
|
||||
D3D11_BUFFER_DESC bd;
|
||||
bd.Usage = D3D11_USAGE_DYNAMIC;
|
||||
|
@ -1402,6 +1637,8 @@ void DXRenderDevice::ReleaseNative()
|
|||
mD3DNormalBlendState = NULL;
|
||||
mD3DDefaultSamplerState->Release();
|
||||
mD3DDefaultSamplerState = NULL;
|
||||
mD3DWrapSamplerState->Release();
|
||||
mD3DWrapSamplerState = NULL;
|
||||
mD3DDeviceContext->Release();
|
||||
mD3DDeviceContext = NULL;
|
||||
mD3DDevice->Release();
|
||||
|
@ -1468,6 +1705,178 @@ void DXRenderDevice::FrameEnd()
|
|||
}
|
||||
}
|
||||
|
||||
Texture* DXRenderDevice::LoadTexture(const StringImpl& fileName, int flags)
|
||||
{
|
||||
if (fileName.StartsWith("!backbuffer:"))
|
||||
{
|
||||
int colon = (int)fileName.IndexOf(':');
|
||||
String addrStr = fileName.Substring(colon + 1);
|
||||
void* addr = (void*)(intptr)strtoll(addrStr.c_str(), NULL, 16);
|
||||
BFWindow* window = (BFWindow*)addr;
|
||||
DXRenderWindow* renderWindow = (DXRenderWindow*)window->mRenderWindow;
|
||||
|
||||
DXTexture* aTexture = NULL;
|
||||
aTexture->mD3DRenderTargetView = renderWindow->mD3DRenderTargetView;
|
||||
aTexture->mD3DTexture = renderWindow->mD3DBackBuffer;
|
||||
|
||||
aTexture->mD3DRenderTargetView->AddRef();
|
||||
aTexture->mD3DTexture->AddRef();
|
||||
aTexture->AddRef();
|
||||
return aTexture;
|
||||
}
|
||||
|
||||
DXTexture* aTexture = NULL;
|
||||
if (mTextureMap.TryGetValue(fileName, &aTexture))
|
||||
{
|
||||
aTexture->AddRef();
|
||||
return aTexture;
|
||||
}
|
||||
|
||||
int dotPos = (int)fileName.LastIndexOf('.');
|
||||
String ext;
|
||||
if (dotPos != -1)
|
||||
ext = fileName.Substring(dotPos);
|
||||
|
||||
if (ext.Equals(".dds", StringImpl::CompareKind_OrdinalIgnoreCase))
|
||||
{
|
||||
FileStream fs;
|
||||
if (!fs.Open(fileName, "rb"))
|
||||
return NULL;
|
||||
|
||||
int header = fs.ReadInt32();
|
||||
if (header != 0x20534444)
|
||||
return NULL;
|
||||
|
||||
auto hdr = fs.ReadT<DDS_HEADER>();
|
||||
|
||||
DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
|
||||
if (hdr.ddspf.dwFlags == DDS_RGBA)
|
||||
{
|
||||
if (hdr.ddspf.dwRGBBitCount == 32)
|
||||
{
|
||||
if (hdr.ddspf.dwRBitMask == 0xff)
|
||||
format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
else if (hdr.ddspf.dwRBitMask = 0xff0000)
|
||||
format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
else if (hdr.ddspf.dwRBitMask == 0xffff)
|
||||
format = DXGI_FORMAT_R16G16_UNORM;
|
||||
else if (hdr.ddspf.dwRBitMask == 0x3ff)
|
||||
format = DXGI_FORMAT_R10G10B10A2_UNORM;
|
||||
}
|
||||
else if (hdr.ddspf.dwRGBBitCount == 16)
|
||||
{
|
||||
if (hdr.ddspf.dwRBitMask == 0x7c00)
|
||||
format = DXGI_FORMAT_B5G5R5A1_UNORM;
|
||||
else if (hdr.ddspf.dwRBitMask == 0xf800)
|
||||
format = DXGI_FORMAT_B5G6R5_UNORM;
|
||||
}
|
||||
else if (hdr.ddspf.dwRGBBitCount == 8)
|
||||
{
|
||||
if (hdr.ddspf.dwRBitMask == 0xff)
|
||||
format = DXGI_FORMAT_R8_UNORM;
|
||||
else if (hdr.ddspf.dwABitMask == 0xff)
|
||||
format = DXGI_FORMAT_A8_UNORM;
|
||||
}
|
||||
}
|
||||
|
||||
if (hdr.ddspf.dwFourCC == '1TXD')
|
||||
format = DXGI_FORMAT_BC1_UNORM;
|
||||
if (hdr.ddspf.dwFourCC == '3TXD')
|
||||
format = DXGI_FORMAT_BC2_UNORM;
|
||||
if (hdr.ddspf.dwFourCC == '5TXD')
|
||||
format = DXGI_FORMAT_BC3_UNORM;
|
||||
if (hdr.ddspf.dwFourCC == 'U4CB')
|
||||
format = DXGI_FORMAT_BC4_UNORM;
|
||||
if (hdr.ddspf.dwFourCC == 'S4CB')
|
||||
format = DXGI_FORMAT_BC4_SNORM;
|
||||
if (hdr.ddspf.dwFourCC == '2ITA')
|
||||
format = DXGI_FORMAT_BC5_UNORM;
|
||||
if (hdr.ddspf.dwFourCC == 'S5CB')
|
||||
format = DXGI_FORMAT_BC5_SNORM;
|
||||
|
||||
if (hdr.ddspf.dwFourCC == '01XD')
|
||||
{
|
||||
auto hdr10 = fs.ReadT<DDS_HEADER_DXT10>();
|
||||
format = hdr10.dxgiFormat;
|
||||
}
|
||||
|
||||
int blockSize = 0;
|
||||
int bytesPerPixel = GetBytesPerPixel(format, blockSize);
|
||||
|
||||
int mipSize = ((hdr.dwWidth + blockSize - 1) / blockSize) * ((hdr.dwHeight + blockSize - 1) / blockSize) * bytesPerPixel;
|
||||
Array<uint8> data;
|
||||
data.Resize(mipSize);
|
||||
fs.Read(data.mVals, data.mSize);
|
||||
|
||||
D3D11_SUBRESOURCE_DATA resData;
|
||||
resData.pSysMem = data.mVals;
|
||||
resData.SysMemPitch = ((hdr.dwWidth + blockSize - 1) / blockSize) * bytesPerPixel;
|
||||
resData.SysMemSlicePitch = mipSize;
|
||||
|
||||
// Create the target texture
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
ZeroMemory(&desc, sizeof(desc));
|
||||
desc.Width = hdr.dwWidth;
|
||||
desc.Height = hdr.dwHeight;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
|
||||
DXGI_FORMAT viewFormat = format;
|
||||
switch (viewFormat)
|
||||
{
|
||||
case DXGI_FORMAT_B8G8R8A8_TYPELESS: viewFormat = DXGI_FORMAT_B8G8R8A8_UNORM; break;
|
||||
case DXGI_FORMAT_R8G8B8A8_TYPELESS: viewFormat = DXGI_FORMAT_R8G8B8A8_UNORM; break;
|
||||
case DXGI_FORMAT_BC1_TYPELESS: viewFormat = DXGI_FORMAT_BC1_UNORM; break;
|
||||
case DXGI_FORMAT_BC2_TYPELESS: viewFormat = DXGI_FORMAT_BC2_UNORM; break;
|
||||
case DXGI_FORMAT_BC3_TYPELESS: viewFormat = DXGI_FORMAT_BC3_UNORM; break;
|
||||
case DXGI_FORMAT_BC4_TYPELESS: viewFormat = DXGI_FORMAT_BC4_UNORM; break;
|
||||
case DXGI_FORMAT_BC5_TYPELESS: viewFormat = DXGI_FORMAT_BC5_UNORM; break;
|
||||
}
|
||||
|
||||
//OutputDebugStrF("Creating texture\n");
|
||||
|
||||
ID3D11Texture2D* d3DTexture = NULL;
|
||||
DXCHECK(mD3DDevice->CreateTexture2D(&desc, &resData, &d3DTexture));
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srDesc;
|
||||
srDesc.Format = viewFormat;
|
||||
srDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srDesc.Texture2D.MostDetailedMip = 0;
|
||||
srDesc.Texture2D.MipLevels = 1;
|
||||
|
||||
ID3D11ShaderResourceView* d3DShaderResourceView = NULL;
|
||||
DXCHECK(mD3DDevice->CreateShaderResourceView(d3DTexture, &srDesc, &d3DShaderResourceView));
|
||||
|
||||
DXTexture* aTexture = new DXTexture();
|
||||
aTexture->mPath = fileName;
|
||||
aTexture->mRenderDevice = this;
|
||||
aTexture->mWidth = hdr.dwWidth;
|
||||
aTexture->mHeight = hdr.dwHeight;
|
||||
aTexture->mD3DTexture = d3DTexture;
|
||||
aTexture->mD3DResourceView = d3DShaderResourceView;
|
||||
aTexture->AddRef();
|
||||
|
||||
mTextureMap[aTexture->mPath] = aTexture;
|
||||
mTextures.Add(aTexture);
|
||||
return aTexture;
|
||||
}
|
||||
|
||||
aTexture = (DXTexture*)RenderDevice::LoadTexture(fileName, flags);
|
||||
if (aTexture != NULL)
|
||||
{
|
||||
aTexture->mPath = fileName;
|
||||
mTextureMap[aTexture->mPath] = aTexture;
|
||||
}
|
||||
|
||||
return aTexture;
|
||||
}
|
||||
|
||||
Texture* DXRenderDevice::LoadTexture(ImageData* imageData, int flags)
|
||||
{
|
||||
ID3D11ShaderResourceView* d3DShaderResourceView = NULL;
|
||||
|
@ -1809,7 +2218,7 @@ Texture* DXRenderDevice::CreateRenderTarget(int width, int height, bool destAlph
|
|||
|
||||
ID3D11Texture2D* d3DTexture = NULL;
|
||||
DXCHECK(mD3DDevice->CreateTexture2D(&desc, NULL, &d3DTexture));
|
||||
|
||||
|
||||
aWidth = width;
|
||||
aHeight = height;
|
||||
|
||||
|
@ -1833,6 +2242,7 @@ Texture* DXRenderDevice::CreateRenderTarget(int width, int height, bool destAlph
|
|||
aRenderTarget->mWidth = width;
|
||||
aRenderTarget->mHeight = height;
|
||||
aRenderTarget->mRenderDevice = this;
|
||||
aRenderTarget->mD3DTexture = d3DTexture;
|
||||
aRenderTarget->mD3DResourceView = d3DShaderResourceView;
|
||||
aRenderTarget->mD3DRenderTargetView = d3DRenderTargetView;
|
||||
aRenderTarget->AddRef();
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "gfx/DrawLayer.h"
|
||||
#include "gfx/ModelInstance.h"
|
||||
#include "util/HashSet.h"
|
||||
#include "util/Dictionary.h"
|
||||
#include <map>
|
||||
|
||||
NS_BF_BEGIN;
|
||||
|
@ -55,6 +56,7 @@ class DXRenderDevice;
|
|||
class DXTexture : public Texture
|
||||
{
|
||||
public:
|
||||
String mPath;
|
||||
DXRenderDevice* mRenderDevice;
|
||||
ID3D11Texture2D* mD3DTexture;
|
||||
ID3D11ShaderResourceView* mD3DResourceView;
|
||||
|
@ -124,8 +126,8 @@ class DXDrawLayer : public DrawLayer
|
|||
public:
|
||||
virtual DrawBatch* CreateDrawBatch();
|
||||
virtual RenderCmd* CreateSetTextureCmd(int textureIdx, Texture* texture) override;
|
||||
virtual void SetShaderConstantData(int slotIdx, void* constData, int size) override;
|
||||
virtual void SetShaderConstantDataTyped(int slotIdx, void* constData, int size, int* typeData, int typeCount) override;
|
||||
virtual void SetShaderConstantData(int usageIdx, int slotIdx, void* constData, int size) override;
|
||||
virtual void SetShaderConstantDataTyped(int usageIdx, int slotIdx, void* constData, int size, int* typeData, int typeCount) override;
|
||||
|
||||
public:
|
||||
DXDrawLayer();
|
||||
|
@ -203,32 +205,40 @@ public:
|
|||
void IndalidateDepthStencilState();
|
||||
|
||||
virtual void SetClipped(bool clipped);
|
||||
virtual void SetTexWrap(bool clipped);
|
||||
virtual void SetClipRect(const Rect& rect);
|
||||
virtual void SetWriteDepthBuffer(bool writeDepthBuffer);
|
||||
virtual void SetDepthFunc(DepthFunc depthFunc);
|
||||
};
|
||||
|
||||
class DXModelMesh
|
||||
class DXModelPrimitives
|
||||
{
|
||||
public:
|
||||
String mMaterialName;
|
||||
int mNumIndices;
|
||||
int mNumVertices;
|
||||
DXTexture* mTexture;
|
||||
Array<DXTexture*> mTextures;
|
||||
|
||||
ID3D11Buffer* mD3DIndexBuffer;
|
||||
//TODO: Split the vertex buffer up into static and dynamic buffers
|
||||
ID3D11Buffer* mD3DVertexBuffer;
|
||||
|
||||
public:
|
||||
DXModelMesh();
|
||||
~DXModelMesh();
|
||||
DXModelPrimitives();
|
||||
~DXModelPrimitives();
|
||||
};
|
||||
|
||||
class DXModelMesh
|
||||
{
|
||||
public:
|
||||
Array<DXModelPrimitives> mPrimitives;
|
||||
};
|
||||
|
||||
class DXModelInstance : public ModelInstance
|
||||
{
|
||||
public:
|
||||
DXRenderDevice* mD3DRenderDevice;
|
||||
std::vector<DXModelMesh> mDXModelMeshs;
|
||||
Array<DXModelMesh> mDXModelMeshs;
|
||||
|
||||
public:
|
||||
DXModelInstance(ModelDef* modelDef);
|
||||
|
@ -274,6 +284,7 @@ public:
|
|||
ID3D11DeviceContext* mD3DDeviceContext;
|
||||
ID3D11BlendState* mD3DNormalBlendState;
|
||||
ID3D11SamplerState* mD3DDefaultSamplerState;
|
||||
ID3D11SamplerState* mD3DWrapSamplerState;
|
||||
bool mHasVSync;
|
||||
|
||||
ID3D11Buffer* mD3DVertexBuffer;
|
||||
|
@ -282,8 +293,10 @@ public:
|
|||
int mIdxByteIdx;
|
||||
|
||||
HashSet<DXRenderState*> mRenderStates;
|
||||
HashSet<DXTexture*> mTextures;
|
||||
|
||||
HashSet<DXTexture*> mTextures;
|
||||
Dictionary<String, DXTexture*> mTextureMap;
|
||||
Dictionary<int, ID3D11Buffer*> mBufferMap;
|
||||
|
||||
public:
|
||||
virtual void PhysSetRenderState(RenderState* renderState) override;
|
||||
virtual void PhysSetRenderWindow(RenderWindow* renderWindow);
|
||||
|
@ -302,6 +315,7 @@ public:
|
|||
void FrameStart() override;
|
||||
void FrameEnd() override;
|
||||
|
||||
Texture* LoadTexture(const StringImpl& fileName, int flags) override;
|
||||
Texture* LoadTexture(ImageData* imageData, int flags) override;
|
||||
Texture* CreateDynTexture(int width, int height) override;
|
||||
Shader* LoadShader(const StringImpl& fileName, VertexDefinition* vertexDefinition) override;
|
||||
|
|
|
@ -2637,6 +2637,9 @@ BFP_EXPORT void BFP_CALLTYPE BfpDirectory_GetSysDirectory(BfpSysDirectoryKind sy
|
|||
case BfpSysDirectoryKind_Programs_Common:
|
||||
_GetKnownFolder(FOLDERID_CommonPrograms);
|
||||
return;
|
||||
case BfpSysDirectoryKind_Documents:
|
||||
_GetKnownFolder(FOLDERID_Documents);
|
||||
return;
|
||||
}
|
||||
|
||||
TryStringOut(path, outPath, inOutPathLen, (BfpResult*)outResult);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue