Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // |
michael@0 | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
michael@0 | 3 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | // found in the LICENSE file. |
michael@0 | 5 | // |
michael@0 | 6 | |
michael@0 | 7 | // Texture.h: Defines the abstract gl::Texture class and its concrete derived |
michael@0 | 8 | // classes Texture2D and TextureCubeMap. Implements GL texture objects and |
michael@0 | 9 | // related functionality. [OpenGL ES 2.0.24] section 3.7 page 63. |
michael@0 | 10 | |
michael@0 | 11 | #ifndef LIBGLESV2_TEXTURE_H_ |
michael@0 | 12 | #define LIBGLESV2_TEXTURE_H_ |
michael@0 | 13 | |
michael@0 | 14 | #include <vector> |
michael@0 | 15 | |
michael@0 | 16 | #define GL_APICALL |
michael@0 | 17 | #include <GLES2/gl2.h> |
michael@0 | 18 | |
michael@0 | 19 | #include "common/debug.h" |
michael@0 | 20 | #include "common/RefCountObject.h" |
michael@0 | 21 | #include "libGLESv2/angletypes.h" |
michael@0 | 22 | |
michael@0 | 23 | namespace egl |
michael@0 | 24 | { |
michael@0 | 25 | class Surface; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | namespace rx |
michael@0 | 29 | { |
michael@0 | 30 | class Renderer; |
michael@0 | 31 | class TextureStorageInterface; |
michael@0 | 32 | class TextureStorageInterface2D; |
michael@0 | 33 | class TextureStorageInterfaceCube; |
michael@0 | 34 | class RenderTarget; |
michael@0 | 35 | class Image; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | namespace gl |
michael@0 | 39 | { |
michael@0 | 40 | class Framebuffer; |
michael@0 | 41 | class Renderbuffer; |
michael@0 | 42 | |
michael@0 | 43 | enum |
michael@0 | 44 | { |
michael@0 | 45 | // These are the maximums the implementation can support |
michael@0 | 46 | // The actual GL caps are limited by the device caps |
michael@0 | 47 | // and should be queried from the Context |
michael@0 | 48 | IMPLEMENTATION_MAX_TEXTURE_SIZE = 16384, |
michael@0 | 49 | IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 16384, |
michael@0 | 50 | |
michael@0 | 51 | IMPLEMENTATION_MAX_TEXTURE_LEVELS = 15 // 1+log2 of MAX_TEXTURE_SIZE |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | class Texture : public RefCountObject |
michael@0 | 55 | { |
michael@0 | 56 | public: |
michael@0 | 57 | Texture(rx::Renderer *renderer, GLuint id); |
michael@0 | 58 | |
michael@0 | 59 | virtual ~Texture(); |
michael@0 | 60 | |
michael@0 | 61 | virtual void addProxyRef(const Renderbuffer *proxy) = 0; |
michael@0 | 62 | virtual void releaseProxy(const Renderbuffer *proxy) = 0; |
michael@0 | 63 | |
michael@0 | 64 | virtual GLenum getTarget() const = 0; |
michael@0 | 65 | |
michael@0 | 66 | bool setMinFilter(GLenum filter); |
michael@0 | 67 | bool setMagFilter(GLenum filter); |
michael@0 | 68 | bool setWrapS(GLenum wrap); |
michael@0 | 69 | bool setWrapT(GLenum wrap); |
michael@0 | 70 | bool setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy); |
michael@0 | 71 | bool setUsage(GLenum usage); |
michael@0 | 72 | |
michael@0 | 73 | GLenum getMinFilter() const; |
michael@0 | 74 | GLenum getMagFilter() const; |
michael@0 | 75 | GLenum getWrapS() const; |
michael@0 | 76 | GLenum getWrapT() const; |
michael@0 | 77 | float getMaxAnisotropy() const; |
michael@0 | 78 | int getLodOffset(); |
michael@0 | 79 | void getSamplerState(SamplerState *sampler); |
michael@0 | 80 | GLenum getUsage() const; |
michael@0 | 81 | bool isMipmapFiltered() const; |
michael@0 | 82 | |
michael@0 | 83 | virtual bool isSamplerComplete() const = 0; |
michael@0 | 84 | |
michael@0 | 85 | rx::TextureStorageInterface *getNativeTexture(); |
michael@0 | 86 | virtual Renderbuffer *getRenderbuffer(GLenum target) = 0; |
michael@0 | 87 | |
michael@0 | 88 | virtual void generateMipmaps() = 0; |
michael@0 | 89 | virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0; |
michael@0 | 90 | |
michael@0 | 91 | bool hasDirtyParameters() const; |
michael@0 | 92 | bool hasDirtyImages() const; |
michael@0 | 93 | void resetDirty(); |
michael@0 | 94 | unsigned int getTextureSerial(); |
michael@0 | 95 | unsigned int getRenderTargetSerial(GLenum target); |
michael@0 | 96 | |
michael@0 | 97 | bool isImmutable() const; |
michael@0 | 98 | |
michael@0 | 99 | 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. |
michael@0 | 100 | |
michael@0 | 101 | protected: |
michael@0 | 102 | void setImage(GLint unpackAlignment, const void *pixels, rx::Image *image); |
michael@0 | 103 | bool subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, rx::Image *image); |
michael@0 | 104 | void setCompressedImage(GLsizei imageSize, const void *pixels, rx::Image *image); |
michael@0 | 105 | bool subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels, rx::Image *image); |
michael@0 | 106 | |
michael@0 | 107 | GLint creationLevels(GLsizei width, GLsizei height) const; |
michael@0 | 108 | GLint creationLevels(GLsizei size) const; |
michael@0 | 109 | |
michael@0 | 110 | virtual void createTexture() = 0; |
michael@0 | 111 | virtual void updateTexture() = 0; |
michael@0 | 112 | virtual void convertToRenderTarget() = 0; |
michael@0 | 113 | virtual rx::RenderTarget *getRenderTarget(GLenum target) = 0; |
michael@0 | 114 | |
michael@0 | 115 | virtual int levelCount() = 0; |
michael@0 | 116 | |
michael@0 | 117 | rx::Renderer *mRenderer; |
michael@0 | 118 | |
michael@0 | 119 | SamplerState mSamplerState; |
michael@0 | 120 | GLenum mUsage; |
michael@0 | 121 | |
michael@0 | 122 | bool mDirtyImages; |
michael@0 | 123 | |
michael@0 | 124 | bool mImmutable; |
michael@0 | 125 | |
michael@0 | 126 | private: |
michael@0 | 127 | DISALLOW_COPY_AND_ASSIGN(Texture); |
michael@0 | 128 | |
michael@0 | 129 | virtual rx::TextureStorageInterface *getStorage(bool renderTarget) = 0; |
michael@0 | 130 | }; |
michael@0 | 131 | |
michael@0 | 132 | class Texture2D : public Texture |
michael@0 | 133 | { |
michael@0 | 134 | public: |
michael@0 | 135 | Texture2D(rx::Renderer *renderer, GLuint id); |
michael@0 | 136 | |
michael@0 | 137 | ~Texture2D(); |
michael@0 | 138 | |
michael@0 | 139 | void addProxyRef(const Renderbuffer *proxy); |
michael@0 | 140 | void releaseProxy(const Renderbuffer *proxy); |
michael@0 | 141 | |
michael@0 | 142 | virtual GLenum getTarget() const; |
michael@0 | 143 | |
michael@0 | 144 | GLsizei getWidth(GLint level) const; |
michael@0 | 145 | GLsizei getHeight(GLint level) const; |
michael@0 | 146 | GLenum getInternalFormat(GLint level) const; |
michael@0 | 147 | GLenum getActualFormat(GLint level) const; |
michael@0 | 148 | bool isCompressed(GLint level) const; |
michael@0 | 149 | bool isDepth(GLint level) const; |
michael@0 | 150 | |
michael@0 | 151 | void setImage(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
michael@0 | 152 | void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels); |
michael@0 | 153 | void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
michael@0 | 154 | void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels); |
michael@0 | 155 | void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source); |
michael@0 | 156 | virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source); |
michael@0 | 157 | void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); |
michael@0 | 158 | |
michael@0 | 159 | virtual bool isSamplerComplete() const; |
michael@0 | 160 | virtual void bindTexImage(egl::Surface *surface); |
michael@0 | 161 | virtual void releaseTexImage(); |
michael@0 | 162 | |
michael@0 | 163 | virtual void generateMipmaps(); |
michael@0 | 164 | |
michael@0 | 165 | virtual Renderbuffer *getRenderbuffer(GLenum target); |
michael@0 | 166 | |
michael@0 | 167 | protected: |
michael@0 | 168 | friend class RenderbufferTexture2D; |
michael@0 | 169 | virtual rx::RenderTarget *getRenderTarget(GLenum target); |
michael@0 | 170 | virtual rx::RenderTarget *getDepthStencil(GLenum target); |
michael@0 | 171 | virtual int levelCount(); |
michael@0 | 172 | |
michael@0 | 173 | private: |
michael@0 | 174 | DISALLOW_COPY_AND_ASSIGN(Texture2D); |
michael@0 | 175 | |
michael@0 | 176 | virtual void createTexture(); |
michael@0 | 177 | virtual void updateTexture(); |
michael@0 | 178 | virtual void convertToRenderTarget(); |
michael@0 | 179 | virtual rx::TextureStorageInterface *getStorage(bool renderTarget); |
michael@0 | 180 | |
michael@0 | 181 | bool isMipmapComplete() const; |
michael@0 | 182 | |
michael@0 | 183 | void redefineImage(GLint level, GLint internalformat, GLsizei width, GLsizei height); |
michael@0 | 184 | void commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height); |
michael@0 | 185 | |
michael@0 | 186 | rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS]; |
michael@0 | 187 | |
michael@0 | 188 | rx::TextureStorageInterface2D *mTexStorage; |
michael@0 | 189 | egl::Surface *mSurface; |
michael@0 | 190 | |
michael@0 | 191 | // A specific internal reference count is kept for colorbuffer proxy references, |
michael@0 | 192 | // because, as the renderbuffer acting as proxy will maintain a binding pointer |
michael@0 | 193 | // back to this texture, there would be a circular reference if we used a binding |
michael@0 | 194 | // pointer here. This reference count will cause the pointer to be set to NULL if |
michael@0 | 195 | // the count drops to zero, but will not cause deletion of the Renderbuffer. |
michael@0 | 196 | Renderbuffer *mColorbufferProxy; |
michael@0 | 197 | unsigned int mProxyRefs; |
michael@0 | 198 | }; |
michael@0 | 199 | |
michael@0 | 200 | class TextureCubeMap : public Texture |
michael@0 | 201 | { |
michael@0 | 202 | public: |
michael@0 | 203 | TextureCubeMap(rx::Renderer *renderer, GLuint id); |
michael@0 | 204 | |
michael@0 | 205 | ~TextureCubeMap(); |
michael@0 | 206 | |
michael@0 | 207 | void addProxyRef(const Renderbuffer *proxy); |
michael@0 | 208 | void releaseProxy(const Renderbuffer *proxy); |
michael@0 | 209 | |
michael@0 | 210 | virtual GLenum getTarget() const; |
michael@0 | 211 | |
michael@0 | 212 | GLsizei getWidth(GLenum target, GLint level) const; |
michael@0 | 213 | GLsizei getHeight(GLenum target, GLint level) const; |
michael@0 | 214 | GLenum getInternalFormat(GLenum target, GLint level) const; |
michael@0 | 215 | GLenum getActualFormat(GLenum target, GLint level) const; |
michael@0 | 216 | bool isCompressed(GLenum target, GLint level) const; |
michael@0 | 217 | |
michael@0 | 218 | void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
michael@0 | 219 | void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
michael@0 | 220 | void setImagePosY(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
michael@0 | 221 | void setImageNegY(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
michael@0 | 222 | void setImagePosZ(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
michael@0 | 223 | void setImageNegZ(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
michael@0 | 224 | |
michael@0 | 225 | void setCompressedImage(GLenum face, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels); |
michael@0 | 226 | |
michael@0 | 227 | void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
michael@0 | 228 | void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels); |
michael@0 | 229 | void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source); |
michael@0 | 230 | virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source); |
michael@0 | 231 | void storage(GLsizei levels, GLenum internalformat, GLsizei size); |
michael@0 | 232 | |
michael@0 | 233 | virtual bool isSamplerComplete() const; |
michael@0 | 234 | |
michael@0 | 235 | virtual void generateMipmaps(); |
michael@0 | 236 | |
michael@0 | 237 | virtual Renderbuffer *getRenderbuffer(GLenum target); |
michael@0 | 238 | |
michael@0 | 239 | static unsigned int faceIndex(GLenum face); |
michael@0 | 240 | |
michael@0 | 241 | protected: |
michael@0 | 242 | friend class RenderbufferTextureCubeMap; |
michael@0 | 243 | virtual rx::RenderTarget *getRenderTarget(GLenum target); |
michael@0 | 244 | virtual int levelCount(); |
michael@0 | 245 | |
michael@0 | 246 | private: |
michael@0 | 247 | DISALLOW_COPY_AND_ASSIGN(TextureCubeMap); |
michael@0 | 248 | |
michael@0 | 249 | virtual void createTexture(); |
michael@0 | 250 | virtual void updateTexture(); |
michael@0 | 251 | virtual void convertToRenderTarget(); |
michael@0 | 252 | virtual rx::TextureStorageInterface *getStorage(bool renderTarget); |
michael@0 | 253 | |
michael@0 | 254 | bool isCubeComplete() const; |
michael@0 | 255 | bool isMipmapCubeComplete() const; |
michael@0 | 256 | |
michael@0 | 257 | void setImage(int faceIndex, GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels); |
michael@0 | 258 | void commitRect(int faceIndex, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height); |
michael@0 | 259 | void redefineImage(int faceIndex, GLint level, GLint internalformat, GLsizei width, GLsizei height); |
michael@0 | 260 | |
michael@0 | 261 | rx::Image *mImageArray[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS]; |
michael@0 | 262 | |
michael@0 | 263 | rx::TextureStorageInterfaceCube *mTexStorage; |
michael@0 | 264 | |
michael@0 | 265 | // A specific internal reference count is kept for colorbuffer proxy references, |
michael@0 | 266 | // because, as the renderbuffer acting as proxy will maintain a binding pointer |
michael@0 | 267 | // back to this texture, there would be a circular reference if we used a binding |
michael@0 | 268 | // pointer here. This reference count will cause the pointer to be set to NULL if |
michael@0 | 269 | // the count drops to zero, but will not cause deletion of the Renderbuffer. |
michael@0 | 270 | Renderbuffer *mFaceProxies[6]; |
michael@0 | 271 | unsigned int *mFaceProxyRefs[6]; |
michael@0 | 272 | }; |
michael@0 | 273 | } |
michael@0 | 274 | |
michael@0 | 275 | #endif // LIBGLESV2_TEXTURE_H_ |