void StGLRootWidget::stglResize(const StGLBoxPx& theRectPx) { const bool isChanged = getRectPx().right() != theRectPx.width() || getRectPx().bottom() != theRectPx.height(); myProjCamera.resize(*myGlCtx, theRectPx.width(), theRectPx.height()); changeRectPx().right() = theRectPx.width(); // (left, top) forced to zero point (0, 0) changeRectPx().bottom() = theRectPx.height(); myProjCamera.getZParams(myRectGl); myScaleGlX = (myRectGl.right() - myRectGl.left()) / GLdouble(getRectPx().width()); myScaleGlY = (myRectGl.top() - myRectGl.bottom()) / GLdouble(getRectPx().height()); myScrProjMat = myProjCamera.getProjMatrix(); myScrProjMat.translate(StGLVec3(0.0f, 0.0f, -myProjCamera.getZScreen())); if(myMenuProgram->isValid()) { myMenuProgram->use(*myGlCtx); myMenuProgram->setProjMat(*myGlCtx, getScreenProjection()); myMenuProgram->unuse(*myGlCtx); } // update all child widgets if(isChanged) { StGLWidget::stglResize(); } }
void StWindow::stglDraw() { if(myWin->myGlContext.isNull()) { return; } const StGLBoxPx aVPMaster = StWindow::stglViewport(ST_WIN_MASTER); const GLsizei aHeight = (aVPMaster .height() == 0) ? 1 : aVPMaster .height(); const StGLBoxPx aRect = {{ aVPMaster.x(), aVPMaster.y(), aVPMaster.width(), aHeight }}; myWin->myGlContext->stglResizeViewport(aRect); signals.onRedraw(ST_DRAW_LEFT); stglSwap(ST_WIN_ALL); }
void StCADViewerGUI::stglResize(const StGLBoxPx& theViewPort, const StMarginsI& theMargins, float theAspect) { const int aNewSizeX = theViewPort.width(); const int aWorkRight = stMax(aNewSizeX - theMargins.right, 2); if(myPanelUpper != NULL) { myPanelUpper->changeRectPx().right() = aWorkRight; } if(myPanelBottom != NULL) { myPanelBottom->changeRectPx().right() = aWorkRight; } StGLRootWidget::stglResize(theViewPort, theMargins, theAspect); }
void StOutAnaglyph::stglDraw() { myFPSControl.setTargetFPS(StWindow::getTargetFps()); const StGLBoxPx aVPort = StWindow::stglViewport(ST_WIN_MASTER); if(!StWindow::isStereoOutput() || myIsBroken) { StWindow::stglMakeCurrent(ST_WIN_MASTER); myContext->stglResizeViewport(aVPort); if(myToCompressMem) { myFrBuffer->release(*myContext); } StWindow::signals.onRedraw(ST_DRAW_LEFT); myFPSControl.sleepToTarget(); // decrease FPS to target by thread sleeps StWindow::stglSwap(ST_WIN_MASTER); ++myFPSControl; return; } StWindow::stglMakeCurrent(ST_WIN_MASTER); // resize FBO if(!myFrBuffer->initLazy(*myContext, aVPort.width(), aVPort.height(), StWindow::hasDepthBuffer())) { myMsgQueue->pushError(stCString("Anaglyph output - critical error:\nFrame Buffer Object resize failed!")); myIsBroken = true; return; } // draw into virtual frame buffers (textures) myFrBuffer->setupViewPort(*myContext); // we set TEXTURE sizes here myFrBuffer->bindBufferLeft(*myContext); StWindow::signals.onRedraw(ST_DRAW_LEFT); myFrBuffer->bindBufferRight(*myContext); StWindow::signals.onRedraw(ST_DRAW_RIGHT); myFrBuffer->unbindBufferRight(*myContext); // now draw to real screen buffer // clear the screen and the depth buffer myContext->stglResizeViewport(aVPort); myContext->core20fwd->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); myContext->core20fwd->glDisable(GL_DEPTH_TEST); myContext->core20fwd->glDisable(GL_BLEND); myFrBuffer->bindMultiTexture(*myContext); myFrBuffer->drawQuad(*myContext, myStereoProgram); myFrBuffer->unbindMultiTexture(*myContext); myFPSControl.sleepToTarget(); // decrease FPS to target by thread sleeps StWindow::stglSwap(ST_WIN_MASTER); ++myFPSControl; }
void StGLRootWidget::stglScissorRect(const StRectI_t& theRect, StGLBoxPx& theScissorRect) const { const GLint aVPortWidth = myViewport[2]; const GLint aVPortHeight = myViewport[3]; const GLint aRootWidth = getRectPx().width(); const GLint aRootHeight = getRectPx().height(); if(aRootWidth <= 0 || aRootHeight <= 0) { // just prevent division by zero - should never happen stMemZero(&theScissorRect, sizeof(StGLBoxPx)); return; } // viewport could have different size in case of rendering to FBO const GLdouble aWidthFactor = GLdouble(aVPortWidth) / GLdouble(aRootWidth); const GLdouble aHeightFactor = GLdouble(aVPortHeight) / GLdouble(aRootHeight); theScissorRect.x() = myViewport[0] + GLint(aWidthFactor * GLdouble(theRect.left())) + myScrDispXPx; theScissorRect.y() = myViewport[1] + GLint(aHeightFactor * GLdouble(aRootHeight - theRect.bottom())); theScissorRect.width() = GLint(aWidthFactor * GLdouble(theRect.width())); theScissorRect.height() = GLint(aHeightFactor * GLdouble(theRect.height())); }
void StOutIZ3D::stglDraw() { if(!StWindow::stglMakeCurrent(ST_WIN_MASTER)) { StWindow::signals.onRedraw(ST_DRAW_MONO); StThread::sleep(10); return; } myFPSControl.setTargetFPS(StWindow::getTargetFps()); const StGLBoxPx aVPMaster = StWindow::stglViewport(ST_WIN_MASTER); const StGLBoxPx aVPSlave = StWindow::stglViewport(ST_WIN_SLAVE); if(!StWindow::isStereoOutput() || myIsBroken) { if(myToCompressMem) { myFrBuffer->release(*myContext); } myContext->stglResizeViewport(aVPMaster); myContext->stglSetScissorRect(aVPMaster, false); StWindow::signals.onRedraw(ST_DRAW_LEFT); myContext->stglResetScissorRect(); StWindow::stglMakeCurrent(ST_WIN_SLAVE); myContext->stglResizeViewport(aVPSlave); myContext->stglSetScissorRect(aVPSlave, false); myContext->core20fwd->glClearColor(0.729740052840723f, 0.729740052840723f, 0.729740052840723f, 0.0f); // clear the screen and the depth buffer myContext->core20fwd->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); myContext->core20fwd->glClearColor(0, 0, 0, 0); myContext->stglResetScissorRect(); myFPSControl.sleepToTarget(); // decrease FPS to target by thread sleeps StWindow::stglSwap(ST_WIN_ALL); ++myFPSControl; return; } // resize FBO if(!myFrBuffer->initLazy(*myContext, aVPMaster.width(), aVPMaster.height(), StWindow::hasDepthBuffer())) { myMsgQueue->pushError(stCString("iZ3D output - critical error:\nFrame Buffer Object resize failed!")); myIsBroken = true; return; } // draw into virtual frame buffers (textures) myFrBuffer->setupViewPort(*myContext); // we set TEXTURE sizes here myFrBuffer->bindBufferLeft(*myContext); StWindow::signals.onRedraw(ST_DRAW_LEFT); myFrBuffer->bindBufferRight(*myContext); StWindow::signals.onRedraw(ST_DRAW_RIGHT); myFrBuffer->unbindBufferRight(*myContext); // now draw to real screen buffer // clear the screen and the depth buffer myContext->stglResizeViewport(aVPMaster); myContext->stglSetScissorRect(aVPMaster, false); myContext->core20fwd->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); myContext->core20fwd->glDisable(GL_DEPTH_TEST); myContext->core20fwd->glDisable(GL_BLEND); StGLTexture& stTexTable = (myShaders.getMode() == StOutIZ3DShaders::IZ3D_TABLE_NEW) ? myTexTableNew : myTexTableOld; myShaders.master()->use(*myContext); myFrBuffer->bindMultiTexture(*myContext); stTexTable.bind(*myContext, GL_TEXTURE2); myFrBuffer->drawQuad(*myContext, myShaders.master()); stTexTable.unbind(*myContext); myFrBuffer->unbindMultiTexture(*myContext); myShaders.master()->unuse(*myContext); myContext->stglResetScissorRect(); StWindow::stglMakeCurrent(ST_WIN_SLAVE); myContext->stglResizeViewport(aVPSlave); myContext->stglSetScissorRect(aVPSlave, false); myContext->core20fwd->glClearColor(0.729740052840723f, 0.729740052840723f, 0.729740052840723f, 0.0f); // clear the screen and the depth buffer myContext->core20fwd->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); myContext->core20fwd->glClearColor(0, 0, 0, 0); myShaders.slave()->use(*myContext); myFrBuffer->bindMultiTexture(*myContext); stTexTable.bind(*myContext, GL_TEXTURE2); myFrBuffer->drawQuad(*myContext, myShaders.slave()); stTexTable.unbind(*myContext); myFrBuffer->unbindMultiTexture(*myContext); myShaders.slave()->unuse(*myContext); myContext->stglResetScissorRect(); myFPSControl.sleepToTarget(); // decrease FPS to target by thread sleeps StWindow::stglSwap(ST_WIN_ALL); ++myFPSControl; // make sure all GL changes in callback (in StDrawer) will fine StWindow::stglMakeCurrent(ST_WIN_MASTER); }