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