IRenderer.cc 18.6 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
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-2011 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                       *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/

43 44
#include <cstdio>
#include <cstring>
Jan Möbius's avatar
Jan Möbius committed
45
#include <iostream>
46
#include <cstdlib>
Jan Möbius's avatar
Jan Möbius committed
47
#include <QFile>
48
#include <QTextStream>
Jan Möbius's avatar
Jan Möbius committed
49 50 51 52 53 54 55

#include <ACG/GL/gl.hh>

#include <ACG/GL/IRenderer.hh>

#include <ACG/GL/VertexDeclaration.hh>
#include <ACG/GL/GLState.hh>
56
#include <ACG/Scenegraph/DrawModes.hh>
57
#include <ACG/Scenegraph/MaterialNode.hh>
58

Jan Möbius's avatar
Jan Möbius committed
59 60 61 62 63
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/GL/ShaderCache.hh>



64 65 66
namespace ACG
{

Jan Möbius's avatar
Jan Möbius committed
67 68
IRenderer::IRenderer()
: numLights_(0), renderObjects_(0)
Jan Möbius's avatar
Jan Möbius committed
69
{
Jan Möbius's avatar
Jan Möbius committed
70
}
Jan Möbius's avatar
Jan Möbius committed
71

72

Jan Möbius's avatar
Jan Möbius committed
73 74 75
IRenderer::~IRenderer()
{
}
76

Jan Möbius's avatar
Jan Möbius committed
77 78 79 80 81 82 83 84
void IRenderer::addRenderObject(ACG::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);
Jan Möbius's avatar
Jan Möbius committed
85 86


Jan Möbius's avatar
Jan Möbius committed
87
    ACG::RenderObject* p = &renderObjects_.back();
88

Jan Möbius's avatar
Jan Möbius committed
89 90
    if (!p->shaderDesc.numLights)
      p->shaderDesc.numLights = numLights_;
Jan Möbius's avatar
Jan Möbius committed
91

Jan Möbius's avatar
Jan Möbius committed
92 93
    else if (p->shaderDesc.numLights < 0 || p->shaderDesc.numLights >= SG_MAX_SHADER_LIGHTS)
      p->shaderDesc.numLights = 0;
Jan Möbius's avatar
Jan Möbius committed
94

Jan Möbius's avatar
Jan Möbius committed
95
    p->internalFlags_ = 0;
Jan Möbius's avatar
Jan Möbius committed
96 97


Jan Möbius's avatar
Jan Möbius committed
98 99
    // precompile shader
    ACG::ShaderCache::getInstance()->getProgram(&p->shaderDesc);
Jan Möbius's avatar
Jan Möbius committed
100

Jan Möbius's avatar
Jan Möbius committed
101 102
  }
}
Jan Möbius's avatar
Jan Möbius committed
103 104 105



Jan Möbius's avatar
Jan Möbius committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

