DepthPeeling.cc 33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
*                                                                            *
\*===========================================================================*/


Jan Möbius's avatar
Jan Möbius committed
43

44
#include <ACG/GL/acg_glew.hh>
Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
45

Jan Möbius's avatar
Jan Möbius committed
46 47 48 49 50 51 52
#include "DepthPeeling.hh"

#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>


#include <ACG/GL/ShaderCache.hh>
53
#include <ACG/GL/GLError.hh>
54
#include <ACG/GL/ScreenQuad.hh>
Jan Möbius's avatar
Jan Möbius committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

using namespace ACG;


// =================================================
// depth peeling shader modifier

class PeelLayerModifier : public ShaderModifier
{
public:


  void modifyFragmentIO(ShaderGenerator* _shader)
  {
    _shader->addUniform("sampler2D g_DepthLayer");
70 71

    _shader->addOutput("float outDepth");
Jan Möbius's avatar
Jan Möbius committed
72 73 74 75 76 77 78 79 80 81 82 83
  }

  void modifyFragmentBeginCode(QStringList* _code)
  {
    // compare current depth with previous layer
    _code->push_back("float dp_prevDepth = texture(g_DepthLayer, sg_vScreenPos).x;");
    _code->push_back("if (gl_FragCoord.z <= dp_prevDepth) discard;");
  }

  void modifyFragmentEndCode(QStringList* _code)
  {
    _code->push_back("outFragment = vec4(sg_cColor.rgb * sg_cColor.a, sg_cColor.a);");
84
    _code->push_back("outDepth = gl_FragCoord.z;");
Jan Möbius's avatar
Jan Möbius committed
85 86 87 88 89 90 91 92 93
  }

  static PeelLayerModifier instance;
};


class PeelInitModifier : public ShaderModifier
{
public:
94 95 96 97 98 99

  void modifyFragmentIO(ShaderGenerator* _shader)
  {
    _shader->addOutput("float outDepth");
  }

Jan Möbius's avatar
Jan Möbius committed
100 101 102
  void modifyFragmentEndCode(QStringList* _code)
  {
    _code->push_back("outFragment = vec4(sg_cColor.rgb * sg_cColor.a, 1.0 - sg_cColor.a);");
103
    _code->push_back("outDepth = gl_FragCoord.z;");
Jan Möbius's avatar
Jan Möbius committed
104 105 106 107 108
  }

  static PeelInitModifier instance;
};

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
// for dual depth peeling only
class PeelDualLayerModifier : public ShaderModifier
{
public:

  void modifyFragmentIO(ShaderGenerator* _shader)
  {
    _shader->addUniform("sampler2D g_DepthLayer");
    _shader->addUniform("sampler2D g_FrontLayer");

    // MRT: color + depth output + last layer (eventually)
    _shader->addOutput("vec4 outDepth");
    _shader->addOutput("vec4 outBackColor");
  }

  void modifyFragmentBeginCode(QStringList* _code)
  {
    _code->push_back("float fragDepth = gl_FragCoord.z;");

128 129 130 131 132 133 134 135 136 137
#ifdef __APPLE__
    if(ACG::openGLVersion(3,3))
    {
        //on Apple systems with OpenGL 3.3 or higher, ht eGLSL version 330 is used no matter what we write
        _code->push_back("vec2 depthLayer = texture(g_DepthLayer, sg_vScreenPos).xy;");
        _code->push_back("vec4 forwardTemp = texture(g_FrontLayer, sg_vScreenPos);");
    }
    else
#endif
    {
138 139
    _code->push_back("vec2 depthLayer = texture2D(g_DepthLayer, sg_vScreenPos).xy;");
    _code->push_back("vec4 forwardTemp = texture2D(g_FrontLayer, sg_vScreenPos);");
140
    }
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    _code->push_back("outDepth = vec4(depthLayer, 0, 0);");
    _code->push_back("outFragment = forwardTemp;");
    _code->push_back("outBackColor = vec4(0,0,0,0);");


    _code->push_back("float nearestDepth = -depthLayer.x;");
    _code->push_back("float farthestDepth = depthLayer.y;");
    _code->push_back("float alphaMultiplier = 1.0 - forwardTemp.w;");


    _code->push_back("if (fragDepth < nearestDepth || fragDepth > farthestDepth) {");
    _code->push_back("outDepth = vec4(-1,-1,-1,-1);");
    _code->push_back("return;");
    _code->push_back("}");

    _code->push_back("if (fragDepth > nearestDepth && fragDepth < farthestDepth) {");
    _code->push_back("outDepth = vec4(-fragDepth, fragDepth, 0, 0);");
    _code->push_back("return;");
    _code->push_back("}");
  }


  void modifyFragmentEndCode(QStringList* _code)
  {
    _code->push_back("outDepth = vec4(-1,-1,-1,-1);");
    _code->push_back("outFragment = forwardTemp;");

    _code->push_back("if (fragDepth == nearestDepth) {");
    _code->push_back("outFragment.xyz += sg_cColor.rgb * sg_cColor.a * alphaMultiplier;");
    _code->push_back("outFragment.w = 1.0 - alphaMultiplier * (1.0 - sg_cColor.a);");

//    _code->push_back("outFragment = vec4(alphaMultiplier,alphaMultiplier,alphaMultiplier,1);");

    _code->push_back("} else {");
    _code->push_back("outBackColor += sg_cColor;");
    _code->push_back("}");
  }

  static PeelDualLayerModifier instance;
};

class PeelDualInitModifier : public ShaderModifier
{
public:
  void modifyFragmentEndCode(QStringList* _code)
  {
    _code->push_back("outFragment = vec4(-gl_FragCoord.z, gl_FragCoord.z, 0, 0);");
  }

  static PeelDualInitModifier instance;
};


Jan Möbius's avatar
Jan Möbius committed
194 195
PeelInitModifier PeelInitModifier::instance;
PeelLayerModifier PeelLayerModifier::instance;
196 197
PeelDualLayerModifier PeelDualLayerModifier::instance;
PeelDualInitModifier PeelDualInitModifier::instance;
Jan Möbius's avatar
Jan Möbius committed
198 199 200 201 202 203 204 205 206

// internal shader-attribute flags

#define RENDERFLAG_ALLOW_PEELING 1


// =================================================

DepthPeeling::DepthPeeling()
207
 : peelMode_(1), copyFrontDepth_(1), maxPeelCount_(20), peelBlend_(0), peelFinal_(0), peelQueryID_(0),
208
peelBlendDual_(0), peelFinalDual_(0)
Jan Möbius's avatar
Jan Möbius committed
209 210 211 212 213 214 215 216 217
{
}


DepthPeeling::~DepthPeeling()
{
}


218 219 220

QString DepthPeeling::checkOpenGL()
{
221 222
  //if(!ACG::compatibilityProfile())
  //  return QString("DepthPeeling render-plugin is nto yet compatible with core profile contexts.");
223
  if (!ACG::openGLVersion(3, 2))
224
    return QString("Insufficient OpenGL Version! OpenGL 3.2 or higher required");  
225

226
  //no other extensions are necessary, as OpenGL version 3.2 includes them all in the spec
227

228
  return QString("");
229 230 231
}


Jan Möbius's avatar
Jan Möbius committed
232 233 234 235 236
void DepthPeeling::initializePlugin()
{
  ACG::ShaderProgGenerator::setShaderDir(OpenFlipper::Options::shaderDirStr());
}

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
void DepthPeeling::exit()
{
  delete peelBlend_;
  peelBlend_ = 0;

  delete peelFinal_;
  peelFinal_ = 0;

  delete peelBlendDual_;
  peelBlendDual_ = 0;

  delete peelFinalDual_;
  peelFinalDual_ = 0;

  if (peelQueryID_)
    glDeleteQueries(1, &peelQueryID_);
  peelQueryID_ = 0;

  viewerRes_.clear();
}

258 259 260 261 262 263 264 265 266 267 268 269
void DepthPeeling::slotModeChanged( QAction *  _action) 
{
  // Prepare Picking Debugger Flag
  if ( _action->text() == "Front to Back") {
    peelMode_ = 0;
  } else if ( _action->text() == "Dual") {
    peelMode_ = 1;
  } else {
    std::cerr << "Error : optionHandling unable to find peeling mode!!! " << _action->text().toStdString() << std::endl;
    peelMode_ = 1;
  }
}
Jan Möbius's avatar
Jan Möbius committed
270 271 272

void DepthPeeling::render(ACG::GLState* _glState, Viewer::ViewerProperties& _properties)
{
273 274 275 276 277
  // debugging utilities
//   if (!dbgProg_)
//     dbgProg_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/dbg_shader.glsl");


Jan Möbius's avatar
Jan Möbius committed
278 279 280 281
  // collect renderobjects
  prepareRenderingPipeline(_glState, _properties.drawMode(), PluginFunctions::getSceneGraphRootNode());


282 283 284 285
  if (peelMode_ == 0)
    renderFrontPeeling(_glState, _properties);
  else
    renderDualPeeling(_glState, _properties);
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300

  // restore common opengl state
  // log window remains hidden otherwise
  finishRenderingPipeline();
}





void DepthPeeling::renderFrontPeeling(ACG::GLState* _glState,
                                      Viewer::ViewerProperties& _properties)
{
  const int numRenderObjects = getNumRenderObjects();

Jan Möbius's avatar
Jan Möbius committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
  // begin rendering
  // find last transparent object
  int lastPeeledObject = -1;

  for (int i = numRenderObjects - 1; i > lastPeeledObject; --i)
  {
    if ((sortedObjects_[i]->internalFlags_ & RENDERFLAG_ALLOW_PEELING) && sortedObjects_[i]->alpha < 0.99f)
      lastPeeledObject = i;
  }

  if (lastPeeledObject == -1)
  {
    // no transparent objects
    for (int i = 0; i < numRenderObjects; ++i)
      renderObject(sortedObjects_[i]);
  }
  else
  {
    // depth peeling code

321 322
    // make sure shaders and occlusion query are initialized
    initDepthPeeling();
Jan Möbius's avatar
Jan Möbius committed
323

324
    // resize fbo as necessary
Jan Möbius's avatar
Jan Möbius committed
325
    ViewerResources* viewRes = &viewerRes_[_properties.viewerId()];
326
    viewRes->resize(false, (unsigned int)_glState->viewport_width(), (unsigned int)_glState->viewport_height());
Jan Möbius's avatar
Jan Möbius committed
327 328


329 330
    // init MRT slots:
    //  RT0 - color blend texture
331
    //  RT1 - depth buffer copy
332 333 334 335 336 337
    const GLenum depthTarget = GL_COLOR_ATTACHMENT0;
    const GLenum colorTarget = GL_COLOR_ATTACHMENT1;
    const GLenum colorBlendTarget = GL_COLOR_ATTACHMENT4;
    GLenum peelLayerTargets[2] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};

    const float clearDepth = 1.0f;
338

Jan Möbius's avatar
Jan Möbius committed
339 340
    // begin peeling
    //  draw  first layer
341 342 343
    //  target depth buffer: depth0, front0
    glViewport(0, 0, viewRes->width_, viewRes->height_);
    glBindFramebuffer(GL_FRAMEBUFFER, viewRes->singleFbo_->getFboID());
Jan Möbius's avatar
Jan Möbius committed
344

345
    // allow color+depth write access
Jan Möbius's avatar
Jan Möbius committed
346 347 348
    glDepthMask(1);
    glColorMask(1,1,1,1);

349 350 351
    // clear color blend target
    glDrawBuffer(colorBlendTarget);
    glClearColor(_glState->clear_color()[0], _glState->clear_color()[1], _glState->clear_color()[2], 0);
352 353
    glClear(GL_COLOR_BUFFER_BIT);

354 355 356 357
    // clear colors  (front and back colors per pass)
    glDrawBuffer(colorTarget);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
Jan Möbius's avatar
Jan Möbius committed
358

359 360 361 362
    // clear depths
    glDrawBuffer(depthTarget);
    glClearColor(clearDepth, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
363

Jan Möbius's avatar
Jan Möbius committed
364

365 366 367 368 369
    // 1. Pass: initialize depth values
    //  the init shader also writes the first front layer colors in accumulation buffer
    peelLayerTargets[0] = colorBlendTarget;
    peelLayerTargets[1] = depthTarget;
    glDrawBuffers(2, peelLayerTargets); // write to MRT slots (color, depth)
Jan Möbius's avatar
Jan Möbius committed
370

371 372
    glDisable(GL_BLEND);
    glDisable(GL_ALPHA_TEST);
Jan Möbius's avatar
Jan Möbius committed
373 374 375

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
376
    glDisable(GL_CULL_FACE);
Jan Möbius's avatar
Jan Möbius committed
377 378 379

    for (int i = 0; i < numRenderObjects; ++i)
    {
380
//      if ((sortedObjects_[i]->internalFlags_ & RENDERFLAG_ALLOW_PEELING) && sortedObjects_[i]->alpha < 0.99f)
Jan Möbius's avatar
Jan Möbius committed
381 382 383
      {
        GLSL::Program* initProg = ShaderCache::getInstance()->getProgram(&sortedObjects_[i]->shaderDesc, PeelInitModifier::instance);

384 385 386 387 388 389
        if (initProg->getFragDataLocation("outFragment") != 0 || initProg->getFragDataLocation("outDepth") != 1)
        {
          initProg->bindFragDataLocation(0, "outFragment"); // color -> slot0
          initProg->bindFragDataLocation(1, "outDepth");    // depth -> slot1
          initProg->link();
        }
390

Jan Möbius's avatar
Jan Möbius committed
391 392 393 394
        renderObject(sortedObjects_[i], initProg, true);
      }
    }

395 396 397
    // copy depth values to input depth buffer if requested
    if (copyFrontDepth_)
      copyDepthToBackBuffer(viewRes->singleDepthTex_[0], 1.0f);
Jan Möbius's avatar
Jan Möbius committed
398 399 400 401

    // peel layers, we start at index 1 instead of 0
    // since the front layer is already initialized in
    // depth buffer 0 and we want to extract the second one now
402 403

    for (int pass = 1; pass < maxPeelCount_; ++pass)
Jan Möbius's avatar
Jan Möbius committed
404
    {
405 406 407
      const int currID = pass & 1;
      const int prevID = 1 - currID;
      const int bufID = currID * 2;
Jan Möbius's avatar
Jan Möbius committed
408

409 410 411 412
      // peeling MRT slots:
      //  RT0 - color
      //  RT1 - depth buffer copy
      const GLenum targetBuffer[2] = {colorTarget + bufID, depthTarget + bufID};
Jan Möbius's avatar
Jan Möbius committed
413

414
      // ---------------------------------------------------------------
Jan Möbius's avatar
Jan Möbius committed
415 416
      // 1st peel next layer

417 418
      // clear color texture
      glDrawBuffer(targetBuffer[0]);
Jan Möbius's avatar
Jan Möbius committed
419
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
420 421 422 423
      glClear(GL_COLOR_BUFFER_BIT);
      // clear depth texture
      glDrawBuffer(targetBuffer[1]);
      glClearColor(clearDepth, 0.0f, 0.0f, 0.0f);
Jan Möbius's avatar
Jan Möbius committed
424 425
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

426 427 428 429

      glDrawBuffers(2, targetBuffer);


Jan Möbius's avatar
Jan Möbius committed
430 431 432 433 434 435 436 437 438
      glDisable(GL_BLEND);
      glEnable(GL_DEPTH_TEST);

      // count # passed fragments
      glBeginQuery(GL_SAMPLES_PASSED, peelQueryID_);


      // bind previous depth layer to texture unit 4
      glActiveTexture(GL_TEXTURE4);
439
      glBindTexture(GL_TEXTURE_2D, viewRes->singleDepthTex_[prevID]);
Jan Möbius's avatar
Jan Möbius committed
440 441 442 443 444 445 446

      // render scene
      for (int k = 0; k < numRenderObjects; ++k)
      {
        if ((sortedObjects_[k]->internalFlags_ & RENDERFLAG_ALLOW_PEELING) && sortedObjects_[k]->alpha < 0.99f)
        {
          GLSL::Program* peelProg = ShaderCache::getInstance()->getProgram(&sortedObjects_[k]->shaderDesc, PeelLayerModifier::instance);
447

448 449 450 451 452 453
          if (peelProg->getFragDataLocation("outFragment") != 0 || peelProg->getFragDataLocation("outDepth") != 1)
          {
            peelProg->bindFragDataLocation(0, "outFragment");
            peelProg->bindFragDataLocation(1, "outDepth");
            peelProg->link();
          }
454

Jan Möbius's avatar
Jan Möbius committed
455 456 457 458 459 460 461 462 463 464 465
          peelProg->use();
          peelProg->setUniform("g_DepthLayer", 4);

          renderObject(sortedObjects_[k], peelProg, true);
        }
      }

      glEndQuery(GL_SAMPLES_PASSED);



466
      // ---------------------------------------------------------------
Jan Möbius's avatar
Jan Möbius committed
467 468
      // 2nd underblend layer with current scene
      //  (fullscreen pass)
469
      glDrawBuffer(colorBlendTarget);
Jan Möbius's avatar
Jan Möbius committed
470 471 472 473 474 475 476 477

      glDepthMask(1);
      glColorMask(1,1,1,1);

      glDisable(GL_DEPTH_TEST);
      glEnable(GL_BLEND);

      glBlendEquation(GL_FUNC_ADD);
478
      ACG::GLState::blendFuncSeparate(GL_DST_ALPHA, GL_ONE,
479
        GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
Jan Möbius's avatar
Jan Möbius committed
480 481 482 483 484 485


      peelBlend_->use();
      peelBlend_->setUniform("BlendTex", 0);

      glActiveTexture(GL_TEXTURE0);
486
      glBindTexture(GL_TEXTURE_2D, viewRes->singleFrontTex_[currID]);
Jan Möbius's avatar
Jan Möbius committed
487

488
      ACG::ScreenQuad::draw(peelBlend_);
Jan Möbius's avatar
Jan Möbius committed
489 490 491 492 493


      glDisable(GL_BLEND);


494

Jan Möbius's avatar
Jan Möbius committed
495 496 497 498 499 500 501 502
      GLuint passedSamples;
      glGetQueryObjectuiv(peelQueryID_, GL_QUERY_RESULT, &passedSamples);
      if (passedSamples == 0)
        break;
    }


    // copy to back buffer
503
    restoreInputFbo();
Jan Möbius's avatar
Jan Möbius committed
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522

    glDepthMask(1);
    glColorMask(1,1,1,1);

    glDisable(GL_DEPTH_TEST);

    peelFinal_->use();


    ACG::Vec3f bkgColor;
    bkgColor[0] = _properties.backgroundColor()[0];
    bkgColor[1] = _properties.backgroundColor()[1];
    bkgColor[2] = _properties.backgroundColor()[2];

    peelFinal_->setUniform("BkgColor", bkgColor);

    peelFinal_->setUniform("SceneTex", 0);

    glActiveTexture(GL_TEXTURE0);
523
    glBindTexture(GL_TEXTURE_2D, viewRes->singleBlendTex_);
Jan Möbius's avatar
Jan Möbius committed
524

525
    ACG::ScreenQuad::draw(peelFinal_);
Jan Möbius's avatar
Jan Möbius committed
526 527 528 529 530 531 532 533 534 535

    ACG::glCheckErrors();




    // draw rest of scene
    glEnable(GL_DEPTH_TEST);


536 537 538
//     // draw rest of opaque objects
//     for (int i = lastPeeledObject + 1; i < numRenderObjects; ++i)
//       renderObject(sortedObjects_[i]);
Jan Möbius's avatar
Jan Möbius committed
539 540

  }
541
}
Jan Möbius's avatar
Jan Möbius committed
542 543


544 545 546
void DepthPeeling::renderDualPeeling(ACG::GLState* _glState, Viewer::ViewerProperties& _properties)
{
  const int numRenderObjects = getNumRenderObjects();
Jan Möbius's avatar
Jan Möbius committed
547

548 549 550
  // begin rendering
  // find last transparent object
  int lastPeeledObject = -1;
Jan Möbius's avatar
Jan Möbius committed
551

552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
  for (int i = numRenderObjects - 1; i > lastPeeledObject; --i)
  {
    if ((sortedObjects_[i]->internalFlags_ & RENDERFLAG_ALLOW_PEELING) && sortedObjects_[i]->alpha < 0.99f)
      lastPeeledObject = i;
  }

  if (0) //lastPeeledObject == -1)
  {
    // no transparent objects
    for (int i = 0; i < numRenderObjects; ++i)
      renderObject(sortedObjects_[i]);
  }
  else
  {
    // depth peeling code

568 569
    // make sure shaders and occlusion query are initialized
    initDualDepthPeeling();
570

571
    // resize fbo as necessary
572
    ViewerResources* viewRes = &viewerRes_[_properties.viewerId()];
573
    viewRes->resize(true, (unsigned int)_glState->viewport_width(), (unsigned int)_glState->viewport_height());
574 575 576 577 578 579 580 581


    // enable color/depth write access
    glDepthMask(1);
    glColorMask(1,1,1,1);


    // clear render targets
582
//    viewRes->dualFboACG_->bind();
Jan Möbius's avatar
Jan Möbius committed
583
    glViewport(0, 0, _glState->viewport_width(), _glState->viewport_height());
584
    glBindFramebuffer(GL_FRAMEBUFFER, viewRes->dualFbo_->getFboID());
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610

    const GLenum depthTarget = GL_COLOR_ATTACHMENT0; // stores (-minDepth, maxDepth)
    const GLenum colorTargets[] = {GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2};
    const GLenum colorBlendTarget = GL_COLOR_ATTACHMENT6;

    // clear colors  (front and back colors per pass)
    glDrawBuffers(2, colorTargets);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    // clear color blend target
    glDrawBuffer(colorBlendTarget);
    glClearColor(_glState->clear_color()[0], _glState->clear_color()[1], _glState->clear_color()[2], 0);
    glClear(GL_COLOR_BUFFER_BIT);

    // clear depths
    glDrawBuffer(depthTarget);
    glClearColor(-1.0f, -1.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);


    // 1. Pass: initialize depth values
    //  the init shader writes min/max depth values (-z, +z)
    glEnable(GL_BLEND);
    glBlendEquation(GL_MAX_EXT);  // get min/max depth
    
611 612
    if(_glState->compatibilityProfile())
      glDisable(GL_ALPHA_TEST);
613 614 615 616 617 618 619 620 621 622 623 624 625

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glDisable(GL_CULL_FACE);

    for (int i = 0; i < numRenderObjects; ++i)
    {
      GLSL::Program* initProg = ShaderCache::getInstance()->getProgram(&sortedObjects_[i]->shaderDesc, PeelDualInitModifier::instance);

      renderObject(sortedObjects_[i], initProg, true);
    }


626 627 628 629 630 631 632 633 634
    // copy depth values of first front layer to input depth buffer if requested
    if (copyFrontDepth_)
    {
      glDisable(GL_BLEND);
      copyDepthToBackBuffer(viewRes->dualDepthTex_[0], -1.0f);
      // dual peeling requires blending
      glEnable(GL_BLEND);
    }

635 636 637 638 639 640
    // 2. peeling passes + color accumulation

    int currID = 0; // ping-pong render targets

//if (0){

641
    for (int pass = 1; 1 && pass < maxPeelCount_; ++pass)
642 643
    {
      currID = pass & 1;
644 645
      const int prevID = 1 - currID;
      const int bufID = currID * 3;
646 647 648 649 650

      GLenum targetBuffer[3];
      targetBuffer[0] = GL_COLOR_ATTACHMENT0 + bufID;
      targetBuffer[1] = GL_COLOR_ATTACHMENT1 + bufID;
      targetBuffer[2] = GL_COLOR_ATTACHMENT2 + bufID;
651
//      GLenum sourceBuffer[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2};
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697

      // clear target colors
      glDrawBuffers(2, targetBuffer + 1);
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      glClear(GL_COLOR_BUFFER_BIT);

      // clear target depth
      glDrawBuffer(targetBuffer[0]);
      glClearColor(-1.0f, -1.0f, 0.0f, 0.0f);
      glClear(GL_COLOR_BUFFER_BIT);



      // Peel pass

      // set target
      glBlendEquation(GL_MAX_EXT);
      glDrawBuffers(3, targetBuffer); // shader writes to (depth_tex, front_color_tex, back_color_tex)

      // set texture source (provide previous layer)
      // slot 4 - depth
      // slot 5 - front color

      glActiveTexture(GL_TEXTURE5);
      glBindTexture(GL_TEXTURE_2D, viewRes->dualFrontTex_[prevID]);

      glActiveTexture(GL_TEXTURE4);
      glBindTexture(GL_TEXTURE_2D, viewRes->dualDepthTex_[prevID]);

      // restore active tex marker to default slot
      glActiveTexture(GL_TEXTURE0);

      // peel scene
      for (int i = 0; i < numRenderObjects; ++i)
      {
        GLSL::Program* peelProg = ShaderCache::getInstance()->getProgram(&sortedObjects_[i]->shaderDesc, PeelDualLayerModifier::instance);

        peelProg->use();
        peelProg->setUniform("g_DepthLayer", 4);
        peelProg->setUniform("g_FrontLayer", 5);

        // setup MRT
        //  outFragment -> front
        //  outDepth -> depth
        //  outBackColor -> back

698 699 700 701 702 703 704
        int locOutFrag = peelProg->getFragDataLocation("outFragment");
        int locOutDepth = peelProg->getFragDataLocation("outDepth");
        int locOutBackColor = peelProg->getFragDataLocation("outBackColor");

        if (locOutFrag != 1 ||
            locOutDepth != 0 ||
            locOutBackColor != 2)
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
        {
          // linking is slow; only link if necessary
          peelProg->bindFragDataLocation(1, "outFragment");
          peelProg->bindFragDataLocation(0, "outDepth");
          peelProg->bindFragDataLocation(2, "outBackColor");

          peelProg->link();
        }
        


        renderObject(sortedObjects_[i], peelProg, true);
      }




      // ----------------------
      // debugging
/*
      if (pass == 1)
      {
        dbgDrawTex(viewRes->dualFrontTex_[currID]);
        return;
      }
*/
      //




      // blend back color into accumulation buffer
      glDrawBuffer(colorBlendTarget);

739
      glBlendEquation(GL_FUNC_ADD);
740
      ACG::GLState::blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
741 742 743 744 745 746 747 748 749 750 751

      // bind back color texture to slot 0
      glActiveTexture(GL_TEXTURE0);
      glBindTexture(GL_TEXTURE_2D, viewRes->dualBackTex_[currID]);


      glBeginQuery(GL_SAMPLES_PASSED_ARB, peelQueryID_);

      peelBlendDual_->use();
      peelBlendDual_->setUniform("BlendTex", 0);
      
752
      ACG::ScreenQuad::draw(peelBlendDual_);
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767

      glEndQuery(GL_SAMPLES_PASSED_ARB);



      // termination check
      GLuint passedSamples;
      glGetQueryObjectuiv(peelQueryID_, GL_QUERY_RESULT, &passedSamples);
      if (passedSamples == 0)
        break;
    }

//}

    // Final pass: combine accumulated front and back colors
Jan Möbius's avatar
Jan Möbius committed
768
    restoreInputFbo();
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798

    glDepthMask(1);
    glColorMask(1,1,1,1);

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);


    peelFinalDual_->use();


    ACG::Vec3f bkgColor;
    bkgColor[0] = _properties.backgroundColor()[0];
    bkgColor[1] = _properties.backgroundColor()[1];
    bkgColor[2] = _properties.backgroundColor()[2];

    peelFinalDual_->setUniform("BkgColor", bkgColor);

    // slot 0 - front colors
    // slot 1 - back colors

    peelFinalDual_->setUniform("FrontSceneTex", 0);
    peelFinalDual_->setUniform("BackSceneTex", 1);

    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, viewRes->dualBlendTex_);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, viewRes->dualFrontTex_[currID]);

