Ejemplo n.º 1
0
//----------------------------------------------------------
//void ofxObject::draw(float *_matrix){
void ofxObject::draw(ofxObjectMaterial *iMaterial, float *iMatrix, int iSelect, bool iDrawAlone)
{
	//if(id == 1) printf("i am a circle %f - %f, %f, %f\n", ofGetElapsedTimef(), color.r, color.g, color.b);
  
	//call idle whether or not the object is shown
	//PEND: this might have to move down, so it doesn't get called multiple times
	//idle(ofGetElapsedTimef());
  
  
	if(shown) {
		
		//printf("ofxObject::draw()\n");
		if(!iDrawAlone){
			float *mat = updateMatrix(iMatrix);
			ofxObjectMaterial *m = updateMaterial(iMaterial);	//v4.0
      
			predraw();
      
			if ((iSelect == OF_RENDER_TRANSPARENT) && !hasTransparency()) {
				//Don't render — Transparent render pass, but this object is opaque
			}else if ((iSelect == OF_RENDER_OPAQUE) && hasTransparency()) {
				//Don't render — Opaque render pass, but this object is transparent
			}else if ((iSelect != OF_RENDER_ONTOP) && renderOntop) {
				//Don't render — Regular pass, but this is an on top object
			}else {
				//Render!
				render();
				//for (unsigned int i = 0; i < children.size(); i++)
        //children[i]->draw(m, mat, iSelect);
			}
			//v4.0 - to get alpha inheritance working
			for (unsigned int i = 0; i < children.size(); i++)
				children[i]->draw(m, mat, iSelect);
      
			postdraw();
		}
		else{
			//iDrawAlone is true — just draw this object (no children)
			//PEND idle of children won't get called for these objects! live with it or fix it
			//v4.0 (moving children draw loop above might have fixed it)
			predraw();
			render();
			postdraw();
		}
	}
	
}
Ejemplo n.º 2
0
void Strings3D::drawAll(const Geom::Vec3f& color)
{
    predraw(color);
    if (m_strpos.size() != m_strTranslate.size())
    {
        CGoGNerr << "Strings3D: for drawAll use exclusively addString with position"<< CGoGNendl;
        return;
    }

    unsigned int nb = m_strpos.size();
    for (unsigned int idSt=0; idSt<nb; ++idSt)
    {
        glUniform3fv(*m_uniform_position, 1, m_strTranslate[idSt].data());
        glDrawArrays(GL_QUADS, m_strpos[idSt].first , m_strpos[idSt].second );
    }
    postdraw();
}
Ejemplo n.º 3
0
void VirtGlWindow::draw( Aircraft* airPtr )
{
	aircraftPtr = airPtr;

	if ( !showFlag ) 
		return;

	predraw();

	airPtr->draw();
	if (focusFlag)
	{
		glDisable(GL_DEPTH_TEST);
		airPtr->drawHighlight();
		airPtr->draw2D();
		glEnable(GL_DEPTH_TEST);
	}

	postdraw();

 
	glDisable(GL_DEPTH_TEST);

	glLineWidth(2.0);

	if ( activeFlag )
		glColor3d( 1.0, 0.2, 0.2 );
	else
		glColor3d( 0.2, 0.2, 0.2 );

	glBegin( GL_LINE_STRIP );
		glVertex2d( orthoL, orthoB );
		glVertex2d( orthoL, orthoT );
		glVertex2d( orthoR, orthoT );
		glVertex2d( orthoR, orthoB );
		glVertex2d( orthoL, orthoB );
	glEnd();
	glEnable(GL_DEPTH_TEST);
}
Ejemplo n.º 4
0
void Node::treeDraw()
{
    if(!mIsVisible)
        return;

    if(!mIsSetup) {
        setup();
        mIsSetup = true;
    }

    // update transform matrix by calling derived class's function
    if(mIsTransformInvalidated) transform();

    // let derived class know we are about to draw stuff
    predraw();

    // apply transform
    gl::pushModelView();

    // usual way to update modelview matrix
    gl::multModelView( mTransform );

    // draw this node by calling derived class
    draw();

    // draw this node's children
    NodeList::iterator itr;
    for(itr=mChildren.begin(); itr!=mChildren.end(); ++itr)
        (*itr)->treeDraw();

    // restore transform
    gl::popModelView();

    // let derived class know we are done drawing
    postdraw();
}
Ejemplo n.º 5
0
void GBufferPass::rendering(SerializedScene const& scene,
                            SceneGraph const& graph,
                            RenderContext const& ctx,
                            CameraMode eye,
                            Camera const& camera,
                            FrameBufferObject* target,
                            View const& view) {

//    pipeline_->camera_block_left_->update(ctx.render_context, pipeline_->get_current_scene(CameraMode::LEFT).frustum);
 //   pipeline_->camera_block_right_->update(ctx.render_context, pipeline_->get_current_scene(CameraMode::RIGHT).frustum);


  if (!depth_stencil_state_ || !bfc_rasterizer_state_ ||
      !no_bfc_rasterizer_state_) {
    initialize_state_objects(ctx);
  }

  ctx.render_context->set_rasterizer_state(
      pipeline_->config.enable_backface_culling() ? bfc_rasterizer_state_
                                                  : no_bfc_rasterizer_state_);

  ctx.render_context->set_depth_stencil_state(depth_stencil_state_);

  // make sure all ubershaders are available
  update_ubershader_from_scene(ctx, scene, graph);

  // draw all drawable geometries
  for (auto const& type_ressource_pair : scene.geometrynodes_) {
    auto const& type = type_ressource_pair.first;
    auto const& ressource_container = type_ressource_pair.second;
    auto ubershader = ubershaders_.at(type);

    // set frame-consistent per-ubershader uniforms
    ubershader->set_left_resolution(pipeline_->config.get_left_resolution());
    ubershader->set_right_resolution(pipeline_->config.get_right_resolution());

    ubershader->set_material_uniforms(
        scene.materials_, ShadingModel::GBUFFER_VERTEX_STAGE, ctx);
    ubershader->set_material_uniforms(
        scene.materials_, ShadingModel::GBUFFER_FRAGMENT_STAGE, ctx);

    ubershader->set_uniform(ctx,
                            scene.enable_global_clipping_plane,
                            "gua_enable_global_clipping_plane");
    ubershader->set_uniform(
        ctx, scene.global_clipping_plane, "gua_global_clipping_plane");
    ubershader->set_uniform(ctx, false, "gua_render_shadow_map");

    for (auto const& program : ubershader->programs()) {
      Pass::bind_inputs(*program, eye, ctx);
      program->set_uniform(ctx, static_cast<int>(eye), "gua_eye");

      if (eye == CameraMode::LEFT || eye == CameraMode::CENTER) {
        ctx.render_context->bind_uniform_buffer(pipeline_->camera_block_left_->block().block_buffer(), 0);
      } else {
        ctx.render_context->bind_uniform_buffer(pipeline_->camera_block_right_->block().block_buffer(), 0);
      }
    }


    // 1. call preframe callback if available for type
    if (ubershader->get_stage_mask() & GeometryUberShader::PRE_FRAME_STAGE) {
      ubershader->preframe(ctx);
    }

    // 2. iterate all drawables of current type and call predraw of current
    // ubershader
    if (ubershader->get_stage_mask() & GeometryUberShader::PRE_DRAW_STAGE) {
      for (auto const& node : ressource_container) {
        auto const& ressource =
            GeometryDatabase::instance()->lookup(node->get_filename());
        auto const& material =
            MaterialDatabase::instance()->lookup(node->get_material());

        if (ressource && material) {
          ubershader->predraw(ctx,
                              node->get_filename(),
                              node->get_material(),
                              node->get_cached_world_transform(),
                              scm::math::transpose(scm::math::inverse(
                                  node->get_cached_world_transform())),
                              scene.frustum,
                              view);
        } else {
          if (!material) {
            Logger::LOG_WARNING
                << "GBufferPass::rendering() Cannot find material. " << material
                << std::endl;
          }
          if (!ressource) {
            Logger::LOG_WARNING
                << "GBufferPass::rendering() Cannot find geometry ressource."
                << ressource << std::endl;
          }
        }
      }
    }


    // 3. iterate all drawables of current type and call draw of current
    // ubershader
    if (ubershader->get_stage_mask() & GeometryUberShader::DRAW_STAGE) {
      for (auto const& node : ressource_container) {
        auto const& ressource =
            GeometryDatabase::instance()->lookup(node->get_filename());
        auto const& material =
            MaterialDatabase::instance()->lookup(node->get_material());

        if (ressource && material) {
          ubershader->draw(ctx,
                           node->get_filename(),
                           node->get_material(),
                           node->get_cached_world_transform(),
                           scm::math::transpose(scm::math::inverse(
                               node->get_cached_world_transform())),
                           scene.frustum,
                           view);
        } else {
          if (!material) {
            Logger::LOG_WARNING
                << "GBufferPass::rendering() Cannot find material. " << material
                << std::endl;
          }
          if (!ressource) {
            Logger::LOG_WARNING
                << "GBufferPass::rendering() Cannot find geometry ressource."
                << ressource << std::endl;

          }
        }
      }
    }

    // 4. iterate all drawables of current type and call postdraw of current
    // ubershader
    if (ubershader->get_stage_mask() & GeometryUberShader::POST_DRAW_STAGE) {
      for (auto const& node : ressource_container) {
        auto const& ressource =
            GeometryDatabase::instance()->lookup(node->get_filename());
        auto const& material =
            MaterialDatabase::instance()->lookup(node->get_material());

        if (ressource && material) {
          ubershader->postdraw(ctx,
                               node->get_filename(),
                               node->get_material(),
                               node->get_cached_world_transform(),
                               scm::math::transpose(scm::math::inverse(
                                   node->get_cached_world_transform())),
                               scene.frustum,
                               view);
        } else {
          if (!material) {
            Logger::LOG_WARNING
                << "GBufferPass::rendering() Cannot find material. " << material
                << std::endl;
          }
          if (!ressource) {
            Logger::LOG_WARNING
                << "GBufferPass::rendering() Cannot find geometry ressource."
                << ressource << std::endl;

          }
        }
      }
    }

    // 5. call postframe callback if available for type
    if (ubershader->get_stage_mask() & GeometryUberShader::POST_FRAME_STAGE) {
      ubershader->postframe(ctx);
    }
  }

  ///////////////////////////////////////////////////////////////
  // draw debug and helper information
  ///////////////////////////////////////////////////////////////
  display_quads(ctx, scene, eye, view);

  ctx.render_context->set_rasterizer_state(bbox_rasterizer_state_);
  display_bboxes(ctx, scene, view);
  display_rays(ctx, scene, view);


  ctx.render_context->reset_state_objects();
}