コード例 #1
0
void Z3DCanvasRenderer::process(Z3DEye eye)
{
  if (!m_canvas)
    return;

  Z3DRenderInputPort &currentInport = (eye == CenterEye) ?
        m_inport : (eye == LeftEye) ? m_leftEyeInport : m_rightEyeInport;

  // render to image
  if (currentInport.isReady() && m_renderToImage) {
    try {
      renderInportToImage(m_renderToImageFilename, eye);
      if (eye == CenterEye) {
        LINFO() << "Saved rendering (" << currentInport.getSize().x << "," <<
                   currentInport.getSize().y << ")" << "to file:" << m_renderToImageFilename;
      } else if (eye == RightEye) {
        if (m_renderToImageType == HalfSideBySideStereoView) {
          LINFO() << "Saved half sbs stereo rendering (" << currentInport.getSize().x << "," <<
                     currentInport.getSize().y << ")" << "to file:" << m_renderToImageFilename;
        } else {
          LINFO() << "Saved stereo rendering (" << currentInport.getSize().x << "x 2," <<
                     currentInport.getSize().y << ")" << "to file:" << m_renderToImageFilename;
        }
      }
    }
    catch (Exception const & e) {
      LERROR() << "Exception:" << e.what();
      m_renderToImageError = QString(e.what());
    }
    catch (std::exception const & e) {
      LERROR() << "std exception:" << e.what();
      m_renderToImageError = QString(e.what());
    }
    if (eye == CenterEye || eye == RightEye) {
      m_renderToImage = false;
      // now render the to screen to prevent a blank screen
      invalidate();
    }
    return;
  }

  // render to screen
  m_canvas->getGLFocus();
  glViewport(0, 0, m_canvas->getPhysicalSize().x, m_canvas->getPhysicalSize().y);
  if (eye == LeftEye)
    glDrawBuffer(GL_BACK_LEFT);
  else if (eye == RightEye)
    glDrawBuffer(GL_BACK_RIGHT);
  if (currentInport.isReady()) {
    m_rendererBase->setViewport(m_canvas->getPhysicalSize());
    m_textureCopyRenderer->setColorTexture(currentInport.getColorTexture());
    m_textureCopyRenderer->setDepthTexture(currentInport.getDepthTexture());
    m_rendererBase->render(eye);
    CHECK_GL_ERROR;
  } else {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    CHECK_GL_ERROR;
  }
}
コード例 #2
0
ファイル: canvasrenderer.cpp プロジェクト: 151706061/Voreen
void CanvasRenderer::process() {
    if (!canvas_)
        return;

    canvas_->getGLFocus();
    glViewport(0, 0, canvas_->getSize().x, canvas_->getSize().y);

    if (inport_.isReady()) {
        // render inport to image, if renderToImage flag has been set
        if (renderToImage_) {
            try {
                renderInportToImage(renderToImageFilename_);
                LINFO("Saved rendering with dimensions " << inport_.getSize() << " to file: " << tgt::FileSystem::cleanupPath(renderToImageFilename_));
            }
            catch (std::bad_alloc& /*e*/) {
                LERROR("Exception in CanvasRenderer::renderInportToImage(): bad allocation (" << getID() << ")");
                renderToImageError_ = "Not enough system memory (bad allocation)";
            }
            catch (VoreenException& e) {
                LERROR(e.what());
                renderToImageError_ = std::string(e.what());
            }
            catch (std::exception& e) {
                LERROR("Exception in CanvasRenderer::renderInportToImage(): " << e.what() << " (" << getID() << ")");
                renderToImageError_ = std::string(e.what());
            }
            renderToImage_ = false;
        }
        // map texture of input target onto a screen-aligned quad
        else {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            // activate shader
            shader_->activate();

            // set common uniforms
            setGlobalShaderParameters(shader_);

            // manually pass the viewport dimensions to the shader,
            // since setGlobalShaderParameters() expects a render outport, which we do not have
            shader_->setIgnoreUniformLocationError(true);
            shader_->setUniform("screenDim_", tgt::vec2(canvas_->getSize()));
            shader_->setUniform("screenDimRCP_", 1.f / tgt::vec2(canvas_->getSize()));
            shader_->setIgnoreUniformLocationError(false);

            // bind input textures
            inport_.bindTextures(GL_TEXTURE0, GL_TEXTURE1);

            // pass texture parameters to the shader
            shader_->setUniform("colorTex_", 0);
            shader_->setUniform("depthTex_", 1);
            inport_.setTextureParameters(shader_, "texParams_");
            LGL_ERROR;

            // execute the shader
            renderQuad();
            shader_->deactivate();
            LGL_ERROR;
        }
    }
    else {
        // render error texture
        if (!errorTex_) {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            return;
        }
        glClear(GL_DEPTH_BUFFER_BIT);

        glActiveTexture(GL_TEXTURE0);
        errorTex_->bind();
        errorTex_->enable();

        glColor3f(1.f, 1.f, 1.f);
        renderQuad();

        errorTex_->disable();
    }

    glActiveTexture(GL_TEXTURE0);
    LGL_ERROR;
}