mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Adding vertex textures WIP.
This commit is contained in:
parent
7bd37979ab
commit
478449e23a
6 changed files with 59 additions and 26 deletions
|
@ -293,9 +293,10 @@ typedef struct bgfx_caps
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supported texture formats.
|
* Supported texture formats.
|
||||||
* 0 - not supported
|
* `BGFX_CAPS_FORMAT_TEXTURE_NONE` - not supported
|
||||||
* 1 - supported
|
* `BGFX_CAPS_FORMAT_TEXTURE_COLOR` - supported
|
||||||
* 2 - emulated
|
* `BGFX_CAPS_FORMAT_TEXTURE_EMULATED` - emulated
|
||||||
|
* `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - supported vertex texture
|
||||||
*/
|
*/
|
||||||
uint8_t formats[BGFX_TEXTURE_FORMAT_COUNT];
|
uint8_t formats[BGFX_TEXTURE_FORMAT_COUNT];
|
||||||
|
|
||||||
|
|
|
@ -315,9 +315,10 @@ namespace bgfx
|
||||||
uint8_t maxFBAttachments; ///< Maximum frame buffer attachments.
|
uint8_t maxFBAttachments; ///< Maximum frame buffer attachments.
|
||||||
|
|
||||||
/// Supported texture formats.
|
/// Supported texture formats.
|
||||||
/// - 0 - not supported
|
/// - `BGFX_CAPS_FORMAT_TEXTURE_NONE` - not supported
|
||||||
/// - 1 - supported
|
/// - `BGFX_CAPS_FORMAT_TEXTURE_COLOR` - supported
|
||||||
/// - 2 - emulated
|
/// - `BGFX_CAPS_FORMAT_TEXTURE_EMULATED` - emulated
|
||||||
|
/// - `BGFX_CAPS_FORMAT_TEXTURE_VERTEX` - supported vertex texture
|
||||||
uint8_t formats[TextureFormat::Count];
|
uint8_t formats[TextureFormat::Count];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -317,6 +317,12 @@
|
||||||
#define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000000400)
|
#define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000000400)
|
||||||
#define BGFX_CAPS_HMD UINT64_C(0x0000000000000800)
|
#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_NONE UINT8_C(0x00)
|
||||||
#define BGFX_VIEW_STEREO UINT8_C(0x01)
|
#define BGFX_VIEW_STEREO UINT8_C(0x01)
|
||||||
|
|
16
src/bgfx.cpp
16
src/bgfx.cpp
|
@ -902,14 +902,18 @@ namespace bgfx
|
||||||
}
|
}
|
||||||
|
|
||||||
BX_TRACE("Supported texture formats:");
|
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)
|
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
|
||||||
{
|
{
|
||||||
if (TextureFormat::Unknown != ii
|
if (TextureFormat::Unknown != ii
|
||||||
&& TextureFormat::UnknownDepth != ii)
|
&& TextureFormat::UnknownDepth != ii)
|
||||||
{
|
{
|
||||||
uint8_t flags = g_caps.formats[ii];
|
uint8_t flags = g_caps.formats[ii];
|
||||||
BX_TRACE("\t[%c] %s"
|
BX_TRACE("\t[%c%c] %s"
|
||||||
, flags&1 ? 'x' : flags&2 ? '*' : ' '
|
, flags&BGFX_CAPS_FORMAT_TEXTURE_COLOR ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_EMULATED ? '*' : ' '
|
||||||
|
, flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' '
|
||||||
, getName(TextureFormat::Enum(ii) )
|
, getName(TextureFormat::Enum(ii) )
|
||||||
);
|
);
|
||||||
BX_UNUSED(flags);
|
BX_UNUSED(flags);
|
||||||
|
@ -938,11 +942,11 @@ namespace bgfx
|
||||||
{
|
{
|
||||||
BX_CHECK(!m_rendererInitialized, "Already initialized?");
|
BX_CHECK(!m_rendererInitialized, "Already initialized?");
|
||||||
|
|
||||||
m_exit = false;
|
m_exit = false;
|
||||||
m_frames = 0;
|
m_frames = 0;
|
||||||
m_render = &m_frame[0];
|
m_render = &m_frame[0];
|
||||||
m_submit = &m_frame[1];
|
m_submit = &m_frame[1];
|
||||||
m_debug = BGFX_DEBUG_NONE;
|
m_debug = BGFX_DEBUG_NONE;
|
||||||
|
|
||||||
m_submit->create();
|
m_submit->create();
|
||||||
m_render->create();
|
m_render->create();
|
||||||
|
@ -1002,9 +1006,9 @@ namespace bgfx
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < BX_COUNTOF(s_emulatedFormats); ++ii)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1786,6 +1786,9 @@ namespace bgfx
|
||||||
|
|
||||||
void commitTextureStage()
|
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->PSSetShaderResources(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_srv);
|
||||||
m_deviceCtx->PSSetSamplers(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_sampler);
|
m_deviceCtx->PSSetSamplers(0, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, m_textureStage.m_sampler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -498,13 +498,23 @@ namespace bgfx
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
|
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
|
, m_deviceType
|
||||||
, adapterFormat
|
, adapterFormat
|
||||||
, 0
|
, 0
|
||||||
, D3DRTYPE_TEXTURE
|
, D3DRTYPE_TEXTURE
|
||||||
, s_textureFormat[ii].m_fmt
|
, 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)
|
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);
|
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;
|
IDirect3DDevice9* device = m_device;
|
||||||
D3DTEXTUREADDRESS tau = s_textureAddress[(_flags&BGFX_TEXTURE_U_MASK)>>BGFX_TEXTURE_U_SHIFT];
|
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];
|
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 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 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];
|
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) );
|
DWORD stage = (_vertex ? D3DVERTEXTEXTURESAMPLER0 : 0) + _stage;
|
||||||
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_ADDRESSW, taw) );
|
|
||||||
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_MINFILTER, minFilter) );
|
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_ADDRESSU, tau) );
|
||||||
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_MAGFILTER, magFilter) );
|
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_ADDRESSV, tav) );
|
||||||
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_MIPFILTER, mipFilter) );
|
DX_CHECK(device->SetSamplerState(stage, D3DSAMP_ADDRESSW, taw) );
|
||||||
DX_CHECK(device->SetSamplerState(_stage, D3DSAMP_MAXANISOTROPY, m_maxAnisotropy) );
|
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;
|
UniformRegistry m_uniformReg;
|
||||||
void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS];
|
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;
|
TextureD3D9* m_updateTexture;
|
||||||
uint8_t* m_updateTextureBits;
|
uint8_t* m_updateTextureBits;
|
||||||
|
@ -2514,6 +2529,9 @@ namespace bgfx
|
||||||
{
|
{
|
||||||
s_renderD3D9->setSamplerState(_stage, 0 == (BGFX_SAMPLER_DEFAULT_FLAGS & _flags) ? _flags : m_flags);
|
s_renderD3D9->setSamplerState(_stage, 0 == (BGFX_SAMPLER_DEFAULT_FLAGS & _flags) ? _flags : m_flags);
|
||||||
DX_CHECK(s_renderD3D9->m_device->SetTexture(_stage, m_ptr) );
|
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
|
void TextureD3D9::resolve() const
|
||||||
|
|
Loading…
Reference in a new issue