799 800 801
//    drawProjQuad(peelFinalDual_);
    ACG::ScreenQuad::draw(peelFinalDual_);

802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835

    peelFinalDual_->disable();





    // ------------------------------------------
    // debugging

//    dbgDrawTex(viewRes->dualDepthTex_[0]);


    // ------------------------------------------








    ACG::glCheckErrors();


//     // draw rest of scene
//     glEnable(GL_DEPTH_TEST);
// 
// 
//     // draw rest of opaque objects
//     for (int i = lastPeeledObject + 1; i < numRenderObjects; ++i)
//       renderObject(sortedObjects_[i]);

  }
Jan Möbius's avatar
Jan Möbius committed
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
}

void DepthPeeling::addRenderObject( RenderObject* _renderObject )
{
  // do some more checks for error detection
  if (!_renderObject->vertexDecl)
    std::cout << "error: missing vertex declaration" << std::endl;
  else
  {
    renderObjects_.push_back(*_renderObject);


    RenderObject* p = &renderObjects_.back();

    if (!p->shaderDesc.numLights)
      p->shaderDesc.numLights = numLights_;

    else if (p->shaderDesc.numLights < 0 || p->shaderDesc.numLights >= SG_MAX_SHADER_LIGHTS)
      p->shaderDesc.numLights = 0;

    p->internalFlags_ = 0;

    // allow potential depth peeling only for compatible
    //  render states

    if (p->alpha < 1.0f &&
      p->depthTest && 
      p->depthWrite && (p->depthFunc == GL_LESS ||
      p->depthFunc == GL_LEQUAL))
      p->internalFlags_ = RENDERFLAG_ALLOW_PEELING;


    // precompile shader
    ShaderCache::getInstance()->getProgram(&p->shaderDesc);

  }
}




