Use StretchRect to speed up simple blits.

Fixed copy position transformation.
TRAC #16494
Signed-off-by: Daniel Koch
Author: Nicolas Capens

git-svn-id: https://angleproject.googlecode.com/svn/trunk@618 736b8ea6-26fd-11df-bfd4-992fa37f6226
This commit is contained in:
daniel@transgaming.com
2011-04-22 11:33:27 +00:00
parent a114c27392
commit eef864ade3
4 changed files with 41 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
#define MAJOR_VERSION 0
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 617
#define BUILD_REVISION 618
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)

View File

@@ -287,6 +287,34 @@ bool Blit::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest)
return true;
}
bool Blit::copy(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest)
{
IDirect3DDevice9 *device = getDevice();
D3DSURFACE_DESC sourceDesc;
D3DSURFACE_DESC destDesc;
source->GetDesc(&sourceDesc);
dest->GetDesc(&destDesc);
if (sourceDesc.Format == destDesc.Format && destDesc.Usage & D3DUSAGE_RENDERTARGET) // Can use StretchRect
{
RECT destRect = {xoffset, yoffset, xoffset + (sourceRect.right - sourceRect.left), yoffset + (sourceRect.bottom - sourceRect.top)};
HRESULT result = device->StretchRect(source, &sourceRect, dest, &destRect, D3DTEXF_POINT);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY, false);
}
}
else
{
return formatConvert(source, sourceRect, destFormat, xoffset, yoffset, dest);
}
return true;
}
bool Blit::formatConvert(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest)
{
IDirect3DTexture9 *texture = copySurfaceToTexture(source, sourceRect);

View File

@@ -28,6 +28,10 @@ class Blit
explicit Blit(Context *context);
~Blit();
// Copy from source surface to dest surface.
// sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left)
bool copy(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest);
// Copy from source surface to dest surface.
// sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left)
// source is interpreted as RGBA and destFormat specifies the desired result format. For example, if destFormat = GL_RGB, the alpha channel will be forced to 0.

View File

@@ -1436,11 +1436,13 @@ void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei
sourceRect.top = clamp(sourceRect.top, 0, source->getColorbuffer()->getHeight());
sourceRect.right = clamp(sourceRect.right, 0, source->getColorbuffer()->getWidth());
sourceRect.bottom = clamp(sourceRect.bottom, 0, source->getColorbuffer()->getHeight());
GLint destYOffset = transformPixelYOffset(0, height, mImageArray[level].height);
IDirect3DSurface9 *dest;
HRESULT hr = mTexture->GetSurfaceLevel(level, &dest);
getBlitter()->formatConvert(source->getRenderTarget(), sourceRect, format, 0, 0, dest);
getBlitter()->copy(source->getRenderTarget(), sourceRect, format, 0, destYOffset, dest);
dest->Release();
}
}
@@ -1489,7 +1491,7 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo
IDirect3DSurface9 *dest;
HRESULT hr = mTexture->GetSurfaceLevel(level, &dest);
getBlitter()->formatConvert(source->getRenderTarget(), sourceRect, mImageArray[0].format, xoffset, destYOffset, dest);
getBlitter()->copy(source->getRenderTarget(), sourceRect, mImageArray[0].format, xoffset, destYOffset, dest);
dest->Release();
}
}
@@ -2281,9 +2283,11 @@ void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint
sourceRect.right = clamp(sourceRect.right, 0, source->getColorbuffer()->getWidth());
sourceRect.bottom = clamp(sourceRect.bottom, 0, source->getColorbuffer()->getHeight());
GLint destYOffset = transformPixelYOffset(0, height, mImageArray[faceindex][level].width);
IDirect3DSurface9 *dest = getCubeMapSurface(target, level);
getBlitter()->formatConvert(source->getRenderTarget(), sourceRect, format, 0, 0, dest);
getBlitter()->copy(source->getRenderTarget(), sourceRect, format, 0, destYOffset, dest);
dest->Release();
}
}
@@ -2349,7 +2353,7 @@ void TextureCubeMap::copySubImage(GLenum target, GLint level, GLint xoffset, GLi
IDirect3DSurface9 *dest = getCubeMapSurface(target, level);
getBlitter()->formatConvert(source->getRenderTarget(), sourceRect, mImageArray[0][0].format, xoffset, destYOffset, dest);
getBlitter()->copy(source->getRenderTarget(), sourceRect, mImageArray[0][0].format, xoffset, destYOffset, dest);
dest->Release();
}
}