Контекст Android OpenGL ES3 не создан

Я работаю над собственным проектом OpebGL ES3 для Android, я создаю поверхность, отображение и контекст, как написано в примере кода от Google, и все работало очень хорошо, пока я не изменил многие вещи в движке и шейдерах, но в основном ничего не изменилось. файл, который имеет инициализацию вещей EGL, теперь контекст может создаваться один раз каждые много раз, и когда он создается и достигает части компиляции шейдеров, я получаю странную ошибку android opengl es3 parse translation unit failed (5,0) Я почти уверен, что ничего не изменил в основном файле:

#include <jni.h>
#include <android/input.h>
#include <android/looper.h>
#include <android/log.h>
#include <android/native_window.h>
#include <android_native_app_glue.h>
#include <android/configuration.h>
#include <android/native_activity.h>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <initializer_list>

#include <EGL/egl.h>
#include <EGL/eglplatform.h>
#include <GLES3/gl3.h>

#include <Game.hpp>

#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", __VA_ARGS__))
/**
 * Our saved state data.
 */
struct saved_state {
        float angle;
        int32_t x;
        int32_t y;
};

/**
 * Shared state for our app.
 */
struct App {
        ~App() {
            //game->clear();
        }
        struct android_app* app;
        EGLDisplay display;
        EGLSurface surface;
        EGLContext context;

        Game* game;
        bool initialized = false;
};
/**
 * Initialize an EGL context for the current display.
 */

int32_t getDensityDpi(android_app* app) {
    AConfiguration* config = AConfiguration_new();
    AConfiguration_fromAssetManager(config, app->activity->assetManager);
    int32_t density = AConfiguration_getDensity(config);
    AConfiguration_delete(config);
    return density;
}

static int appEngine_init_display(App* appEngine) {
    // initialize OpenGL ES and EGL
    /*
     * Here specify the attributes of the desired configuration.
     * Below, we select an EGLConfig with at least 8 bits per color
     * component compatible with on-screen windows
     */
    const EGLint attribs[] = { EGL_RENDERABLE_TYPE,
    EGL_OPENGL_ES2_BIT,
    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
    EGL_BLUE_SIZE, 8,
    EGL_GREEN_SIZE, 8,
    EGL_RED_SIZE, 8,
    EGL_DEPTH_SIZE, 24,
    EGL_NONE };

    EGLint format;
    EGLint numConfigs;
    EGLConfig config;
    EGLSurface surface;
    EGLContext context;

    EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    eglInitialize(display, 0, 0);

    /* Here, the application chooses the configuration it desires.
     * find the best match if possible, otherwise use the very first one
     */
    eglChooseConfig(display, attribs, nullptr, 0, &numConfigs);
    std::unique_ptr<EGLConfig[]> supportedConfigs(new EGLConfig[numConfigs]);
    assert(supportedConfigs);
    eglChooseConfig(display, attribs, supportedConfigs.get(), numConfigs, &numConfigs);
    assert(numConfigs);
    auto i = 0;
    for (; i < numConfigs; i++) {
        auto& cfg = supportedConfigs[i];
        EGLint r, g, b, d;
        if (eglGetConfigAttrib(display, cfg, EGL_RED_SIZE, &r) && eglGetConfigAttrib(display, cfg, EGL_GREEN_SIZE, &g) && eglGetConfigAttrib(display, cfg, EGL_BLUE_SIZE, &b) && eglGetConfigAttrib(display, cfg, EGL_DEPTH_SIZE, &d) && r == 8 && g == 8
                && b == 8 && d == 0) {
            config = supportedConfigs[i];
            break;
        }
    }
    if (i == numConfigs) {
        config = supportedConfigs[0];
    }

    /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
     * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
     * As soon as we picked a EGLConfig, we can safely reconfigure the
     * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
    surface = eglCreateWindowSurface(display, config, appEngine->app->window, NULL);

    const EGLint ctxAttrs[] = { EGL_CONTEXT_CLIENT_VERSION, 3,
    EGL_NONE, 0 };
    context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctxAttrs);

    if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
        LOGW("Unable to eglMakeCurrent");
        return -1;
    }

    eglQuerySurface(display, surface, EGL_WIDTH, (EGLint*) &appEngine->game->width);
    eglQuerySurface(display, surface, EGL_HEIGHT, (EGLint*) &appEngine->game->height);

    appEngine->display = display;
    appEngine->context = context;
    appEngine->surface = surface;
    // Check openGL on the system
    auto opengl_info = { GL_VENDOR, GL_RENDERER, GL_VERSION, GL_EXTENSIONS };
    for (auto name : opengl_info) {
        auto info = glGetString(name);
        LOGI("OpenGL Info: %s", info);
    }
    LOGI("game start initialize");
    appEngine->initialized = appEngine->game->init();
    return 0;
}

/**
 * Just the current frame in the display.
 */
static void appEngine_draw_frame(App* appEngine) {
    if (appEngine->display == NULL) {
        return;
    }
    if (appEngine->initialized) {
        glViewport(0, 0, appEngine->game->width, appEngine->game->height);
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_CULL_FACE);
        glCullFace(GL_BACK);
        appEngine->game->render();
        eglSwapBuffers(appEngine->display, appEngine->surface);
    }
}

/**
 * Tear down the EGL context currently associated with the display.
 */
static void appEngine_term_display(App* appEngine) {
    if (appEngine->display != EGL_NO_DISPLAY) {
        eglMakeCurrent(appEngine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
        if (appEngine->context != EGL_NO_CONTEXT) {
            eglDestroyContext(appEngine->display, appEngine->context);
        }
        if (appEngine->surface != EGL_NO_SURFACE) {
            eglDestroySurface(appEngine->display, appEngine->surface);
        }
        eglTerminate(appEngine->display);
    }
    appEngine->game->animating = 0;
    appEngine->display = EGL_NO_DISPLAY;
    appEngine->context = EGL_NO_CONTEXT;
    appEngine->surface = EGL_NO_SURFACE;
}

/**
 * Process the next input event.
 */
static int32_t appEngine_handle_input(struct android_app* app, AInputEvent* event) {
    App* appEngine = (App*) app->userData;
    appEngine->game->onInput(event);
    return 0;
}

/**
 * Process the next main command.
 */
static void appEngine_handle_cmd(struct android_app* app, int32_t cmd) {
    App* appEngine = (App*) app->userData;
    switch (cmd) {
        case APP_CMD_SAVE_STATE:
            // The system has asked us to save our current state.  Do so.
            break;
        case APP_CMD_INIT_WINDOW:
            // The window is being shown, get it ready.
            if (appEngine->app->window != NULL) {
                appEngine_init_display(appEngine);
                appEngine_draw_frame(appEngine);
            }
            break;
        case APP_CMD_TERM_WINDOW:
            // The window is being hidden or closed, clean it up.
            appEngine_term_display(appEngine);
            break;
        case APP_CMD_GAINED_FOCUS:
            // When our app gains focus, we start monitoring the accelerometer.
            appEngine->game->animating = 1;
            appEngine_draw_frame(appEngine);
            break;
        case APP_CMD_LOST_FOCUS:
            // When our app loses focus, we stop monitoring the accelerometer.
            // This is to avoid consuming battery while not being used.

            // Also stop animating.
            appEngine->game->animating = 0;
            appEngine_draw_frame(appEngine);
            break;
    }
}

/**
 * This is the main entry point of a native application that is using
 * android_native_app_glue.  It runs in its own thread, with its own
 * event loop for receiving input events and doing other things.
 */

void android_main(struct android_app* state) {
    const char* internalPath = state->activity->internalDataPath;
    const char* externalPath = state->activity->externalDataPath;
    std::string dataPath(internalPath);

    AAssetManager* mgr;
    mgr = state->activity->assetManager;

    Game* game = Game::createGame(mgr, dataPath, getDensityDpi(state));

    App appEngine;
    memset(&appEngine, 0, sizeof(appEngine));
    state->userData = &appEngine;
    state->onAppCmd = appEngine_handle_cmd;
    state->onInputEvent = appEngine_handle_input;
    appEngine.app = state;
    appEngine.game = game;

    if (state->savedState != NULL) {
        // We are starting with a previous saved state; restore from it.

    }

    // loop waiting for stuff to do.

    while (1) {
        // Read all pending events.
        int ident;
        int events;
        struct android_poll_source* source;

        // If not animating, we will block forever waiting for events.
        // If animating, we loop until all events are read, then continue
        // to draw the next frame of animation.
        while ((ident = ALooper_pollAll(appEngine.game->animating ? 0 : -1, NULL, &events, (void**) &source)) >= 0) {

            // Process this event.
            if (source != NULL) {
                source->process(state, source);
            }

            // If a sensor has data, process it now.
            if (ident == LOOPER_ID_USER) {

            }

            // Check if we are exiting.
            if (state->destroyRequested != 0) {
                appEngine_term_display(&appEngine);
                return;
            }
        }

        if (appEngine.game->animating) {
            appEngine_draw_frame(&appEngine);
        }
    }
}

Я просто создаю объект Game в главной функции, а затем инициализирую его в appEngine_init_display но это в основном не достигает context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctxAttrs); линия и приложение перестают работать, это вывод logcat

        09-20 17:21:11.067: V/SettingsInterface(11159): invalidate [system]: current 10 != cached 0
    09-20 17:21:11.070: D/ActivityThread(11159): hoder:android.app.IActivityManager$ContentProviderHolder@11868227,provider,holder.Provider:android.content.ContentProviderProxy@3177cd4
    09-20 17:21:11.103: D/Proxy(11159): setHttpRequestCheckHandler
    09-20 17:21:11.108: D/ActivityThread(11159): BIND_APPLICATION handled : 0 / AppBindData{appInfo=ApplicationInfo{1fbdd172 com.ogzoma}}
    09-20 17:21:11.111: V/ActivityThread(11159): Handling launch of ActivityRecord{9cf19c3 token=android.os.BinderProxy@36d99240 {com.ogzoma/com.ogzoma.Loader}}
    09-20 17:21:11.122: V/ActivityThread(11159): ActivityRecord{9cf19c3 token=android.os.BinderProxy@36d99240 {com.ogzoma/com.ogzoma.Loader}}: app=android.app.Application@19392be, appName=com.ogzoma, pkg=com.ogzoma, comp={com.ogzoma/com.ogzoma.Loader}, dir=/data/app/com.ogzoma-2/base.apk
    09-20 17:21:11.125: D/FeatureProxyBase(11159): FeatureProxyBase class constructor
    09-20 17:21:11.125: D/MultiWindow(11159): MultiWindowProxy constructor.
    09-20 17:21:11.125: D/FeatureProxyBase(11159): getService(), serviceName = multiwindow_service_v1
    09-20 17:21:11.127: W/Typeface(11159): VIBEUI_setThemeFont(): FontPath Not Changed!
    09-20 17:21:11.127: D/FeatureProxyBase(11159): FeatureProxyBase class constructor
    09-20 17:21:11.128: D/MultiWindow(11159): MultiWindowProxy constructor.
    09-20 17:21:11.128: D/FeatureProxyBase(11159): getService(), serviceName = multiwindow_service_v1
    09-20 17:21:11.129: D/FeatureProxyBase(11159): FeatureProxyBase class constructor
    09-20 17:21:11.129: D/MultiWindow(11159): MultiWindowProxy constructor.
    09-20 17:21:11.129: D/FeatureProxyBase(11159): getService(), serviceName = multiwindow_service_v1
    09-20 17:21:11.143: D/AccessibilityManager(11159): setStateLocked: wasEnabled = false, mIsEnabled = true, wasTouchExplorationEnabled = false, mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false
    09-20 17:21:11.143: D/AccessibilityManager(11159): java.lang.Throwable: setStateLocked
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.view.accessibility.AccessibilityManager.setStateLocked(AccessibilityManager.java:553)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.view.accessibility.AccessibilityManager.tryConnectToServiceLocked(AccessibilityManager.java:636)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.view.accessibility.AccessibilityManager.<init>(AccessibilityManager.java:226)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.view.accessibility.AccessibilityManager.getInstance(AccessibilityManager.java:206)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.view.View.setFlags(View.java:9843)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.view.ViewGroup.initViewGroup(ViewGroup.java:536)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.view.ViewGroup.<init>(ViewGroup.java:525)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.view.ViewGroup.<init>(ViewGroup.java:520)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.view.ViewGroup.<init>(ViewGroup.java:516)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.view.ViewGroup.<init>(ViewGroup.java:512)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.widget.FrameLayout.<init>(FrameLayout.java:119)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at com.android.internal.policy.impl.PhoneWindow$DecorView.<init>(PhoneWindow.java:2354)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at com.android.internal.policy.impl.PhoneWindow.generateDecor(PhoneWindow.java:3718)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:4119)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:463)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:454)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.app.Activity.setContentView(Activity.java:2222)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.app.NativeActivity.onCreate(NativeActivity.java:144)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.app.Activity.performCreate(Activity.java:6119)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2491)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2618)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.app.ActivityThread.access$800(ActivityThread.java:183)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1475)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.os.Handler.dispatchMessage(Handler.java:111)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.os.Looper.loop(Looper.java:194)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at android.app.ActivityThread.main(ActivityThread.java:5651)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at java.lang.reflect.Method.invoke(Native Method)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at java.lang.reflect.Method.invoke(Method.java:372)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
    09-20 17:21:11.143: D/AccessibilityManager(11159):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
    09-20 17:21:11.170: W/linker(11159): libogzoma.so: unused DT entry: type 0x6ffffffe arg 0x5db5c
    09-20 17:21:11.170: W/linker(11159): libogzoma.so: unused DT entry: type 0x6fffffff arg 0x2
    09-20 17:21:11.170: W/linker(11159): libfreetype.so: unused DT entry: type 0x6ffffffe arg 0x88d4
    09-20 17:21:11.170: W/linker(11159): libfreetype.so: unused DT entry: type 0x6fffffff arg 0x1
    09-20 17:21:15.363: A/libc(11159): Fatal signal 11 (SIGSEGV), code 1, fault addr 0xfffffffc in tid 11184 (com.ogzoma)
    09-20 17:21:15.364: V/ActivityThread(11159): Performing resume of ActivityRecord{9cf19c3 token=android.os.BinderProxy@36d99240 {com.ogzoma/com.ogzoma.Loader}}
    09-20 17:21:15.364: D/ActivityThread(11159): ACT-AM_ON_RESUME_CALLED ActivityRecord{9cf19c3 token=android.os.BinderProxy@36d99240 {com.ogzoma/com.ogzoma.Loader}}
    09-20 17:21:15.365: V/PhoneWindow(11159): DecorView setVisiblity: visibility = 4 ,Parent =null, this =com.android.internal.policy.impl.PhoneWindow$DecorView{2297fe3b I.E..... R.....ID 0,0-0,0}
    09-20 17:21:15.364: V/ActivityThread(11159): Resume ActivityRecord{9cf19c3 token=android.os.BinderProxy@36d99240 {com.ogzoma/com.ogzoma.Loader}} started activity: false, hideForNow: false, finished: false
    09-20 17:21:15.389: V/ActivityThread(11159): Resuming ActivityRecord{9cf19c3 token=android.os.BinderProxy@36d99240 {com.ogzoma/com.ogzoma.Loader}} with isForward=false
    09-20 17:21:15.390: D/FeatureProxyBase(11159): FeatureProxyBase class constructor
    09-20 17:21:15.390: D/MultiWindow(11159): MultiWindowProxy constructor.
    09-20 17:21:15.391: D/FeatureProxyBase(11159): getService(), serviceName = multiwindow_service_v1
    09-20 17:21:15.392: V/PhoneWindow(11159): DecorView setVisiblity: visibility = 0 ,Parent =ViewRoot{6307e0f com.ogzoma/com.ogzoma.Loader,ident = 0}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{2297fe3b V.E..... R.....ID 0,0-0,0}
    09-20 17:21:15.393: V/ActivityThread(11159): Scheduling idle handler for ActivityRecord{9cf19c3 token=android.os.BinderProxy@36d99240 {com.ogzoma/com.ogzoma.Loader}}
    09-20 17:21:15.394: D/ActivityThread(11159): ACT-LAUNCH_ACTIVITY handled : 0 / ActivityRecord{9cf19c3 token=android.os.BinderProxy@36d99240 {com.ogzoma/com.ogzoma.Loader}}

Я работаю на своем телефоне, который поддерживает OpenGL ES3, и до вчерашнего дня все было отлично

0 ответов

Другие вопросы по тегам