예제 #1
0
int init(int argc, char** argv) {
    
    for(int i = 0; i < argc; i++) {
        char* p = argv[i];
        if (strcmp(p, "-noevents") == 0) {
            printf("-noevents: will not look for events.\n");
            gNoEvents = true;
        }
    }
    
    if (! gNoEvents) {
        gpEventQueue = new EventQueue();
    }

    EGLNativeWindowType window = android_createDisplaySurface();

    gDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    
    EGLint majorVersion;
    EGLint minorVersion;
    
    eglInitialize(gDisplay, &majorVersion, &minorVersion);
    checkEGLError("eglInitialize");
        
    EGLint configRequest[] = {
            EGL_SURFACE_TYPE, EGL_PBUFFER_BIT|EGL_WINDOW_BIT,
            EGL_DEPTH_SIZE, 16,
            EGL_NONE
    };
 
    EGLConfig config;
    android::EGLUtils::selectConfigForNativeWindow(gDisplay, configRequest, window, &config);
    gSurface = eglCreateWindowSurface(gDisplay, config, window, NULL);

    eglQuerySurface(gDisplay, gSurface, EGL_WIDTH, &gDisplayWidth);
    eglQuerySurface(gDisplay, gSurface, EGL_HEIGHT, &gDisplayHeight);
    fprintf(stderr, "display width = %d, height = %d\n", gDisplayWidth,
            gDisplayHeight);

    gContext = eglCreateContext(gDisplay, config, NULL, NULL);
    checkEGLError("eglCreateContext");
    eglMakeCurrent(gDisplay, gSurface, gSurface, gContext);
    checkEGLError("eglMakeCurrent");
    
    printf("vendor    : %s\n", glGetString(GL_VENDOR));
    printf("renderer  : %s\n", glGetString(GL_RENDERER));
    printf("version   : %s\n", glGetString(GL_VERSION));
    printf("extensions: %s\n", glGetString(GL_EXTENSIONS));
        
    return 0;
}
bool QQnxGLContext::makeCurrent(QPlatformSurface *surface)
{
    qGLContextDebug() << Q_FUNC_INFO;

    Q_ASSERT(surface->surface()->surfaceType() == QSurface::OpenGLSurface);

    // Set current rendering API
    EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API);
    if (eglResult != EGL_TRUE)
        qFatal("QQnxGLContext: failed to set EGL API, err=%d", eglGetError());

    QQnxEglWindow *platformWindow = dynamic_cast<QQnxEglWindow*>(surface);
    if (!platformWindow)
        return false;

    platformWindow->setPlatformOpenGLContext(this);

    if (m_currentEglSurface == EGL_NO_SURFACE || m_currentEglSurface != platformWindow->getSurface()) {
        m_currentEglSurface = platformWindow->getSurface();
        doneCurrent();
    }

    eglResult = eglMakeCurrent(ms_eglDisplay, m_currentEglSurface, m_currentEglSurface, m_eglContext);
    if (eglResult != EGL_TRUE) {
        checkEGLError("eglMakeCurrent");
        qWarning("QQNX: failed to set current EGL context, err=%d", eglGetError());
        return false;
    }
    return (eglResult == EGL_TRUE);
}
void QQnxGLContext::initialize()
{
    qGLContextDebug() << Q_FUNC_INFO;

    // Initialize connection to EGL
    ms_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (ms_eglDisplay == EGL_NO_DISPLAY) {
        checkEGLError("eglGetDisplay");
        qFatal("QQnxGLContext: failed to obtain EGL display");
    }

    EGLBoolean eglResult = eglInitialize(ms_eglDisplay, 0, 0);
    if (eglResult != EGL_TRUE) {
        checkEGLError("eglInitialize");
        qFatal("QQnxGLContext: failed to initialize EGL display, err=%d", eglGetError());
    }
}
예제 #4
0
int main(int argc, char** argv) {
    fprintf(stderr, "Welcome to stand-alone Android quake.\n");
    AndroidInitArgs(argc, argv);
    
    int result = init(argc, argv);
    if (result) {
        return result;
    }
    
    if (!AndroidInit()) {
        return 1;
    }

    while(true) {
        AndroidStep(gDisplayWidth, gDisplayHeight);
        checkGLError("AndroidStep");
        eglSwapBuffers(gDisplay, gSurface);
        checkEGLError("eglSwapBuffers");
        checkEvents();
    }
    return 0;
}
QQnxGLContext::QQnxGLContext(QOpenGLContext *glContext)
    : QPlatformOpenGLContext(),
      m_glContext(glContext),
      m_currentEglSurface(EGL_NO_SURFACE)
{
    qGLContextDebug() << Q_FUNC_INFO;
    QSurfaceFormat format = m_glContext->format();

    // Set current rendering API
    EGLBoolean eglResult = eglBindAPI(EGL_OPENGL_ES_API);
    if (eglResult != EGL_TRUE)
        qFatal("QQNX: failed to set EGL API, err=%d", eglGetError());

    // Get colour channel sizes from window format
    int alphaSize = format.alphaBufferSize();
    int redSize = format.redBufferSize();
    int greenSize = format.greenBufferSize();
    int blueSize = format.blueBufferSize();

    // Check if all channels are don't care
    if (alphaSize == -1 && redSize == -1 && greenSize == -1 && blueSize == -1) {
        // Set colour channels based on depth of window's screen
        QQnxScreen *screen = static_cast<QQnxScreen*>(glContext->screen()->handle());
        int depth = screen->depth();
        if (depth == 32) {
            // SCREEN_FORMAT_RGBA8888
            alphaSize = 8;
            redSize = 8;
            greenSize = 8;
            blueSize = 8;
        } else {
            // SCREEN_FORMAT_RGB565
            alphaSize = 0;
            redSize = 5;
            greenSize = 6;
            blueSize = 5;
        }
    } else {
        // Choose best match based on supported pixel formats
        if (alphaSize <= 0 && redSize <= 5 && greenSize <= 6 && blueSize <= 5) {
            // SCREEN_FORMAT_RGB565
            alphaSize = 0;
            redSize = 5;
            greenSize = 6;
            blueSize = 5;
        } else {
            // SCREEN_FORMAT_RGBA8888
            alphaSize = 8;
            redSize = 8;
            greenSize = 8;
            blueSize = 8;
        }
    }

    // Update colour channel sizes in window format
    format.setAlphaBufferSize(alphaSize);
    format.setRedBufferSize(redSize);
    format.setGreenBufferSize(greenSize);
    format.setBlueBufferSize(blueSize);

    // Select EGL config based on requested window format
    m_eglConfig = q_configFromGLFormat(ms_eglDisplay, format);
    if (m_eglConfig == 0)
        qFatal("QQnxGLContext: failed to find EGL config");

    QQnxGLContext *glShareContext = static_cast<QQnxGLContext*>(m_glContext->shareHandle());
    m_eglShareContext = glShareContext ? glShareContext->m_eglContext : EGL_NO_CONTEXT;

    m_eglContext = eglCreateContext(ms_eglDisplay, m_eglConfig, m_eglShareContext,
                                    contextAttrs(format));
    if (m_eglContext == EGL_NO_CONTEXT) {
        checkEGLError("eglCreateContext");
        qFatal("QQnxGLContext: failed to create EGL context, err=%d", eglGetError());
    }

    // Query/cache window format of selected EGL config
    m_windowFormat = q_glFormatFromConfig(ms_eglDisplay, m_eglConfig);
}