diff --git a/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt index 46106ff61009..24f5423c690f 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt @@ -69,7 +69,6 @@ import org.citra.citra_emu.utils.GameIconUtils import org.citra.citra_emu.utils.EmulationLifecycleUtil import org.citra.citra_emu.utils.Log import org.citra.citra_emu.utils.ViewUtils -import org.citra.citra_emu.vendor.simongellis.leia.webxr.LeiaSurfaceView import org.citra.citra_emu.viewmodel.EmulationViewModel class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.FrameCallback { @@ -866,7 +865,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) { Log.debug("[EmulationFragment] Surface changed. Resolution: " + width + "x" + height) - emulationState.newSurface(binding.surfaceEmulation.holder.surface) + emulationState.newSurface(holder.surface) } override fun surfaceDestroyed(holder: SurfaceHolder) { diff --git a/src/android/app/src/main/java/org/citra/citra_emu/vendor/simongellis/leia/webxr/LeiaSurfaceView.kt b/src/android/app/src/main/java/org/citra/citra_emu/vendor/simongellis/leia/webxr/LeiaSurfaceView.kt index c79409fcda3c..90e048f35dc8 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/vendor/simongellis/leia/webxr/LeiaSurfaceView.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/vendor/simongellis/leia/webxr/LeiaSurfaceView.kt @@ -3,14 +3,16 @@ package org.citra.citra_emu.vendor.simongellis.leia.webxr import android.content.Context import android.graphics.SurfaceTexture import android.util.AttributeSet +import android.util.Log import com.leia.sdk.views.InputViewsAsset import com.leia.sdk.views.InterlacedSurfaceView -open class LeiaSurfaceView(context: Context, attrs: AttributeSet) : InterlacedSurfaceView(context, attrs) { +class LeiaSurfaceView(context: Context, attrs: AttributeSet) : InterlacedSurfaceView(context, attrs) { private val textureRenderer = LeiaTextureRenderer() private val asset = InputViewsAsset(RendererImpl(textureRenderer)) init { + Log.i("LeiaSurfaceView", "init") setViewAsset(asset) } diff --git a/src/android/app/src/main/jni/default_ini.h b/src/android/app/src/main/jni/default_ini.h index a2cd02c8595d..b80c73fa1432 100644 --- a/src/android/app/src/main/jni/default_ini.h +++ b/src/android/app/src/main/jni/default_ini.h @@ -155,12 +155,12 @@ bg_blue = bg_green = # Whether and how Stereoscopic 3D should be rendered -# 0 (default): Off, 1: Side by Side, 2: Anaglyph, 3: Interlaced, 4: Reverse Interlaced, 5: Cardboard VR -render_3d = +# 0 (default): Off, 1: Side by Side, 2: Anaglyph, 3: Interlaced, 4: Reverse Interlaced, 5: Cardboard VR, 6: Lumepad 1, 7: Lumepad 2 +render_3d = 7 # Change 3D Intensity # 0 - 100: Intensity. 0 (default) -factor_3d = +factor_3d = 50 # The name of the post processing shader to apply. # Loaded from shaders if render_3d is off or side by side. diff --git a/src/android/app/src/main/jni/emu_window/emu_window.cpp b/src/android/app/src/main/jni/emu_window/emu_window.cpp index 436442acd98d..bbf887cd151a 100644 --- a/src/android/app/src/main/jni/emu_window/emu_window.cpp +++ b/src/android/app/src/main/jni/emu_window/emu_window.cpp @@ -83,7 +83,11 @@ EmuWindow_Android::~EmuWindow_Android() { } void EmuWindow_Android::MakeCurrent() { - core_context->MakeCurrent(); + try { + core_context->MakeCurrent(); + } catch (const std::exception& e) { + LOG_DEBUG(Frontend, "Exception caught in MakeCurrent: {}", e.what()); + } } void EmuWindow_Android::DoneCurrent() { diff --git a/src/android/app/src/main/jni/emu_window/emu_window_gl.cpp b/src/android/app/src/main/jni/emu_window/emu_window_gl.cpp index f3bb97dc34fb..5a820aced04a 100644 --- a/src/android/app/src/main/jni/emu_window/emu_window_gl.cpp +++ b/src/android/app/src/main/jni/emu_window/emu_window_gl.cpp @@ -75,11 +75,11 @@ class SharedContext_Android : public Frontend::GraphicsContext { EmuWindow_Android_OpenGL::EmuWindow_Android_OpenGL(Core::System& system_, ANativeWindow* surface) : EmuWindow_Android{surface}, system{system_} { if (egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); egl_display == EGL_NO_DISPLAY) { - LOG_CRITICAL(Frontend, "eglGetDisplay() failed"); + LOG_CRITICAL(Frontend, "eglGetDisplay() failed 1"); return; } if (eglInitialize(egl_display, 0, 0) != EGL_TRUE) { - LOG_CRITICAL(Frontend, "eglInitialize() failed"); + LOG_CRITICAL(Frontend, "eglInitialize() failed 2"); return; } if (EGLint egl_num_configs{}; eglChooseConfig(egl_display, egl_attribs.data(), &egl_config, 1, @@ -99,12 +99,12 @@ EmuWindow_Android_OpenGL::EmuWindow_Android_OpenGL(Core::System& system_, ANativ if (egl_context = eglCreateContext(egl_display, egl_config, 0, egl_context_attribs.data()); egl_context == EGL_NO_CONTEXT) { - LOG_CRITICAL(Frontend, "eglCreateContext() failed"); + LOG_CRITICAL(Frontend, "eglCreateContext() failed a"); return; } if (eglSurfaceAttrib(egl_display, egl_surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED) != EGL_TRUE) { - LOG_CRITICAL(Frontend, "eglSurfaceAttrib() failed"); + LOG_CRITICAL(Frontend, "eglSurfaceAttrib() failed b"); return; } if (core_context = CreateSharedContext(); !core_context) { @@ -136,12 +136,20 @@ bool EmuWindow_Android_OpenGL::CreateWindowSurface() { eglGetConfigAttrib(egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(host_window, 0, 0, format); - if (egl_surface = eglCreateWindowSurface(egl_display, egl_config, host_window, 0); - egl_surface == EGL_NO_SURFACE) { - return {}; + // Check if a surface already exists and destroy it + if (egl_surface != EGL_NO_SURFACE) { + eglDestroySurface(egl_display, egl_surface); } - return egl_surface; + egl_surface = eglCreateWindowSurface(egl_display, egl_config, host_window, nullptr); + + if (egl_surface == EGL_NO_SURFACE) { + EGLint error = eglGetError(); // Get the error code + LOG_CRITICAL(Frontend, "EmuWindow_Android_OpenGL eglCreateWindowSurface() returned error {}", error); + return true; + } + + return true; } void EmuWindow_Android_OpenGL::DestroyWindowSurface() { diff --git a/src/android/app/src/main/res/values/arrays.xml b/src/android/app/src/main/res/values/arrays.xml index cd542bae8130..4b78844c9bdb 100644 --- a/src/android/app/src/main/res/values/arrays.xml +++ b/src/android/app/src/main/res/values/arrays.xml @@ -141,6 +141,8 @@ @string/interlaced @string/reverse_interlaced @string/cardboard_vr + @string/lumepad_1 + @string/lumepad_2 @@ -150,6 +152,8 @@ 3 4 5 + 6 + 7 @@ -450,5 +454,4 @@ 11 12 - diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index a7caab91f329..77a4efddc6c3 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -236,6 +236,8 @@ Depth Specifies the value of the 3D slider. This should be set to higher than 0% when Stereoscopic 3D is enabled. Cardboard VR + Lumepad 2 / Nubia Pad 3D + Lumepad 1 Cardboard Screen Size Scales the screen to a percentage of its original size. Horizontal Shift