blob: 07bef2e8017a4e75df01be47e55491fe9f51a840 [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
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 Lang8040f572013-07-25 16:49:54 -040067 void addProxyRef(const Renderbuffer *proxy);
68 void releaseProxy(const Renderbuffer *proxy);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000069
Geoff Lang4907f2c2013-07-25 12:53:57 -040070 GLenum getTarget() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000071
Geoff Lang63b5f1f2013-09-23 14:52:14 -040072 void setMinFilter(GLenum filter);
73 void setMagFilter(GLenum filter);
74 void setWrapS(GLenum wrap);
75 void setWrapT(GLenum wrap);
76 void setWrapR(GLenum wrap);
77 void setMaxAnisotropy(float textureMaxAnisotropy, float contextMaxAnisotropy);
78 void setCompareMode(GLenum mode);
79 void setCompareFunc(GLenum func);
80 void setUsage(GLenum usage);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000081
82 GLenum getMinFilter() const;
83 GLenum getMagFilter() const;
84 GLenum getWrapS() const;
85 GLenum getWrapT() const;
shannon.woods%transgaming.com@gtempaccount.com0b3a8df2013-04-13 03:44:51 +000086 GLenum getWrapR() const;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +000087 float getMaxAnisotropy() const;
daniel@transgaming.comebf139f2012-10-31 18:07:32 +000088 int getLodOffset();
89 void getSamplerState(SamplerState *sampler);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000090 GLenum getUsage() const;
91
Jamie Madilld3d2a342013-10-07 10:46:35 -040092 GLint getBaseLevelWidth() const;
93 GLint getBaseLevelHeight() const;
94 GLint getBaseLevelDepth() const;
95 GLenum getBaseLevelInternalFormat() const;
96
Jamie Madillf8989902013-07-19 16:36:58 -040097 virtual bool isSamplerComplete(const SamplerState &samplerState) const = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000098
daniel@transgaming.com87705f82012-12-20 21:10:45 +000099 rx::TextureStorageInterface *getNativeTexture();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000100
101 virtual void generateMipmaps() = 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000102 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 +0000103
104 bool hasDirtyParameters() const;
105 bool hasDirtyImages() const;
106 void resetDirty();
107 unsigned int getTextureSerial();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000108
109 bool isImmutable() const;
Jamie Madill51a94372013-10-24 17:49:43 -0400110 int immutableLevelCount();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000111
112 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.
113
114 protected:
Jamie Madill88f18f42013-09-18 14:36:19 -0400115 void setImage(const PixelUnpackState &unpack, GLenum type, const void *pixels, rx::Image *image);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000116 bool subImage(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
Jamie Madill88f18f42013-09-18 14:36:19 -0400117 GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels, rx::Image *image);
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000118 void setCompressedImage(GLsizei imageSize, const void *pixels, rx::Image *image);
shannon.woods%transgaming.com@gtempaccount.com4760c562013-04-13 03:42:30 +0000119 bool subImageCompressed(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
120 GLenum format, GLsizei imageSize, const void *pixels, rx::Image *image);
Geoff Lang005df412013-10-16 14:12:50 -0400121 bool isFastUnpackable(const PixelUnpackState &unpack, GLenum sizedInternalFormat);
Jamie Madill1beb1db2013-09-18 14:36:28 -0400122 bool fastUnpackPixels(const PixelUnpackState &unpack, const void *pixels, const Box &destArea,
Jamie Madill8cc7d972013-10-10 15:51:55 -0400123 GLenum sizedInternalFormat, GLenum type, rx::RenderTarget *destRenderTarget);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000124
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000125 GLint creationLevels(GLsizei width, GLsizei height, GLsizei depth) const;
Jamie Madill22f843a2013-10-24 17:49:36 -0400126 int mipLevels() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000127
Jamie Madill73b5d062013-10-24 17:49:38 -0400128 virtual void initializeStorage(bool renderTarget) = 0;
Jamie Madill169d1112013-10-24 17:49:37 -0400129 virtual void updateStorage() = 0;
Jamie Madille83d1a92013-10-24 17:49:33 -0400130 virtual bool ensureRenderTarget() = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000131
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000132 rx::Renderer *mRenderer;
133
daniel@transgaming.comebf139f2012-10-31 18:07:32 +0000134 SamplerState mSamplerState;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000135 GLenum mUsage;
136
137 bool mDirtyImages;
138
139 bool mImmutable;
140
Geoff Lang4907f2c2013-07-25 12:53:57 -0400141 GLenum mTarget;
142
Geoff Lang8040f572013-07-25 16:49:54 -0400143 // A specific internal reference count is kept for colorbuffer proxy references,
144 // because, as the renderbuffer acting as proxy will maintain a binding pointer
145 // back to this texture, there would be a circular reference if we used a binding
146 // pointer here. This reference count will cause the pointer to be set to NULL if
147 // the count drops to zero, but will not cause deletion of the Renderbuffer.
148 RenderbufferProxySet mRenderbufferProxies;
149
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000150 private:
151 DISALLOW_COPY_AND_ASSIGN(Texture);
152
Jamie Madill2ebab852013-10-24 17:49:42 -0400153 virtual rx::TextureStorageInterface *getBaseLevelStorage() = 0;
Jamie Madilld3d2a342013-10-07 10:46:35 -0400154 virtual const rx::Image *getBaseLevelImage() const = 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000155};
156
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000157class Texture2D : public Texture
158{
159 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000160 Texture2D(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000161
162 ~Texture2D();
163
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000164 GLsizei getWidth(GLint level) const;
165 GLsizei getHeight(GLint level) const;
166 GLenum getInternalFormat(GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000167 GLenum getActualFormat(GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000168 bool isCompressed(GLint level) const;
169 bool isDepth(GLint level) const;
170
Geoff Lang005df412013-10-16 14:12:50 -0400171 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 +0000172 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400173 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 +0000174 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
175 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 +0000176 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 +0000177 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
178
Jamie Madillf8989902013-07-19 16:36:58 -0400179 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000180 virtual void bindTexImage(egl::Surface *surface);
181 virtual void releaseTexImage();
182
183 virtual void generateMipmaps();
184
Geoff Lang8040f572013-07-25 16:49:54 -0400185 Renderbuffer *getRenderbuffer(GLint level);
186 unsigned int getRenderTargetSerial(GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000187
188 protected:
189 friend class RenderbufferTexture2D;
Geoff Lang8040f572013-07-25 16:49:54 -0400190 rx::RenderTarget *getRenderTarget(GLint level);
191 rx::RenderTarget *getDepthSencil(GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000192
193 private:
194 DISALLOW_COPY_AND_ASSIGN(Texture2D);
195
Jamie Madill73b5d062013-10-24 17:49:38 -0400196 virtual void initializeStorage(bool renderTarget);
197 rx::TextureStorageInterface2D *createCompleteStorage(bool renderTarget) const;
198 void setCompleteTexStorage(rx::TextureStorageInterface2D *newCompleteTexStorage);
199
Jamie Madill169d1112013-10-24 17:49:37 -0400200 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400201 virtual bool ensureRenderTarget();
Jamie Madill2ebab852013-10-24 17:49:42 -0400202 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400203 virtual const rx::Image *getBaseLevelImage() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000204
205 bool isMipmapComplete() const;
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400206 bool isValidLevel(int level) const;
Jamie Madill07edd442013-07-19 16:36:58 -0400207 bool isLevelComplete(int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400208 void updateStorageLevel(int level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000209
Geoff Lang005df412013-10-16 14:12:50 -0400210 void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000211 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
212
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000213 rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000214
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000215 rx::TextureStorageInterface2D *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000216 egl::Surface *mSurface;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000217};
218
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000219class TextureCubeMap : public Texture
220{
221 public:
daniel@transgaming.com370482e2012-11-28 19:32:13 +0000222 TextureCubeMap(rx::Renderer *renderer, GLuint id);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000223
224 ~TextureCubeMap();
225
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000226 GLsizei getWidth(GLenum target, GLint level) const;
227 GLsizei getHeight(GLenum target, GLint level) const;
228 GLenum getInternalFormat(GLenum target, GLint level) const;
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000229 GLenum getActualFormat(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000230 bool isCompressed(GLenum target, GLint level) const;
Geoff Lang8040f572013-07-25 16:49:54 -0400231 bool isDepth(GLenum target, GLint level) const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000232
Geoff Lang005df412013-10-16 14:12:50 -0400233 void setImagePosX(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
234 void setImageNegX(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
235 void setImagePosY(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
236 void setImageNegY(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
237 void setImagePosZ(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels);
238 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 +0000239
Jamie Madill2db197c2013-10-24 17:49:35 -0400240 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 +0000241
Jamie Madill88f18f42013-09-18 14:36:19 -0400242 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 +0000243 void subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels);
244 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 +0000245 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 +0000246 void storage(GLsizei levels, GLenum internalformat, GLsizei size);
247
Jamie Madillf8989902013-07-19 16:36:58 -0400248 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
Jamie Madillc1f8b162013-10-07 10:46:38 -0400249 bool isCubeComplete() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000250
251 virtual void generateMipmaps();
252
Geoff Lang8040f572013-07-25 16:49:54 -0400253 Renderbuffer *getRenderbuffer(GLenum target, GLint level);
Jamie Madill2db197c2013-10-24 17:49:35 -0400254 unsigned int getRenderTargetSerial(GLenum target, GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000255
Jamie Madill2db197c2013-10-24 17:49:35 -0400256 static int targetToIndex(GLenum target);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000257
258 protected:
259 friend class RenderbufferTextureCubeMap;
Geoff Lang8040f572013-07-25 16:49:54 -0400260 rx::RenderTarget *getRenderTarget(GLenum target, GLint level);
261 rx::RenderTarget *getDepthStencil(GLenum target, GLint level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000262
263 private:
264 DISALLOW_COPY_AND_ASSIGN(TextureCubeMap);
265
Jamie Madill73b5d062013-10-24 17:49:38 -0400266 virtual void initializeStorage(bool renderTarget);
Jamie Madill3c0989c2013-10-24 17:49:39 -0400267 rx::TextureStorageInterfaceCube *createCompleteStorage(bool renderTarget) const;
268 void setCompleteTexStorage(rx::TextureStorageInterfaceCube *newCompleteTexStorage);
269
Jamie Madill169d1112013-10-24 17:49:37 -0400270 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400271 virtual bool ensureRenderTarget();
Jamie Madill2ebab852013-10-24 17:49:42 -0400272 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400273 virtual const rx::Image *getBaseLevelImage() const;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000274
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000275 bool isMipmapCubeComplete() const;
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400276 bool isValidFaceLevel(int faceIndex, int level) const;
Jamie Madill2db197c2013-10-24 17:49:35 -0400277 bool isFaceLevelComplete(int faceIndex, int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400278 void updateStorageFaceLevel(int faceIndex, int level);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000279
Geoff Lang005df412013-10-16 14:12:50 -0400280 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 +0000281 void commitRect(int faceIndex, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
Geoff Lang005df412013-10-16 14:12:50 -0400282 void redefineImage(int faceIndex, GLint level, GLenum internalformat, GLsizei width, GLsizei height);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000283
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000284 rx::Image *mImageArray[6][IMPLEMENTATION_MAX_TEXTURE_LEVELS];
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000285
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000286 rx::TextureStorageInterfaceCube *mTexStorage;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000287};
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000288
289class Texture3D : public Texture
290{
291 public:
292 Texture3D(rx::Renderer *renderer, GLuint id);
293
294 ~Texture3D();
295
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000296 GLsizei getWidth(GLint level) const;
297 GLsizei getHeight(GLint level) const;
298 GLsizei getDepth(GLint level) const;
299 GLenum getInternalFormat(GLint level) const;
300 GLenum getActualFormat(GLint level) const;
301 bool isCompressed(GLint level) const;
302 bool isDepth(GLint level) const;
303
Geoff Lang005df412013-10-16 14:12:50 -0400304 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 +0000305 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400306 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 +0000307 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
308 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
309
310 virtual void generateMipmaps();
311 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
312
Jamie Madillf8989902013-07-19 16:36:58 -0400313 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000314 virtual bool isMipmapComplete() const;
315
Geoff Lang8040f572013-07-25 16:49:54 -0400316 Renderbuffer *getRenderbuffer(GLint level, GLint layer);
317 unsigned int getRenderTargetSerial(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000318
319 protected:
Geoff Langd5d8e392013-07-25 16:53:03 -0400320 friend class RenderbufferTexture3DLayer;
Jamie Madilla2d4e552013-10-10 15:12:01 -0400321 rx::RenderTarget *getRenderTarget(GLint level);
Geoff Lang8040f572013-07-25 16:49:54 -0400322 rx::RenderTarget *getRenderTarget(GLint level, GLint layer);
323 rx::RenderTarget *getDepthStencil(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000324
325 private:
326 DISALLOW_COPY_AND_ASSIGN(Texture3D);
327
Jamie Madill73b5d062013-10-24 17:49:38 -0400328 virtual void initializeStorage(bool renderTarget);
Jamie Madille664e202013-10-24 17:49:40 -0400329 rx::TextureStorageInterface3D *createCompleteStorage(bool renderTarget) const;
330 void setCompleteTexStorage(rx::TextureStorageInterface3D *newCompleteTexStorage);
331
Jamie Madill169d1112013-10-24 17:49:37 -0400332 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400333 virtual bool ensureRenderTarget();
334
Jamie Madill2ebab852013-10-24 17:49:42 -0400335 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400336 virtual const rx::Image *getBaseLevelImage() const;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000337
Geoff Lang005df412013-10-16 14:12:50 -0400338 void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000339 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth);
340
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400341 bool isValidLevel(int level) const;
Jamie Madill07edd442013-07-19 16:36:58 -0400342 bool isLevelComplete(int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400343 void updateStorageLevel(int level);
Jamie Madill07edd442013-07-19 16:36:58 -0400344
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000345 rx::Image *mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
346
347 rx::TextureStorageInterface3D *mTexStorage;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000348};
349
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000350class Texture2DArray : public Texture
351{
352 public:
353 Texture2DArray(rx::Renderer *renderer, GLuint id);
354
355 ~Texture2DArray();
356
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000357 GLsizei getWidth(GLint level) const;
358 GLsizei getHeight(GLint level) const;
359 GLsizei getDepth(GLint level) const;
360 GLenum getInternalFormat(GLint level) const;
361 GLenum getActualFormat(GLint level) const;
362 bool isCompressed(GLint level) const;
363 bool isDepth(GLint level) const;
364
Geoff Lang005df412013-10-16 14:12:50 -0400365 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 +0000366 void setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
Jamie Madill88f18f42013-09-18 14:36:19 -0400367 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 +0000368 void subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels);
369 void storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
370
371 virtual void generateMipmaps();
372 virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
373
Jamie Madillf8989902013-07-19 16:36:58 -0400374 virtual bool isSamplerComplete(const SamplerState &samplerState) const;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000375 virtual bool isMipmapComplete() const;
376
Geoff Lang8040f572013-07-25 16:49:54 -0400377 Renderbuffer *getRenderbuffer(GLint level, GLint layer);
378 unsigned int getRenderTargetSerial(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000379
380 protected:
Geoff Langd5d8e392013-07-25 16:53:03 -0400381 friend class RenderbufferTexture2DArrayLayer;
Geoff Lang8040f572013-07-25 16:49:54 -0400382 rx::RenderTarget *getRenderTarget(GLint level, GLint layer);
383 rx::RenderTarget *getDepthStencil(GLint level, GLint layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000384
385 private:
386 DISALLOW_COPY_AND_ASSIGN(Texture2DArray);
387
Jamie Madill73b5d062013-10-24 17:49:38 -0400388 virtual void initializeStorage(bool renderTarget);
Jamie Madill884a4622013-10-24 17:49:41 -0400389 rx::TextureStorageInterface2DArray *createCompleteStorage(bool renderTarget) const;
390 void setCompleteTexStorage(rx::TextureStorageInterface2DArray *newCompleteTexStorage);
391
Jamie Madill169d1112013-10-24 17:49:37 -0400392 virtual void updateStorage();
Jamie Madille83d1a92013-10-24 17:49:33 -0400393 virtual bool ensureRenderTarget();
394
Jamie Madill2ebab852013-10-24 17:49:42 -0400395 virtual rx::TextureStorageInterface *getBaseLevelStorage();
Jamie Madilld3d2a342013-10-07 10:46:35 -0400396 virtual const rx::Image *getBaseLevelImage() const;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000397
Jamie Madill884a4622013-10-24 17:49:41 -0400398 void deleteImages();
Geoff Lang005df412013-10-16 14:12:50 -0400399 void redefineImage(GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000400 void commitRect(GLint level, GLint xoffset, GLint yoffset, GLint layerTarget, GLsizei width, GLsizei height);
401
Jamie Madill07bb8cf2013-10-24 17:49:44 -0400402 bool isValidLevel(int level) const;
Jamie Madill07edd442013-07-19 16:36:58 -0400403 bool isLevelComplete(int level) const;
Jamie Madill169d1112013-10-24 17:49:37 -0400404 void updateStorageLevel(int level);
Jamie Madill07edd442013-07-19 16:36:58 -0400405
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000406 // Storing images as an array of single depth textures since D3D11 treats each array level of a
407 // Texture2D object as a separate subresource. Each layer would have to be looped over
408 // to update all the texture layers since they cannot all be updated at once and it makes the most
409 // 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 +0000410 GLsizei mLayerCounts[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
shannonwoods@chromium.org644f7662013-05-30 00:02:07 +0000411 rx::Image **mImageArray[IMPLEMENTATION_MAX_TEXTURE_LEVELS];
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000412
413 rx::TextureStorageInterface2DArray *mTexStorage;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000414};
415
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000416}
417
jbauman@chromium.org68715282012-07-12 23:28:41 +0000418#endif // LIBGLESV2_TEXTURE_H_