|
9 | 9 | #include <jni.h> |
10 | 10 | #include <stdio.h> |
11 | 11 |
|
| 12 | +#include <android/asset_manager.h> |
| 13 | +#include <android/asset_manager_jni.h> |
| 14 | +#include <android/native_window_jni.h> |
| 15 | + |
| 16 | +#include <EGL/egl.h> |
| 17 | +#include <EGL/eglext.h> |
| 18 | + |
12 | 19 | // need to copy example/src/main/jniLibs (fmod) |
13 | 20 | // inject strings for other samples res/values |
14 | 21 |
|
15 | 22 | // BLOG NOTES: |
16 | 23 | // - gradle version, always changing |
17 | 24 | // - depracated maven etc |
18 | 25 | // - trying to link .so vs .a |
| 26 | +// - EGL_NONE, array terminator. |
19 | 27 | // - No implementation found for void cc.pmtech.pen_activity.entry() (tried Java_cc_pmtech_pen_1activity_entry and Java_cc_pmtech_pen_1activity_entry__) - is the library loaded, e.g. System.loadLibrary? |
20 | 28 |
|
21 | 29 | // DONE: |
@@ -43,6 +51,84 @@ PEN_JNIFUNC(void, pen_1activity, entry)(JNIEnv* env, jclass thiz) |
43 | 51 | PEN_LOG("hello print %i\n", 69); |
44 | 52 | } |
45 | 53 |
|
| 54 | +PEN_JNIFUNC(void, SurfaceWrapper, render)(JNIEnv* env, jclass thiz, jobject caller) |
| 55 | +{ |
| 56 | + PEN_LOG("render%i\n", 79); |
| 57 | +} |
| 58 | + |
| 59 | +PEN_JNIFUNC(void, SurfaceWrapper, surface_1created)(JNIEnv* env, jclass thiz, jobject surface, int window_width, int window_height, int device_width, int device_height, int orientation, long app_ptr) |
| 60 | +{ |
| 61 | + auto window = ANativeWindow_fromSurface(env, surface); |
| 62 | + |
| 63 | + EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 64 | + PEN_ASSERT(display != EGL_NO_DISPLAY); |
| 65 | + EGLBoolean res = eglInitialize(display, nullptr, nullptr); |
| 66 | + PEN_ASSERT(res == EGL_TRUE); |
| 67 | + |
| 68 | + EGLint attr[] = { |
| 69 | + EGL_BUFFER_SIZE, 32, |
| 70 | + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR, |
| 71 | + EGL_NONE |
| 72 | + }; |
| 73 | + |
| 74 | + EGLint num_configs; |
| 75 | + EGLConfig config; |
| 76 | + res = eglChooseConfig(display, &attr[0], &config, 1, &num_configs); |
| 77 | + PEN_ASSERT(res == EGL_TRUE); |
| 78 | + |
| 79 | + EGLint ctx_attr[] = { |
| 80 | + EGL_CONTEXT_MAJOR_VERSION, 2, |
| 81 | + EGL_NONE |
| 82 | + }; |
| 83 | + |
| 84 | + eglBindAPI(EGL_OPENGL_ES_API); |
| 85 | + EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attr); |
| 86 | + PEN_ASSERT(context != EGL_NO_CONTEXT); |
| 87 | + |
| 88 | + EGLSurface egl_surface = eglCreateWindowSurface(display, config, window, nullptr); |
| 89 | + PEN_ASSERT(surface != EGL_NO_SURFACE); |
| 90 | + |
| 91 | + res = eglMakeCurrent( |
| 92 | + display, |
| 93 | + egl_surface, |
| 94 | + egl_surface, |
| 95 | + context |
| 96 | + ); |
| 97 | + PEN_ASSERT(res == EGL_TRUE); |
| 98 | + |
| 99 | + eglSwapBuffers(display, egl_surface); |
| 100 | + |
| 101 | + // TODO: call user_setup |
| 102 | + pen::pen_creation_params params = pen::pen_entry(0, nullptr); |
| 103 | + |
| 104 | + pen::jobs_create_job(params.user_thread_function, 1024 * 1024, params.user_data, pen::e_thread_start_flags::detached); |
| 105 | + |
| 106 | + /* |
| 107 | + // for get elapsed time |
| 108 | + s_startTime = getElapsedTimeMs(); |
| 109 | +
|
| 110 | + s_context.m_windowWidth = windowWidth; |
| 111 | + s_context.m_windowHeight = windowHeight; |
| 112 | +
|
| 113 | + if(s_context.m_device.m_window) |
| 114 | + ANativeWindow_release(s_context.m_device.m_window); |
| 115 | + s_context.m_device.m_window = ANativeWindow_fromSurface(env, surface); |
| 116 | + s_context.m_device.m_surfaceWrapperClass = thiz; |
| 117 | +
|
| 118 | + fw::gfx::createMainContext((fw::gfx::Device)&s_context.m_device); |
| 119 | +
|
| 120 | + fw::AppConfig::get()->setupSystemInfo(); |
| 121 | +
|
| 122 | + if (!s_context.m_app && appPtr != 0) |
| 123 | + { |
| 124 | + FW_LOG_CONSOLE("Surface created with width=%d, height=%d\n", s_context.m_windowWidth, s_context.m_windowHeight); |
| 125 | +
|
| 126 | + s_context.m_app = (App*)((intptr_t)appPtr); |
| 127 | + s_context.m_app->setup(); |
| 128 | + } |
| 129 | + */ |
| 130 | +} |
| 131 | + |
46 | 132 | namespace pen |
47 | 133 | { |
48 | 134 | u32 window_init(void* params) |
|
0 commit comments