Moved createSurface() to Image.

TRAC #18714 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@821 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 9ab8e3e0
...@@ -1050,9 +1050,9 @@ void Texture::loadDXT5ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLs ...@@ -1050,9 +1050,9 @@ void Texture::loadDXT5ImageData(GLint xoffset, GLint yoffset, GLsizei width, GLs
} }
} }
void Texture::createSurface(Image *image) void Texture::Image::createSurface()
{ {
if(image->surface) if(surface)
{ {
return; return;
} }
...@@ -1060,12 +1060,12 @@ void Texture::createSurface(Image *image) ...@@ -1060,12 +1060,12 @@ void Texture::createSurface(Image *image)
IDirect3DTexture9 *newTexture = NULL; IDirect3DTexture9 *newTexture = NULL;
IDirect3DSurface9 *newSurface = NULL; IDirect3DSurface9 *newSurface = NULL;
if (image->width != 0 && image->height != 0) if (width != 0 && height != 0)
{ {
int levelToFetch = 0; int levelToFetch = 0;
GLsizei requestWidth = image->width; GLsizei requestWidth = width;
GLsizei requestHeight = image->height; GLsizei requestHeight = height;
if (IsCompressed(image->format) && (image->width % 4 != 0 || image->height % 4 != 0)) if (IsCompressed(format) && (width % 4 != 0 || height % 4 != 0))
{ {
bool isMult4 = false; bool isMult4 = false;
int upsampleCount = 0; int upsampleCount = 0;
...@@ -1082,7 +1082,7 @@ void Texture::createSurface(Image *image) ...@@ -1082,7 +1082,7 @@ void Texture::createSurface(Image *image)
levelToFetch = upsampleCount; levelToFetch = upsampleCount;
} }
HRESULT result = getDevice()->CreateTexture(requestWidth, requestHeight, levelToFetch + 1, NULL, image->getD3DFormat(), HRESULT result = getDevice()->CreateTexture(requestWidth, requestHeight, levelToFetch + 1, NULL, getD3DFormat(),
D3DPOOL_SYSTEMMEM, &newTexture, NULL); D3DPOOL_SYSTEMMEM, &newTexture, NULL);
if (FAILED(result)) if (FAILED(result))
...@@ -1095,12 +1095,12 @@ void Texture::createSurface(Image *image) ...@@ -1095,12 +1095,12 @@ void Texture::createSurface(Image *image)
newTexture->Release(); newTexture->Release();
} }
image->surface = newSurface; surface = newSurface;
} }
void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image) void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image)
{ {
createSurface(image); image->createSurface();
if (pixels != NULL && image->surface != NULL) if (pixels != NULL && image->surface != NULL)
{ {
...@@ -1125,7 +1125,7 @@ void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image) ...@@ -1125,7 +1125,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)
{ {
createSurface(image); image->createSurface();
if (pixels != NULL && image->surface != NULL) if (pixels != NULL && image->surface != NULL)
{ {
...@@ -1167,10 +1167,7 @@ bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heig ...@@ -1167,10 +1167,7 @@ bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heig
return false; return false;
} }
if (!image->surface) image->createSurface();
{
createSurface(image);
}
if (pixels != NULL && image->surface != NULL) if (pixels != NULL && image->surface != NULL)
{ {
...@@ -1209,10 +1206,7 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL ...@@ -1209,10 +1206,7 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
return false; return false;
} }
if (!image->surface) image->createSurface();
{
createSurface(image);
}
if (pixels != NULL && image->surface != NULL) if (pixels != NULL && image->surface != NULL)
{ {
...@@ -1245,15 +1239,12 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL ...@@ -1245,15 +1239,12 @@ 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->surface) if (!image->surface)
{ {
createSurface(image); ERR("Failed to create an image surface.");
return error(GL_OUT_OF_MEMORY);
if (!image->surface)
{
ERR("Failed to create an image surface.");
return error(GL_OUT_OF_MEMORY);
}
} }
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
...@@ -1563,7 +1554,7 @@ void Texture2D::redefineTexture(GLint level, GLenum format, GLsizei width, GLsiz ...@@ -1563,7 +1554,7 @@ void Texture2D::redefineTexture(GLint level, GLenum format, GLsizei width, GLsiz
mImageArray[level].dirty = true; mImageArray[level].dirty = true;
} }
createSurface(&mImageArray[level]); mImageArray[level].createSurface();
if (!mTexture) if (!mTexture)
{ {
...@@ -2057,7 +2048,7 @@ void Texture2D::generateMipmaps() ...@@ -2057,7 +2048,7 @@ void Texture2D::generateMipmaps()
{ {
for (unsigned int i = 1; i <= q; i++) for (unsigned int i = 1; i <= q; i++)
{ {
createSurface(&mImageArray[i]); mImageArray[i].createSurface();
if (mImageArray[i].surface == NULL) if (mImageArray[i].surface == NULL)
{ {
...@@ -2504,7 +2495,7 @@ void TextureCubeMap::redefineTexture(int face, GLint level, GLenum format, GLsiz ...@@ -2504,7 +2495,7 @@ void TextureCubeMap::redefineTexture(int face, GLint level, GLenum format, GLsiz
mImageArray[face][level].dirty = true; mImageArray[face][level].dirty = true;
} }
createSurface(&mImageArray[face][level]); mImageArray[face][level].createSurface();
if (!mTexture) if (!mTexture)
{ {
...@@ -2731,7 +2722,7 @@ void TextureCubeMap::generateMipmaps() ...@@ -2731,7 +2722,7 @@ void TextureCubeMap::generateMipmaps()
{ {
for (unsigned int i = 1; i <= q; i++) for (unsigned int i = 1; i <= q; i++)
{ {
createSurface(&mImageArray[f][i]); mImageArray[f][i].createSurface();
if (mImageArray[f][i].surface == NULL) if (mImageArray[f][i].surface == NULL)
{ {
return error(GL_OUT_OF_MEMORY); return error(GL_OUT_OF_MEMORY);
......
...@@ -93,6 +93,8 @@ class Texture : public RefCountObject ...@@ -93,6 +93,8 @@ class Texture : public RefCountObject
Image(); Image();
~Image(); ~Image();
void createSurface();
bool isRenderable() const; bool isRenderable() const;
D3DFORMAT getD3DFormat() const; D3DFORMAT getD3DFormat() const;
...@@ -121,8 +123,6 @@ class Texture : public RefCountObject ...@@ -121,8 +123,6 @@ class Texture : public RefCountObject
virtual void convertToRenderTarget() = 0; virtual void convertToRenderTarget() = 0;
virtual IDirect3DSurface9 *getRenderTarget(GLenum target) = 0; virtual IDirect3DSurface9 *getRenderTarget(GLenum target) = 0;
void createSurface(Image *image);
Blit *getBlitter(); Blit *getBlitter();
int levelCount() const; int levelCount() const;
......
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