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
diff --git a/src/libGLESv2/Texture.cpp b/src/libGLESv2/Texture.cpp
index a0f446e..26a47b3 100644
--- a/src/libGLESv2/Texture.cpp
+++ b/src/libGLESv2/Texture.cpp
@@ -49,7 +49,6 @@
mDirty = true;
mIsRenderable = false;
mType = GL_UNSIGNED_BYTE;
- mBaseTexture = NULL;
}
Texture::~Texture()
@@ -1159,7 +1158,7 @@
if (mDirtyMetaData)
{
- mBaseTexture = createTexture();
+ createTexture();
mIsRenderable = false;
}
@@ -1171,7 +1170,7 @@
mDirtyMetaData = false;
ASSERT(!dirtyImageData());
- return mBaseTexture;
+ return getBaseTexture();
}
bool Texture::isDirty() const
@@ -1184,7 +1183,7 @@
{
if (!mIsRenderable)
{
- mBaseTexture = convertToRenderTarget();
+ convertToRenderTarget();
mIsRenderable = true;
}
@@ -1196,25 +1195,6 @@
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
{
if (isPow2(width) && isPow2(height))
@@ -1235,12 +1215,7 @@
int Texture::levelCount() const
{
- return mBaseTexture ? mBaseTexture->GetLevelCount() : 0;
-}
-
-bool Texture::isRenderable() const
-{
- return mIsRenderable;
+ return getBaseTexture() ? getBaseTexture()->GetLevelCount() : 0;
}
Texture2D::Texture2D(GLuint id) : Texture(id)
@@ -1311,7 +1286,7 @@
{
mTexture->Release();
mTexture = NULL;
- dropTexture();
+ mIsRenderable = false;
}
mWidth = width << level;
@@ -1405,7 +1380,9 @@
if (redefined)
{
convertToRenderTarget();
- pushTexture(mTexture, true);
+ mDirtyMetaData = false;
+ mIsRenderable = true;
+ mDirty = true;
}
else
{
@@ -1459,7 +1436,9 @@
if (redefined)
{
convertToRenderTarget();
- pushTexture(mTexture, true);
+ mDirtyMetaData = false;
+ mIsRenderable = true;
+ mDirty = true;
}
else
{
@@ -1565,8 +1544,13 @@
return IsCompressed(getInternalFormat());
}
-// Constructs a Direct3D 9 texture resource from the texture images, or returns an existing one
-IDirect3DBaseTexture9 *Texture2D::createTexture()
+IDirect3DBaseTexture9 *Texture2D::getBaseTexture() const
+{
+ return mTexture;
+}
+
+// Constructs a Direct3D 9 texture resource from the texture images
+void Texture2D::createTexture()
{
IDirect3DTexture9 *texture;
@@ -1578,12 +1562,15 @@
if (FAILED(result))
{
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;
- return texture;
}
void Texture2D::updateTexture()
@@ -1614,7 +1601,7 @@
}
}
-IDirect3DBaseTexture9 *Texture2D::convertToRenderTarget()
+void Texture2D::convertToRenderTarget()
{
IDirect3DTexture9 *texture = NULL;
@@ -1629,7 +1616,7 @@
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
- return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
+ return error(GL_OUT_OF_MEMORY);
}
if (mTexture != NULL)
@@ -1646,7 +1633,7 @@
texture->Release();
- return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
+ return error(GL_OUT_OF_MEMORY);
}
IDirect3DSurface9 *dest;
@@ -1659,7 +1646,7 @@
texture->Release();
source->Release();
- return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
+ return error(GL_OUT_OF_MEMORY);
}
display->endScene();
@@ -1673,7 +1660,7 @@
source->Release();
dest->Release();
- return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
+ return error(GL_OUT_OF_MEMORY);
}
source->Release();
@@ -1688,7 +1675,6 @@
}
mTexture = texture;
- return mTexture;
}
bool Texture2D::dirtyImageData() const
@@ -1727,7 +1713,7 @@
mImageArray[i].height = std::max(mImageArray[0].height >> i, 1);
}
- if (isRenderable())
+ if (mIsRenderable)
{
if (mTexture == NULL)
{
@@ -1998,8 +1984,13 @@
return IsCompressed(getInternalFormat());
}
+IDirect3DBaseTexture9 *TextureCubeMap::getBaseTexture() const
+{
+ return mTexture;
+}
+
// Constructs a Direct3D 9 texture resource from the texture images, or returns an existing one
-IDirect3DBaseTexture9 *TextureCubeMap::createTexture()
+void TextureCubeMap::createTexture()
{
IDirect3DDevice9 *device = getDevice();
D3DFORMAT format = selectFormat(mImageArray[0][0].format, mType);
@@ -2011,13 +2002,15 @@
if (FAILED(result))
{
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;
- return mTexture;
}
void TextureCubeMap::updateTexture()
@@ -2050,7 +2043,7 @@
}
}
-IDirect3DBaseTexture9 *TextureCubeMap::convertToRenderTarget()
+void TextureCubeMap::convertToRenderTarget()
{
IDirect3DCubeTexture9 *texture = NULL;
@@ -2065,7 +2058,7 @@
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
- return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
+ return error(GL_OUT_OF_MEMORY);
}
if (mTexture != NULL)
@@ -2084,7 +2077,7 @@
texture->Release();
- return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
+ return error(GL_OUT_OF_MEMORY);
}
IDirect3DSurface9 *dest;
@@ -2097,7 +2090,7 @@
texture->Release();
source->Release();
- return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
+ return error(GL_OUT_OF_MEMORY);
}
display->endScene();
@@ -2111,7 +2104,7 @@
source->Release();
dest->Release();
- return error(GL_OUT_OF_MEMORY, (IDirect3DBaseTexture9*)NULL);
+ return error(GL_OUT_OF_MEMORY);
}
}
}
@@ -2124,7 +2117,6 @@
}
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)
@@ -2198,7 +2190,7 @@
{
mTexture->Release();
mTexture = NULL;
- dropTexture();
+ mIsRenderable = false;
}
mWidth = width << level;
@@ -2234,7 +2226,9 @@
if (redefined)
{
convertToRenderTarget();
- pushTexture(mTexture, true);
+ mDirtyMetaData = false;
+ mIsRenderable = true;
+ mDirty = true;
}
else
{
@@ -2307,7 +2301,9 @@
if (redefined)
{
convertToRenderTarget();
- pushTexture(mTexture, true);
+ mDirtyMetaData = false;
+ mIsRenderable = true;
+ mDirty = true;
}
else
{
@@ -2378,7 +2374,7 @@
}
}
- if (isRenderable())
+ if (mIsRenderable)
{
if (mTexture == NULL)
{
diff --git a/src/libGLESv2/Texture.h b/src/libGLESv2/Texture.h
index 4060b32..6ee49f6 100644
--- a/src/libGLESv2/Texture.h
+++ b/src/libGLESv2/Texture.h
@@ -108,24 +108,20 @@
GLint creationLevels(GLsizei width, GLsizei height, 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 *createTexture() = 0;
+ virtual IDirect3DBaseTexture9 *getBaseTexture() const = 0;
+ virtual void createTexture() = 0;
virtual void updateTexture() = 0;
- virtual IDirect3DBaseTexture9 *convertToRenderTarget() = 0;
+ virtual void convertToRenderTarget() = 0;
virtual IDirect3DSurface9 *getRenderTarget(GLenum target) = 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);
Blit *getBlitter();
int levelCount() const;
- bool isRenderable() const;
-
GLsizei mWidth;
GLsizei mHeight;
GLenum mMinFilter;
@@ -135,6 +131,8 @@
GLenum mType;
bool mDirtyMetaData;
+ bool mIsRenderable;
+ bool mDirty;
private:
DISALLOW_COPY_AND_ASSIGN(Texture);
@@ -182,11 +180,6 @@
int inputPitch, const void *input, size_t outputPitch, void *output) const;
void loadCompressedImageData(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
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
@@ -216,9 +209,10 @@
private:
DISALLOW_COPY_AND_ASSIGN(Texture2D);
- virtual IDirect3DBaseTexture9 *createTexture();
+ virtual IDirect3DBaseTexture9 *getBaseTexture() const;
+ virtual void createTexture();
virtual void updateTexture();
- virtual IDirect3DBaseTexture9 *convertToRenderTarget();
+ virtual void convertToRenderTarget();
virtual IDirect3DSurface9 *getRenderTarget(GLenum target);
virtual bool dirtyImageData() const;
@@ -267,9 +261,10 @@
private:
DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
- virtual IDirect3DBaseTexture9 *createTexture();
+ virtual IDirect3DBaseTexture9 *getBaseTexture() const;
+ virtual void createTexture();
virtual void updateTexture();
- virtual IDirect3DBaseTexture9 *convertToRenderTarget();
+ virtual void convertToRenderTarget();
virtual IDirect3DSurface9 *getRenderTarget(GLenum target);
virtual bool dirtyImageData() const;