blob: 118a8c8df7dd8a00f6b56f107916ba4f68b2c4a2 [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
shannon.woods%transgaming.com@gtempaccount.comf26ddae2013-04-13 03:29:13 +000017#include <GLES3/gl3.h>
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000018#include <GLES2/gl2.h>
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000019
20#include "common/debug.h"
21#include "common/RefCountObject.h"
daniel@transgaming.com8bc304a2013-01-11 04:07:42 +000022#include "libGLESv2/angletypes.h"
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000023
24namespace egl
25{
26class Surface;
27}
28
daniel@transgaming.com370482e2012-11-28 19:32:13 +000029namespace rx
30{
31class Renderer;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000032class TextureStorageInterface;
33class TextureStorageInterface2D;
34class TextureStorageInterfaceCube;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +000035class TextureStorageInterface3D;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000036class RenderTarget;
37class Image;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000038}
39
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000040namespace gl
41{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000042class Framebuffer;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000043class Renderbuffer;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000044
45enum
46{
47 // These are the maximums the implementation can support
48 // The actual GL caps are limited by the device caps
49 // and should be queried from the Context
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +000050 IMPLEMENTATION_MAX_2D_TEXTURE_SIZE = 16384,
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000051 IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 16384,
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +000052 IMPLEMENTATION_MAX_3D_TEXTURE_SIZE = 2048,
shannon.woods%transgaming.com@gtempaccount.coma98a8112013-04-13 03:45:57 +000053 IMPLEMENTATION_MAX_2D_ARRAY_TEXTURE_LAYERS = 2048,
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000054
55 IMPLEMENTATION_MAX_TEXTURE_LEVELS = 15 // 1+log2 of MAX_TEXTURE_SIZE
56};
57
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000058class Texture : public RefCountObject
59{
60 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000061 Texture(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000062
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);
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +000074 bool setWrapR(GLenum wrap);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +000075 bool setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000076 bool setUsage(GLenum usage);
77
78 GLenum getMinFilter() const;
79 GLenum getMagFilter() const;
80 GLenum getWrapS() const;
81 GLenum getWrapT() const;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +000082 GLenum getWrapR() const;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +000083 float getMaxAnisotropy() const;
daniel@transgaming.comebf139f2012-10-31 18:07:32 +000084 int getLodOffset();
85 void getSamplerState(SamplerState *sampler);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000086 GLenum getUsage() const;
daniel@transgaming.comca9a3c82012-10-26 18:55:07 +000087 bool isMipmapFiltered() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000088
89 virtual bool isSamplerComplete() const = 0;
90
daniel@transgaming.com87705f82012-12-20 21:10:45 +000091 rx::TextureStorageInterface *getNativeTexture();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000092 virtual Renderbuffer *getRenderbuffer(GLenum target) = 0;
93
94 virtual void generateMipmaps() = 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +000095 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000096
97 bool hasDirtyParameters() const;
98 bool hasDirtyImages() const;
99 void resetDirty();
100 unsigned int getTextureSerial();
101 unsigned int getRenderTargetSerial(GLenum target);
102
103 bool isImmutable() const;
104
105 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.
106
107 protected:
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000108 void setImage(GLint unpackAlignment, const void *pixels, rx::Image *image);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000109 bool subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
110 GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, rx::Image *image);
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000111 void setCompressedImage(GLsizei imageSize, const void *pixels, rx::Image *image);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000112 bool subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
113 GLenum format, GLsizei imageSize, const void *pixels, rx::Image *image);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000114
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000115 GLint creationLevels(GLsizei width, GLsizei height, GLsizei depth) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000116 GLint creationLevels(GLsizei width, GLsizei height) const;
117 GLint creationLevels(GLsizei size) const;
118
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000119 virtual void createTexture() = 0;
120 virtual void updateTexture() = 0;
121 virtual void convertToRenderTarget() = 0;
daniel@transgaming.comd186dc72012-11-28 19:40:16 +0000122 virtual rx::RenderTarget *getRenderTarget(GLenum target) = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000123
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000124 virtual int levelCount() = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000125
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000126 rx::Renderer *mRenderer;
127
daniel@transgaming.comebf139f2012-10-31 18:07:32 +0000128 SamplerState mSamplerState;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000129 GLenum mUsage;
130
131 bool mDirtyImages;
132
133 bool mImmutable;
134
135 private:
136 DISALLOW_COPY_AND_ASSIGN(Texture);
137
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000138 virtual rx::TextureStorageInterface *getStorage(bool renderTarget) = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000139};
140
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000141class Texture2D : public Texture
142{
143 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000144 Texture2D(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000145
146 ~Texture2D();
147
148 void addProxyRef(const Renderbuffer *proxy);
149 void releaseProxy(const Renderbuffer *proxy);
150
151 virtual GLenum getTarget() const;
152
153 GLsizei getWidth(GLint level) const;
154 GLsizei getHeight(GLint level) const;
155 GLenum getInternalFormat(GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000156 GLenum getActualFormat(GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000157 bool isCompressed(GLint level) const;
158 bool isDepth(GLint level) const;
159
160 void setImage(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
161 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
162 void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
163 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
164 void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000165 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000166 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
167
168 virtual bool isSamplerComplete() const;
169 virtual void bindTexImage(egl::Surface *surface);
170 virtual void releaseTexImage();
171
172 virtual void generateMipmaps();
173
174 virtual Renderbuffer *getRenderbuffer(GLenum target);
175
176 protected:
177 friend class RenderbufferTexture2D;
daniel@transgaming.comd186dc72012-11-28 19:40:16 +0000178 virtual rx::RenderTarget *getRenderTarget(GLenum target);
179 virtual rx::RenderTarget *getDepthStencil(GLenum target);
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000180 virtual int levelCount();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000181
182 private:
183 DISALLOW_COPY_AND_ASSIGN(Texture2D);
184
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000185 virtual void createTexture();
186 virtual void updateTexture();
187 virtual void convertToRenderTarget();
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000188 virtual rx::TextureStorageInterface *getStorage(bool renderTarget);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000189
190 bool isMipmapComplete() const;
191
shannon.woods@transgaming.come2e97982013-02-28 23:18:50 +0000192 void redefineImage(GLint level, GLint internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000193 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
194
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000195 rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000196
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000197 rx::TextureStorageInterface2D *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000198 egl::Surface *mSurface;
199
200 // A specific internal reference count is kept for colorbuffer proxy references,
201 // because, as the renderbuffer acting as proxy will maintain a binding pointer
202 // back to this texture, there would be a circular reference if we used a binding
203 // pointer here. This reference count will cause the pointer to be set to NULL if
204 // the count drops to zero, but will not cause deletion of the Renderbuffer.
205 Renderbuffer *mColorbufferProxy;
206 unsigned int mProxyRefs;
207};
208
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000209class TextureCubeMap : public Texture
210{
211 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000212 TextureCubeMap(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000213
214 ~TextureCubeMap();
215
216 void addProxyRef(const Renderbuffer *proxy);
217 void releaseProxy(const Renderbuffer *proxy);
218
219 virtual GLenum getTarget() const;
220
221 GLsizei getWidth(GLenum target, GLint level) const;
222 GLsizei getHeight(GLenum target, GLint level) const;
223 GLenum getInternalFormat(GLenum target, GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000224 GLenum getActualFormat(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000225 bool isCompressed(GLenum target, GLint level) const;
226
227 void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
228 void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
229 void setImagePosY(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
230 void setImageNegY(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
231 void setImagePosZ(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
232 void setImageNegZ(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
233
234 void setCompressedImage(GLenum face, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
235
236 void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
237 void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
238 void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000239 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000240 void storage(GLsizei levels, GLenum internalformat, GLsizei size);
241
242 virtual bool isSamplerComplete() const;
243
244 virtual void generateMipmaps();
245
246 virtual Renderbuffer *getRenderbuffer(GLenum target);
247
248 static unsigned int faceIndex(GLenum face);
249
250 protected:
251 friend class RenderbufferTextureCubeMap;
daniel@transgaming.comd186dc72012-11-28 19:40:16 +0000252 virtual rx::RenderTarget *getRenderTarget(GLenum target);
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000253 virtual int levelCount();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000254
255 private:
256 DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
257
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000258 virtual void createTexture();
259 virtual void updateTexture();
260 virtual void convertToRenderTarget();
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000261 virtual rx::TextureStorageInterface *getStorage(bool renderTarget);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000262
263 bool isCubeComplete() const;
264 bool isMipmapCubeComplete() const;
265
266 void setImage(int faceIndex, GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
267 void commitRect(int faceIndex, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
shannon.woods@transgaming.come2e97982013-02-28 23:18:50 +0000268 void redefineImage(int faceIndex, GLint level, GLint internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000269
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000270 rx::Image *mImageArray[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000271
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000272 rx::TextureStorageInterfaceCube *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000273
274 // A specific internal reference count is kept for colorbuffer proxy references,
275 // because, as the renderbuffer acting as proxy will maintain a binding pointer
276 // back to this texture, there would be a circular reference if we used a binding
277 // pointer here. This reference count will cause the pointer to be set to NULL if
278 // the count drops to zero, but will not cause deletion of the Renderbuffer.
279 Renderbuffer *mFaceProxies[6];
280 unsigned int *mFaceProxyRefs[6];
281};
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000282
283class Texture3D : public Texture
284{
285 public:
286 Texture3D(rx::Renderer *renderer, GLuint id);
287
288 ~Texture3D();
289
290 void addProxyRef(const Renderbuffer *proxy);
291 void releaseProxy(const Renderbuffer *proxy);
292
293 virtual GLenum getTarget() const;
294
295 GLsizei getWidth(GLint level) const;
296 GLsizei getHeight(GLint level) const;
297 GLsizei getDepth(GLint level) const;
298 GLenum getInternalFormat(GLint level) const;
299 GLenum getActualFormat(GLint level) const;
300 bool isCompressed(GLint level) const;
301 bool isDepth(GLint level) const;
302
303 void setImage(GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
304 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
305 void subImage(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
306 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
307 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
308
309 virtual void generateMipmaps();
310 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
311
312 virtual bool isSamplerComplete() const;
313 virtual bool isMipmapComplete() const;
314
315 virtual Renderbuffer *getRenderbuffer(GLenum target);
316
317 protected:
318 virtual int levelCount();
319
320 private:
321 DISALLOW_COPY_AND_ASSIGN(Texture3D);
322
323 virtual void createTexture();
324 virtual void updateTexture();
325 virtual void convertToRenderTarget();
326 virtual rx::RenderTarget *getRenderTarget(GLenum target);
327
328 virtual rx::TextureStorageInterface *getStorage(bool renderTarget);
329
330 void redefineImage(GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth);
331 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
332
333 rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
334
335 rx::TextureStorageInterface3D *mTexStorage;
336
337 // A specific internal reference count is kept for colorbuffer proxy references,
338 // because, as the renderbuffer acting as proxy will maintain a binding pointer
339 // back to this texture, there would be a circular reference if we used a binding
340 // pointer here. This reference count will cause the pointer to be set to NULL if
341 // the count drops to zero, but will not cause deletion of the Renderbuffer.
342 Renderbuffer *mColorbufferProxy;
343 unsigned int mProxyRefs;
344};
345
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000346}
347
jbauman@chromium.org68715282012-07-12 23:28:41 +0000348#endif // LIBGLESV2_TEXTURE_H_