Added depth parameters to all image loading functions.

TRAC #22705 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2159 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 8dce651e
...@@ -2031,7 +2031,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, ...@@ -2031,7 +2031,7 @@ void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height,
return gl::error(GL_INVALID_OPERATION); return gl::error(GL_INVALID_OPERATION);
} }
GLsizei outputPitch = ComputePitch(width, ConvertSizedInternalFormat(format, type), getPackAlignment()); GLsizei outputPitch = ComputeRowPitch(width, ConvertSizedInternalFormat(format, type), getPackAlignment());
// sized query sanity check // sized query sanity check
if (bufSize) if (bufSize)
{ {
......
...@@ -198,7 +198,7 @@ void Texture::setImage(GLint unpackAlignment, const void *pixels, rx::Image *ima ...@@ -198,7 +198,7 @@ void Texture::setImage(GLint unpackAlignment, const void *pixels, rx::Image *ima
{ {
if (pixels != NULL) if (pixels != NULL)
{ {
image->loadData(0, 0, image->getWidth(), image->getHeight(), unpackAlignment, pixels); image->loadData(0, 0, 0, image->getWidth(), image->getHeight(), image->getDepth(), unpackAlignment, pixels);
mDirtyImages = true; mDirtyImages = true;
} }
} }
...@@ -207,27 +207,29 @@ void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, rx::Imag ...@@ -207,27 +207,29 @@ void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, rx::Imag
{ {
if (pixels != NULL) if (pixels != NULL)
{ {
image->loadCompressedData(0, 0, image->getWidth(), image->getHeight(), pixels); image->loadCompressedData(0, 0, 0, image->getWidth(), image->getHeight(), image->getDepth(), pixels);
mDirtyImages = true; mDirtyImages = true;
} }
} }
bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, rx::Image *image) bool Texture::subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, rx::Image *image)
{ {
if (pixels != NULL) if (pixels != NULL)
{ {
image->loadData(xoffset, yoffset, width, height, unpackAlignment, pixels); image->loadData(xoffset, yoffset, zoffset, width, height, depth, unpackAlignment, pixels);
mDirtyImages = true; mDirtyImages = true;
} }
return true; return true;
} }
bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, rx::Image *image) bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLsizei imageSize, const void *pixels, rx::Image *image)
{ {
if (pixels != NULL) if (pixels != NULL)
{ {
image->loadCompressedData(xoffset, yoffset, width, height, pixels); image->loadCompressedData(xoffset, yoffset, zoffset, width, height, depth, pixels);
mDirtyImages = true; mDirtyImages = true;
} }
...@@ -387,7 +389,7 @@ void Texture2D::redefineImage(GLint level, GLint internalformat, GLsizei width, ...@@ -387,7 +389,7 @@ void Texture2D::redefineImage(GLint level, GLint internalformat, GLsizei width,
const int storageHeight = std::max(1, mImageArray[0]->getHeight() >> level); const int storageHeight = std::max(1, mImageArray[0]->getHeight() >> level);
const int storageFormat = mImageArray[0]->getInternalFormat(); const int storageFormat = mImageArray[0]->getInternalFormat();
mImageArray[level]->redefine(mRenderer, internalformat, width, height, false); mImageArray[level]->redefine(mRenderer, internalformat, width, height, 1, false);
if (mTexStorage) if (mTexStorage)
{ {
...@@ -424,7 +426,7 @@ void Texture2D::bindTexImage(egl::Surface *surface) ...@@ -424,7 +426,7 @@ void Texture2D::bindTexImage(egl::Surface *surface)
GLint internalformat = surface->getFormat(); GLint internalformat = surface->getFormat();
mImageArray[0]->redefine(mRenderer, internalformat, surface->getWidth(), surface->getHeight(), true); mImageArray[0]->redefine(mRenderer, internalformat, surface->getWidth(), surface->getHeight(), 1, true);
delete mTexStorage; delete mTexStorage;
mTexStorage = new rx::TextureStorageInterface2D(mRenderer, surface->getSwapChain()); mTexStorage = new rx::TextureStorageInterface2D(mRenderer, surface->getSwapChain());
...@@ -449,7 +451,7 @@ void Texture2D::releaseTexImage() ...@@ -449,7 +451,7 @@ void Texture2D::releaseTexImage()
for (int i = 0; i < IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++) for (int i = 0; i < IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
{ {
mImageArray[i]->redefine(mRenderer, GL_NONE, 0, 0, true); mImageArray[i]->redefine(mRenderer, GL_NONE, 0, 0, 0, true);
} }
} }
} }
...@@ -476,7 +478,7 @@ void Texture2D::commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei wi ...@@ -476,7 +478,7 @@ void Texture2D::commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei wi
void Texture2D::subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels) void Texture2D::subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels)
{ {
if (Texture::subImage(xoffset, yoffset, width, height, format, type, unpackAlignment, pixels, mImageArray[level])) if (Texture::subImage(xoffset, yoffset, 0, width, height, 1, format, type, unpackAlignment, pixels, mImageArray[level]))
{ {
commitRect(level, xoffset, yoffset, width, height); commitRect(level, xoffset, yoffset, width, height);
} }
...@@ -484,7 +486,7 @@ void Texture2D::subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei widt ...@@ -484,7 +486,7 @@ void Texture2D::subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei widt
void Texture2D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels) void Texture2D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels)
{ {
if (Texture::subImageCompressed(xoffset, yoffset, width, height, format, imageSize, pixels, mImageArray[level])) if (Texture::subImageCompressed(xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels, mImageArray[level]))
{ {
commitRect(level, xoffset, yoffset, width, height); commitRect(level, xoffset, yoffset, width, height);
} }
...@@ -566,14 +568,14 @@ void Texture2D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GL ...@@ -566,14 +568,14 @@ void Texture2D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GL
for (int level = 0; level < levels; level++) for (int level = 0; level < levels; level++)
{ {
mImageArray[level]->redefine(mRenderer, internalformat, width, height, true); mImageArray[level]->redefine(mRenderer, internalformat, width, height, 1, true);
width = std::max(1, width >> 1); width = std::max(1, width >> 1);
height = std::max(1, height >> 1); height = std::max(1, height >> 1);
} }
for (int level = levels; level < IMPLEMENTATION_MAX_TEXTURE_LEVELS; level++) for (int level = levels; level < IMPLEMENTATION_MAX_TEXTURE_LEVELS; level++)
{ {
mImageArray[level]->redefine(mRenderer, GL_NONE, 0, 0, true); mImageArray[level]->redefine(mRenderer, GL_NONE, 0, 0, 0, true);
} }
if (mTexStorage->isManaged()) if (mTexStorage->isManaged())
...@@ -1026,7 +1028,7 @@ void TextureCubeMap::commitRect(int face, GLint level, GLint xoffset, GLint yoff ...@@ -1026,7 +1028,7 @@ void TextureCubeMap::commitRect(int face, GLint level, GLint xoffset, GLint yoff
void TextureCubeMap::subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels) void TextureCubeMap::subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels)
{ {
if (Texture::subImage(xoffset, yoffset, width, height, format, type, unpackAlignment, pixels, mImageArray[faceIndex(target)][level])) if (Texture::subImage(xoffset, yoffset, 0, width, height, 1, format, type, unpackAlignment, pixels, mImageArray[faceIndex(target)][level]))
{ {
commitRect(faceIndex(target), level, xoffset, yoffset, width, height); commitRect(faceIndex(target), level, xoffset, yoffset, width, height);
} }
...@@ -1034,7 +1036,7 @@ void TextureCubeMap::subImage(GLenum target, GLint level, GLint xoffset, GLint y ...@@ -1034,7 +1036,7 @@ void TextureCubeMap::subImage(GLenum target, GLint level, GLint xoffset, GLint y
void TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels) void TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels)
{ {
if (Texture::subImageCompressed(xoffset, yoffset, width, height, format, imageSize, pixels, mImageArray[faceIndex(target)][level])) if (Texture::subImageCompressed(xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels, mImageArray[faceIndex(target)][level]))
{ {
commitRect(faceIndex(target), level, xoffset, yoffset, width, height); commitRect(faceIndex(target), level, xoffset, yoffset, width, height);
} }
...@@ -1249,7 +1251,7 @@ void TextureCubeMap::redefineImage(int face, GLint level, GLint internalformat, ...@@ -1249,7 +1251,7 @@ void TextureCubeMap::redefineImage(int face, GLint level, GLint internalformat,
const int storageHeight = std::max(1, mImageArray[0][0]->getHeight() >> level); const int storageHeight = std::max(1, mImageArray[0][0]->getHeight() >> level);
const int storageFormat = mImageArray[0][0]->getInternalFormat(); const int storageFormat = mImageArray[0][0]->getInternalFormat();
mImageArray[face][level]->redefine(mRenderer, internalformat, width, height, false); mImageArray[face][level]->redefine(mRenderer, internalformat, width, height, 1, false);
if (mTexStorage) if (mTexStorage)
{ {
...@@ -1360,7 +1362,7 @@ void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size ...@@ -1360,7 +1362,7 @@ void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size
{ {
for (int face = 0; face < 6; face++) for (int face = 0; face < 6; face++)
{ {
mImageArray[face][level]->redefine(mRenderer, internalformat, size, size, true); mImageArray[face][level]->redefine(mRenderer, internalformat, size, size, 1, true);
size = std::max(1, size >> 1); size = std::max(1, size >> 1);
} }
} }
...@@ -1369,7 +1371,7 @@ void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size ...@@ -1369,7 +1371,7 @@ void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size
{ {
for (int face = 0; face < 6; face++) for (int face = 0; face < 6; face++)
{ {
mImageArray[face][level]->redefine(mRenderer, GL_NONE, 0, 0, true); mImageArray[face][level]->redefine(mRenderer, GL_NONE, 0, 0, 0, true);
} }
} }
......
...@@ -101,9 +101,11 @@ class Texture : public RefCountObject ...@@ -101,9 +101,11 @@ class Texture : public RefCountObject
protected: protected:
void setImage(GLint unpackAlignment, const void *pixels, rx::Image *image); void setImage(GLint unpackAlignment, const void *pixels, rx::Image *image);
bool subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, rx::Image *image); bool subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, rx::Image *image);
void setCompressedImage(GLsizei imageSize, const void *pixels, rx::Image *image); void setCompressedImage(GLsizei imageSize, const void *pixels, rx::Image *image);
bool subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, rx::Image *image); bool subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLsizei imageSize, const void *pixels, rx::Image *image);
GLint creationLevels(GLsizei width, GLsizei height) const; GLint creationLevels(GLsizei width, GLsizei height) const;
GLint creationLevels(GLsizei size) const; GLint creationLevels(GLsizei size) const;
......
...@@ -41,14 +41,14 @@ class Image11 : public Image ...@@ -41,14 +41,14 @@ class Image11 : public Image
virtual bool updateSurface(TextureStorageInterface2D *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height); virtual bool updateSurface(TextureStorageInterface2D *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
virtual bool updateSurface(TextureStorageInterfaceCube *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height); virtual bool updateSurface(TextureStorageInterfaceCube *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
virtual bool redefine(Renderer *renderer, GLint internalformat, GLsizei width, GLsizei height, bool forceRelease); virtual bool redefine(Renderer *renderer, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease);
virtual bool isRenderableFormat() const; virtual bool isRenderableFormat() const;
DXGI_FORMAT getDXGIFormat() const; DXGI_FORMAT getDXGIFormat() const;
virtual void loadData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLint unpackAlignment, const void *input); GLint unpackAlignment, const void *input);
virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
const void *input); const void *input);
virtual void copy(GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source); virtual void copy(GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
......
...@@ -141,10 +141,14 @@ void Image9::copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *so ...@@ -141,10 +141,14 @@ void Image9::copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *so
else UNREACHABLE(); else UNREACHABLE();
} }
bool Image9::redefine(rx::Renderer *renderer, GLint internalformat, GLsizei width, GLsizei height, bool forceRelease) bool Image9::redefine(rx::Renderer *renderer, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease)
{ {
// 3D textures are not supported by the D3D9 backend.
ASSERT(depth <= 1);
if (mWidth != width || if (mWidth != width ||
mHeight != height || mHeight != height ||
mDepth != depth ||
mInternalFormat != internalformat || mInternalFormat != internalformat ||
forceRelease) forceRelease)
{ {
...@@ -152,6 +156,7 @@ bool Image9::redefine(rx::Renderer *renderer, GLint internalformat, GLsizei widt ...@@ -152,6 +156,7 @@ bool Image9::redefine(rx::Renderer *renderer, GLint internalformat, GLsizei widt
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;
mDepth = depth;
mInternalFormat = internalformat; mInternalFormat = internalformat;
// compute the d3d format that will be used // compute the d3d format that will be used
mD3DFormat = mRenderer->ConvertTextureInternalFormat(internalformat); mD3DFormat = mRenderer->ConvertTextureInternalFormat(internalformat);
...@@ -351,9 +356,12 @@ bool Image9::updateSurface(IDirect3DSurface9 *destSurface, GLint xoffset, GLint ...@@ -351,9 +356,12 @@ bool Image9::updateSurface(IDirect3DSurface9 *destSurface, GLint xoffset, GLint
// Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input // Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input
// into the target pixel rectangle. // into the target pixel rectangle.
void Image9::loadData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, void Image9::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLint unpackAlignment, const void *input) GLint unpackAlignment, const void *input)
{ {
// 3D textures are not supported by the D3D9 backend.
ASSERT(zoffset == 0 && depth == 1);
RECT lockRect = RECT lockRect =
{ {
xoffset, yoffset, xoffset, yoffset,
...@@ -368,81 +376,81 @@ void Image9::loadData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heigh ...@@ -368,81 +376,81 @@ void Image9::loadData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heigh
} }
GLsizei inputPitch = gl::ComputePitch(width, mInternalFormat, unpackAlignment); GLsizei inputPitch = gl::ComputeRowPitch(width, mInternalFormat, unpackAlignment);
switch (mInternalFormat) switch (mInternalFormat)
{ {
case GL_ALPHA8_EXT: case GL_ALPHA8_EXT:
if (gl::supportsSSE2()) if (gl::supportsSSE2())
{ {
loadAlphaDataToBGRASSE2(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadAlphaDataToBGRASSE2(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
} }
else else
{ {
loadAlphaDataToBGRA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadAlphaDataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
} }
break; break;
case GL_LUMINANCE8_EXT: case GL_LUMINANCE8_EXT:
loadLuminanceDataToNativeOrBGRA(width, height, inputPitch, input, locked.Pitch, locked.pBits, getD3DFormat() == D3DFMT_L8); loadLuminanceDataToNativeOrBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits, getD3DFormat() == D3DFMT_L8);
break; break;
case GL_ALPHA32F_EXT: case GL_ALPHA32F_EXT:
loadAlphaFloatDataToRGBA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadAlphaFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_LUMINANCE32F_EXT: case GL_LUMINANCE32F_EXT:
loadLuminanceFloatDataToRGBA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadLuminanceFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_ALPHA16F_EXT: case GL_ALPHA16F_EXT:
loadAlphaHalfFloatDataToRGBA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadAlphaHalfFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_LUMINANCE16F_EXT: case GL_LUMINANCE16F_EXT:
loadLuminanceHalfFloatDataToRGBA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadLuminanceHalfFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_LUMINANCE8_ALPHA8_EXT: case GL_LUMINANCE8_ALPHA8_EXT:
loadLuminanceAlphaDataToNativeOrBGRA(width, height, inputPitch, input, locked.Pitch, locked.pBits, getD3DFormat() == D3DFMT_A8L8); loadLuminanceAlphaDataToNativeOrBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits, getD3DFormat() == D3DFMT_A8L8);
break; break;
case GL_LUMINANCE_ALPHA32F_EXT: case GL_LUMINANCE_ALPHA32F_EXT:
loadLuminanceAlphaFloatDataToRGBA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadLuminanceAlphaFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_LUMINANCE_ALPHA16F_EXT: case GL_LUMINANCE_ALPHA16F_EXT:
loadLuminanceAlphaHalfFloatDataToRGBA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadLuminanceAlphaHalfFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_RGB8_OES: case GL_RGB8_OES:
loadRGBUByteDataToBGRX(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadRGBUByteDataToBGRX(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_RGB565: case GL_RGB565:
loadRGB565DataToBGRA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadRGB565DataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_RGBA8_OES: case GL_RGBA8_OES:
if (gl::supportsSSE2()) if (gl::supportsSSE2())
{ {
loadRGBAUByteDataToBGRASSE2(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadRGBAUByteDataToBGRASSE2(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
} }
else else
{ {
loadRGBAUByteDataToBGRA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadRGBAUByteDataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
} }
break; break;
case GL_RGBA4: case GL_RGBA4:
loadRGBA4444DataToBGRA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadRGBA4444DataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_RGB5_A1: case GL_RGB5_A1:
loadRGBA5551DataToBGRA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadRGBA5551DataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_BGRA8_EXT: case GL_BGRA8_EXT:
loadBGRADataToBGRA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadBGRADataToBGRA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
// float textures are converted to RGBA, not BGRA, as they're stored that way in D3D // float textures are converted to RGBA, not BGRA, as they're stored that way in D3D
case GL_RGB32F_EXT: case GL_RGB32F_EXT:
loadRGBFloatDataToRGBA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadRGBFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_RGB16F_EXT: case GL_RGB16F_EXT:
loadRGBHalfFloatDataToRGBA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadRGBHalfFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_RGBA32F_EXT: case GL_RGBA32F_EXT:
loadRGBAFloatDataToRGBA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadRGBAFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
case GL_RGBA16F_EXT: case GL_RGBA16F_EXT:
loadRGBAHalfFloatDataToRGBA(width, height, inputPitch, input, locked.Pitch, locked.pBits); loadRGBAHalfFloatDataToRGBA(width, height, depth, inputPitch, 0, input, locked.Pitch, 0, locked.pBits);
break; break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -450,12 +458,15 @@ void Image9::loadData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heigh ...@@ -450,12 +458,15 @@ void Image9::loadData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heigh
unlock(); unlock();
} }
void Image9::loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, void Image9::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
const void *input) const void *input)
{ {
ASSERT(xoffset % 4 == 0); ASSERT(xoffset % 4 == 0);
ASSERT(yoffset % 4 == 0); ASSERT(yoffset % 4 == 0);
// 3D textures are not supported by the D3D9 backend.
ASSERT(zoffset == 0 && depth == 1);
RECT lockRect = { RECT lockRect = {
xoffset, yoffset, xoffset, yoffset,
xoffset + width, yoffset + height xoffset + width, yoffset + height
...@@ -469,7 +480,7 @@ void Image9::loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLs ...@@ -469,7 +480,7 @@ void Image9::loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLs
} }
GLsizei inputSize = gl::ComputeCompressedSize(width, height, mInternalFormat); GLsizei inputSize = gl::ComputeCompressedSize(width, height, mInternalFormat);
GLsizei inputPitch = gl::ComputeCompressedPitch(width, mInternalFormat); GLsizei inputPitch = gl::ComputeCompressedRowPitch(width, mInternalFormat);
int rows = inputSize / inputPitch; int rows = inputSize / inputPitch;
for (int i = 0; i < rows; ++i) for (int i = 0; i < rows; ++i)
{ {
......
...@@ -37,7 +37,7 @@ class Image9 : public Image ...@@ -37,7 +37,7 @@ class Image9 : public Image
static void generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurface); static void generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurface);
static void copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *source); static void copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *source);
virtual bool redefine(Renderer *renderer, GLint internalformat, GLsizei width, GLsizei height, bool forceRelease); virtual bool redefine(Renderer *renderer, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease);
virtual bool isRenderableFormat() const; virtual bool isRenderableFormat() const;
D3DFORMAT getD3DFormat() const; D3DFORMAT getD3DFormat() const;
...@@ -50,9 +50,9 @@ class Image9 : public Image ...@@ -50,9 +50,9 @@ class Image9 : public Image
virtual bool updateSurface(TextureStorageInterface2D *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height); virtual bool updateSurface(TextureStorageInterface2D *storage, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
virtual bool updateSurface(TextureStorageInterfaceCube *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height); virtual bool updateSurface(TextureStorageInterfaceCube *storage, int face, int level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
virtual void loadData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLint unpackAlignment, const void *input); GLint unpackAlignment, const void *input);
virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
const void *input); const void *input);
virtual void copy(GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source); virtual void copy(GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
......
...@@ -15,84 +15,92 @@ ...@@ -15,84 +15,92 @@
namespace rx namespace rx
{ {
void Image::loadRGBAUByteDataToBGRASSE2(GLsizei width, GLsizei height, void Image::loadRGBAUByteDataToBGRASSE2(GLsizei width, GLsizei height, GLsizei depth,
int inputPitch, const void *input, size_t outputPitch, void *output) int inputRowPitch, int inputDepthPitch, const void *input,
size_t outputRowPitch, size_t outputDepthPitch, void *output)
{ {
const unsigned int *source = NULL; const unsigned int *source = NULL;
unsigned int *dest = NULL; unsigned int *dest = NULL;
__m128i brMask = _mm_set1_epi32(0x00ff00ff); __m128i brMask = _mm_set1_epi32(0x00ff00ff);
for (int y = 0; y < height; y++) for (int z = 0; z < depth; z++)
{ {
source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputPitch); for (int y = 0; y < height; y++)
dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputPitch);
int x = 0;
// Make output writes aligned
for (x = 0; ((reinterpret_cast<intptr_t>(&dest[x]) & 15) != 0) && x < width; x++)
{ {
unsigned int rgba = source[x]; source = reinterpret_cast<const unsigned int*>(static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch);
dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00); dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
} int x = 0;
for (; x + 3 < width; x += 4) // Make output writes aligned
{ for (x = 0; ((reinterpret_cast<intptr_t>(&dest[x]) & 15) != 0) && x < width; x++)
__m128i sourceData = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&source[x])); {
// Mask out g and a, which don't change unsigned int rgba = source[x];
__m128i gaComponents = _mm_andnot_si128(brMask, sourceData); dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
// Mask out b and r }
__m128i brComponents = _mm_and_si128(sourceData, brMask);
// Swap b and r
__m128i brSwapped = _mm_shufflehi_epi16(_mm_shufflelo_epi16(brComponents, _MM_SHUFFLE(2, 3, 0, 1)), _MM_SHUFFLE(2, 3, 0, 1));
__m128i result = _mm_or_si128(gaComponents, brSwapped);
_mm_store_si128(reinterpret_cast<__m128i*>(&dest[x]), result);
}
// Perform leftover writes for (; x + 3 < width; x += 4)
for (; x < width; x++) {
{ __m128i sourceData = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&source[x]));
unsigned int rgba = source[x]; // Mask out g and a, which don't change
dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00); __m128i gaComponents = _mm_andnot_si128(brMask, sourceData);
// Mask out b and r
__m128i brComponents = _mm_and_si128(sourceData, brMask);
// Swap b and r
__m128i brSwapped = _mm_shufflehi_epi16(_mm_shufflelo_epi16(brComponents, _MM_SHUFFLE(2, 3, 0, 1)), _MM_SHUFFLE(2, 3, 0, 1));
__m128i result = _mm_or_si128(gaComponents, brSwapped);
_mm_store_si128(reinterpret_cast<__m128i*>(&dest[x]), result);
}
// Perform leftover writes
for (; x < width; x++)
{
unsigned int rgba = source[x];
dest[x] = (_rotl(rgba, 16) & 0x00ff00ff) | (rgba & 0xff00ff00);
}
} }
} }
} }
void Image::loadAlphaDataToBGRASSE2(GLsizei width, GLsizei height, void Image::loadAlphaDataToBGRASSE2(GLsizei width, GLsizei height, GLsizei depth,
int inputPitch, const void *input, size_t outputPitch, void *output) int inputRowPitch, int inputDepthPitch, const void *input,
size_t outputRowPitch, size_t outputDepthPitch, void *output)
{ {
const unsigned char *source = NULL; const unsigned char *source = NULL;
unsigned int *dest = NULL; unsigned int *dest = NULL;
__m128i zeroWide = _mm_setzero_si128(); __m128i zeroWide = _mm_setzero_si128();
for (int y = 0; y < height; y++) for (int z = 0; z < depth; z++)
{ {
source = static_cast<const unsigned char*>(input) + y * inputPitch; for (int y = 0; y < height; y++)
dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputPitch);
int x;
// Make output writes aligned
for (x = 0; ((reinterpret_cast<intptr_t>(&dest[x]) & 0xF) != 0 && x < width); x++)
{ {
dest[x] = static_cast<unsigned int>(source[x]) << 24; source = static_cast<const unsigned char*>(input) + y * inputRowPitch + z * inputDepthPitch;
} dest = reinterpret_cast<unsigned int*>(static_cast<unsigned char*>(output) + y * outputRowPitch + z * outputDepthPitch);
for (; x + 7 < width; x += 8) int x;
{ // Make output writes aligned
__m128i sourceData = _mm_loadl_epi64(reinterpret_cast<const __m128i*>(&source[x])); for (x = 0; ((reinterpret_cast<intptr_t>(&dest[x]) & 0xF) != 0 && x < width); x++)
// Interleave each byte to 16bit, make the lower byte to zero {
sourceData = _mm_unpacklo_epi8(zeroWide, sourceData); dest[x] = static_cast<unsigned int>(source[x]) << 24;
// Interleave each 16bit to 32bit, make the lower 16bit to zero }
__m128i lo = _mm_unpacklo_epi16(zeroWide, sourceData);
__m128i hi = _mm_unpackhi_epi16(zeroWide, sourceData);
_mm_store_si128(reinterpret_cast<__m128i*>(&dest[x]), lo); for (; x + 7 < width; x += 8)
_mm_store_si128(reinterpret_cast<__m128i*>(&dest[x + 4]), hi); {
} __m128i sourceData = _mm_loadl_epi64(reinterpret_cast<const __m128i*>(&source[x]));
// Interleave each byte to 16bit, make the lower byte to zero
sourceData = _mm_unpacklo_epi8(zeroWide, sourceData);
// Interleave each 16bit to 32bit, make the lower 16bit to zero
__m128i lo = _mm_unpacklo_epi16(zeroWide, sourceData);
__m128i hi = _mm_unpackhi_epi16(zeroWide, sourceData);
// Handle the remainder _mm_store_si128(reinterpret_cast<__m128i*>(&dest[x]), lo);
for (; x < width; x++) _mm_store_si128(reinterpret_cast<__m128i*>(&dest[x + 4]), hi);
{ }
dest[x] = static_cast<unsigned int>(source[x]) << 24;
// Handle the remainder
for (; x < width; x++)
{
dest[x] = static_cast<unsigned int>(source[x]) << 24;
}
} }
} }
} }
......
...@@ -259,7 +259,7 @@ int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsig ...@@ -259,7 +259,7 @@ int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsig
return -1; return -1;
} }
GLsizei ComputePitch(GLsizei width, GLint internalformat, GLint alignment) GLsizei ComputeRowPitch(GLsizei width, GLint internalformat, GLint alignment)
{ {
ASSERT(alignment > 0 && isPow2(alignment)); ASSERT(alignment > 0 && isPow2(alignment));
...@@ -267,11 +267,21 @@ GLsizei ComputePitch(GLsizei width, GLint internalformat, GLint alignment) ...@@ -267,11 +267,21 @@ GLsizei ComputePitch(GLsizei width, GLint internalformat, GLint alignment)
return (rawPitch + alignment - 1) & ~(alignment - 1); return (rawPitch + alignment - 1) & ~(alignment - 1);
} }
GLsizei ComputeCompressedPitch(GLsizei width, GLenum internalformat) GLsizei ComputeDepthPitch(GLsizei width, GLsizei height, GLint internalformat, GLint alignment)
{
return ComputeRowPitch(width, internalformat, alignment) * height;
}
GLsizei ComputeCompressedRowPitch(GLsizei width, GLenum internalformat)
{ {
return ComputeCompressedSize(width, 1, internalformat); return ComputeCompressedSize(width, 1, internalformat);
} }
GLsizei ComputeCompressedDepthPitch(GLsizei width, GLsizei height, GLenum internalformat)
{
return ComputeCompressedSize(width, height, internalformat);
}
GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum internalformat) GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum internalformat)
{ {
switch (internalformat) switch (internalformat)
......
...@@ -35,8 +35,10 @@ int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsig ...@@ -35,8 +35,10 @@ int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsig
void MakeValidSize(bool isImage, bool isCompressed, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset); void MakeValidSize(bool isImage, bool isCompressed, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset);
int ComputePixelSize(GLint internalformat); int ComputePixelSize(GLint internalformat);
GLsizei ComputePitch(GLsizei width, GLint internalformat, GLint alignment); GLsizei ComputeRowPitch(GLsizei width, GLint internalformat, GLint alignment);
GLsizei ComputeCompressedPitch(GLsizei width, GLenum format); GLsizei ComputeDepthPitch(GLsizei width, GLsizei height, GLint internalformat, GLint alignment);
GLsizei ComputeCompressedRowPitch(GLsizei width, GLenum format);
GLsizei ComputeCompressedDepthPitch(GLsizei width, GLsizei height, GLenum format);
GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format); GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format);
bool IsCompressed(GLenum format); bool IsCompressed(GLenum format);
bool IsDepthTexture(GLenum format); bool IsDepthTexture(GLenum format);
......
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