void IRenderer::collectRenderObjects( ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _sceneGraphRoot )
{
  // collect light sources
//  collectLightNodes(_sceneGraphRoot);
  numLights_ = 0; // reset light counter

  // flush render objects
  // clear() may actually free memory, resulting in capacity = 0
  renderObjects_.resize(0);


  // default material needed
  ACG::SceneGraph::Material defMat;
  defMat.baseColor(ACG::Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
  defMat.ambientColor(ACG::Vec4f(0.2f, 0.2f, 0.2f, 1.0f));
  defMat.diffuseColor(ACG::Vec4f(0.6f, 0.6f, 0.6f, 1.0f));
  defMat.specularColor(ACG::Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
  defMat.shininess(1.0f);
  //  defMat.alphaValue(1.0f);

  // collect renderables
  traverseRenderableNodes(_glState, _drawMode, _sceneGraphRoot, &defMat);
Jan Möbius's avatar
Jan Möbius committed
129
}
Jan Möbius's avatar
Jan Möbius committed
130

Jan Möbius's avatar
Jan Möbius committed
131 132 133 134 135




void IRenderer::traverseRenderableNodes( ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _node, const ACG::SceneGraph::Material* _mat )
136
{
Jan Möbius's avatar
Jan Möbius committed
137
  if (_node)
138
  {
Jan Möbius's avatar
Jan Möbius committed
139 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
    ACG::SceneGraph::BaseNode::StatusMode status(_node->status());
    bool process_children(status != ACG::SceneGraph::BaseNode::HideChildren);

    ACG::SceneGraph::DrawModes::DrawMode nodeDM = _node->drawMode();

    if (nodeDM == ACG::SceneGraph::DrawModes::DEFAULT)
      nodeDM = _drawMode;


    // If the subtree is hidden, ignore this node and its children while rendering
    if (status != ACG::SceneGraph::BaseNode::HideSubtree)
    {

      if ( _node->status() != ACG::SceneGraph::BaseNode::HideNode )
        _node->enter(*_glState, _drawMode);


      // fetch material (Node itself can be a material node, so we have to
      // set that in front of the nodes own rendering
      ACG::SceneGraph::MaterialNode* matNode = dynamic_cast<ACG::SceneGraph::MaterialNode*>(_node);
      if (matNode)
        _mat = &matNode->material();

      if (_node->status() != ACG::SceneGraph::BaseNode::HideNode)
        _node->getRenderObjects(this, *_glState, nodeDM, _mat);

      if (process_children)
      {

        ACG::SceneGraph::BaseNode::ChildIter cIt, cEnd(_node->childrenEnd());

        // Process all children which are not second pass
        for (cIt = _node->childrenBegin(); cIt != cEnd; ++cIt)
          if (~(*cIt)->traverseMode() & ACG::SceneGraph::BaseNode::SecondPass)
            traverseRenderableNodes( _glState, _drawMode, *cIt, _mat);
174

Jan Möbius's avatar
Jan Möbius committed
175 176 177 178
        // Process all children which are second pass
        for (cIt = _node->childrenBegin(); cIt != cEnd; ++cIt)
          if ((*cIt)->traverseMode() & ACG::SceneGraph::BaseNode::SecondPass)
            traverseRenderableNodes( _glState, _drawMode, *cIt, _mat);
179

Jan Möbius's avatar
Jan Möbius committed
180 181 182 183 184 185
      }


      if (_node->status() != ACG::SceneGraph::BaseNode::HideNode )
        _node->leave(*_glState, nodeDM);
    }
186 187 188
  }
}

Jan Möbius's avatar
Jan Möbius committed
189 190

int IRenderer::cmpPriority(const void* _a, const void* _b)
191
{
Jan Möbius's avatar
Jan Möbius committed
192 193 194 195
  const ACG::RenderObject* a = *(const ACG::RenderObject**)_a;
  const ACG::RenderObject* b = *(const ACG::RenderObject**)_b;

  return a->priority - b->priority;
196 197 198
}


199 200


Jan Möbius's avatar
Jan Möbius committed
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
void IRenderer::prepareRenderingPipeline(ACG::GLState* _glState, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ACG::SceneGraph::BaseNode* _scenegraphRoot)
{
  // First, all render objects get collected.
  collectRenderObjects(_glState, _drawMode, _scenegraphRoot);

  // Check if there is anything to render
  if (renderObjects_.empty())
    return;


  // ==========================================================
  // Sort renderable objects based on their priority
  // ==========================================================

  const size_t numRenderObjects = getNumRenderObjects();

  // sort for priority
  if (sortedObjects_.size() < numRenderObjects)
    sortedObjects_.resize(numRenderObjects);

  // init sorted objects array
  for (size_t i = 0; i < numRenderObjects; ++i)
    sortedObjects_[i] = &renderObjects_[i];

  sortRenderObjects();

227

Jan Möbius's avatar
Jan Möbius committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
  // ---------------------------
  // Initialize the render state
  // ---------------------------
  // gl cleanup

  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_COLOR_ARRAY);
  glDisableClientState(GL_NORMAL_ARRAY);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  glDisableClientState(GL_INDEX_ARRAY);


  // size of a rendered point is set in vertex-shader via gl_PointSize
  #ifndef __APPLE__
    glEnable(GL_PROGRAM_POINT_SIZE_ARB);
  #endif

  glEnable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LESS);
  glDepthMask(GL_TRUE);
}



void IRenderer::finishRenderingPipeline()
Jan Möbius's avatar
Jan Möbius committed
254
{
Jan Möbius's avatar
Jan Möbius committed
255 256
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
  glDrawBuffer(GL_BACK);
257

Jan Möbius's avatar
Jan Möbius committed
258 259
  glDepthMask(1);
  glColorMask(1,1,1,1);
260

Jan Möbius's avatar
Jan Möbius committed
261
  glUseProgram(0);
262

Jan Möbius's avatar
Jan Möbius committed
263 264
  glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
  glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
265 266
}

Jan Möbius's avatar
Jan Möbius committed
267 268 269 270 271 272 273 274 275 276

void IRenderer::sortRenderObjects()
{
  qsort(&sortedObjects_[0], getNumRenderObjects(), sizeof(ACG::RenderObject*), cmpPriority);
}



void IRenderer::bindObjectVBO(ACG::RenderObject* _obj,
                                       GLSL::Program*     _prog)
