Exemple #1
0
    /* Sets the color based on argument (color/background, verify, wrong, idle)
     * and type (line, background and fill). Type defines alpha value and tint.
     * Utilizes color_array() and frees after use.
     */
    void set_color(cairo_t *cr, char *colorarg, char colortype) {
        uint32_t *rgb16 = color_array(colorarg);

        switch(colortype) {
            case 'b': /* Background */
                cairo_set_source_rgb(cr, rgb16[0] / 255.0, rgb16[1] / 255.0, rgb16[2] / 255.0);
                break;
            case 'l': /* Line and text */
                cairo_set_source_rgba(cr, rgb16[0] / 255.0, rgb16[1] / 255.0, rgb16[2] / 255.0, 0.8);
                break;
            case 'f': /* Fill */
                /* Use a lighter tint of the user defined color for circle fill */
                for (int i=0; i < 3; i++) {
                    rgb16[i] = ((255 - rgb16[i]) * .5) + rgb16[i];
                }
                cairo_set_source_rgba(cr, rgb16[0] / 255.0, rgb16[1] / 255.0, rgb16[2] / 255.0, 0.2);
                break;
        }
        free(rgb16);
    }
Exemple #2
0
void Video3DUberShader::draw(RenderContext const& ctx,
                             std::string const& ksfile_name,
                             std::string const& material_name,
                             scm::math::mat4 const& model_matrix,
                             scm::math::mat4 const& normal_matrix,
                             Frustum const& /*frustum*/,
                             View const& view) const
{  if (!GeometryDatabase::instance()->is_supported(ksfile_name) ||
      !MaterialDatabase::instance()->is_supported(material_name)) {
    gua::Logger::LOG_WARNING << "Video3DUberShader::draw(): No such video or material." << ksfile_name << ", " << material_name << std::endl;
    return;
  }

  auto video3d_ressource = std::static_pointer_cast<Video3DRessource>(GeometryDatabase::instance()->lookup(ksfile_name));
  auto material          = MaterialDatabase::instance()->lookup(material_name);

  if (!video3d_ressource || !material) {
    gua::Logger::LOG_WARNING << "Video3DUberShader::draw(): Invalid video or material." << std::endl;
    return;
  }

  // update stream data
  video3d_ressource->update_buffers(ctx);

  // make sure ressources are on the GPU
  upload_to(ctx);
  {
    // single texture only
    scm::gl::context_all_guard guard(ctx.render_context);

    ctx.render_context->set_rasterizer_state(no_bfc_rasterizer_state_);
    ctx.render_context->set_depth_stencil_state(depth_stencil_state_warp_pass_);

    // set uniforms
    ctx.render_context->bind_texture(video3d_ressource->depth_array(ctx), nearest_sampler_state_, 0);
    get_program(warp_pass)->get_program(ctx)->uniform_sampler("depth_video3d_texture", 0);


    get_program(warp_pass)->set_uniform(ctx, normal_matrix, "gua_normal_matrix");
    get_program(warp_pass)->set_uniform(ctx, model_matrix, "gua_model_matrix");
    get_program(warp_pass)->set_uniform(ctx, int(1), "bbxclip");

    auto bbox(video3d_ressource->get_bounding_box());
    get_program(warp_pass)->set_uniform(ctx, bbox.min, "bbx_min");
    get_program(warp_pass)->set_uniform(ctx, bbox.max, "bbx_max");

    // pre passes
    for (unsigned layer = 0; layer != video3d_ressource->number_of_cameras(); ++layer)
    {
      // configure fbo
      warp_result_fbo_->clear_attachments();
      warp_result_fbo_->attach_depth_stencil_buffer(warp_depth_result_, 0, layer);
      warp_result_fbo_->attach_color_buffer(0, warp_color_result_, 0, layer);

      // bind and clear fbo
      ctx.render_context->set_frame_buffer(warp_result_fbo_);
      ctx.render_context->clear_depth_stencil_buffer(warp_result_fbo_);
      ctx.render_context->clear_color_buffer(warp_result_fbo_, 0, scm::math::vec4f(0.0f, 0.0f, 0.0f, 0.0f));
      ctx.render_context->set_viewport(scm::gl::viewport(scm::math::vec2ui(0,0), warp_color_result_->dimensions()));

      // set uniforms
      get_program(warp_pass)->set_uniform(ctx, video3d_ressource->calibration_file(layer).getTexSizeInvD(), "tex_size_inv");
      get_program(warp_pass)->set_uniform(ctx, int(layer), "layer");


      if (material && video3d_ressource)
      {
        get_program(warp_pass)->set_uniform(ctx, video3d_ressource->calibration_file(layer).getImageDToEyeD(), "image_d_to_eye_d");
        get_program(warp_pass)->set_uniform(ctx, video3d_ressource->calibration_file(layer).getEyeDToWorld(), "eye_d_to_world");
        get_program(warp_pass)->set_uniform(ctx, video3d_ressource->calibration_file(layer).getEyeDToEyeRGB(), "eye_d_to_eye_rgb");
        get_program(warp_pass)->set_uniform(ctx, video3d_ressource->calibration_file(layer).getEyeRGBToImageRGB(), "eye_rgb_to_image_rgb");

	      ctx.render_context->bind_texture(video3d_ressource->cv_xyz(ctx,layer), linear_sampler_state_, 1);
	      get_program(warp_pass)->get_program(ctx)->uniform_sampler("cv_xyz", 1);

	      ctx.render_context->bind_texture(video3d_ressource->cv_uv(ctx,layer), linear_sampler_state_, 2);
	      get_program(warp_pass)->get_program(ctx)->uniform_sampler("cv_uv", 2);

	      get_program(warp_pass)->set_uniform(ctx, video3d_ressource->calibration_file(layer).cv_min_d, "cv_min_d");
	      get_program(warp_pass)->set_uniform(ctx, video3d_ressource->calibration_file(layer).cv_max_d, "cv_max_d");

        get_program(warp_pass)->use(ctx);
        {
          video3d_ressource->draw(ctx);
        }
        get_program(warp_pass)->unuse(ctx);
      }

      ctx.render_context->reset_framebuffer();
    }
  }

  {
    // single texture only
    scm::gl::context_all_guard guard(ctx.render_context);

    ctx.render_context->set_depth_stencil_state(depth_stencil_state_warp_pass_);

    // second pass
    get_program(blend_pass)->use(ctx);
    {
      if (material && video3d_ressource)
      {
        set_uniform(ctx, material->get_id(), "gua_material_id");
        set_uniform(ctx, normal_matrix, "gua_normal_matrix");
        set_uniform(ctx, model_matrix, "gua_model_matrix");

        // needs to be multiplied with scene scaling
        set_uniform(ctx, 0.075f, "epsilon");
        set_uniform(ctx, int(video3d_ressource->number_of_cameras()), "numlayers");
        get_program(blend_pass)->set_uniform(ctx, int(material_name == default_video_material_name()), "using_default_video_material");
        get_program(blend_pass)->set_uniform(ctx, int(video3d_ressource->do_overwrite_normal()), "overwrite_normal");
        get_program(blend_pass)->set_uniform(ctx, video3d_ressource->get_overwrite_normal(), "o_normal");

        ctx.render_context->bind_texture(warp_color_result_, nearest_sampler_state_, 0);
        get_program(blend_pass)->get_program(ctx)->uniform_sampler("quality_texture", 0);

        ctx.render_context->bind_texture(warp_depth_result_, nearest_sampler_state_, 1);
        get_program(blend_pass)->get_program(ctx)->uniform_sampler("depth_texture", 1);

        ctx.render_context->bind_texture(video3d_ressource->color_array(ctx), linear_sampler_state_, 2);
        get_program(blend_pass)->get_program(ctx)->uniform_sampler("video_color_texture", 2);

        fullscreen_quad_->draw(ctx.render_context);
      }
    }
    get_program(blend_pass)->unuse(ctx);
  }
}