Example #1
0
  void Graphics::Render()
  {
    mat_stack_->Push(camera_->GetViewMatrix());
    scene_constants_.fogNear = std::max(scene_constants_.fogNear, 0.5f);
    scene_constants_.fogFar = std::max(scene_constants_.fogFar, scene_constants_.fogNear + 1.0f);

    Matrix4 modelToWorld;
    BeginScene();
    
    graphicsAPI->SetBlendType(BlendType::Off);
    graphicsAPI->SetDepthType(DepthType::Normal);

    //7 passes because reflection is great



    graphicsAPI->ClearRenderTargets();
    graphicsAPI->FlushDepth();
    graphicsAPI->ClearShaderResources();
    graphicsAPI->AddRenderTarget(back_buffer_);
    graphicsAPI->SetRenderTargets();



    LightingShaderParam paramList;
    int count = 0;
    Shader* debugShader = nullptr;
    for(auto& shaderIt : shaders_)
    {
      Shader* shader = shaderIt.val;
        
      if(shaderIt.key != "lines" && 
          shaderIt.key != "particle")
      {
        Model* model = nullptr;
        for(auto& modelIt : shader->GetInstances())
        {
          model = modelIt.first;
          model->Render();

          for(auto& inst : modelIt.second)
          {

            paramList.modelComp = inst;
            paramList.shader = shader;

            shader->PrepareBuffers((void*) &paramList);

            shader->Render(model->GetNumVerts());
          }
        }
      }
      else
      {
        debugShader = shader;
      }

    }
    



    const bool drawParticles = true;
    if(drawParticles)
    {

      //PARTICLES
      auto& particleSystems = particle_manager_->GetSystems();
      auto shaderIt = shaders_.find("particle");
      Shader* particleShader = nullptr;
      if(shaderIt != shaders_.end())
      {
        particleShader = (*shaderIt).val;
      }
      graphicsAPI->SetBlendType(BlendType::Additive);
      graphicsAPI->SetDepthType(DepthType::Off);
      ParticleShaderParam particleParam;
      particleParam.shader = particleShader;
      Model* particleModel;
      for(auto& it : particleSystems)
      {
        for(auto& particleEmitter : it->GetEmitters())
        {
          particleModel = GetModel(particleEmitter->GetDescription().sourceModel);
          if(particleModel)
          {
            particleModel->Render();
            particleParam.emitter = particleEmitter;
            auto& particles = particleEmitter->GetParticles();
            for(auto& particleIndex : particleEmitter->GetAlive())
            {
              particleParam.particle = &particles[particleIndex];
              particleShader->PrepareBuffers(&particleParam);
              particleShader->Render(particleModel->GetNumVerts());
            }
          }
        }

      }
      graphicsAPI->SetBlendType(BlendType::Off);
      graphicsAPI->SetDepthType(DepthType::Normal);
    }




    //if(debugShader)
    //{
    //  for(auto& it : debug_models_)
    //  {
    //    if(it->GetDrawType() != DrawType::Default)
    //    {
    //      PrepareDebug(it);
    //      RenderDebug();
    //      debugShader->PrepareBuffers(it);
    //      debugShader->Render(debug_lines_.size());
    //    }
    //  }
    //}

    if(draw_ui_)  
    {
      TwDraw();
    }
    
    EndScene();
    mat_stack_->Pop();

  }