1//
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.
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 "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"
20
21#include "angle_gl.h"
22
23#include <vector>
24
25namespace egl
26{
27class Surface;
28}
29
30namespace rx
31{
32class TextureStorageInterface;
33class Image;
34}
35
36namespace gl
37{
38class Framebuffer;
39class FramebufferAttachment;
40struct ImageIndex;
41
42bool IsMipmapFiltered(const gl::SamplerState &samplerState);
43
44class Texture : public RefCountObject
45{
46  public:
47    Texture(rx::TextureImpl *impl, GLuint id, GLenum target);
48
49    virtual ~Texture();
50
51    GLenum getTarget() const;
52
53    const SamplerState &getSamplerState() const { return mSamplerState; }
54    SamplerState &getSamplerState() { return mSamplerState; }
55    void getSamplerStateWithNativeOffset(SamplerState *sampler);
56
57    void setUsage(GLenum usage);
58    GLenum getUsage() const;
59
60    GLint getBaseLevelWidth() const;
61    GLint getBaseLevelHeight() const;
62    GLint getBaseLevelDepth() const;
63    GLenum getBaseLevelInternalFormat() const;
64
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;
69
70    virtual bool isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const = 0;
71
72    rx::TextureStorage *getNativeTexture();
73
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);
76
77    unsigned int getTextureSerial();
78
79    bool isImmutable() const;
80    int immutableLevelCount();
81
82    rx::TextureImpl *getImplementation() { return mTexture; }
83    const rx::TextureImpl *getImplementation() const { return mTexture; }
84
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.
86
87  protected:
88    int mipLevels() const;
89
90    rx::TextureImpl *mTexture;
91
92    SamplerState mSamplerState;
93    GLenum mUsage;
94
95    bool mImmutable;
96
97    GLenum mTarget;
98
99    const rx::Image *getBaseLevelImage() const;
100
101  private:
102    DISALLOW_COPY_AND_ASSIGN(Texture);
103};
104
105class Texture2D : public Texture
106{
107  public:
108    Texture2D(rx::TextureImpl *impl, GLuint id);
109
110    virtual ~Texture2D();
111
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;
118
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);
125
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();
129
130    virtual void generateMipmaps();
131
132  private:
133    DISALLOW_COPY_AND_ASSIGN(Texture2D);
134
135    bool isMipmapComplete() const;
136    bool isLevelComplete(int level) const;
137
138    egl::Surface *mSurface;
139};
140
141class TextureCubeMap : public Texture
142{
143  public:
144    TextureCubeMap(rx::TextureImpl *impl, GLuint id);
145
146    virtual ~TextureCubeMap();
147
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;
154
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);
161
162    void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
163
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);
168
169    virtual bool isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const;
170
171    bool isCubeComplete() const;
172
173    static int targetToLayerIndex(GLenum target);
174    static GLenum layerIndexToTarget(GLint layer);
175
176  private:
177    DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
178
179    bool isMipmapComplete() const;
180    bool isFaceLevelComplete(int faceIndex, int level) const;
181};
182
183class Texture3D : public Texture
184{
185  public:
186    Texture3D(rx::TextureImpl *impl, GLuint id);
187
188    virtual ~Texture3D();
189
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;
197
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);
203
204    virtual bool isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const;
205
206  private:
207    DISALLOW_COPY_AND_ASSIGN(Texture3D);
208
209    bool isMipmapComplete() const;
210    bool isLevelComplete(int level) const;
211};
212
213class Texture2DArray : public Texture
214{
215  public:
216    Texture2DArray(rx::TextureImpl *impl, GLuint id);
217
218    virtual ~Texture2DArray();
219
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;
227
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);
233
234    virtual bool isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const;
235
236  private:
237    DISALLOW_COPY_AND_ASSIGN(Texture2DArray);
238
239    bool isMipmapComplete() const;
240    bool isLevelComplete(int level) const;
241};
242
243}
244
245#endif   // LIBGLESV2_TEXTURE_H_
246