mirror of
https://github.com/android/ndk-samples
synced 2025-11-04 22:53:57 +08:00
Migrate gles3jni to RegisterNatives.
This commit is contained in:
@@ -19,4 +19,12 @@ android {
|
|||||||
path 'src/main/cpp/CMakeLists.txt'
|
path 'src/main/cpp/CMakeLists.txt'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildFeatures {
|
||||||
|
prefab true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(":base")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.22.1)
|
|||||||
project(Gles3Jni LANGUAGES CXX)
|
project(Gles3Jni LANGUAGES CXX)
|
||||||
|
|
||||||
include(AppLibrary)
|
include(AppLibrary)
|
||||||
|
find_package(base CONFIG REQUIRED)
|
||||||
|
|
||||||
add_app_library(gles3jni SHARED
|
add_app_library(gles3jni SHARED
|
||||||
${GL3STUB_SRC}
|
${GL3STUB_SRC}
|
||||||
@@ -10,8 +11,8 @@ add_app_library(gles3jni SHARED
|
|||||||
RendererES3.cpp
|
RendererES3.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Include libraries needed for gles3jni lib
|
|
||||||
target_link_libraries(gles3jni
|
target_link_libraries(gles3jni
|
||||||
|
base::base
|
||||||
GLESv3
|
GLESv3
|
||||||
android
|
android
|
||||||
EGL
|
EGL
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "gles3jni.h"
|
#include "gles3jni.h"
|
||||||
|
|
||||||
|
#include <base/macros.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -227,21 +228,11 @@ void Renderer::render() {
|
|||||||
|
|
||||||
static Renderer* g_renderer = NULL;
|
static Renderer* g_renderer = NULL;
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
JNIEXPORT void JNICALL Java_com_android_gles3jni_GLES3JNILib_init(JNIEnv* env,
|
|
||||||
jobject obj);
|
|
||||||
JNIEXPORT void JNICALL Java_com_android_gles3jni_GLES3JNILib_resize(
|
|
||||||
JNIEnv* env, jobject obj, jint width, jint height);
|
|
||||||
JNIEXPORT void JNICALL Java_com_android_gles3jni_GLES3JNILib_step(JNIEnv* env,
|
|
||||||
jobject obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
#if !defined(DYNAMIC_ES3)
|
#if !defined(DYNAMIC_ES3)
|
||||||
static GLboolean gl3stubInit() { return GL_TRUE; }
|
static GLboolean gl3stubInit() { return GL_TRUE; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_com_android_gles3jni_GLES3JNILib_init(JNIEnv*,
|
void Init(JNIEnv*, jclass) {
|
||||||
jobject) {
|
|
||||||
if (g_renderer) {
|
if (g_renderer) {
|
||||||
delete g_renderer;
|
delete g_renderer;
|
||||||
g_renderer = NULL;
|
g_renderer = NULL;
|
||||||
@@ -262,16 +253,34 @@ JNIEXPORT void JNICALL Java_com_android_gles3jni_GLES3JNILib_init(JNIEnv*,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_com_android_gles3jni_GLES3JNILib_resize(
|
void Resize(JNIEnv*, jclass, jint width, jint height) {
|
||||||
JNIEnv*, jobject, jint width, jint height) {
|
|
||||||
if (g_renderer) {
|
if (g_renderer) {
|
||||||
g_renderer->resize(width, height);
|
g_renderer->resize(width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_com_android_gles3jni_GLES3JNILib_step(JNIEnv*,
|
void Step(JNIEnv*, jclass) {
|
||||||
jobject) {
|
|
||||||
if (g_renderer) {
|
if (g_renderer) {
|
||||||
g_renderer->render();
|
g_renderer->render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* _Nonnull vm, void* _Nullable) {
|
||||||
|
JNIEnv* env;
|
||||||
|
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||||||
|
return JNI_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
jclass c = env->FindClass("com/android/gles3jni/GLES3JNILib");
|
||||||
|
if (c == nullptr) return JNI_ERR;
|
||||||
|
|
||||||
|
static const JNINativeMethod methods[] = {
|
||||||
|
{"init", "()V", reinterpret_cast<void*>(Init)},
|
||||||
|
{"resize", "(II)V", reinterpret_cast<void*>(Resize)},
|
||||||
|
{"step", "()V", reinterpret_cast<void*>(Step)},
|
||||||
|
};
|
||||||
|
int rc = env->RegisterNatives(c, methods, arraysize(methods));
|
||||||
|
if (rc != JNI_OK) return rc;
|
||||||
|
|
||||||
|
return JNI_VERSION_1_6;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user