Creating a 0x0 texture fails.

TRAC #11792 Signed-off-by: Nicolas Capens Signed-off-by: Daniel Koch Author: Andrew Lewycky git-svn-id: https://angleproject.googlecode.com/svn/trunk@150 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent aa1ff879
...@@ -294,6 +294,9 @@ void Texture::loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei ...@@ -294,6 +294,9 @@ void Texture::loadImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei
void Texture::setImage(GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, Image *img) void Texture::setImage(GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, Image *img)
{ {
IDirect3DSurface9 *newSurface = NULL; IDirect3DSurface9 *newSurface = NULL;
if (width != 0 && height != 0)
{
HRESULT result = getDevice()->CreateOffscreenPlainSurface(width, height, selectFormat(format), D3DPOOL_SYSTEMMEM, &newSurface, NULL); HRESULT result = getDevice()->CreateOffscreenPlainSurface(width, height, selectFormat(format), D3DPOOL_SYSTEMMEM, &newSurface, NULL);
if (FAILED(result)) if (FAILED(result))
...@@ -301,6 +304,7 @@ void Texture::setImage(GLsizei width, GLsizei height, GLenum format, GLenum type ...@@ -301,6 +304,7 @@ void Texture::setImage(GLsizei width, GLsizei height, GLenum format, GLenum type
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY); return error(GL_OUT_OF_MEMORY);
} }
}
if (img->surface) img->surface->Release(); if (img->surface) img->surface->Release();
img->surface = newSurface; img->surface = newSurface;
...@@ -309,7 +313,7 @@ void Texture::setImage(GLsizei width, GLsizei height, GLenum format, GLenum type ...@@ -309,7 +313,7 @@ void Texture::setImage(GLsizei width, GLsizei height, GLenum format, GLenum type
img->height = height; img->height = height;
img->format = format; img->format = format;
if (pixels != NULL) if (pixels != NULL && newSurface != NULL)
{ {
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
HRESULT result = newSurface->LockRect(&locked, NULL, 0); HRESULT result = newSurface->LockRect(&locked, NULL, 0);
...@@ -541,6 +545,8 @@ void Texture2D::copyImage(GLint level, GLenum internalFormat, GLint x, GLint y, ...@@ -541,6 +545,8 @@ void Texture2D::copyImage(GLint level, GLenum internalFormat, GLint x, GLint y,
pushTexture(mTexture); pushTexture(mTexture);
} }
if (width != 0 && height != 0)
{
RECT sourceRect; RECT sourceRect;
sourceRect.left = x; sourceRect.left = x;
sourceRect.top = y + height; sourceRect.top = y + height;
...@@ -552,6 +558,7 @@ void Texture2D::copyImage(GLint level, GLenum internalFormat, GLint x, GLint y, ...@@ -552,6 +558,7 @@ void Texture2D::copyImage(GLint level, GLenum internalFormat, GLint x, GLint y,
getBlitter()->formatConvert(source->getRenderTarget(), sourceRect, internalFormat, 0, 0, dest); getBlitter()->formatConvert(source->getRenderTarget(), sourceRect, internalFormat, 0, 0, dest);
dest->Release(); dest->Release();
}
mImageArray[level].width = width; mImageArray[level].width = width;
mImageArray[level].height = height; mImageArray[level].height = height;
...@@ -560,6 +567,11 @@ void Texture2D::copyImage(GLint level, GLenum internalFormat, GLint x, GLint y, ...@@ -560,6 +567,11 @@ void Texture2D::copyImage(GLint level, GLenum internalFormat, GLint x, GLint y,
void Texture2D::copySubImage(GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source) void Texture2D::copySubImage(GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source)
{ {
if (xoffset + width > mImageArray[level].width || yoffset + height > mImageArray[level].height)
{
return error(GL_INVALID_VALUE);
}
if (redefineTexture(0, mImageArray[0].format, mImageArray[0].width, mImageArray[0].height)) if (redefineTexture(0, mImageArray[0].format, mImageArray[0].width, mImageArray[0].height))
{ {
convertToRenderTarget(); convertToRenderTarget();
...@@ -687,8 +699,10 @@ void Texture2D::updateTexture() ...@@ -687,8 +699,10 @@ void Texture2D::updateTexture()
IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget() IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
{ {
IDirect3DTexture9 *texture; IDirect3DTexture9 *texture = NULL;
if (mWidth != 0 && mHeight != 0)
{
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DFORMAT format = selectFormat(mImageArray[0].format); D3DFORMAT format = selectFormat(mImageArray[0].format);
...@@ -746,7 +760,11 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget() ...@@ -746,7 +760,11 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
source->Release(); source->Release();
dest->Release(); dest->Release();
} }
}
}
if (mTexture != NULL)
{
mTexture->Release(); mTexture->Release();
} }
...@@ -983,8 +1001,10 @@ void TextureCubeMap::updateTexture() ...@@ -983,8 +1001,10 @@ void TextureCubeMap::updateTexture()
IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget() IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
{ {
IDirect3DCubeTexture9 *texture; IDirect3DCubeTexture9 *texture = NULL;
if (mWidth != 0)
{
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DFORMAT format = selectFormat(mImageArray[0][0].format); D3DFORMAT format = selectFormat(mImageArray[0][0].format);
...@@ -1042,7 +1062,11 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget() ...@@ -1042,7 +1062,11 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
} }
} }
} }
}
}
if (mTexture != NULL)
{
mTexture->Release(); mTexture->Release();
} }
...@@ -1154,6 +1178,10 @@ void TextureCubeMap::copyImage(GLenum face, GLint level, GLenum internalFormat, ...@@ -1154,6 +1178,10 @@ void TextureCubeMap::copyImage(GLenum face, GLint level, GLenum internalFormat,
pushTexture(mTexture); pushTexture(mTexture);
} }
ASSERT(width == height);
if (width > 0)
{
RECT sourceRect; RECT sourceRect;
sourceRect.left = x; sourceRect.left = x;
sourceRect.top = y + height; sourceRect.top = y + height;
...@@ -1164,6 +1192,7 @@ void TextureCubeMap::copyImage(GLenum face, GLint level, GLenum internalFormat, ...@@ -1164,6 +1192,7 @@ void TextureCubeMap::copyImage(GLenum face, GLint level, GLenum internalFormat,
getBlitter()->formatConvert(source->getRenderTarget(), sourceRect, internalFormat, 0, 0, dest); getBlitter()->formatConvert(source->getRenderTarget(), sourceRect, internalFormat, 0, 0, dest);
dest->Release(); dest->Release();
}
mImageArray[faceindex][level].width = width; mImageArray[faceindex][level].width = width;
mImageArray[faceindex][level].height = height; mImageArray[faceindex][level].height = height;
...@@ -1203,6 +1232,13 @@ IDirect3DSurface9 *TextureCubeMap::getCubeMapSurface(unsigned int faceIdentifier ...@@ -1203,6 +1232,13 @@ IDirect3DSurface9 *TextureCubeMap::getCubeMapSurface(unsigned int faceIdentifier
void TextureCubeMap::copySubImage(GLenum face, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source) void TextureCubeMap::copySubImage(GLenum face, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Renderbuffer *source)
{ {
GLsizei size = mImageArray[faceIndex(face)][level].width;
if (xoffset + width > size || yoffset + height > size)
{
return error(GL_INVALID_VALUE);
}
if (redefineTexture(0, mImageArray[0][0].format, mImageArray[0][0].width)) if (redefineTexture(0, mImageArray[0][0].format, mImageArray[0][0].width))
{ {
convertToRenderTarget(); convertToRenderTarget();
......
...@@ -822,7 +822,7 @@ void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalforma ...@@ -822,7 +822,7 @@ void __stdcall glCopyTexImage2D(GLenum target, GLint level, GLenum internalforma
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
if (!gl::isPow2(width) || !gl::isPow2(height)) if (width != height)
{ {
return error(GL_INVALID_VALUE); return error(GL_INVALID_VALUE);
} }
...@@ -3506,7 +3506,7 @@ void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GL ...@@ -3506,7 +3506,7 @@ void __stdcall glTexImage2D(GLenum target, GLint level, GLint internalformat, GL
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
if (!gl::isPow2(width) || !gl::isPow2(height)) if (width != height)
{ {
return error(GL_INVALID_VALUE); return error(GL_INVALID_VALUE);
} }
......
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