blob: 928a4dd378065efbfb951011e3786489dd3f3819 [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
Jamie Madillf51639a2014-06-25 16:04:57 -040016#include "angle_gl.h"
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000017
18#include "common/debug.h"
19#include "common/RefCountObject.h"
daniel@transgaming.com8bc304a2013-01-11 04:07:42 +000020#include "libGLESv2/angletypes.h"
Brandon Jonesf47bebc2014-07-09 14:28:42 -070021#include "libGLESv2/constants.h"
Brandon Jones6b19b002014-07-16 14:32:05 -070022#include "libGLESv2/renderer/TextureImpl.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{
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000031class TextureStorageInterface;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000032class RenderTarget;
33class Image;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000034}
35
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000036namespace gl
37{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000038class Framebuffer;
Jamie Madill3c7fa222014-06-05 13:08:51 -040039class FramebufferAttachment;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000040
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000041class Texture : public RefCountObject
42{
43 public:
Brandon Jonesf47bebc2014-07-09 14:28:42 -070044 Texture(GLuint id, GLenum target);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000045
46 virtual ~Texture();
47
Geoff Lang4907f2c2013-07-25 12:53:57 -040048 GLenum getTarget() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000049
Brandon Jonesa328d562014-07-01 13:52:40 -070050 const SamplerState &getSamplerState() const { return mSamplerState; }
51 SamplerState &getSamplerState() { return mSamplerState; }
52 void getSamplerStateWithNativeOffset(SamplerState *sampler);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000053
Brandon Jonesf47bebc2014-07-09 14:28:42 -070054 virtual void setUsage(GLenum usage);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000055 GLenum getUsage() const;
56
Jamie Madilld3d2a342013-10-07 10:46:35 -040057 GLint getBaseLevelWidth() const;
58 GLint getBaseLevelHeight() const;
59 GLint getBaseLevelDepth() const;
60 GLenum getBaseLevelInternalFormat() const;
61
Brandon Jones6b19b002014-07-16 14:32:05 -070062 bool isSamplerComplete(const SamplerState &samplerState) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000063
Brandon Jones6b19b002014-07-16 14:32:05 -070064 rx::TextureStorageInterface *getNativeTexture();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000065
66 virtual void generateMipmaps() = 0;
Brandon Jones6b19b002014-07-16 14:32:05 -070067 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 +000068
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000069 unsigned int getTextureSerial();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000070
71 bool isImmutable() const;
Jamie Madill51a94372013-10-24 17:49:43 -040072 int immutableLevelCount();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000073
Brandon Jones6b19b002014-07-16 14:32:05 -070074 virtual rx::TextureImpl *getImplementation() = 0;
75 virtual const rx::TextureImpl *getImplementation() const = 0;
76
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000077 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.
78
79 protected:
Brandon Jonesf47bebc2014-07-09 14:28:42 -070080 int mipLevels() const;
81
82 SamplerState mSamplerState;
83 GLenum mUsage;
84
85 bool mImmutable;
86
87 GLenum mTarget;
88
89 private:
90 DISALLOW_COPY_AND_ASSIGN(Texture);
91
92 virtual const rx::Image *getBaseLevelImage() const = 0;
93};
94
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000095class Texture2D : public Texture
96{
97 public:
Brandon Jonesf47bebc2014-07-09 14:28:42 -070098 Texture2D(rx::Texture2DImpl *impl, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000099
100 ~Texture2D();
101
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700102 virtual void setUsage(GLenum usage);
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700103
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000104 GLsizei getWidth(GLint level) const;
105 GLsizei getHeight(GLint level) const;
106 GLenum getInternalFormat(GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000107 GLenum getActualFormat(GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000108 bool isCompressed(GLint level) const;
109 bool isDepth(GLint level) const;
110
Geoff Lang005df412013-10-16 14:12:50 -0400111 void setImage(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000112 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400113 void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000114 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
115 void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000116 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
117
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000118 virtual void bindTexImage(egl::Surface *surface);
119 virtual void releaseTexImage();
120
121 virtual void generateMipmaps();
122
Geoff Lang8040f572013-07-25 16:49:54 -0400123 unsigned int getRenderTargetSerial(GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000124
Brandon Jones6b19b002014-07-16 14:32:05 -0700125 virtual rx::TextureImpl *getImplementation() { return mTexture; }
126 virtual const rx::TextureImpl *getImplementation() const { return mTexture; }
127
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000128 protected:
Jamie Madill3c7fa222014-06-05 13:08:51 -0400129 friend class Texture2DAttachment;
Geoff Lang8040f572013-07-25 16:49:54 -0400130 rx::RenderTarget *getRenderTarget(GLint level);
131 rx::RenderTarget *getDepthSencil(GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000132
133 private:
134 DISALLOW_COPY_AND_ASSIGN(Texture2D);
135
Jamie Madilld3d2a342013-10-07 10:46:35 -0400136 virtual const rx::Image *getBaseLevelImage() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000137
Geoff Lang005df412013-10-16 14:12:50 -0400138 void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000139
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700140 rx::Texture2DImpl *mTexture;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000141 egl::Surface *mSurface;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000142};
143
Brandon Jones0511e802014-07-14 16:27:26 -0700144class TextureCubeMap : public Texture
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000145{
146 public:
Brandon Jones0511e802014-07-14 16:27:26 -0700147 TextureCubeMap(rx::TextureCubeImpl *impl, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000148
149 ~TextureCubeMap();
150
Brandon Jones0511e802014-07-14 16:27:26 -0700151 virtual void setUsage(GLenum usage);
Brandon Jones0511e802014-07-14 16:27:26 -0700152
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000153 GLsizei getWidth(GLenum target, GLint level) const;
154 GLsizei getHeight(GLenum target, GLint level) const;
155 GLenum getInternalFormat(GLenum target, GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000156 GLenum getActualFormat(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000157 bool isCompressed(GLenum target, GLint level) const;
Geoff Lang8040f572013-07-25 16:49:54 -0400158 bool isDepth(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000159
Geoff Lang005df412013-10-16 14:12:50 -0400160 void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
161 void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
162 void setImagePosY(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
163 void setImageNegY(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
164 void setImagePosZ(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
165 void setImageNegZ(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000166
Jamie Madill2db197c2013-10-24 17:49:35 -0400167 void setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000168
Jamie Madill88f18f42013-09-18 14:36:19 -0400169 void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000170 void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
171 void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000172 void storage(GLsizei levels, GLenum internalformat, GLsizei size);
173
Jamie Madillc1f8b162013-10-07 10:46:38 -0400174 bool isCubeComplete() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000175
176 virtual void generateMipmaps();
177
Jamie Madill2db197c2013-10-24 17:49:35 -0400178 unsigned int getRenderTargetSerial(GLenum target, GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000179
Brandon Jones6b19b002014-07-16 14:32:05 -0700180 virtual rx::TextureImpl *getImplementation() { return mTexture; }
181 virtual const rx::TextureImpl *getImplementation() const { return mTexture; }
182
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000183 protected:
Jamie Madill3c7fa222014-06-05 13:08:51 -0400184 friend class TextureCubeMapAttachment;
Geoff Lang8040f572013-07-25 16:49:54 -0400185 rx::RenderTarget *getRenderTarget(GLenum target, GLint level);
186 rx::RenderTarget *getDepthStencil(GLenum target, GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000187
188 private:
189 DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
190
Jamie Madilld3d2a342013-10-07 10:46:35 -0400191 virtual const rx::Image *getBaseLevelImage() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000192
Brandon Jones0511e802014-07-14 16:27:26 -0700193 rx::TextureCubeImpl *mTexture;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000194};
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000195
Brandon Jones78b1acd2014-07-15 15:33:07 -0700196class Texture3D : public Texture
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000197{
198 public:
Brandon Jones78b1acd2014-07-15 15:33:07 -0700199 Texture3D(rx::Texture3DImpl *impl, GLuint id);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000200
201 ~Texture3D();
202
Brandon Jones78b1acd2014-07-15 15:33:07 -0700203 virtual void setUsage(GLenum usage);
Brandon Jones78b1acd2014-07-15 15:33:07 -0700204
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000205 GLsizei getWidth(GLint level) const;
206 GLsizei getHeight(GLint level) const;
207 GLsizei getDepth(GLint level) const;
208 GLenum getInternalFormat(GLint level) const;
209 GLenum getActualFormat(GLint level) const;
210 bool isCompressed(GLint level) const;
211 bool isDepth(GLint level) const;
212
Geoff Lang005df412013-10-16 14:12:50 -0400213 void setImage(GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000214 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400215 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);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000216 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
217 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
218
219 virtual void generateMipmaps();
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000220
Geoff Lang8040f572013-07-25 16:49:54 -0400221 unsigned int getRenderTargetSerial(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000222
Brandon Jones6b19b002014-07-16 14:32:05 -0700223 virtual rx::TextureImpl *getImplementation() { return mTexture; }
224 virtual const rx::TextureImpl *getImplementation() const { return mTexture; }
225
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000226 protected:
Jamie Madill3c7fa222014-06-05 13:08:51 -0400227 friend class Texture3DAttachment;
Geoff Lang8040f572013-07-25 16:49:54 -0400228 rx::RenderTarget *getRenderTarget(GLint level, GLint layer);
229 rx::RenderTarget *getDepthStencil(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000230
231 private:
232 DISALLOW_COPY_AND_ASSIGN(Texture3D);
233
Jamie Madilld3d2a342013-10-07 10:46:35 -0400234 virtual const rx::Image *getBaseLevelImage() const;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000235
Brandon Jones78b1acd2014-07-15 15:33:07 -0700236 rx::Texture3DImpl *mTexture;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000237};
238
Brandon Jones142ec422014-07-16 10:31:30 -0700239class Texture2DArray : public Texture
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000240{
241 public:
Brandon Jones142ec422014-07-16 10:31:30 -0700242 Texture2DArray(rx::Texture2DArrayImpl *impl, GLuint id);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000243
244 ~Texture2DArray();
245
Brandon Jones142ec422014-07-16 10:31:30 -0700246 virtual void setUsage(GLenum usage);
Brandon Jones142ec422014-07-16 10:31:30 -0700247
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000248 GLsizei getWidth(GLint level) const;
249 GLsizei getHeight(GLint level) const;
Jamie Madillb8f8b892014-01-07 10:12:50 -0500250 GLsizei getLayers(GLint level) const;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000251 GLenum getInternalFormat(GLint level) const;
252 GLenum getActualFormat(GLint level) const;
253 bool isCompressed(GLint level) const;
254 bool isDepth(GLint level) const;
255
Geoff Lang005df412013-10-16 14:12:50 -0400256 void setImage(GLint level, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000257 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400258 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);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000259 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
260 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
261
262 virtual void generateMipmaps();
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000263
Geoff Lang8040f572013-07-25 16:49:54 -0400264 unsigned int getRenderTargetSerial(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000265
Brandon Jones6b19b002014-07-16 14:32:05 -0700266 virtual rx::TextureImpl *getImplementation() { return mTexture; }
267 virtual const rx::TextureImpl *getImplementation() const { return mTexture; }
268
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000269 protected:
Jamie Madill3c7fa222014-06-05 13:08:51 -0400270 friend class Texture2DArrayAttachment;
Geoff Lang8040f572013-07-25 16:49:54 -0400271 rx::RenderTarget *getRenderTarget(GLint level, GLint layer);
272 rx::RenderTarget *getDepthStencil(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000273
274 private:
275 DISALLOW_COPY_AND_ASSIGN(Texture2DArray);
276
Jamie Madilld3d2a342013-10-07 10:46:35 -0400277 virtual const rx::Image *getBaseLevelImage() const;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000278
Brandon Jones142ec422014-07-16 10:31:30 -0700279 rx::Texture2DArrayImpl *mTexture;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000280};
281
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000282}
283
jbauman@chromium.org68715282012-07-12 23:28:41 +0000284#endif // LIBGLESV2_TEXTURE_H_