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