Example #1
0
bool Blit::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest)
{
    IDirect3DTexture9 *texture = copySurfaceToTexture(source, getSurfaceRect(source));
    if (!texture)
    {
        return false;
    }

    IDirect3DDevice9 *device = getDevice();

    saveState();

    device->SetTexture(0, texture);
    device->SetRenderTarget(0, dest);

    setVertexShader(SHADER_VS_STANDARD);
    setPixelShader(SHADER_PS_PASSTHROUGH);

    setCommonBlitState();
    device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
    device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);

    setViewport(getSurfaceRect(dest), 0, 0);

    render();

    texture->Release();

    restoreState();

    return true;
}
Example #2
0
gl::Error Blit9::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest)
{
    IDirect3DTexture9 *texture = NULL;
    gl::Error error = copySurfaceToTexture(source, getSurfaceRect(source), &texture);
    if (error.isError())
    {
        return error;
    }

    IDirect3DDevice9 *device = mRenderer->getDevice();

    saveState();

    device->SetTexture(0, texture);
    device->SetRenderTarget(0, dest);

    setVertexShader(SHADER_VS_STANDARD);
    setPixelShader(SHADER_PS_PASSTHROUGH);

    setCommonBlitState();
    device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
    device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);

    setViewport(getSurfaceRect(dest), 0, 0);

    render();

    SafeRelease(texture);

    restoreState();

    return gl::Error(GL_NO_ERROR);
}
bool DxSurf::doAlphaBlit(DxSurf& src, int xpos, int ypos, int trans){
   ASSERT((!m_locked) && src.m_dd_surf && (!src.m_locked));
   if (m_locked || (!src.m_dd_surf) || src.m_locked || (!m_dd_surf)) return false;
//    if (!m_enabled) return false;


#ifdef TIMINGS
   DWORD starttime = GetTickCount();
#endif

   RECT srcRect;
   
   if (getSurfaceRect(src.m_dd_surf, srcRect)){
      // prepare DDALPHABLTFX structure
      DDALPHABLTFX ddfx = {0};
      ddfx.dwSize = sizeof( DDALPHABLTFX);
      ddfx.ddargbScaleFactors.alpha = trans; // trans from args
      ddfx.ddargbScaleFactors.red = 255;
      ddfx.ddargbScaleFactors.green = 255;
      ddfx.ddargbScaleFactors.blue = 255;

      if (m_y_shift) ypos += m_y_shift;
      if (m_x_shift) xpos += m_x_shift;

      // Calc rects
      RECT destRect = { xpos, ypos, xpos + srcRect.right, ypos + srcRect.bottom };

      if (fixDestSrcRect(destRect, srcRect)){
         
         bool retval = false;
         if (m_dd_surf){
            retval = m_dd_surf->AlphaBlt(&destRect, src.m_dd_surf, &srcRect, DDBLT_WAITNOTBUSY,  &ddfx) == DD_OK;
         }

#ifdef TIMINGS
         DWORD endtime = GetTickCount();
         FILE *bltfile = fopen("/blttime.txt", "ab");
         if (bltfile){
            fprintf(bltfile, "image %dx%d alphablitted to %dx%d in %d ms (trans: %d)\n",
                    srcRect.right, srcRect.bottom,
                    destRect.right, destRect.bottom,
                    endtime - starttime, trans);
            fclose(bltfile);
         }
#endif
         return retval;
      }
   }

   return true;
}
bool DxSurf::doBlit( DxSurf& src, int xpos, int ypos, bool keysrc){
   ASSERT((!m_locked) && src.m_dd_surf && (!src.m_locked));
   if (m_locked || (!src.m_dd_surf) || src.m_locked || (!m_dd_surf)) return false;
//    if (!m_enabled) return false;
#ifdef TIMINGS
   DWORD starttime = GetTickCount();
#endif
      

   RECT srcRect;
   
   if ( getSurfaceRect(src.m_dd_surf, srcRect) ){
      
      if (m_y_shift) ypos += m_y_shift;
      if (m_x_shift) xpos += m_x_shift;
      
      RECT destRect = {xpos,  ypos, xpos + srcRect.right, ypos + srcRect.bottom };

      // fix destination rect
      if ( fixDestSrcRect(destRect, srcRect) ){
         // setup flags
         DWORD flags = DDBLT_WAITNOTBUSY;
         if (keysrc) flags |= DDBLT_KEYSRC;

         // Blit!   
         bool retval = false;
         if (m_dd_surf){
            retval = m_dd_surf->Blt( &destRect, src.m_dd_surf, &srcRect, flags, 0 ) == DD_OK;
         }

#ifdef TIMINGS
         DWORD endtime = GetTickCount();
         FILE *bltfile = fopen("/blttime.txt", "ab");
         if (bltfile){
            fprintf(bltfile, "image %dx%d blitted to %dx%d in %d ms (keysrc %d)\n",
                    srcRect.right, srcRect.bottom,
                    destRect.right, destRect.bottom,
                    endtime - starttime,
                    keysrc);
            fclose(bltfile);
         }
#endif
         return retval;

      }
   }

   return false;
}
void DxSurf::setSurf(IDirectDrawSurface *a_dd_surf, bool a_can_be_released){
   // assume setting unlocked surface !!
   m_dc = 0;
   m_ptr = 0;
   m_locked = false;

   m_dd_surf = a_dd_surf;
   m_can_be_released = a_can_be_released;
   if (a_dd_surf){
      RECT rect;      
      getSurfaceRect(a_dd_surf, rect);
      m_size.cx = rect.right;
      m_size.cy = rect.bottom;
   }
}