void SVG::render(const QRectF& texCoords) { // get on-screen and full rectangle corresponding to the window in pixel units const QRectF screenRect = renderContext_->getGLWindow()->getProjectedPixelRect(true); const QRectF fullRect = renderContext_->getGLWindow()->getProjectedPixelRect(false); // maps to [tX, tY, tW, tH] // If we're not visible or we don't have a valid SVG, we're done. if(screenRect.isEmpty() || !svgRenderer_.isValid()) { textureData_.erase(renderContext_->getActiveGLWindow()->getTileIndex()); return; } // Get the texture for the current GLWindow SVGTextureData& textureData = textureData_[renderContext_->getActiveGLWindow()->getTileIndex()]; const QRectF textureRect = computeTextureRect(screenRect, fullRect, texCoords); const QSize textureSize(round(screenRect.width()), round(screenRect.height())); const bool recreateTextureFbo = !textureData.fbo || textureData.fbo->size() != textureSize; if( recreateTextureFbo || textureRect != textureData.region ) { if ( recreateTextureFbo ) { textureData.fbo.reset( new QGLFramebufferObject( textureSize )); } renderToTexture(textureRect, textureData.fbo); // keep rendered texture information so we know when to rerender // this works great when the SVG is only rendered once per GLWindow // however, it will rerender every time otherwise, for example if the zoom context is shown textureData.region = textureRect; } assert(textureData.fbo); // figure out what visible region is for screenRect, a subregion of [0, 0, 1, 1] const float xp = (screenRect.x() - fullRect.x()) / fullRect.width(); const float yp = (screenRect.y() - fullRect.y()) / fullRect.height(); const float wp = screenRect.width() / fullRect.width(); const float hp = screenRect.height() / fullRect.height(); // Render the (scaled) unit textured quad glPushMatrix(); glTranslatef(xp, yp, 0); glScalef(wp, hp, 1.f); drawUnitTexturedQuad(textureData.fbo->texture()); glPopMatrix(); }
bool PixelStreamSegmentRenderer::render(bool showSegmentBorders, bool showSegmentStatistics) { if(!texture_.isValid()) return false; // OpenGL transformation glPushMatrix(); glTranslatef(x_, y_, 0.); // The following draw calls assume normalized coordinates, so we must pre-multiply by this segment's dimensions glScalef(width_, height_, 0.); drawUnitTexturedQuad(); if(showSegmentBorders || showSegmentStatistics) { glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT | GL_DEPTH_BUFFER_BIT); glLineWidth(2); glPushMatrix(); glTranslatef(0.,0.,0.05); // render segment borders if(showSegmentBorders) { drawSegmentBorders(); } // render segment statistics if(showSegmentStatistics) { drawSegmentStatistics(); } glPopMatrix(); glPopAttrib(); } glPopMatrix(); return true; }
void PDF::render(const QRectF& texCoords) { if (!pdfPage_) return; // get on-screen and full rectangle corresponding to the window const QRectF screenRect = GLWindow::getProjectedPixelRect(true); const QRectF fullRect = GLWindow::getProjectedPixelRect(false); // if we're not visible or we don't have a valid SVG, we're done... if(screenRect.isEmpty()) { // TODO clear existing FBO for this OpenGL window return; } // generate texture corresponding to the visible part of these texture coordinates generateTexture(screenRect, fullRect, texCoords); if(!texture_.isValid()) return; // figure out what visible region is for screenRect, a subregion of [0, 0, 1, 1] const float xp = (screenRect.x() - fullRect.x()) / fullRect.width(); const float yp = (screenRect.y() - fullRect.y()) / fullRect.height(); const float wp = screenRect.width() / fullRect.width(); const float hp = screenRect.height() / fullRect.height(); // Render the entire texture on a (scaled) unit textured quad glPushMatrix(); glTranslatef(xp, yp, 0); glScalef(wp, hp, 1.f); drawUnitTexturedQuad(); glPopMatrix(); }