Bug 713266 - Update ANGLE to r930 - no review

No review because this is just syncing us with the upstream
  http://code.google.com/p/angleproject/
This commit is contained in:
Benoit Jacob 2012-01-03 05:01:43 -05:00
parent 6d9dd02ad0
commit 08064474fb
9 changed files with 134 additions and 112 deletions

View File

@ -1,6 +1,6 @@
This is the ANGLE project, from http://code.google.com/p/angleproject/ This is the ANGLE project, from http://code.google.com/p/angleproject/
Current revision: r924 Current revision: r930
== Applied local patches == == Applied local patches ==

View File

@ -1,7 +1,7 @@
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 924 #define BUILD_REVISION 930
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)

View File

@ -188,7 +188,7 @@ void OutputHLSL::header()
if (mUsesFragCoord) if (mUsesFragCoord)
{ {
out << "uniform float4 dx_Viewport;\n" out << "uniform float4 dx_Coord;\n"
"uniform float2 dx_Depth;\n"; "uniform float2 dx_Depth;\n";
} }

View File

@ -1798,11 +1798,13 @@ bool Context::applyRenderTarget(bool ignoreViewport)
GLfloat xy[2] = {1.0f / viewport.Width, -1.0f / viewport.Height}; GLfloat xy[2] = {1.0f / viewport.Width, -1.0f / viewport.Height};
programObject->setUniform2fv(halfPixelSize, 1, xy); programObject->setUniform2fv(halfPixelSize, 1, xy);
GLint viewport = programObject->getDxViewportLocation(); // These values are used for computing gl_FragCoord in Program::linkVaryings(). The approach depends on Shader Model 3.0 support.
GLfloat whxy[4] = {mState.viewportWidth / 2.0f, mState.viewportHeight / 2.0f, GLint coord = programObject->getDxCoordLocation();
float h = mSupportsShaderModel3 ? mRenderTargetDesc.Height : mState.viewportHeight / 2.0f;
GLfloat whxy[4] = {mState.viewportWidth / 2.0f, h,
(float)mState.viewportX + mState.viewportWidth / 2.0f, (float)mState.viewportX + mState.viewportWidth / 2.0f,
(float)mState.viewportY + mState.viewportHeight / 2.0f}; (float)mState.viewportY + mState.viewportHeight / 2.0f};
programObject->setUniform4fv(viewport, 1, whxy); programObject->setUniform4fv(coord, 1, whxy);
GLint depth = programObject->getDxDepthLocation(); GLint depth = programObject->getDxDepthLocation();
GLfloat dz[2] = {(zFar - zNear) / 2.0f, (zNear + zFar) / 2.0f}; GLfloat dz[2] = {(zFar - zNear) / 2.0f, (zNear + zFar) / 2.0f};
@ -2596,18 +2598,7 @@ void Context::clear(GLbitfield mask)
float depth = clamp01(mState.depthClearValue); float depth = clamp01(mState.depthClearValue);
int stencil = mState.stencilClearValue & 0x000000FF; int stencil = mState.stencilClearValue & 0x000000FF;
IDirect3DSurface9 *renderTarget = framebufferObject->getRenderTarget(); bool alphaUnmasked = (dx2es::GetAlphaSize(mRenderTargetDesc.Format) == 0) || mState.colorMaskAlpha;
if (!renderTarget)
{
return; // Context must be lost, return silently
}
D3DSURFACE_DESC desc;
renderTarget->GetDesc(&desc);
renderTarget->Release();
renderTarget = NULL;
bool alphaUnmasked = (dx2es::GetAlphaSize(desc.Format) == 0) || mState.colorMaskAlpha;
const bool needMaskedStencilClear = (flags & D3DCLEAR_STENCIL) && const bool needMaskedStencilClear = (flags & D3DCLEAR_STENCIL) &&
(mState.stencilWritemask & stencilUnmasked) != stencilUnmasked; (mState.stencilWritemask & stencilUnmasked) != stencilUnmasked;
@ -2708,12 +2699,12 @@ void Context::clear(GLbitfield mask)
float quad[4][4]; // A quadrilateral covering the target, aligned to match the edges float quad[4][4]; // A quadrilateral covering the target, aligned to match the edges
quad[0][0] = -0.5f; quad[0][0] = -0.5f;
quad[0][1] = desc.Height - 0.5f; quad[0][1] = mRenderTargetDesc.Height - 0.5f;
quad[0][2] = 0.0f; quad[0][2] = 0.0f;
quad[0][3] = 1.0f; quad[0][3] = 1.0f;
quad[1][0] = desc.Width - 0.5f; quad[1][0] = mRenderTargetDesc.Width - 0.5f;
quad[1][1] = desc.Height - 0.5f; quad[1][1] = mRenderTargetDesc.Height - 0.5f;
quad[1][2] = 0.0f; quad[1][2] = 0.0f;
quad[1][3] = 1.0f; quad[1][3] = 1.0f;
@ -2722,7 +2713,7 @@ void Context::clear(GLbitfield mask)
quad[2][2] = 0.0f; quad[2][2] = 0.0f;
quad[2][3] = 1.0f; quad[2][3] = 1.0f;
quad[3][0] = desc.Width - 0.5f; quad[3][0] = mRenderTargetDesc.Width - 0.5f;
quad[3][1] = -0.5f; quad[3][1] = -0.5f;
quad[3][2] = 0.0f; quad[3][2] = 0.0f;
quad[3][3] = 1.0f; quad[3][3] = 1.0f;

