コード例 #1
0
ファイル: gs-test.c プロジェクト: mlankhorst/Mesa-3D
static void init( void )
{
   struct pipe_framebuffer_state fb;
   struct pipe_resource templat;
   struct pipe_surface surf_tmpl;
   int i;

   /* It's hard to say whether window or screen should be created
    * first.  Different environments would prefer one or the other.
    *
    * Also, no easy way of querying supported formats if the screen
    * cannot be created first.
    */
   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                             formats[i],
                                             &window);
      if (window && screen)
         break;
   }
   if (!screen || !window) {
      fprintf(stderr, "Unable to create window\n");
      exit(1);
   }

   ctx = screen->context_create(screen, NULL);
   if (ctx == NULL)
      exit(3);

   templat.target = PIPE_TEXTURE_2D;
   templat.format = formats[i];
   templat.width0 = WIDTH;
   templat.height0 = HEIGHT;
   templat.depth0 = 1;
   templat.array_size = 1;
   templat.last_level = 0;
   templat.nr_samples = 1;
   templat.bind = (PIPE_BIND_RENDER_TARGET |
                   PIPE_BIND_DISPLAY_TARGET);
   
   rttex = screen->resource_create(screen,
                                 &templat);
   if (rttex == NULL)
      exit(4);

   surf_tmpl.format = templat.format;
   surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
   surf_tmpl.u.tex.level = 0;
   surf_tmpl.u.tex.first_layer = 0;
   surf_tmpl.u.tex.last_layer = 0;
   surf = ctx->create_surface(ctx, rttex, &surf_tmpl);
   if (surf == NULL)
      exit(5);

   memset(&fb, 0, sizeof fb);
   fb.nr_cbufs = 1;
   fb.width = WIDTH;
   fb.height = HEIGHT;
   fb.cbufs[0] = surf;

   ctx->set_framebuffer_state(ctx, &fb);
   
   {
      struct pipe_blend_state blend;
      void *handle;
      memset(&blend, 0, sizeof blend);
      blend.rt[0].colormask = PIPE_MASK_RGBA;
      handle = ctx->create_blend_state(ctx, &blend);
      ctx->bind_blend_state(ctx, handle);
   }

   {
      struct pipe_depth_stencil_alpha_state depthstencil;
      void *handle;
      memset(&depthstencil, 0, sizeof depthstencil);
      handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil);
      ctx->bind_depth_stencil_alpha_state(ctx, handle);
   }

   {
      struct pipe_rasterizer_state rasterizer;
      void *handle;
      memset(&rasterizer, 0, sizeof rasterizer);
      rasterizer.cull_face = PIPE_FACE_NONE;
      rasterizer.gl_rasterization_rules = 1;
      handle = ctx->create_rasterizer_state(ctx, &rasterizer);
      ctx->bind_rasterizer_state(ctx, handle);
   }

   set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000);

   init_tex();
   init_fs_constbuf();

   set_vertices();
   set_vertex_shader();
   set_fragment_shader();
   set_geometry_shader();
}
コード例 #2
0
ファイル: render_chain.cpp プロジェクト: AreaScout/retro
bool RenderChain::render(const void *data,
      unsigned width, unsigned height, unsigned pitch, unsigned rotation)
{
   start_render();

   unsigned current_width = width, current_height = height;
   unsigned out_width = 0, out_height = 0;
   convert_geometry(passes[0].info, out_width, out_height,
         current_width, current_height, final_viewport);

   blit_to_texture(data, width, height, pitch);

   // Grab back buffer.
   LPDIRECT3DSURFACE back_buffer;
   dev->GetRenderTarget(0, &back_buffer);

   // In-between render target passes.
   for (unsigned i = 0; i < passes.size() - 1; i++)
   {
      Pass &from_pass = passes[i];
      Pass &to_pass = passes[i + 1];

      LPDIRECT3DSURFACE target;
      to_pass.tex->GetSurfaceLevel(0, &target);
      dev->SetRenderTarget(0, target);

      convert_geometry(from_pass.info,
            out_width, out_height,
            current_width, current_height, final_viewport);

      // Clear out whole FBO.
      D3DVIEWPORT viewport = {0};
      viewport.Width = to_pass.info.tex_w;
      viewport.Height = to_pass.info.tex_h;
      viewport.MinZ = 0.0f;
      viewport.MaxZ = 1.0f;
      dev->SetViewport(&viewport);
      dev->Clear(0, 0, D3DCLEAR_TARGET, 0, 1, 0);
      
      viewport.Width = out_width;
      viewport.Height = out_height;
      set_viewport(viewport);

      set_vertices(from_pass,
            current_width, current_height,
            out_width, out_height,
            out_width, out_height, 0);

      render_pass(from_pass, i + 1);

      current_width = out_width;
      current_height = out_height;
      target->Release();
   }

   // Final pass
   dev->SetRenderTarget(0, back_buffer);
   Pass &last_pass = passes.back();

   convert_geometry(last_pass.info,
         out_width, out_height,
         current_width, current_height, final_viewport);
   set_viewport(final_viewport);
   set_vertices(last_pass,
            current_width, current_height,
            out_width, out_height,
            final_viewport.Width, final_viewport.Height,
            rotation);
   render_pass(last_pass, passes.size());

   frame_count++;

   back_buffer->Release();

   end_render();
   set_shaders(fStock, vStock);
   set_cg_mvp(vStock, final_viewport.Width, final_viewport.Height, 0);
   return true;
}
コード例 #3
0
ファイル: box.cpp プロジェクト: aleksijuvani/polygonist
    void box::update_mesh()
    {
        float x = position.get_x();
        float y = position.get_y();
        float z = position.get_z();
        float length = size.get_x();
        float height = size.get_y();
        float depth = size.get_z();

        std::vector<std::unique_ptr<vertex_format>> vertices;

        // Front

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y - height * 0.5f, z - depth * 0.5f },
            { 0.0f, 0.0f, -1.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 0.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y - height * 0.5f, z - depth * 0.5f },
            { 0.0f, 0.0f, -1.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 0.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y + height * 0.5f, z - depth * 0.5f },
            { 0.0f, 0.0f, -1.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 1.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y + height * 0.5f, z - depth * 0.5f },
            { 0.0f, 0.0f, -1.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 1.0f }
        ));

        // Back

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y - height * 0.5f, z + depth * 0.5f },
            { 0.0f, 0.0f, 1.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 0.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y - height * 0.5f, z + depth * 0.5f },
            { 0.0f, 0.0f, 1.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 0.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y + height * 0.5f, z + depth * 0.5f },
            { 0.0f, 0.0f, 1.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 1.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y + height * 0.5f, z + depth * 0.5f },
            { 0.0f, 0.0f, 1.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 1.0f }
        ));

        // Left

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y + height * 0.5f, z + depth * 0.5f },
            { -1.0f, 0.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 0.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y + height * 0.5f, z - depth * 0.5f },
            { -1.0f, 0.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 1.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y - height * 0.5f, z - depth * 0.5f },
            { -1.0f, 0.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 1.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y - height * 0.5f, z + depth * 0.5f },
            { -1.0f, 0.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 0.0f }
        ));

        // Right

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y + height * 0.5f, z + depth * 0.5f },
            { 1.0f, 0.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 0.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y + height * 0.5f, z - depth * 0.5f },
            { 1.0f, 0.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 1.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y - height * 0.5f, z - depth * 0.5f },
            { 1.0f, 0.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 1.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y - height * 0.5f, z + depth * 0.5f },
            { 1.0f, 0.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 0.0f }
        ));

        // Down

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y - height * 0.5f, z - depth * 0.5f },
            { 0.0f, -1.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 1.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y - height * 0.5f, z - depth * 0.5f },
            { 0.0f, -1.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 1.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y - height * 0.5f, z + depth * 0.5f },
            { 0.0f, -1.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 0.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y - height * 0.5f, z + depth * 0.5f },
            { 0.0f, -1.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 0.0f }
        ));

        // Up

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y + height * 0.5f, z - depth * 0.5f },
            { 0.0f, 1.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 1.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y + height * 0.5f, z - depth * 0.5f },
            { 0.0f, 1.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 1.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x + length * 0.5f, y + height * 0.5f, z + depth * 0.5f },
            { 0.0f, 1.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 1.0f, 0.0f }
        ));

        vertices.emplace_back(new vertex_formats::position_normal_tangent_uv(
            { x - length * 0.5f, y + height * 0.5f, z + depth * 0.5f },
            { 0.0f, 1.0f, 0.0f },
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate tangent
            { 0.0f, 0.0f, 0.0f }, // TODO: calculate bitangent
            { 0.0f, 0.0f }
        ));

        set_vertices(vertices);
    }