Compare commits

..

No commits in common. "9680ca975c8d3e01984aaea7de94d5b8fd15e92f" and "a7ea09b149d71cba418a92b28a211817b1002c99" have entirely different histories.

6 changed files with 25 additions and 72 deletions

View File

@ -21,7 +21,7 @@
#include "engine/shader_source.h"
#include "third_party/texture_compressor/texture_compressor.h"
#define USE_VULKAN_RENDERER 1
#define USE_VULKAN_RENDERER 0
using namespace base;
@ -43,7 +43,6 @@ Engine::Engine(Platform* platform)
DCHECK(!singleton);
singleton = this;
platform_->SetObserver(this);
renderer_->SetContextLostCB(std::bind(&Engine::ContextLost, this));
stats_ = std::make_unique<ImageQuad>();
@ -51,7 +50,6 @@ Engine::Engine(Platform* platform)
Engine::~Engine() {
LOG << "Shutting down engine.";
game_.reset();
stats_.reset();
textures_.clear();
@ -68,7 +66,14 @@ Engine& Engine::Get() {
}
bool Engine::Initialize() {
InitializeRenderer();
bool res;
#if defined(__ANDROID__)
res = renderer_->Initialize(platform_->GetWindow());
#elif defined(__linux__)
res = renderer_->Initialize(platform_->GetDisplay(), platform_->GetWindow());
#endif
CHECK(res) << "Failed to initialize " << renderer_->GetDebugName()
<< " renderer.";
// Normalize viewport.
if (GetScreenWidth() > GetScreenHeight()) {
@ -501,33 +506,6 @@ bool Engine::IsMobile() const {
return platform_->mobile_device();
}
void Engine::OnWindowCreated() {
InitializeRenderer();
}
void Engine::OnWindowDestroyed() {
renderer_->Shutdown();
}
void Engine::OnWindowResized(int width, int height) {
if (width != renderer_->screen_width() ||
height != renderer_->screen_height()) {
renderer_->Shutdown();
InitializeRenderer();
}
}
void Engine::InitializeRenderer() {
bool res;
#if defined(__ANDROID__)
res = renderer_->Initialize(platform_->GetWindow());
#elif defined(__linux__)
res = renderer_->Initialize(platform_->GetDisplay(), platform_->GetWindow());
#endif
CHECK(res) << "Failed to initialize " << renderer_->GetDebugName()
<< " renderer.";
}
void Engine::CreateTextureCompressors() {
tex_comp_alpha_.reset();
tex_comp_opaque_.reset();

View File

@ -10,7 +10,6 @@
#include "base/random.h"
#include "base/vecmath.h"
#include "engine/persistent_data.h"
#include "engine/platform/platform_observer.h"
class TextureCompressor;
@ -30,7 +29,7 @@ class Shader;
class Texture;
class Platform;
class Engine : public PlatformObserver {
class Engine {
public:
using CreateImageCB = std::function<std::unique_ptr<Image>()>;
@ -221,13 +220,6 @@ class Engine : public PlatformObserver {
base::Randomf random_;
// PlatformObserver implementation
void OnWindowCreated() final;
void OnWindowDestroyed() final;
void OnWindowResized(int width, int height) final;
void InitializeRenderer();
void CreateTextureCompressors();
void ContextLost();

View File

@ -25,7 +25,6 @@ struct ANativeWindow;
namespace eng {
class Engine;
class PlatformObserver;
class Platform {
public:
@ -44,8 +43,6 @@ class Platform {
void Exit();
void SetObserver(PlatformObserver* observer) { observer_ = observer; }
// Renderer* SwitchRenderer(bool vulkan);
void Vibrate(int duration);
@ -87,8 +84,6 @@ class Platform {
bool has_focus_ = false;
bool should_exit_ = false;
PlatformObserver* observer_ = nullptr;
std::unique_ptr<Engine> engine_;
base::ThreadPool thread_pool_;

View File

@ -9,7 +9,6 @@
#include "base/task_runner.h"
#include "engine/engine.h"
#include "engine/input_event.h"
#include "engine/platform/platform_observer.h"
using namespace base;
@ -295,21 +294,30 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) {
DLOG << "APP_CMD_INIT_WINDOW";
if (app->window != NULL) {
platform->SetFrameRate(60);
platform->observer_->OnWindowCreated();
bool res = platform->InitializeRenderer();
CHECK(res) << "Failed to initialize "
<< platform->renderer_->GetDebugName() << " renderer.";
}
break;
case APP_CMD_TERM_WINDOW:
DLOG << "APP_CMD_TERM_WINDOW";
platform->observer_->OnWindowDestroyed();
platform->renderer_->Shutdown();
break;
case APP_CMD_CONFIG_CHANGED:
DLOG << "APP_CMD_CONFIG_CHANGED";
if (platform->app_->window != NULL)
platform->observer_->OnWindowResized(
ANativeWindow_getWidth(app->window),
ANativeWindow_getHeight(app->window));
if (platform->app_->window != NULL) {
int width = platform->renderer_->screen_width();
int height = platform->renderer_->screen_height();
if (width != ANativeWindow_getWidth(app->window) ||
height != ANativeWindow_getHeight(app->window)) {
platform->renderer_->Shutdown();
bool res = platform->InitializeRenderer();
CHECK(res) << "Failed to initialize "
<< platform->renderer_->GetDebugName() << " renderer.";
}
}
break;
case APP_CMD_STOP:

View File

@ -145,9 +145,7 @@ bool Platform::CreateWindow(int width, int height) {
void Platform::DestroyWindow() {
if (display_) {
XDestroyWindow(display_, window_);
#if 0 // TODO: Figure out why XCloseDisplay is crashing
XCloseDisplay(display_);
#endif
display_ = nullptr;
window_ = 0;
}

View File

@ -1,18 +0,0 @@
#ifndef ENGINE_PLATFORM_PLATFORM_OBSERVER_H
#define ENGINE_PLATFORM_PLATFORM_OBSERVER_H
namespace eng {
class PlatformObserver {
public:
PlatformObserver() = default;
virtual ~PlatformObserver() = default;
virtual void OnWindowCreated() = 0;
virtual void OnWindowDestroyed() = 0;
virtual void OnWindowResized(int width, int height) = 0;
};
} // namespace eng
#endif // ENGINE_PLATFORM_PLATFORM_OBSERVER_H