Beispiel #1
0
void
rig_paint_camera_entity (RutEntity *camera, RigPaintContext *paint_ctx)
{
  RutPaintContext *rut_paint_ctx = &paint_ctx->_parent;
  RutCamera *save_camera = rut_paint_ctx->camera;
  RutCamera *camera_component =
    rut_entity_get_component (camera, RUT_COMPONENT_TYPE_CAMERA);

  rut_paint_ctx->camera = camera_component;

  rut_camera_flush (camera_component);
  paint_scene (paint_ctx);
  rut_camera_end_frame (camera_component);

  rut_paint_ctx->camera = save_camera;
}
Beispiel #2
0
cg_texture_t *
rig_downsampler_downsample(rig_downsampler_t *downsampler,
                           cg_texture_t *source,
                           int scale_factor_x,
                           int scale_factor_y)
{
    cg_texture_components_t components;
    int src_w, src_h;
    int dest_width, dest_height;
    cg_pipeline_t *pipeline;

    /* validation */
    src_w = cg_texture_get_width(source);
    src_h = cg_texture_get_height(source);

    if (src_w % scale_factor_x != 0) {
        c_warning("downsample: the width of the texture (%d) is not a "
                  "multiple of the scale factor (%d)",
                  src_w,
                  scale_factor_x);
    }
    if (src_h % scale_factor_y != 0) {
        c_warning("downsample: the height of the texture (%d) is not a "
                  "multiple of the scale factor (%d)",
                  src_h,
                  scale_factor_y);
    }

    /* create the destination texture up front */
    dest_width = src_w / scale_factor_x;
    dest_height = src_h / scale_factor_y;
    components = cg_texture_get_components(source);

    if (downsampler->dest == NULL ||
        cg_texture_get_width(downsampler->dest) != dest_width ||
        cg_texture_get_height(downsampler->dest) != dest_height ||
        cg_texture_get_components(downsampler->dest) != components) {
        cg_offscreen_t *offscreen;
        cg_texture_2d_t *texture_2d = cg_texture_2d_new_with_size(
            downsampler->engine->shell->cg_device, dest_width, dest_height);

        cg_texture_set_components(texture_2d, components);

        _rig_downsampler_reset(downsampler);

        downsampler->dest = texture_2d;

        /* create the FBO to render the downsampled texture */
        offscreen = cg_offscreen_new_with_texture(downsampler->dest);
        downsampler->fb = offscreen;

        /* create the camera that will setup the scene for the render */
        downsampler->camera = rig_camera_new(downsampler->engine,
                                             dest_width, /* ortho width */
                                             dest_height, /* ortho height */
                                             downsampler->fb);
        rut_camera_set_near_plane(downsampler->camera, -1.f);
        rut_camera_set_far_plane(downsampler->camera, 1.f);
    }

    pipeline = cg_pipeline_copy(downsampler->pipeline);
    cg_pipeline_set_layer_texture(pipeline, 0, source);

    rut_camera_flush(downsampler->camera);

    cg_framebuffer_draw_rectangle(
        downsampler->fb, pipeline, 0, 0, dest_width, dest_height);

    rut_camera_end_frame(downsampler->camera);

    cg_object_unref(pipeline);

    return cg_object_ref(downsampler->dest);
}