View File

@ -65,7 +65,7 @@ enum
MAX_TEXTURE_IMAGE_UNITS = 16, MAX_TEXTURE_IMAGE_UNITS = 16,
MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF = 4, // For devices supporting vertex texture fetch MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF = 4, // For devices supporting vertex texture fetch
MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF, MAX_COMBINED_TEXTURE_IMAGE_UNITS_VTF = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS_VTF,
MAX_FRAGMENT_UNIFORM_VECTORS_SM2 = 32 - 3, // Reserve space for dx_Viewport, dx_Depth, and dx_DepthRange. dx_PointOrLines and dx_FrontCCW use separate bool registers. MAX_FRAGMENT_UNIFORM_VECTORS_SM2 = 32 - 3, // Reserve space for dx_Coord, dx_Depth, and dx_DepthRange. dx_PointOrLines and dx_FrontCCW use separate bool registers.
MAX_FRAGMENT_UNIFORM_VECTORS_SM3 = 224 - 3, MAX_FRAGMENT_UNIFORM_VECTORS_SM3 = 224 - 3,
MAX_DRAW_BUFFERS = 1, MAX_DRAW_BUFFERS = 1,

View File

@ -1600,13 +1600,20 @@ bool Program::linkVaryings()
if (mFragmentShader->mUsesFragCoord) if (mFragmentShader->mUsesFragCoord)
{ {
mPixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n"; mPixelHLSL += " float rhw = 1.0 / input.gl_FragCoord.w;\n";
if (sm3) {
if (sm3)
{
// dx_Coord.y contains the render target height. See Context::applyRenderTarget()
mPixelHLSL += " gl_FragCoord.x = input.dx_VPos.x + 0.5;\n" mPixelHLSL += " gl_FragCoord.x = input.dx_VPos.x + 0.5;\n"
" gl_FragCoord.y = 2.0 * dx_Viewport.y - input.dx_VPos.y - 0.5;\n"; " gl_FragCoord.y = dx_Coord.y - input.dx_VPos.y - 0.5;\n";
} else {
mPixelHLSL += " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_Viewport.x + dx_Viewport.z;\n"
" gl_FragCoord.y = -(input.gl_FragCoord.y * rhw) * dx_Viewport.y + dx_Viewport.w;\n";
} }
else
{
// dx_Coord contains the viewport width/2, height/2, center.x and center.y. See Context::applyRenderTarget()
mPixelHLSL += " gl_FragCoord.x = (input.gl_FragCoord.x * rhw) * dx_Coord.x + dx_Coord.z;\n"
" gl_FragCoord.y = -(input.gl_FragCoord.y * rhw) * dx_Coord.y + dx_Coord.w;\n";
}
mPixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_Depth.x + dx_Depth.y;\n" mPixelHLSL += " gl_FragCoord.z = (input.gl_FragCoord.z * rhw) * dx_Depth.x + dx_Depth.y;\n"
" gl_FragCoord.w = rhw;\n"; " gl_FragCoord.w = rhw;\n";
} }
@ -1732,7 +1739,7 @@ void Program::link()
// are reserved prefixes, and do not receive additional decoration // are reserved prefixes, and do not receive additional decoration
mDxDepthRangeLocation = getUniformLocation("dx_DepthRange"); mDxDepthRangeLocation = getUniformLocation("dx_DepthRange");
mDxDepthLocation = getUniformLocation("dx_Depth"); mDxDepthLocation = getUniformLocation("dx_Depth");
mDxViewportLocation = getUniformLocation("dx_Viewport"); mDxCoordLocation = getUniformLocation("dx_Coord");
mDxHalfPixelSizeLocation = getUniformLocation("dx_HalfPixelSize"); mDxHalfPixelSizeLocation = getUniformLocation("dx_HalfPixelSize");
mDxFrontCCWLocation = getUniformLocation("dx_FrontCCW"); mDxFrontCCWLocation = getUniformLocation("dx_FrontCCW");
mDxPointsOrLinesLocation = getUniformLocation("dx_PointsOrLines"); mDxPointsOrLinesLocation = getUniformLocation("dx_PointsOrLines");
@ -2420,7 +2427,7 @@ void Program::unlink(bool destroy)
mDxDepthRangeLocation = -1; mDxDepthRangeLocation = -1;
mDxDepthLocation = -1; mDxDepthLocation = -1;
mDxViewportLocation = -1; mDxCoordLocation = -1;
mDxHalfPixelSizeLocation = -1; mDxHalfPixelSizeLocation = -1;
mDxFrontCCWLocation = -1; mDxFrontCCWLocation = -1;
mDxPointsOrLinesLocation = -1; mDxPointsOrLinesLocation = -1;
@ -2841,9 +2848,9 @@ GLint Program::getDxDepthLocation() const
return mDxDepthLocation; return mDxDepthLocation;
} }
GLint Program::getDxViewportLocation() const GLint Program::getDxCoordLocation() const
{ {
return mDxViewportLocation; return mDxCoordLocation;
} }
GLint Program::getDxHalfPixelSizeLocation() const GLint Program::getDxHalfPixelSizeLocation() const

