blob: 336ff5ce956b57c71d828fcbf17d606c48b670c3 [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;
35class RenderTarget;
36class Image;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000037}
38
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000039namespace gl
40{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000041class Framebuffer;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000042class Renderbuffer;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000043
44enum
45{
46 // These are the maximums the implementation can support
47 // The actual GL caps are limited by the device caps
48 // and should be queried from the Context
49 IMPLEMENTATION_MAX_TEXTURE_SIZE = 16384,
50 IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 16384,
51
52 IMPLEMENTATION_MAX_TEXTURE_LEVELS = 15 // 1+log2 of MAX_TEXTURE_SIZE
53};
54
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000055class Texture : public RefCountObject
56{
57 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +000058 Texture(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000059
60 virtual ~Texture();
61
62 virtual void addProxyRef(const Renderbuffer *proxy) = 0;
63 virtual void releaseProxy(const Renderbuffer *proxy) = 0;
64
65 virtual GLenum getTarget() const = 0;
66
67 bool setMinFilter(GLenum filter);
68 bool setMagFilter(GLenum filter);
69 bool setWrapS(GLenum wrap);
70 bool setWrapT(GLenum wrap);
daniel@transgaming.com07ab8412012-07-12 15:17:09 +000071 bool setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000072 bool setUsage(GLenum usage);
73
74 GLenum getMinFilter() const;
75 GLenum getMagFilter() const;
76 GLenum getWrapS() const;
77 GLenum getWrapT() const;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +000078 float getMaxAnisotropy() const;
daniel@transgaming.comebf139f2012-10-31 18:07:32 +000079 int getLodOffset();
80 void getSamplerState(SamplerState *sampler);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000081 GLenum getUsage() const;
daniel@transgaming.comca9a3c82012-10-26 18:55:07 +000082 bool isMipmapFiltered() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000083
84 virtual bool isSamplerComplete() const = 0;
85
daniel@transgaming.com87705f82012-12-20 21:10:45 +000086 rx::TextureStorageInterface *getNativeTexture();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000087 virtual Renderbuffer *getRenderbuffer(GLenum target) = 0;
88
89 virtual void generateMipmaps() = 0;
90 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) = 0;
91
92 bool hasDirtyParameters() const;
93 bool hasDirtyImages() const;
94 void resetDirty();
95 unsigned int getTextureSerial();
96 unsigned int getRenderTargetSerial(GLenum target);
97
98 bool isImmutable() const;
99
100 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.
101
102 protected:
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000103 void setImage(GLint unpackAlignment, const void *pixels, rx::Image *image);
104 bool subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels, rx::Image *image);
105 void setCompressedImage(GLsizei imageSize, const void *pixels, rx::Image *image);
106 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 +0000107
108 GLint creationLevels(GLsizei width, GLsizei height) const;
109 GLint creationLevels(GLsizei size) const;
110
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000111 virtual void createTexture() = 0;
112 virtual void updateTexture() = 0;
113 virtual void convertToRenderTarget() = 0;
daniel@transgaming.comd186dc72012-11-28 19:40:16 +0000114 virtual rx::RenderTarget *getRenderTarget(GLenum target) = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000115
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000116 virtual int levelCount() = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000117
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000118 rx::Renderer *mRenderer;
119
daniel@transgaming.comebf139f2012-10-31 18:07:32 +0000120 SamplerState mSamplerState;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000121 GLenum mUsage;
122
123 bool mDirtyImages;
124
125 bool mImmutable;
126
127 private:
128 DISALLOW_COPY_AND_ASSIGN(Texture);
129
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000130 virtual rx::TextureStorageInterface *getStorage(bool renderTarget) = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000131};
132
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000133class Texture2D : public Texture
134{
135 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000136 Texture2D(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000137
138 ~Texture2D();
139
140 void addProxyRef(const Renderbuffer *proxy);
141 void releaseProxy(const Renderbuffer *proxy);
142
143 virtual GLenum getTarget() const;
144
145 GLsizei getWidth(GLint level) const;
146 GLsizei getHeight(GLint level) const;
147 GLenum getInternalFormat(GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000148 GLenum getActualFormat(GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000149 bool isCompressed(GLint level) const;
150 bool isDepth(GLint level) const;
151
152 void setImage(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
153 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
154 void subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
155 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
156 void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
157 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
158 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
159
160 virtual bool isSamplerComplete() const;
161 virtual void bindTexImage(egl::Surface *surface);
162 virtual void releaseTexImage();
163
164 virtual void generateMipmaps();
165
166 virtual Renderbuffer *getRenderbuffer(GLenum target);
167
168 protected:
169 friend class RenderbufferTexture2D;
daniel@transgaming.comd186dc72012-11-28 19:40:16 +0000170 virtual rx::RenderTarget *getRenderTarget(GLenum target);
171 virtual rx::RenderTarget *getDepthStencil(GLenum target);
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000172 virtual int levelCount();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000173
174 private:
175 DISALLOW_COPY_AND_ASSIGN(Texture2D);
176
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000177 virtual void createTexture();
178 virtual void updateTexture();
179 virtual void convertToRenderTarget();
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000180 virtual rx::TextureStorageInterface *getStorage(bool renderTarget);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000181
182 bool isMipmapComplete() const;
183
shannon.woods@transgaming.come2e97982013-02-28 23:18:50 +0000184 void redefineImage(GLint level, GLint internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000185 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
186
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000187 rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000188
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000189 rx::TextureStorageInterface2D *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000190 egl::Surface *mSurface;
191
192 // A specific internal reference count is kept for colorbuffer proxy references,
193 // because, as the renderbuffer acting as proxy will maintain a binding pointer
194 // back to this texture, there would be a circular reference if we used a binding
195 // pointer here. This reference count will cause the pointer to be set to NULL if
196 // the count drops to zero, but will not cause deletion of the Renderbuffer.
197 Renderbuffer *mColorbufferProxy;
198 unsigned int mProxyRefs;
199};
200
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000201class TextureCubeMap : public Texture
202{
203 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000204 TextureCubeMap(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000205
206 ~TextureCubeMap();
207
208 void addProxyRef(const Renderbuffer *proxy);
209 void releaseProxy(const Renderbuffer *proxy);
210
211 virtual GLenum getTarget() const;
212
213 GLsizei getWidth(GLenum target, GLint level) const;
214 GLsizei getHeight(GLenum target, GLint level) const;
215 GLenum getInternalFormat(GLenum target, GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000216 GLenum getActualFormat(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000217 bool isCompressed(GLenum target, GLint level) const;
218
219 void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
220 void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
221 void setImagePosY(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
222 void setImageNegY(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
223 void setImagePosZ(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
224 void setImageNegZ(GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
225
226 void setCompressedImage(GLenum face, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
227
228 void subImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
229 void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
230 void copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
231 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
232 void storage(GLsizei levels, GLenum internalformat, GLsizei size);
233
234 virtual bool isSamplerComplete() const;
235
236 virtual void generateMipmaps();
237
238 virtual Renderbuffer *getRenderbuffer(GLenum target);
239
240 static unsigned int faceIndex(GLenum face);
241
242 protected:
243 friend class RenderbufferTextureCubeMap;
daniel@transgaming.comd186dc72012-11-28 19:40:16 +0000244 virtual rx::RenderTarget *getRenderTarget(GLenum target);
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000245 virtual int levelCount();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000246
247 private:
248 DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
249
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000250 virtual void createTexture();
251 virtual void updateTexture();
252 virtual void convertToRenderTarget();
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000253 virtual rx::TextureStorageInterface *getStorage(bool renderTarget);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000254
255 bool isCubeComplete() const;
256 bool isMipmapCubeComplete() const;
257
258 void setImage(int faceIndex, GLint level, GLsizei width, GLsizei height, GLenum format, GLenum type, GLint unpackAlignment, const void *pixels);
259 void commitRect(int faceIndex, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
shannon.woods@transgaming.come2e97982013-02-28 23:18:50 +0000260 void redefineImage(int faceIndex, GLint level, GLint internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000261
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000262 rx::Image *mImageArray[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000263
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000264 rx::TextureStorageInterfaceCube *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000265
266 // A specific internal reference count is kept for colorbuffer proxy references,
267 // because, as the renderbuffer acting as proxy will maintain a binding pointer
268 // back to this texture, there would be a circular reference if we used a binding
269 // pointer here. This reference count will cause the pointer to be set to NULL if
270 // the count drops to zero, but will not cause deletion of the Renderbuffer.
271 Renderbuffer *mFaceProxies[6];
272 unsigned int *mFaceProxyRefs[6];
273};
274}
275
jbauman@chromium.org68715282012-07-12 23:28:41 +0000276#endif // LIBGLESV2_TEXTURE_H_