Texture2D::Texture2D(GLuint name) : Texture(name)
{
- for(int i = 0; i < IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
- {
- image[i] = nullptr;
- }
-
mSurface = nullptr;
mColorbufferProxy = nullptr;
Texture2D::~Texture2D()
{
- for(int i = 0; i < IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
- {
- if(image[i])
- {
- image[i]->unbind(this);
- image[i] = nullptr;
- }
- }
+ image.unbind(this);
if(mSurface)
{
void Texture2D::bindTexImage(gl::Surface *surface)
{
- for(int level = 0; level < IMPLEMENTATION_MAX_TEXTURE_LEVELS; level++)
- {
- if(image[level])
- {
- image[level]->release();
- image[level] = nullptr;
- }
- }
+ image.release();
image[0] = surface->getRenderTarget();
void Texture2D::releaseTexImage()
{
- for(int level = 0; level < IMPLEMENTATION_MAX_TEXTURE_LEVELS; level++)
- {
- if(image[level])
- {
- image[level]->release();
- image[level] = nullptr;
- }
- }
+ image.release();
if(mSurface)
{
{
for(int f = 0; f < 6; f++)
{
- for(int i = 0; i < IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
- {
- image[f][i] = nullptr;
- }
- }
-
- for(int f = 0; f < 6; f++)
- {
mFaceProxies[f] = nullptr;
mFaceProxyRefs[f] = 0;
}
TextureCubeMap::~TextureCubeMap()
{
- for(int f = 0; f < 6; f++)
- {
- for(int i = 0; i < IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
- {
- if(image[f][i])
- {
- image[f][i]->unbind(this);
- image[f][i] = nullptr;
- }
- }
- }
-
for(int i = 0; i < 6; i++)
{
+ image[i].unbind(this);
mFaceProxies[i] = nullptr;
}
}
Texture3D::Texture3D(GLuint name) : Texture(name)
{
- for(int i = 0; i < IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
- {
- image[i] = nullptr;
- }
-
mSurface = nullptr;
mColorbufferProxy = nullptr;
Texture3D::~Texture3D()
{
- for(int i = 0; i < IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
- {
- if(image[i])
- {
- image[i]->unbind(this);
- image[i] = nullptr;
- }
- }
+ image.unbind(this);
if(mSurface)
{
IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = sw::OUTLINE_RESOLUTION,
};
+class ImageLevels
+{
+public:
+ inline const egl::Image* operator[](size_t index) const
+ {
+ return (index < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? image[index] : nullptr;
+ }
+
+ inline egl::Image*& operator[](size_t index)
+ {
+ if(index < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
+ {
+ return image[index];
+ }
+
+ static egl::Image* nullImage;
+ nullImage = nullptr;
+ return nullImage;
+ }
+
+ inline void release()
+ {
+ for(int i = 0; i < IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
+ {
+ if(image[i])
+ {
+ image[i]->release();
+ image[i] = nullptr;
+ }
+ }
+ }
+
+ inline void unbind(const egl::Texture* texture)
+ {
+ for(int i = 0; i < IMPLEMENTATION_MAX_TEXTURE_LEVELS; i++)
+ {
+ if(image[i])
+ {
+ image[i]->unbind(texture);
+ image[i] = nullptr;
+ }
+ }
+ }
+
+private:
+ egl::Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS] = {};
+};
+
class Texture : public egl::Texture
{
public:
bool isMipmapComplete() const;
- egl::Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
+ ImageLevels image;
gl::Surface *mSurface;
// face is one of the GL_TEXTURE_CUBE_MAP_* enumerants. Returns nullptr on failure.
egl::Image *getImage(GLenum face, unsigned int level);
- egl::Image *image[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];
+ ImageLevels image[6];
// A specific internal reference count is kept for colorbuffer proxy references,
// because, as the renderbuffer acting as proxy will maintain a binding pointer
bool isMipmapComplete() const;
- egl::Image *image[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
+ ImageLevels image;
gl::Surface *mSurface;