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
return false;
}
D3DLOCKED_RECT locked;
HRESULT result = img->surface->LockRect(&locked, NULL, 0);
ASSERT(SUCCEEDED(result));
if (!img->surface)
{
createSurface(img->width, img->height, format, type, img);
}
if (SUCCEEDED(result))
if (pixels != NULL && img->surface != NULL)
{
loadImageData(xoffset, yoffset, width, height, format, type, unpackAlignment, pixels, locked.Pitch, locked.pBits);
img->surface->UnlockRect();
D3DLOCKED_RECT locked;
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;
}
......@@ -806,29 +815,38 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
return false;
}
RECT updateRegion;
updateRegion.left = xoffset;
updateRegion.right = xoffset + width;
updateRegion.bottom = yoffset + height;
updateRegion.top = yoffset;
if (!img->surface)
{
createSurface(img->width, img->height, format, GL_UNSIGNED_BYTE, img);
}
D3DLOCKED_RECT locked;
HRESULT result = img->surface->LockRect(&locked, &updateRegion, 0);
if (pixels != NULL && img->surface != NULL)
{
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))
{
GLsizei inputPitch = ComputeCompressedPitch(width, format);
int rows = imageSize / inputPitch;
for (int i = 0; i < rows; ++i)
ASSERT(SUCCEEDED(result));
if (SUCCEEDED(result))
{
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;
}
......
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