Eliminate D3DXLoadSurfaceFromSurface from setManagedSurface.

TRAC #21621 Issue=311 Signed-off-by: Shannon Woods Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@1309 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent e0adbd80
......@@ -116,7 +116,8 @@ static inline DWORD GetTextureUsage(D3DFORMAT d3dfmt, GLenum glusage, bool force
return d3dusage;
}
static void MakeValidSize(bool isImage, bool isCompressed, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset) {
static void MakeValidSize(bool isImage, bool isCompressed, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset)
{
int upsampleCount = 0;
if (isCompressed)
......@@ -136,6 +137,34 @@ static void MakeValidSize(bool isImage, bool isCompressed, GLsizei *requestWidth
*levelOffset = upsampleCount;
}
static void CopyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *source)
{
D3DLOCKED_RECT sourceLock = {0};
D3DLOCKED_RECT destLock = {0};
source->LockRect(&sourceLock, NULL, 0);
dest->LockRect(&destLock, NULL, 0);
if (sourceLock.pBits && destLock.pBits)
{
D3DSURFACE_DESC desc;
source->GetDesc(&desc);
int rows = dx::IsCompressedFormat(desc.Format) ? desc.Height / 4 : desc.Height;
int bytes = dx::ComputeRowSize(desc.Format, desc.Width);
ASSERT(bytes <= sourceLock.Pitch && bytes <= destLock.Pitch);
for(int i = 0; i < rows; i++)
{
memcpy((char*)destLock.pBits + destLock.Pitch * i, (char*)sourceLock.pBits + sourceLock.Pitch * i, bytes);
}
source->UnlockRect();
dest->UnlockRect();
}
else UNREACHABLE();
}
Image::Image()
{
mWidth = 0;
......@@ -273,7 +302,8 @@ void Image::setManagedSurface(IDirect3DSurface9 *surface)
{
if (mSurface)
{
D3DXLoadSurfaceFromSurface(surface, NULL, NULL, mSurface, NULL, NULL, D3DX_FILTER_BOX, 0);
CopyLockableSurfaces(surface, mSurface);
mSurface->Release();
}
......@@ -1363,7 +1393,7 @@ TextureStorage2D::TextureStorage2D(int levels, D3DFORMAT format, DWORD usage, in
if (width > 0 && height > 0)
{
IDirect3DDevice9 *device = getDevice();
MakeValidSize(false, dx2es::IsCompressedD3DFormat(format), &width, &height, &mLodOffset);
MakeValidSize(false, dx::IsCompressedFormat(format), &width, &height, &mLodOffset);
HRESULT result = device->CreateTexture(width, height, levels ? levels + mLodOffset : 0, getUsage(), format, getPool(), &mTexture, NULL);
if (FAILED(result))
......@@ -2091,7 +2121,7 @@ TextureStorageCubeMap::TextureStorageCubeMap(int levels, D3DFORMAT format, DWORD
{
IDirect3DDevice9 *device = getDevice();
int height = size;
MakeValidSize(false, dx2es::IsCompressedD3DFormat(format), &size, &height, &mLodOffset);
MakeValidSize(false, dx::IsCompressedFormat(format), &size, &height, &mLodOffset);
HRESULT result = device->CreateCubeTexture(size, levels ? levels + mLodOffset : 0, getUsage(), format, getPool(), &mTexture, NULL);
if (FAILED(result))
......
......@@ -248,15 +248,13 @@ GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum internalform
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
return 8 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);
break;
return 8 * ((width + 3) / 4) * ((height + 3) / 4);
case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
return 16 * (GLsizei)ceil((float)width / 4.0f) * (GLsizei)ceil((float)height / 4.0f);
return 16 * ((width + 3) / 4) * ((height + 3) / 4);
default:
return 0;
}
}
bool IsCompressed(GLenum format)
......@@ -1023,21 +1021,6 @@ unsigned int GetDepthSize(D3DFORMAT depthFormat)
}
}
bool IsCompressedD3DFormat(D3DFORMAT surfaceFormat)
{
switch(surfaceFormat)
{
case D3DFMT_DXT1:
case D3DFMT_DXT2:
case D3DFMT_DXT3:
case D3DFMT_DXT4:
case D3DFMT_DXT5:
return true;
default:
return false;
}
}
GLsizei GetSamplesFromMultisampleType(D3DMULTISAMPLE_TYPE type)
{
if (type == D3DMULTISAMPLE_NONMASKABLE)
......@@ -1151,6 +1134,56 @@ GLenum ConvertDepthStencilFormat(D3DFORMAT format)
}
namespace dx
{
bool IsCompressedFormat(D3DFORMAT surfaceFormat)
{
switch(surfaceFormat)
{
case D3DFMT_DXT1:
case D3DFMT_DXT2:
case D3DFMT_DXT3:
case D3DFMT_DXT4:
case D3DFMT_DXT5:
return true;
default:
return false;
}
}
size_t ComputeRowSize(D3DFORMAT format, unsigned int width)
{
if (format == D3DFMT_INTZ)
{
return 4 * width;
}
switch (format)
{
case D3DFMT_L8:
return 1 * width;
case D3DFMT_A8L8:
return 2 * width;
case D3DFMT_X8R8G8B8:
case D3DFMT_A8R8G8B8:
return 4 * width;
case D3DFMT_A16B16G16R16F:
return 8 * width;
case D3DFMT_A32B32G32R32F:
return 16 * width;
case D3DFMT_DXT1:
return 8 * ((width + 3) / 4);
case D3DFMT_DXT3:
case D3DFMT_DXT5:
return 16 * ((width + 3) / 4);
default:
UNREACHABLE();
return 0;
}
}
}
std::string getTempPath()
{
char path[MAX_PATH];
......
......@@ -78,13 +78,13 @@ D3DMULTISAMPLE_TYPE GetMultisampleTypeFromSamples(GLsizei samples);
namespace dx2es
{
GLuint GetAlphaSize(D3DFORMAT colorFormat);
GLuint GetRedSize(D3DFORMAT colorFormat);
GLuint GetGreenSize(D3DFORMAT colorFormat);
GLuint GetBlueSize(D3DFORMAT colorFormat);
GLuint GetDepthSize(D3DFORMAT depthFormat);
GLuint GetStencilSize(D3DFORMAT stencilFormat);
bool IsCompressedD3DFormat(D3DFORMAT format);
GLsizei GetSamplesFromMultisampleType(D3DMULTISAMPLE_TYPE type);
......@@ -95,6 +95,12 @@ GLenum ConvertDepthStencilFormat(D3DFORMAT format);
}
namespace dx
{
bool IsCompressedFormat(D3DFORMAT format);
size_t ComputeRowSize(D3DFORMAT format, unsigned int width);
}
std::string getTempPath();
void writeFile(const char* path, const void* data, size_t size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment