Encapsulate image surface creation.

TRAC #18714 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@829 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 4c0a7715
...@@ -100,6 +100,7 @@ void Image::createSurface() ...@@ -100,6 +100,7 @@ void Image::createSurface()
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
ERR("Creating image surface failed.");
return error(GL_OUT_OF_MEMORY); return error(GL_OUT_OF_MEMORY);
} }
...@@ -202,6 +203,13 @@ D3DFORMAT Image::getD3DFormat() const ...@@ -202,6 +203,13 @@ D3DFORMAT Image::getD3DFormat() const
return D3DFMT_A8R8G8B8; return D3DFMT_A8R8G8B8;
} }
IDirect3DSurface9 *Image::getSurface()
{
createSurface();
return mSurface;
}
Texture::Texture(GLuint id) : RefCountObject(id), mSerial(issueSerial()) Texture::Texture(GLuint id) : RefCountObject(id), mSerial(issueSerial())
{ {
mMinFilter = GL_NEAREST_MIPMAP_LINEAR; mMinFilter = GL_NEAREST_MIPMAP_LINEAR;
...@@ -1146,18 +1154,16 @@ void Texture::loadDXT5ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLs ...@@ -1146,18 +1154,16 @@ void Texture::loadDXT5ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLs
void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image) void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image)
{ {
image->createSurface(); if (pixels != NULL)
if (pixels != NULL && image->getSurface() != NULL)
{ {
D3DSURFACE_DESC description;
image->getSurface()->GetDesc(&description);
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
HRESULT result = image->lock(&locked, NULL); HRESULT result = image->lock(&locked, NULL);
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
D3DSURFACE_DESC description;
image->getSurface()->GetDesc(&description);
loadImageData(0, 0, image->getWidth(), image->getHeight(), image->getFormat(), image->getType(), unpackAlignment, pixels, locked.Pitch, locked.pBits, &description); loadImageData(0, 0, image->getWidth(), image->getHeight(), image->getFormat(), image->getType(), unpackAlignment, pixels, locked.Pitch, locked.pBits, &description);
image->unlock(); image->unlock();
} }
...@@ -1169,9 +1175,7 @@ void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image) ...@@ -1169,9 +1175,7 @@ void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image)
void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, Image *image) void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, Image *image)
{ {
image->createSurface(); if (pixels != NULL)
if (pixels != NULL && image->getSurface() != NULL)
{ {
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
HRESULT result = image->lock(&locked, NULL); HRESULT result = image->lock(&locked, NULL);
...@@ -1209,18 +1213,16 @@ bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heig ...@@ -1209,18 +1213,16 @@ bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heig
return false; return false;
} }
image->createSurface(); if (pixels != NULL)
if (pixels != NULL && image->getSurface() != NULL)
{ {
D3DSURFACE_DESC description;
image->getSurface()->GetDesc(&description);
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
HRESULT result = image->lock(&locked, NULL); HRESULT result = image->lock(&locked, NULL);
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
D3DSURFACE_DESC description;
image->getSurface()->GetDesc(&description);
loadImageData(xoffset, transformPixelYOffset(yoffset, height, image->getHeight()), width, height, format, type, unpackAlignment, pixels, locked.Pitch, locked.pBits, &description); loadImageData(xoffset, transformPixelYOffset(yoffset, height, image->getHeight()), width, height, format, type, unpackAlignment, pixels, locked.Pitch, locked.pBits, &description);
image->unlock(); image->unlock();
} }
...@@ -1275,14 +1277,6 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL ...@@ -1275,14 +1277,6 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
// This implements glCopyTex[Sub]Image2D for non-renderable internal texture formats and incomplete textures // This implements glCopyTex[Sub]Image2D for non-renderable internal texture formats and incomplete textures
void Texture::copyToImage(Image *image, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, IDirect3DSurface9 *renderTarget) void Texture::copyToImage(Image *image, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, IDirect3DSurface9 *renderTarget)
{ {
image->createSurface();
if (!image->getSurface())
{
ERR("Failed to create an image surface.");
return error(GL_OUT_OF_MEMORY);
}
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
IDirect3DSurface9 *renderTargetData = NULL; IDirect3DSurface9 *renderTargetData = NULL;
D3DSURFACE_DESC description; D3DSURFACE_DESC description;
...@@ -2061,8 +2055,6 @@ void Texture2D::generateMipmaps() ...@@ -2061,8 +2055,6 @@ void Texture2D::generateMipmaps()
{ {
for (unsigned int i = 1; i <= q; i++) for (unsigned int i = 1; i <= q; i++)
{ {
mImageArray[i].createSurface();
if (mImageArray[i].getSurface() == NULL) if (mImageArray[i].getSurface() == NULL)
{ {
return error(GL_OUT_OF_MEMORY); return error(GL_OUT_OF_MEMORY);
...@@ -2713,7 +2705,6 @@ void TextureCubeMap::generateMipmaps() ...@@ -2713,7 +2705,6 @@ void TextureCubeMap::generateMipmaps()
{ {
for (unsigned int i = 1; i <= q; i++) for (unsigned int i = 1; i <= q; i++)
{ {
mImageArray[f][i].createSurface();
if (mImageArray[f][i].getSurface() == NULL) if (mImageArray[f][i].getSurface() == NULL)
{ {
return error(GL_OUT_OF_MEMORY); return error(GL_OUT_OF_MEMORY);
......
...@@ -50,7 +50,6 @@ class Image ...@@ -50,7 +50,6 @@ class Image
~Image(); ~Image();
void redefine(GLenum format, GLsizei width, GLsizei height, GLenum type); void redefine(GLenum format, GLsizei width, GLsizei height, GLenum type);
void createSurface();
void markDirty() {mDirty = true;} void markDirty() {mDirty = true;}
void markClean() {mDirty = false;} void markClean() {mDirty = false;}
...@@ -65,11 +64,13 @@ class Image ...@@ -65,11 +64,13 @@ class Image
GLenum getFormat() const {return mFormat;} GLenum getFormat() const {return mFormat;}
GLenum getType() const {return mType;} GLenum getType() const {return mType;}
bool isDirty() const {return mSurface && mDirty;} bool isDirty() const {return mSurface && mDirty;}
IDirect3DSurface9 *getSurface() {return mSurface;} IDirect3DSurface9 *getSurface();
private: private:
DISALLOW_COPY_AND_ASSIGN(Image); DISALLOW_COPY_AND_ASSIGN(Image);
void createSurface();
GLsizei mWidth; GLsizei mWidth;
GLsizei mHeight; GLsizei mHeight;
GLenum mFormat; GLenum mFormat;
......
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