277
{
Jan Möbius's avatar
Jan Möbius committed
278 279 280 281 282 283 284 285 286 287 288 289
  _prog->use();

  //////////////////////////////////////////////////////////////////////////
  // NOTE:
  //  always bind buffers before glVertexAttribPointer calls!!
  //  freeze in glDrawElements guaranteed (with no error message whatsoever)
  glBindBufferARB(GL_ARRAY_BUFFER_ARB, _obj->vertexBuffer);
  glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, _obj->indexBuffer);


  // activate vertex declaration
  _obj->vertexDecl->activateShaderPipeline(_prog);
290
}
291

Jan Möbius's avatar
Jan Möbius committed
292 293

void IRenderer::bindObjectUniforms( ACG::RenderObject* _obj, GLSL::Program* _prog )
294
{
Jan Möbius's avatar
Jan Möbius committed
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
  // transforms
  ACG::GLMatrixf mvp = _obj->proj * _obj->modelview;
  ACG::GLMatrixf mvIT = _obj->modelview;
  mvIT.invert();
  mvIT.transpose();

  _prog->setUniform("g_mWVP", mvp);
  _prog->setUniform("g_mWV", _obj->modelview);
  _prog->setUniformMat3("g_mWVIT", mvIT);
  _prog->setUniform("g_mP", _obj->proj);


  // material
  _prog->setUniform("g_cDiffuse", _obj->diffuse);
  _prog->setUniform("g_cAmbient", _obj->ambient);
  _prog->setUniform("g_cEmissive", _obj->emissive);
  _prog->setUniform("g_cSpecular", _obj->specular);

  ACG::Vec4f materialParams(_obj->shininess, _obj->alpha, 0.0f, 0.0f);
  _prog->setUniform("g_vMaterial", materialParams);


317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
  // Additional Uniforms defined in the render Object
  for ( QMap<QString, QPair<unsigned int, QVariant> >::iterator additionalUniformsIter = _obj->additionalUniforms_.begin();
      additionalUniformsIter != _obj->additionalUniforms_.end(); ++additionalUniformsIter ) {

    switch (additionalUniformsIter.value().first) {
      case GL_FLOAT:
        _prog->setUniform(additionalUniformsIter.key().toAscii(),additionalUniformsIter.value().second.toFloat());
        break;
      case GL_INT:
        _prog->setUniform(additionalUniformsIter.key().toAscii(),additionalUniformsIter.value().second.toInt());
        break;
      default:
        std::cerr << "IRenderer Error: Additional Uniform data type not supported" << std::endl;
        break;
    }

  }

Jan Möbius's avatar
Jan Möbius committed
335 336

  // texture
337 338 339 340 341 342 343 344 345 346 347 348 349
  for (std::map<unsigned,RenderObject::Texture>::const_iterator iter = _obj->textures().begin();
      iter != _obj->textures().end();++iter)
  {
    //check for valid texture id
    const unsigned texture_stage = iter->first;
    const RenderObject::Texture tex = iter->second;
    if (!tex.id)
      continue;

    glActiveTexture(GL_TEXTURE0 +texture_stage);
    glBindTexture(iter->second.type, tex.id);
    _prog->setUniform(QString("g_Texture%1").arg(texture_stage).toStdString().c_str(), (int)texture_stage);
  }
350

Jan Möbius's avatar
Jan Möbius committed
351 352 353 354 355
  _prog->setUniform("g_PointSize", 5.0f);


  // lights
  for (int i = 0; i < numLights_; ++i)
356
  {
Jan Möbius's avatar
Jan Möbius committed
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
    LightData* lgt = lights_ + i;

    char szUniformName[256];

    sprintf(szUniformName, "g_cLightDiffuse_%d", i);
    _prog->setUniform(szUniformName, lgt->diffuse);

    sprintf(szUniformName, "g_cLightAmbient_%d", i);
    _prog->setUniform(szUniformName, lgt->ambient);

    sprintf(szUniformName, "g_cLightSpecular_%d", i);
    _prog->setUniform(szUniformName, lgt->specular);


    if (lgt->ltype == ACG::SG_LIGHT_POINT || lgt->ltype == ACG::SG_LIGHT_SPOT)
    {
      sprintf(szUniformName, "g_vLightPos_%d", i);
      _prog->setUniform(szUniformName, lgt->pos);

      sprintf(szUniformName, "g_vLightAtten_%d", i);
      _prog->setUniform(szUniformName, lgt->atten);
    }

    if (lgt->ltype == ACG::SG_LIGHT_DIRECTIONAL || lgt->ltype == ACG::SG_LIGHT_SPOT)
    {
      sprintf(szUniformName, "g_vLightDir_%d", i);
      _prog->setUniform(szUniformName, lgt->dir);
    }

    if (lgt->ltype == ACG::SG_LIGHT_SPOT)
    {
      sprintf(szUniformName, "g_vLightAngleExp_%d", i);
      _prog->setUniform(szUniformName, lgt->spotCutoffExponent);
    }
  }
}

