blob: 8a92a5e72e70227f75e1dff1dd63275bf38252c8 [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
shannon.woods%transgaming.com@gtempaccount.comf26ddae2013-04-13 03:29:13 +000016#include <GLES3/gl3.h>
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000017#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;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +000034class TextureStorageInterface3D;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +000035class TextureStorageInterface2DArray;
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;
Jamie Madill3c7fa222014-06-05 13:08:51 -040043class FramebufferAttachment;
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
Nicolas Capense47e7362014-03-27 13:34:56 -040058bool IsMipmapFiltered(const SamplerState &samplerState);
59
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000060class Texture : public RefCountObject
61{
62 public:
Geoff Lang4907f2c2013-07-25 12:53:57 -040063 Texture(rx::Renderer *renderer, GLuint id, GLenum target);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000064
65 virtual ~Texture();
66
Geoff Lang4907f2c2013-07-25 12:53:57 -040067 GLenum getTarget() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000068
Geoff Lang63b5f1f2013-09-23 14:52:14 -040069 void setMinFilter(GLenum filter);
70 void setMagFilter(GLenum filter);
71 void setWrapS(GLenum wrap);
72 void setWrapT(GLenum wrap);
73 void setWrapR(GLenum wrap);
74 void setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy);
75 void setCompareMode(GLenum mode);
76 void setCompareFunc(GLenum func);
Geoff Langbc90a482013-09-17 16:51:27 -040077 void setSwizzleRed(GLenum swizzle);
78 void setSwizzleGreen(GLenum swizzle);
79 void setSwizzleBlue(GLenum swizzle);
80 void setSwizzleAlpha(GLenum swizzle);
Nicolas Capens8de68282014-04-04 11:10:27 -040081 void setBaseLevel(GLint baseLevel);
82 void setMaxLevel(GLint maxLevel);
83 void setMinLod(GLfloat minLod);
84 void setMaxLod(GLfloat maxLod);
Geoff Lang63b5f1f2013-09-23 14:52:14 -040085 void setUsage(GLenum usage);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000086
87 GLenum getMinFilter() const;
88 GLenum getMagFilter() const;
89 GLenum getWrapS() const;
90 GLenum getWrapT() const;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +000091 GLenum getWrapR() const;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +000092 float getMaxAnisotropy() const;
Geoff Langbc90a482013-09-17 16:51:27 -040093 GLenum getSwizzleRed() const;
94 GLenum getSwizzleGreen() const;
95 GLenum getSwizzleBlue() const;
96 GLenum getSwizzleAlpha() const;
Nicolas Capens8de68282014-04-04 11:10:27 -040097 GLint getBaseLevel() const;
98 GLint getMaxLevel() const;
99 GLfloat getMinLod() const;
100 GLfloat getMaxLod() const;
Geoff Langbc90a482013-09-17 16:51:27 -0400101 bool isSwizzled() const;
daniel@transgaming.comebf139f2012-10-31 18:07:32 +0000102 void getSamplerState(SamplerState *sampler);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000103 GLenum getUsage() const;
104
Jamie Madilld3d2a342013-10-07 10:46:35 -0400105 GLint getBaseLevelWidth() const;
106 GLint getBaseLevelHeight() const;
107 GLint getBaseLevelDepth() const;
108 GLenum getBaseLevelInternalFormat() const;
109
Jamie Madillf8989902013-07-19 16:36:58 -0400110 virtual bool isSamplerComplete(const SamplerState &samplerState) const = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000111
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000112 rx::TextureStorageInterface *getNativeTexture();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000113
114 virtual void generateMipmaps() = 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000115 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 +0000116
117 bool hasDirtyParameters() const;
118 bool hasDirtyImages() const;
119 void resetDirty();
120 unsigned int getTextureSerial();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000121
122 bool isImmutable() const;
Jamie Madill51a94372013-10-24 17:49:43 -0400123 int immutableLevelCount();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000124
125 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.
126
127 protected:
Jamie Madill88f18f42013-09-18 14:36:19 -0400128 void setImage(const PixelUnpackState &unpack, GLenum type, const void *pixels, rx::Image *image);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000129 bool subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
Jamie Madill88f18f42013-09-18 14:36:19 -0400130 GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels, rx::Image *image);
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000131 void setCompressedImage(GLsizei imageSize, const void *pixels, rx::Image *image);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000132 bool subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
133 GLenum format, GLsizei imageSize, const void *pixels, rx::Image *image);
Geoff Lang005df412013-10-16 14:12:50 -0400134 bool isFastUnpackable(const PixelUnpackState &unpack, GLenum sizedInternalFormat);
Jamie Madill1beb1db2013-09-18 14:36:28 -0400135 bool fastUnpackPixels(const PixelUnpackState &unpack, const void *pixels, const Box &destArea,
Jamie Madill8cc7d972013-10-10 15:51:55 -0400136 GLenum sizedInternalFormat, GLenum type, rx::RenderTarget *destRenderTarget);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000137
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000138 GLint creationLevels(GLsizei width, GLsizei height, GLsizei depth) const;
Jamie Madill22f843a2013-10-24 17:49:36 -0400139 int mipLevels() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000140
Jamie Madill73b5d062013-10-24 17:49:38 -0400141 virtual void initializeStorage(bool renderTarget) = 0;
Jamie Madill169d1112013-10-24 17:49:37 -0400142 virtual void updateStorage() = 0;
Jamie Madille83d1a92013-10-24 17:49:33 -0400143 virtual bool ensureRenderTarget() = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000144
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000145 rx::Renderer *mRenderer;
146
daniel@transgaming.comebf139f2012-10-31 18:07:32 +0000147 SamplerState mSamplerState;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000148 GLenum mUsage;
149
150 bool mDirtyImages;
151
152 bool mImmutable;
153
Geoff Lang4907f2c2013-07-25 12:53:57 -0400154 GLenum mTarget;
155
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000156 private:
157 DISALLOW_COPY_AND_ASSIGN(Texture);
158
Jamie Madill2ebab852013-10-24 17:49:42 -0400159 virtual rx::TextureStorageInterface *getBaseLevelStorage() = 0;
Jamie Madilld3d2a342013-10-07 10:46:35 -0400160 virtual const rx::Image *getBaseLevelImage() const = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000161};
162
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000163class Texture2D : public Texture
164{
165 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000166 Texture2D(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000167
168 ~Texture2D();
169
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000170 GLsizei getWidth(GLint level) const;
171 GLsizei getHeight(GLint level) const;
172 GLenum getInternalFormat(GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000173 GLenum getActualFormat(GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000174 bool isCompressed(GLint level) const;
175 bool isDepth(GLint level) const;
176
Geoff Lang005df412013-10-16 14:12:50 -0400177 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 +0000178 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400179 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 +0000180 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
181 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 +0000182 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 +0000183 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
184
Jamie Madillf8989902013-07-19 16:36:58 -0400185 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000186 virtual void bindTexImage(egl::Surface *surface);
187 virtual void releaseTexImage();
188
189 virtual void generateMipmaps();
190
Geoff Lang8040f572013-07-25 16:49:54 -0400191 unsigned int getRenderTargetSerial(GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000192
193 protected:
Jamie Madill3c7fa222014-06-05 13:08:51 -0400194 friend class Texture2DAttachment;
Geoff Lang8040f572013-07-25 16:49:54 -0400195 rx::RenderTarget *getRenderTarget(GLint level);
196 rx::RenderTarget *getDepthSencil(GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000197
198 private:
199 DISALLOW_COPY_AND_ASSIGN(Texture2D);
200
Jamie Madill73b5d062013-10-24 17:49:38 -0400201 virtual void initializeStorage(bool renderTarget);
202 rx::TextureStorageInterface2D *createCompleteStorage(bool renderTarget) const;
203 void setCompleteTexStorage(rx::TextureStorageInterface2D *newCompleteTexStorage);
204
Jamie Madill169d1112013-10-24 17:49:37 -0400205 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400206 virtual bool ensureRenderTarget();
Jamie Madill2ebab852013-10-24 17:49:42 -0400207 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400208 virtual const rx::Image *getBaseLevelImage() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000209
210 bool isMipmapComplete() const;
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400211 bool isValidLevel(int level) const;
Jamie Madill07edd442013-07-19 16:36:58 -0400212 bool isLevelComplete(int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400213 void updateStorageLevel(int level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000214
Geoff Lang005df412013-10-16 14:12:50 -0400215 void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000216 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
217
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000218 rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000219
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000220 rx::TextureStorageInterface2D *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000221 egl::Surface *mSurface;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000222};
223
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000224class TextureCubeMap : public Texture
225{
226 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000227 TextureCubeMap(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000228
229 ~TextureCubeMap();
230
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000231 GLsizei getWidth(GLenum target, GLint level) const;
232 GLsizei getHeight(GLenum target, GLint level) const;
233 GLenum getInternalFormat(GLenum target, GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000234 GLenum getActualFormat(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000235 bool isCompressed(GLenum target, GLint level) const;
Geoff Lang8040f572013-07-25 16:49:54 -0400236 bool isDepth(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000237
Geoff Lang005df412013-10-16 14:12:50 -0400238 void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
239 void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
240 void setImagePosY(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
241 void setImageNegY(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
242 void setImagePosZ(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
243 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 +0000244
Jamie Madill2db197c2013-10-24 17:49:35 -0400245 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 +0000246
Jamie Madill88f18f42013-09-18 14:36:19 -0400247 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 +0000248 void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
249 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 +0000250 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 +0000251 void storage(GLsizei levels, GLenum internalformat, GLsizei size);
252
Jamie Madillf8989902013-07-19 16:36:58 -0400253 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
Jamie Madillc1f8b162013-10-07 10:46:38 -0400254 bool isCubeComplete() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000255
256 virtual void generateMipmaps();
257
Jamie Madill2db197c2013-10-24 17:49:35 -0400258 unsigned int getRenderTargetSerial(GLenum target, GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000259
Jamie Madill2db197c2013-10-24 17:49:35 -0400260 static int targetToIndex(GLenum target);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000261
262 protected:
Jamie Madill3c7fa222014-06-05 13:08:51 -0400263 friend class TextureCubeMapAttachment;
Geoff Lang8040f572013-07-25 16:49:54 -0400264 rx::RenderTarget *getRenderTarget(GLenum target, GLint level);
265 rx::RenderTarget *getDepthStencil(GLenum target, GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000266
267 private:
268 DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
269
Jamie Madill73b5d062013-10-24 17:49:38 -0400270 virtual void initializeStorage(bool renderTarget);
Jamie Madill3c0989c2013-10-24 17:49:39 -0400271 rx::TextureStorageInterfaceCube *createCompleteStorage(bool renderTarget) const;
272 void setCompleteTexStorage(rx::TextureStorageInterfaceCube *newCompleteTexStorage);
273
Jamie Madill169d1112013-10-24 17:49:37 -0400274 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400275 virtual bool ensureRenderTarget();
Jamie Madill2ebab852013-10-24 17:49:42 -0400276 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400277 virtual const rx::Image *getBaseLevelImage() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000278
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000279 bool isMipmapCubeComplete() const;
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400280 bool isValidFaceLevel(int faceIndex, int level) const;
Jamie Madill2db197c2013-10-24 17:49:35 -0400281 bool isFaceLevelComplete(int faceIndex, int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400282 void updateStorageFaceLevel(int faceIndex, int level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000283
Geoff Lang005df412013-10-16 14:12:50 -0400284 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 +0000285 void commitRect(int faceIndex, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
Geoff Lang005df412013-10-16 14:12:50 -0400286 void redefineImage(int faceIndex, GLint level, GLenum internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000287
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000288 rx::Image *mImageArray[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000289
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000290 rx::TextureStorageInterfaceCube *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000291};
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000292
293class Texture3D : public Texture
294{
295 public:
296 Texture3D(rx::Renderer *renderer, GLuint id);
297
298 ~Texture3D();
299
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000300 GLsizei getWidth(GLint level) const;
301 GLsizei getHeight(GLint level) const;
302 GLsizei getDepth(GLint level) const;
303 GLenum getInternalFormat(GLint level) const;
304 GLenum getActualFormat(GLint level) const;
305 bool isCompressed(GLint level) const;
306 bool isDepth(GLint level) const;
307
Geoff Lang005df412013-10-16 14:12:50 -0400308 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 +0000309 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400310 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 +0000311 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
312 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
313
314 virtual void generateMipmaps();
315 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
316
Jamie Madillf8989902013-07-19 16:36:58 -0400317 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000318 virtual bool isMipmapComplete() const;
319
Geoff Lang8040f572013-07-25 16:49:54 -0400320 unsigned int getRenderTargetSerial(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000321
322 protected:
Jamie Madill3c7fa222014-06-05 13:08:51 -0400323 friend class Texture3DAttachment;
Jamie Madilla2d4e552013-10-10 15:12:01 -0400324 rx::RenderTarget *getRenderTarget(GLint level);
Geoff Lang8040f572013-07-25 16:49:54 -0400325 rx::RenderTarget *getRenderTarget(GLint level, GLint layer);
326 rx::RenderTarget *getDepthStencil(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000327
328 private:
329 DISALLOW_COPY_AND_ASSIGN(Texture3D);
330
Jamie Madill73b5d062013-10-24 17:49:38 -0400331 virtual void initializeStorage(bool renderTarget);
Jamie Madille664e202013-10-24 17:49:40 -0400332 rx::TextureStorageInterface3D *createCompleteStorage(bool renderTarget) const;
333 void setCompleteTexStorage(rx::TextureStorageInterface3D *newCompleteTexStorage);
334
Jamie Madill169d1112013-10-24 17:49:37 -0400335 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400336 virtual bool ensureRenderTarget();
337
Jamie Madill2ebab852013-10-24 17:49:42 -0400338 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400339 virtual const rx::Image *getBaseLevelImage() const;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000340
Geoff Lang005df412013-10-16 14:12:50 -0400341 void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000342 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
343
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400344 bool isValidLevel(int level) const;
Jamie Madill07edd442013-07-19 16:36:58 -0400345 bool isLevelComplete(int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400346 void updateStorageLevel(int level);
Jamie Madill07edd442013-07-19 16:36:58 -0400347
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000348 rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
349
350 rx::TextureStorageInterface3D *mTexStorage;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000351};
352
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000353class Texture2DArray : public Texture
354{
355 public:
356 Texture2DArray(rx::Renderer *renderer, GLuint id);
357
358 ~Texture2DArray();
359
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000360 GLsizei getWidth(GLint level) const;
361 GLsizei getHeight(GLint level) const;
Jamie Madillb8f8b892014-01-07 10:12:50 -0500362 GLsizei getLayers(GLint level) const;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000363 GLenum getInternalFormat(GLint level) const;
364 GLenum getActualFormat(GLint level) const;
365 bool isCompressed(GLint level) const;
366 bool isDepth(GLint level) const;
367
Geoff Lang005df412013-10-16 14:12:50 -0400368 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 +0000369 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400370 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 +0000371 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
372 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
373
374 virtual void generateMipmaps();
375 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
376
Jamie Madillf8989902013-07-19 16:36:58 -0400377 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000378 virtual bool isMipmapComplete() const;
379
Geoff Lang8040f572013-07-25 16:49:54 -0400380 unsigned int getRenderTargetSerial(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000381
382 protected:
Jamie Madill3c7fa222014-06-05 13:08:51 -0400383 friend class Texture2DArrayAttachment;
Geoff Lang8040f572013-07-25 16:49:54 -0400384 rx::RenderTarget *getRenderTarget(GLint level, GLint layer);
385 rx::RenderTarget *getDepthStencil(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000386
387 private:
388 DISALLOW_COPY_AND_ASSIGN(Texture2DArray);
389
Jamie Madill73b5d062013-10-24 17:49:38 -0400390 virtual void initializeStorage(bool renderTarget);
Jamie Madill884a4622013-10-24 17:49:41 -0400391 rx::TextureStorageInterface2DArray *createCompleteStorage(bool renderTarget) const;
392 void setCompleteTexStorage(rx::TextureStorageInterface2DArray *newCompleteTexStorage);
393
Jamie Madill169d1112013-10-24 17:49:37 -0400394 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400395 virtual bool ensureRenderTarget();
396
Jamie Madill2ebab852013-10-24 17:49:42 -0400397 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400398 virtual const rx::Image *getBaseLevelImage() const;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000399
Jamie Madill884a4622013-10-24 17:49:41 -0400400 void deleteImages();
Geoff Lang005df412013-10-16 14:12:50 -0400401 void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000402 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLint layerTarget, GLsizei width, GLsizei height);
403
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400404 bool isValidLevel(int level) const;
Jamie Madill07edd442013-07-19 16:36:58 -0400405 bool isLevelComplete(int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400406 void updateStorageLevel(int level);
Jamie Madill07edd442013-07-19 16:36:58 -0400407
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000408 // Storing images as an array of single depth textures since D3D11 treats each array level of a
409 // Texture2D object as a separate subresource. Each layer would have to be looped over
410 // to update all the texture layers since they cannot all be updated at once and it makes the most
411 // 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 +0000412 GLsizei mLayerCounts[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
shannonwoods@chromium.org644f7662013-05-30 00:02:07 +0000413 rx::Image **mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000414
415 rx::TextureStorageInterface2DArray *mTexStorage;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000416};
417
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000418}
419
jbauman@chromium.org68715282012-07-12 23:28:41 +0000420#endif // LIBGLESV2_TEXTURE_H_