예제 #1
0
void GlxContextHandler::createContext(const AbstractXApplication::Configuration& configuration, Window nativeWindow) {
    window = nativeWindow;

    GLint attributes[] = {
        /* Leave some space for optional attributes below */
        0, 0,
        0, 0,
        0, 0,

        0
    };

    /* Set context version, if requested */
    if(configuration.version() != Version::None) {
        Int major, minor;
        std::tie(major, minor) = version(configuration.version());

        attributes[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
        attributes[1] = major;
        attributes[2] = GLX_CONTEXT_MINOR_VERSION_ARB;
        attributes[3] = minor;

        #ifndef MAGNUM_TARGET_GLES
        if(configuration.version() >= Version::GL310) {
            attributes[4] = GLX_CONTEXT_PROFILE_MASK_ARB;
            attributes[5] = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
        }
        #else
        attributes[4] = GLX_CONTEXT_PROFILE_MASK_ARB;
        attributes[5] = GLX_CONTEXT_ES2_PROFILE_BIT_EXT;
        #endif
    }

    /* We need this to run ES (default is desktop GL) */
    #ifdef MAGNUM_TARGET_GLES
    else {
        attributes[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
        #ifdef MAGNUM_TARGET_GLES3
        attributes[1] = 3;
        #elif defined(MAGNUM_TARGET_GLES2)
        attributes[1] = 2;
        #else
        #error unsupported OpenGL ES version
        #endif
        attributes[2] = GLX_CONTEXT_MINOR_VERSION_ARB;
        attributes[3] = 0;
        attributes[4] = GLX_CONTEXT_PROFILE_MASK_ARB;
        attributes[5] = GLX_CONTEXT_ES2_PROFILE_BIT_EXT;
    }
    #endif

    /** @todo Use some extension wrangler for this, not GLEW, as it apparently needs context to create context, yo dawg wtf. */
    PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB");
    context = glXCreateContextAttribsARB(display, configs[0], nullptr, True, attributes);
    XFree(configs);
    if(!context) {
        Error() << "GlxContextHandler: cannot create context.";
        std::exit(1);
    }
}
예제 #2
0
void EglContextHandler::createContext(const AbstractXApplication::Configuration& configuration, EGLNativeWindowType window) {
    EGLint attributes[] = {
        /* Leave some space for optional attributes below */
        EGL_NONE, EGL_NONE,
        EGL_NONE, EGL_NONE,
        EGL_NONE, EGL_NONE,

        EGL_NONE
    };

    /* Set context version, if requested. On desktop needs
       EGL_KHR_create_context. */
    /** @todo Test for presence of EGL_KHR_create_context extension */
    if(configuration.version() != Version::None) {
        Int major, minor;
        std::tie(major, minor) = version(configuration.version());

        attributes[0] = EGL_CONTEXT_MAJOR_VERSION_KHR;
        attributes[1] = major;
        attributes[2] = EGL_CONTEXT_MINOR_VERSION_KHR;
        attributes[3] = minor;

        #ifndef MAGNUM_TARGET_GLES
        if(configuration.version() >= Version::GL310) {
            attributes[4] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
            attributes[5] = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
        }
        #endif
    }

    /* We need this to run ES (default is desktop GL) */
    #ifdef MAGNUM_TARGET_GLES
    else {
        attributes[0] = EGL_CONTEXT_CLIENT_VERSION;
        #ifdef MAGNUM_TARGET_GLES3
        attributes[1] = 3;
        #elif defined(MAGNUM_TARGET_GLES2)
        attributes[1] = 2;
        #else
        #error Unsupported OpenGL ES version
        #endif
    }
    #endif

    if(!(context = eglCreateContext(display, config, EGL_NO_CONTEXT, attributes))) {
        Error() << "Cannot create EGL context:" << Implementation::eglErrorString(eglGetError());
        std::exit(1);
    }
    if(!(surface = eglCreateWindowSurface(display, config, window, nullptr))) {
        Error() << "Cannot create window surface:" << Implementation::eglErrorString(eglGetError());
        std::exit(1);
    }

    /** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */
}