DepthPeeling::ViewerResources::ViewerResources()
878
: width_(0), height_(0), singleBlendTex_(0), singleFbo_(0), dualBlendTex_(0), dualFbo_(0)
Jan Möbius's avatar
Jan Möbius committed
879
{
880 881
  memset(singleDepthTex_, 0, sizeof(singleDepthTex_));
  memset(singleFrontTex_, 0, sizeof(singleFrontTex_));
882 883 884 885
 
  memset(dualDepthTex_, 0, sizeof(dualDepthTex_));
  memset(dualFrontTex_, 0, sizeof(dualFrontTex_));
  memset(dualBackTex_, 0, sizeof(dualBackTex_));
Jan Möbius's avatar
Jan Möbius committed
886 887 888
}


889 890 891 892 893 894 895
DepthPeeling::ViewerResources::~ViewerResources()
{
  delete singleFbo_;
  delete dualFbo_;
}


896 897
void DepthPeeling::ViewerResources::resize(bool _dualPeeling, unsigned int _width, unsigned int _height)
{
898
  if (!_width ||  !_height)
Jan Möbius's avatar
Jan Möbius committed
899 900
    return;

901 902
  width_ = _width;
  height_ = _height;
903 904

  if (!_dualPeeling)
Jan Möbius's avatar
Jan Möbius committed
905
  {
906
    if (!singleFbo_)
907
    {
908
      singleFbo_ = new ACG::FBO();
Jan Möbius's avatar
Jan Möbius committed
909

910
      singleFbo_->init();
Jan Möbius's avatar
Jan Möbius committed
911

912 913 914 915
      // texture formats:
      //  depth textures: store layer depth as float
      //  front color textures: store (r,g,b,a) colors as R8G8B8A8
      //  color blending and accumulation texture: (r,g,b,a) color as R8G8B8A8
916 917 918 919 920
      GLint wrapmode;
      if(ACG::openGLVersion(3,2))
          wrapmode = GL_CLAMP_TO_EDGE;
      else
          wrapmode = GL_CLAMP;
Jan Möbius's avatar
Jan Möbius committed
921

922 923
      singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT0, width_, height_, GL_R32F, GL_RGB, wrapmode, GL_NEAREST, GL_NEAREST);
      singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT1, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST);
Jan Möbius's avatar
Jan Möbius committed
924

925 926
      singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT2, width_, height_, GL_R32F, GL_RGB, wrapmode, GL_NEAREST, GL_NEAREST);
      singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT3, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST);
