Image9 and Image11 determine the d3d formats through the new helper methods.

TRAC #22972 Signed-off-by: Jamie Madill Signed-off-by: Nicolas Capens Author: Geoff Lang git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2320 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent cead8ad7
...@@ -22,6 +22,7 @@ Image::Image() ...@@ -22,6 +22,7 @@ Image::Image()
mInternalFormat = GL_NONE; mInternalFormat = GL_NONE;
mActualFormat = GL_NONE; mActualFormat = GL_NONE;
mTarget = GL_NONE; mTarget = GL_NONE;
mRenderable = false;
} }
} }
...@@ -38,6 +38,7 @@ class Image ...@@ -38,6 +38,7 @@ class Image
GLenum getInternalFormat() const { return mInternalFormat; } GLenum getInternalFormat() const { return mInternalFormat; }
GLenum getActualFormat() const { return mActualFormat; } GLenum getActualFormat() const { return mActualFormat; }
GLenum getTarget() const { return mTarget; } GLenum getTarget() const { return mTarget; }
bool isRenderableFormat() const { return mRenderable; }
void markDirty() {mDirty = true;} void markDirty() {mDirty = true;}
void markClean() {mDirty = false;} void markClean() {mDirty = false;}
...@@ -54,8 +55,6 @@ class Image ...@@ -54,8 +55,6 @@ class Image
virtual bool redefine(Renderer *renderer, GLenum target, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease) = 0; virtual bool redefine(Renderer *renderer, GLenum target, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease) = 0;
virtual bool isRenderableFormat() const = 0;
virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLint unpackAlignment, GLenum type, const void *input) = 0; GLint unpackAlignment, GLenum type, const void *input) = 0;
virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
...@@ -69,6 +68,7 @@ class Image ...@@ -69,6 +68,7 @@ class Image
GLsizei mDepth; GLsizei mDepth;
GLint mInternalFormat; GLint mInternalFormat;
GLenum mActualFormat; GLenum mActualFormat;
bool mRenderable;
GLenum mTarget; GLenum mTarget;
bool mDirty; bool mDirty;
......
...@@ -119,15 +119,18 @@ bool Image11::redefine(Renderer *renderer, GLenum target, GLint internalformat, ...@@ -119,15 +119,18 @@ bool Image11::redefine(Renderer *renderer, GLenum target, GLint internalformat,
forceRelease) forceRelease)
{ {
mRenderer = Renderer11::makeRenderer11(renderer); mRenderer = Renderer11::makeRenderer11(renderer);
GLuint clientVersion = mRenderer->getCurrentClientVersion();
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;
mDepth = depth; mDepth = depth;
mInternalFormat = internalformat; mInternalFormat = internalformat;
mTarget = target; mTarget = target;
// compute the d3d format that will be used // compute the d3d format that will be used
mDXGIFormat = gl_d3d11::ConvertTextureFormat(internalformat); mDXGIFormat = gl_d3d11::GetTexFormat(internalformat, clientVersion);
mActualFormat = d3d11_gl::ConvertTextureInternalFormat(mDXGIFormat); mActualFormat = d3d11_gl::GetInternalFormat(mDXGIFormat);
mRenderable = gl_d3d11::GetTexFormat(internalformat, clientVersion) != DXGI_FORMAT_UNKNOWN;
if (mStagingTexture) if (mStagingTexture)
{ {
...@@ -141,11 +144,6 @@ bool Image11::redefine(Renderer *renderer, GLenum target, GLint internalformat, ...@@ -141,11 +144,6 @@ bool Image11::redefine(Renderer *renderer, GLenum target, GLint internalformat,
return false; return false;
} }
bool Image11::isRenderableFormat() const
{
return TextureStorage11::IsTextureFormatRenderable(mDXGIFormat);
}
DXGI_FORMAT Image11::getDXGIFormat() const DXGI_FORMAT Image11::getDXGIFormat() const
{ {
// this should only happen if the image hasn't been redefined first // this should only happen if the image hasn't been redefined first
...@@ -286,13 +284,14 @@ void Image11::copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y ...@@ -286,13 +284,14 @@ void Image11::copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y
// This format requires conversion, so we must copy the texture to staging and manually convert via readPixels // This format requires conversion, so we must copy the texture to staging and manually convert via readPixels
D3D11_MAPPED_SUBRESOURCE mappedImage; D3D11_MAPPED_SUBRESOURCE mappedImage;
HRESULT result = map(D3D11_MAP_WRITE, &mappedImage); HRESULT result = map(D3D11_MAP_WRITE, &mappedImage);
// determine the offset coordinate into the destination buffer // determine the offset coordinate into the destination buffer
GLsizei rowOffset = gl::ComputePixelSize(mActualFormat) * xoffset; GLuint clientVersion = mRenderer->getCurrentClientVersion();
GLsizei rowOffset = gl::GetPixelBytes(mActualFormat, clientVersion) * xoffset;
void *dataOffset = static_cast<unsigned char*>(mappedImage.pData) + mappedImage.RowPitch * yoffset + rowOffset + zoffset * mappedImage.DepthPitch; void *dataOffset = static_cast<unsigned char*>(mappedImage.pData) + mappedImage.RowPitch * yoffset + rowOffset + zoffset * mappedImage.DepthPitch;
mRenderer->readPixels(source, x, y, width, height, gl::ExtractFormat(mInternalFormat), mRenderer->readPixels(source, x, y, width, height, gl::GetFormat(mInternalFormat, clientVersion),
gl::ExtractType(mInternalFormat), mappedImage.RowPitch, false, 4, dataOffset); gl::GetType(mInternalFormat, clientVersion), mappedImage.RowPitch, false, 4, dataOffset);
unmap(); unmap();
} }
...@@ -320,7 +319,6 @@ void Image11::createStagingTexture() ...@@ -320,7 +319,6 @@ void Image11::createStagingTexture()
} }
const DXGI_FORMAT dxgiFormat = getDXGIFormat(); const DXGI_FORMAT dxgiFormat = getDXGIFormat();
ASSERT(!d3d11::IsDepthStencilFormat(dxgiFormat)); // We should never get here for depth textures
if (mWidth > 0 && mHeight > 0 && mDepth > 0) if (mWidth > 0 && mHeight > 0 && mDepth > 0)
{ {
...@@ -331,7 +329,7 @@ void Image11::createStagingTexture() ...@@ -331,7 +329,7 @@ void Image11::createStagingTexture()
GLsizei height = mHeight; GLsizei height = mHeight;
// adjust size if needed for compressed textures // adjust size if needed for compressed textures
gl::MakeValidSize(false, d3d11::IsCompressed(dxgiFormat), &width, &height, &lodOffset); d3d11::MakeValidSize(false, dxgiFormat, &width, &height, &lodOffset);
if (mTarget == GL_TEXTURE_3D) if (mTarget == GL_TEXTURE_3D)
{ {
......
...@@ -45,7 +45,6 @@ class Image11 : public Image ...@@ -45,7 +45,6 @@ class Image11 : public Image
virtual bool redefine(Renderer *renderer, GLenum target, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease); virtual bool redefine(Renderer *renderer, GLenum target, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease);
virtual bool isRenderableFormat() const;
DXGI_FORMAT getDXGIFormat() const; DXGI_FORMAT getDXGIFormat() const;
virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, virtual void loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
......
...@@ -109,8 +109,10 @@ void Image9::copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *so ...@@ -109,8 +109,10 @@ void Image9::copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *so
D3DSURFACE_DESC desc; D3DSURFACE_DESC desc;
source->GetDesc(&desc); source->GetDesc(&desc);
int rows = d3d9::IsCompressedFormat(desc.Format) ? desc.Height / 4 : desc.Height; int blockHeight = d3d9::GetBlockHeight(desc.Format);
int bytes = d3d9::ComputeRowSize(desc.Format, desc.Width); int rows = desc.Height / blockHeight;
int bytes = d3d9::GetBlockSize(desc.Format, desc.Width, blockHeight);
ASSERT(bytes <= sourceLock.Pitch && bytes <= destLock.Pitch); ASSERT(bytes <= sourceLock.Pitch && bytes <= destLock.Pitch);
for(int i = 0; i < rows; i++) for(int i = 0; i < rows; i++)
...@@ -139,14 +141,17 @@ bool Image9::redefine(rx::Renderer *renderer, GLenum target, GLint internalforma ...@@ -139,14 +141,17 @@ bool Image9::redefine(rx::Renderer *renderer, GLenum target, GLint internalforma
forceRelease) forceRelease)
{ {
mRenderer = Renderer9::makeRenderer9(renderer); mRenderer = Renderer9::makeRenderer9(renderer);
GLuint clientVersion = mRenderer->getCurrentClientVersion();
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;
mDepth = depth; 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 = gl_d3d9::GetTexureFormat(internalformat, mRenderer);
mActualFormat = d3d9_gl::GetEquivalentFormat(mD3DFormat); mActualFormat = d3d9_gl::GetInternalFormat(mD3DFormat);
mRenderable = gl_d3d9::GetRenderFormat(internalformat, mRenderer) != D3DFMT_UNKNOWN;
if (mSurface) if (mSurface)
{ {
...@@ -171,14 +176,13 @@ void Image9::createSurface() ...@@ -171,14 +176,13 @@ void Image9::createSurface()
IDirect3DSurface9 *newSurface = NULL; IDirect3DSurface9 *newSurface = NULL;
const D3DPOOL poolToUse = D3DPOOL_SYSTEMMEM; const D3DPOOL poolToUse = D3DPOOL_SYSTEMMEM;
const D3DFORMAT d3dFormat = getD3DFormat(); const D3DFORMAT d3dFormat = getD3DFormat();
ASSERT(d3dFormat != D3DFMT_INTZ); // We should never get here for depth textures
if (mWidth != 0 && mHeight != 0) if (mWidth != 0 && mHeight != 0)
{ {
int levelToFetch = 0; int levelToFetch = 0;
GLsizei requestWidth = mWidth; GLsizei requestWidth = mWidth;
GLsizei requestHeight = mHeight; GLsizei requestHeight = mHeight;
gl::MakeValidSize(true, gl::IsCompressed(mInternalFormat), &requestWidth, &requestHeight, &levelToFetch); d3d9::MakeValidSize(true, d3dFormat, &requestWidth, &requestHeight, &levelToFetch);
IDirect3DDevice9 *device = mRenderer->getDevice(); IDirect3DDevice9 *device = mRenderer->getDevice();
...@@ -227,11 +231,6 @@ void Image9::unlock() ...@@ -227,11 +231,6 @@ void Image9::unlock()
} }
} }
bool Image9::isRenderableFormat() const
{
return TextureStorage9::IsTextureFormatRenderable(getD3DFormat());
}
D3DFORMAT Image9::getD3DFormat() const D3DFORMAT Image9::getD3DFormat() const
{ {
// this should only happen if the image hasn't been redefined first // this should only happen if the image hasn't been redefined first
......
...@@ -39,7 +39,6 @@ class Image9 : public Image ...@@ -39,7 +39,6 @@ class Image9 : public Image
virtual bool redefine(Renderer *renderer, GLenum target, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease); virtual bool redefine(Renderer *renderer, GLenum target, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease);
virtual bool isRenderableFormat() const;
D3DFORMAT getD3DFormat() const; D3DFORMAT getD3DFormat() const;
virtual bool isDirty() const {return mSurface && mDirty;} virtual bool isDirty() const {return mSurface && mDirty;}
......
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