From c1162678bb5783d4b10b919de86726141019a918 Mon Sep 17 00:00:00 2001 From: offtkp Date: Tue, 28 Nov 2023 13:26:07 +0200 Subject: [PATCH] Cleanup jni_driver --- patch.patch | 118 ------------------ src/jni_driver.cpp | 76 +++++------ .../panda3ds/pandroid/app/GameActivity.java | 2 +- 3 files changed, 39 insertions(+), 157 deletions(-) delete mode 100644 patch.patch diff --git a/patch.patch b/patch.patch deleted file mode 100644 index 98cad32b7..000000000 --- a/patch.patch +++ /dev/null @@ -1,118 +0,0 @@ -diff --git a/src/host_shaders/opengl_display.frag b/src/host_shaders/opengl_display.frag -index 612671c8..1937f711 100644 ---- a/src/host_shaders/opengl_display.frag -+++ b/src/host_shaders/opengl_display.frag -@@ -1,4 +1,5 @@ --#version 410 core -+#version 300 es -+precision mediump float; - in vec2 UV; - out vec4 FragColor; - -diff --git a/src/host_shaders/opengl_display.vert b/src/host_shaders/opengl_display.vert -index 990e2f80..6917c23c 100644 ---- a/src/host_shaders/opengl_display.vert -+++ b/src/host_shaders/opengl_display.vert -@@ -1,4 +1,4 @@ --#version 410 core -+#version 300 es - out vec2 UV; - - void main() { -diff --git a/src/host_shaders/opengl_fragment_shader.frag b/src/host_shaders/opengl_fragment_shader.frag -index f6fa6c55..b0850438 100644 ---- a/src/host_shaders/opengl_fragment_shader.frag -+++ b/src/host_shaders/opengl_fragment_shader.frag -@@ -1,4 +1,5 @@ --#version 410 core -+#version 300 es -+precision mediump float; - - in vec3 v_tangent; - in vec3 v_normal; -@@ -27,7 +28,7 @@ uniform bool u_depthmapEnable; - uniform sampler2D u_tex0; - uniform sampler2D u_tex1; - uniform sampler2D u_tex2; --uniform sampler1DArray u_tex_lighting_lut; -+// uniform sampler1DArray u_tex_lighting_lut; - - uniform uint u_picaRegs[0x200 - 0x48]; - -@@ -145,9 +146,15 @@ vec4 tevCalculateCombiner(int tev_id) { - #define RR_LUT 6u - - float lutLookup(uint lut, uint light, float value) { -- if (lut >= FR_LUT && lut <= RR_LUT) lut -= 1; -- if (lut == SP_LUT) lut = light + 8; -- return texture(u_tex_lighting_lut, vec2(value, lut)).r; -+ // if (lut >= FR_LUT && lut <= RR_LUT) lut -= 1; -+ // if (lut == SP_LUT) lut = light + 8; -+ // return texture(u_tex_lighting_lut, vec2(value, lut)).r; -+ return 0.0; -+} -+ -+uint bitfieldExtract(uint val, int off, int size) { -+ uint mask = uint((1 << size) - 1); -+ return uint(val >> off) & mask; - } - - vec3 regToColor(uint reg) { -diff --git a/src/host_shaders/opengl_vertex_shader.vert b/src/host_shaders/opengl_vertex_shader.vert -index a25d7a6d..5967ccd6 100644 ---- a/src/host_shaders/opengl_vertex_shader.vert -+++ b/src/host_shaders/opengl_vertex_shader.vert -@@ -1,4 +1,4 @@ --#version 410 core -+#version 300 es - - layout(location = 0) in vec4 a_coords; - layout(location = 1) in vec4 a_quaternion; -@@ -20,7 +20,7 @@ out vec2 v_texcoord2; - flat out vec4 v_textureEnvColor[6]; - flat out vec4 v_textureEnvBufferColor; - --out float gl_ClipDistance[2]; -+// out float gl_ClipDistance[2]; - - // TEV uniforms - uniform uint u_textureEnvColor[6]; -@@ -93,6 +93,6 @@ void main() { - ); - - // There's also another, always-on clipping plane based on vertex z -- gl_ClipDistance[0] = -a_coords.z; -- gl_ClipDistance[1] = dot(clipData, a_coords); -+ // gl_ClipDistance[0] = -a_coords.z; -+ // gl_ClipDistance[1] = dot(clipData, a_coords); - } -diff --git a/third_party/opengl/opengl.hpp b/third_party/opengl/opengl.hpp -index f368f573..5ead7f63 100644 ---- a/third_party/opengl/opengl.hpp -+++ b/third_party/opengl/opengl.hpp -@@ -520,21 +520,21 @@ namespace OpenGL { - static void enableBlend() { glEnable(GL_BLEND); } - static void disableBlend() { glDisable(GL_BLEND); } - static void enableLogicOp() { glEnable(GL_COLOR_LOGIC_OP); } -- static void disableLogicOp() { glDisable(GL_COLOR_LOGIC_OP); } -+ static void disableLogicOp() { /* glDisable(GL_COLOR_LOGIC_OP); */ } - static void enableDepth() { glEnable(GL_DEPTH_TEST); } - static void disableDepth() { glDisable(GL_DEPTH_TEST); } - static void enableStencil() { glEnable(GL_STENCIL_TEST); } - static void disableStencil() { glDisable(GL_STENCIL_TEST); } - -- static void enableClipPlane(GLuint index) { glEnable(GL_CLIP_DISTANCE0 + index); } -- static void disableClipPlane(GLuint index) { glDisable(GL_CLIP_DISTANCE0 + index); } -+ static void enableClipPlane(GLuint index) { /* glEnable(GL_CLIP_DISTANCE0 + index); */ } -+ static void disableClipPlane(GLuint index) { /* glDisable(GL_CLIP_DISTANCE0 + index); */ } - - static void setDepthFunc(DepthFunc func) { glDepthFunc(static_cast(func)); } - static void setColourMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a) { glColorMask(r, g, b, a); } - static void setDepthMask(GLboolean mask) { glDepthMask(mask); } - - // TODO: Add a proper enum for this -- static void setLogicOp(GLenum op) { glLogicOp(op); } -+ static void setLogicOp(GLenum op) { /* glLogicOp(op); */ } - - enum Primitives { - Triangle = GL_TRIANGLES, diff --git a/src/jni_driver.cpp b/src/jni_driver.cpp index 5cd519e6d..422096d88 100644 --- a/src/jni_driver.cpp +++ b/src/jni_driver.cpp @@ -1,74 +1,74 @@ +#include +#include #include + #include -#include -#include -#include "renderer_gl/renderer_gl.hpp" + #include "emulator.hpp" +#include "renderer_gl/renderer_gl.hpp" +#include "services/hid.hpp" std::unique_ptr emulator = nullptr; +HIDService* hidService = nullptr; RendererGL* renderer = nullptr; bool romLoaded = false; extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_Initialize(JNIEnv* env, jobject obj) { - emulator = std::make_unique(); - if (emulator->getRendererType() != RendererType::OpenGL) { - throw std::runtime_error("Renderer is not OpenGL"); - } - renderer = static_cast(emulator->getRenderer()); - __android_log_print(ANDROID_LOG_INFO, "AlberDriver", "OpenGL ES Before %d.%d", GLVersion.major, GLVersion.minor); - if (!gladLoadGLES2Loader(reinterpret_cast(eglGetProcAddress))) { + emulator = std::make_unique(); + + if (emulator->getRendererType() != RendererType::OpenGL) { + throw std::runtime_error("Renderer is not OpenGL"); + } + + renderer = static_cast(emulator->getRenderer()); + hidService = &emulator->getServiceManager().getHID(); + + if (!gladLoadGLES2Loader(reinterpret_cast(eglGetProcAddress))) { throw std::runtime_error("OpenGL ES init failed"); } - __android_log_print(ANDROID_LOG_INFO, "AlberDriver", "OpenGL ES %d.%d", GLVersion.major, GLVersion.minor); + + __android_log_print(ANDROID_LOG_INFO, "AlberDriver", "OpenGL ES %d.%d", GLVersion.major, GLVersion.minor); emulator->initGraphicsContext(nullptr); } extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_RunFrame(JNIEnv* env, jobject obj, jint fbo) { - renderer->setFBO(fbo); - renderer->resetStateManager(); - emulator->runFrame(); - - emulator->getServiceManager().getHID().updateInputs(emulator->getTicks()); + renderer->setFBO(fbo); + renderer->resetStateManager(); + emulator->runFrame(); + + hidService->updateInputs(emulator->getTicks()); } extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_Finalize(JNIEnv* env, jobject obj) { - emulator = nullptr; - renderer = nullptr; + emulator = nullptr; + hidService = nullptr; + renderer = nullptr; } -extern "C" JNIEXPORT jboolean JNICALL Java_com_panda3ds_pandroid_AlberDriver_HasRomLoaded(JNIEnv* env, jobject obj) { - return romLoaded; -} +extern "C" JNIEXPORT jboolean JNICALL Java_com_panda3ds_pandroid_AlberDriver_HasRomLoaded(JNIEnv* env, jobject obj) { return romLoaded; } extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_LoadRom(JNIEnv* env, jobject obj, jstring path) { - const char* pathStr = env->GetStringUTFChars(path, nullptr); - __android_log_print(ANDROID_LOG_INFO, "AlberDriver", "Loading ROM %s", pathStr); - romLoaded = emulator->loadROM(pathStr); - env->ReleaseStringUTFChars(path, pathStr); + const char* pathStr = env->GetStringUTFChars(path, nullptr); + __android_log_print(ANDROID_LOG_INFO, "AlberDriver", "Loading ROM %s", pathStr); + romLoaded = emulator->loadROM(pathStr); + env->ReleaseStringUTFChars(path, pathStr); } - - extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_TouchScreenDown(JNIEnv* env, jobject obj, jint x, jint y) { - emulator->getServiceManager().getHID().setTouchScreenPress((u16)x, (u16)y); -} - -extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_TouchScreenUp(JNIEnv* env, jobject obj) { - emulator->getServiceManager().getHID().releaseTouchScreen(); + hidService->setTouchScreenPress((u16)x, (u16)y); } +extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_TouchScreenUp(JNIEnv* env, jobject obj) { hidService->releaseTouchScreen(); } extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_KeyUp(JNIEnv* env, jobject obj, jint keyCode) { - emulator->getServiceManager().getHID().releaseKey((u32)keyCode); + hidService->releaseKey((u32)keyCode); } extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_KeyDown(JNIEnv* env, jobject obj, jint keyCode) { - emulator->getServiceManager().getHID().pressKey((u32)keyCode); + hidService->pressKey((u32)keyCode); } extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_SetCirclepadAxis(JNIEnv* env, jobject obj, jint x, jint y) { - emulator->getServiceManager().getHID().setCirclepadX((s16)x); - emulator->getServiceManager().getHID().setCirclepadY((s16)y); + hidService->setCirclepadX((s16)x); + hidService->setCirclepadY((s16)y); } - - diff --git a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java index 275797fbb..60fe87248 100644 --- a/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java +++ b/src/pandroid/app/src/main/java/com/panda3ds/pandroid/app/GameActivity.java @@ -38,7 +38,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { return; } - pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.EXTRA_PATH));; + pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.EXTRA_PATH)); setContentView(R.layout.game_activity);