diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index 1e3295d74..464b5846d 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -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]); diff --git a/include/bgfx.h b/include/bgfx.h index 852e97301..3c3541e4a 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -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) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index ecb85250f..6cf8b8813 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -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" diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index cb89a94b9..05ee5716d 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -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) { diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 38d164073..3ece50b99 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -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; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index f2e8d0f9b..da66578d3 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -896,7 +896,9 @@ namespace bgfx { if (0 == (BGFX_SAMPLER_DEFAULT_FLAGS & _flags) ) { - _flags = (_flags&(~BGFX_TEXTURE_RESERVED_MASK) ) | (_numMips<