blob: 143f7acf84318fc3096c87749a157896771509e3 [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"
Geoff Lang8040f572013-07-25 16:49:54 -040023#include "libGLESv2/RenderbufferProxySet.h"
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000024
25namespace egl
26{
27class Surface;
28}
29
daniel@transgaming.com370482e2012-11-28 19:32:13 +000030namespace rx
31{
32class Renderer;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000033class TextureStorageInterface;
34class TextureStorageInterface2D;
35class TextureStorageInterfaceCube;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +000036class TextureStorageInterface3D;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +000037class TextureStorageInterface2DArray;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000038class RenderTarget;
39class Image;
daniel@transgaming.com370482e2012-11-28 19:32:13 +000040}
41
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000042namespace gl
43{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000044class Framebuffer;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000045class Renderbuffer;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000046
47enum
48{
49 // These are the maximums the implementation can support
50 // The actual GL caps are limited by the device caps
51 // and should be queried from the Context
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +000052 IMPLEMENTATION_MAX_2D_TEXTURE_SIZE = 16384,
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000053 IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 16384,
shannon.woods%transgaming.com@gtempaccount.comc1fdf6b2013-04-13 03:44:41 +000054 IMPLEMENTATION_MAX_3D_TEXTURE_SIZE = 2048,
shannon.woods%transgaming.com@gtempaccount.coma98a8112013-04-13 03:45:57 +000055 IMPLEMENTATION_MAX_2D_ARRAY_TEXTURE_LAYERS = 2048,
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000056
57 IMPLEMENTATION_MAX_TEXTURE_LEVELS = 15 // 1+log2 of MAX_TEXTURE_SIZE
58};
59
Nicolas Capense47e7362014-03-27 13:34:56 -040060bool IsMipmapFiltered(const SamplerState &samplerState);
61
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000062class Texture : public RefCountObject
63{
64 public:
Geoff Lang4907f2c2013-07-25 12:53:57 -040065 Texture(rx::Renderer *renderer, GLuint id, GLenum target);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000066
67 virtual ~Texture();
68
Geoff Lang8040f572013-07-25 16:49:54 -040069 void addProxyRef(const Renderbuffer *proxy);
70 void releaseProxy(const Renderbuffer *proxy);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000071
Geoff Lang4907f2c2013-07-25 12:53:57 -040072 GLenum getTarget() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000073
Geoff Lang63b5f1f2013-09-23 14:52:14 -040074 void setMinFilter(GLenum filter);
75 void setMagFilter(GLenum filter);
76 void setWrapS(GLenum wrap);
77 void setWrapT(GLenum wrap);
78 void setWrapR(GLenum wrap);
79 void setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy);
80 void setCompareMode(GLenum mode);
81 void setCompareFunc(GLenum func);
Geoff Langbc90a482013-09-17 16:51:27 -040082 void setSwizzleRed(GLenum swizzle);
83 void setSwizzleGreen(GLenum swizzle);
84 void setSwizzleBlue(GLenum swizzle);
85 void setSwizzleAlpha(GLenum swizzle);
Geoff Lang63b5f1f2013-09-23 14:52:14 -040086 void setUsage(GLenum usage);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000087
88 GLenum getMinFilter() const;
89 GLenum getMagFilter() const;
90 GLenum getWrapS() const;
91 GLenum getWrapT() const;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +000092 GLenum getWrapR() const;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +000093 float getMaxAnisotropy() const;
Geoff Langbc90a482013-09-17 16:51:27 -040094 GLenum getSwizzleRed() const;
95 GLenum getSwizzleGreen() const;
96 GLenum getSwizzleBlue() const;
97 GLenum getSwizzleAlpha() const;
98 bool isSwizzled() const;
daniel@transgaming.comebf139f2012-10-31 18:07:32 +000099 int getLodOffset();
100 void getSamplerState(SamplerState *sampler);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000101 GLenum getUsage() const;
102
Jamie Madilld3d2a342013-10-07 10:46:35 -0400103 GLint getBaseLevelWidth() const;
104 GLint getBaseLevelHeight() const;
105 GLint getBaseLevelDepth() const;
106 GLenum getBaseLevelInternalFormat() const;
107
Jamie Madillf8989902013-07-19 16:36:58 -0400108 virtual bool isSamplerComplete(const SamplerState &samplerState) const = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000109
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000110 rx::TextureStorageInterface *getNativeTexture();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000111
112 virtual void generateMipmaps() = 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000113 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 +0000114
115 bool hasDirtyParameters() const;
116 bool hasDirtyImages() const;
117 void resetDirty();
118 unsigned int getTextureSerial();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000119
120 bool isImmutable() const;
Jamie Madill51a94372013-10-24 17:49:43 -0400121 int immutableLevelCount();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000122
123 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.
124
125 protected:
Jamie Madill88f18f42013-09-18 14:36:19 -0400126 void setImage(const PixelUnpackState &unpack, GLenum type, const void *pixels, rx::Image *image);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000127 bool subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
Jamie Madill88f18f42013-09-18 14:36:19 -0400128 GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels, rx::Image *image);
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000129 void setCompressedImage(GLsizei imageSize, const void *pixels, rx::Image *image);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000130 bool subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
131 GLenum format, GLsizei imageSize, const void *pixels, rx::Image *image);
Geoff Lang005df412013-10-16 14:12:50 -0400132 bool isFastUnpackable(const PixelUnpackState &unpack, GLenum sizedInternalFormat);
Jamie Madill1beb1db2013-09-18 14:36:28 -0400133 bool fastUnpackPixels(const PixelUnpackState &unpack, const void *pixels, const Box &destArea,
Jamie Madill8cc7d972013-10-10 15:51:55 -0400134 GLenum sizedInternalFormat, GLenum type, rx::RenderTarget *destRenderTarget);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000135
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000136 GLint creationLevels(GLsizei width, GLsizei height, GLsizei depth) const;
Jamie Madill22f843a2013-10-24 17:49:36 -0400137 int mipLevels() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000138
Jamie Madill73b5d062013-10-24 17:49:38 -0400139 virtual void initializeStorage(bool renderTarget) = 0;
Jamie Madill169d1112013-10-24 17:49:37 -0400140 virtual void updateStorage() = 0;
Jamie Madille83d1a92013-10-24 17:49:33 -0400141 virtual bool ensureRenderTarget() = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000142
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000143 rx::Renderer *mRenderer;
144
daniel@transgaming.comebf139f2012-10-31 18:07:32 +0000145 SamplerState mSamplerState;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000146 GLenum mUsage;
147
148 bool mDirtyImages;
149
150 bool mImmutable;
151
Geoff Lang4907f2c2013-07-25 12:53:57 -0400152 GLenum mTarget;
153
Geoff Lang8040f572013-07-25 16:49:54 -0400154 // A specific internal reference count is kept for colorbuffer proxy references,
155 // because, as the renderbuffer acting as proxy will maintain a binding pointer
156 // back to this texture, there would be a circular reference if we used a binding
157 // pointer here. This reference count will cause the pointer to be set to NULL if
158 // the count drops to zero, but will not cause deletion of the Renderbuffer.
159 RenderbufferProxySet mRenderbufferProxies;
160
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000161 private:
162 DISALLOW_COPY_AND_ASSIGN(Texture);
163
Jamie Madill2ebab852013-10-24 17:49:42 -0400164 virtual rx::TextureStorageInterface *getBaseLevelStorage() = 0;
Jamie Madilld3d2a342013-10-07 10:46:35 -0400165 virtual const rx::Image *getBaseLevelImage() const = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000166};
167
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000168class Texture2D : public Texture
169{
170 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000171 Texture2D(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000172
173 ~Texture2D();
174
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000175 GLsizei getWidth(GLint level) const;
176 GLsizei getHeight(GLint level) const;
177 GLenum getInternalFormat(GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000178 GLenum getActualFormat(GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000179 bool isCompressed(GLint level) const;
180 bool isDepth(GLint level) const;
181
Geoff Lang005df412013-10-16 14:12:50 -0400182 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 +0000183 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400184 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 +0000185 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
186 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 +0000187 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 +0000188 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
189
Jamie Madillf8989902013-07-19 16:36:58 -0400190 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000191 virtual void bindTexImage(egl::Surface *surface);
192 virtual void releaseTexImage();
193
194 virtual void generateMipmaps();
195
Geoff Lang8040f572013-07-25 16:49:54 -0400196 Renderbuffer *getRenderbuffer(GLint level);
197 unsigned int getRenderTargetSerial(GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000198
199 protected:
200 friend class RenderbufferTexture2D;
Geoff Lang8040f572013-07-25 16:49:54 -0400201 rx::RenderTarget *getRenderTarget(GLint level);
202 rx::RenderTarget *getDepthSencil(GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000203
204 private:
205 DISALLOW_COPY_AND_ASSIGN(Texture2D);
206
Jamie Madill73b5d062013-10-24 17:49:38 -0400207 virtual void initializeStorage(bool renderTarget);
208 rx::TextureStorageInterface2D *createCompleteStorage(bool renderTarget) const;
209 void setCompleteTexStorage(rx::TextureStorageInterface2D *newCompleteTexStorage);
210
Jamie Madill169d1112013-10-24 17:49:37 -0400211 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400212 virtual bool ensureRenderTarget();
Jamie Madill2ebab852013-10-24 17:49:42 -0400213 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400214 virtual const rx::Image *getBaseLevelImage() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000215
216 bool isMipmapComplete() const;
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400217 bool isValidLevel(int level) const;
Jamie Madill07edd442013-07-19 16:36:58 -0400218 bool isLevelComplete(int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400219 void updateStorageLevel(int level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000220
Geoff Lang005df412013-10-16 14:12:50 -0400221 void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000222 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
223
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000224 rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000225
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000226 rx::TextureStorageInterface2D *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000227 egl::Surface *mSurface;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000228};
229
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000230class TextureCubeMap : public Texture
231{
232 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000233 TextureCubeMap(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000234
235 ~TextureCubeMap();
236
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000237 GLsizei getWidth(GLenum target, GLint level) const;
238 GLsizei getHeight(GLenum target, GLint level) const;
239 GLenum getInternalFormat(GLenum target, GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000240 GLenum getActualFormat(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000241 bool isCompressed(GLenum target, GLint level) const;
Geoff Lang8040f572013-07-25 16:49:54 -0400242 bool isDepth(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000243
Geoff Lang005df412013-10-16 14:12:50 -0400244 void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
245 void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
246 void setImagePosY(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
247 void setImageNegY(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
248 void setImagePosZ(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
249 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 +0000250
Jamie Madill2db197c2013-10-24 17:49:35 -0400251 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 +0000252
Jamie Madill88f18f42013-09-18 14:36:19 -0400253 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 +0000254 void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
255 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 +0000256 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 +0000257 void storage(GLsizei levels, GLenum internalformat, GLsizei size);
258
Jamie Madillf8989902013-07-19 16:36:58 -0400259 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
Jamie Madillc1f8b162013-10-07 10:46:38 -0400260 bool isCubeComplete() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000261
262 virtual void generateMipmaps();
263
Geoff Lang8040f572013-07-25 16:49:54 -0400264 Renderbuffer *getRenderbuffer(GLenum target, GLint level);
Jamie Madill2db197c2013-10-24 17:49:35 -0400265 unsigned int getRenderTargetSerial(GLenum target, GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000266
Jamie Madill2db197c2013-10-24 17:49:35 -0400267 static int targetToIndex(GLenum target);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000268
269 protected:
270 friend class RenderbufferTextureCubeMap;
Geoff Lang8040f572013-07-25 16:49:54 -0400271 rx::RenderTarget *getRenderTarget(GLenum target, GLint level);
272 rx::RenderTarget *getDepthStencil(GLenum target, GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000273
274 private:
275 DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
276
Jamie Madill73b5d062013-10-24 17:49:38 -0400277 virtual void initializeStorage(bool renderTarget);
Jamie Madill3c0989c2013-10-24 17:49:39 -0400278 rx::TextureStorageInterfaceCube *createCompleteStorage(bool renderTarget) const;
279 void setCompleteTexStorage(rx::TextureStorageInterfaceCube *newCompleteTexStorage);
280
Jamie Madill169d1112013-10-24 17:49:37 -0400281 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400282 virtual bool ensureRenderTarget();
Jamie Madill2ebab852013-10-24 17:49:42 -0400283 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400284 virtual const rx::Image *getBaseLevelImage() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000285
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000286 bool isMipmapCubeComplete() const;
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400287 bool isValidFaceLevel(int faceIndex, int level) const;
Jamie Madill2db197c2013-10-24 17:49:35 -0400288 bool isFaceLevelComplete(int faceIndex, int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400289 void updateStorageFaceLevel(int faceIndex, int level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000290
Geoff Lang005df412013-10-16 14:12:50 -0400291 void setImage(int faceIndex, 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 +0000292 void commitRect(int faceIndex, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
Geoff Lang005df412013-10-16 14:12:50 -0400293 void redefineImage(int faceIndex, GLint level, GLenum internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000294
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000295 rx::Image *mImageArray[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000296
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000297 rx::TextureStorageInterfaceCube *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000298};
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000299
300class Texture3D : public Texture
301{
302 public:
303 Texture3D(rx::Renderer *renderer, GLuint id);
304
305 ~Texture3D();
306
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000307 GLsizei getWidth(GLint level) const;
308 GLsizei getHeight(GLint level) const;
309 GLsizei getDepth(GLint level) const;
310 GLenum getInternalFormat(GLint level) const;
311 GLenum getActualFormat(GLint level) const;
312 bool isCompressed(GLint level) const;
313 bool isDepth(GLint level) const;
314
Geoff Lang005df412013-10-16 14:12:50 -0400315 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 +0000316 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400317 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 +0000318 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
319 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
320
321 virtual void generateMipmaps();
322 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
323
Jamie Madillf8989902013-07-19 16:36:58 -0400324 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000325 virtual bool isMipmapComplete() const;
326
Geoff Lang8040f572013-07-25 16:49:54 -0400327 Renderbuffer *getRenderbuffer(GLint level, GLint layer);
328 unsigned int getRenderTargetSerial(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000329
330 protected:
Geoff Langd5d8e392013-07-25 16:53:03 -0400331 friend class RenderbufferTexture3DLayer;
Jamie Madilla2d4e552013-10-10 15:12:01 -0400332 rx::RenderTarget *getRenderTarget(GLint level);
Geoff Lang8040f572013-07-25 16:49:54 -0400333 rx::RenderTarget *getRenderTarget(GLint level, GLint layer);
334 rx::RenderTarget *getDepthStencil(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000335
336 private:
337 DISALLOW_COPY_AND_ASSIGN(Texture3D);
338
Jamie Madill73b5d062013-10-24 17:49:38 -0400339 virtual void initializeStorage(bool renderTarget);
Jamie Madille664e202013-10-24 17:49:40 -0400340 rx::TextureStorageInterface3D *createCompleteStorage(bool renderTarget) const;
341 void setCompleteTexStorage(rx::TextureStorageInterface3D *newCompleteTexStorage);
342
Jamie Madill169d1112013-10-24 17:49:37 -0400343 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400344 virtual bool ensureRenderTarget();
345
Jamie Madill2ebab852013-10-24 17:49:42 -0400346 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400347 virtual const rx::Image *getBaseLevelImage() const;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000348
Geoff Lang005df412013-10-16 14:12:50 -0400349 void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000350 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
351
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400352 bool isValidLevel(int level) const;
Jamie Madill07edd442013-07-19 16:36:58 -0400353 bool isLevelComplete(int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400354 void updateStorageLevel(int level);
Jamie Madill07edd442013-07-19 16:36:58 -0400355
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000356 rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
357
358 rx::TextureStorageInterface3D *mTexStorage;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000359};
360
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000361class Texture2DArray : public Texture
362{
363 public:
364 Texture2DArray(rx::Renderer *renderer, GLuint id);
365
366 ~Texture2DArray();
367
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000368 GLsizei getWidth(GLint level) const;
369 GLsizei getHeight(GLint level) const;
Jamie Madillb8f8b892014-01-07 10:12:50 -0500370 GLsizei getLayers(GLint level) const;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000371 GLenum getInternalFormat(GLint level) const;
372 GLenum getActualFormat(GLint level) const;
373 bool isCompressed(GLint level) const;
374 bool isDepth(GLint level) const;
375
Geoff Lang005df412013-10-16 14:12:50 -0400376 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 +0000377 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400378 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 +0000379 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
380 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
381
382 virtual void generateMipmaps();
383 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
384
Jamie Madillf8989902013-07-19 16:36:58 -0400385 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000386 virtual bool isMipmapComplete() const;
387
Geoff Lang8040f572013-07-25 16:49:54 -0400388 Renderbuffer *getRenderbuffer(GLint level, GLint layer);
389 unsigned int getRenderTargetSerial(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000390
391 protected:
Geoff Langd5d8e392013-07-25 16:53:03 -0400392 friend class RenderbufferTexture2DArrayLayer;
Geoff Lang8040f572013-07-25 16:49:54 -0400393 rx::RenderTarget *getRenderTarget(GLint level, GLint layer);
394 rx::RenderTarget *getDepthStencil(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000395
396 private:
397 DISALLOW_COPY_AND_ASSIGN(Texture2DArray);
398
Jamie Madill73b5d062013-10-24 17:49:38 -0400399 virtual void initializeStorage(bool renderTarget);
Jamie Madill884a4622013-10-24 17:49:41 -0400400 rx::TextureStorageInterface2DArray *createCompleteStorage(bool renderTarget) const;
401 void setCompleteTexStorage(rx::TextureStorageInterface2DArray *newCompleteTexStorage);
402
Jamie Madill169d1112013-10-24 17:49:37 -0400403 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400404 virtual bool ensureRenderTarget();
405
Jamie Madill2ebab852013-10-24 17:49:42 -0400406 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400407 virtual const rx::Image *getBaseLevelImage() const;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000408
Jamie Madill884a4622013-10-24 17:49:41 -0400409 void deleteImages();
Geoff Lang005df412013-10-16 14:12:50 -0400410 void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000411 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLint layerTarget, GLsizei width, GLsizei height);
412
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400413 bool isValidLevel(int level) const;
Jamie Madill07edd442013-07-19 16:36:58 -0400414 bool isLevelComplete(int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400415 void updateStorageLevel(int level);
Jamie Madill07edd442013-07-19 16:36:58 -0400416
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000417 // Storing images as an array of single depth textures since D3D11 treats each array level of a
418 // Texture2D object as a separate subresource. Each layer would have to be looped over
419 // to update all the texture layers since they cannot all be updated at once and it makes the most
420 // sense for the Image class to not have to worry about layer subresource as well as mip subresources.
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000421 GLsizei mLayerCounts[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
shannonwoods@chromium.org644f7662013-05-30 00:02:07 +0000422 rx::Image **mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000423
424 rx::TextureStorageInterface2DArray *mTexStorage;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000425};
426
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000427}
428
jbauman@chromium.org68715282012-07-12 23:28:41 +0000429#endif // LIBGLESV2_TEXTURE_H_