Jan Möbius's avatar
Jan Möbius committed
927

928
      singleFbo_->attachTexture2D(GL_COLOR_ATTACHMENT4, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST);
Jan Möbius's avatar
Jan Möbius committed
929

930
      singleFbo_->attachTexture2DDepth(width_, height_);
Jan Möbius's avatar
Jan Möbius committed
931

932 933
      singleDepthTex_[0] = singleFbo_->getAttachment(GL_COLOR_ATTACHMENT0);
      singleDepthTex_[1] = singleFbo_->getAttachment(GL_COLOR_ATTACHMENT2);
Jan Möbius's avatar
Jan Möbius committed
934

935 936
      singleFrontTex_[0] = singleFbo_->getAttachment(GL_COLOR_ATTACHMENT1);
      singleFrontTex_[1] = singleFbo_->getAttachment(GL_COLOR_ATTACHMENT3);
Jan Möbius's avatar
Jan Möbius committed
937

938
      singleBlendTex_ = singleFbo_->getAttachment(GL_COLOR_ATTACHMENT4);
939 940


941
      singleFbo_->checkFramebufferStatus();
942 943 944

      ACG::glCheckErrors();
    }
945 946
    else
      singleFbo_->resize(_width, _height);
947

Jan Möbius's avatar
Jan Möbius committed
948
  }
