mirror of https://github.com/auygun/kaliber.git
Initialize(Platform* platform)
This commit is contained in:
parent
a00110cc94
commit
98e7e5f107
|
@ -208,14 +208,14 @@ void Engine::CreateRenderer(bool vulkan) {
|
|||
renderer_ = std::make_unique<RendererOpenGL>();
|
||||
renderer_->SetContextLostCB(std::bind(&Engine::ContextLost, this));
|
||||
|
||||
bool result = InitializeRenderer();
|
||||
bool result = renderer_->Initialize(platform_);
|
||||
LOG_IF(!result) << "Failed to initialize " << renderer_->GetDebugName()
|
||||
<< " renderer.";
|
||||
if (!result && vulkan) {
|
||||
LOG << "Fallback to OpenGL renderer.";
|
||||
renderer_ = std::make_unique<RendererOpenGL>();
|
||||
renderer_->SetContextLostCB(std::bind(&Engine::ContextLost, this));
|
||||
result = InitializeRenderer();
|
||||
result = renderer_->Initialize(platform_);
|
||||
}
|
||||
CHECK(result) << "Failed to initialize " << renderer_->GetDebugName()
|
||||
<< " renderer.";
|
||||
|
@ -480,7 +480,7 @@ bool Engine::IsMobile() const {
|
|||
}
|
||||
|
||||
void Engine::OnWindowCreated() {
|
||||
InitializeRenderer();
|
||||
renderer_->Initialize(platform_);
|
||||
}
|
||||
|
||||
void Engine::OnWindowDestroyed() {
|
||||
|
@ -491,7 +491,7 @@ void Engine::OnWindowResized(int width, int height) {
|
|||
if (width != renderer_->screen_width() ||
|
||||
height != renderer_->screen_height()) {
|
||||
renderer_->Shutdown();
|
||||
InitializeRenderer();
|
||||
renderer_->Initialize(platform_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -546,14 +546,6 @@ void Engine::AddInputEvent(std::unique_ptr<InputEvent> event) {
|
|||
input_queue_.push_back(std::move(event));
|
||||
}
|
||||
|
||||
bool Engine::InitializeRenderer() {
|
||||
#if defined(__ANDROID__)
|
||||
return renderer_->Initialize(platform_->GetWindow());
|
||||
#elif defined(__linux__)
|
||||
return renderer_->Initialize(platform_->GetDisplay(), platform_->GetWindow());
|
||||
#endif
|
||||
}
|
||||
|
||||
void Engine::CreateTextureCompressors() {
|
||||
tex_comp_alpha_.reset();
|
||||
tex_comp_opaque_.reset();
|
||||
|
|
|
@ -231,8 +231,6 @@ class Engine : public PlatformObserver {
|
|||
void GainedFocus(bool from_interstitial_ad) final;
|
||||
void AddInputEvent(std::unique_ptr<InputEvent> event) final;
|
||||
|
||||
bool InitializeRenderer();
|
||||
|
||||
void CreateTextureCompressors();
|
||||
|
||||
void ContextLost();
|
||||
|
|
|
@ -40,12 +40,7 @@ class RendererOpenGL final : public Renderer {
|
|||
RendererOpenGL();
|
||||
~RendererOpenGL() final;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
bool Initialize(ANativeWindow* window) final;
|
||||
#elif defined(__linux__)
|
||||
bool Initialize(Display* display, Window window) final;
|
||||
#endif
|
||||
|
||||
virtual bool Initialize(Platform* platform) final;
|
||||
void Shutdown() final;
|
||||
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
|
||||
|
|
|
@ -3,14 +3,15 @@
|
|||
#include <android/native_window.h>
|
||||
|
||||
#include "base/log.h"
|
||||
#include "engine/platform/platform.h"
|
||||
#include "third_party/android/GLContext.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
bool RendererOpenGL::Initialize(ANativeWindow* window) {
|
||||
bool RendererOpenGL::Initialize(Platform* platform) {
|
||||
LOG << "Initializing renderer.";
|
||||
|
||||
window_ = window;
|
||||
window_ = platform->GetWindow();
|
||||
return StartRenderThread();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
#include "engine/renderer/opengl/renderer_opengl.h"
|
||||
|
||||
#include "base/log.h"
|
||||
#include "engine/platform/platform.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
bool RendererOpenGL::Initialize(Display* display, Window window) {
|
||||
bool RendererOpenGL::Initialize(Platform* platform) {
|
||||
LOG << "Initializing renderer.";
|
||||
|
||||
display_ = display;
|
||||
window_ = window;
|
||||
display_ = platform->GetDisplay();
|
||||
window_ = platform->GetWindow();
|
||||
|
||||
XWindowAttributes xwa;
|
||||
XGetWindowAttributes(display_, window_, &xwa);
|
||||
|
@ -24,8 +25,7 @@ bool RendererOpenGL::InitInternal() {
|
|||
GLint glx_attributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER,
|
||||
None};
|
||||
XVisualInfo* visual_info = glXChooseVisual(display_, 0, glx_attributes);
|
||||
glx_context_ =
|
||||
glXCreateContext(display_, visual_info, NULL, GL_TRUE);
|
||||
glx_context_ = glXCreateContext(display_, visual_info, NULL, GL_TRUE);
|
||||
if (!glx_context_) {
|
||||
LOG << "Couldn't create the glx context.";
|
||||
return false;
|
||||
|
|
|
@ -4,24 +4,16 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#endif
|
||||
|
||||
#include "base/closure.h"
|
||||
#include "base/vecmath.h"
|
||||
#include "engine/renderer/renderer_types.h"
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
struct ANativeWindow;
|
||||
#endif
|
||||
|
||||
namespace eng {
|
||||
|
||||
class Image;
|
||||
class ShaderSource;
|
||||
class Mesh;
|
||||
class Platform;
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
|
@ -32,12 +24,7 @@ class Renderer {
|
|||
|
||||
void SetContextLostCB(base::Closure cb) { context_lost_cb_ = std::move(cb); }
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
virtual bool Initialize(ANativeWindow* window) = 0;
|
||||
#elif defined(__linux__)
|
||||
virtual bool Initialize(Display* display, Window window) = 0;
|
||||
#endif
|
||||
|
||||
virtual bool Initialize(Platform* platform) = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
virtual uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) = 0;
|
||||
|
|
|
@ -18,19 +18,12 @@
|
|||
|
||||
namespace eng {
|
||||
|
||||
class Image;
|
||||
|
||||
class RendererVulkan final : public Renderer {
|
||||
public:
|
||||
RendererVulkan();
|
||||
~RendererVulkan() final;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
bool Initialize(ANativeWindow* window) final;
|
||||
#elif defined(__linux__)
|
||||
bool Initialize(Display* display, Window window) final;
|
||||
#endif
|
||||
|
||||
virtual bool Initialize(Platform* platform) final;
|
||||
void Shutdown() final;
|
||||
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
|
||||
|
|
|
@ -3,20 +3,22 @@
|
|||
#include <android/native_window.h>
|
||||
|
||||
#include "base/log.h"
|
||||
#include "engine/platform/platform.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
bool RendererVulkan::Initialize(ANativeWindow* window) {
|
||||
bool RendererVulkan::Initialize(Platform* platform) {
|
||||
LOG << "Initializing renderer.";
|
||||
|
||||
screen_width_ = ANativeWindow_getWidth(window);
|
||||
screen_height_ = ANativeWindow_getHeight(window);
|
||||
screen_width_ = ANativeWindow_getWidth(platform->GetWindow());
|
||||
screen_height_ = ANativeWindow_getHeight(platform->GetWindow());
|
||||
|
||||
if (!context_.Initialize()) {
|
||||
LOG << "Failed to initialize Vulkan context.";
|
||||
return false;
|
||||
}
|
||||
if (!context_.CreateWindow(window, screen_width_, screen_height_)) {
|
||||
if (!context_.CreateWindow(platform->GetWindow(), screen_width_,
|
||||
screen_height_)) {
|
||||
LOG << "Vulkan context failed to create window.";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
#include "engine/renderer/vulkan/renderer_vulkan.h"
|
||||
|
||||
#include "base/log.h"
|
||||
#include "engine/platform/platform.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
bool RendererVulkan::Initialize(Display* display, Window window) {
|
||||
bool RendererVulkan::Initialize(Platform* platform) {
|
||||
LOG << "Initializing renderer.";
|
||||
|
||||
XWindowAttributes xwa;
|
||||
XGetWindowAttributes(display, window, &xwa);
|
||||
XGetWindowAttributes(platform->GetDisplay(), platform->GetWindow(), &xwa);
|
||||
screen_width_ = xwa.width;
|
||||
screen_height_ = xwa.height;
|
||||
|
||||
|
@ -16,7 +17,8 @@ bool RendererVulkan::Initialize(Display* display, Window window) {
|
|||
LOG << "Failed to initialize Vulkan context.";
|
||||
return false;
|
||||
}
|
||||
if (!context_.CreateWindow(display, window, screen_width_, screen_height_)) {
|
||||
if (!context_.CreateWindow(platform->GetDisplay(), platform->GetWindow(),
|
||||
screen_width_, screen_height_)) {
|
||||
LOG << "Vulkan context failed to create window.";
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue