Skip to content

Commit

Permalink
[Android]Add input
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBRDeveloper authored and OFFTKP committed Nov 28, 2023
1 parent 3f9c8d8 commit 62880f0
Show file tree
Hide file tree
Showing 37 changed files with 1,245 additions and 77 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/Android_Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Android Build

on:
push:
branches:
- master
pull_request:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
x64:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Fetch submodules
run: git submodule update --init --recursive

- name: Setup Vulkan SDK
uses: humbletim/[email protected]
with:
vulkan-query-version: latest
vulkan-use-cache: true
vulkan-components: Vulkan-Headers, Vulkan-Loader, SPIRV-Tools, Glslang

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '17'

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DBUILD_HYDRA_CORE=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86_64 -DENABLE_VULKAN=0

- name: Build
run: |
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
mv ./build/libAlber.so ./src/pandroid/app/src/main/jniLibs/x86_64/
cd src/pandroid
./gradlew assembleDebug
cd ../..
- name: Upload executable
uses: actions/upload-artifact@v2
with:
name: Android APK (x86-64)
path: './src/pandroid/app/build/outputs/apk/debug/app-debug.apk'

arm64:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Fetch submodules
run: git submodule update --init --recursive

- name: Setup Vulkan SDK
uses: humbletim/[email protected]
with:
vulkan-query-version: latest
vulkan-use-cache: true
vulkan-components: Vulkan-Headers, Vulkan-Loader, SPIRV-Tools, Glslang

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '17'

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DBUILD_HYDRA_CORE=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DENABLE_VULKAN=0 -DCMAKE_CXX_FLAGS="-march=armv8.1-a+crypto"

- name: Build
run: |
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
mv ./build/libAlber.so ./src/pandroid/app/src/main/jniLibs/arm64-v8a/
cd src/pandroid
./gradlew assembleDebug
cd ../..
- name: Upload executable
uses: actions/upload-artifact@v2
with:
name: Android APK (arm64)
path: './src/pandroid/app/build/outputs/apk/debug/app-debug.apk'

118 changes: 118 additions & 0 deletions patch.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
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<GLenum>(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,
30 changes: 29 additions & 1 deletion src/jni_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_RunFram
renderer->setFBO(fbo);
renderer->resetStateManager();
emulator->runFrame();

emulator->getServiceManager().getHID().updateInputs(emulator->getTicks());
}

extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_Finalize(JNIEnv* env, jobject obj) {
Expand All @@ -43,4 +45,30 @@ extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_LoadRom
__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();
}


extern "C" JNIEXPORT void JNICALL Java_com_panda3ds_pandroid_AlberDriver_KeyUp(JNIEnv* env, jobject obj, jint keyCode) {
emulator->getServiceManager().getHID().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);
}

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);
}


16 changes: 12 additions & 4 deletions src/pandroid/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage"/>

<uses-feature
android:required="true"
android:glEsVersion="0x0030002"/>

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -13,14 +19,16 @@
android:theme="@style/Theme.Pandroid"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".app.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".app.GameActivity"
android:configChanges="screenSize|screenLayout|orientation|density|uiMode">
</activity>
</application>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage"/>
</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public class AlberDriver {
public static native void LoadRom(String path);
public static native void Finalize();

public static native void KeyDown(int code);
public static native void KeyUp(int code);
public static native void SetCirclepadAxis(int x, int y);
public static native void TouchScreenUp();
public static native void TouchScreenDown(int x, int y);

static {
System.loadLibrary("Alber");
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.panda3ds.pandroid.app;

import androidx.appcompat.app.AppCompatActivity;

public class BaseActivity extends AppCompatActivity {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.panda3ds.pandroid.app;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.panda3ds.pandroid.AlberDriver;
import com.panda3ds.pandroid.R;
import com.panda3ds.pandroid.utils.Constants;
import com.panda3ds.pandroid.view.PandaGlSurfaceView;
import com.panda3ds.pandroid.view.PandaLayoutController;
import com.panda3ds.pandroid.view.controller.ControllerLayout;

public class GameActivity extends BaseActivity {
private PandaGlSurfaceView pandaSurface;
private PandaLayoutController controllerLayout;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Intent intent = getIntent();
if(!intent.hasExtra(Constants.EXTRA_PATH)){

setContentView(new FrameLayout(this));
Toast.makeText(this, "INVALID ROM PATH", Toast.LENGTH_LONG).show();
finish();
return;
}

pandaSurface = new PandaGlSurfaceView(this, intent.getStringExtra(Constants.EXTRA_PATH));;

setContentView(R.layout.game_activity);

((FrameLayout)findViewById(R.id.panda_gl_frame))
.addView(pandaSurface, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

controllerLayout = findViewById(R.id.controller_layout);
controllerLayout.initialize();

((CheckBox)findViewById(R.id.hide_screen_controller))
.setOnCheckedChangeListener((buttonView, isChecked) -> {
controllerLayout.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE);
});
}
}
Loading

0 comments on commit 62880f0

Please sign in to comment.