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