blob: 4f5fab28d01d67794577a1ded11930859501bc76 [file] [log] [blame]
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00001//
shannon.woods@transgaming.come2e97982013-02-28 23:18:50 +00002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00003// 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.com95a758f2012-07-12 15:17:06 +000018
19#include "common/debug.h"
20#include "common/RefCountObject.h"
daniel@transgaming.com8bc304a2013-01-11 04:07:42 +000021#include "libGLESv2/angletypes.h"
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000022
23namespace egl
24{
25class Surface;
26}
27
daniel@transgaming.com370482e2012-11-28 19:32:13 +000028namespace rx
29{
30class Renderer;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000031class TextureStorageInterface;
32class TextureStorageInterface2D;
33class TextureStorageInterfaceCube;
34class RenderTarget;
35class Image;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000036}
37
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000038namespace gl
39{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000040class Framebuffer;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000041class Renderbuffer;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000042
43enum
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.com95a758f2012-07-12 15:17:06 +000054class Texture : public RefCountObject
55{
56 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000057 Texture(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000058
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.com07ab8412012-07-12 15:17:09 +000070 bool setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000071 bool setUsage(GLenum usage);
72
73 GLenum getMinFilter() const;
74 GLenum getMagFilter() const;
75 GLenum getWrapS() const;
76 GLenum getWrapT() const;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +000077 float getMaxAnisotropy() const;
daniel@transgaming.comebf139f2012-10-31 18:07:32 +000078 int getLodOffset();
79 void getSamplerState(SamplerState *sampler);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000080 GLenum getUsage() const;
daniel@transgaming.comca9a3c82012-10-26 18:55:07 +000081 bool isMipmapFiltered() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000082
83 virtual bool isSamplerComplete() const = 0;
84
daniel@transgaming.com87705f82012-12-20 21:10:45 +000085 rx::TextureStorageInterface *getNativeTexture();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000086 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.com31b13e12012-11-28 19:34:30 +0000102 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.com95a758f2012-07-12 15:17:06 +0000106
107 GLint creationLevels(GLsizei width, GLsizei height) const;
108 GLint creationLevels(GLsizei size) const;
109
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000110 virtual void createTexture() = 0;
111 virtual void updateTexture() = 0;
112 virtual void convertToRenderTarget() = 0;
daniel@transgaming.comd186dc72012-11-28 19:40:16 +0000113 virtual rx::RenderTarget *getRenderTarget(GLenum target) = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000114
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000115 virtual int levelCount() = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000116
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000117 rx::Renderer *mRenderer;
118
daniel@transgaming.comebf139f2012-10-31 18:07:32 +0000119 SamplerState mSamplerState;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000120 GLenum mUsage;
121
122 bool mDirtyImages;
123
124 bool mImmutable;
125
126 private:
127 DISALLOW_COPY_AND_ASSIGN(Texture);
128
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000129 virtual rx::TextureStorageInterface *getStorage(bool renderTarget) = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000130};
131
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000132class Texture2D : public Texture
133{
134 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000135 Texture2D(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000136
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.com20d36662012-10-31 19:51:43 +0000147 GLenum getActualFormat(GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000148 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.comd186dc72012-11-28 19:40:16 +0000169 virtual rx::RenderTarget *getRenderTarget(GLenum target);
170 virtual rx::RenderTarget *getDepthStencil(GLenum target);
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000171 virtual int levelCount();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000172
173 private:
174 DISALLOW_COPY_AND_ASSIGN(Texture2D);
175
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000176 virtual void createTexture();
177 virtual void updateTexture();
178 virtual void convertToRenderTarget();
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000179 virtual rx::TextureStorageInterface *getStorage(bool renderTarget);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000180
181 bool isMipmapComplete() const;
182
shannon.woods@transgaming.come2e97982013-02-28 23:18:50 +0000183 void redefineImage(GLint level, GLint internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000184 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
185
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000186 rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000187
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000188 rx::TextureStorageInterface2D *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000189 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.com95a758f2012-07-12 15:17:06 +0000200class TextureCubeMap : public Texture
201{
202 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000203 TextureCubeMap(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000204
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.com20d36662012-10-31 19:51:43 +0000215 GLenum getActualFormat(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000216 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.comd186dc72012-11-28 19:40:16 +0000243 virtual rx::RenderTarget *getRenderTarget(GLenum target);
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000244 virtual int levelCount();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000245
246 private:
247 DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
248
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000249 virtual void createTexture();
250 virtual void updateTexture();
251 virtual void convertToRenderTarget();
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000252 virtual rx::TextureStorageInterface *getStorage(bool renderTarget);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000253
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.come2e97982013-02-28 23:18:50 +0000259 void redefineImage(int faceIndex, GLint level, GLint internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000260
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000261 rx::Image *mImageArray[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000262
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000263 rx::TextureStorageInterfaceCube *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000264
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.org68715282012-07-12 23:28:41 +0000275#endif // LIBGLESV2_TEXTURE_H_