Exemplo n.º 1
0
//----------------------------------------------------------------------
// configInit
//----------------------------------------------------------------------
bool Window::configInit( const uint128_t& initID )
{
    if( !getPixelViewport().isValid( ))
    {
        sendError( ERROR_WINDOW_PVP_INVALID );
        return false;
    }

    LBASSERT( !_systemWindow );

    int glMajorVersion = 1;
    int glMinorVersion = 1;
    if( getPipe()->getSystemPipe()->getMaxOpenGLVersion() != AUTO )
    {
        float maj, min;
        min = modff( getPipe()->getSystemPipe()->getMaxOpenGLVersion(), &maj );
        glMajorVersion = static_cast< int >( maj );
        glMinorVersion = static_cast< int >( min*10.f );
    }

    if( getIAttribute( WindowSettings::IATTR_HINT_OPENGL_MAJOR ) == AUTO )
        setIAttribute( WindowSettings::IATTR_HINT_OPENGL_MAJOR, glMajorVersion);
    if( getIAttribute( WindowSettings::IATTR_HINT_OPENGL_MINOR ) == AUTO )
        setIAttribute( WindowSettings::IATTR_HINT_OPENGL_MINOR, glMinorVersion);

    return configInitSystemWindow( initID ) && configInitGL( initID );
}
Exemplo n.º 2
0
//----------------------------------------------------------------------
// configInit
//----------------------------------------------------------------------
bool Window::configInit( const uint128_t& initID )
{
    if( !getPixelViewport().isValid( ))
    {
        sendError( ERROR_WINDOW_PVP_INVALID );
        return false;
    }

    LBASSERT( !_systemWindow );

    return configInitSystemWindow( initID ) && configInitGL( initID );
}
Exemplo n.º 3
0
bool Pipe::_configInitGLXEW()
{
    LBASSERT( _xDisplay );

    //----- Create and make current a temporary GL context to initialize GLXEW
    // visual
    std::vector<int> attributes;
    attributes.push_back( GLX_RGBA );
    attributes.push_back( None );

    const int    screen  = DefaultScreen( _xDisplay );
    XVisualInfo *visualInfo = glXChooseVisual( _xDisplay, screen,
                                               &attributes.front( ));
    if( !visualInfo )
    {
        setError( ERROR_SYSTEMPIPE_PIXELFORMAT_NOTFOUND );
        return false;
    }

    //context
    GLXContext context = glXCreateContext( _xDisplay, visualInfo, 0, True );
    if( !context )
    {
        setError( ERROR_SYSTEMPIPE_CREATECONTEXT_FAILED );
        return false;
    }

    // window
    const XID parent = RootWindow( _xDisplay, screen );
    XSetWindowAttributes wa;
    wa.colormap = XCreateColormap( _xDisplay, parent, visualInfo->visual,
                                   AllocNone );
    wa.background_pixmap = None;
    wa.border_pixel = 0;
    XID drawable = XCreateWindow( _xDisplay, parent, 0, 0, 16, 16,
                                  0, visualInfo->depth, InputOutput,
                                  visualInfo->visual, 
                                  CWBackPixmap | CWBorderPixel | CWColormap,
                                  &wa );
    if( !drawable )
    {
        setError( ERROR_SYSTEMPIPE_CREATEWINDOW_FAILED );
        return false;
    }   

    XFree( visualInfo );
    XSync( _xDisplay, False );

    glXMakeCurrent( _xDisplay, drawable, context );

    const GLenum result = glxewInit();
    bool success = result == GLEW_OK;
    if( success )
    {
        LBVERB << "Pipe GLXEW initialization successful" << std::endl;
        success = configInitGL();
    }
    else
    {
        setError( ERROR_GLXPIPE_GLXEWINIT_FAILED );
        LBWARN << getError() << ": " << result << std::endl;
    }

    XSync( _xDisplay, False );
    glXDestroyContext( _xDisplay, context );
    XDestroyWindow( _xDisplay, drawable );

    return success;
}
Exemplo n.º 4
0
bool Pipe::_configInitWGLEW()
{
    //----- Create and make current a temporary GL context to initialize WGLEW

    // window class
    std::ostringstream className;
    className << "TMP" << (void*)this;
    const std::string& classStr = className.str();
                                  
    HINSTANCE instance = GetModuleHandle( 0 );
    WNDCLASS  wc       = { 0 };
    wc.lpfnWndProc   = DefWindowProc;
    wc.hInstance     = instance; 
    wc.hIcon         = LoadIcon( 0, IDI_WINLOGO );
    wc.hCursor       = LoadCursor( 0, IDC_ARROW );
    wc.lpszClassName = classStr.c_str();       

    if( !RegisterClass( &wc ))
    {
        setError( ERROR_WGLPIPE_REGISTERCLASS_FAILED );
        EQWARN << getError() << ": " << co::base::sysError << std::endl;
        return false;
    }

    // window
    DWORD windowStyleEx = WS_EX_APPWINDOW;
    DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;

    HWND hWnd = CreateWindowEx( windowStyleEx,
                                wc.lpszClassName, "TMP",
                                windowStyle, 0, 0, 1, 1,
                                0, 0, // parent, menu
                                instance, 0 );

    if( !hWnd )
    {
        setError( ERROR_SYSTEMPIPE_CREATEWINDOW_FAILED );
        EQWARN << getError() << ": " << co::base::sysError << std::endl;
        UnregisterClass( classStr.c_str(),  instance );
        return false;
    }

    HDC                   dc  = GetDC( hWnd );
    PIXELFORMATDESCRIPTOR pfd = {0};
    pfd.nSize        = sizeof(PIXELFORMATDESCRIPTOR);
    pfd.nVersion     = 1;
    pfd.dwFlags      = PFD_DRAW_TO_WINDOW |
                       PFD_SUPPORT_OPENGL;

    int pf = ChoosePixelFormat( dc, &pfd );
    if( pf == 0 )
    {
        setError( ERROR_SYSTEMPIPE_PIXELFORMAT_NOTFOUND );
        EQWARN << getError() << ": " << co::base::sysError << std::endl;
        DestroyWindow( hWnd );
        UnregisterClass( classStr.c_str(),  instance );
        return false;
    }
 
    if( !SetPixelFormat( dc, pf, &pfd ))
    {
        setError( ERROR_WGLPIPE_SETPF_FAILED );
        EQWARN << getError() << ": " << co::base::sysError << std::endl;
        ReleaseDC( hWnd, dc );
        DestroyWindow( hWnd );
        UnregisterClass( classStr.c_str(),  instance );
        return false;
    }

    // context
    HGLRC context = wglCreateContext( dc );
    if( !context )
    {
        setError( ERROR_SYSTEMPIPE_CREATECONTEXT_FAILED );
        EQWARN << getError() << ": " << co::base::sysError << std::endl;
        ReleaseDC( hWnd, dc );
        DestroyWindow( hWnd );
        UnregisterClass( classStr.c_str(),  instance );
        return false;
    }

    HDC   oldDC      = wglGetCurrentDC();
    HGLRC oldContext = wglGetCurrentContext();

    wglMakeCurrent( dc, context );

    const GLenum result = wglewInit();
    bool success = result == GLEW_OK;
    if( success )
    {
        EQINFO << "Pipe WGLEW initialization successful" << std::endl;
        success = configInitGL();
    }
    else
    {
        setError( ERROR_WGLPIPE_WGLEWINIT_FAILED );
        EQWARN << getError() << ": " << result << std::endl;
    }

    wglDeleteContext( context );
    ReleaseDC( hWnd, dc );
    DestroyWindow( hWnd );
    UnregisterClass( classStr.c_str(),  instance );
    wglMakeCurrent( oldDC, oldContext );

    return success;
}