Exemplo n.º 1
0
void RenderChain::bind_orig(Pass &pass)
{
   D3DXVECTOR2 video_size, texture_size;
   video_size.x = passes[0].last_width;
   video_size.y = passes[0].last_height;
   texture_size.x = passes[0].info.tex_w;
   texture_size.y = passes[0].info.tex_h;

   set_cg_param(pass.vPrg, "ORIG.video_size", video_size);
   set_cg_param(pass.fPrg, "ORIG.video_size", video_size);
   set_cg_param(pass.vPrg, "ORIG.texture_size", texture_size);
   set_cg_param(pass.fPrg, "ORIG.texture_size", texture_size);

   CGparameter param = cgGetNamedParameter(pass.fPrg, "ORIG.texture");
   if (param)
   {
      unsigned index = cgGetParameterResourceIndex(param);
      dev->SetTexture(index, passes[0].tex);
      dev->SetSamplerState(index, D3DSAMP_MAGFILTER,
            translate_filter(passes[0].info.pass->filter));
      dev->SetSamplerState(index, D3DSAMP_MINFILTER,
            translate_filter(passes[0].info.pass->filter));
      dev->SetSamplerState(index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
      dev->SetSamplerState(index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
      bound_tex.push_back(index);
   }

   param = cgGetNamedParameter(pass.vPrg, "ORIG.tex_coord");
   if (param)
   {
      unsigned index = pass.attrib_map[cgGetParameterResourceIndex(param)];
      dev->SetStreamSource(index, passes[0].vertex_buf, 0, sizeof(Vertex));
      bound_vert.push_back(index);
   }
}
Exemplo n.º 2
0
void RenderChain::bind_pass(Pass &pass, unsigned pass_index)
{
   // We only bother binding passes which are two indices behind.
   if (pass_index < 3)
      return;

   for (unsigned i = 1; i < pass_index - 1; i++)
   {
      char pass_base[64];
      snprintf(pass_base, sizeof(pass_base), "PASS%u.", i);

      std::string attr_texture = pass_base;
      attr_texture += "texture";
      std::string attr_video_size = pass_base;
      attr_video_size += "video_size";
      std::string attr_texture_size = pass_base;
      attr_texture_size += "texture_size";
      std::string attr_tex_coord = pass_base;
      attr_tex_coord += "tex_coord";

      D3DXVECTOR2 video_size, texture_size;
      video_size.x = passes[i].last_width;
      video_size.y = passes[i].last_height;
      texture_size.x = passes[i].info.tex_w;
      texture_size.y = passes[i].info.tex_h;

      set_cg_param(pass.vPrg, attr_video_size.c_str(), video_size);
      set_cg_param(pass.fPrg, attr_video_size.c_str(), video_size);
      set_cg_param(pass.vPrg, attr_texture_size.c_str(), texture_size);
      set_cg_param(pass.fPrg, attr_texture_size.c_str(), texture_size);

      CGparameter param = cgGetNamedParameter(pass.fPrg, attr_texture.c_str());
      if (param)
      {
         unsigned index = cgGetParameterResourceIndex(param);
         bound_tex.push_back(index);

         dev->SetTexture(index, passes[i].tex);
         dev->SetSamplerState(index, D3DSAMP_MAGFILTER,
               translate_filter(passes[i].info.pass->filter));
         dev->SetSamplerState(index, D3DSAMP_MINFILTER,
               translate_filter(passes[i].info.pass->filter));
         dev->SetSamplerState(index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
         dev->SetSamplerState(index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
      }

      param = cgGetNamedParameter(pass.vPrg, attr_tex_coord.c_str());
      if (param)
      {
         unsigned index = pass.attrib_map[cgGetParameterResourceIndex(param)];
         dev->SetStreamSource(index, passes[i].vertex_buf, 0, sizeof(Vertex));
         bound_vert.push_back(index);
      }
   }
}
Exemplo n.º 3
0
static void renderchain_set_shader_params(cg_renderchain_t *chain,
      Pass *pass,
      unsigned video_w, unsigned video_h,
      unsigned tex_w, unsigned tex_h,
      unsigned viewport_w, unsigned viewport_h)
{
   float frame_cnt;
   D3DXVECTOR2 video_size, texture_size, output_size;

   if (!chain || !pass)
      return;

   video_size.x         = video_w;
   video_size.y         = video_h;
   texture_size.x       = tex_w;
   texture_size.y       = tex_h;
   output_size.x        = viewport_w;
   output_size.y        = viewport_h;

   set_cg_param(pass->vPrg, "IN.video_size", video_size);
   set_cg_param(pass->fPrg, "IN.video_size", video_size);
   set_cg_param(pass->vPrg, "IN.texture_size", texture_size);
   set_cg_param(pass->fPrg, "IN.texture_size", texture_size);
   set_cg_param(pass->vPrg, "IN.output_size", output_size);
   set_cg_param(pass->fPrg, "IN.output_size", output_size);

   frame_cnt            = chain->frame_count;

   if (pass->info.pass->frame_count_mod)
      frame_cnt         = chain->frame_count % pass->info.pass->frame_count_mod;

   set_cg_param(pass->fPrg, "IN.frame_count", frame_cnt);
   set_cg_param(pass->vPrg, "IN.frame_count", frame_cnt);
}
Exemplo n.º 4
0
void RenderChain::set_cg_params(Pass &pass,
            unsigned video_w, unsigned video_h,
            unsigned tex_w, unsigned tex_h,
            unsigned viewport_w, unsigned viewport_h)
{
   D3DXVECTOR2 video_size, texture_size, output_size;
   video_size.x = video_w;
   video_size.y = video_h;
   texture_size.x = tex_w;
   texture_size.y = tex_h;
   output_size.x = viewport_w;
   output_size.y = viewport_h;

   set_cg_param(pass.vPrg, "IN.video_size", video_size);
   set_cg_param(pass.fPrg, "IN.video_size", video_size);
   set_cg_param(pass.vPrg, "IN.texture_size", texture_size);
   set_cg_param(pass.fPrg, "IN.texture_size", texture_size);
   set_cg_param(pass.vPrg, "IN.output_size", output_size);
   set_cg_param(pass.fPrg, "IN.output_size", output_size);

   float frame_cnt = frame_count;
   if (pass.info.pass->frame_count_mod)
      frame_cnt = frame_count % pass.info.pass->frame_count_mod;
   set_cg_param(pass.fPrg, "IN.frame_count", frame_cnt);
   set_cg_param(pass.vPrg, "IN.frame_count", frame_cnt);
}
Exemplo n.º 5
0
void RenderChain::bind_tracker(Pass &pass, unsigned pass_index)
{
   if (!tracker)
      return;

   if (pass_index == 1)
      uniform_cnt = state_get_uniform(tracker, uniform_info, MAX_VARIABLES, frame_count);

   for (unsigned i = 0; i < uniform_cnt; i++)
   {
      set_cg_param(pass.fPrg, uniform_info[i].id, uniform_info[i].value);
      set_cg_param(pass.vPrg, uniform_info[i].id, uniform_info[i].value);
   }
}
Exemplo n.º 6
0
static void renderchain_bind_tracker(cg_renderchain_t *chain,
      Pass *pass, unsigned pass_index)
{
   unsigned i;
   if (!chain || !chain->tracker || !pass)
      return;

   if (pass_index == 1)
      chain->uniform_cnt = state_tracker_get_uniform(chain->tracker,
            chain->uniform_info, MAX_VARIABLES, chain->frame_count);

   for (i = 0; i < chain->uniform_cnt; i++)
   {
      set_cg_param(pass->fPrg, chain->uniform_info[i].id,
            chain->uniform_info[i].value);
      set_cg_param(pass->vPrg, chain->uniform_info[i].id,
            chain->uniform_info[i].value);
   }
}
Exemplo n.º 7
0
static void renderchain_bind_orig(cg_renderchain_t *chain, void *pass_data)
{
   unsigned index;
   CGparameter param;
   D3DXVECTOR2 video_size, texture_size;
   Pass           *pass = (Pass*)pass_data;
   video_size.x         = chain->passes[0].last_width;
   video_size.y         = chain->passes[0].last_height;
   texture_size.x       = chain->passes[0].info.tex_w;
   texture_size.y       = chain->passes[0].info.tex_h;

   set_cg_param(pass->vPrg, "ORIG.video_size", video_size);
   set_cg_param(pass->fPrg, "ORIG.video_size", video_size);
   set_cg_param(pass->vPrg, "ORIG.texture_size", texture_size);
   set_cg_param(pass->fPrg, "ORIG.texture_size", texture_size);

   param = cgGetNamedParameter(pass->fPrg, "ORIG.texture");
   if (param)
   {
      index = cgGetParameterResourceIndex(param);
      d3d_set_texture(chain->dev, index, chain->passes[0].tex);
      d3d_set_sampler_magfilter(chain->dev, index,
            d3d_translate_filter(chain->passes[0].info.pass->filter));
      d3d_set_sampler_minfilter(chain->dev, index, 
            d3d_translate_filter(chain->passes[0].info.pass->filter));
      d3d_set_sampler_address_u(chain->dev, index, D3DTADDRESS_BORDER);
      d3d_set_sampler_address_v(chain->dev, index, D3DTADDRESS_BORDER);
      chain->bound_tex.push_back(index);
   }

   param = cgGetNamedParameter(pass->vPrg, "ORIG.tex_coord");
   if (param)
   {
      LPDIRECT3DVERTEXBUFFER vert_buf = (LPDIRECT3DVERTEXBUFFER)chain->passes[0].vertex_buf;

      index = pass->attrib_map[cgGetParameterResourceIndex(param)];

      d3d_set_stream_source(chain->dev, index, vert_buf, 0, sizeof(Vertex));
      chain->bound_vert.push_back(index);
   }
}
Exemplo n.º 8
0
static void renderchain_bind_pass(cg_renderchain_t *chain,
      Pass *pass, unsigned pass_index)
{
   unsigned i, index;

   /* We only bother binding passes which are two indices behind. */
   if (pass_index < 3)
      return;

   for (i = 1; i < pass_index - 1; i++)
   {
      CGparameter param;
      D3DXVECTOR2 video_size, texture_size;
      char pass_base[64]       = {0};
      char attr_texture[64]    = {0};
      char attr_input_size[64] = {0};
      char attr_tex_size[64]   = {0};
      char attr_coord[64]      = {0};

      snprintf(pass_base,       sizeof(pass_base),       "PASS%u",          i);
      snprintf(attr_texture,    sizeof(attr_texture),    "%s.texture",      pass_base);
      snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size",   pass_base);
      snprintf(attr_tex_size,   sizeof(attr_tex_size),   "%s.texture_size", pass_base);
      snprintf(attr_coord,      sizeof(attr_coord),      "%s.tex_coord",    pass_base);

      video_size.x   = chain->passes[i].last_width;
      video_size.y   = chain->passes[i].last_height;
      texture_size.x = chain->passes[i].info.tex_w;
      texture_size.y = chain->passes[i].info.tex_h;

      set_cg_param(pass->vPrg, attr_input_size,   video_size);
      set_cg_param(pass->fPrg, attr_input_size,   video_size);
      set_cg_param(pass->vPrg, attr_tex_size,     texture_size);
      set_cg_param(pass->fPrg, attr_tex_size,     texture_size);

      param = cgGetNamedParameter(pass->fPrg, attr_texture);
      if (param)
      {
         index = cgGetParameterResourceIndex(param);
         chain->bound_tex.push_back(index);

         d3d_set_texture(chain->dev, index, chain->passes[i].tex);
         d3d_set_sampler_magfilter(chain->dev, index,
               d3d_translate_filter(chain->passes[i].info.pass->filter));
         d3d_set_sampler_minfilter(chain->dev, index, 
               d3d_translate_filter(chain->passes[i].info.pass->filter));
         d3d_set_sampler_address_u(chain->dev, index, D3DTADDRESS_BORDER);
         d3d_set_sampler_address_v(chain->dev, index, D3DTADDRESS_BORDER);
      }

      param = cgGetNamedParameter(pass->vPrg, attr_coord);
      if (param)
      {
         index = pass->attrib_map[cgGetParameterResourceIndex(param)];

         d3d_set_stream_source(chain->dev, index, chain->passes[i].vertex_buf,
               0, sizeof(Vertex));
         chain->bound_vert.push_back(index);
      }
   }
}
Exemplo n.º 9
0
static void renderchain_bind_prev(void *data, void *pass_data)
{
   unsigned i, index;
   D3DXVECTOR2 texture_size;
   char attr_texture[64]    = {0};
   char attr_input_size[64] = {0};
   char attr_tex_size[64]   = {0};
   char attr_coord[64]      = {0};
   cg_renderchain_t *chain  = (cg_renderchain_t*)data;
   Pass               *pass = (Pass*)pass_data;
   static const char *prev_names[] = {
      "PREV",
      "PREV1",
      "PREV2",
      "PREV3",
      "PREV4",
      "PREV5",
      "PREV6",
   };

   texture_size.x = chain->passes[0].info.tex_w;
   texture_size.y = chain->passes[0].info.tex_h;

   for (i = 0; i < TEXTURES - 1; i++)
   {
      CGparameter param;
      D3DXVECTOR2 video_size;

      snprintf(attr_texture,    sizeof(attr_texture),    "%s.texture",      prev_names[i]);
      snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size",   prev_names[i]);
      snprintf(attr_tex_size,   sizeof(attr_tex_size),   "%s.texture_size", prev_names[i]);
      snprintf(attr_coord,      sizeof(attr_coord),      "%s.tex_coord",    prev_names[i]);

      video_size.x = chain->prev.last_width[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];
      video_size.y = chain->prev.last_height[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];

      set_cg_param(pass->vPrg, attr_input_size, video_size);
      set_cg_param(pass->fPrg, attr_input_size, video_size);
      set_cg_param(pass->vPrg, attr_tex_size, texture_size);
      set_cg_param(pass->fPrg, attr_tex_size, texture_size);

      param = cgGetNamedParameter(pass->fPrg, attr_texture);
      if (param)
      {
         LPDIRECT3DTEXTURE tex;

         index = cgGetParameterResourceIndex(param);

         tex = (LPDIRECT3DTEXTURE)
            chain->prev.tex[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];

         d3d_set_texture(chain->dev, index, tex);
         chain->bound_tex.push_back(index);

         d3d_set_sampler_magfilter(chain->dev, index,
               d3d_translate_filter(chain->passes[0].info.pass->filter));
         d3d_set_sampler_minfilter(chain->dev, index, 
               d3d_translate_filter(chain->passes[0].info.pass->filter));
         d3d_set_sampler_address_u(chain->dev, index, D3DTADDRESS_BORDER);
         d3d_set_sampler_address_v(chain->dev, index, D3DTADDRESS_BORDER);
      }

      param = cgGetNamedParameter(pass->vPrg, attr_coord);
      if (param)
      {
         LPDIRECT3DVERTEXBUFFER vert_buf = (LPDIRECT3DVERTEXBUFFER)
            chain->prev.vertex_buf[(chain->prev.ptr - (i + 1)) & TEXTURESMASK];

         index = pass->attrib_map[cgGetParameterResourceIndex(param)];

         d3d_set_stream_source(chain->dev, index, vert_buf, 0, sizeof(Vertex));
         chain->bound_vert.push_back(index);
      }
   }
}
Exemplo n.º 10
0
void RenderChain::bind_prev(Pass &pass)
{
   static const char *prev_names[] = {
      "PREV",
      "PREV1",
      "PREV2",
      "PREV3",
      "PREV4",
      "PREV5",
      "PREV6",
   };

   char attr_texture[64], attr_input_size[64], attr_tex_size[64], attr_coord[64];
   D3DXVECTOR2 texture_size;

   texture_size.x = passes[0].info.tex_w;
   texture_size.y = passes[0].info.tex_h;

   for (unsigned i = 0; i < Textures - 1; i++)
   {
      snprintf(attr_texture,    sizeof(attr_texture),    "%s.texture",      prev_names[i]);
      snprintf(attr_input_size, sizeof(attr_input_size), "%s.video_size",   prev_names[i]);
      snprintf(attr_tex_size,   sizeof(attr_tex_size),   "%s.texture_size", prev_names[i]);
      snprintf(attr_coord,      sizeof(attr_coord),      "%s.tex_coord",    prev_names[i]);

      D3DXVECTOR2 video_size;
      video_size.x = prev.last_width[(prev.ptr - (i + 1)) & TexturesMask];
      video_size.y = prev.last_height[(prev.ptr - (i + 1)) & TexturesMask];

      set_cg_param(pass.vPrg, attr_input_size, video_size);
      set_cg_param(pass.fPrg, attr_input_size, video_size);
      set_cg_param(pass.vPrg, attr_tex_size, texture_size);
      set_cg_param(pass.fPrg, attr_tex_size, texture_size);

      CGparameter param = cgGetNamedParameter(pass.fPrg, attr_texture);
      if (param)
      {
         unsigned index = cgGetParameterResourceIndex(param);

         LPDIRECT3DTEXTURE tex = prev.tex[(prev.ptr - (i + 1)) & TexturesMask];
         dev->SetTexture(index, tex);
         bound_tex.push_back(index);

         dev->SetSamplerState(index, D3DSAMP_MAGFILTER,
               translate_filter(passes[0].info.pass->filter));
         dev->SetSamplerState(index, D3DSAMP_MINFILTER,
               translate_filter(passes[0].info.pass->filter));
         dev->SetSamplerState(index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
         dev->SetSamplerState(index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
      }

      param = cgGetNamedParameter(pass.vPrg, attr_coord);
      if (param)
      {
         unsigned index = pass.attrib_map[cgGetParameterResourceIndex(param)];
         LPDIRECT3DVERTEXBUFFER vert_buf = prev.vertex_buf[(prev.ptr - (i + 1)) & TexturesMask];
         bound_vert.push_back(index);

         dev->SetStreamSource(index, vert_buf, 0, sizeof(Vertex));
      }
   }
}