Support redefinition of textures through glTexImage2D.

TRAC #11316. Keep a dirty data flag, recreate the texture when it is set. Texture now owns getTexture() and calls a virtual createTexture method when the derived classes need to recreate. Signed-off-by: Daniel Koch Author: Andrew Lewycky <andrew.lewycky@transgaming.com> git-svn-id: https://angleproject.googlecode.com/svn/trunk@12 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent fab5a1ae
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <d3d9.h> #include <d3d9.h>
#include <vector>
namespace gl namespace gl
{ {
enum enum
...@@ -27,17 +29,6 @@ enum ...@@ -27,17 +29,6 @@ enum
MAX_TEXTURE_LEVELS = 11 // log2 of MAX_TEXTURE_SIZE MAX_TEXTURE_LEVELS = 11 // log2 of MAX_TEXTURE_SIZE
}; };
// Helper structure representing a single image layer
struct Image
{
GLenum internalFormat;
GLsizei width;
GLsizei height;
GLenum format;
GLenum type;
void *pixels;
};
class Texture : public Colorbuffer class Texture : public Colorbuffer
{ {
public: public:
...@@ -58,10 +49,22 @@ class Texture : public Colorbuffer ...@@ -58,10 +49,22 @@ class Texture : public Colorbuffer
GLenum getWrapT(); GLenum getWrapT();
virtual bool isComplete() = 0; virtual bool isComplete() = 0;
virtual IDirect3DBaseTexture9 *getTexture() = 0; IDirect3DBaseTexture9 *getTexture();
protected: protected:
void copyImage(D3DLOCKED_RECT &lock, D3DFORMAT format, Image &image); // Helper structure representing a single image layer
struct Image
{
GLenum internalFormat;
GLsizei width;
GLsizei height;
GLenum format;
GLenum type;
std::vector<unsigned char> pixels;
};
void copyImage(const D3DLOCKED_RECT &lock, D3DFORMAT format, Image *image);
static D3DFORMAT selectFormat(const Image &image); static D3DFORMAT selectFormat(const Image &image);
static int pixelSize(const Image &image); static int pixelSize(const Image &image);
...@@ -71,8 +74,17 @@ class Texture : public Colorbuffer ...@@ -71,8 +74,17 @@ class Texture : public Colorbuffer
GLenum mWrapS; GLenum mWrapS;
GLenum mWrapT; GLenum mWrapT;
void setImage(GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels, Image *img);
// 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;
bool mDirtyImageData; // FIXME: would be private but getRenderTarget is still implemented through the derived classes and they need it.
private: private:
DISALLOW_COPY_AND_ASSIGN(Texture); DISALLOW_COPY_AND_ASSIGN(Texture);
IDirect3DBaseTexture9 *mBaseTexture; // This is a weak pointer. The derived class is assumed to own a strong pointer.
}; };
class Texture2D : public Texture class Texture2D : public Texture
...@@ -97,12 +109,13 @@ class Texture2D : public Texture ...@@ -97,12 +109,13 @@ class Texture2D : public Texture
GLenum getWrapT(); GLenum getWrapT();
bool isComplete(); bool isComplete();
IDirect3DBaseTexture9 *getTexture();
IDirect3DSurface9 *getRenderTarget(); IDirect3DSurface9 *getRenderTarget();
private: private:
DISALLOW_COPY_AND_ASSIGN(Texture2D); DISALLOW_COPY_AND_ASSIGN(Texture2D);
virtual IDirect3DBaseTexture9 *createTexture();
Image mImageArray[MAX_TEXTURE_LEVELS]; Image mImageArray[MAX_TEXTURE_LEVELS];
IDirect3DTexture9 *mTexture; IDirect3DTexture9 *mTexture;
...@@ -125,11 +138,12 @@ class TextureCubeMap : public Texture ...@@ -125,11 +138,12 @@ class TextureCubeMap : public Texture
void setImageNegZ(GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); void setImageNegZ(GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
bool isComplete(); bool isComplete();
IDirect3DBaseTexture9 *getTexture();
private: private:
DISALLOW_COPY_AND_ASSIGN(TextureCubeMap); DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
virtual IDirect3DBaseTexture9 *createTexture();
void setImage(int face, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); void setImage(int face, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
Image mImageArray[6][MAX_TEXTURE_LEVELS]; Image mImageArray[6][MAX_TEXTURE_LEVELS];
......
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