Adding vertex textures WIP.

This commit is contained in:
Branimir Karadžić 2015-03-01 22:01:30 -08:00
parent 7bd37979ab
commit 478449e23a
6 changed files with 59 additions and 26 deletions

View File

@ -293,9 +293,10 @@ typedef struct bgfx_caps
/**
* Supported texture formats.
* 0 - not supported
* 1 - supported
* 2 - emulated
* `BGFX_CAPS_FORMAT_TEXTURE_NONE` - not supported
* `BGFX_CAPS_FORMAT_TEXTURE_COLOR` - supported
* `BGFX_CAPS_FORMAT_TEXTURE_EMULATED` - emulated
* `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - supported vertex texture
*/
uint8_t formats[BGFX_TEXTURE_FORMAT_COUNT];

View File

@ -315,9 +315,10 @@ namespace bgfx
uint8_t maxFBAttachments; ///< Maximum frame buffer attachments.
/// Supported texture formats.
/// - 0 - not supported
/// - 1 - supported
/// - 2 - emulated
/// - `BGFX_CAPS_FORMAT_TEXTURE_NONE` - not supported
/// - `BGFX_CAPS_FORMAT_TEXTURE_COLOR` - supported
/// - `BGFX_CAPS_FORMAT_TEXTURE_EMULATED` - emulated
/// - `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - supported vertex texture
uint8_t formats[TextureFormat::Count];
};

View File

@ -317,6 +317,12 @@
#define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000000400)
#define BGFX_CAPS_HMD UINT64_C(0x0000000000000800)
///
#define BGFX_CAPS_FORMAT_TEXTURE_NONE UINT8_C(0x00)
#define BGFX_CAPS_FORMAT_TEXTURE_COLOR UINT8_C(0x01)
#define BGFX_CAPS_FORMAT_TEXTURE_EMULATED UINT8_C(0x02)
#define BGFX_CAPS_FORMAT_TEXTURE_VERTEX UINT8_C(0x04)
///
#define BGFX_VIEW_NONE UINT8_C(0x00)
#define BGFX_VIEW_STEREO UINT8_C(0x01)

View File

