mirror of
https://github.com/MobileGL-Dev/MobileGlues.git
synced 2025-08-02 23:16:13 -04:00
initial bringup
This commit is contained in:
parent
589710f888
commit
6f753ba82f
49
build.gradle
Normal file
49
build.gradle
Normal file
@ -0,0 +1,49 @@
|
||||
plugins {
|
||||
id 'com.android.library'
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.swung0x48.mobileglues'
|
||||
compileSdk 34
|
||||
|
||||
defaultConfig {
|
||||
minSdk 24
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
cppFlags ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
fordebug {
|
||||
debuggable true
|
||||
}
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "src/main/cpp/CMakeLists.txt"
|
||||
version "3.22.1"
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'com.google.android.material:material:1.10.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
}
|
0
consumer-rules.pro
Normal file
0
consumer-rules.pro
Normal file
8
local.properties
Normal file
8
local.properties
Normal file
@ -0,0 +1,8 @@
|
||||
## This file must *NOT* be checked into Version Control Systems,
|
||||
# as it contains information specific to your local configuration.
|
||||
#
|
||||
# Location of the SDK. This is only used by Gradle.
|
||||
# For customization when using a Version Control System, please read the
|
||||
# header note.
|
||||
#Mon Oct 07 23:18:27 CST 2024
|
||||
sdk.dir=/Users/swung0x48/Library/Android/sdk
|
21
proguard-rules.pro
vendored
Normal file
21
proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
39
src/main/cpp/CMakeLists.txt
Normal file
39
src/main/cpp/CMakeLists.txt
Normal file
@ -0,0 +1,39 @@
|
||||
# For more information about using CMake with Android Studio, read the
|
||||
# documentation: https://d.android.com/studio/projects/add-native-code.html.
|
||||
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
|
||||
|
||||
# Sets the minimum CMake version required for this project.
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
|
||||
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
|
||||
# Since this is the top level CMakeLists.txt, the project name is also accessible
|
||||
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
|
||||
# build script scope).
|
||||
project("mobileglues")
|
||||
|
||||
# Creates and names a library, sets it as either STATIC
|
||||
# or SHARED, and provides the relative paths to its source code.
|
||||
# You can define multiple libraries, and CMake builds them for you.
|
||||
# Gradle automatically packages shared libraries with your APK.
|
||||
#
|
||||
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
|
||||
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
|
||||
# is preferred for the same purpose.
|
||||
#
|
||||
# In order to load a library into your app from Java/Kotlin, you must call
|
||||
# System.loadLibrary() and pass the name of the library defined here;
|
||||
# for GameActivity/NativeActivity derived applications, the same library name must be
|
||||
# used in the AndroidManifest.xml file.
|
||||
add_library(${CMAKE_PROJECT_NAME} SHARED
|
||||
# List C/C++ source files with relative paths to this CMakeLists.txt.
|
||||
native-lib.cpp
|
||||
main.c)
|
||||
|
||||
# Specifies libraries CMake should link to your target library. You
|
||||
# can link libraries from various origins, such as libraries defined in this
|
||||
# build script, prebuilt third-party libraries, or Android system libraries.
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
# List libraries link to the target library
|
||||
android
|
||||
log
|
||||
EGL)
|
39
src/main/cpp/includes.h
Normal file
39
src/main/cpp/includes.h
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// Created by Swung 0x48 on 2024/10/7.
|
||||
//
|
||||
|
||||
#ifndef MOBILEGLUES_INCLUDES_H
|
||||
#define MOBILEGLUES_INCLUDES_H
|
||||
|
||||
#define RENDERERNAME "MobileGlues"
|
||||
#include <android/log.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES3/gl32.h>
|
||||
|
||||
#define _mglues_dlopen(name) dlopen(name, RTLD_LAZY)
|
||||
#define _mglues_dlclose(handle) dlclose(handle)
|
||||
#define _mglues_dlsym(handle, name) dlsym(handle, name)
|
||||
|
||||
static int g_initialized = 0;
|
||||
|
||||
typedef __eglMustCastToProperFunctionPointerType (EGLGETPROCADDRESSPROC) (const char *procname);
|
||||
typedef EGLGETPROCADDRESSPROC* EGLGETPROCADDRESSPROCP;
|
||||
typedef EGLContext (EGLCREATECONTEXTPROC) (EGLDisplay, EGLConfig, EGLContext, const EGLint *);
|
||||
typedef EGLCREATECONTEXTPROC* EGLCREATECONTEXTPROCP;
|
||||
typedef EGLBoolean (EGLDESTROYCONTEXTPROC) (EGLDisplay, EGLContext);
|
||||
typedef EGLDESTROYCONTEXTPROC* EGLDESTROYCONTEXTPROCP;
|
||||
typedef EGLBoolean (EGLMAKECURRENTPROC)(EGLDisplay, EGLSurface, EGLSurface, EGLContext);
|
||||
typedef EGLMAKECURRENTPROC* EGLMAKECURRENTPROCP;
|
||||
|
||||
struct egl_func_t {
|
||||
EGLGETPROCADDRESSPROCP eglGetProcAddress;
|
||||
EGLCREATECONTEXTPROCP eglCreateContext;
|
||||
EGLDESTROYCONTEXTPROCP eglDestroyContext;
|
||||
EGLMAKECURRENTPROCP eglMakeCurrent;
|
||||
};
|
||||
|
||||
static struct egl_func_t g_target_egl_func;
|
||||
|
||||
#endif //MOBILEGLUES_INCLUDES_H
|
113
src/main/cpp/main.c
Normal file
113
src/main/cpp/main.c
Normal file
@ -0,0 +1,113 @@
|
||||
//
|
||||
// Created by Swung 0x48 on 2024/10/7.
|
||||
//
|
||||
|
||||
#include <string.h>
|
||||
#include "includes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void init_target_egl();
|
||||
void init_target_gles();
|
||||
__eglMustCastToProperFunctionPointerType prehook(const char *procname);
|
||||
__eglMustCastToProperFunctionPointerType posthook(const char *procname);
|
||||
|
||||
void proc_init() {
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
|
||||
|
||||
void* handle = _mglues_dlopen("libEGL.so");
|
||||
if (handle == NULL)
|
||||
__android_log_print(ANDROID_LOG_FATAL, RENDERERNAME,
|
||||
"Cannot load system libEGL.so!");
|
||||
|
||||
g_target_egl_func.eglGetProcAddress = dlsym(handle, "eglGetProcAddress");
|
||||
|
||||
init_target_egl();
|
||||
init_target_gles();
|
||||
|
||||
g_initialized = 1;
|
||||
}
|
||||
|
||||
void init_target_egl() {
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Initializing %s @ %s", RENDERERNAME, __FUNCTION__);
|
||||
|
||||
g_target_egl_func.eglCreateContext =
|
||||
(EGLCREATECONTEXTPROCP)g_target_egl_func.eglGetProcAddress("eglCreateContext");
|
||||
g_target_egl_func.eglDestroyContext =
|
||||
(EGLDESTROYCONTEXTPROCP) g_target_egl_func.eglGetProcAddress("eglDestroyContext");
|
||||
g_target_egl_func.eglMakeCurrent =
|
||||
(EGLMAKECURRENTPROCP) g_target_egl_func.eglGetProcAddress("eglMakeCurrent");
|
||||
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Got host eglCreateContext @ 0x%lx", g_target_egl_func.eglCreateContext);
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Got host eglDestroyContext @ 0x%lx", g_target_egl_func.eglDestroyContext);
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"Got host eglMakeCurrent @ 0x%lx", g_target_egl_func.eglMakeCurrent);
|
||||
}
|
||||
|
||||
void init_target_gles() {
|
||||
|
||||
}
|
||||
|
||||
__eglMustCastToProperFunctionPointerType prehook(const char *procname) {
|
||||
if (strcmp(procname, "glGetString") == 0)
|
||||
return (__eglMustCastToProperFunctionPointerType) glGetString;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
__eglMustCastToProperFunctionPointerType posthook(const char *procname) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY glXGetProcAddress (const char *procname) {
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"%s @ %s(%s)", RENDERERNAME, __FUNCTION__, procname);
|
||||
|
||||
if (!g_initialized) {
|
||||
proc_init();
|
||||
}
|
||||
|
||||
__eglMustCastToProperFunctionPointerType proc = NULL;
|
||||
|
||||
proc = prehook(procname);
|
||||
if (proc) return proc;
|
||||
else
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"UnImplemented function: %s(%s) @ prehook", __FUNCTION__, procname);
|
||||
|
||||
//proc = eglGetProcAddress(procname);
|
||||
if (proc) return proc;
|
||||
else
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"UnImplemented function: %s(%s) @ system", __FUNCTION__, procname);
|
||||
|
||||
proc = posthook(procname);
|
||||
if (!proc)
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"UnImplemented function: %s(%s) @ posthook", __FUNCTION__, procname);
|
||||
return proc;
|
||||
}
|
||||
|
||||
EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress (const char *procname) {
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, RENDERERNAME,
|
||||
"%s @ %s(%s)", RENDERERNAME, __FUNCTION__, procname);
|
||||
}
|
||||
|
||||
GL_APICALL const GLubyte *GL_APIENTRY glGetString (GLenum name) {
|
||||
switch (name) {
|
||||
case GL_VENDOR: return "GL_VENDOR";
|
||||
case GL_RENDERER:
|
||||
return "GL_VENDOR";
|
||||
default:
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
18
src/main/cpp/native-lib.cpp
Normal file
18
src/main/cpp/native-lib.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_com_swung0x48_mobileglues_MainActivity_stringFromJNI(
|
||||
JNIEnv* env,
|
||||
jobject /* this */) {
|
||||
std::string hello = "Hello from C++";
|
||||
return env->NewStringUTF(hello.c_str());
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT jstring JNICALL
|
||||
Java_com_swung0x48_mobilegluesapp_MainActivity_stringFromJNI(
|
||||
JNIEnv* env,
|
||||
jobject /* this */) {
|
||||
std::string hello = "Hello from C++";
|
||||
return env->NewStringUTF(hello.c_str());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user