949 950 951
  else
  {
    // dual peeling render targets
Jan Möbius's avatar
Jan Möbius committed
952

953
    // fbo
954
    if (!dualFbo_)
955
    {
956
      dualFbo_ = new ACG::FBO();
957

958
      dualFbo_->init();
959

960 961 962 963
      // texture formats:
      //  depth textures: store (min,max) depth as float2
      //  front+back color textures: store (r,g,b,a) colors as R8G8B8A8
      //  color blending and accumulation texture: (r,g,b) color as R8G8B8X8
964 965 966 967 968 969 970 971 972 973
      GLint wrapmode;
      if(ACG::openGLVersion(3,2))
      {
          wrapmode = GL_CLAMP_TO_EDGE;
      }
      else
          wrapmode = GL_CLAMP;
      dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT0, width_, height_, GL_RG32F, GL_RGB, wrapmode, GL_NEAREST, GL_NEAREST);
      dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT1, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST);
      dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT2, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST);
974

975 976 977
      dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT3, width_, height_, GL_RG32F, GL_RGB, wrapmode, GL_NEAREST, GL_NEAREST);
      dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT4, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST);
      dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT5, width_, height_, GL_RGBA, GL_RGBA, wrapmode, GL_NEAREST, GL_NEAREST);
Jan Möbius's avatar
Jan Möbius committed
978

979
      dualFbo_->attachTexture2D(GL_COLOR_ATTACHMENT6, width_, height_, GL_RGB, GL_RGB, wrapmode, GL_NEAREST, GL_NEAREST);
980

981 982
      dualDepthTex_[0] = dualFbo_->getAttachment(GL_COLOR_ATTACHMENT0);
      dualDepthTex_[1] = dualFbo_->getAttachment(GL_COLOR_ATTACHMENT3);
983

984 985
      dualFrontTex_[0] = dualFbo_->getAttachment(GL_COLOR_ATTACHMENT1);
      dualFrontTex_[1] = dualFbo_->getAttachment(GL_COLOR_ATTACHMENT4);
Jan Möbius's avatar
Jan Möbius committed
986

987 988
      dualBackTex_[0] = dualFbo_->getAttachment(GL_COLOR_ATTACHMENT2);
      dualBackTex_[1] = dualFbo_->getAttachment(GL_COLOR_ATTACHMENT5);
Jan Möbius's avatar
Jan Möbius committed
989

990
      dualBlendTex_ = dualFbo_->getAttachment(GL_COLOR_ATTACHMENT6);
Jan Möbius's avatar
Jan Möbius committed
991 992


993
      dualFbo_->checkFramebufferStatus();
Jan Möbius's avatar
Jan Möbius committed
994

995
      ACG::glCheckErrors();
996
    }
997
    else
998
      dualFbo_->resize(_width, _height);