View File

@ -103,7 +103,7 @@ class Program
GLint getDxDepthRangeLocation() const; GLint getDxDepthRangeLocation() const;
GLint getDxDepthLocation() const; GLint getDxDepthLocation() const;
GLint getDxViewportLocation() const; GLint getDxCoordLocation() const;
GLint getDxHalfPixelSizeLocation() const; GLint getDxHalfPixelSizeLocation() const;
GLint getDxFrontCCWLocation() const; GLint getDxFrontCCWLocation() const;
GLint getDxPointsOrLinesLocation() const; GLint getDxPointsOrLinesLocation() const;
@ -207,7 +207,7 @@ class Program
GLint mDxDepthRangeLocation; GLint mDxDepthRangeLocation;
GLint mDxDepthLocation; GLint mDxDepthLocation;
GLint mDxViewportLocation; GLint mDxCoordLocation;
GLint mDxHalfPixelSizeLocation; GLint mDxHalfPixelSizeLocation;
GLint mDxFrontCCWLocation; GLint mDxFrontCCWLocation;
GLint mDxPointsOrLinesLocation; GLint mDxPointsOrLinesLocation;

View File

@ -79,6 +79,28 @@ static D3DFORMAT ConvertTextureFormatType(GLenum format, GLenum type)
return D3DFMT_A8R8G8B8; return D3DFMT_A8R8G8B8;
} }
static bool IsTextureFormatRenderable(D3DFORMAT format)
{
switch(format)
{
case D3DFMT_L8:
case D3DFMT_A8L8:
case D3DFMT_DXT1:
case D3DFMT_DXT3:
case D3DFMT_DXT5:
return false;
case D3DFMT_A8R8G8B8:
case D3DFMT_X8R8G8B8:
case D3DFMT_A16B16G16R16F:
case D3DFMT_A32B32G32R32F:
return true;
default:
UNREACHABLE();
}
return false;
}
Image::Image() Image::Image()
{ {
mWidth = 0; mWidth = 0;
@ -207,26 +229,9 @@ void Image::unlock()
} }
} }
bool Image::isRenderable() const bool Image::isRenderableFormat() const
{ {
switch(getD3DFormat()) return IsTextureFormatRenderable(getD3DFormat());
{
case D3DFMT_L8:
case D3DFMT_A8L8:
case D3DFMT_DXT1:
case D3DFMT_DXT3:
case D3DFMT_DXT5:
return false;
case D3DFMT_A8R8G8B8:
case D3DFMT_X8R8G8B8:
case D3DFMT_A16B16G16R16F:
case D3DFMT_A32B32G32R32F:
return true;
default:
UNREACHABLE();
}
return false;
} }
D3DFORMAT Image::getD3DFormat() const D3DFORMAT Image::getD3DFormat() const
@ -1126,7 +1131,7 @@ void Image::copy(GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width,
int destYOffset = transformPixelYOffset(yoffset, height, mHeight); int destYOffset = transformPixelYOffset(yoffset, height, mHeight);
RECT destRect = {xoffset, destYOffset, xoffset + width, destYOffset + height}; RECT destRect = {xoffset, destYOffset, xoffset + width, destYOffset + height};
if (isRenderable()) if (isRenderableFormat())
{ {
result = D3DXLoadSurfaceFromSurface(getSurface(), NULL, &destRect, renderTargetData, NULL, &sourceRect, D3DX_FILTER_BOX, 0); result = D3DXLoadSurfaceFromSurface(getSurface(), NULL, &destRect, renderTargetData, NULL, &sourceRect, D3DX_FILTER_BOX, 0);
@ -1268,9 +1273,9 @@ void Image::copy(GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width,
mDirty = true; mDirty = true;
} }
TextureStorage::TextureStorage(bool renderable) TextureStorage::TextureStorage(bool renderTarget)
: mRenderable(renderable), : mRenderTarget(renderTarget),
mD3DPool(getDisplay()->getTexturePool(renderable)), mD3DPool(getDisplay()->getTexturePool(mRenderTarget)),
mTextureSerial(issueTextureSerial()) mTextureSerial(issueTextureSerial())
{ {
} }
@ -1279,9 +1284,9 @@ TextureStorage::~TextureStorage()
{ {
} }
bool TextureStorage::isRenderable() const bool TextureStorage::isRenderTarget() const
{ {
return mRenderable; return mRenderTarget;
} }
bool TextureStorage::isManaged() const bool TextureStorage::isManaged() const
@ -1566,9 +1571,10 @@ IDirect3DBaseTexture9 *Texture::getTexture()
return NULL; return NULL;
} }
if (!getBaseTexture()) // ensure the underlying texture is created
if (getStorage(false) == NULL)
{ {
createTexture(); return NULL;
} }
updateTexture(); updateTexture();
@ -1592,15 +1598,15 @@ void Texture::resetDirty()
mDirtyImages = false; mDirtyImages = false;
} }
unsigned int Texture::getTextureSerial() const unsigned int Texture::getTextureSerial()
{ {
TextureStorage *texture = getStorage(); TextureStorage *texture = getStorage(false);
return texture ? texture->getTextureSerial() : 0; return texture ? texture->getTextureSerial() : 0;
} }
unsigned int Texture::getRenderTargetSerial(GLenum target) const unsigned int Texture::getRenderTargetSerial(GLenum target)
{ {
TextureStorage *texture = getStorage(); TextureStorage *texture = getStorage(true);
return texture ? texture->getRenderTargetSerial(target) : 0; return texture ? texture->getRenderTargetSerial(target) : 0;
} }
@ -1672,12 +1678,13 @@ TextureStorage2D::TextureStorage2D(IDirect3DTexture9 *surfaceTexture) : TextureS
mTexture = surfaceTexture; mTexture = surfaceTexture;
} }
TextureStorage2D::TextureStorage2D(int levels, D3DFORMAT format, int width, int height, bool renderable) : TextureStorage(renderable), mRenderTargetSerial(RenderbufferStorage::issueSerial()) TextureStorage2D::TextureStorage2D(int levels, D3DFORMAT format, int width, int height, bool renderTarget)
: TextureStorage(renderTarget), mRenderTargetSerial(RenderbufferStorage::issueSerial())
{ {
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
mTexture = NULL; mTexture = NULL;
HRESULT result = device->CreateTexture(width, height, levels, renderable ? D3DUSAGE_RENDERTARGET : 0, format, getPool(), &mTexture, NULL); HRESULT result = device->CreateTexture(width, height, levels, isRenderTarget() ? D3DUSAGE_RENDERTARGET : 0, format, getPool(), &mTexture, NULL);
if (FAILED(result)) if (FAILED(result))
{ {
@ -1902,14 +1909,14 @@ void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei
redefineImage(level, format, width, height, GL_UNSIGNED_BYTE); redefineImage(level, format, width, height, GL_UNSIGNED_BYTE);
if (!mImageArray[level].isRenderable()) if (!mImageArray[level].isRenderableFormat())
{ {
mImageArray[level].copy(0, 0, x, y, width, height, renderTarget); mImageArray[level].copy(0, 0, x, y, width, height, renderTarget);
mDirtyImages = true; mDirtyImages = true;
} }
else else
{ {
if (!mTexStorage || !mTexStorage->isRenderable()) if (!mTexStorage || !mTexStorage->isRenderTarget())
{ {
convertToRenderTarget(); convertToRenderTarget();
} }
@ -1954,14 +1961,14 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo
return error(GL_OUT_OF_MEMORY); return error(GL_OUT_OF_MEMORY);
} }
if (!mImageArray[level].isRenderable() || (!mTexStorage && !isSamplerComplete())) if (!mImageArray[level].isRenderableFormat() || (!mTexStorage && !isSamplerComplete()))
{ {
mImageArray[level].copy(xoffset, yoffset, x, y, width, height, renderTarget); mImageArray[level].copy(xoffset, yoffset, x, y, width, height, renderTarget);
mDirtyImages = true; mDirtyImages = true;
} }
else else
{ {
if (!mTexStorage || !mTexStorage->isRenderable()) if (!mTexStorage || !mTexStorage->isRenderTarget())
{ {
convertToRenderTarget(); convertToRenderTarget();
} }
@ -1996,10 +2003,10 @@ void Texture2D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GL
GLenum format = gl::ExtractFormat(internalformat); GLenum format = gl::ExtractFormat(internalformat);
GLenum type = gl::ExtractType(internalformat); GLenum type = gl::ExtractType(internalformat);
D3DFORMAT d3dfmt = ConvertTextureFormatType(format, type); D3DFORMAT d3dfmt = ConvertTextureFormatType(format, type);
const bool renderable = (mUsage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE); const bool renderTarget = IsTextureFormatRenderable(d3dfmt) && (mUsage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
delete mTexStorage; delete mTexStorage;
mTexStorage = new TextureStorage2D(levels, d3dfmt, width, height, renderable); mTexStorage = new TextureStorage2D(levels, d3dfmt, width, height, renderTarget);
mImmutable = true; mImmutable = true;
for (int level = 0; level < levels; level++) for (int level = 0; level < levels; level++)
@ -2154,10 +2161,10 @@ void Texture2D::createTexture()
GLsizei height = mImageArray[0].getHeight(); GLsizei height = mImageArray[0].getHeight();
GLint levels = creationLevels(width, height); GLint levels = creationLevels(width, height);
D3DFORMAT format = mImageArray[0].getD3DFormat(); D3DFORMAT format = mImageArray[0].getD3DFormat();
const bool renderable = (mUsage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE); const bool renderTarget = IsTextureFormatRenderable(format) && (mUsage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
delete mTexStorage; delete mTexStorage;
mTexStorage = new TextureStorage2D(levels, format, width, height, renderable); mTexStorage = new TextureStorage2D(levels, format, width, height, renderTarget);
if (mTexStorage->isManaged()) if (mTexStorage->isManaged())
{ {
@ -2249,7 +2256,7 @@ void Texture2D::generateMipmaps()
mImageArray[0].getType()); mImageArray[0].getType());
} }
if (mTexStorage && mTexStorage->isRenderable()) if (mTexStorage && mTexStorage->isRenderTarget())
{ {
for (unsigned int i = 1; i <= q; i++) for (unsigned int i = 1; i <= q; i++)
{ {
@ -2305,12 +2312,8 @@ IDirect3DSurface9 *Texture2D::getRenderTarget(GLenum target)
{ {
ASSERT(target == GL_TEXTURE_2D); ASSERT(target == GL_TEXTURE_2D);
if (!mTexStorage || !mTexStorage->isRenderable()) // ensure the underlying texture is created
{ if (getStorage(true) == NULL)
convertToRenderTarget();
}
if (mTexStorage == NULL)
{ {
return NULL; return NULL;
} }
@ -2320,17 +2323,30 @@ IDirect3DSurface9 *Texture2D::getRenderTarget(GLenum target)
return mTexStorage->getSurfaceLevel(0); return mTexStorage->getSurfaceLevel(0);
} }
TextureStorage *Texture2D::getStorage() const TextureStorage *Texture2D::getStorage(bool renderTarget)
{ {
if (!mTexStorage || (renderTarget && !mTexStorage->isRenderTarget()))
{
if (renderTarget)
{
convertToRenderTarget();
}
else
{
createTexture();
}
}
return mTexStorage; return mTexStorage;
} }
TextureStorageCubeMap::TextureStorageCubeMap(int levels, D3DFORMAT format, int size, bool renderable) : TextureStorage(renderable), mFirstRenderTargetSerial(RenderbufferStorage::issueCubeSerials()) TextureStorageCubeMap::TextureStorageCubeMap(int levels, D3DFORMAT format, int size, bool renderTarget)
: TextureStorage(renderTarget), mFirstRenderTargetSerial(RenderbufferStorage::issueCubeSerials())
{ {
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
mTexture = NULL; mTexture = NULL;
HRESULT result = device->CreateCubeTexture(size, levels, renderable ? D3DUSAGE_RENDERTARGET : 0, format, getPool(), &mTexture, NULL); HRESULT result = device->CreateCubeTexture(size, levels, isRenderTarget() ? D3DUSAGE_RENDERTARGET : 0, format, getPool(), &mTexture, NULL);
if (FAILED(result)) if (FAILED(result))
{ {
@ -2630,10 +2646,10 @@ void TextureCubeMap::createTexture()
GLsizei size = mImageArray[0][0].getWidth(); GLsizei size = mImageArray[0][0].getWidth();
GLint levels = creationLevels(size, 0); GLint levels = creationLevels(size, 0);
D3DFORMAT format = mImageArray[0][0].getD3DFormat(); D3DFORMAT format = mImageArray[0][0].getD3DFormat();
const bool renderable = (mUsage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE); const bool renderTarget = IsTextureFormatRenderable(format) && (mUsage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
delete mTexStorage; delete mTexStorage;
mTexStorage = new TextureStorageCubeMap(levels, format, size, renderable); mTexStorage = new TextureStorageCubeMap(levels, format, size, renderTarget);
if (mTexStorage->isManaged()) if (mTexStorage->isManaged())
{ {
@ -2767,14 +2783,14 @@ void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint
unsigned int faceindex = faceIndex(target); unsigned int faceindex = faceIndex(target);
redefineImage(faceindex, level, format, width, height, GL_UNSIGNED_BYTE); redefineImage(faceindex, level, format, width, height, GL_UNSIGNED_BYTE);
if (!mImageArray[faceindex][level].isRenderable()) if (!mImageArray[faceindex][level].isRenderableFormat())
{ {
mImageArray[faceindex][level].copy(0, 0, x, y, width, height, renderTarget); mImageArray[faceindex][level].copy(0, 0, x, y, width, height, renderTarget);
mDirtyImages = true; mDirtyImages = true;
} }
else else
{ {
if (!mTexStorage || !mTexStorage->isRenderable()) if (!mTexStorage || !mTexStorage->isRenderTarget())
{ {
convertToRenderTarget(); convertToRenderTarget();
} }
@ -2825,14 +2841,14 @@ void TextureCubeMap::copySubImage(GLenum target, GLint level, GLint xoffset, GLi
unsigned int faceindex = faceIndex(target); unsigned int faceindex = faceIndex(target);
if (!mImageArray[faceindex][level].isRenderable() || (!mTexStorage && !isSamplerComplete())) if (!mImageArray[faceindex][level].isRenderableFormat() || (!mTexStorage && !isSamplerComplete()))
{ {
mImageArray[faceindex][level].copy(0, 0, x, y, width, height, renderTarget); mImageArray[faceindex][level].copy(0, 0, x, y, width, height, renderTarget);
mDirtyImages = true; mDirtyImages = true;
} }
else else
{ {
if (!mTexStorage || !mTexStorage->isRenderable()) if (!mTexStorage || !mTexStorage->isRenderTarget())
{ {
convertToRenderTarget(); convertToRenderTarget();
} }
@ -2867,10 +2883,10 @@ void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size
GLenum format = gl::ExtractFormat(internalformat); GLenum format = gl::ExtractFormat(internalformat);
GLenum type = gl::ExtractType(internalformat); GLenum type = gl::ExtractType(internalformat);
D3DFORMAT d3dfmt = ConvertTextureFormatType(format, type); D3DFORMAT d3dfmt = ConvertTextureFormatType(format, type);
const bool renderable = (mUsage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE); const bool renderTarget = IsTextureFormatRenderable(d3dfmt) && (mUsage == GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
delete mTexStorage; delete mTexStorage;
mTexStorage = new TextureStorageCubeMap(levels, d3dfmt, size, renderable); mTexStorage = new TextureStorageCubeMap(levels, d3dfmt, size, renderTarget);
mImmutable = true; mImmutable = true;
for (int level = 0; level < levels; level++) for (int level = 0; level < levels; level++)
@ -2933,7 +2949,7 @@ void TextureCubeMap::generateMipmaps()
} }
} }
if (mTexStorage && mTexStorage->isRenderable()) if (mTexStorage && mTexStorage->isRenderTarget())
{ {
for (unsigned int f = 0; f < 6; f++) for (unsigned int f = 0; f < 6; f++)
{ {
@ -2997,12 +3013,8 @@ IDirect3DSurface9 *TextureCubeMap::getRenderTarget(GLenum target)
{ {
ASSERT(IsCubemapTextureTarget(target)); ASSERT(IsCubemapTextureTarget(target));
if (!mTexStorage || !mTexStorage->isRenderable()) // ensure the underlying texture is created
{ if (getStorage(true) == NULL)
convertToRenderTarget();
}
if (mTexStorage == NULL)
{ {
return NULL; return NULL;
} }
@ -3012,8 +3024,20 @@ IDirect3DSurface9 *TextureCubeMap::getRenderTarget(GLenum target)
return mTexStorage->getCubeMapSurface(target, 0); return mTexStorage->getCubeMapSurface(target, 0);
} }
TextureStorage *TextureCubeMap::getStorage() const TextureStorage *TextureCubeMap::getStorage(bool renderTarget)
{ {
if (!mTexStorage || (renderTarget && !mTexStorage->isRenderTarget()))
{
if (renderTarget)
{
convertToRenderTarget();
}
else
{
createTexture();
}
}
return mTexStorage; return mTexStorage;
} }

View File

@ -56,7 +56,7 @@ class Image
HRESULT lock(D3DLOCKED_RECT *lockedRect, const RECT *rect); HRESULT lock(D3DLOCKED_RECT *lockedRect, const RECT *rect);
void unlock(); void unlock();
bool isRenderable() const; bool isRenderableFormat() const;
D3DFORMAT getD3DFormat() const; D3DFORMAT getD3DFormat() const;
GLsizei getWidth() const {return mWidth;} GLsizei getWidth() const {return mWidth;}
@ -144,11 +144,11 @@ class Image
class TextureStorage class TextureStorage
{ {
public: public:
explicit TextureStorage(bool renderable); explicit TextureStorage(bool renderTarget);
virtual ~TextureStorage(); virtual ~TextureStorage();
bool isRenderable() const; bool isRenderTarget() const;
bool isManaged() const; bool isManaged() const;
D3DPOOL getPool() const; D3DPOOL getPool() const;
unsigned int getTextureSerial() const; unsigned int getTextureSerial() const;
@ -157,7 +157,7 @@ class TextureStorage
private: private:
DISALLOW_COPY_AND_ASSIGN(TextureStorage); DISALLOW_COPY_AND_ASSIGN(TextureStorage);
const bool mRenderable; const bool mRenderTarget;
const D3DPOOL mD3DPool; const D3DPOOL mD3DPool;
const unsigned int mTextureSerial; const unsigned int mTextureSerial;
@ -205,8 +205,8 @@ class Texture : public RefCountObject
bool hasDirtyParameters() const; bool hasDirtyParameters() const;
bool hasDirtyImages() const; bool hasDirtyImages() const;
void resetDirty(); void resetDirty();
unsigned int getTextureSerial() const; unsigned int getTextureSerial();
unsigned int getRenderTargetSerial(GLenum target) const; unsigned int getRenderTargetSerial(GLenum target);
bool isImmutable() const; bool isImmutable() const;
@ -248,14 +248,14 @@ class Texture : public RefCountObject
private: private:
DISALLOW_COPY_AND_ASSIGN(Texture); DISALLOW_COPY_AND_ASSIGN(Texture);
virtual TextureStorage *getStorage() const = 0; virtual TextureStorage *getStorage(bool renderTarget) = 0;
}; };
class TextureStorage2D : public TextureStorage class TextureStorage2D : public TextureStorage
{ {
public: public:
explicit TextureStorage2D(IDirect3DTexture9 *surfaceTexture); explicit TextureStorage2D(IDirect3DTexture9 *surfaceTexture);
TextureStorage2D(int levels, D3DFORMAT format, int width, int height, bool renderable); TextureStorage2D(int levels, D3DFORMAT format, int width, int height, bool renderTarget);
virtual ~TextureStorage2D(); virtual ~TextureStorage2D();
@ -311,7 +311,7 @@ class Texture2D : public Texture
virtual void updateTexture(); virtual void updateTexture();
virtual void convertToRenderTarget(); virtual void convertToRenderTarget();
virtual IDirect3DSurface9 *getRenderTarget(GLenum target); virtual IDirect3DSurface9 *getRenderTarget(GLenum target);
virtual TextureStorage *getStorage() const; virtual TextureStorage *getStorage(bool renderTarget);
bool isMipmapComplete() const; bool isMipmapComplete() const;
@ -329,7 +329,7 @@ class Texture2D : public Texture
class TextureStorageCubeMap : public TextureStorage class TextureStorageCubeMap : public TextureStorage
{ {
public: public:
TextureStorageCubeMap(int levels, D3DFORMAT format, int size, bool renderable); TextureStorageCubeMap(int levels, D3DFORMAT format, int size, bool renderTarget);
virtual ~TextureStorageCubeMap(); virtual ~TextureStorageCubeMap();
@ -392,7 +392,7 @@ class TextureCubeMap : public Texture
virtual void updateTexture(); virtual void updateTexture();
virtual void convertToRenderTarget(); virtual void convertToRenderTarget();
virtual IDirect3DSurface9 *getRenderTarget(GLenum target); virtual IDirect3DSurface9 *getRenderTarget(GLenum target);
virtual TextureStorage *getStorage() const; virtual TextureStorage *getStorage(bool renderTarget);
bool isCubeComplete() const; bool isCubeComplete() const;
bool isMipmapCubeComplete() const; bool isMipmapCubeComplete() const;