gfx/angle/src/libGLESv2/Texture.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/angle/src/libGLESv2/Texture.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,275 @@
     1.4 +//
     1.5 +// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
     1.6 +// Use of this source code is governed by a BSD-style license that can be
     1.7 +// found in the LICENSE file.
     1.8 +//
     1.9 +
    1.10 +// Texture.h: Defines the abstract gl::Texture class and its concrete derived
    1.11 +// classes Texture2D and TextureCubeMap. Implements GL texture objects and
    1.12 +// related functionality. [OpenGL ES 2.0.24] section 3.7 page 63.
    1.13 +
    1.14 +#ifndef LIBGLESV2_TEXTURE_H_
    1.15 +#define LIBGLESV2_TEXTURE_H_
    1.16 +
    1.17 +#include <vector>
    1.18 +
    1.19 +#define GL_APICALL
    1.20 +#include <GLES2/gl2.h>
    1.21 +
    1.22 +#include "common/debug.h"
    1.23 +#include "common/RefCountObject.h"
    1.24 +#include "libGLESv2/angletypes.h"
    1.25 +
    1.26 +namespace egl
    1.27 +{
    1.28 +class Surface;
    1.29 +}
    1.30 +
    1.31 +namespace rx
    1.32 +{
    1.33 +class Renderer;
    1.34 +class TextureStorageInterface;
    1.35 +class TextureStorageInterface2D;
    1.36 +class TextureStorageInterfaceCube;
    1.37 +class RenderTarget;
    1.38 +class Image;
    1.39 +}
    1.40 +
    1.41 +namespace gl
    1.42 +{
    1.43 +class Framebuffer;
    1.44 +class Renderbuffer;
    1.45 +
    1.46 +enum
    1.47 +{
    1.48 +    // These are the maximums the implementation can support
    1.49 +    // The actual GL caps are limited by the device caps
    1.50 +    // and should be queried from the Context
    1.51 +    IMPLEMENTATION_MAX_TEXTURE_SIZE = 16384,
    1.52 +    IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 16384,
    1.53 +
    1.54 +    IMPLEMENTATION_MAX_TEXTURE_LEVELS = 15   // 1+log2 of MAX_TEXTURE_SIZE
    1.55 +};
    1.56 +
    1.57 +class Texture : public RefCountObject
    1.58 +{
    1.59 +  public:
    1.60 +    Texture(rx::Renderer *renderer, GLuint id);
    1.61 +
    1.62 +    virtual ~Texture();
    1.63 +
    1.64 +    virtual void addProxyRef(const Renderbuffer *proxy) = 0;
    1.65 +    virtual void releaseProxy(const Renderbuffer *proxy) = 0;
    1.66 +
    1.67 +    virtual GLenum getTarget() const = 0;
    1.68 +
    1.69 +    bool setMinFilter(GLenum filter);
    1.70 +    bool setMagFilter(GLenum filter);
    1.71 +    bool setWrapS(GLenum wrap);
    1.72 +    bool setWrapT(GLenum wrap);
    1.73 +    bool setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy);
    1.74 +    bool setUsage(GLenum usage);
    1.75 +
    1.76 +    GLenum getMinFilter() const;
    1.77 +    GLenum getMagFilter() const;
    1.78 +    GLenum getWrapS() const;
    1.79 +    GLenum getWrapT() const;
    1.80 +    float getMaxAnisotropy() const;
    1.81 +    int getLodOffset();
    1.82 +    void getSamplerState(SamplerState *sampler);
    1.83 +    GLenum getUsage() const;
    1.84 +    bool isMipmapFiltered() const;
    1.85 +
    1.86 +    virtual bool isSamplerComplete() const = 0;
    1.87 +
    1.88 +    rx::TextureStorageInterface *getNativeTexture();
    1.89 +    virtual Renderbuffer *getRenderbuffer(GLenum target) = 0;
    1.90 +
    1.91 +    virtual void generateMipmaps() = 0;
    1.92 +    virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0;
    1.93 +
    1.94 +    bool hasDirtyParameters() const;
    1.95 +    bool hasDirtyImages() const;
    1.96 +    void resetDirty();
    1.97 +    unsigned int getTextureSerial();
    1.98 +    unsigned int getRenderTargetSerial(GLenum target);
    1.99 +
   1.100 +    bool isImmutable() const;
   1.101 +
   1.102 +    static const GLuint INCOMPLETE_TEXTURE_ID = static_cast<GLuint>(-1);   // Every texture takes an id at creation time. The value is arbitrary because it is never registered with the resource manager.
   1.103 +
   1.104 +  protected:
   1.105 +    void setImage(GLint unpackAlignment, const void *pixels, rx::Image *image);
   1.106 +    bool subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, rx::Image *image);
   1.107 +    void setCompressedImage(GLsizei imageSize, const void *pixels, rx::Image *image);
   1.108 +    bool subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, rx::Image *image);
   1.109 +
   1.110 +    GLint creationLevels(GLsizei width, GLsizei height) const;
   1.111 +    GLint creationLevels(GLsizei size) const;
   1.112 +
   1.113 +    virtual void createTexture() = 0;
   1.114 +    virtual void updateTexture() = 0;
   1.115 +    virtual void convertToRenderTarget() = 0;
   1.116 +    virtual rx::RenderTarget *getRenderTarget(GLenum target) = 0;
   1.117 +
   1.118 +    virtual int levelCount() = 0;
   1.119 +
   1.120 +    rx::Renderer *mRenderer;
   1.121 +
   1.122 +    SamplerState mSamplerState;
   1.123 +    GLenum mUsage;
   1.124 +
   1.125 +    bool mDirtyImages;
   1.126 +
   1.127 +    bool mImmutable;
   1.128 +
   1.129 +  private:
   1.130 +    DISALLOW_COPY_AND_ASSIGN(Texture);
   1.131 +
   1.132 +    virtual rx::TextureStorageInterface *getStorage(bool renderTarget) = 0;
   1.133 +};
   1.134 +
   1.135 +class Texture2D : public Texture
   1.136 +{
   1.137 +  public:
   1.138 +    Texture2D(rx::Renderer *renderer, GLuint id);
   1.139 +
   1.140 +    ~Texture2D();
   1.141 +
   1.142 +    void addProxyRef(const Renderbuffer *proxy);
   1.143 +    void releaseProxy(const Renderbuffer *proxy);
   1.144 +
   1.145 +    virtual GLenum getTarget() const;
   1.146 +
   1.147 +    GLsizei getWidth(GLint level) const;
   1.148 +    GLsizei getHeight(GLint level) const;
   1.149 +    GLenum getInternalFormat(GLint level) const;
   1.150 +    GLenum getActualFormat(GLint level) const;
   1.151 +    bool isCompressed(GLint level) const;
   1.152 +    bool isDepth(GLint level) const;
   1.153 +
   1.154 +    void setImage(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
   1.155 +    void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
   1.156 +    void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
   1.157 +    void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
   1.158 +    void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
   1.159 +    virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
   1.160 +    void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
   1.161 +
   1.162 +    virtual bool isSamplerComplete() const;
   1.163 +    virtual void bindTexImage(egl::Surface *surface);
   1.164 +    virtual void releaseTexImage();
   1.165 +
   1.166 +    virtual void generateMipmaps();
   1.167 +
   1.168 +    virtual Renderbuffer *getRenderbuffer(GLenum target);
   1.169 +
   1.170 +  protected:
   1.171 +    friend class RenderbufferTexture2D;
   1.172 +    virtual rx::RenderTarget *getRenderTarget(GLenum target);
   1.173 +    virtual rx::RenderTarget *getDepthStencil(GLenum target);
   1.174 +    virtual int levelCount();
   1.175 +
   1.176 +  private:
   1.177 +    DISALLOW_COPY_AND_ASSIGN(Texture2D);
   1.178 +
   1.179 +    virtual void createTexture();
   1.180 +    virtual void updateTexture();
   1.181 +    virtual void convertToRenderTarget();
   1.182 +    virtual rx::TextureStorageInterface *getStorage(bool renderTarget);
   1.183 +
   1.184 +    bool isMipmapComplete() const;
   1.185 +
   1.186 +    void redefineImage(GLint level, GLint internalformat, GLsizei width, GLsizei height);
   1.187 +    void commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
   1.188 +
   1.189 +    rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
   1.190 +
   1.191 +    rx::TextureStorageInterface2D *mTexStorage;
   1.192 +    egl::Surface *mSurface;
   1.193 +
   1.194 +    // A specific internal reference count is kept for colorbuffer proxy references,
   1.195 +    // because, as the renderbuffer acting as proxy will maintain a binding pointer
   1.196 +    // back to this texture, there would be a circular reference if we used a binding
   1.197 +    // pointer here. This reference count will cause the pointer to be set to NULL if
   1.198 +    // the count drops to zero, but will not cause deletion of the Renderbuffer.
   1.199 +    Renderbuffer *mColorbufferProxy;
   1.200 +    unsigned int mProxyRefs;
   1.201 +};
   1.202 +
   1.203 +class TextureCubeMap : public Texture
   1.204 +{
   1.205 +  public:
   1.206 +    TextureCubeMap(rx::Renderer *renderer, GLuint id);
   1.207 +
   1.208 +    ~TextureCubeMap();
   1.209 +
   1.210 +    void addProxyRef(const Renderbuffer *proxy);
   1.211 +    void releaseProxy(const Renderbuffer *proxy);
   1.212 +
   1.213 +    virtual GLenum getTarget() const;
   1.214 +    
   1.215 +    GLsizei getWidth(GLenum target, GLint level) const;
   1.216 +    GLsizei getHeight(GLenum target, GLint level) const;
   1.217 +    GLenum getInternalFormat(GLenum target, GLint level) const;
   1.218 +    GLenum getActualFormat(GLenum target, GLint level) const;
   1.219 +    bool isCompressed(GLenum target, GLint level) const;
   1.220 +
   1.221 +    void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
   1.222 +    void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
   1.223 +    void setImagePosY(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
   1.224 +    void setImageNegY(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
   1.225 +    void setImagePosZ(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
   1.226 +    void setImageNegZ(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
   1.227 +
   1.228 +    void setCompressedImage(GLenum face, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
   1.229 +
   1.230 +    void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
   1.231 +    void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
   1.232 +    void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
   1.233 +    virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
   1.234 +    void storage(GLsizei levels, GLenum internalformat, GLsizei size);
   1.235 +
   1.236 +    virtual bool isSamplerComplete() const;
   1.237 +
   1.238 +    virtual void generateMipmaps();
   1.239 +
   1.240 +    virtual Renderbuffer *getRenderbuffer(GLenum target);
   1.241 +
   1.242 +    static unsigned int faceIndex(GLenum face);
   1.243 +
   1.244 +  protected:
   1.245 +    friend class RenderbufferTextureCubeMap;
   1.246 +    virtual rx::RenderTarget *getRenderTarget(GLenum target);
   1.247 +    virtual int levelCount();
   1.248 +
   1.249 +  private:
   1.250 +    DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
   1.251 +
   1.252 +    virtual void createTexture();
   1.253 +    virtual void updateTexture();
   1.254 +    virtual void convertToRenderTarget();
   1.255 +    virtual rx::TextureStorageInterface *getStorage(bool renderTarget);
   1.256 +
   1.257 +    bool isCubeComplete() const;
   1.258 +    bool isMipmapCubeComplete() const;
   1.259 +
   1.260 +    void setImage(int faceIndex, GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
   1.261 +    void commitRect(int faceIndex, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
   1.262 +    void redefineImage(int faceIndex, GLint level, GLint internalformat, GLsizei width, GLsizei height);
   1.263 +
   1.264 +    rx::Image *mImageArray[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];
   1.265 +
   1.266 +    rx::TextureStorageInterfaceCube *mTexStorage;
   1.267 +
   1.268 +    // A specific internal reference count is kept for colorbuffer proxy references,
   1.269 +    // because, as the renderbuffer acting as proxy will maintain a binding pointer
   1.270 +    // back to this texture, there would be a circular reference if we used a binding
   1.271 +    // pointer here. This reference count will cause the pointer to be set to NULL if
   1.272 +    // the count drops to zero, but will not cause deletion of the Renderbuffer.
   1.273 +    Renderbuffer *mFaceProxies[6];
   1.274 +    unsigned int *mFaceProxyRefs[6];
   1.275 +};
   1.276 +}
   1.277 +
   1.278 +#endif   // LIBGLESV2_TEXTURE_H_

mercurial