mirror of https://github.com/auygun/kaliber.git
Renderer(base::Closure context_lost_cb)
This commit is contained in:
parent
98e7e5f107
commit
231efe1c92
|
@ -203,19 +203,18 @@ void Engine::CreateRenderer(bool vulkan) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (vulkan)
|
if (vulkan)
|
||||||
renderer_ = std::make_unique<RendererVulkan>();
|
renderer_ =
|
||||||
|
std::make_unique<RendererVulkan>(std::bind(&Engine::ContextLost, this));
|
||||||
else
|
else
|
||||||
renderer_ = std::make_unique<RendererOpenGL>();
|
renderer_ =
|
||||||
renderer_->SetContextLostCB(std::bind(&Engine::ContextLost, this));
|
std::make_unique<RendererOpenGL>(std::bind(&Engine::ContextLost, this));
|
||||||
|
|
||||||
bool result = renderer_->Initialize(platform_);
|
bool result = renderer_->Initialize(platform_);
|
||||||
LOG_IF(!result) << "Failed to initialize " << renderer_->GetDebugName()
|
|
||||||
<< " renderer.";
|
|
||||||
if (!result && vulkan) {
|
if (!result && vulkan) {
|
||||||
|
LOG << "Failed to initialize " << renderer_->GetDebugName() << " renderer.";
|
||||||
LOG << "Fallback to OpenGL renderer.";
|
LOG << "Fallback to OpenGL renderer.";
|
||||||
renderer_ = std::make_unique<RendererOpenGL>();
|
CreateRenderer(false);
|
||||||
renderer_->SetContextLostCB(std::bind(&Engine::ContextLost, this));
|
return;
|
||||||
result = renderer_->Initialize(platform_);
|
|
||||||
}
|
}
|
||||||
CHECK(result) << "Failed to initialize " << renderer_->GetDebugName()
|
CHECK(result) << "Failed to initialize " << renderer_->GetDebugName()
|
||||||
<< " renderer.";
|
<< " renderer.";
|
||||||
|
|
|
@ -40,8 +40,9 @@ const std::string kAttributeNames[eng::kAttribType_Max] = {
|
||||||
namespace eng {
|
namespace eng {
|
||||||
|
|
||||||
#ifdef THREADED_RENDERING
|
#ifdef THREADED_RENDERING
|
||||||
RendererOpenGL::RendererOpenGL()
|
RendererOpenGL::RendererOpenGL(base::Closure context_lost_cb)
|
||||||
: main_thread_task_runner_(TaskRunner::GetThreadLocalTaskRunner()) {}
|
: Renderer(context_lost_cb),
|
||||||
|
main_thread_task_runner_(TaskRunner::GetThreadLocalTaskRunner()) {}
|
||||||
#else
|
#else
|
||||||
RendererOpenGL::RendererOpenGL() = default;
|
RendererOpenGL::RendererOpenGL() = default;
|
||||||
#endif // THREADED_RENDERING
|
#endif // THREADED_RENDERING
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct RenderCommand;
|
||||||
|
|
||||||
class RendererOpenGL final : public Renderer {
|
class RendererOpenGL final : public Renderer {
|
||||||
public:
|
public:
|
||||||
RendererOpenGL();
|
RendererOpenGL(base::Closure context_lost_cb);
|
||||||
~RendererOpenGL() final;
|
~RendererOpenGL() final;
|
||||||
|
|
||||||
virtual bool Initialize(Platform* platform) final;
|
virtual bool Initialize(Platform* platform) final;
|
||||||
|
|
|
@ -19,11 +19,10 @@ class Renderer {
|
||||||
public:
|
public:
|
||||||
const unsigned kInvalidId = 0;
|
const unsigned kInvalidId = 0;
|
||||||
|
|
||||||
Renderer() = default;
|
Renderer(base::Closure context_lost_cb)
|
||||||
|
: context_lost_cb_{std::move(context_lost_cb)} {}
|
||||||
virtual ~Renderer() = default;
|
virtual ~Renderer() = default;
|
||||||
|
|
||||||
void SetContextLostCB(base::Closure cb) { context_lost_cb_ = std::move(cb); }
|
|
||||||
|
|
||||||
virtual bool Initialize(Platform* platform) = 0;
|
virtual bool Initialize(Platform* platform) = 0;
|
||||||
virtual void Shutdown() = 0;
|
virtual void Shutdown() = 0;
|
||||||
|
|
||||||
|
|
|
@ -370,7 +370,8 @@ std::pair<int, int> GetNumBlocksForImageFormat(VkFormat format,
|
||||||
|
|
||||||
namespace eng {
|
namespace eng {
|
||||||
|
|
||||||
RendererVulkan::RendererVulkan() = default;
|
RendererVulkan::RendererVulkan(base::Closure context_lost_cb)
|
||||||
|
: Renderer(context_lost_cb) {}
|
||||||
|
|
||||||
RendererVulkan::~RendererVulkan() {
|
RendererVulkan::~RendererVulkan() {
|
||||||
Shutdown();
|
Shutdown();
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace eng {
|
||||||
|
|
||||||
class RendererVulkan final : public Renderer {
|
class RendererVulkan final : public Renderer {
|
||||||
public:
|
public:
|
||||||
RendererVulkan();
|
RendererVulkan(base::Closure context_lost_cb);
|
||||||
~RendererVulkan() final;
|
~RendererVulkan() final;
|
||||||
|
|
||||||
virtual bool Initialize(Platform* platform) final;
|
virtual bool Initialize(Platform* platform) final;
|
||||||
|
|
Loading…
Reference in New Issue