@ -902,14 +902,18 @@ namespace bgfx
}
BX_TRACE("Supported texture formats:");
BX_TRACE("\t +------ x = supported / * = emulated");
BX_TRACE("\t |+----- vertex format");
BX_TRACE("\t || +-- name");
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
{
if (TextureFormat::Unknown != ii
&& TextureFormat::UnknownDepth != ii)
{
uint8_t flags = g_caps.formats[ii];
BX_TRACE("\t[%c] %s"
, flags&1 ? 'x' : flags&2 ? '*' : ' '
BX_TRACE("\t[%c%c] %s"
, flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_EMULATED ? '*' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' '
, getName(TextureFormat::Enum(ii) )
);
BX_UNUSED(flags);
@ -938,11 +942,11 @@ namespace bgfx
{
BX_CHECK(!m_rendererInitialized, "Already initialized?");
m_exit = false;
m_exit = false;
m_frames = 0;
m_render = &m_frame[0];
m_submit = &m_frame[1];
m_debug = BGFX_DEBUG_NONE;
m_debug = BGFX_DEBUG_NONE;
m_submit->create();
m_render->create();
@ -1002,9 +1006,9 @@ namespace bgfx
for (uint32_t ii = 0; ii < BX_COUNTOF(s_emulatedFormats); ++ii)
{
if (0 == g_caps.formats[s_emulatedFormats[ii] ])
if (0 == (g_caps.formats[s_emulatedFormats[ii] ] & BGFX_CAPS_FORMAT_TEXTURE_COLOR) )
{
g_caps.formats[s_emulatedFormats[ii] ] = 2;
g_caps.formats[s_emulatedFormats[ii] ] |= BGFX_CAPS_FORMAT_TEXTURE_EMULATED;
}
}

View File

@ -1786,6 +1786,9 @@ namespace bgfx
void commitTextureStage()
{
m_deviceCtx->VSSetShaderResources(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_srv);
m_deviceCtx->VSSetSamplers(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_sampler);
m_deviceCtx->PSSetShaderResources(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_srv);
m_deviceCtx->PSSetSamplers(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_sampler);
}

View File

@ -498,13 +498,23 @@ namespace bgfx
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
{
g_caps.formats[ii] = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
uint8_t support = SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
, m_deviceType
, adapterFormat
, 0
, D3DRTYPE_TEXTURE
, s_textureFormat[ii].m_fmt
) ) ? 1 : 0;
) ) ? BGFX_CAPS_FORMAT_TEXTURE_COLOR : BGFX_CAPS_FORMAT_TEXTURE_NONE;
support |= SUCCEEDED(m_d3d9->CheckDeviceFormat(m_adapter
, m_deviceType
, adapterFormat
, D3DUSAGE_QUERY_VERTEXTEXTURE
, D3DRTYPE_TEXTURE
, s_textureFormat[ii].m_fmt
) ) ? BGFX_CAPS_FORMAT_TEXTURE_VERTEX : BGFX_CAPS_FORMAT_TEXTURE_NONE;
g_caps.formats[ii] = support;
}
}
@ -1236,16 +1246,18 @@ namespace bgfx
{
for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage)
{
m_samplerFlags[stage] = UINT32_MAX;
m_samplerFlags[stage][0] = UINT32_MAX;
m_samplerFlags[stage][1] = UINT32_MAX;
}
}
void setSamplerState(uint8_t _stage, uint32_t _flags)
void setSamplerState(uint8_t _stage, uint32_t _flags, bool _vertex = false)
{
const uint32_t flags = _flags&( (~BGFX_TEXTURE_RESERVED_MASK) | BGFX_TEXTURE_SAMPLER_BITS_MASK);
if (m_samplerFlags[_stage] != flags)
BX_CHECK(_stage < BX_COUNTOF(m_samplerFlags), "");
if (m_samplerFlags[_stage][_vertex] != flags)
{
m_samplerFlags[_stage] = flags;
m_samplerFlags[_stage][_vertex] = flags;
IDirect3DDevice9* device = m_device;
D3DTEXTUREADDRESS tau = s_textureAddress[(_flags&BGFX_TEXTURE_U_MASK)>>BGFX_TEXTURE_U_SHIFT];
D3DTEXTUREADDRESS tav = s_textureAddress[(_flags&BGFX_TEXTURE_V_MASK)>>BGFX_TEXTURE_V_SHIFT];
@ -1253,13 +1265,16 @@ namespace bgfx
D3DTEXTUREFILTERTYPE minFilter = s_textureFilter[(_flags&BGFX_TEXTURE_MIN_MASK)>>BGFX_TEXTURE_MIN_SHIFT];
D3DTEXTUREFILTERTYPE magFilter = s_textureFilter[(_flags&BGFX_TEXTURE_MAG_MASK)>>BGFX_TEXTURE_MAG_SHIFT];
D3DTEXTUREFILTERTYPE mipFilter = s_textureFilter[(_flags&BGFX_TEXTURE_MIP_MASK)>>BGFX_TEXTURE_MIP_SHIFT];
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_ADDRESSU, tau) );
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_ADDRESSV, tav) );
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_ADDRESSW, taw) );
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_MINFILTER, minFilter) );
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_MAGFILTER, magFilter) );
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_MIPFILTER, mipFilter) );
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_MAXANISOTROPY, m_maxAnisotropy) );
DWORD stage = (_vertex ? D3DVERTEXTEXTURESAMPLER0 : 0) + _stage;
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_ADDRESSU, tau) );
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_ADDRESSV, tav) );
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_ADDRESSW, taw) );
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_MINFILTER, minFilter) );
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_MAGFILTER, magFilter) );
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_MIPFILTER, mipFilter) );
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_MAXANISOTROPY, m_maxAnisotropy) );
}
}
@ -1699,7 +1714,7 @@ namespace bgfx
UniformRegistry m_uniformReg;
void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS];
uint32_t m_samplerFlags[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
uint32_t m_samplerFlags[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS][1];
TextureD3D9* m_updateTexture;
uint8_t* m_updateTextureBits;
@ -2514,6 +2529,9 @@ namespace bgfx
{
s_renderD3D9->setSamplerState(_stage, 0 == (BGFX_SAMPLER_DEFAULT_FLAGS & _flags) ? _flags : m_flags);
DX_CHECK(s_renderD3D9->m_device->SetTexture(_stage, m_ptr) );
// s_renderD3D9->setSamplerState(_stage, 0 == (BGFX_SAMPLER_DEFAULT_FLAGS & _flags) ? _flags : m_flags, true);
// DX_CHECK(s_renderD3D9->m_device->SetTexture(D3DVERTEXTEXTURESAMPLER0 + _stage, m_ptr) );
}
void TextureD3D9::resolve() const