2012-12-17 21:01:52 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#include "Host.h"
|
|
|
|
#include "RenderBase.h"
|
|
|
|
|
2012-12-26 01:08:24 +00:00
|
|
|
#include "../GLInterface.h"
|
2013-03-25 02:06:34 +00:00
|
|
|
#include "EGL.h"
|
2012-12-17 21:01:52 +00:00
|
|
|
|
|
|
|
// Show the current FPS
|
|
|
|
void cInterfaceEGL::UpdateFPSDisplay(const char *text)
|
|
|
|
{
|
2013-03-25 02:06:34 +00:00
|
|
|
Platform.UpdateFPSDisplay(text);
|
2012-12-17 21:01:52 +00:00
|
|
|
}
|
2012-12-26 06:34:09 +00:00
|
|
|
void cInterfaceEGL::Swap()
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
|
|
|
eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf);
|
|
|
|
}
|
2013-03-25 02:06:34 +00:00
|
|
|
void cInterfaceEGL::SwapInterval(int Interval)
|
|
|
|
{
|
|
|
|
eglSwapInterval(GLWin.egl_dpy, Interval);
|
|
|
|
}
|
2012-12-17 21:01:52 +00:00
|
|
|
|
|
|
|
// Create rendering window.
|
|
|
|
// Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize()
|
2012-12-26 06:07:43 +00:00
|
|
|
bool cInterfaceEGL::Create(void *&window_handle)
|
2012-12-17 21:01:52 +00:00
|
|
|
{
|
2013-03-25 02:06:34 +00:00
|
|
|
const char *s;
|
2013-01-24 16:39:38 +00:00
|
|
|
EGLint egl_major, egl_minor;
|
2013-03-25 02:06:34 +00:00
|
|
|
EGLConfig config;
|
|
|
|
EGLint num_configs;
|
2012-12-17 21:01:52 +00:00
|
|
|
|
|
|
|
// attributes for a visual in RGBA format with at least
|
2013-10-29 18:19:56 +00:00
|
|
|
// 8 bits per color
|
2012-12-17 21:01:52 +00:00
|
|
|
int attribs[] = {
|
|
|
|
EGL_RED_SIZE, 8,
|
|
|
|
EGL_GREEN_SIZE, 8,
|
|
|
|
EGL_BLUE_SIZE, 8,
|
|
|
|
#ifdef USE_GLES
|
2013-05-06 03:47:15 +00:00
|
|
|
#ifdef USE_GLES3
|
2013-06-26 13:18:53 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-06-26 13:18:53 +00:00
|
|
|
// OpenGL ES 3 bit is disabled for now, until we have a way to select it from runtime
|
|
|
|
// Qualcomm drivers don't even care if it is ES2 or ES3 bit set.
|
|
|
|
// Intel drivers /might/ not care, but that code path is untested
|
|
|
|
// EGL_RENDERABLE_TYPE, (1 << 6) /* EGL_OPENGL_ES3_BIT */,
|
2013-05-06 03:47:15 +00:00
|
|
|
#else
|
2012-12-17 21:01:52 +00:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
2013-05-06 03:47:15 +00:00
|
|
|
#endif
|
2012-12-17 21:01:52 +00:00
|
|
|
#else
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
|
|
|
#endif
|
|
|
|
EGL_NONE };
|
|
|
|
|
|
|
|
static const EGLint ctx_attribs[] = {
|
|
|
|
#ifdef USE_GLES
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
#endif
|
|
|
|
EGL_NONE
|
|
|
|
};
|
2013-01-24 16:39:38 +00:00
|
|
|
|
2013-03-25 02:06:34 +00:00
|
|
|
if(!Platform.SelectDisplay())
|
2013-01-24 16:39:38 +00:00
|
|
|
return false;
|
|
|
|
|
2013-03-25 02:06:34 +00:00
|
|
|
GLWin.egl_dpy = Platform.EGLGetDisplay();
|
|
|
|
|
|
|
|
if (!GLWin.egl_dpy) {
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglGetDisplay() failed\n");
|
2013-01-24 16:39:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-25 02:06:34 +00:00
|
|
|
GLWin.platform = Platform.platform;
|
|
|
|
|
|
|
|
if (!eglInitialize(GLWin.egl_dpy, &egl_major, &egl_minor)) {
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglInitialize() failed\n");
|
2013-01-24 16:39:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-12-17 21:01:52 +00:00
|
|
|
|
|
|
|
#ifdef USE_GLES
|
|
|
|
eglBindAPI(EGL_OPENGL_ES_API);
|
|
|
|
#else
|
|
|
|
eglBindAPI(EGL_OPENGL_API);
|
|
|
|
#endif
|
2013-03-25 02:06:34 +00:00
|
|
|
|
|
|
|
if (!eglChooseConfig( GLWin.egl_dpy, attribs, &config, 1, &num_configs)) {
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: couldn't get an EGL visual config\n");
|
2013-03-25 02:06:34 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Platform.Init(config))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
s = eglQueryString(GLWin.egl_dpy, EGL_VERSION);
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "EGL_VERSION = %s\n", s);
|
2013-03-25 02:06:34 +00:00
|
|
|
|
|
|
|
s = eglQueryString(GLWin.egl_dpy, EGL_VENDOR);
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "EGL_VENDOR = %s\n", s);
|
2013-03-25 02:06:34 +00:00
|
|
|
|
|
|
|
s = eglQueryString(GLWin.egl_dpy, EGL_EXTENSIONS);
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "EGL_EXTENSIONS = %s\n", s);
|
2013-03-25 02:06:34 +00:00
|
|
|
|
|
|
|
s = eglQueryString(GLWin.egl_dpy, EGL_CLIENT_APIS);
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "EGL_CLIENT_APIS = %s\n", s);
|
2013-03-25 02:06:34 +00:00
|
|
|
|
2012-12-17 21:01:52 +00:00
|
|
|
GLWin.egl_ctx = eglCreateContext(GLWin.egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs );
|
2013-01-24 16:39:38 +00:00
|
|
|
if (!GLWin.egl_ctx) {
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglCreateContext failed\n");
|
2013-03-25 02:06:34 +00:00
|
|
|
exit(1);
|
2013-01-24 16:39:38 +00:00
|
|
|
}
|
|
|
|
|
2013-03-25 02:06:34 +00:00
|
|
|
GLWin.native_window = Platform.CreateWindow();
|
|
|
|
|
|
|
|
GLWin.egl_surf = eglCreateWindowSurface(GLWin.egl_dpy, config,
|
|
|
|
GLWin.native_window, NULL);
|
2013-01-24 16:39:38 +00:00
|
|
|
if (!GLWin.egl_surf) {
|
2013-04-23 19:17:16 +00:00
|
|
|
INFO_LOG(VIDEO, "Error: eglCreateWindowSurface failed\n");
|
2013-03-25 02:06:34 +00:00
|
|
|
exit(1);
|
2013-01-24 16:39:38 +00:00
|
|
|
}
|
|
|
|
|
2013-03-25 02:06:34 +00:00
|
|
|
Platform.ToggleFullscreen(SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen);
|
|
|
|
|
|
|
|
window_handle = (void *)GLWin.native_window;
|
2012-12-17 21:01:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cInterfaceEGL::MakeCurrent()
|
|
|
|
{
|
|
|
|
return eglMakeCurrent(GLWin.egl_dpy, GLWin.egl_surf, GLWin.egl_surf, GLWin.egl_ctx);
|
|
|
|
}
|
|
|
|
// Close backend
|
|
|
|
void cInterfaceEGL::Shutdown()
|
|
|
|
{
|
2013-03-25 02:06:34 +00:00
|
|
|
Platform.DestroyWindow();
|
2012-12-17 21:01:52 +00:00
|
|
|
if (GLWin.egl_ctx && !eglMakeCurrent(GLWin.egl_dpy, GLWin.egl_surf, GLWin.egl_surf, GLWin.egl_ctx))
|
|
|
|
NOTICE_LOG(VIDEO, "Could not release drawing context.");
|
|
|
|
if (GLWin.egl_ctx)
|
|
|
|
{
|
2013-04-23 19:17:16 +00:00
|
|
|
eglMakeCurrent(GLWin.egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
if(!eglDestroyContext(GLWin.egl_dpy, GLWin.egl_ctx))
|
|
|
|
NOTICE_LOG(VIDEO, "Could not destroy drawing context.");
|
|
|
|
if(!eglDestroySurface(GLWin.egl_dpy, GLWin.egl_surf))
|
|
|
|
NOTICE_LOG(VIDEO, "Could not destroy window surface.");
|
|
|
|
if(!eglTerminate(GLWin.egl_dpy))
|
|
|
|
NOTICE_LOG(VIDEO, "Could not destroy display connection.");
|
2012-12-17 21:01:52 +00:00
|
|
|
GLWin.egl_ctx = NULL;
|
|
|
|
}
|
|
|
|
}
|