Beispiel #1
0
RenderArea::RenderArea(RenderAreaPtr theContext) : AbstractRenderWindow(jslib::JSApp::ShellErrorReporter),
    _myContextRefCount(0),
    _isFirstFrame(true)
{
    GdkGLConfig * myGLConfig = gdk_gl_config_new_by_mode(
                GdkGLConfigMode(GDK_GL_MODE_RGBA | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_ALPHA));
    if (myGLConfig == 0) {
        throw asl::Exception("can't init GL",PLUS_FILE_LINE);
    }

    // If another render area is supplied as constructor paramter, this render area is uses as
    // source for a shared y60-gl-context and gdk-gl-context.
    GdkGLContext * myGdkGLContext = 0;
    if (theContext) {
        myGdkGLContext = theContext->getGdkGlContext();
        if (!myGdkGLContext) {
            throw asl::Exception("RenderArea: Failed to get gdk GL context from shared render area.", PLUS_FILE_LINE);
        }
        setGLContext(theContext->getGLContext());
    } else {
        setGLContext(GLContextPtr(new GLContext()));
    }

    /* Set OpenGL-capability to the widget. */
    DB(cerr << "RenderArea::RenderArea() sharing with " << myGdkGLContext << endl);
    if (!gtk_widget_set_gl_capability (GTK_WIDGET(gobj()),
                myGLConfig,
                myGdkGLContext,
                true,
                GDK_GL_RGBA_TYPE))
    {
        throw asl::Exception("RenderArea: could not create GL context!", PLUS_FILE_LINE);
    }

    // enable mouse events
    Gdk::EventMask flags = get_events();
    flags |= Gdk::BUTTON_PRESS_MASK;
    flags |= Gdk::POINTER_MOTION_MASK;
    flags |= Gdk::BUTTON_RELEASE_MASK;
    flags |= Gdk::SCROLL_MASK;
    flags |= Gdk::ENTER_NOTIFY_MASK;
    flags |= Gdk::LEAVE_NOTIFY_MASK;
    set_events(flags);

    y60::EventDispatcher::get().addSource(&_myEventAdapter);
    y60::EventDispatcher::get().addSink(this);
    // TODO: createRenderer(theOtherRenderer);

    ShaderLibrary::setGLisReadyFlag(true);
}
Beispiel #2
0
SecondaryWindow::SecondaryWindow(const WindowParams& wp, bool bIsFullscreen,
        GLConfig glConfig)
    : Window(wp, bIsFullscreen)
{
#ifdef linux
    GLContext* pMainContext = GLContext::getCurrent();
    GLContext* pGLContext;
    IntRect windowDimensions(wp.m_Pos, wp.m_Pos+wp.m_Size);
    string sDisplay = ":0." + toString(wp.m_DisplayServer);
    pGLContext = new SecondaryGLXContext(glConfig, sDisplay, windowDimensions,
            wp.m_bHasWindowFrame);
    setGLContext(pGLContext);
    
    pMainContext->activate();
#endif
}
Beispiel #3
0
SDLWindow::SDLWindow(const DisplayParams& dp, GLConfig glConfig)
    : Window(dp.getWindowParams(0), dp.isFullscreen()),
      m_pLastMouseEvent(new MouseEvent(Event::CURSOR_MOTION, false, false, false, 
            IntPoint(-1, -1), MouseEvent::NO_BUTTON, glm::vec2(-1, -1), 0))
{
    initTranslationTable();

    // This "fixes" the default behaviour of SDL under x11, avoiding it
    // to report relative mouse coordinates when going fullscreen and
    // the mouse cursor is hidden (grabbed). So far libavg and apps based
    // on it don't use relative coordinates.
    setEnv("SDL_MOUSE_RELATIVE", "0");
    const WindowParams& wp = dp.getWindowParams(0);

    stringstream ss;
    IntPoint pos = getPos();
    if (pos.x != -1) {
        ss << pos.x << "," << pos.y;
        setEnv("SDL_VIDEO_WINDOW_POS", ss.str().c_str());
    }
    unsigned int flags = 0;
    if (dp.isFullscreen()) {
        flags |= SDL_FULLSCREEN;
    }
    if (!wp.m_bHasWindowFrame) {
        flags |= SDL_NOFRAME;
    }

    IntPoint size = wp.m_Size;
    SDL_Surface * pSDLSurface = 0;
#ifndef linux
    if (glConfig.m_bUseDebugContext) {
        glConfig.m_bUseDebugContext = false;
    }
    switch (dp.getBPP()) {
        case 24:
            SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
            SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
            SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
            SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 24);
            break;
        case 16:
            SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
            SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
            SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
            SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16);
            break;
        default:
            AVG_LOG_ERROR("Unsupported bpp " << dp.getBPP() <<
                    "in Window::init()");
            exit(-1);
    }
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL , 0); 
    flags |= SDL_OPENGL;

    while (glConfig.m_MultiSampleSamples && !pSDLSurface) {
        if (glConfig.m_MultiSampleSamples > 1) {
            SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
            SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,
                    glConfig.m_MultiSampleSamples);
        } else {
            SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
            SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
        }
        pSDLSurface = SDL_SetVideoMode(size.x, size.y, dp.getBPP(), flags);
        if (!pSDLSurface) {
            glConfig.m_MultiSampleSamples = GLContext::nextMultiSampleValue(
                    glConfig.m_MultiSampleSamples);
        }
    }
#else
    // Linux version: Context created manually, not by SDL
    pSDLSurface = SDL_SetVideoMode(size.x, size.y, dp.getBPP(), flags);
#endif
    if (!pSDLSurface) {
        throw Exception(AVG_ERR_UNSUPPORTED, string("Setting SDL video mode failed: ")
                + SDL_GetError() + ". (size=" + toString(size) + ", bpp=" + 
                toString(dp.getBPP()) + ").");
    }
    SDL_SysWMinfo info;
    SDL_VERSION(&info.version);
    int rc = SDL_GetWMInfo(&info);
    AVG_ASSERT(rc != -1);
    GLContext* pGLContext = GLContextManager::get()->createContext(glConfig, size, &info);
    setGLContext(pGLContext);

#if defined(HAVE_XI2_1) || defined(HAVE_XI2_2) 
    SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
    m_pXIMTInputDevice = 0;
#endif
    SDL_WM_SetCaption("libavg", 0);

    pGLContext->logConfig();
}