void IRenderer::bindObjectRenderStates(ACG::RenderObject* _obj)
{
  if (_obj->culling)
    glEnable(GL_CULL_FACE);
  else
    glDisable(GL_CULL_FACE);

  if (_obj->blending)
    glEnable(GL_BLEND);
  else
    glDisable(GL_BLEND);

  if (_obj->alphaTest)
    glEnable(GL_ALPHA_TEST);
  else
    glDisable(GL_ALPHA_TEST);

  if (_obj->depthTest)
    glEnable(GL_DEPTH_TEST);
  else
    glDisable(GL_DEPTH_TEST);


  glDepthMask(_obj->depthWrite ? GL_TRUE : GL_FALSE);

  glColorMask(_obj->colorWriteMask[0], _obj->colorWriteMask[1], _obj->colorWriteMask[2], _obj->colorWriteMask[3]);

  glDepthFunc(_obj->depthFunc);

  //  ACG::GLState::shadeModel(_obj->shadeModel);

  glBlendFunc(_obj->blendSrc, _obj->blendDest);
}

void IRenderer::drawObject(ACG::RenderObject* _obj)
{
  if (_obj->numIndices)
431
  {
Jan Möbius's avatar
Jan Möbius committed
432 433 434 435 436 437
    // indexed drawing?
    bool noIndices = true;
    if (_obj->indexBuffer || _obj->sysmemIndexBuffer)
      noIndices = false;

    glPolygonMode(GL_FRONT_AND_BACK, _obj->fillMode);
438

439
    if (noIndices) {
Jan Möbius's avatar
Jan Möbius committed
440
      glDrawArrays(_obj->primitiveMode, _obj->indexOffset, _obj->numIndices);
441
    }
Jan Möbius's avatar
Jan Möbius committed
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
    else
    {
      // ------------------------------------------
      // index offset stuff not tested
      int indexSize = 0;
      switch (_obj->indexType)
      {
      case GL_UNSIGNED_INT: indexSize = 4; break;
      case GL_UNSIGNED_SHORT: indexSize = 2; break;
      default: indexSize = 1; break;
      }

      glDrawElements(_obj->primitiveMode, _obj->numIndices, _obj->indexType,
        ((const char*)_obj->sysmemIndexBuffer) + _obj->indexOffset * indexSize);
    }
  }
  else
459
  {
Jan Möbius's avatar
Jan Möbius committed
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
    // user defined draw-call
    _obj->executeImmediateMode();
  }
}

void IRenderer::renderObject(ACG::RenderObject* _obj, 
                                      GLSL::Program* _prog,
                                      bool _constRenderStates)
{
  // select shader from cache
  GLSL::Program* prog = _prog ? _prog : ACG::ShaderCache::getInstance()->getProgram(&_obj->shaderDesc);


  bindObjectVBO(_obj, prog);

  // ---------------------------------------
  // set shader uniforms
477

Jan Möbius's avatar
Jan Möbius committed
478
  bindObjectUniforms(_obj, prog);
479

Jan Möbius's avatar
Jan Möbius committed
480
  // render states
481

Jan Möbius's avatar
Jan Möbius committed
482 483
  if (!_constRenderStates)
    bindObjectRenderStates(_obj);
484

Jan Möbius's avatar
Jan Möbius committed
485 486
  // ----------------------------
  // OpenGL draw call
487

Jan Möbius's avatar
Jan Möbius committed
488
  drawObject(_obj);
489

490

Jan Möbius's avatar
Jan Möbius committed
491
  ACG::glCheckErrors();
492

Jan Möbius's avatar
Jan Möbius committed
493 494
  // deactivate vertex declaration to avoid errors
  _obj->vertexDecl->deactivateShaderPipeline(prog);
495

Jan Möbius's avatar
Jan Möbius committed
496
}
497 498


Jan Möbius's avatar
Jan Möbius committed
499 500 501 502 503
void IRenderer::addLight(const LightData& _light)
{
  if (numLights_ < SG_MAX_SHADER_LIGHTS)
    lights_[numLights_++] = _light;
}
504 505


