2 // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
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.
11 #ifndef LIBGLESV2_TEXTURE_H_
12 #define LIBGLESV2_TEXTURE_H_
14 #include "common/debug.h"
15 #include "common/RefCountObject.h"
16 #include "libGLESv2/angletypes.h"
17 #include "libGLESv2/constants.h"
18 #include "libGLESv2/renderer/TextureImpl.h"
19 #include "libGLESv2/Caps.h"
32 class TextureStorageInterface;
39 class FramebufferAttachment;
42 bool IsMipmapFiltered(const gl::SamplerState &samplerState);
44 class Texture : public RefCountObject
47 Texture(rx::TextureImpl *impl, GLuint id, GLenum target);
51 GLenum getTarget() const;
53 const SamplerState &getSamplerState() const { return mSamplerState; }
54 SamplerState &getSamplerState() { return mSamplerState; }
55 void getSamplerStateWithNativeOffset(SamplerState *sampler);
57 void setUsage(GLenum usage);
58 GLenum getUsage() const;
60 GLint getBaseLevelWidth() const;
61 GLint getBaseLevelHeight() const;
62 GLint getBaseLevelDepth() const;
63 GLenum getBaseLevelInternalFormat() const;
65 GLsizei getWidth(const ImageIndex &index) const;
66 GLsizei getHeight(const ImageIndex &index) const;
67 GLenum getInternalFormat(const ImageIndex &index) const;
68 GLenum getActualFormat(const ImageIndex &index) const;
70 virtual bool isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const = 0;
72 rx::TextureStorage *getNativeTexture();
74 virtual void generateMipmaps();
75 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
77 unsigned int getTextureSerial();
79 bool isImmutable() const;
80 int immutableLevelCount();
82 rx::TextureImpl *getImplementation() { return mTexture; }
83 const rx::TextureImpl *getImplementation() const { return mTexture; }
85 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.
88 int mipLevels() const;
90 rx::TextureImpl *mTexture;
92 SamplerState mSamplerState;
99 const rx::Image *getBaseLevelImage() const;
102 DISALLOW_COPY_AND_ASSIGN(Texture);
105 class Texture2D : public Texture
108 Texture2D(rx::TextureImpl *impl, GLuint id);
110 virtual ~Texture2D();
112 GLsizei getWidth(GLint level) const;
113 GLsizei getHeight(GLint level) const;
114 GLenum getInternalFormat(GLint level) const;
115 GLenum getActualFormat(GLint level) const;
116 bool isCompressed(GLint level) const;
117 bool isDepth(GLint level) const;
119 void setImage(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
120 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
121 void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
122 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
123 void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
124 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
126 virtual bool isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const;
127 virtual void bindTexImage(egl::Surface *surface);
128 virtual void releaseTexImage();
130 virtual void generateMipmaps();
133 DISALLOW_COPY_AND_ASSIGN(Texture2D);
135 bool isMipmapComplete() const;
136 bool isLevelComplete(int level) const;
138 egl::Surface *mSurface;
141 class TextureCubeMap : public Texture
144 TextureCubeMap(rx::TextureImpl *impl, GLuint id);
146 virtual ~TextureCubeMap();
148 GLsizei getWidth(GLenum target, GLint level) const;
149 GLsizei getHeight(GLenum target, GLint level) const;
150 GLenum getInternalFormat(GLenum target, GLint level) const;
151 GLenum getActualFormat(GLenum target, GLint level) const;
152 bool isCompressed(GLenum target, GLint level) const;
153 bool isDepth(GLenum target, GLint level) const;
155 void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
156 void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
157 void setImagePosY(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
158 void setImageNegY(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
159 void setImagePosZ(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
160 void setImageNegZ(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
162 void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
164 void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
165 void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
166 void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
167 void storage(GLsizei levels, GLenum internalformat, GLsizei size);
169 virtual bool isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const;
171 bool isCubeComplete() const;
173 static int targetToLayerIndex(GLenum target);
174 static GLenum layerIndexToTarget(GLint layer);
177 DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
179 bool isMipmapComplete() const;
180 bool isFaceLevelComplete(int faceIndex, int level) const;
183 class Texture3D : public Texture
186 Texture3D(rx::TextureImpl *impl, GLuint id);
188 virtual ~Texture3D();
190 GLsizei getWidth(GLint level) const;
191 GLsizei getHeight(GLint level) const;
192 GLsizei getDepth(GLint level) const;
193 GLenum getInternalFormat(GLint level) const;
194 GLenum getActualFormat(GLint level) const;
195 bool isCompressed(GLint level) const;
196 bool isDepth(GLint level) const;
198 void setImage(GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
199 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
200 void subImage(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
201 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
202 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
204 virtual bool isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const;
207 DISALLOW_COPY_AND_ASSIGN(Texture3D);
209 bool isMipmapComplete() const;
210 bool isLevelComplete(int level) const;
213 class Texture2DArray : public Texture
216 Texture2DArray(rx::TextureImpl *impl, GLuint id);
218 virtual ~Texture2DArray();
220 GLsizei getWidth(GLint level) const;
221 GLsizei getHeight(GLint level) const;
222 GLsizei getLayers(GLint level) const;
223 GLenum getInternalFormat(GLint level) const;
224 GLenum getActualFormat(GLint level) const;
225 bool isCompressed(GLint level) const;
226 bool isDepth(GLint level) const;
228 void setImage(GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
229 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
230 void subImage(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
231 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
232 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
234 virtual bool isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const;
237 DISALLOW_COPY_AND_ASSIGN(Texture2DArray);
239 bool isMipmapComplete() const;
240 bool isLevelComplete(int level) const;
245 #endif // LIBGLESV2_TEXTURE_H_