示例#1
0
文件: glx11.cpp 项目: beanhome/dev
/* static */
bool wxGLContext::MakeCurrent(GLXDrawable drawable, GLXContext context)
{
    if (wxGLCanvas::GetGLXVersion() >= 13)
        return glXMakeContextCurrent( wxGetX11Display(), drawable, drawable, context);
    else // GLX <= 1.2 doesn't have glXMakeContextCurrent()
        return glXMakeCurrent( wxGetX11Display(), drawable, context);
}
示例#2
0
文件: glx11.cpp 项目: beanhome/dev
/* static */
bool
wxGLCanvasX11::InitXVisualInfo(const int *attribList,
                               GLXFBConfig **pFBC,
                               XVisualInfo **pXVisual)
{
    int data[512];
    if ( !ConvertWXAttrsToGL(attribList, data, WXSIZEOF(data)) )
        return false;

    Display * const dpy = wxGetX11Display();

    if ( GetGLXVersion() >= 13 )
    {
        int returned;
        *pFBC = glXChooseFBConfig(dpy, DefaultScreen(dpy), data, &returned);

        if ( *pFBC )
        {
            *pXVisual = glXGetVisualFromFBConfig(wxGetX11Display(), **pFBC);
            if ( !*pXVisual )
            {
                XFree(*pFBC);
                *pFBC = NULL;
            }
        }
    }
    else // GLX <= 1.2
    {
        *pFBC = NULL;
        *pXVisual = glXChooseVisual(dpy, DefaultScreen(dpy), data);
    }

    return *pXVisual != NULL;
}
示例#3
0
wxGLContext::wxGLContext(wxGLCanvas *gc, const wxGLContext *other)
{
    if ( gc->GetGLXContextAttribs()[0] != 0 ) // OpenGL 3 context creation
    {
        XVisualInfo *vi = gc->GetXVisualInfo();
        wxCHECK_RET( vi, wxT("invalid visual for OpenGL") );

        // We need to create a temporary context to get the
        // glXCreateContextAttribsARB function
        GLXContext tempContext = glXCreateContext( wxGetX11Display(), vi,
                                                   NULL,
                                                   GL_TRUE );
        wxCHECK_RET( tempContext, wxT("Couldn't create OpenGL context") );

        PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB
            = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
            glXGetProcAddress((GLubyte *)"glXCreateContextAttribsARB");
        if ( !glXCreateContextAttribsARB )
        {
            wxLogError(_("Core OpenGL profile is not supported by the OpenGL driver."));
            return;
        }

        GLXFBConfig *fbc = gc->GetGLXFBConfig();
        wxCHECK_RET( fbc, wxT("invalid GLXFBConfig for OpenGL") );

        m_glContext = glXCreateContextAttribsARB( wxGetX11Display(), fbc[0],
            other ? other->m_glContext : None,
            GL_TRUE, gc->GetGLXContextAttribs() );

        glXDestroyContext( wxGetX11Display(), tempContext );
    }
    else if ( wxGLCanvas::GetGLXVersion() >= 13 )
    {
        GLXFBConfig *fbc = gc->GetGLXFBConfig();
        wxCHECK_RET( fbc, wxT("invalid GLXFBConfig for OpenGL") );

        m_glContext = glXCreateNewContext( wxGetX11Display(), fbc[0], GLX_RGBA_TYPE,
                                           other ? other->m_glContext : None,
                                           GL_TRUE );
    }
    else // GLX <= 1.2
    {
        XVisualInfo *vi = gc->GetXVisualInfo();
        wxCHECK_RET( vi, wxT("invalid visual for OpenGL") );

        m_glContext = glXCreateContext( wxGetX11Display(), vi,
                                        other ? other->m_glContext : None,
                                        GL_TRUE );
    }

    wxASSERT_MSG( m_glContext, wxT("Couldn't create OpenGL context") );
}
示例#4
0
文件: glx11.cpp 项目: beanhome/dev
/* static */
bool wxGLCanvasBase::IsExtensionSupported(const char *extension)
{
    Display * const dpy = wxGetX11Display();

    return IsExtensionInList(glXQueryExtensionsString(dpy, DefaultScreen(dpy)),
                             extension);
}
示例#5
0
文件: glx11.cpp 项目: beanhome/dev
bool wxGLCanvasX11::SwapBuffers()
{
    const Window xid = GetXWindow();
    wxCHECK2_MSG( xid, return false, wxT("window must be shown") );

    glXSwapBuffers(wxGetX11Display(), xid);
    return true;
}
示例#6
0
文件: glx11.cpp 项目: beanhome/dev
wxGLContext::~wxGLContext()
{
    if ( !m_glContext )
        return;

    if ( m_glContext == glXGetCurrentContext() )
        MakeCurrent(None, NULL);

    glXDestroyContext( wxGetX11Display(), m_glContext );
}
示例#7
0
文件: glx11.cpp 项目: beanhome/dev
wxGLContext::wxGLContext(wxGLCanvas *gc, const wxGLContext *other)
{
    if ( wxGLCanvas::GetGLXVersion() >= 13 )
    {
        GLXFBConfig *fbc = gc->GetGLXFBConfig();
        wxCHECK_RET( fbc, wxT("invalid GLXFBConfig for OpenGL") );

        m_glContext = glXCreateNewContext( wxGetX11Display(), fbc[0], GLX_RGBA_TYPE,
                                           other ? other->m_glContext : None,
                                           GL_TRUE );
    }
    else // GLX <= 1.2
    {
        XVisualInfo *vi = gc->GetXVisualInfo();
        wxCHECK_RET( vi, wxT("invalid visual for OpenGL") );

        m_glContext = glXCreateContext( wxGetX11Display(), vi,
                                        other ? other->m_glContext : None,
                                        GL_TRUE );
    }

    wxASSERT_MSG( m_glContext, wxT("Couldn't create OpenGL context") );
}
示例#8
0
文件: glx11.cpp 项目: beanhome/dev
/* static */
int wxGLCanvasX11::GetGLXVersion()
{
    static int s_glxVersion = 0;
    if ( s_glxVersion == 0 )
    {
        // check the GLX version
        int glxMajorVer, glxMinorVer;
        bool ok = glXQueryVersion(wxGetX11Display(), &glxMajorVer, &glxMinorVer);
        wxASSERT_MSG( ok, wxT("GLX version not found") );
        if (!ok)
            s_glxVersion = 10; // 1.0 by default
        else
            s_glxVersion = glxMajorVer*10 + glxMinorVer;
    }

    return s_glxVersion;
}