Fixed GL texture sampler state. Issue#85
This commit is contained in:
parent
efc6516a00
commit
ea34b9476c
@ -27,7 +27,7 @@ struct PosColorVertex
|
||||
|
||||
static bgfx::VertexDecl s_PosTexcoordDecl;
|
||||
|
||||
static PosColorVertex s_cubeVertices[24] =
|
||||
static PosColorVertex s_cubeVertices[28] =
|
||||
{
|
||||
{-1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f },
|
||||
@ -58,27 +58,35 @@ static PosColorVertex s_cubeVertices[24] =
|
||||
{-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f },
|
||||
{ 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f },
|
||||
{ 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f },
|
||||
|
||||
{-1.0f, 1.0f, 1.0f, -2.0f, 2.0f, 2.0f },
|
||||
{ 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f },
|
||||
{-1.0f, -1.0f, 1.0f, -2.0f, -2.0f, 2.0f },
|
||||
{ 1.0f, -1.0f, 1.0f, 2.0f, -2.0f, 2.0f },
|
||||
};
|
||||
|
||||
static const uint16_t s_cubeIndices[36] =
|
||||
static const uint16_t s_cubeIndices[42] =
|
||||
{
|
||||
0, 1, 2, // 0
|
||||
1, 3, 2,
|
||||
|
||||
|
||||
4, 6, 5, // 2
|
||||
5, 6, 7,
|
||||
|
||||
|
||||
8, 10, 9, // 4
|
||||
9, 10, 11,
|
||||
|
||||
|
||||
12, 14, 13, // 6
|
||||
14, 15, 13,
|
||||
|
||||
|
||||
16, 18, 17, // 8
|
||||
18, 19, 17,
|
||||
|
||||
|
||||
20, 22, 21, // 10
|
||||
21, 22, 23,
|
||||
|
||||
24, 25, 26, //
|
||||
25, 27, 26,
|
||||
};
|
||||
|
||||
static const char* s_shaderPath = NULL;
|
||||
@ -224,9 +232,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
||||
|
||||
bgfx::TextureHandle textures[] =
|
||||
{
|
||||
bgfx::createTexture(loadTexture("texture_compression_bc1.dds") ),
|
||||
bgfx::createTexture(loadTexture("texture_compression_bc2.dds") ),
|
||||
bgfx::createTexture(loadTexture("texture_compression_bc3.dds") ),
|
||||
bgfx::createTexture(loadTexture("texture_compression_bc1.dds"), BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP),
|
||||
bgfx::createTexture(loadTexture("texture_compression_bc2.dds"), BGFX_TEXTURE_U_CLAMP),
|
||||
bgfx::createTexture(loadTexture("texture_compression_bc3.dds"), BGFX_TEXTURE_V_CLAMP),
|
||||
bgfx::createTexture(loadTexture("texture_compression_etc1.ktx") ),
|
||||
bgfx::createTexture(loadTexture("texture_compression_etc2.ktx") ),
|
||||
bgfx::createTexture(loadTexture("texture_compression_ptc12.pvr") ),
|
||||
@ -447,7 +455,31 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
||||
|
||||
// Set vertex and index buffer.
|
||||
bgfx::setVertexBuffer(vbh);
|
||||
bgfx::setIndexBuffer(ibh);
|
||||
bgfx::setIndexBuffer(ibh, 0, 6);
|
||||
|
||||
// Bind texture.
|
||||
bgfx::setTexture(0, u_texColor, textures[ii]);
|
||||
|
||||
// Set render states.
|
||||
bgfx::setState(BGFX_STATE_DEFAULT);
|
||||
|
||||
// Submit primitive for rendering to view 0.
|
||||
bgfx::submit(1);
|
||||
}
|
||||
|
||||
for (uint32_t ii = 0; ii < 3; ++ii)
|
||||
{
|
||||
mtxTranslate(mtx, -8.0f - BX_COUNTOF(textures)*0.1f*0.5f + 8*2.1f, -4.0f + ii*2.1f, 0.0f);
|
||||
|
||||
// Set model matrix for rendering.
|
||||
bgfx::setTransform(mtx);
|
||||
|
||||
// Set vertex and fragment shaders.
|
||||
bgfx::setProgram(programCmp);
|
||||
|
||||
// Set vertex and index buffer.
|
||||
bgfx::setVertexBuffer(vbh);
|
||||
bgfx::setIndexBuffer(ibh, 36, 6);
|
||||
|
||||
// Bind texture.
|
||||
bgfx::setTexture(0, u_texColor, textures[ii]);
|
||||
|
@ -241,6 +241,16 @@
|
||||
#define BGFX_TEXTURE_RESERVED_SHIFT 24
|
||||
#define BGFX_TEXTURE_RESERVED_MASK UINT32_C(0xff000000)
|
||||
|
||||
#define BGFX_TEXTURE_SAMPLER_BITS_MASK (0 \
|
||||
| BGFX_TEXTURE_U_MASK \
|
||||
| BGFX_TEXTURE_V_MASK \
|
||||
| BGFX_TEXTURE_W_MASK \
|
||||
| BGFX_TEXTURE_MIN_MASK \
|
||||
| BGFX_TEXTURE_MAG_MASK \
|
||||
| BGFX_TEXTURE_MIP_MASK \
|
||||
| BGFX_TEXTURE_COMPARE_MASK \
|
||||
)
|
||||
|
||||
///
|
||||
#define BGFX_RESET_NONE UINT32_C(0x00000000)
|
||||
#define BGFX_RESET_FULLSCREEN UINT32_C(0x00000001)
|
||||
|
@ -137,7 +137,7 @@ namespace stl
|
||||
#define BGFX_STATE_TEX_MASK UINT64_C(0xff00000000000000)
|
||||
#define BGFX_STATE_TEX_COUNT 8
|
||||
|
||||
#define BGFX_SAMPLER_DEFAULT_FLAGS UINT32_C(0x10000000)
|
||||
#define BGFX_SAMPLER_DEFAULT_FLAGS UINT32_C(0x10000000)
|
||||
|
||||
#if BGFX_CONFIG_RENDERER_DIRECT3D9
|
||||
# define BGFX_RENDERER_NAME "Direct3D 9"
|
||||
|
@ -1059,11 +1059,7 @@ namespace bgfx
|
||||
|
||||
ID3D11SamplerState* getSamplerState(uint32_t _flags)
|
||||
{
|
||||
_flags &= BGFX_TEXTURE_MIN_MASK|BGFX_TEXTURE_MAG_MASK|BGFX_TEXTURE_MIP_MASK
|
||||
| BGFX_TEXTURE_U_MASK|BGFX_TEXTURE_V_MASK|BGFX_TEXTURE_W_MASK
|
||||
| BGFX_TEXTURE_COMPARE_MASK
|
||||
;
|
||||
|
||||
_flags &= BGFX_TEXTURE_SAMPLER_BITS_MASK;
|
||||
ID3D11SamplerState* sampler = m_samplerStateCache.find(_flags);
|
||||
if (NULL == sampler)
|
||||
{
|
||||
|
@ -830,7 +830,7 @@ namespace bgfx
|
||||
|
||||
void setSamplerState(uint8_t _stage, uint32_t _flags)
|
||||
{
|
||||
const uint32_t flags = _flags&(~BGFX_TEXTURE_RESERVED_MASK);
|
||||
const uint32_t flags = _flags&( (~BGFX_TEXTURE_RESERVED_MASK) | BGFX_TEXTURE_SAMPLER_BITS_MASK);
|
||||
if (m_samplerFlags[_stage] != flags)
|
||||
{
|
||||
m_samplerFlags[_stage] = flags;
|
||||
|
@ -896,7 +896,9 @@ namespace bgfx
|
||||
{
|
||||
if (0 == (BGFX_SAMPLER_DEFAULT_FLAGS & _flags) )
|
||||
{
|
||||
_flags = (_flags&(~BGFX_TEXTURE_RESERVED_MASK) ) | (_numMips<<BGFX_TEXTURE_RESERVED_SHIFT);
|
||||
_flags &= ~BGFX_TEXTURE_RESERVED_MASK;
|
||||
_flags &= BGFX_TEXTURE_SAMPLER_BITS_MASK;
|
||||
_flags |= _numMips<<BGFX_TEXTURE_RESERVED_SHIFT;
|
||||
GLuint sampler = m_samplerStateCache.find(_flags);
|
||||
|
||||
if (UINT32_MAX == sampler)
|
||||
@ -2403,9 +2405,8 @@ namespace bgfx
|
||||
|
||||
void Texture::setSamplerState(uint32_t _flags)
|
||||
{
|
||||
const uint32_t flags = _flags&(~BGFX_TEXTURE_RESERVED_MASK);
|
||||
if ( (0 != (BGFX_SAMPLER_DEFAULT_FLAGS & _flags) && m_flags != m_currentFlags)
|
||||
|| m_currentFlags != flags)
|
||||
const uint32_t flags = (0 != (BGFX_SAMPLER_DEFAULT_FLAGS & _flags) ? m_flags : _flags) & BGFX_TEXTURE_SAMPLER_BITS_MASK;
|
||||
if (flags != m_currentFlags)
|
||||
{
|
||||
const GLenum target = m_target;
|
||||
const uint8_t numMips = m_numMips;
|
||||
|
Loading…
Reference in New Issue
Block a user