Exemple #1
0
WINGDIAPI BOOL WINAPI wglMakeCurrent(HDC hdc, DHGLRC hglrc)
{
    if (!gCurrentContextSet)
    {
        gCurrentContext = gContexts.end();
        gCurrentContextSet = true;
    }

    if (!hdc || !hglrc)
    {
        gCurrentContext = gContexts.end();
        return 1;
    }

    int rc = (int)hglrc;

    if (gContexts.find(rc) == gCurrentContext)
    {
        return 1;
    }

    gCurrentContext = gContexts.find(rc);

    auto &xCtxt = gContexts[rc];
    OGL::State *pState = xCtxt.pState;

    HWND hWnd = WindowFromDC(hdc);
    RECT rect;
    GetClientRect(hWnd, &rect);

    int width = rect.right - rect.left;
    int height = rect.bottom - rect.top;

    SetOGL(pState);
    OGL::GetDDProcTable().pfnBindContext(OGL::GetDDHandle(), NULL, hWnd, NULL, width, height);

    // according to spec, only set current viewport to draw buffer dimensions if the context hasn't
    // been initialized
    if (!xCtxt.initialized)
    {
        pState->mViewport.x = 0;
        pState->mViewport.y = 0;
        pState->mViewport.width = width;
        pState->mViewport.height = height;
        pState->mScissor.x = 0;
        pState->mScissor.y = 0;
        pState->mScissor.width = width;
        pState->mScissor.height = height;
        xCtxt.initialized = true;
    }
    return 1;
}
Exemple #2
0
Bool glXMakeContextCurrent(Display *pDisplay, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
{
    // unbind current context if NULL ctx passed in
    if (ctx == NULL)
    {
        currentContext = contexts.end();
        return 1;
    }

    auto *pState = reinterpret_cast<OGL::State *>(ctx);
    if (contexts.find(pState) == currentContext)
    {
        return 1;
    }

    auto &xCtxt = contexts[pState];
    xCtxt.drawable = draw;

    SetOGL(pState);

    GLuint width, height;
    XWindowAttributes xWindowAttributes = { 0 };
    SWRPBuffer *buf;
    bool isDisplay;
    switch (gDrawables[draw])
    {
    case X:
        XGetWindowAttributes(pDisplay, draw, &xWindowAttributes);
        width = xWindowAttributes.width;
        height = xWindowAttributes.height;
        isDisplay = true;
        break;
    case PBUFFER:
        buf = (SWRPBuffer *)draw;
        width = buf->width;
        height = buf->height;
        isDisplay = false;
        break;
    default:
        assert(0 && "Invalid buffer type");
        return 0;
    }

    // bind render target set to SWR pipeline
    FrameBuffer *fb;
    if (gDrawableBuffers.find(draw) == gDrawableBuffers.end())
    {
        // we haven't seen this drawable yet, create a new frame buffer
        fb = new FrameBuffer();
        fb->Initialize(width, height, draw, xCtxt.pDisplay, xCtxt.pVisInfo, isDisplay);
        gDrawableBuffers[draw] = fb;
    }
    else
    {
        fb = gDrawableBuffers[draw];
    }

    OGL::GetDDProcTable().pfnSetRenderTarget(OGL::GetDDHandle(), fb->GetBackBuffer(), fb->GetDepthBuffer());

    // according to spec, only set current viewport to draw buffer dimensions if the context hasn't
    // been initialized
    if (!xCtxt.initialized)
    {
        pState->mViewport.x = 0;
        pState->mViewport.y = 0;
        pState->mViewport.width = width;
        pState->mViewport.height = height;
        pState->mScissor.x = 0;
        pState->mScissor.y = 0;
        pState->mScissor.width = width;
        pState->mScissor.height = height;
        xCtxt.initialized = true;
    }

    currentContext = contexts.find(pState);

    return 1;
}