mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-10-26 10:45:27 +00:00
Added explicit texture mip count, and per-binding sampler LOD clamp. (#4002)
This commit is contained in:
+27
-12
@@ -4098,12 +4098,12 @@ namespace bgfx { namespace gl
|
||||
{
|
||||
FrameBufferGL& frameBuffer = m_frameBuffers[m_fbh.idx];
|
||||
|
||||
m_glctx.makeCurrent(UINT16_MAX != frameBuffer.m_denseIdx
|
||||
? frameBuffer.m_swapChain
|
||||
: NULL
|
||||
);
|
||||
if (UINT16_MAX == frameBuffer.m_denseIdx)
|
||||
{
|
||||
m_glctx.makeCurrent(NULL);
|
||||
frameBuffer.resolve();
|
||||
}
|
||||
|
||||
frameBuffer.resolve();
|
||||
m_rtMsaa = false;
|
||||
}
|
||||
}
|
||||
@@ -4491,7 +4491,7 @@ namespace bgfx { namespace gl
|
||||
m_textureViewStateCache.invalidate();
|
||||
}
|
||||
|
||||
void setSamplerState(uint32_t _stage, uint32_t _numMips, uint32_t _flags, const float _rgba[4])
|
||||
void setSamplerState(uint32_t _stage, uint32_t _numMips, uint32_t _flags, const float _rgba[4], uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX)
|
||||
{
|
||||
BX_ASSERT(m_samplerObjectSupport, "Cannot use Sampler Objects");
|
||||
|
||||
@@ -4505,6 +4505,8 @@ namespace bgfx { namespace gl
|
||||
_flags |= srgb;
|
||||
_flags |= _numMips<<BGFX_SAMPLER_RESERVED_SHIFT;
|
||||
|
||||
const uint16_t lod = uint16_t( (uint16_t(_lodMin) << 8) | _lodMax);
|
||||
|
||||
GLuint sampler;
|
||||
|
||||
bool hasBorderColor = false;
|
||||
@@ -4513,6 +4515,7 @@ namespace bgfx { namespace gl
|
||||
|
||||
murmur.begin();
|
||||
murmur.add(_flags);
|
||||
murmur.add(lod);
|
||||
if (!needBorderColor(_flags) )
|
||||
{
|
||||
murmur.add(-1);
|
||||
@@ -4564,6 +4567,9 @@ namespace bgfx { namespace gl
|
||||
GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_LOD_BIAS, float(BGFX_CONFIG_MIP_LOD_BIAS) ) );
|
||||
}
|
||||
|
||||
GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_MIN_LOD, float(_lodMin) * 0.25f) );
|
||||
GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_MAX_LOD, UINT8_MAX == _lodMax ? 1000.0f : float(_lodMax) * 0.25f) );
|
||||
|
||||
if (m_borderColorSupport
|
||||
&& hasBorderColor)
|
||||
{
|
||||
@@ -6762,7 +6768,7 @@ namespace bgfx { namespace gl
|
||||
}
|
||||
}
|
||||
|
||||
void TextureGL::setSamplerState(uint32_t _flags, const float _rgba[4])
|
||||
void TextureGL::setSamplerState(uint32_t _flags, const float _rgba[4], uint8_t _lodMin, uint8_t _lodMax)
|
||||
{
|
||||
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
|
||||
&& !s_textureFilter[m_textureFormat])
|
||||
@@ -6781,11 +6787,13 @@ namespace bgfx { namespace gl
|
||||
}
|
||||
|
||||
const uint32_t flags = (0 != (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) ? m_flags : _flags) & (BGFX_SAMPLER_BITS_MASK|BGFX_SAMPLER_SRGB);
|
||||
const uint16_t lod = uint16_t( (uint16_t(_lodMin) << 8) | _lodMax);
|
||||
|
||||
bool hasBorderColor = false;
|
||||
bx::HashMurmur2A murmur;
|
||||
murmur.begin();
|
||||
murmur.add(flags);
|
||||
murmur.add(lod);
|
||||
if (NULL != _rgba)
|
||||
{
|
||||
if (BGFX_SAMPLER_U_BORDER == (flags & BGFX_SAMPLER_U_BORDER)
|
||||
@@ -6829,6 +6837,13 @@ namespace bgfx { namespace gl
|
||||
GL_CHECK(glTexParameterf(target, GL_TEXTURE_LOD_BIAS, float(BGFX_CONFIG_MIP_LOD_BIAS) ) );
|
||||
}
|
||||
|
||||
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL)
|
||||
|| BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) )
|
||||
{
|
||||
GL_CHECK(glTexParameterf(target, GL_TEXTURE_MIN_LOD, float(_lodMin) * 0.25f) );
|
||||
GL_CHECK(glTexParameterf(target, GL_TEXTURE_MAX_LOD, UINT8_MAX == _lodMax ? 1000.0f : float(_lodMax) * 0.25f) );
|
||||
}
|
||||
|
||||
if (s_renderGL->m_borderColorSupport
|
||||
&& hasBorderColor)
|
||||
{
|
||||
@@ -6978,7 +6993,7 @@ namespace bgfx { namespace gl
|
||||
return viewId;
|
||||
}
|
||||
|
||||
void TextureGL::commit(uint32_t _stage, uint32_t _flags, const float _palette[][4], uint8_t _firstMip, uint8_t _numMips, uint16_t _firstLayer, uint16_t _numLayers)
|
||||
void TextureGL::commit(uint32_t _stage, uint32_t _flags, const float _palette[][4], uint8_t _firstMip, uint8_t _numMips, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _lodMin, uint8_t _lodMax)
|
||||
{
|
||||
const uint32_t flags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags)
|
||||
? _flags
|
||||
@@ -7016,11 +7031,11 @@ namespace bgfx { namespace gl
|
||||
|
||||
if (s_renderGL->m_samplerObjectSupport)
|
||||
{
|
||||
s_renderGL->setSamplerState(_stage, m_numMips, samplerFlags, _palette[index]);
|
||||
s_renderGL->setSamplerState(_stage, m_numMips, samplerFlags, _palette[index], _lodMin, _lodMax);
|
||||
}
|
||||
else
|
||||
{
|
||||
setSamplerState(samplerFlags, _palette[index]);
|
||||
setSamplerState(samplerFlags, _palette[index], _lodMin, _lodMax);
|
||||
}
|
||||
|
||||
if (id == m_id
|
||||
@@ -8945,7 +8960,7 @@ namespace bgfx { namespace gl
|
||||
case Binding::Texture:
|
||||
{
|
||||
TextureGL& texture = m_textures[bind.m_idx];
|
||||
texture.commit(ii, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstMip, bind.m_numMips, bind.m_firstLayer, bind.m_numLayers);
|
||||
texture.commit(ii, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstMip, bind.m_numMips, bind.m_firstLayer, bind.m_numLayers, bind.m_lod.min, bind.m_lod.max);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -9622,7 +9637,7 @@ namespace bgfx { namespace gl
|
||||
case Binding::Texture:
|
||||
{
|
||||
TextureGL& texture = m_textures[bind.m_idx];
|
||||
texture.commit(stage, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstMip, bind.m_numMips, bind.m_firstLayer, bind.m_numLayers);
|
||||
texture.commit(stage, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstMip, bind.m_numMips, bind.m_firstLayer, bind.m_numLayers, bind.m_lod.min, bind.m_lod.max);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user