mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 03:18:37 +08:00
Merge pull request #20118 from vnen/uwp-gles2
UWP: Add support for GLES2 driver
This commit is contained in:
commit
1fc7973a00
@ -143,14 +143,13 @@ void App::SetWindow(CoreWindow ^ p_window) {
|
||||
window->KeyUp +=
|
||||
ref new TypedEventHandler<CoreWindow ^, KeyEventArgs ^>(this, &App::OnKeyUp);
|
||||
|
||||
os->set_window(window);
|
||||
|
||||
unsigned int argc;
|
||||
char **argv = get_command_line(&argc);
|
||||
|
||||
Main::setup("uwp", argc, argv, false);
|
||||
|
||||
// The CoreWindow has been created, so EGL can be initialized.
|
||||
ContextEGL *context = memnew(ContextEGL(window));
|
||||
os->set_gl_context(context);
|
||||
UpdateWindowSize(Size(window->Bounds.Width, window->Bounds.Height));
|
||||
|
||||
Main::setup2();
|
||||
@ -513,7 +512,7 @@ char **App::get_command_line(unsigned int *out_argc) {
|
||||
|
||||
if (f == NULL) {
|
||||
|
||||
wprintf(L"Couldn't open command line file.");
|
||||
wprintf(L"Couldn't open command line file.\n");
|
||||
return fail_cl;
|
||||
}
|
||||
|
||||
@ -527,7 +526,7 @@ char **App::get_command_line(unsigned int *out_argc) {
|
||||
|
||||
if (r < 4) {
|
||||
fclose(f);
|
||||
wprintf(L"Wrong cmdline length.");
|
||||
wprintf(L"Wrong cmdline length.\n");
|
||||
return (fail_cl);
|
||||
}
|
||||
|
||||
@ -539,7 +538,7 @@ char **App::get_command_line(unsigned int *out_argc) {
|
||||
|
||||
if (r < 4) {
|
||||
fclose(f);
|
||||
wprintf(L"Wrong cmdline param length.");
|
||||
wprintf(L"Wrong cmdline param length.\n");
|
||||
return (fail_cl);
|
||||
}
|
||||
|
||||
@ -547,7 +546,7 @@ char **App::get_command_line(unsigned int *out_argc) {
|
||||
|
||||
if (strlen > CMD_MAX_LEN) {
|
||||
fclose(f);
|
||||
wprintf(L"Wrong command length.");
|
||||
wprintf(L"Wrong command length.\n");
|
||||
return (fail_cl);
|
||||
}
|
||||
|
||||
@ -568,7 +567,7 @@ char **App::get_command_line(unsigned int *out_argc) {
|
||||
|
||||
delete[] arg;
|
||||
fclose(f);
|
||||
wprintf(L"Error reading command.");
|
||||
wprintf(L"Error reading command.\n");
|
||||
return (fail_cl);
|
||||
}
|
||||
}
|
||||
|
@ -93,12 +93,26 @@ Error ContextEGL::initialize() {
|
||||
|
||||
EGLint numConfigs = 0;
|
||||
EGLint majorVersion = 1;
|
||||
EGLint minorVersion = 0;
|
||||
EGLint minorVersion;
|
||||
if (driver == GLES_2_0) {
|
||||
minorVersion = 0;
|
||||
} else {
|
||||
minorVersion = 5;
|
||||
}
|
||||
EGLDisplay display = EGL_NO_DISPLAY;
|
||||
EGLContext context = EGL_NO_CONTEXT;
|
||||
EGLSurface surface = EGL_NO_SURFACE;
|
||||
EGLConfig config = nullptr;
|
||||
EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE, EGL_NONE };
|
||||
EGLint contextAttribs[3];
|
||||
if (driver == GLES_2_0) {
|
||||
contextAttribs[0] = EGL_CONTEXT_CLIENT_VERSION;
|
||||
contextAttribs[1] = 2;
|
||||
contextAttribs[2] = EGL_NONE;
|
||||
} else {
|
||||
contextAttribs[0] = EGL_CONTEXT_CLIENT_VERSION;
|
||||
contextAttribs[1] = 3;
|
||||
contextAttribs[2] = EGL_NONE;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@ -114,7 +128,8 @@ Error ContextEGL::initialize() {
|
||||
|
||||
// EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices.
|
||||
// Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it.
|
||||
//EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE,
|
||||
EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER,
|
||||
EGL_TRUE,
|
||||
|
||||
// EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE is an option that enables ANGLE to automatically call
|
||||
// the IDXGIDevice3::Trim method on behalf of the application when it gets suspended.
|
||||
@ -193,13 +208,12 @@ void ContextEGL::cleanup() {
|
||||
}
|
||||
};
|
||||
|
||||
ContextEGL::ContextEGL(CoreWindow ^ p_window) :
|
||||
ContextEGL::ContextEGL(CoreWindow ^ p_window, Driver p_driver) :
|
||||
mEglDisplay(EGL_NO_DISPLAY),
|
||||
mEglContext(EGL_NO_CONTEXT),
|
||||
mEglSurface(EGL_NO_SURFACE) {
|
||||
|
||||
window = p_window;
|
||||
};
|
||||
mEglSurface(EGL_NO_SURFACE),
|
||||
driver(p_driver),
|
||||
window(p_window) {}
|
||||
|
||||
ContextEGL::~ContextEGL() {
|
||||
|
||||
|
@ -42,6 +42,13 @@ using namespace Windows::UI::Core;
|
||||
|
||||
class ContextEGL : public ContextGL {
|
||||
|
||||
public:
|
||||
enum Driver {
|
||||
GLES_2_0,
|
||||
GLES_3_0,
|
||||
};
|
||||
|
||||
private:
|
||||
CoreWindow ^ window;
|
||||
|
||||
EGLDisplay mEglDisplay;
|
||||
@ -53,6 +60,8 @@ class ContextEGL : public ContextGL {
|
||||
|
||||
bool vsync;
|
||||
|
||||
Driver driver;
|
||||
|
||||
public:
|
||||
virtual void release_current();
|
||||
|
||||
@ -70,7 +79,7 @@ public:
|
||||
|
||||
void cleanup();
|
||||
|
||||
ContextEGL(CoreWindow ^ p_window);
|
||||
ContextEGL(CoreWindow ^ p_window, Driver p_driver);
|
||||
~ContextEGL();
|
||||
};
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "os_uwp.h"
|
||||
|
||||
#include "drivers/gles2/rasterizer_gles2.h"
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#include "drivers/unix/ip_unix.h"
|
||||
#include "drivers/windows/dir_access_windows.h"
|
||||
@ -66,12 +67,7 @@ using namespace Windows::ApplicationModel::DataTransfer;
|
||||
using namespace concurrency;
|
||||
|
||||
int OSUWP::get_video_driver_count() const {
|
||||
|
||||
return 1;
|
||||
}
|
||||
const char *OSUWP::get_video_driver_name(int p_driver) const {
|
||||
|
||||
return "GLES3";
|
||||
return 2;
|
||||
}
|
||||
|
||||
Size2 OSUWP::get_window_size() const {
|
||||
@ -133,18 +129,6 @@ void OSUWP::set_keep_screen_on(bool p_enabled) {
|
||||
OS::set_keep_screen_on(p_enabled);
|
||||
}
|
||||
|
||||
int OSUWP::get_audio_driver_count() const {
|
||||
|
||||
return AudioDriverManager::get_driver_count();
|
||||
}
|
||||
|
||||
const char *OSUWP::get_audio_driver_name(int p_driver) const {
|
||||
|
||||
AudioDriver *driver = AudioDriverManager::get_driver(p_driver);
|
||||
ERR_FAIL_COND_V(!driver, "");
|
||||
return AudioDriverManager::get_driver(p_driver)->get_name();
|
||||
}
|
||||
|
||||
void OSUWP::initialize_core() {
|
||||
|
||||
last_button_state = 0;
|
||||
@ -185,10 +169,9 @@ bool OSUWP::can_draw() const {
|
||||
return !minimized;
|
||||
};
|
||||
|
||||
void OSUWP::set_gl_context(ContextEGL *p_context) {
|
||||
|
||||
gl_context = p_context;
|
||||
};
|
||||
void OSUWP::set_window(Windows::UI::Core::CoreWindow ^ p_window) {
|
||||
window = p_window;
|
||||
}
|
||||
|
||||
void OSUWP::screen_size_changed() {
|
||||
|
||||
@ -200,6 +183,11 @@ Error OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
|
||||
main_loop = NULL;
|
||||
outside = true;
|
||||
|
||||
if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
gl_context = memnew(ContextEGL(window, ContextEGL::GLES_2_0));
|
||||
} else {
|
||||
gl_context = memnew(ContextEGL(window, ContextEGL::GLES_3_0));
|
||||
}
|
||||
gl_context->initialize();
|
||||
VideoMode vm;
|
||||
vm.width = gl_context->get_window_width();
|
||||
@ -240,8 +228,13 @@ Error OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
|
||||
|
||||
gl_context->make_current();
|
||||
|
||||
RasterizerGLES3::register_config();
|
||||
RasterizerGLES3::make_current();
|
||||
if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
RasterizerGLES2::register_config();
|
||||
RasterizerGLES2::make_current();
|
||||
} else {
|
||||
RasterizerGLES3::register_config();
|
||||
RasterizerGLES3::make_current();
|
||||
}
|
||||
gl_context->set_use_vsync(vm.use_vsync);
|
||||
|
||||
visual_server = memnew(VisualServerRaster);
|
||||
|
@ -96,6 +96,7 @@ private:
|
||||
int pressrc;
|
||||
|
||||
ContextEGL *gl_context;
|
||||
Windows::UI::Core::CoreWindow ^ window;
|
||||
|
||||
VideoMode video_mode;
|
||||
|
||||
@ -153,10 +154,6 @@ private:
|
||||
// functions used by main to initialize/deintialize the OS
|
||||
protected:
|
||||
virtual int get_video_driver_count() const;
|
||||
virtual const char *get_video_driver_name(int p_driver) const;
|
||||
|
||||
virtual int get_audio_driver_count() const;
|
||||
virtual const char *get_audio_driver_name(int p_driver) const;
|
||||
|
||||
virtual void initialize_core();
|
||||
virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
|
||||
@ -231,7 +228,7 @@ public:
|
||||
|
||||
virtual bool _check_internal_feature_support(const String &p_feature);
|
||||
|
||||
void set_gl_context(ContextEGL *p_context);
|
||||
void set_window(Windows::UI::Core::CoreWindow ^ p_window);
|
||||
void screen_size_changed();
|
||||
|
||||
virtual void release_rendering_thread();
|
||||
|
Loading…
Reference in New Issue
Block a user