Jan Möbius's avatar
Jan Möbius committed
999

1000
  }
1001
  
Jan Möbius's avatar
Jan Möbius committed
1002 1003 1004 1005 1006 1007 1008 1009

  glBindFramebuffer(GL_FRAMEBUFFER, 0);

  ACG::glCheckErrors();
}

void DepthPeeling::initDepthPeeling()
{
1010
  // check if already initialized
1011
  if (peelBlend_ && peelFinal_ && peelQueryID_)
1012 1013
    return;

Jan Möbius's avatar
Jan Möbius committed
1014 1015 1016 1017
  // register shader modifiers
  ShaderProgGenerator::registerModifier(&PeelInitModifier::instance);
  ShaderProgGenerator::registerModifier(&PeelLayerModifier::instance);

1018
  // load intermediate blending and final shader
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
#ifdef __APPLE__
  if(ACG::openGLVersion(3,3))
  {
      if (!peelBlend_)
        peelBlend_ = GLSL::loadProgram("DepthPeeling/screenquad_330.glsl", "DepthPeeling/blend_330.glsl");

      if (!peelFinal_)
        peelFinal_ = GLSL::loadProgram("DepthPeeling/screenquad_330.glsl", "DepthPeeling/final_330.glsl");
  }
  else
#endif
  {
Jan Möbius's avatar
Jan Möbius committed
1031
  if (!peelBlend_)
1032
    peelBlend_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/blend.glsl");
Jan Möbius's avatar
Jan Möbius committed
1033 1034

  if (!peelFinal_)
1035
    peelFinal_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/final.glsl");
1036
  }
Jan Möbius's avatar
Jan Möbius committed
1037 1038 1039 1040 1041 1042 1043 1044

  // occ query id
  if (!peelQueryID_)
    glGenQueries(1, &peelQueryID_);

  ACG::glCheckErrors();
}

1045 1046
void DepthPeeling::initDualDepthPeeling()
{
1047
  // check if already initialized
1048
  if (peelBlendDual_ && peelFinalDual_ && peelQueryID_)
1049 1050
    return;

1051 1052 1053 1054
  // register shader modifiers
  ShaderProgGenerator::registerModifier(&PeelDualInitModifier::instance);
  ShaderProgGenerator::registerModifier(&PeelDualLayerModifier::instance);

1055
  // load intermediate blending and final shader
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
#ifdef __APPLE__ //this is fugly, pimpl pattern would be much appreciated
      if(ACG::openGLVersion(3,3))
      {
          if(!peelBlendDual_)
            peelBlendDual_ = GLSL::loadProgram("DepthPeeling/screenquad_330.glsl", "DepthPeeling/blend_dual_330.glsl");
          if (!peelFinalDual_)
            peelFinalDual_ = GLSL::loadProgram("DepthPeeling/screenquad_330.glsl", "DepthPeeling/final_dual_330.glsl");
      }
      else
#endif
      {
        if(!peelBlendDual_)
            peelBlendDual_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/blend_dual.glsl");
        if (!peelFinalDual_)
          peelFinalDual_ = GLSL::loadProgram("DepthPeeling/screenquad.glsl", "DepthPeeling/final_dual.glsl");
      }
1072 1073 1074 1075 1076 1077 1078 1079

  // occ query id
  if (!peelQueryID_)
    glGenQueries(1, &peelQueryID_);

  ACG::glCheckErrors();
}

1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
QString DepthPeeling::renderObjectsInfo( bool _outputShaderInfo )
{
  QString infoString;

  ACG::ShaderModifier* availableMods[4] = 
  {
    &PeelInitModifier::instance, &PeelLayerModifier::instance,
    &PeelDualInitModifier::instance, &PeelDualLayerModifier::instance
  };


  // write modified shaders for init and peel passes

  infoString += "PeelInit:\n\n\n";

  std::vector<ACG::ShaderModifier*> mods;
  mods.push_back(availableMods[peelMode_*2]);

  infoString += dumpCurrentRenderObjectsToString(&sortedObjects_[0],_outputShaderInfo, &mods);


  infoString += "\n\n-----------------------------------------------\n\n\n\n";
  infoString += "PeelLayer:\n\n\n";

  mods[0] = availableMods[peelMode_*2 + 1];

  infoString += dumpCurrentRenderObjectsToString(&sortedObjects_[0],_outputShaderInfo, &mods);
    
  return infoString;
}

1111

1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
// 
// void DepthPeeling::dbgDrawTex( GLuint _texID )
// {
//   glBindFramebuffer(GL_FRAMEBUFFER, 0);
//   glDrawBuffer(GL_BACK);
//   glClearColor(0,0,0,0);
//   glClear(GL_COLOR_BUFFER_BIT);
// 
// 
//   glDepthMask(1);
//   glColorMask(1,1,1,1);
// 
//   glDisable(GL_DEPTH_TEST);
//   glDisable(GL_BLEND);
// 
//   dbgProg_->use();
// 
//   dbgProg_->setUniform("Tex", 0);
// 
//   glActiveTexture(GL_TEXTURE0);
//   glBindTexture(GL_TEXTURE_2D, _texID);
// 
//   drawProjQuad(dbgProg_);
// 
//   dbgProg_->disable();
// }
// 


Jan Möbius's avatar
Jan Möbius committed
1141 1142