Ensure that a surface is present before writing to it

TRAC #13595 This fixes a bug where glTexSubImage is called on a mipmapped texture before calling glTexImage. Signed-off-by: Daniel Koch git-svn-id: https://angleproject.googlecode.com/svn/trunk@434 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent ecd7cf35
...@@ -777,18 +777,27 @@ bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heig ...@@ -777,18 +777,27 @@ bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heig
return false; return false;
} }
D3DLOCKED_RECT locked; if (!img->surface)
HRESULT result = img->surface->LockRect(&locked, NULL, 0); {
createSurface(img->width, img->height, format, type, img);
ASSERT(SUCCEEDED(result)); }
if (SUCCEEDED(result)) if (pixels != NULL && img->surface != NULL)
{ {
loadImageData(xoffset, yoffset, width, height, format, type, unpackAlignment, pixels, locked.Pitch, locked.pBits); D3DLOCKED_RECT locked;
img->surface->UnlockRect(); HRESULT result = img->surface->LockRect(&locked, NULL, 0);
ASSERT(SUCCEEDED(result));
if (SUCCEEDED(result))
{
loadImageData(xoffset, yoffset, width, height, format, type, unpackAlignment, pixels, locked.Pitch, locked.pBits);
img->surface->UnlockRect();
}
img->dirty = true;
} }
img->dirty = true;
return true; return true;
} }
...@@ -806,29 +815,38 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL ...@@ -806,29 +815,38 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
return false; return false;
} }
RECT updateRegion; if (!img->surface)
updateRegion.left = xoffset; {
updateRegion.right = xoffset + width; createSurface(img->width, img->height, format, GL_UNSIGNED_BYTE, img);
updateRegion.bottom = yoffset + height; }
updateRegion.top = yoffset;
D3DLOCKED_RECT locked; if (pixels != NULL && img->surface != NULL)
HRESULT result = img->surface->LockRect(&locked, &updateRegion, 0); {
RECT updateRegion;
updateRegion.left = xoffset;
updateRegion.right = xoffset + width;
updateRegion.bottom = yoffset + height;
updateRegion.top = yoffset;
ASSERT(SUCCEEDED(result)); D3DLOCKED_RECT locked;
HRESULT result = img->surface->LockRect(&locked, &updateRegion, 0);
if (SUCCEEDED(result)) ASSERT(SUCCEEDED(result));
{
GLsizei inputPitch = ComputeCompressedPitch(width, format); if (SUCCEEDED(result))
int rows = imageSize / inputPitch;
for (int i = 0; i < rows; ++i)
{ {
memcpy((void*)((BYTE*)locked.pBits + i * locked.Pitch), (void*)((BYTE*)pixels + i * inputPitch), inputPitch); GLsizei inputPitch = ComputeCompressedPitch(width, format);
int rows = imageSize / inputPitch;
for (int i = 0; i < rows; ++i)
{
memcpy((void*)((BYTE*)locked.pBits + i * locked.Pitch), (void*)((BYTE*)pixels + i * inputPitch), inputPitch);
}
img->surface->UnlockRect();
} }
img->surface->UnlockRect();
img->dirty = true;
} }
img->dirty = true;
return true; return true;
} }
......
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