Fixed early texture destruction when multiple frame buffers take ownership.

This commit is contained in:
Branimir Karadžić 2015-08-07 17:31:31 -07:00
parent f82f99b2a6
commit 9c9dc90336
2 changed files with 22 additions and 11 deletions

View file

@ -2778,16 +2778,7 @@ again:
, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS , BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS
); );
BX_CHECK(NULL != _handles, "_handles can't be NULL"); BX_CHECK(NULL != _handles, "_handles can't be NULL");
FrameBufferHandle handle = s_ctx->createFrameBuffer(_num, _handles); return s_ctx->createFrameBuffer(_num, _handles, _destroyTextures);
if (_destroyTextures)
{
for (uint32_t ii = 0; ii < _num; ++ii)
{
destroyTexture(_handles[ii]);
}
}
return handle;
} }
FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat) FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _depthFormat)

View file

@ -2839,6 +2839,7 @@ namespace bgfx
ref.m_refCount = 1; ref.m_refCount = 1;
ref.m_bbRatio = uint8_t(_ratio); ref.m_bbRatio = uint8_t(_ratio);
ref.m_format = uint8_t(_info->format); ref.m_format = uint8_t(_info->format);
ref.m_owned = false;
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateTexture); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateTexture);
cmdbuf.write(handle); cmdbuf.write(handle);
@ -2883,6 +2884,16 @@ namespace bgfx
cmdbuf.write(_height); cmdbuf.write(_height);
} }
void textureTakeOwnership(TextureHandle _handle)
{
TextureRef& ref = m_textureRef[_handle.idx];
if (!ref.m_owned)
{
ref.m_owned = true;
textureDecRef(_handle);
}
}
void textureIncRef(TextureHandle _handle) void textureIncRef(TextureHandle _handle)
{ {
TextureRef& ref = m_textureRef[_handle.idx]; TextureRef& ref = m_textureRef[_handle.idx];
@ -2919,7 +2930,7 @@ namespace bgfx
cmdbuf.write(_mem); cmdbuf.write(_mem);
} }
BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles) ) BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(uint8_t _num, TextureHandle* _handles, bool _destroyTextures) )
{ {
FrameBufferHandle handle = { m_frameBufferHandle.alloc() }; FrameBufferHandle handle = { m_frameBufferHandle.alloc() };
BX_WARN(isValid(handle), "Failed to allocate frame buffer handle."); BX_WARN(isValid(handle), "Failed to allocate frame buffer handle.");
@ -2949,6 +2960,14 @@ namespace bgfx
} }
} }
if (_destroyTextures)
{
for (uint32_t ii = 0; ii < _num; ++ii)
{
textureTakeOwnership(_handles[ii]);
}
}
return handle; return handle;
} }
@ -3565,6 +3584,7 @@ namespace bgfx
int16_t m_refCount; int16_t m_refCount;
uint8_t m_bbRatio; uint8_t m_bbRatio;
uint8_t m_format; uint8_t m_format;
bool m_owned;
}; };
struct FrameBufferRef struct FrameBufferRef