mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-20 05:43:12 +01:00
Fixed mipmap chain generation for textures created with backbuffer ratio size.
This commit is contained in:
25
src/bgfx.cpp
25
src/bgfx.cpp
@@ -2247,7 +2247,10 @@ namespace bgfx
|
||||
uint16_t height;
|
||||
_cmdbuf.read(height);
|
||||
|
||||
m_renderCtx->resizeTexture(handle, width, height);
|
||||
uint8_t numMips;
|
||||
_cmdbuf.read(numMips);
|
||||
|
||||
m_renderCtx->resizeTexture(handle, width, height, numMips);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2952,7 +2955,14 @@ error:
|
||||
, getName(_format)
|
||||
);
|
||||
|
||||
_numMips = uint8_t(bx::uint32_max(1, _numMips) );
|
||||
if (BackbufferRatio::Count != _ratio)
|
||||
{
|
||||
_width = uint16_t(s_ctx->m_resolution.m_width);
|
||||
_height = uint16_t(s_ctx->m_resolution.m_height);
|
||||
getTextureSizeFromRatio(_ratio, _width, _height);
|
||||
}
|
||||
|
||||
_numMips = calcNumMips(_numMips, _width, _height);
|
||||
|
||||
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
|
||||
&& NULL != _mem)
|
||||
@@ -2966,13 +2976,6 @@ error:
|
||||
);
|
||||
}
|
||||
|
||||
if (BackbufferRatio::Count != _ratio)
|
||||
{
|
||||
_width = uint16_t(s_ctx->m_resolution.m_width);
|
||||
_height = uint16_t(s_ctx->m_resolution.m_height);
|
||||
getTextureSizeFromRatio(_ratio, _width, _height);
|
||||
}
|
||||
|
||||
uint32_t size = sizeof(uint32_t)+sizeof(TextureCreate);
|
||||
const Memory* mem = alloc(size);
|
||||
|
||||
@@ -3015,7 +3018,7 @@ error:
|
||||
, getName(_format)
|
||||
);
|
||||
|
||||
_numMips = uint8_t(bx::uint32_max(1, _numMips) );
|
||||
_numMips = calcNumMips(_numMips, _width, _height, _depth);
|
||||
|
||||
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
|
||||
&& NULL != _mem)
|
||||
@@ -3058,7 +3061,7 @@ error:
|
||||
, getName(_format)
|
||||
);
|
||||
|
||||
_numMips = uint8_t(bx::uint32_max(1, _numMips) );
|
||||
_numMips = calcNumMips(_numMips, _size, _size);
|
||||
|
||||
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
|
||||
&& NULL != _mem)
|
||||
|
||||
22
src/bgfx_p.h
22
src/bgfx_p.h
@@ -364,6 +364,19 @@ namespace bgfx
|
||||
;
|
||||
}
|
||||
|
||||
inline uint8_t calcNumMips(uint8_t _numMips, uint16_t _width, uint16_t _height, uint16_t _depth = 1)
|
||||
{
|
||||
if (1 < _numMips)
|
||||
{
|
||||
const uint32_t max = bx::uint32_max(bx::uint32_max(_width, _height), _depth);
|
||||
const uint32_t num = 1 + uint32_t(bx::flog2(float(max) ) );
|
||||
|
||||
return uint8_t(num);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void dump(const VertexDecl& _decl);
|
||||
|
||||
struct TextVideoMem
|
||||
@@ -2061,7 +2074,7 @@ namespace bgfx
|
||||
virtual void updateTexture(TextureHandle _handle, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) = 0;
|
||||
virtual void updateTextureEnd() = 0;
|
||||
virtual void readTexture(TextureHandle _handle, void* _data) = 0;
|
||||
virtual void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) = 0;
|
||||
virtual void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) = 0;
|
||||
virtual void overrideInternal(TextureHandle _handle, uintptr_t _ptr) = 0;
|
||||
virtual uintptr_t getInternal(TextureHandle _handle) = 0;
|
||||
virtual void destroyTexture(TextureHandle _handle) = 0;
|
||||
@@ -2160,6 +2173,7 @@ namespace bgfx
|
||||
resizeTexture(handle
|
||||
, uint16_t(m_resolution.m_width)
|
||||
, uint16_t(m_resolution.m_height)
|
||||
, textureRef.m_numMips
|
||||
);
|
||||
m_resolution.m_flags |= BGFX_RESET_INTERNAL_FORCE;
|
||||
}
|
||||
@@ -3107,6 +3121,7 @@ namespace bgfx
|
||||
ref.m_refCount = 1;
|
||||
ref.m_bbRatio = uint8_t(_ratio);
|
||||
ref.m_format = uint8_t(_info->format);
|
||||
ref.m_numMips = imageContainer.m_numMips;
|
||||
ref.m_owned = false;
|
||||
|
||||
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateTexture);
|
||||
@@ -3149,12 +3164,13 @@ namespace bgfx
|
||||
return readTexture(textureHandle, _data);
|
||||
}
|
||||
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height)
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips)
|
||||
{
|
||||
const TextureRef& textureRef = m_textureRef[_handle.idx];
|
||||
BX_CHECK(BackbufferRatio::Count != textureRef.m_bbRatio, "");
|
||||
|
||||
getTextureSizeFromRatio(BackbufferRatio::Enum(textureRef.m_bbRatio), _width, _height);
|
||||
_numMips = calcNumMips(_numMips, _width, _height);
|
||||
|
||||
BX_TRACE("Resize %3d: %4dx%d %s"
|
||||
, _handle.idx
|
||||
@@ -3167,6 +3183,7 @@ namespace bgfx
|
||||
cmdbuf.write(_handle);
|
||||
cmdbuf.write(_width);
|
||||
cmdbuf.write(_height);
|
||||
cmdbuf.write(_numMips);
|
||||
}
|
||||
|
||||
void textureTakeOwnership(TextureHandle _handle)
|
||||
@@ -4012,6 +4029,7 @@ namespace bgfx
|
||||
int16_t m_refCount;
|
||||
uint8_t m_bbRatio;
|
||||
uint8_t m_format;
|
||||
uint8_t m_numMips;
|
||||
bool m_owned;
|
||||
};
|
||||
|
||||
|
||||
@@ -1831,7 +1831,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
m_deviceCtx->Unmap(texture.m_ptr, 0);
|
||||
}
|
||||
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) BX_OVERRIDE
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) BX_OVERRIDE
|
||||
{
|
||||
TextureD3D11& texture = m_textures[_handle.idx];
|
||||
|
||||
@@ -1847,7 +1847,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
tc.m_height = _height;
|
||||
tc.m_sides = 0;
|
||||
tc.m_depth = 0;
|
||||
tc.m_numMips = 1;
|
||||
tc.m_numMips = _numMips;
|
||||
tc.m_format = TextureFormat::Enum(texture.m_requestedFormat);
|
||||
tc.m_cubeMap = false;
|
||||
tc.m_mem = NULL;
|
||||
|
||||
@@ -1464,7 +1464,7 @@ namespace bgfx { namespace d3d12
|
||||
DX_RELEASE(readback, 0);
|
||||
}
|
||||
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) BX_OVERRIDE
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) BX_OVERRIDE
|
||||
{
|
||||
TextureD3D12& texture = m_textures[_handle.idx];
|
||||
|
||||
@@ -1480,7 +1480,7 @@ namespace bgfx { namespace d3d12
|
||||
tc.m_height = _height;
|
||||
tc.m_sides = 0;
|
||||
tc.m_depth = 0;
|
||||
tc.m_numMips = 1;
|
||||
tc.m_numMips = _numMips;
|
||||
tc.m_format = TextureFormat::Enum(texture.m_requestedFormat);
|
||||
tc.m_cubeMap = false;
|
||||
tc.m_mem = NULL;
|
||||
|
||||
@@ -1011,7 +1011,7 @@ namespace bgfx { namespace d3d9
|
||||
DX_CHECK(texture.m_texture2d->UnlockRect(0) );
|
||||
}
|
||||
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) BX_OVERRIDE
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) BX_OVERRIDE
|
||||
{
|
||||
TextureD3D9& texture = m_textures[_handle.idx];
|
||||
|
||||
@@ -1027,7 +1027,7 @@ namespace bgfx { namespace d3d9
|
||||
tc.m_height = _height;
|
||||
tc.m_sides = 0;
|
||||
tc.m_depth = 0;
|
||||
tc.m_numMips = 1;
|
||||
tc.m_numMips = _numMips;
|
||||
tc.m_format = TextureFormat::Enum(texture.m_requestedFormat);
|
||||
tc.m_cubeMap = false;
|
||||
tc.m_mem = NULL;
|
||||
|
||||
@@ -2269,7 +2269,7 @@ namespace bgfx { namespace gl
|
||||
}
|
||||
}
|
||||
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) BX_OVERRIDE
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) BX_OVERRIDE
|
||||
{
|
||||
TextureGL& texture = m_textures[_handle.idx];
|
||||
|
||||
@@ -2285,7 +2285,7 @@ namespace bgfx { namespace gl
|
||||
tc.m_height = _height;
|
||||
tc.m_sides = 0;
|
||||
tc.m_depth = 0;
|
||||
tc.m_numMips = 1;
|
||||
tc.m_numMips = _numMips;
|
||||
tc.m_format = TextureFormat::Enum(texture.m_requestedFormat);
|
||||
tc.m_cubeMap = false;
|
||||
tc.m_mem = NULL;
|
||||
|
||||
@@ -772,7 +772,7 @@ namespace bgfx { namespace mtl
|
||||
{
|
||||
}
|
||||
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) BX_OVERRIDE
|
||||
void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) BX_OVERRIDE
|
||||
{
|
||||
TextureMtl& texture = m_textures[_handle.idx];
|
||||
|
||||
@@ -788,7 +788,7 @@ namespace bgfx { namespace mtl
|
||||
tc.m_height = _height;
|
||||
tc.m_sides = 0;
|
||||
tc.m_depth = 0;
|
||||
tc.m_numMips = 1;
|
||||
tc.m_numMips = _numMips;
|
||||
tc.m_format = TextureFormat::Enum(texture.m_requestedFormat);
|
||||
tc.m_cubeMap = false;
|
||||
tc.m_mem = NULL;
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace bgfx { namespace noop
|
||||
{
|
||||
}
|
||||
|
||||
void resizeTexture(TextureHandle /*_handle*/, uint16_t /*_width*/, uint16_t /*_height*/) BX_OVERRIDE
|
||||
void resizeTexture(TextureHandle /*_handle*/, uint16_t /*_width*/, uint16_t /*_height*/, uint8_t /*_numMips*/) BX_OVERRIDE
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user