blob: fe39829f50835edd964a0f865fd98c69027034bd [file] [log] [blame]
shannon.woods@transgaming.combdf2d802013-02-28 23:16:20 +00001#include "precompiled.h"
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00002//
Geoff Langcec35902014-04-16 10:52:36 -04003// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// Texture.cpp: Implements the gl::Texture class and its derived classes
9// Texture2D and TextureCubeMap. Implements GL texture objects and related
10// functionality. [OpenGL ES 2.0.24] section 3.7 page 63.
11
12#include "libGLESv2/Texture.h"
13
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000014#include "libGLESv2/main.h"
shannonwoods@chromium.orga2ecfcc2013-05-30 00:11:59 +000015#include "common/mathutil.h"
16#include "common/utilities.h"
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +000017#include "libGLESv2/formatutils.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000018#include "libGLESv2/Renderbuffer.h"
19#include "libGLESv2/renderer/Image.h"
Brandon Jones6518fe22014-07-08 15:16:52 -070020#include "libGLESv2/renderer/d3d/TextureStorage.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000021#include "libEGL/Surface.h"
Jamie Madill0e0510f2013-10-10 15:46:23 -040022#include "libGLESv2/renderer/RenderTarget.h"
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000023
24namespace gl
25{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000026
Brandon Jonesf47bebc2014-07-09 14:28:42 -070027Texture::Texture(GLuint id, GLenum target)
28 : RefCountObject(id),
29 mUsage(GL_NONE),
30 mImmutable(false),
31 mTarget(target)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000032{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000033}
34
35Texture::~Texture()
36{
37}
38
Geoff Lang4907f2c2013-07-25 12:53:57 -040039GLenum Texture::getTarget() const
40{
41 return mTarget;
42}
43
Geoff Lang63b5f1f2013-09-23 14:52:14 -040044void Texture::setUsage(GLenum usage)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000045{
Geoff Lang63b5f1f2013-09-23 14:52:14 -040046 mUsage = usage;
Brandon Jones8c9038d2014-07-21 09:43:22 -070047 getImplementation()->setUsage(usage);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000048}
49
Brandon Jonesa328d562014-07-01 13:52:40 -070050void Texture::getSamplerStateWithNativeOffset(SamplerState *sampler)
daniel@transgaming.comebf139f2012-10-31 18:07:32 +000051{
52 *sampler = mSamplerState;
Nicolas Capens8de68282014-04-04 11:10:27 -040053
54 // Offset the effective base level by the texture storage's top level
55 rx::TextureStorageInterface *texture = getNativeTexture();
56 int topLevel = texture ? texture->getTopLevel() : 0;
57 sampler->baseLevel = topLevel + mSamplerState.baseLevel;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +000058}
59
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000060GLenum Texture::getUsage() const
61{
62 return mUsage;
63}
64
Jamie Madilld3d2a342013-10-07 10:46:35 -040065GLint Texture::getBaseLevelWidth() const
66{
67 const rx::Image *baseImage = getBaseLevelImage();
68 return (baseImage ? baseImage->getWidth() : 0);
69}
70
71GLint Texture::getBaseLevelHeight() const
72{
73 const rx::Image *baseImage = getBaseLevelImage();
74 return (baseImage ? baseImage->getHeight() : 0);
75}
76
77GLint Texture::getBaseLevelDepth() const
78{
79 const rx::Image *baseImage = getBaseLevelImage();
80 return (baseImage ? baseImage->getDepth() : 0);
81}
82
Jamie Madillb8f8b892014-01-07 10:12:50 -050083// Note: "base level image" is loosely defined to be any image from the base level,
84// where in the base of 2D array textures and cube maps there are several. Don't use
85// the base level image for anything except querying texture format and size.
Jamie Madilld3d2a342013-10-07 10:46:35 -040086GLenum Texture::getBaseLevelInternalFormat() const
87{
88 const rx::Image *baseImage = getBaseLevelImage();
89 return (baseImage ? baseImage->getInternalFormat() : GL_NONE);
90}
91
Brandon Jones6b19b002014-07-16 14:32:05 -070092// Tests for texture sampling completeness
93bool Texture::isSamplerComplete(const SamplerState &samplerState) const
94{
95 return getImplementation()->isSamplerComplete(samplerState);
96}
97
98rx::TextureStorageInterface *Texture::getNativeTexture()
99{
100 return getImplementation()->getNativeTexture();
101}
102
Brandon Jones8c9038d2014-07-21 09:43:22 -0700103void Texture::generateMipmaps()
104{
105 getImplementation()->generateMipmaps();
106}
107
Brandon Jones6b19b002014-07-16 14:32:05 -0700108void Texture::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
109{
110 getImplementation()->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, source);
111}
112
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700113unsigned int Texture::getTextureSerial()
114{
115 rx::TextureStorageInterface *texture = getNativeTexture();
116 return texture ? texture->getTextureSerial() : 0;
117}
118
119bool Texture::isImmutable() const
120{
121 return mImmutable;
122}
123
124int Texture::immutableLevelCount()
125{
126 return (mImmutable ? getNativeTexture()->getStorageInstance()->getLevelCount() : 0);
127}
128
129int Texture::mipLevels() const
130{
131 return log2(std::max(std::max(getBaseLevelWidth(), getBaseLevelHeight()), getBaseLevelDepth())) + 1;
132}
133
Brandon Jones8c9038d2014-07-21 09:43:22 -0700134const rx::Image *Texture::getBaseLevelImage() const
135{
136 return (getImplementation()->getLayerCount(0) > 0 ? getImplementation()->getImage(0, 0) : NULL);
137}
138
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700139Texture2D::Texture2D(rx::Texture2DImpl *impl, GLuint id)
140 : Texture(id, GL_TEXTURE_2D),
141 mTexture(impl)
Jamie Madill22f843a2013-10-24 17:49:36 -0400142{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000143 mSurface = NULL;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000144}
145
146Texture2D::~Texture2D()
147{
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700148 SafeDelete(mTexture);
149
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000150 if (mSurface)
151 {
152 mSurface->setBoundTexture(NULL);
153 mSurface = NULL;
154 }
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700155}
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000156
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000157GLsizei Texture2D::getWidth(GLint level) const
158{
159 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jones8c9038d2014-07-21 09:43:22 -0700160 return mTexture->getImage(level, 0)->getWidth();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000161 else
162 return 0;
163}
164
165GLsizei Texture2D::getHeight(GLint level) const
166{
167 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jones8c9038d2014-07-21 09:43:22 -0700168 return mTexture->getImage(level, 0)->getHeight();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000169 else
170 return 0;
171}
172
173GLenum Texture2D::getInternalFormat(GLint level) const
174{
175 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jones8c9038d2014-07-21 09:43:22 -0700176 return mTexture->getImage(level, 0)->getInternalFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000177 else
178 return GL_NONE;
179}
180
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000181GLenum Texture2D::getActualFormat(GLint level) const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000182{
183 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jones8c9038d2014-07-21 09:43:22 -0700184 return mTexture->getImage(level, 0)->getActualFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000185 else
Geoff Langcbf727a2014-02-10 12:50:45 -0500186 return GL_NONE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000187}
188
Brandon Jones8c9038d2014-07-21 09:43:22 -0700189void Texture2D::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 +0000190{
191 releaseTexImage();
shannon.woods@transgaming.com8a406682013-02-28 23:15:26 +0000192
Brandon Jones8c9038d2014-07-21 09:43:22 -0700193 mTexture->setImage(GL_TEXTURE_2D, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000194}
195
196void Texture2D::bindTexImage(egl::Surface *surface)
197{
198 releaseTexImage();
199
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700200 mTexture->bindTexImage(surface);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000201
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000202 mSurface = surface;
203 mSurface->setBoundTexture(this);
204}
205
206void Texture2D::releaseTexImage()
207{
208 if (mSurface)
209 {
210 mSurface->setBoundTexture(NULL);
211 mSurface = NULL;
212
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700213 mTexture->releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000214 }
215}
216
217void Texture2D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels)
218{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700219 releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000220
Brandon Jones8c9038d2014-07-21 09:43:22 -0700221 mTexture->setCompressedImage(GL_TEXTURE_2D, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000222}
223
Jamie Madill88f18f42013-09-18 14:36:19 -0400224void Texture2D::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 +0000225{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700226 mTexture->subImage(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000227}
228
229void Texture2D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels)
230{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700231 mTexture->subImageCompressed(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000232}
233
234void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
235{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700236 releaseTexImage();
shannon.woods@transgaming.com8a406682013-02-28 23:15:26 +0000237
Brandon Jones8c9038d2014-07-21 09:43:22 -0700238 mTexture->copyImage(GL_TEXTURE_2D, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000239}
240
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000241void Texture2D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
242{
Jamie Madill73b5d062013-10-24 17:49:38 -0400243 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000244
Brandon Jones8c9038d2014-07-21 09:43:22 -0700245 mTexture->storage(GL_TEXTURE_2D, levels, internalformat, width, height, 1);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000246}
247
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000248bool Texture2D::isCompressed(GLint level) const
249{
Geoff Lange4a492b2014-06-19 14:14:41 -0400250 return IsFormatCompressed(getInternalFormat(level));
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000251}
252
253bool Texture2D::isDepth(GLint level) const
254{
Geoff Lange4a492b2014-06-19 14:14:41 -0400255 return GetDepthBits(getInternalFormat(level)) > 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000256}
257
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000258void Texture2D::generateMipmaps()
259{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700260 releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000261
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700262 mTexture->generateMipmaps();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000263}
264
Geoff Lang8040f572013-07-25 16:49:54 -0400265unsigned int Texture2D::getRenderTargetSerial(GLint level)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000266{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700267 return mTexture->getRenderTargetSerial(level, 0);
Geoff Lang8040f572013-07-25 16:49:54 -0400268}
269
270rx::RenderTarget *Texture2D::getRenderTarget(GLint level)
271{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700272 return mTexture->getRenderTarget(level, 0);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000273}
274
Brandon Jones8c9038d2014-07-21 09:43:22 -0700275rx::RenderTarget *Texture2D::getDepthStencil(GLint level)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000276{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700277 return mTexture->getDepthStencil(level, 0);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000278}
279
Brandon Jones0511e802014-07-14 16:27:26 -0700280TextureCubeMap::TextureCubeMap(rx::TextureCubeImpl *impl, GLuint id)
281 : Texture(id, GL_TEXTURE_CUBE_MAP),
282 mTexture(impl)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000283{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000284}
285
286TextureCubeMap::~TextureCubeMap()
287{
Brandon Jones0511e802014-07-14 16:27:26 -0700288 SafeDelete(mTexture);
289}
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000290
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000291GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const
292{
293 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jones8c9038d2014-07-21 09:43:22 -0700294 return mTexture->getImage(level, targetToLayerIndex(target))->getWidth();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000295 else
296 return 0;
297}
298
299GLsizei TextureCubeMap::getHeight(GLenum target, GLint level) const
300{
301 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jones8c9038d2014-07-21 09:43:22 -0700302 return mTexture->getImage(level, targetToLayerIndex(target))->getHeight();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000303 else
304 return 0;
305}
306
307GLenum TextureCubeMap::getInternalFormat(GLenum target, GLint level) const
308{
309 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jones8c9038d2014-07-21 09:43:22 -0700310 return mTexture->getImage(level, targetToLayerIndex(target))->getInternalFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000311 else
312 return GL_NONE;
313}
314
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000315GLenum TextureCubeMap::getActualFormat(GLenum target, GLint level) const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000316{
317 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jones8c9038d2014-07-21 09:43:22 -0700318 return mTexture->getImage(level, targetToLayerIndex(target))->getActualFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000319 else
Geoff Langcbf727a2014-02-10 12:50:45 -0500320 return GL_NONE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000321}
322
Geoff Lang005df412013-10-16 14:12:50 -0400323void TextureCubeMap::setImagePosX(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 +0000324{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700325 mTexture->setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000326}
327
Geoff Lang005df412013-10-16 14:12:50 -0400328void TextureCubeMap::setImageNegX(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 +0000329{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700330 mTexture->setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000331}
332
Geoff Lang005df412013-10-16 14:12:50 -0400333void TextureCubeMap::setImagePosY(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 +0000334{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700335 mTexture->setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000336}
337
Geoff Lang005df412013-10-16 14:12:50 -0400338void TextureCubeMap::setImageNegY(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 +0000339{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700340 mTexture->setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000341}
342
Geoff Lang005df412013-10-16 14:12:50 -0400343void TextureCubeMap::setImagePosZ(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 +0000344{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700345 mTexture->setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, width, height, 4, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000346}
347
Geoff Lang005df412013-10-16 14:12:50 -0400348void TextureCubeMap::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 +0000349{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700350 mTexture->setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, width, height, 5, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000351}
352
Jamie Madill2db197c2013-10-24 17:49:35 -0400353void TextureCubeMap::setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000354{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700355 mTexture->setCompressedImage(target, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000356}
357
Jamie Madill88f18f42013-09-18 14:36:19 -0400358void TextureCubeMap::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 +0000359{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700360 mTexture->subImage(target, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000361}
362
363void TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels)
364{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700365 mTexture->subImageCompressed(target, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000366}
367
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000368// Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
369bool TextureCubeMap::isCubeComplete() const
370{
Brandon Jones0511e802014-07-14 16:27:26 -0700371 return mTexture->isCubeComplete();
Jamie Madill07edd442013-07-19 16:36:58 -0400372}
373
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000374bool TextureCubeMap::isCompressed(GLenum target, GLint level) const
375{
Geoff Lange4a492b2014-06-19 14:14:41 -0400376 return IsFormatCompressed(getInternalFormat(target, level));
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000377}
378
Geoff Lang8040f572013-07-25 16:49:54 -0400379bool TextureCubeMap::isDepth(GLenum target, GLint level) const
380{
Geoff Lange4a492b2014-06-19 14:14:41 -0400381 return GetDepthBits(getInternalFormat(target, level)) > 0;
Geoff Lang8040f572013-07-25 16:49:54 -0400382}
383
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000384void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
385{
Brandon Jones0511e802014-07-14 16:27:26 -0700386 mTexture->copyImage(target, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000387}
388
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000389void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size)
390{
Jamie Madill3c0989c2013-10-24 17:49:39 -0400391 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000392
Brandon Jones8c9038d2014-07-21 09:43:22 -0700393 mTexture->storage(GL_TEXTURE_CUBE_MAP, levels, internalformat, size, size, 1);
Jamie Madill2ebab852013-10-24 17:49:42 -0400394}
395
Jamie Madill2db197c2013-10-24 17:49:35 -0400396unsigned int TextureCubeMap::getRenderTargetSerial(GLenum target, GLint level)
Geoff Lang8040f572013-07-25 16:49:54 -0400397{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700398 return mTexture->getRenderTargetSerial(level, targetToLayerIndex(target));
399}
400
401int TextureCubeMap::targetToLayerIndex(GLenum target)
402{
403 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
404 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
405 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
406 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
407 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
408
409 return target - GL_TEXTURE_CUBE_MAP_POSITIVE_X;
410}
411
412GLenum TextureCubeMap::layerIndexToTarget(GLint layer)
413{
414 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
415 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
416 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
417 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
418 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
419
420 return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
Geoff Lang8040f572013-07-25 16:49:54 -0400421}
422
423rx::RenderTarget *TextureCubeMap::getRenderTarget(GLenum target, GLint level)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000424{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700425 return mTexture->getRenderTarget(level, targetToLayerIndex(target));
Geoff Lang8040f572013-07-25 16:49:54 -0400426}
427
428rx::RenderTarget *TextureCubeMap::getDepthStencil(GLenum target, GLint level)
429{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700430 return mTexture->getDepthStencil(level, targetToLayerIndex(target));
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000431}
432
Brandon Jones78b1acd2014-07-15 15:33:07 -0700433Texture3D::Texture3D(rx::Texture3DImpl *impl, GLuint id)
434 : Texture(id, GL_TEXTURE_3D),
435 mTexture(impl)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000436{
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000437}
438
439Texture3D::~Texture3D()
440{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700441 SafeDelete(mTexture);
442}
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000443
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000444GLsizei Texture3D::getWidth(GLint level) const
445{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700446 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getWidth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000447}
448
449GLsizei Texture3D::getHeight(GLint level) const
450{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700451 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getHeight() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000452}
453
454GLsizei Texture3D::getDepth(GLint level) const
455{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700456 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getDepth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000457}
458
459GLenum Texture3D::getInternalFormat(GLint level) const
460{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700461 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000462}
463
464GLenum Texture3D::getActualFormat(GLint level) const
465{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700466 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getActualFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000467}
468
469bool Texture3D::isCompressed(GLint level) const
470{
Geoff Lange4a492b2014-06-19 14:14:41 -0400471 return IsFormatCompressed(getInternalFormat(level));
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000472}
473
474bool Texture3D::isDepth(GLint level) const
475{
Geoff Lange4a492b2014-06-19 14:14:41 -0400476 return GetDepthBits(getInternalFormat(level)) > 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000477}
478
Geoff Lang005df412013-10-16 14:12:50 -0400479void Texture3D::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 +0000480{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700481 mTexture->setImage(GL_TEXTURE_3D, level, width, height, depth, internalFormat, format, type, unpack, pixels);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000482}
483
484void Texture3D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
485{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700486 mTexture->setCompressedImage(GL_TEXTURE_3D, level, format, width, height, depth, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000487}
488
Jamie Madill88f18f42013-09-18 14:36:19 -0400489void Texture3D::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 +0000490{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700491 mTexture->subImage(GL_TEXTURE_3D, level, xoffset, yoffset, zoffset, width, height, depth, format, type, unpack, pixels);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000492}
493
494void Texture3D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
495{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700496 mTexture->subImageCompressed(GL_TEXTURE_3D, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000497}
498
499void Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
500{
Jamie Madille664e202013-10-24 17:49:40 -0400501 mImmutable = true;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000502
Brandon Jones8c9038d2014-07-21 09:43:22 -0700503 mTexture->storage(GL_TEXTURE_3D, levels, internalformat, width, height, depth);
Jamie Madill2ebab852013-10-24 17:49:42 -0400504}
505
Geoff Lang8040f572013-07-25 16:49:54 -0400506unsigned int Texture3D::getRenderTargetSerial(GLint level, GLint layer)
507{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700508 return mTexture->getRenderTargetSerial(level, layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000509}
510
Jamie Madilla2d4e552013-10-10 15:12:01 -0400511
Geoff Lang8040f572013-07-25 16:49:54 -0400512rx::RenderTarget *Texture3D::getRenderTarget(GLint level, GLint layer)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000513{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700514 return mTexture->getRenderTarget(level, layer);
Geoff Lang8040f572013-07-25 16:49:54 -0400515}
516
517rx::RenderTarget *Texture3D::getDepthStencil(GLint level, GLint layer)
518{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700519 return mTexture->getDepthStencil(level, layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000520}
521
Brandon Jones142ec422014-07-16 10:31:30 -0700522Texture2DArray::Texture2DArray(rx::Texture2DArrayImpl *impl, GLuint id)
523 : Texture(id, GL_TEXTURE_2D_ARRAY),
524 mTexture(impl)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000525{
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000526}
527
528Texture2DArray::~Texture2DArray()
529{
Brandon Jones142ec422014-07-16 10:31:30 -0700530 SafeDelete(mTexture);
Jamie Madill884a4622013-10-24 17:49:41 -0400531}
532
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000533GLsizei Texture2DArray::getWidth(GLint level) const
534{
Brandon Jones142ec422014-07-16 10:31:30 -0700535 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getWidth() : 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000536}
537
538GLsizei Texture2DArray::getHeight(GLint level) const
539{
Brandon Jones142ec422014-07-16 10:31:30 -0700540 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getHeight() : 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000541}
542
Jamie Madillb8f8b892014-01-07 10:12:50 -0500543GLsizei Texture2DArray::getLayers(GLint level) const
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000544{
Brandon Jones142ec422014-07-16 10:31:30 -0700545 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getLayerCount(level) : 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000546}
547
548GLenum Texture2DArray::getInternalFormat(GLint level) const
549{
Brandon Jones142ec422014-07-16 10:31:30 -0700550 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000551}
552
553GLenum Texture2DArray::getActualFormat(GLint level) const
554{
Brandon Jones142ec422014-07-16 10:31:30 -0700555 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getActualFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000556}
557
558bool Texture2DArray::isCompressed(GLint level) const
559{
Geoff Lange4a492b2014-06-19 14:14:41 -0400560 return IsFormatCompressed(getInternalFormat(level));
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000561}
562
563bool Texture2DArray::isDepth(GLint level) const
564{
Geoff Lange4a492b2014-06-19 14:14:41 -0400565 return GetDepthBits(getInternalFormat(level)) > 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000566}
567
Geoff Lang005df412013-10-16 14:12:50 -0400568void Texture2DArray::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 +0000569{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700570 mTexture->setImage(GL_TEXTURE_2D_ARRAY, level, width, height, depth, internalFormat, format, type, unpack, pixels);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000571}
572
573void Texture2DArray::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
574{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700575 mTexture->setCompressedImage(GL_TEXTURE_2D_ARRAY, level, format, width, height, depth, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000576}
577
Jamie Madill88f18f42013-09-18 14:36:19 -0400578void Texture2DArray::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 +0000579{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700580 mTexture->subImage(GL_TEXTURE_2D_ARRAY, level, xoffset, yoffset, zoffset, width, height, depth, format, type, unpack, pixels);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000581}
582
583void Texture2DArray::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
584{
Brandon Jones8c9038d2014-07-21 09:43:22 -0700585 mTexture->subImageCompressed(GL_TEXTURE_2D_ARRAY, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000586}
587
588void Texture2DArray::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
589{
Jamie Madill884a4622013-10-24 17:49:41 -0400590 mImmutable = true;
Brandon Jones142ec422014-07-16 10:31:30 -0700591
Brandon Jones8c9038d2014-07-21 09:43:22 -0700592 mTexture->storage(GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, depth);
Jamie Madill2ebab852013-10-24 17:49:42 -0400593}
594
Jamie Madille83d1a92013-10-24 17:49:33 -0400595unsigned int Texture2DArray::getRenderTargetSerial(GLint level, GLint layer)
Geoff Lang8040f572013-07-25 16:49:54 -0400596{
Brandon Jones142ec422014-07-16 10:31:30 -0700597 return mTexture->getRenderTargetSerial(level, layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000598}
599
Geoff Lang8040f572013-07-25 16:49:54 -0400600rx::RenderTarget *Texture2DArray::getRenderTarget(GLint level, GLint layer)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000601{
Brandon Jones142ec422014-07-16 10:31:30 -0700602 return mTexture->getRenderTarget(level, layer);
Geoff Lang8040f572013-07-25 16:49:54 -0400603}
604
605rx::RenderTarget *Texture2DArray::getDepthStencil(GLint level, GLint layer)
606{
Brandon Jones142ec422014-07-16 10:31:30 -0700607 return mTexture->getDepthStencil(level, layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000608}
609
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000610}