Esempio n. 1
0
void renderchain_render_pass(void *data, Pass &pass, unsigned pass_index)
{
   renderchain_t *chain = (renderchain_t*)data;
   LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
   renderchain_set_shaders(chain, pass.fPrg, pass.vPrg);

   d3dr->SetTexture(0, pass.tex);
   D3DDevice_SetSamplerState_MinFilter(d3dr, 0, translate_filter(pass.info.pass->filter));
   D3DDevice_SetSamplerState_MagFilter(d3dr, 0, translate_filter(pass.info.pass->filter));

#ifdef _XBOX1
   d3dr->SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1);
#else
   d3dr->SetVertexDeclaration(pass.vertex_decl);
#endif
   for (unsigned i = 0; i < 4; i++)
   {
      D3DDevice_SetStreamSources(d3dr, i, pass.vertex_buf, 0, sizeof(Vertex));
   }

   renderchain_bind_orig(chain, pass);
   renderchain_bind_prev(chain, pass);
   renderchain_bind_pass(chain, pass, pass_index);
   renderchain_bind_luts(chain, pass);
   renderchain_bind_tracker(chain, pass, pass_index);

   D3DDevice_DrawPrimitive(d3dr, D3DPT_TRIANGLESTRIP, 0, 2);

   // So we don't render with linear filter into render targets,
   // which apparently looked odd (too blurry).
   D3DDevice_SetSamplerState_MinFilter(d3dr, 0, D3DTEXF_POINT);
   D3DDevice_SetSamplerState_MagFilter(d3dr, 0, D3DTEXF_POINT);

   renderchain_unbind_all(chain);
}
Esempio n. 2
0
void d3d9_render_msg_post(xdk360_video_font_t * font)
{
   if( --font->m_dwNestedBeginCount > 0 )
      return;

   // Restore state
   if( font->m_bSaveState )
   {
      // Cache the global pointer into a register
      xdk_d3d_video_t *vid = (xdk_d3d_video_t*)driver.video_data;
      D3DDevice *pD3dDevice = vid->d3d_render_device;

      D3DDevice_SetTexture_Inline(pD3dDevice, 0, NULL);
      D3DDevice_SetVertexDeclaration(pD3dDevice, NULL);
      D3DDevice_SetVertexShader(pD3dDevice, NULL );
      D3DDevice_SetPixelShader(pD3dDevice, NULL );
      D3DDevice_SetRenderState_AlphaBlendEnable(pD3dDevice, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHABLENDENABLE ]);
      D3DDevice_SetRenderState_SrcBlend(pD3dDevice, font->m_dwSavedState[ SAVEDSTATE_D3DRS_SRCBLEND ] );
      D3DDevice_SetRenderState_DestBlend( pD3dDevice, font->m_dwSavedState[ SAVEDSTATE_D3DRS_DESTBLEND ] );
      D3DDevice_SetRenderState_BlendOp( pD3dDevice, font->m_dwSavedState[ SAVEDSTATE_D3DRS_BLENDOP ] );
      pD3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHATESTENABLE ] );
      pD3dDevice->SetRenderState( D3DRS_ALPHAREF, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAREF ] );
      pD3dDevice->SetRenderState( D3DRS_ALPHAFUNC, font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAFUNC ] );
      pD3dDevice->SetRenderState( D3DRS_FILLMODE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_FILLMODE ] );
      pD3dDevice->SetRenderState( D3DRS_CULLMODE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_CULLMODE ] );
      pD3dDevice->SetRenderState( D3DRS_VIEWPORTENABLE, font->m_dwSavedState[ SAVEDSTATE_D3DRS_VIEWPORTENABLE ] );
      D3DDevice_SetSamplerState_MinFilter(pD3dDevice, 0, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MINFILTER ] );
      D3DDevice_SetSamplerState_MagFilter(pD3dDevice, 0, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MAGFILTER ] );
      D3DDevice_SetSamplerState_AddressU_Inline(pD3dDevice, 0, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSU ] );
      D3DDevice_SetSamplerState_AddressV_Inline(pD3dDevice, 0, font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSV ] );
   }
}
Esempio n. 3
0
void d3d_set_sampler_magfilter(LPDIRECT3DDEVICE dev,
      unsigned sampler, unsigned value)
{
#if defined(_XBOX1)
   D3D__DirtyFlags |= (D3DDIRTYFLAG_TEXTURE_STATE_0 << sampler);
   D3D__TextureState[sampler][D3DTSS_MAGFILTER] = value;
#elif defined(_XBOX360)
   D3DDevice_SetSamplerState_MagFilter(dev, sampler, value);
#else
   dev->SetSamplerState(sampler, D3DSAMP_MAGFILTER, value);
#endif
}
Esempio n. 4
0
bool renderchain_create_first_pass(void *data, const LinkInfo *info, PixelFormat fmt)
{
   renderchain_t *chain = (renderchain_t*)data;
   D3DXMATRIX ident;
   D3DXMatrixIdentity(&ident);
   LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
   d3dr->SetTransform(D3DTS_WORLD, &ident);
   d3dr->SetTransform(D3DTS_VIEW, &ident);

   Pass pass;
   pass.info = *info;
   pass.last_width = 0;
   pass.last_height = 0;

   chain->prev.ptr = 0;
   for (unsigned i = 0; i < TEXTURES; i++)
   {
      chain->prev.last_width[i] = 0;
      chain->prev.last_height[i] = 0;

      if (FAILED(d3dr->CreateVertexBuffer(
                  4 * sizeof(Vertex),
                  d3dr->GetSoftwareVertexProcessing() ? D3DUSAGE_SOFTWAREPROCESSING : 0,
                  0,
                  D3DPOOL_DEFAULT,
                  &chain->prev.vertex_buf[i],
                  NULL)))
      {
         return false;
      }

      if (FAILED(d3dr->CreateTexture(info->tex_w, info->tex_h, 1, 0,
                  fmt == RGB565 ? D3DFMT_R5G6B5 : D3DFMT_X8R8G8B8,
                  D3DPOOL_MANAGED,
                  &chain->prev.tex[i], NULL)))
      {
         return false;
      }

      d3dr->SetTexture(0, chain->prev.tex[i]);
      D3DDevice_SetSamplerState_MinFilter(d3dr, 0, translate_filter(info->pass->filter));
      D3DDevice_SetSamplerState_MagFilter(d3dr, 0, translate_filter(info->pass->filter));
      D3DDevice_SetSamplerState_AddressU(d3dr, 0, D3DTADDRESS_BORDER);
      D3DDevice_SetSamplerState_AddressV(d3dr, 0, D3DTADDRESS_BORDER);
      d3dr->SetTexture(0, NULL);
   }

   renderchain_compile_shaders(chain, pass.fPrg, pass.vPrg, info->pass->source.path);
   if (!renderchain_init_shader_fvf(chain, pass))
      return false;
   chain->passes.push_back(pass);
   return true;
}
Esempio n. 5
0
void renderchain_unbind_all(void *data)
{
   renderchain_t *chain = (renderchain_t*)data;
   LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
   // Have to be a bit anal about it.
   // Render targets hate it when they have filters apparently.
   for (unsigned i = 0; i < chain->bound_tex.size(); i++)
   {
      D3DDevice_SetSamplerState_MinFilter(d3dr, chain->bound_tex[i], D3DTEXF_POINT);
      D3DDevice_SetSamplerState_MagFilter(d3dr, chain->bound_tex[i], D3DTEXF_POINT);
      d3dr->SetTexture(chain->bound_tex[i], NULL);
   }

   for (unsigned i = 0; i < chain->bound_vert.size(); i++)
   {
      D3DDevice_SetStreamSources(d3dr, chain->bound_vert[i], 0, 0, 0);
   }

   chain->bound_tex.clear();
   chain->bound_vert.clear();
}
Esempio n. 6
0
void d3d9_render_msg_pre(xdk360_video_font_t * font)
{
   // Set state on the first call
   if( font->m_dwNestedBeginCount == 0 )
   {
      // Cache the global pointer into a register
      xdk_d3d_video_t *vid = (xdk_d3d_video_t*)driver.video_data;
      D3DDevice *pD3dDevice = vid->d3d_render_device;

      // Save state
      if( font->m_bSaveState )
      {
         pD3dDevice->GetRenderState( D3DRS_ALPHABLENDENABLE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHABLENDENABLE ] );
         pD3dDevice->GetRenderState( D3DRS_SRCBLEND, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_SRCBLEND ] );
		 pD3dDevice->GetRenderState( D3DRS_DESTBLEND, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_DESTBLEND ] );
		 pD3dDevice->GetRenderState( D3DRS_BLENDOP, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_BLENDOP ] );
		 pD3dDevice->GetRenderState( D3DRS_ALPHATESTENABLE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHATESTENABLE ] );
		 pD3dDevice->GetRenderState( D3DRS_ALPHAREF, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAREF ] );
		 pD3dDevice->GetRenderState( D3DRS_ALPHAFUNC, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_ALPHAFUNC ] );
		 pD3dDevice->GetRenderState( D3DRS_FILLMODE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_FILLMODE ] );
		 pD3dDevice->GetRenderState( D3DRS_CULLMODE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_CULLMODE ] );
		 pD3dDevice->GetRenderState( D3DRS_VIEWPORTENABLE, &font->m_dwSavedState[ SAVEDSTATE_D3DRS_VIEWPORTENABLE ] );
		 font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MINFILTER ] = D3DDevice_GetSamplerState_MinFilter( pD3dDevice, 0 );
		 font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_MAGFILTER ] = D3DDevice_GetSamplerState_MagFilter( pD3dDevice, 0 );
		 font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSU ] = D3DDevice_GetSamplerState_AddressU( pD3dDevice, 0);
		 font->m_dwSavedState[ SAVEDSTATE_D3DSAMP_ADDRESSV ]  = D3DDevice_GetSamplerState_AddressV( pD3dDevice, 0);
      }

      // Set the texture scaling factor as a vertex shader constant
      D3DSURFACE_DESC TextureDesc;
      D3DTexture_GetLevelDesc(font->m_pFontTexture, 0, &TextureDesc); // Get the description

      // Set render state
      D3DDevice_SetTexture_Inline(pD3dDevice, 0, font->m_pFontTexture);

      // Read the TextureDesc here to ensure no load/hit/store from GetLevelDesc()
      float vTexScale[4];
      vTexScale[0] = 1.0f / TextureDesc.Width;		// LHS due to int->float conversion
      vTexScale[1] = 1.0f / TextureDesc.Height;
      vTexScale[2] = 0.0f;
      vTexScale[3] = 0.0f;

      D3DDevice_SetRenderState_AlphaBlendEnable( pD3dDevice, TRUE );
      D3DDevice_SetRenderState_SrcBlend(pD3dDevice, D3DBLEND_SRCALPHA );
      D3DDevice_SetRenderState_DestBlend( pD3dDevice, D3DBLEND_INVSRCALPHA );
      D3DDevice_SetRenderState_BlendOp( pD3dDevice, D3DBLENDOP_ADD );
      pD3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
      pD3dDevice->SetRenderState( D3DRS_ALPHAREF, 0x08 );
      pD3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
      pD3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
      pD3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
      pD3dDevice->SetRenderState( D3DRS_VIEWPORTENABLE, FALSE );
      D3DDevice_SetSamplerState_MinFilter(pD3dDevice, 0, D3DTEXF_LINEAR );
      D3DDevice_SetSamplerState_MagFilter(pD3dDevice, 0, D3DTEXF_LINEAR );
      D3DDevice_SetSamplerState_AddressU_Inline(pD3dDevice, 0, D3DTADDRESS_CLAMP );
      D3DDevice_SetSamplerState_AddressV_Inline(pD3dDevice, 0, D3DTADDRESS_CLAMP );

      D3DDevice_SetVertexDeclaration(pD3dDevice, s_FontLocals.m_pFontVertexDecl );
      D3DDevice_SetVertexShader(pD3dDevice, s_FontLocals.m_pFontVertexShader );
      D3DDevice_SetPixelShader(pD3dDevice, s_FontLocals.m_pFontPixelShader );

      // Set the texture scaling factor as a vertex shader constant
      // Call here to avoid load hit store from writing to vTexScale above
      pD3dDevice->SetVertexShaderConstantF( 2, vTexScale, 1 );
   }

   // Keep track of the nested begin/end calls.
   font->m_dwNestedBeginCount++;
}