mirror of https://github.com/auygun/kaliber.git
Shutdown renderer in destructor
This commit is contained in:
parent
94242fca0b
commit
b7f1f7faa2
|
@ -46,7 +46,27 @@ RendererOpenGL::RendererOpenGL()
|
||||||
RendererOpenGL::RendererOpenGL() = default;
|
RendererOpenGL::RendererOpenGL() = default;
|
||||||
#endif // THREADED_RENDERING
|
#endif // THREADED_RENDERING
|
||||||
|
|
||||||
RendererOpenGL::~RendererOpenGL() = default;
|
RendererOpenGL::~RendererOpenGL() {
|
||||||
|
Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RendererOpenGL::Shutdown() {
|
||||||
|
#ifdef THREADED_RENDERING
|
||||||
|
if (terminate_render_thread_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
LOG << "Shutting down renderer.";
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> scoped_lock(mutex_);
|
||||||
|
terminate_render_thread_ = true;
|
||||||
|
}
|
||||||
|
cv_.notify_one();
|
||||||
|
LOG << "Terminating render thread";
|
||||||
|
render_thread_.join();
|
||||||
|
#else
|
||||||
|
ShutdownInternal();
|
||||||
|
#endif // THREADED_RENDERING
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t RendererOpenGL::CreateGeometry(std::unique_ptr<Mesh> mesh) {
|
uint64_t RendererOpenGL::CreateGeometry(std::unique_ptr<Mesh> mesh) {
|
||||||
auto cmd = std::make_unique<CmdCreateGeometry>();
|
auto cmd = std::make_unique<CmdCreateGeometry>();
|
||||||
|
@ -348,24 +368,6 @@ bool RendererOpenGL::StartRenderThread() {
|
||||||
#endif // THREADED_RENDERING
|
#endif // THREADED_RENDERING
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererOpenGL::TerminateRenderThread() {
|
|
||||||
#ifdef THREADED_RENDERING
|
|
||||||
if (terminate_render_thread_)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Notify worker thread and wait for it to terminate.
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> scoped_lock(mutex_);
|
|
||||||
terminate_render_thread_ = true;
|
|
||||||
}
|
|
||||||
cv_.notify_one();
|
|
||||||
LOG << "Terminating render thread";
|
|
||||||
render_thread_.join();
|
|
||||||
#else
|
|
||||||
ShutdownInternal();
|
|
||||||
#endif // THREADED_RENDERING
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef THREADED_RENDERING
|
#ifdef THREADED_RENDERING
|
||||||
|
|
||||||
void RendererOpenGL::RenderThreadMain(std::promise<bool> promise) {
|
void RendererOpenGL::RenderThreadMain(std::promise<bool> promise) {
|
||||||
|
|
|
@ -170,7 +170,6 @@ class RendererOpenGL final : public Renderer {
|
||||||
void DestroyAllResources();
|
void DestroyAllResources();
|
||||||
|
|
||||||
bool StartRenderThread();
|
bool StartRenderThread();
|
||||||
void TerminateRenderThread();
|
|
||||||
|
|
||||||
#ifdef THREADED_RENDERING
|
#ifdef THREADED_RENDERING
|
||||||
void RenderThreadMain(std::promise<bool> promise);
|
void RenderThreadMain(std::promise<bool> promise);
|
||||||
|
|
|
@ -14,11 +14,6 @@ bool RendererOpenGL::Initialize(ANativeWindow* window) {
|
||||||
return StartRenderThread();
|
return StartRenderThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererOpenGL::Shutdown() {
|
|
||||||
LOG << "Shutting down renderer.";
|
|
||||||
TerminateRenderThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RendererOpenGL::InitInternal() {
|
bool RendererOpenGL::InitInternal() {
|
||||||
ndk_helper::GLContext* gl_context = ndk_helper::GLContext::GetInstance();
|
ndk_helper::GLContext* gl_context = ndk_helper::GLContext::GetInstance();
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,6 @@ bool RendererOpenGL::Initialize(Display* display, Window window) {
|
||||||
return StartRenderThread();
|
return StartRenderThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererOpenGL::Shutdown() {
|
|
||||||
LOG << "Shutting down renderer.";
|
|
||||||
|
|
||||||
TerminateRenderThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RendererOpenGL::InitInternal() {
|
bool RendererOpenGL::InitInternal() {
|
||||||
// Create the OpenGL context.
|
// Create the OpenGL context.
|
||||||
glx_context_ =
|
glx_context_ =
|
||||||
|
|
|
@ -372,7 +372,9 @@ namespace eng {
|
||||||
|
|
||||||
RendererVulkan::RendererVulkan() = default;
|
RendererVulkan::RendererVulkan() = default;
|
||||||
|
|
||||||
RendererVulkan::~RendererVulkan() = default;
|
RendererVulkan::~RendererVulkan() {
|
||||||
|
Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t RendererVulkan::CreateGeometry(std::unique_ptr<Mesh> mesh) {
|
uint64_t RendererVulkan::CreateGeometry(std::unique_ptr<Mesh> mesh) {
|
||||||
auto& geometry = geometries_[++last_resource_id_] = {};
|
auto& geometry = geometries_[++last_resource_id_] = {};
|
||||||
|
|
Loading…
Reference in New Issue