Eliminate the weak base texture pointer.

TRAC #15703 Issue=86 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@578 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 831fe2af
...@@ -49,7 +49,6 @@ Texture::Texture(GLuint id) : RefCountObject(id) ...@@ -49,7 +49,6 @@ Texture::Texture(GLuint id) : RefCountObject(id)
mDirty = true; mDirty = true;
mIsRenderable = false; mIsRenderable = false;
mType = GL_UNSIGNED_BYTE; mType = GL_UNSIGNED_BYTE;
mBaseTexture = NULL;
} }
Texture::~Texture() Texture::~Texture()
...@@ -1159,7 +1158,7 @@ IDirect3DBaseTexture9 *Texture::getTexture() ...@@ -1159,7 +1158,7 @@ IDirect3DBaseTexture9 *Texture::getTexture()
if (mDirtyMetaData) if (mDirtyMetaData)
{ {
mBaseTexture = createTexture(); createTexture();
mIsRenderable = false; mIsRenderable = false;
} }
...@@ -1171,7 +1170,7 @@ IDirect3DBaseTexture9 *Texture::getTexture() ...@@ -1171,7 +1170,7 @@ IDirect3DBaseTexture9 *Texture::getTexture()
mDirtyMetaData = false; mDirtyMetaData = false;
ASSERT(!dirtyImageData()); ASSERT(!dirtyImageData());
return mBaseTexture; return getBaseTexture();
} }
bool Texture::isDirty() const bool Texture::isDirty() const
...@@ -1184,7 +1183,7 @@ void Texture::needRenderTarget() ...@@ -1184,7 +1183,7 @@ void Texture::needRenderTarget()
{ {
if (!mIsRenderable) if (!mIsRenderable)
{ {
mBaseTexture = convertToRenderTarget(); convertToRenderTarget();
mIsRenderable = true; mIsRenderable = true;
} }
...@@ -1196,25 +1195,6 @@ void Texture::needRenderTarget() ...@@ -1196,25 +1195,6 @@ void Texture::needRenderTarget()
mDirtyMetaData = false; mDirtyMetaData = false;
} }
void Texture::dropTexture()
{
if (mBaseTexture)
{
mBaseTexture = NULL;
}
mIsRenderable = false;
}
void Texture::pushTexture(IDirect3DBaseTexture9 *newTexture, bool renderable)
{
mBaseTexture = newTexture;
mDirtyMetaData = false;
mIsRenderable = renderable;
mDirty = true;
}
GLint Texture::creationLevels(GLsizei width, GLsizei height, GLint maxlevel) const GLint Texture::creationLevels(GLsizei width, GLsizei height, GLint maxlevel) const
{ {
if (isPow2(width) && isPow2(height)) if (isPow2(width) && isPow2(height))
...@@ -1235,12 +1215,7 @@ GLint Texture::creationLevels(GLsizei size, GLint maxlevel) const ...@@ -1235,12 +1215,7 @@ GLint Texture::creationLevels(GLsizei size, GLint maxlevel) const
int Texture::levelCount() const int Texture::levelCount() const
{ {
return mBaseTexture ? mBaseTexture->GetLevelCount() : 0; return getBaseTexture() ? getBaseTexture()->GetLevelCount() : 0;
}
bool Texture::isRenderable() const
{
return mIsRenderable;
} }
Texture2D::Texture2D(GLuint id) : Texture(id) Texture2D::Texture2D(GLuint id) : Texture(id)
...@@ -1311,7 +1286,7 @@ bool Texture2D::redefineTexture(GLint level, GLenum internalFormat, GLsizei widt ...@@ -1311,7 +1286,7 @@ bool Texture2D::redefineTexture(GLint level, GLenum internalFormat, GLsizei widt
{ {
mTexture->Release(); mTexture->Release();
mTexture = NULL; mTexture = NULL;
dropTexture(); mIsRenderable = false;
} }
mWidth = width << level; mWidth = width << level;
...@@ -1405,7 +1380,9 @@ void Texture2D::copyImage(GLint level, GLenum internalFormat, GLint x, GLint y, ...@@ -1405,7 +1380,9 @@ void Texture2D::copyImage(GLint level, GLenum internalFormat, GLint x, GLint y,
if (redefined) if (redefined)
{ {
convertToRenderTarget(); convertToRenderTarget();
pushTexture(mTexture, true); mDirtyMetaData = false;
mIsRenderable = true;
mDirty = true;
} }
else else
{ {
...@@ -1459,7 +1436,9 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo ...@@ -1459,7 +1436,9 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo
if (redefined) if (redefined)
{ {
convertToRenderTarget(); convertToRenderTarget();
pushTexture(mTexture, true); mDirtyMetaData = false;
mIsRenderable = true;
mDirty = true;
} }
else else
{ {
...@@ -1565,8 +1544,13 @@ bool Texture2D::isCompressed() const ...@@ -1565,8 +1544,13 @@ bool Texture2D::isCompressed() const
return IsCompressed(getInternalFormat()); return IsCompressed(getInternalFormat());
} }
// Constructs a Direct3D 9 texture resource from the texture images, or returns an existing one IDirect3DBaseTexture9 *Texture2D::getBaseTexture() const
IDirect3DBaseTexture9 *Texture2D::createTexture() {
return mTexture;
}
// Constructs a Direct3D 9 texture resource from the texture images
void Texture2D::createTexture()
{ {
IDirect3DTexture9 *texture; IDirect3DTexture9 *texture;
...@@ -1578,12 +1562,15 @@ IDirect3DBaseTexture9 *Texture2D::createTexture() ...@@ -1578,12 +1562,15 @@ IDirect3DBaseTexture9 *Texture2D::createTexture()
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY);
}
if (mTexture)
{
mTexture->Release();
} }
if (mTexture) mTexture->Release();
mTexture = texture; mTexture = texture;
return texture;
} }
void Texture2D::updateTexture() void Texture2D::updateTexture()
...@@ -1614,7 +1601,7 @@ void Texture2D::updateTexture() ...@@ -1614,7 +1601,7 @@ void Texture2D::updateTexture()
} }
} }
IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget() void Texture2D::convertToRenderTarget()
{ {
IDirect3DTexture9 *texture = NULL; IDirect3DTexture9 *texture = NULL;
...@@ -1629,7 +1616,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget() ...@@ -1629,7 +1616,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY);
} }
if (mTexture != NULL) if (mTexture != NULL)
...@@ -1646,7 +1633,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget() ...@@ -1646,7 +1633,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
texture->Release(); texture->Release();
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY);
} }
IDirect3DSurface9 *dest; IDirect3DSurface9 *dest;
...@@ -1659,7 +1646,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget() ...@@ -1659,7 +1646,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
texture->Release(); texture->Release();
source->Release(); source->Release();
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY);
} }
display->endScene(); display->endScene();
...@@ -1673,7 +1660,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget() ...@@ -1673,7 +1660,7 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
source->Release(); source->Release();
dest->Release(); dest->Release();
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY);
} }
source->Release(); source->Release();
...@@ -1688,7 +1675,6 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget() ...@@ -1688,7 +1675,6 @@ IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
} }
mTexture = texture; mTexture = texture;
return mTexture;
} }
bool Texture2D::dirtyImageData() const bool Texture2D::dirtyImageData() const
...@@ -1727,7 +1713,7 @@ void Texture2D::generateMipmaps() ...@@ -1727,7 +1713,7 @@ void Texture2D::generateMipmaps()
mImageArray[i].height = std::max(mImageArray[0].height >> i, 1); mImageArray[i].height = std::max(mImageArray[0].height >> i, 1);
} }
if (isRenderable()) if (mIsRenderable)
{ {
if (mTexture == NULL) if (mTexture == NULL)
{ {
...@@ -1998,8 +1984,13 @@ bool TextureCubeMap::isCompressed() const ...@@ -1998,8 +1984,13 @@ bool TextureCubeMap::isCompressed() const
return IsCompressed(getInternalFormat()); return IsCompressed(getInternalFormat());
} }
IDirect3DBaseTexture9 *TextureCubeMap::getBaseTexture() const
{
return mTexture;
}
// Constructs a Direct3D 9 texture resource from the texture images, or returns an existing one // Constructs a Direct3D 9 texture resource from the texture images, or returns an existing one
IDirect3DBaseTexture9 *TextureCubeMap::createTexture() void TextureCubeMap::createTexture()
{ {
IDirect3DDevice9 *device = getDevice(); IDirect3DDevice9 *device = getDevice();
D3DFORMAT format = selectFormat(mImageArray[0][0].format, mType); D3DFORMAT format = selectFormat(mImageArray[0][0].format, mType);
...@@ -2011,13 +2002,15 @@ IDirect3DBaseTexture9 *TextureCubeMap::createTexture() ...@@ -2011,13 +2002,15 @@ IDirect3DBaseTexture9 *TextureCubeMap::createTexture()
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY);
} }
if (mTexture) mTexture->Release(); if (mTexture)
{
mTexture->Release();
}
mTexture = texture; mTexture = texture;
return mTexture;
} }
void TextureCubeMap::updateTexture() void TextureCubeMap::updateTexture()
...@@ -2050,7 +2043,7 @@ void TextureCubeMap::updateTexture() ...@@ -2050,7 +2043,7 @@ void TextureCubeMap::updateTexture()
} }
} }
IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget() void TextureCubeMap::convertToRenderTarget()
{ {
IDirect3DCubeTexture9 *texture = NULL; IDirect3DCubeTexture9 *texture = NULL;
...@@ -2065,7 +2058,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget() ...@@ -2065,7 +2058,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY);
} }
if (mTexture != NULL) if (mTexture != NULL)
...@@ -2084,7 +2077,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget() ...@@ -2084,7 +2077,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
texture->Release(); texture->Release();
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY);
} }
IDirect3DSurface9 *dest; IDirect3DSurface9 *dest;
...@@ -2097,7 +2090,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget() ...@@ -2097,7 +2090,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
texture->Release(); texture->Release();
source->Release(); source->Release();
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY);
} }
display->endScene(); display->endScene();
...@@ -2111,7 +2104,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget() ...@@ -2111,7 +2104,7 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
source->Release(); source->Release();
dest->Release(); dest->Release();
return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL); return error(GL_OUT_OF_MEMORY);
} }
} }
} }
...@@ -2124,7 +2117,6 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget() ...@@ -2124,7 +2117,6 @@ IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
} }
mTexture = texture; mTexture = texture;
return mTexture;
} }
void TextureCubeMap::setImage(int face, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels) void TextureCubeMap::setImage(int face, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels)
...@@ -2198,7 +2190,7 @@ bool TextureCubeMap::redefineTexture(GLint level, GLenum internalFormat, GLsizei ...@@ -2198,7 +2190,7 @@ bool TextureCubeMap::redefineTexture(GLint level, GLenum internalFormat, GLsizei
{ {
mTexture->Release(); mTexture->Release();
mTexture = NULL; mTexture = NULL;
dropTexture(); mIsRenderable = false;
} }
mWidth = width << level; mWidth = width << level;
...@@ -2234,7 +2226,9 @@ void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum internalFormat ...@@ -2234,7 +2226,9 @@ void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum internalFormat
if (redefined) if (redefined)
{ {
convertToRenderTarget(); convertToRenderTarget();
pushTexture(mTexture, true); mDirtyMetaData = false;
mIsRenderable = true;
mDirty = true;
} }
else else
{ {
...@@ -2307,7 +2301,9 @@ void TextureCubeMap::copySubImage(GLenum target, GLint level, GLint xoffset, GLi ...@@ -2307,7 +2301,9 @@ void TextureCubeMap::copySubImage(GLenum target, GLint level, GLint xoffset, GLi
if (redefined) if (redefined)
{ {
convertToRenderTarget(); convertToRenderTarget();
pushTexture(mTexture, true); mDirtyMetaData = false;
mIsRenderable = true;
mDirty = true;
} }
else else
{ {
...@@ -2378,7 +2374,7 @@ void TextureCubeMap::generateMipmaps() ...@@ -2378,7 +2374,7 @@ void TextureCubeMap::generateMipmaps()
} }
} }
if (isRenderable()) if (mIsRenderable)
{ {
if (mTexture == NULL) if (mTexture == NULL)
{ {
......
...@@ -108,24 +108,20 @@ class Texture : public RefCountObject ...@@ -108,24 +108,20 @@ class Texture : public RefCountObject
GLint creationLevels(GLsizei width, GLsizei height, GLint maxlevel) const; GLint creationLevels(GLsizei width, GLsizei height, GLint maxlevel) const;
GLint creationLevels(GLsizei size, GLint maxlevel) const; GLint creationLevels(GLsizei size, GLint maxlevel) const;
// The pointer returned is weak and it is assumed the derived class will keep a strong pointer until the next createTexture() call. virtual IDirect3DBaseTexture9 *getBaseTexture() const = 0;
virtual IDirect3DBaseTexture9 *createTexture() = 0; virtual void createTexture() = 0;
virtual void updateTexture() = 0; virtual void updateTexture() = 0;
virtual IDirect3DBaseTexture9 *convertToRenderTarget() = 0; virtual void convertToRenderTarget() = 0;
virtual IDirect3DSurface9 *getRenderTarget(GLenum target) = 0; virtual IDirect3DSurface9 *getRenderTarget(GLenum target) = 0;
virtual bool dirtyImageData() const = 0; virtual bool dirtyImageData() const = 0;
void dropTexture();
void pushTexture(IDirect3DBaseTexture9 *newTexture, bool renderable);
void createSurface(GLsizei width, GLsizei height, GLenum format, GLenum type, Image *img); void createSurface(GLsizei width, GLsizei height, GLenum format, GLenum type, Image *img);
Blit *getBlitter(); Blit *getBlitter();
int levelCount() const; int levelCount() const;
bool isRenderable() const;
GLsizei mWidth; GLsizei mWidth;
GLsizei mHeight; GLsizei mHeight;
GLenum mMinFilter; GLenum mMinFilter;
...@@ -135,6 +131,8 @@ class Texture : public RefCountObject ...@@ -135,6 +131,8 @@ class Texture : public RefCountObject
GLenum mType; GLenum mType;
bool mDirtyMetaData; bool mDirtyMetaData;
bool mIsRenderable;
bool mDirty;
private: private:
DISALLOW_COPY_AND_ASSIGN(Texture); DISALLOW_COPY_AND_ASSIGN(Texture);
...@@ -182,11 +180,6 @@ class Texture : public RefCountObject ...@@ -182,11 +180,6 @@ class Texture : public RefCountObject
int inputPitch, const void *input, size_t outputPitch, void *output) const; int inputPitch, const void *input, size_t outputPitch, void *output) const;
void loadCompressedImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, void loadCompressedImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
int inputPitch, const void *input, size_t outputPitch, void *output) const; int inputPitch, const void *input, size_t outputPitch, void *output) const;
IDirect3DBaseTexture9 *mBaseTexture; // This is a weak pointer. The derived class is assumed to own a strong pointer.
bool mDirty;
bool mIsRenderable;
}; };
class Texture2D : public Texture class Texture2D : public Texture
...@@ -216,9 +209,10 @@ class Texture2D : public Texture ...@@ -216,9 +209,10 @@ class Texture2D : public Texture
private: private:
DISALLOW_COPY_AND_ASSIGN(Texture2D); DISALLOW_COPY_AND_ASSIGN(Texture2D);
virtual IDirect3DBaseTexture9 *createTexture(); virtual IDirect3DBaseTexture9 *getBaseTexture() const;
virtual void createTexture();
virtual void updateTexture(); virtual void updateTexture();
virtual IDirect3DBaseTexture9 *convertToRenderTarget(); virtual void convertToRenderTarget();
virtual IDirect3DSurface9 *getRenderTarget(GLenum target); virtual IDirect3DSurface9 *getRenderTarget(GLenum target);
virtual bool dirtyImageData() const; virtual bool dirtyImageData() const;
...@@ -267,9 +261,10 @@ class TextureCubeMap : public Texture ...@@ -267,9 +261,10 @@ class TextureCubeMap : public Texture
private: private:
DISALLOW_COPY_AND_ASSIGN(TextureCubeMap); DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
virtual IDirect3DBaseTexture9 *createTexture(); virtual IDirect3DBaseTexture9 *getBaseTexture() const;
virtual void createTexture();
virtual void updateTexture(); virtual void updateTexture();
virtual IDirect3DBaseTexture9 *convertToRenderTarget(); virtual void convertToRenderTarget();
virtual IDirect3DSurface9 *getRenderTarget(GLenum target); virtual IDirect3DSurface9 *getRenderTarget(GLenum target);
virtual bool dirtyImageData() const; virtual bool dirtyImageData() const;
......
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