diff --git a/CMakeLists.txt b/CMakeLists.txt index 29e41047a1..69aa385504 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 2.6) option(ANDROID "Enables a build for Android" OFF) option(USE_EGL "Enables EGL OpenGL Interface" OFF) +option(USE_X11 "Enables X11 Support" ON) +option(USE_WAYLAND "Enables Wayland Support" OFF) option(USE_GLES "Enables GLES And EGL, disables OGL" OFF) option(DISABLE_WX "Disable wxWidgets (use CLI interface)" OFF) @@ -263,16 +265,28 @@ if(USE_GLES) add_definitions(-DUSE_EGL=1) set(USE_EGL True) endif() +# For now Wayland and EGL are tied to each other. +# The alternative would be an shm path +if(USE_WAYLAND) + add_definitions(-DUSE_EGL) + set(USE_EGL 1) +endif() if(USE_EGL) message("EGL OpenGL interface enabled") add_definitions(-DUSE_EGL=1) +else() +# Using GLX + set(USE_X11 1) + set(USE_WAYLAND 0) endif() add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE) if(ANDROID) message("Building for Android") add_definitions(-DANDROID) + set(USE_X11 0) + set(USE_WAYLAND 0) endif() ######################################## # Dependency checking @@ -348,29 +362,53 @@ if(NOT ANDROID) message("OpenAL NOT found, disabling OpenAL sound backend") endif(OPENAL_FOUND) + if(UNIX AND NOT APPLE) +# Note: The convention is to check USE_X11 or USE_WAYLAND where needed. +# This is where we detect platforms and set the variables accordingly. + pkg_check_modules(WAYLAND wayland-egl wayland-client wayland-cursor) + if(USE_WAYLAND AND WAYLAND_FOUND) + pkg_check_modules(XKBCOMMON xkbcommon) + if(XKBCOMMON_FOUND) + set(USE_WAYLAND 1) + add_definitions(-DHAVE_WAYLAND) + include_directories(${WAYLAND_INCLUDE_DIR}) + message("Wayland support enabled") + endif(XKBCOMMON_FOUND) + else() + set(USE_WAYLAND 0) + message("Wayland support disabled") + add_definitions(-DHAVE_WAYLAND=0) + endif(USE_WAYLAND AND WAYLAND_FOUND) + # Note: We do not need to explicitly check for X11 as it is done in the cmake # FindOpenGL module on linux. - if(UNIX AND NOT APPLE) - if(X11_FOUND) + if(USE_X11 AND X11_FOUND) + set(USE_X11 1) add_definitions(-DHAVE_X11=1) include_directories(${X11_INCLUDE_DIR}) - message("X11 found") + message("X11 support enabled") else() - message(FATAL_ERROR "X11 is required but not found") - endif(X11_FOUND) - else() - add_definitions(-DHAVE_X11=0) + set(USE_X11 0) + SET(X11_FOUND "") + message("X11 support disabled") + add_definitions(-DHAVE_X11=0) + endif(USE_X11 AND X11_FOUND) + + if (NOT USE_WAYLAND AND NOT USE_X11) + message(FATAL_ERROR "\n" + "No suitable display platform found\n" + "Requires wayland or x11 to run") + endif() endif() - if(X11_FOUND) + if(USE_X11) check_lib(XRANDR Xrandr) + if(XRANDR_FOUND) + add_definitions(-DHAVE_XRANDR=1) + else() + add_definitions(-DHAVE_XRANDR=0) + endif(XRANDR_FOUND) endif() - if(XRANDR_FOUND) - add_definitions(-DHAVE_XRANDR=1) - else() - add_definitions(-DHAVE_XRANDR=0) - endif(XRANDR_FOUND) - if(ENCODE_FRAMEDUMPS) check_libav() endif() diff --git a/Source/Android/AndroidManifest.xml b/Source/Android/AndroidManifest.xml index e22370dd16..5da904401f 100644 --- a/Source/Android/AndroidManifest.xml +++ b/Source/Android/AndroidManifest.xml @@ -24,6 +24,12 @@ + + diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java b/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java index f95195b53e..249ec33703 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/DolphinEmulator.java @@ -18,7 +18,6 @@ import android.view.WindowManager; public class DolphinEmulator extends Activity { static private NativeGLSurfaceView GLview = null; - static private NativeRenderer Renderer = null; static private boolean Running = false; private float screenWidth; @@ -42,21 +41,21 @@ public class DolphinEmulator extends Activity { { super.onStop(); if (Running) - Renderer.StopEmulation(); + NativeGLSurfaceView.StopEmulation(); } @Override public void onPause() { super.onPause(); if (Running) - Renderer.PauseEmulation(); + NativeGLSurfaceView.PauseEmulation(); } @Override public void onResume() { super.onResume(); if (Running) - Renderer.UnPauseEmulation(); + NativeGLSurfaceView.UnPauseEmulation(); } /** Called when the activity is first created. */ @@ -84,15 +83,10 @@ public class DolphinEmulator extends Activity { screenWidth = displayMetrics.widthPixels; screenHeight = displayMetrics.heightPixels; - String FileName = data.getStringExtra("Select"); - Renderer = new NativeRenderer(); - Renderer.setContext(getApplicationContext()); - GLview = new NativeGLSurfaceView(this); - GLview.setEGLContextClientVersion(2); - GLview.setRenderer(Renderer); + GLview.SetDimensions(screenWidth, screenHeight); GLview.SetFileName(FileName); setContentView(GLview); Running = true; @@ -108,10 +102,10 @@ public class DolphinEmulator extends Activity { Y = event.getY(); Action = event.getActionMasked(); - int Button = Renderer.ButtonPressed(Action, ((X / screenWidth) * 2.0f) - 1.0f, ((Y / screenHeight) * 2.0f) - 1.0f); + //int Button = Renderer.ButtonPressed(Action, ((X / screenWidth) * 2.0f) - 1.0f, ((Y / screenHeight) * 2.0f) - 1.0f); - if (Button != -1) - SetKey(Action, Button); + //if (Button != -1) + //SetKey(Action, Button); return false; } diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/NativeGLSurfaceView.java b/Source/Android/src/org/dolphinemu/dolphinemu/NativeGLSurfaceView.java index 0babd5b919..22cba8a4e9 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/NativeGLSurfaceView.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/NativeGLSurfaceView.java @@ -5,14 +5,21 @@ import android.opengl.GLSurfaceView; import android.util.Log; import android.view.Surface; import android.view.SurfaceHolder; +import android.view.SurfaceView; -public class NativeGLSurfaceView extends GLSurfaceView { +public class NativeGLSurfaceView extends SurfaceView { static private String FileName; static private Thread myRun; static private boolean Running = false; static private boolean Created = false; + static private float width; + static private float height; - public static native void main(String File, Surface surf); + public static native void main(String File, Surface surf, int width, int height); + + public static native void UnPauseEmulation(); + public static native void PauseEmulation(); + public static native void StopEmulation(); static { @@ -35,27 +42,41 @@ public class NativeGLSurfaceView extends GLSurfaceView { { @Override public void run() { - main(FileName, getHolder().getSurface()); + main(FileName, getHolder().getSurface(), (int)width, (int)height); } }; + getHolder().addCallback(new SurfaceHolder.Callback() { + + + public void surfaceCreated(SurfaceHolder holder) { + // TODO Auto-generated method stub + myRun.start(); + } + + public void surfaceChanged(SurfaceHolder arg0, int arg1, + int arg2, int arg3) { + // TODO Auto-generated method stub + + } + + public void surfaceDestroyed(SurfaceHolder arg0) { + // TODO Auto-generated method stub + + } + }); Created = true; } } - public void surfaceCreated(SurfaceHolder holder) - { - super.surfaceCreated(holder); - if (!Running) - { - myRun.start(); - Running = true; - } - } - public void SetFileName(String file) { FileName = file; } + public void SetDimensions(float screenWidth, float screenHeight) + { + width = screenWidth; + height = screenHeight; + } } diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/NativeRenderer.java b/Source/Android/src/org/dolphinemu/dolphinemu/NativeRenderer.java index f802cd2b55..031d9aff17 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/NativeRenderer.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/NativeRenderer.java @@ -33,9 +33,6 @@ public class NativeRenderer implements GLSurfaceView.Renderer { public static native void DrawButton(int GLTex, int ID); public static native void SetButtonCoords(float[] Coords); public static native void PrepareME(); - public static native void UnPauseEmulation(); - public static native void PauseEmulation(); - public static native void StopEmulation(); // Texture loading private static int buttonA = -1; diff --git a/Source/Core/Common/Src/MemArena.cpp b/Source/Core/Common/Src/MemArena.cpp index 26ce81f578..76f2e48548 100644 --- a/Source/Core/Common/Src/MemArena.cpp +++ b/Source/Core/Common/Src/MemArena.cpp @@ -153,7 +153,12 @@ u8* MemArena::Find4GBBase() } return base; #else - void* base = mmap(0, 0x31000000, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); +#ifdef ANDROID + const u32 MemSize = 0x04000000; +#else + const u32 MemSize = 0x31000000; +#endif + void* base = mmap(0, MemSize, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); if (base == MAP_FAILED) { PanicAlert("Failed to map 1 GB of memory space: %s", strerror(errno)); return 0; diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index 1256890eb5..ebee7299db 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -7,10 +7,19 @@ set(LIBS core audiocommon z sfml-network - ${GTK2_LIBRARIES} - ${XRANDR_LIBRARIES} - ${X11_LIBRARIES}) + ${GTK2_LIBRARIES}) if(NOT ANDROID) + if(USE_X11) + set(LIBS ${LIBS} ${X11_LIBRARIES} + ${XRANDR_LIBRARIES}) + endif() + if(USE_WAYLAND) + set(LIBS ${LIBS} ${WAYLAND_LIBRARIES} + ${XKBCOMMON_LIBRARIES}) + endif() + + link_directories(${CMAKE_PREFIX_PATH}/lib) + if(SDL2_FOUND) # Using shared SDL2 set(LIBS ${LIBS} ${SDL2_LIBRARY}) @@ -87,13 +96,17 @@ else() endif() if(USE_EGL) - if(NOT ANDROID) - set(SRCS ${SRCS} Src/GLInterface/EGL_X11.cpp - Src/GLInterface/X11_Util.cpp) + set(SRCS ${SRCS} Src/GLInterface/Platform.cpp + Src/GLInterface/EGL.cpp) + if(USE_WAYLAND) + set(SRCS ${SRCS} Src/GLInterface/Wayland_Util.cpp) + endif() + if(USE_X11) + set(SRCS ${SRCS} Src/GLInterface/X11_Util.cpp) endif() else() if(WIN32) - set(SRCS ${SRCS} Src/GLInterface/GLW.cpp) + set(SRCS ${SRCS} Src/GLInterface/WGL.cpp) elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(SRCS ${SRCS} Src/GLInterface/AGL.cpp) else() @@ -127,10 +140,8 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") list(APPEND SRCS ${RESOURCES}) set_source_files_properties(${RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) -else() - if(NOT ANDROID) - set(SRCS ${SRCS} Src/X11Utils.cpp) - endif() +elseif(USE_X11) + set(SRCS ${SRCS} Src/X11Utils.cpp) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR diff --git a/Source/Core/DolphinWX/Src/GLInterface.h b/Source/Core/DolphinWX/Src/GLInterface.h index c58e0c5ecb..da74646f1b 100644 --- a/Source/Core/DolphinWX/Src/GLInterface.h +++ b/Source/Core/DolphinWX/Src/GLInterface.h @@ -17,14 +17,18 @@ #ifndef _GLINTERFACE_H_ #define _GLINTERFACE_H_ +#if USE_EGL +#include "GLInterface/Platform.h" +#else + #include "Thread.h" #ifdef ANDROID #include #include #include -#include +#include "GLInterface/EGL.h" #elif defined(USE_EGL) && USE_EGL -#include "GLInterface/EGL_X11.h" +#include "GLInterface/EGL.h" #elif defined(__APPLE__) #include "GLInterface/AGL.h" #elif defined(_WIN32) @@ -36,19 +40,11 @@ #endif typedef struct { -#ifdef ANDROID -#elif defined(USE_EGL) && USE_EGL // This is currently a X11/EGL implementation for desktop +#if defined(USE_EGL) && USE_EGL // This is currently a X11/EGL implementation for desktop int screen; - Display *dpy; - Display *evdpy; - Window win; - Window parent; EGLSurface egl_surf; EGLContext egl_ctx; EGLDisplay egl_dpy; - XVisualInfo *vi; - XSetWindowAttributes attr; - std::thread xEventThread; int x, y; unsigned int width, height; #elif defined(__APPLE__) @@ -74,3 +70,4 @@ extern cInterfaceBase *GLInterface; extern GLWindow GLWin; #endif +#endif diff --git a/Source/Core/DolphinWX/Src/GLInterface/EGL_X11.cpp b/Source/Core/DolphinWX/Src/GLInterface/EGL.cpp similarity index 54% rename from Source/Core/DolphinWX/Src/GLInterface/EGL_X11.cpp rename to Source/Core/DolphinWX/Src/GLInterface/EGL.cpp index ccb2fc04b8..a419a2d7dc 100644 --- a/Source/Core/DolphinWX/Src/GLInterface/EGL_X11.cpp +++ b/Source/Core/DolphinWX/Src/GLInterface/EGL.cpp @@ -19,59 +19,30 @@ #include "RenderBase.h" #include "../GLInterface.h" -#include "EGL_X11.h" +#include "EGL.h" // Show the current FPS void cInterfaceEGL::UpdateFPSDisplay(const char *text) { - XStoreName(GLWin.dpy, GLWin.win, text); + Platform.UpdateFPSDisplay(text); } - -void cInterfaceEGL::SwapInterval(int Interval) -{ - eglSwapInterval(GLWin.egl_dpy, Interval); -} - void cInterfaceEGL::Swap() { eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf); } +void cInterfaceEGL::SwapInterval(int Interval) +{ + eglSwapInterval(GLWin.egl_dpy, Interval); +} // Create rendering window. // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() bool cInterfaceEGL::Create(void *&window_handle) { - int _tx, _ty, _twidth, _theight; - Host_GetRenderWindowSize(_tx, _ty, _twidth, _theight); - - // Control window size and picture scaling - s_backbuffer_width = _twidth; - s_backbuffer_height = _theight; - + const char *s; EGLint egl_major, egl_minor; - - GLWin.dpy = XOpenDisplay(NULL); - - if (!GLWin.dpy) { - ERROR_LOG(VIDEO, "Error: couldn't open display\n"); - return false; - } - - GLWin.egl_dpy = eglGetDisplay(GLWin.dpy); - if (!GLWin.egl_dpy) { - ERROR_LOG(VIDEO, "Error: eglGetDisplay() failed\n"); - return false; - } - - if (!eglInitialize(GLWin.egl_dpy, &egl_major, &egl_minor)) { - ERROR_LOG(VIDEO, "Error: eglInitialize() failed\n"); - return false; - } - - INFO_LOG(VIDEO, "EGL_VERSION = %s\n", eglQueryString(GLWin.egl_dpy, EGL_VERSION)); - INFO_LOG(VIDEO, "EGL_VENDOR = %s\n", eglQueryString(GLWin.egl_dpy, EGL_VENDOR)); - INFO_LOG(VIDEO, "EGL_EXTENSIONS = %s\n", eglQueryString(GLWin.egl_dpy, EGL_EXTENSIONS)); - INFO_LOG(VIDEO, "EGL_CLIENT_APIS = %s\n", eglQueryString(GLWin.egl_dpy, EGL_CLIENT_APIS)); + EGLConfig config; + EGLint num_configs; // attributes for a visual in RGBA format with at least // 8 bits per color and a 24 bit depth buffer @@ -93,70 +64,79 @@ bool cInterfaceEGL::Create(void *&window_handle) #endif EGL_NONE }; - - GLWin.evdpy = XOpenDisplay(NULL); - GLWin.parent = (Window)window_handle; - GLWin.screen = DefaultScreen(GLWin.dpy); - if (GLWin.parent == 0) - GLWin.parent = RootWindow(GLWin.dpy, GLWin.screen); - XVisualInfo visTemplate; - int num_visuals; - EGLConfig config; - EGLint num_configs; - EGLint vid; + if(!Platform.SelectDisplay()) + return false; - if (!eglChooseConfig( GLWin.egl_dpy, attribs, &config, 1, &num_configs)) { - ERROR_LOG(VIDEO, "Error: couldn't get an EGL visual config\n"); + GLWin.egl_dpy = Platform.EGLGetDisplay(); + + if (!GLWin.egl_dpy) { + printf("Error: eglGetDisplay() failed\n"); return false; } - if (!eglGetConfigAttrib(GLWin.egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { - ERROR_LOG(VIDEO, "Error: eglGetConfigAttrib() failed\n"); + GLWin.platform = Platform.platform; + + if (!eglInitialize(GLWin.egl_dpy, &egl_major, &egl_minor)) { + printf("Error: eglInitialize() failed\n"); return false; } - /* The X window visual must match the EGL config */ - visTemplate.visualid = vid; - GLWin.vi = XGetVisualInfo(GLWin.dpy, VisualIDMask, &visTemplate, &num_visuals); - if (!GLWin.vi) { - ERROR_LOG(VIDEO, "Error: couldn't get X visual\n"); - return false; - } - - GLWin.x = _tx; - GLWin.y = _ty; - GLWin.width = _twidth; - GLWin.height = _theight; - - XWindow.CreateXWindow(); #ifdef USE_GLES eglBindAPI(EGL_OPENGL_ES_API); #else eglBindAPI(EGL_OPENGL_API); #endif - GLWin.egl_ctx = eglCreateContext(GLWin.egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); - if (!GLWin.egl_ctx) { - ERROR_LOG(VIDEO, "Error: eglCreateContext failed\n"); - return false; + + if (!eglChooseConfig( GLWin.egl_dpy, attribs, &config, 1, &num_configs)) { + printf("Error: couldn't get an EGL visual config\n"); + exit(1); } - GLWin.egl_surf = eglCreateWindowSurface(GLWin.egl_dpy, config, (NativeWindowType)GLWin.win, NULL); - if (!GLWin.egl_surf) { - ERROR_LOG(VIDEO, "Error: eglCreateWindowSurface failed\n"); + if (!Platform.Init(config)) return false; + + s = eglQueryString(GLWin.egl_dpy, EGL_VERSION); + printf("EGL_VERSION = %s\n", s); + + s = eglQueryString(GLWin.egl_dpy, EGL_VENDOR); + printf("EGL_VENDOR = %s\n", s); + + s = eglQueryString(GLWin.egl_dpy, EGL_EXTENSIONS); + printf("EGL_EXTENSIONS = %s\n", s); + + s = eglQueryString(GLWin.egl_dpy, EGL_CLIENT_APIS); + printf("EGL_CLIENT_APIS = %s\n", s); + + GLWin.egl_ctx = eglCreateContext(GLWin.egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); + if (!GLWin.egl_ctx) { + printf("Error: eglCreateContext failed\n"); + exit(1); + } + + GLWin.native_window = Platform.CreateWindow(); + + GLWin.egl_surf = eglCreateWindowSurface(GLWin.egl_dpy, config, + GLWin.native_window, NULL); + if (!GLWin.egl_surf) { + printf("Error: eglCreateWindowSurface failed\n"); + exit(1); } if (!eglMakeCurrent(GLWin.egl_dpy, GLWin.egl_surf, GLWin.egl_surf, GLWin.egl_ctx)) { - ERROR_LOG(VIDEO, "Error: eglMakeCurrent() failed\n"); + + printf("Error: eglMakeCurrent() failed\n"); return false; } - - INFO_LOG(VIDEO, "GL_VENDOR: %s\n", glGetString(GL_VENDOR)); - INFO_LOG(VIDEO, "GL_RENDERER: %s\n", glGetString(GL_RENDERER)); - INFO_LOG(VIDEO, "GL_VERSION: %s\n", glGetString(GL_VERSION)); - INFO_LOG(VIDEO, "GL_EXTENSIONS: %s\n", glGetString(GL_EXTENSIONS)); - window_handle = (void *)GLWin.win; + + printf("GL_VENDOR: %s\n", glGetString(GL_VENDOR)); + printf("GL_RENDERER: %s\n", glGetString(GL_RENDERER)); + printf("GL_VERSION: %s\n", glGetString(GL_VERSION)); + printf("GL_EXTENSIONS: %s\n", glGetString(GL_EXTENSIONS)); + + Platform.ToggleFullscreen(SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen); + + window_handle = (void *)GLWin.native_window; return true; } @@ -167,7 +147,7 @@ bool cInterfaceEGL::MakeCurrent() // Close backend void cInterfaceEGL::Shutdown() { - XWindow.DestroyXWindow(); + Platform.DestroyWindow(); 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) @@ -178,4 +158,3 @@ void cInterfaceEGL::Shutdown() GLWin.egl_ctx = NULL; } } - diff --git a/Source/Core/DolphinWX/Src/GLInterface/EGL_X11.h b/Source/Core/DolphinWX/Src/GLInterface/EGL.h similarity index 89% rename from Source/Core/DolphinWX/Src/GLInterface/EGL_X11.h rename to Source/Core/DolphinWX/Src/GLInterface/EGL.h index e47573e4d8..cf218ad760 100644 --- a/Source/Core/DolphinWX/Src/GLInterface/EGL_X11.h +++ b/Source/Core/DolphinWX/Src/GLInterface/EGL.h @@ -17,24 +17,23 @@ #ifndef _INTERFACEEGL_H_ #define _INTERFACEEGL_H_ -#include -#ifdef USE_GLES +#if USE_GLES #include -#include #else #include #include #endif -#include "X11_Util.h" #include "InterfaceBase.h" +class cPlatform; + class cInterfaceEGL : public cInterfaceBase { private: - cX11Window XWindow; + cPlatform Platform; public: - friend class cX11Window; + friend class cPlatform; void SwapInterval(int Interval); void Swap(); void UpdateFPSDisplay(const char *Text); diff --git a/Source/Core/DolphinWX/Src/MainAndroid.cpp b/Source/Core/DolphinWX/Src/MainAndroid.cpp index aa6db56aa1..73befff785 100644 --- a/Source/Core/DolphinWX/Src/MainAndroid.cpp +++ b/Source/Core/DolphinWX/Src/MainAndroid.cpp @@ -39,6 +39,7 @@ #include JNIEnv *g_env = NULL; ANativeWindow* surf; +int g_width, g_height; #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "Dolphinemu", __VA_ARGS__)) bool rendererHasFocus = true; @@ -83,8 +84,8 @@ void Host_GetRenderWindowSize(int& x, int& y, int& width, int& height) { x = SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos; y = SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos; - width = SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth; - height = SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight; + width = g_width; + height = g_height; } void Host_RequestRenderWindowSize(int width, int height) {} @@ -122,18 +123,12 @@ void Host_SysMessage(const char *fmt, ...) void Host_SetWiiMoteConnectionState(int _State) {} -extern void DrawReal(); -extern void PrepareShit(); extern void DrawButton(int tex, int ID); extern void SetButtonCoords(float *Coords); #ifdef __cplusplus extern "C" { #endif -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_PrepareME(JNIEnv *env, jobject obj) -{ - PrepareShit(); -} JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_SetButtonCoords(JNIEnv *env, jobject obj, jfloatArray Coords) { jfloat* flt1 = env->GetFloatArrayElements(Coords, 0); @@ -148,33 +143,30 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_DrawButton( DrawButton((int)GLTex, (int)ID); } -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_UnPauseEmulation(JNIEnv *env, jobject obj) +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_UnPauseEmulation(JNIEnv *env, jobject obj) { PowerPC::Start(); } -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_PauseEmulation(JNIEnv *env, jobject obj) +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_PauseEmulation(JNIEnv *env, jobject obj) { PowerPC::Pause(); } -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_StopEmulation(JNIEnv *env, jobject obj) +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_StopEmulation(JNIEnv *env, jobject obj) { PowerPC::Stop(); } - -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_DrawME(JNIEnv *env, jobject obj) -{ - DrawReal(); -} JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_DolphinEmulator_SetKey(JNIEnv *env, jobject obj, jint Value, jint Key) { WARN_LOG(COMMON, "Key %d with action %d\n", (int)Key, (int)Value); KeyStates[(int)Key] = (int)Value == 0 ? true : false; } -JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_main(JNIEnv *env, jobject obj, jstring jFile, jobject _surf) +JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_main(JNIEnv *env, jobject obj, jstring jFile, jobject _surf, jint _width, jint _height) { surf = ANativeWindow_fromSurface(env, _surf); + g_width = (int)_width; + g_height = (int)_height; g_env = env; LogManager::Init(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index 4f71fb4a7d..55b1d6e52a 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -51,9 +51,7 @@ void VideoBackend::UpdateFPSDisplay(const char *text) } void InitInterface() { - #ifdef ANDROID - GLInterface = new cInterfaceBase; - #elif defined(USE_EGL) && USE_EGL + #if defined(USE_EGL) && USE_EGL GLInterface = new cInterfaceEGL; #elif defined(__APPLE__) GLInterface = new cInterfaceAGL; diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp index e81fb99206..e41d6402ff 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/SWRenderer.cpp @@ -77,10 +77,13 @@ void CreateShaders() uni_tex = glGetUniformLocation(program, "Texture"); attr_pos = glGetAttribLocation(program, "pos"); attr_tex = glGetAttribLocation(program, "TexCoordIn"); + + } -#include -void PrepareShit() + +void SWRenderer::Prepare() { + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // 4-byte pixel alignment glGenTextures(1, &s_RenderTarget); @@ -94,9 +97,6 @@ void PrepareShit() #endif GL_REPORT_ERRORD(); } -void SWRenderer::Prepare() -{ -} void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color) { @@ -135,71 +135,66 @@ void SWRenderer::DrawDebugText() p+=sprintf(p,"Rasterized Pix: %i\n",swstats.thisFrame.rasterizedPixels); p+=sprintf(p,"TEV Pix In: %i\n",swstats.thisFrame.tevPixelsIn); p+=sprintf(p,"TEV Pix Out: %i\n",swstats.thisFrame.tevPixelsOut); - } +} // Render a shadow, and then the text. SWRenderer::RenderText(debugtext_buffer, 21, 21, 0xDD000000); SWRenderer::RenderText(debugtext_buffer, 20, 20, 0xFFFFFF00); } -u8 image[1024*1024*4]; +#ifdef ANDROID float ButtonCoords[8 * 2]; -int gW, gH; -bool once = false; -std::recursive_mutex section; void SetButtonCoords(float *Coords) { - memcpy(ButtonCoords, Coords, sizeof(float) * 8 * 2); + memcpy(ButtonCoords, Coords, sizeof(float) * 8 * 2); } void DrawButton(int tex, int ID) { - //Texture rectangle uses pixel coordinates + //Texture rectangle uses pixel coordinates #ifndef USE_GLES - GLfloat u_max = (GLfloat)width; - GLfloat v_max = (GLfloat)height; + GLfloat u_max = (GLfloat)width; + GLfloat v_max = (GLfloat)height; - static const GLfloat texverts[4][2] = { - {0, v_max}, - {0, 0}, - {u_max, 0}, - {u_max, v_max} - }; + static const GLfloat texverts[4][2] = { + {0, v_max}, + {0, 0}, + {u_max, 0}, + {u_max, v_max} + }; #else - static const GLfloat texverts[4][2] = { - {0, 1}, - {0, 0}, - {1, 0}, - {1, 1} - }; + static const GLfloat texverts[4][2] = { + {0, 1}, + {0, 0}, + {1, 0}, + {1, 1} + }; #endif - glBindTexture(TEX2D, tex); + glBindTexture(TEX2D, tex); - glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, &ButtonCoords[ID * 8]); - glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, texverts); - glEnableVertexAttribArray(attr_pos); - glEnableVertexAttribArray(attr_tex); - glActiveTexture(GL_TEXTURE0); - glUniform1i(uni_tex, 0); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - glDisableVertexAttribArray(attr_pos); - glDisableVertexAttribArray(attr_tex); - - glBindTexture(TEX2D, 0); + glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, &ButtonCoords[ID * 8]); + glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, texverts); + glEnableVertexAttribArray(attr_pos); + glEnableVertexAttribArray(attr_tex); + glActiveTexture(GL_TEXTURE0); + glUniform1i(uni_tex, 0); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + glDisableVertexAttribArray(attr_pos); + glDisableVertexAttribArray(attr_tex); + glBindTexture(TEX2D, 0); } -void DrawReal() +#endif +void SWRenderer::DrawTexture(u8 *texture, int width, int height) { - section.lock(); - if (!once) - { - section.unlock(); - return; - } - int width = gW; - int height = gH; + GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth(); + GLsizei glHeight = (GLsizei)GLInterface->GetBackBufferHeight(); + + // Update GLViewPort + glViewport(0, 0, glWidth, glHeight); + glScissor(0, 0, glWidth, glHeight); glBindTexture(GL_TEXTURE_2D, s_RenderTarget); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -228,19 +223,20 @@ void DrawReal() glDisableVertexAttribArray(attr_tex); glBindTexture(GL_TEXTURE_2D, 0); - section.unlock(); GL_REPORT_ERRORD(); } -void SWRenderer::DrawTexture(u8 *texture, int width, int height) -{ - section.lock(); - memcpy(image, texture, width * height * 4); - gW = width; - gH = height; - once = true; - section.unlock(); -} void SWRenderer::SwapBuffer() { + DrawDebugText(); + + glFlush(); + + GLInterface->Swap(); + + swstats.ResetFrame(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + GL_REPORT_ERRORD(); }