summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/src/renderer_d3d9.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/src/renderer_d3d9.cpp')
-rw-r--r--3rdparty/bgfx/src/renderer_d3d9.cpp69
1 files changed, 49 insertions, 20 deletions
diff --git a/3rdparty/bgfx/src/renderer_d3d9.cpp b/3rdparty/bgfx/src/renderer_d3d9.cpp
index 970485bb5d1..faf5f98ac39 100644
--- a/3rdparty/bgfx/src/renderer_d3d9.cpp
+++ b/3rdparty/bgfx/src/renderer_d3d9.cpp
@@ -219,7 +219,7 @@ namespace bgfx { namespace d3d9
{ D3DFMT_UNKNOWN }, // RG32
{ D3DFMT_G32R32F }, // RG32F
{ D3DFMT_A8R8G8B8 }, // BGRA8
- { D3DFMT_A8R8G8B8 }, // RGBA8
+ { D3DFMT_UNKNOWN }, // RGBA8
{ D3DFMT_A16B16G16R16 }, // RGBA16
{ D3DFMT_A16B16G16R16F }, // RGBA16F
{ D3DFMT_UNKNOWN }, // RGBA32
@@ -462,6 +462,7 @@ namespace bgfx { namespace d3d9
BX_TRACE("Max fragment shader 2.0 instr. slots: %d", m_caps.PS20Caps.NumInstructionSlots);
BX_TRACE("Max fragment shader 3.0 instr. slots: %d", m_caps.MaxPixelShader30InstructionSlots);
BX_TRACE("Num simultaneous render targets: %d", m_caps.NumSimultaneousRTs);
+ BX_TRACE("Max vertex index: %d", m_caps.MaxVertexIndex);
g_caps.supported |= ( 0
| BGFX_CAPS_TEXTURE_3D
@@ -469,8 +470,10 @@ namespace bgfx { namespace d3d9
| BGFX_CAPS_VERTEX_ATTRIB_HALF
| BGFX_CAPS_FRAGMENT_DEPTH
| BGFX_CAPS_SWAP_CHAIN
+ | ( (UINT16_MAX < m_caps.MaxVertexIndex) ? BGFX_CAPS_INDEX32 : 0)
);
g_caps.maxTextureSize = uint16_t(bx::uint32_min(m_caps.MaxTextureWidth, m_caps.MaxTextureHeight) );
+// g_caps.maxVertexIndex = m_caps.MaxVertexIndex;
m_caps.NumSimultaneousRTs = uint8_t(bx::uint32_min(m_caps.NumSimultaneousRTs, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) );
g_caps.maxFBAttachments = uint8_t(m_caps.NumSimultaneousRTs);
@@ -668,9 +671,9 @@ namespace bgfx { namespace d3d9
return BGFX_RENDERER_DIRECT3D9_NAME;
}
- void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint8_t /*_flags*/) BX_OVERRIDE
+ void createIndexBuffer(IndexBufferHandle _handle, Memory* _mem, uint8_t _flags) BX_OVERRIDE
{
- m_indexBuffers[_handle.idx].create(_mem->size, _mem->data);
+ m_indexBuffers[_handle.idx].create(_mem->size, _mem->data, _flags);
}
void destroyIndexBuffer(IndexBufferHandle _handle) BX_OVERRIDE
@@ -698,9 +701,9 @@ namespace bgfx { namespace d3d9
m_vertexBuffers[_handle.idx].destroy();
}
- void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint8_t /*_flags*/) BX_OVERRIDE
+ void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint8_t _flags) BX_OVERRIDE
{
- m_indexBuffers[_handle.idx].create(_size, NULL);
+ m_indexBuffers[_handle.idx].create(_size, NULL, _flags);
}
void updateDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _offset, uint32_t _size, Memory* _mem) BX_OVERRIDE
@@ -771,6 +774,13 @@ namespace bgfx { namespace d3d9
m_updateTexture = NULL;
}
+ void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) BX_OVERRIDE
+ {
+ TextureD3D9& texture = m_textures[_handle.idx];
+ texture.m_width = _width;
+ texture.m_height = _height;
+ }
+
void destroyTexture(TextureHandle _handle) BX_OVERRIDE
{
m_textures[_handle.idx].destroy();
@@ -941,7 +951,7 @@ namespace bgfx { namespace d3d9
DX_CHECK(device->SetIndices(ib.m_ptr) );
float proj[16];
- mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f);
+ bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f);
PredefinedUniform& predefined = program.m_predefined[0];
uint8_t flags = predefined.m_type;
@@ -1134,7 +1144,7 @@ namespace bgfx { namespace d3d9
;
}
- void flip() BX_OVERRIDE
+ void flip(HMD& /*_hmd*/) BX_OVERRIDE
{
if (NULL != m_device)
{
@@ -1762,13 +1772,14 @@ namespace bgfx { namespace d3d9
s_renderD3D9 = NULL;
}
- void IndexBufferD3D9::create(uint32_t _size, void* _data)
+ void IndexBufferD3D9::create(uint32_t _size, void* _data, uint8_t _flags)
{
- m_size = _size;
+ m_size = _size;
+ m_flags = _flags;
m_dynamic = NULL == _data;
uint32_t usage = D3DUSAGE_WRITEONLY;
- D3DPOOL pool = s_renderD3D9->m_pool;
+ D3DPOOL pool = s_renderD3D9->m_pool;
if (m_dynamic)
{
@@ -1776,9 +1787,14 @@ namespace bgfx { namespace d3d9
pool = D3DPOOL_DEFAULT;
}
+ const D3DFORMAT format = 0 == (_flags & BGFX_BUFFER_INDEX32)
+ ? D3DFMT_INDEX16
+ : D3DFMT_INDEX32
+ ;
+
DX_CHECK(s_renderD3D9->m_device->CreateIndexBuffer(m_size
, usage
- , D3DFMT_INDEX16
+ , format
, pool
, &m_ptr
, NULL
@@ -1802,9 +1818,14 @@ namespace bgfx { namespace d3d9
{
if (m_dynamic)
{
+ const D3DFORMAT format = 0 == (m_flags & BGFX_BUFFER_INDEX32)
+ ? D3DFMT_INDEX16
+ : D3DFMT_INDEX32
+ ;
+
DX_CHECK(s_renderD3D9->m_device->CreateIndexBuffer(m_size
, D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC
- , D3DFMT_INDEX16
+ , format
, D3DPOOL_DEFAULT
, &m_ptr
, NULL
@@ -1949,7 +1970,7 @@ namespace bgfx { namespace d3d9
for (uint8_t ii = 0; ii < _numInstanceData; ++ii)
{
memcpy(elem, &inst, sizeof(D3DVERTEXELEMENT9) );
- elem->UsageIndex = uint8_t(8-_numInstanceData+ii);
+ elem->UsageIndex = uint8_t(7-ii); // TEXCOORD7 = i_data0, TEXCOORD6 = i_data1, etc.
elem->Offset = ii*16;
++elem;
}
@@ -2375,10 +2396,8 @@ namespace bgfx { namespace d3d9
m_textureFormat = imageContainer.m_format;
const TextureFormatInfo& tfi = s_textureFormat[m_requestedFormat];
- const bool convert = D3DFMT_UNKNOWN == tfi.m_fmt;
-
uint8_t bpp = getBitsPerPixel(TextureFormat::Enum(m_textureFormat) );
- if (convert)
+ if (D3DFMT_UNKNOWN == tfi.m_fmt)
{
m_textureFormat = (uint8_t)TextureFormat::BGRA8;
bpp = 32;
@@ -2420,6 +2439,8 @@ namespace bgfx { namespace d3d9
&& imageContainer.m_format != TextureFormat::BC5
;
+ const bool convert = m_textureFormat != m_requestedFormat;
+
for (uint8_t side = 0, numSides = imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side)
{
uint32_t width = textureWidth;
@@ -2452,7 +2473,13 @@ namespace bgfx { namespace d3d9
uint32_t srcpitch = mipWidth*bpp/8;
uint8_t* temp = (uint8_t*)BX_ALLOC(g_allocator, srcpitch*mipHeight);
- imageDecodeToBgra8(temp, mip.m_data, mip.m_width, mip.m_height, srcpitch, mip.m_format);
+ imageDecodeToBgra8(temp
+ , mip.m_data
+ , mip.m_width
+ , mip.m_height
+ , srcpitch
+ , mip.m_format
+ );
uint32_t dstpitch = pitch;
for (uint32_t yy = 0; yy < height; ++yy)
@@ -3325,10 +3352,12 @@ namespace bgfx { namespace d3d9
{
if (UINT32_MAX == draw.m_numIndices)
{
- numIndices = m_indexBuffers[draw.m_indexBuffer.idx].m_size/2;
+ const IndexBufferD3D9& ib = m_indexBuffers[draw.m_indexBuffer.idx];
+ const uint32_t indexSize = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32) ? 2 : 4;
+ numIndices = ib.m_size/indexSize;
numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub;
- numInstances = draw.m_numInstances;
- numPrimsRendered = numPrimsSubmitted*draw.m_numInstances;
+ numInstances = draw.m_numInstances;
+ numPrimsRendered = numPrimsSubmitted*draw.m_numInstances;
DX_CHECK(device->DrawIndexedPrimitive(prim.m_type
, draw.m_startVertex