Jan Möbius's avatar
Jan Möbius committed
506 507 508 509
int IRenderer::getNumRenderObjects() const
{
  return renderObjects_.size();
}
510

511

512
void IRenderer::dumpRenderObjectsToFile(const char* _fileName, ACG::RenderObject** _sortedList) const
Jan Möbius's avatar
Jan Möbius committed
513 514 515 516 517 518 519 520 521 522 523 524
{
  QFile fileOut(_fileName);
  if (fileOut.open(QFile::WriteOnly | QFile::Truncate))
  {
    QTextStream outStrm(&fileOut);
    for (int i = 0; i < getNumRenderObjects(); ++i)
    {
      if (_sortedList)
        outStrm << "\n" << _sortedList[i]->toString();
      else
        outStrm << "\n" << renderObjects_[i].toString();
    }
525

Jan Möbius's avatar
Jan Möbius committed
526 527 528
    fileOut.close();
  }
}
529 530


531
QString IRenderer::dumpCurrentRenderObjectsToString(ACG::RenderObject** _list, bool _outputShaders ) {
532

533
  QString objectString;
534

535 536 537
  QTextStream outStrm(&objectString);
  for (int i = 0; i < getNumRenderObjects(); ++i)
  {
538
    if (_list) {
539
      outStrm << "\n" << _list[i]->toString();
540 541 542 543 544

      if ( _outputShaders ) {

        outStrm << "\n";

545
        // TODO: Remove!!!
Jan Möbius's avatar
Jan Möbius committed
546
//        _list[i]->shaderDesc.geometryShader = true;
547

548 549 550 551 552 553 554 555 556
        outStrm << _list[i]->shaderDesc.toString();

        ShaderProgGenerator progGen(&(_list[i]->shaderDesc));

        outStrm << "\n---------------------vertex-shader--------------------\n\n";
        for (int i = 0; i < progGen.getVertexShaderCode().size(); ++i)
          outStrm << progGen.getVertexShaderCode()[i] << "\n";
        outStrm << "\n---------------------end-vertex-shader--------------------\n\n";

557
        outStrm << "\n---------------------geometry-shader--------------------\n\n";
558 559
        if ( progGen.hasGeometryShader() )
          for (int i = 0; i < progGen.getGeometryShaderCode().size(); ++i)
560
            outStrm << progGen.getGeometryShaderCode()[i] << "\n";
561 562
        else
          outStrm << "No geometry shader\n";
563 564 565
        outStrm << "\n---------------------end-geometry-shader--------------------\n\n";


566 567 568 569 570 571 572
        outStrm << "\n---------------------fragment-shader--------------------\n\n";
        for (int i = 0; i < progGen.getFragmentShaderCode().size(); ++i)
          outStrm << progGen.getFragmentShaderCode()[i] << "\n";
        outStrm << "\n---------------------end-fragment-shader--------------------\n\n";
      }

    } else {
573
      outStrm << "\n" << renderObjects_[i].toString();
574 575 576 577 578 579


      if ( _outputShaders ) {

        outStrm << "\n";

580
        // TODO: Remove!!!
Jan Möbius's avatar
Jan Möbius committed
581
        //_list[i]->shaderDesc.geometryShader = true;
582

583
        outStrm << renderObjects_[i].shaderDesc.toString();
584

585
        ShaderProgGenerator progGen(&(renderObjects_[i].shaderDesc));
586 587 588 589 590 591

        outStrm << "\n---------------------vertex-shader--------------------\n\n";
        for (int i = 0; i < progGen.getVertexShaderCode().size(); ++i)
          outStrm << progGen.getVertexShaderCode()[i] << "\n";
        outStrm << "\n---------------------end-vertex-shader--------------------\n\n";

592
        outStrm << "\n---------------------geometry-shader--------------------\n\n";
593 594 595 596 597
        if ( progGen.hasGeometryShader() )
          for (int i = 0; i < progGen.getGeometryShaderCode().size(); ++i)
            outStrm << progGen.getGeometryShaderCode()[i] << "\n";
        else
          outStrm << "No geometry shader\n";
598 599
        outStrm << "\n---------------------end-geometry-shader--------------------\n\n";

600 601 602 603 604 605 606 607
        outStrm << "\n---------------------fragment-shader--------------------\n\n";
        for (int i = 0; i < progGen.getFragmentShaderCode().size(); ++i)
          outStrm << progGen.getFragmentShaderCode()[i] << "\n";
        outStrm << "\n---------------------end-fragment-shader--------------------\n\n";

      }
    }

608
  }
609

610 611
  return objectString;
}
612

613

Jan Möbius's avatar
Jan Möbius committed
614 615
} // namespace ACG end