chore: don't keep superfluous handle to rtDepth and rtColor

This commit is contained in:
Nick Fisher
2024-09-27 16:40:30 +08:00
parent fb6204e47c
commit 399d447eec
2 changed files with 16 additions and 17 deletions

View File

@@ -160,18 +160,11 @@ namespace thermion_filament
const ResourceLoaderWrapperImpl *const _resourceLoaderWrapper; const ResourceLoaderWrapperImpl *const _resourceLoaderWrapper;
void* _context = nullptr; void* _context = nullptr;
Scene *_scene = nullptr; Scene *_scene = nullptr;
View *_view = nullptr; View *_view = nullptr;
Engine *_engine = nullptr; Engine *_engine = nullptr;
thermion_filament::ThreadPool *_tp = nullptr; thermion_filament::ThreadPool *_tp = nullptr;
Renderer *_renderer = nullptr; Renderer *_renderer = nullptr;
RenderTarget *_rt = nullptr;
Texture *_rtColor = nullptr;
Texture *_rtDepth = nullptr;
SwapChain *_swapChain = nullptr; SwapChain *_swapChain = nullptr;
SceneManager *_sceneManager = nullptr; SceneManager *_sceneManager = nullptr;
std::mutex mtx; // mutex to ensure thread safety when removing assets std::mutex mtx; // mutex to ensure thread safety when removing assets

View File

@@ -781,7 +781,7 @@ namespace thermion_filament
void FilamentViewer::createRenderTarget(intptr_t texture, uint32_t width, uint32_t height) void FilamentViewer::createRenderTarget(intptr_t texture, uint32_t width, uint32_t height)
{ {
// Create filament textures and render targets (note the color buffer has the import call) // Create filament textures and render targets (note the color buffer has the import call)
_rtColor = filament::Texture::Builder() auto rtColor = filament::Texture::Builder()
.width(width) .width(width)
.height(height) .height(height)
.levels(1) .levels(1)
@@ -789,7 +789,7 @@ namespace thermion_filament
.format(filament::Texture::InternalFormat::RGBA8) .format(filament::Texture::InternalFormat::RGBA8)
.import(texture) .import(texture)
.build(*_engine); .build(*_engine);
_rtDepth = filament::Texture::Builder() auto rtDepth = filament::Texture::Builder()
.width(width) .width(width)
.height(height) .height(height)
.levels(1) .levels(1)
@@ -797,8 +797,8 @@ namespace thermion_filament
.format(filament::Texture::InternalFormat::DEPTH32F) .format(filament::Texture::InternalFormat::DEPTH32F)
.build(*_engine); .build(*_engine);
_rt = filament::RenderTarget::Builder() _rt = filament::RenderTarget::Builder()
.texture(RenderTarget::AttachmentPoint::COLOR, _rtColor) .texture(RenderTarget::AttachmentPoint::COLOR, rtColor)
.texture(RenderTarget::AttachmentPoint::DEPTH, _rtDepth) .texture(RenderTarget::AttachmentPoint::DEPTH, rtDepth)
.build(*_engine); .build(*_engine);
_view->setRenderTarget(_rt); _view->setRenderTarget(_rt);
@@ -811,12 +811,18 @@ namespace thermion_filament
if (_rt) if (_rt)
{ {
_view->setRenderTarget(nullptr); _view->setRenderTarget(nullptr);
_engine->destroy(_rtDepth); auto rtDepth = _rt->getTexture(RenderTarget::AttachmentPoint::DEPTH);
_engine->destroy(_rtColor); if(rtDepth) {
_engine->destroy(rtDepth);
Log("destroyed depth");
}
auto rtColor = _rt->getTexture(RenderTarget::AttachmentPoint::COLOR);
if(rtColor) {
_engine->destroy(rtColor);
Log("destroyed color");
}
_engine->destroy(_rt); _engine->destroy(_rt);
_rt = nullptr; _rt = nullptr;
_rtDepth = nullptr;
_rtColor = nullptr;
} }
if (_swapChain) if (_swapChain)
{ {