blob: 3ec492de0771879e3ae3099fd1531b0f3cb63fb7 [file] [log] [blame]
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2002-2014 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.cpp: Implements the gl::Texture class and its derived classes
8// Texture2D and TextureCubeMap. Implements GL texture objects and related
9// functionality. [OpenGL ES 2.0.24] section 3.7 page 63.
10
11#include "libGLESv2/Texture.h"
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000012#include "libGLESv2/main.h"
Brandon Jones6053a522014-07-25 16:22:09 -070013#include "libGLESv2/Context.h"
shannonwoods@chromium.org4ad58e02013-05-30 00:08:11 +000014#include "libGLESv2/formatutils.h"
Jamie Madillfeda4d22014-09-17 13:03:29 -040015#include "libGLESv2/ImageIndex.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000016#include "libGLESv2/Renderbuffer.h"
17#include "libGLESv2/renderer/Image.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "libGLESv2/renderer/d3d/TextureStorage.h"
19
20#include "libEGL/Surface.h"
21
22#include "common/mathutil.h"
23#include "common/utilities.h"
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000024
25namespace gl
26{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000027
Brandon Jones6053a522014-07-25 16:22:09 -070028bool IsMipmapFiltered(const gl::SamplerState &samplerState)
29{
30 switch (samplerState.minFilter)
31 {
32 case GL_NEAREST:
33 case GL_LINEAR:
34 return false;
35 case GL_NEAREST_MIPMAP_NEAREST:
36 case GL_LINEAR_MIPMAP_NEAREST:
37 case GL_NEAREST_MIPMAP_LINEAR:
38 case GL_LINEAR_MIPMAP_LINEAR:
39 return true;
40 default: UNREACHABLE();
41 return false;
42 }
43}
44
45bool IsPointSampled(const gl::SamplerState &samplerState)
46{
47 return (samplerState.magFilter == GL_NEAREST && (samplerState.minFilter == GL_NEAREST || samplerState.minFilter == GL_NEAREST_MIPMAP_NEAREST));
48}
49
50Texture::Texture(rx::TextureImpl *impl, GLuint id, GLenum target)
Brandon Jonesf47bebc2014-07-09 14:28:42 -070051 : RefCountObject(id),
Brandon Jones6053a522014-07-25 16:22:09 -070052 mTexture(impl),
Brandon Jonesf47bebc2014-07-09 14:28:42 -070053 mUsage(GL_NONE),
54 mImmutable(false),
55 mTarget(target)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000056{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000057}
58
59Texture::~Texture()
60{
Brandon Jones6053a522014-07-25 16:22:09 -070061 SafeDelete(mTexture);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000062}
63
Geoff Lang4907f2c2013-07-25 12:53:57 -040064GLenum Texture::getTarget() const
65{
66 return mTarget;
67}
68
Geoff Lang63b5f1f2013-09-23 14:52:14 -040069void Texture::setUsage(GLenum usage)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000070{
Geoff Lang63b5f1f2013-09-23 14:52:14 -040071 mUsage = usage;
Brandon Jonescef06ff2014-08-05 13:27:48 -070072 getImplementation()->setUsage(usage);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000073}
74
Brandon Jonesa328d562014-07-01 13:52:40 -070075void Texture::getSamplerStateWithNativeOffset(SamplerState *sampler)
daniel@transgaming.comebf139f2012-10-31 18:07:32 +000076{
77 *sampler = mSamplerState;
Nicolas Capens8de68282014-04-04 11:10:27 -040078
79 // Offset the effective base level by the texture storage's top level
Jamie Madill2f06dbf2014-09-18 15:08:50 -040080 rx::TextureStorage *texture = getNativeTexture();
Nicolas Capens8de68282014-04-04 11:10:27 -040081 int topLevel = texture ? texture->getTopLevel() : 0;
82 sampler->baseLevel = topLevel + mSamplerState.baseLevel;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +000083}
84
daniel@transgaming.com95a758f2012-07-12 15:17:06 +000085GLenum Texture::getUsage() const
86{
87 return mUsage;
88}
89
Jamie Madilld3d2a342013-10-07 10:46:35 -040090GLint Texture::getBaseLevelWidth() const
91{
92 const rx::Image *baseImage = getBaseLevelImage();
93 return (baseImage ? baseImage->getWidth() : 0);
94}
95
96GLint Texture::getBaseLevelHeight() const
97{
98 const rx::Image *baseImage = getBaseLevelImage();
99 return (baseImage ? baseImage->getHeight() : 0);
100}
101
102GLint Texture::getBaseLevelDepth() const
103{
104 const rx::Image *baseImage = getBaseLevelImage();
105 return (baseImage ? baseImage->getDepth() : 0);
106}
107
Jamie Madillb8f8b892014-01-07 10:12:50 -0500108// Note: "base level image" is loosely defined to be any image from the base level,
109// where in the base of 2D array textures and cube maps there are several. Don't use
110// the base level image for anything except querying texture format and size.
Jamie Madilld3d2a342013-10-07 10:46:35 -0400111GLenum Texture::getBaseLevelInternalFormat() const
112{
113 const rx::Image *baseImage = getBaseLevelImage();
114 return (baseImage ? baseImage->getInternalFormat() : GL_NONE);
115}
116
Jamie Madill945f7322014-09-03 15:07:14 -0400117GLsizei Texture::getWidth(const ImageIndex &index) const
118{
Jamie Madillfeda4d22014-09-17 13:03:29 -0400119 rx::Image *image = mTexture->getImage(index);
Jamie Madill945f7322014-09-03 15:07:14 -0400120 return image->getWidth();
121}
122
123GLsizei Texture::getHeight(const ImageIndex &index) const
124{
Jamie Madillfeda4d22014-09-17 13:03:29 -0400125 rx::Image *image = mTexture->getImage(index);
Jamie Madill945f7322014-09-03 15:07:14 -0400126 return image->getHeight();
127}
128
129GLenum Texture::getInternalFormat(const ImageIndex &index) const
130{
Jamie Madillfeda4d22014-09-17 13:03:29 -0400131 rx::Image *image = mTexture->getImage(index);
Jamie Madill945f7322014-09-03 15:07:14 -0400132 return image->getInternalFormat();
133}
134
135GLenum Texture::getActualFormat(const ImageIndex &index) const
136{
Jamie Madillfeda4d22014-09-17 13:03:29 -0400137 rx::Image *image = mTexture->getImage(index);
Jamie Madill945f7322014-09-03 15:07:14 -0400138 return image->getActualFormat();
139}
140
Jamie Madill2f06dbf2014-09-18 15:08:50 -0400141rx::TextureStorage *Texture::getNativeTexture()
Brandon Jones6b19b002014-07-16 14:32:05 -0700142{
143 return getImplementation()->getNativeTexture();
144}
145
Brandon Jonescef06ff2014-08-05 13:27:48 -0700146void Texture::generateMipmaps()
147{
148 getImplementation()->generateMipmaps();
149}
150
Brandon Jones6b19b002014-07-16 14:32:05 -0700151void Texture::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
152{
153 getImplementation()->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, source);
154}
155
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700156unsigned int Texture::getTextureSerial()
157{
Jamie Madill2f06dbf2014-09-18 15:08:50 -0400158 rx::TextureStorage *texture = getNativeTexture();
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700159 return texture ? texture->getTextureSerial() : 0;
160}
161
162bool Texture::isImmutable() const
163{
164 return mImmutable;
165}
166
167int Texture::immutableLevelCount()
168{
Jamie Madill2f06dbf2014-09-18 15:08:50 -0400169 return (mImmutable ? getNativeTexture()->getLevelCount() : 0);
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700170}
171
172int Texture::mipLevels() const
173{
174 return log2(std::max(std::max(getBaseLevelWidth(), getBaseLevelHeight()), getBaseLevelDepth())) + 1;
175}
176
Brandon Jonescef06ff2014-08-05 13:27:48 -0700177const rx::Image *Texture::getBaseLevelImage() const
178{
179 return (getImplementation()->getLayerCount(0) > 0 ? getImplementation()->getImage(0, 0) : NULL);
180}
181
Brandon Jones6053a522014-07-25 16:22:09 -0700182Texture2D::Texture2D(rx::TextureImpl *impl, GLuint id)
183 : Texture(impl, id, GL_TEXTURE_2D)
Jamie Madill22f843a2013-10-24 17:49:36 -0400184{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000185 mSurface = NULL;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000186}
187
188Texture2D::~Texture2D()
189{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000190 if (mSurface)
191 {
192 mSurface->setBoundTexture(NULL);
193 mSurface = NULL;
194 }
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700195}
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000196
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000197GLsizei Texture2D::getWidth(GLint level) const
198{
199 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700200 return mTexture->getImage(level, 0)->getWidth();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000201 else
202 return 0;
203}
204
205GLsizei Texture2D::getHeight(GLint level) const
206{
207 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700208 return mTexture->getImage(level, 0)->getHeight();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000209 else
210 return 0;
211}
212
213GLenum Texture2D::getInternalFormat(GLint level) const
214{
215 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700216 return mTexture->getImage(level, 0)->getInternalFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000217 else
218 return GL_NONE;
219}
220
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000221GLenum Texture2D::getActualFormat(GLint level) const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000222{
223 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700224 return mTexture->getImage(level, 0)->getActualFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000225 else
Geoff Langcbf727a2014-02-10 12:50:45 -0500226 return GL_NONE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000227}
228
Brandon Jonescef06ff2014-08-05 13:27:48 -0700229void 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 +0000230{
231 releaseTexImage();
shannon.woods@transgaming.com8a406682013-02-28 23:15:26 +0000232
Brandon Jonescef06ff2014-08-05 13:27:48 -0700233 mTexture->setImage(GL_TEXTURE_2D, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000234}
235
236void Texture2D::bindTexImage(egl::Surface *surface)
237{
238 releaseTexImage();
239
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700240 mTexture->bindTexImage(surface);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000241
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000242 mSurface = surface;
243 mSurface->setBoundTexture(this);
244}
245
246void Texture2D::releaseTexImage()
247{
248 if (mSurface)
249 {
250 mSurface->setBoundTexture(NULL);
251 mSurface = NULL;
252
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700253 mTexture->releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000254 }
255}
256
257void Texture2D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels)
258{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700259 releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000260
Brandon Jonescef06ff2014-08-05 13:27:48 -0700261 mTexture->setCompressedImage(GL_TEXTURE_2D, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000262}
263
Jamie Madill88f18f42013-09-18 14:36:19 -0400264void 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 +0000265{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700266 mTexture->subImage(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000267}
268
269void Texture2D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels)
270{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700271 mTexture->subImageCompressed(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000272}
273
274void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
275{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700276 releaseTexImage();
Geoff Lang5d601382014-07-22 15:14:06 -0400277
Brandon Jonescef06ff2014-08-05 13:27:48 -0700278 mTexture->copyImage(GL_TEXTURE_2D, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000279}
280
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000281void Texture2D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
282{
Jamie Madill73b5d062013-10-24 17:49:38 -0400283 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000284
Brandon Jonescef06ff2014-08-05 13:27:48 -0700285 mTexture->storage(GL_TEXTURE_2D, levels, internalformat, width, height, 1);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000286}
287
Brandon Jones6053a522014-07-25 16:22:09 -0700288// Tests for 2D texture sampling completeness. [OpenGL ES 2.0.24] section 3.8.2 page 85.
289bool Texture2D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
290{
291 GLsizei width = getBaseLevelWidth();
292 GLsizei height = getBaseLevelHeight();
293
294 if (width <= 0 || height <= 0)
295 {
296 return false;
297 }
298
299 if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
300 {
301 return false;
302 }
303
304 bool npotSupport = extensions.textureNPOT;
305
306 if (!npotSupport)
307 {
308 if ((samplerState.wrapS != GL_CLAMP_TO_EDGE && !gl::isPow2(width)) ||
309 (samplerState.wrapT != GL_CLAMP_TO_EDGE && !gl::isPow2(height)))
310 {
311 return false;
312 }
313 }
314
315 if (IsMipmapFiltered(samplerState))
316 {
317 if (!npotSupport)
318 {
319 if (!gl::isPow2(width) || !gl::isPow2(height))
320 {
321 return false;
322 }
323 }
324
325 if (!isMipmapComplete())
326 {
327 return false;
328 }
329 }
330
331 // OpenGLES 3.0.2 spec section 3.8.13 states that a texture is not mipmap complete if:
332 // The internalformat specified for the texture arrays is a sized internal depth or
333 // depth and stencil format (see table 3.13), the value of TEXTURE_COMPARE_-
334 // MODE is NONE, and either the magnification filter is not NEAREST or the mini-
335 // fication filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST.
336 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(getInternalFormat(0));
337 if (formatInfo.depthBits > 0 && clientVersion > 2)
338 {
339 if (samplerState.compareMode == GL_NONE)
340 {
341 if ((samplerState.minFilter != GL_NEAREST && samplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST) ||
342 samplerState.magFilter != GL_NEAREST)
343 {
344 return false;
345 }
346 }
347 }
348
349 return true;
350}
351
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000352bool Texture2D::isCompressed(GLint level) const
353{
Geoff Lang5d601382014-07-22 15:14:06 -0400354 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000355}
356
357bool Texture2D::isDepth(GLint level) const
358{
Geoff Lang5d601382014-07-22 15:14:06 -0400359 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000360}
361
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000362void Texture2D::generateMipmaps()
363{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700364 releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000365
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700366 mTexture->generateMipmaps();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000367}
368
Brandon Jones6053a522014-07-25 16:22:09 -0700369// Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
370bool Texture2D::isMipmapComplete() const
371{
372 int levelCount = mipLevels();
373
374 for (int level = 0; level < levelCount; level++)
375 {
376 if (!isLevelComplete(level))
377 {
378 return false;
379 }
380 }
381
382 return true;
383}
384
385bool Texture2D::isLevelComplete(int level) const
386{
387 if (isImmutable())
388 {
389 return true;
390 }
391
392 const rx::Image *baseImage = getBaseLevelImage();
393
394 GLsizei width = baseImage->getWidth();
395 GLsizei height = baseImage->getHeight();
396
397 if (width <= 0 || height <= 0)
398 {
399 return false;
400 }
401
402 // The base image level is complete if the width and height are positive
403 if (level == 0)
404 {
405 return true;
406 }
407
408 ASSERT(level >= 1 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
409 rx::Image *image = mTexture->getImage(level, 0);
410
411 if (image->getInternalFormat() != baseImage->getInternalFormat())
412 {
413 return false;
414 }
415
416 if (image->getWidth() != std::max(1, width >> level))
417 {
418 return false;
419 }
420
421 if (image->getHeight() != std::max(1, height >> level))
422 {
423 return false;
424 }
425
426 return true;
427}
428
429TextureCubeMap::TextureCubeMap(rx::TextureImpl *impl, GLuint id)
430 : Texture(impl, id, GL_TEXTURE_CUBE_MAP)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000431{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000432}
433
434TextureCubeMap::~TextureCubeMap()
435{
Brandon Jones0511e802014-07-14 16:27:26 -0700436}
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000437
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000438GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const
439{
440 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700441 return mTexture->getImage(level, targetToLayerIndex(target))->getWidth();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000442 else
443 return 0;
444}
445
446GLsizei TextureCubeMap::getHeight(GLenum target, GLint level) const
447{
448 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700449 return mTexture->getImage(level, targetToLayerIndex(target))->getHeight();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000450 else
451 return 0;
452}
453
454GLenum TextureCubeMap::getInternalFormat(GLenum target, GLint level) const
455{
456 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700457 return mTexture->getImage(level, targetToLayerIndex(target))->getInternalFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000458 else
459 return GL_NONE;
460}
461
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000462GLenum TextureCubeMap::getActualFormat(GLenum target, GLint level) const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000463{
464 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700465 return mTexture->getImage(level, targetToLayerIndex(target))->getActualFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000466 else
Geoff Langcbf727a2014-02-10 12:50:45 -0500467 return GL_NONE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000468}
469
Geoff Lang005df412013-10-16 14:12:50 -0400470void 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 +0000471{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700472 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 +0000473}
474
Geoff Lang005df412013-10-16 14:12:50 -0400475void 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 +0000476{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700477 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 +0000478}
479
Geoff Lang005df412013-10-16 14:12:50 -0400480void 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 +0000481{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700482 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 +0000483}
484
Geoff Lang005df412013-10-16 14:12:50 -0400485void 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 +0000486{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700487 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 +0000488}
489
Geoff Lang005df412013-10-16 14:12:50 -0400490void 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 +0000491{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700492 mTexture->setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000493}
494
Geoff Lang005df412013-10-16 14:12:50 -0400495void 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 +0000496{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700497 mTexture->setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000498}
499
Jamie Madill2db197c2013-10-24 17:49:35 -0400500void 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 +0000501{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700502 mTexture->setCompressedImage(target, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000503}
504
Jamie Madill88f18f42013-09-18 14:36:19 -0400505void 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 +0000506{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700507 mTexture->subImage(target, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000508}
509
510void TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels)
511{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700512 mTexture->subImageCompressed(target, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000513}
514
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000515// Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
516bool TextureCubeMap::isCubeComplete() const
517{
Brandon Jones6053a522014-07-25 16:22:09 -0700518 int baseWidth = getBaseLevelWidth();
519 int baseHeight = getBaseLevelHeight();
520 GLenum baseFormat = getBaseLevelInternalFormat();
521
522 if (baseWidth <= 0 || baseWidth != baseHeight)
523 {
524 return false;
525 }
526
527 for (int faceIndex = 1; faceIndex < 6; faceIndex++)
528 {
529 const rx::Image *faceBaseImage = mTexture->getImage(0, faceIndex);
530
531 if (faceBaseImage->getWidth() != baseWidth ||
532 faceBaseImage->getHeight() != baseHeight ||
533 faceBaseImage->getInternalFormat() != baseFormat )
534 {
535 return false;
536 }
537 }
538
539 return true;
Jamie Madill07edd442013-07-19 16:36:58 -0400540}
541
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000542bool TextureCubeMap::isCompressed(GLenum target, GLint level) const
543{
Geoff Lang5d601382014-07-22 15:14:06 -0400544 return GetInternalFormatInfo(getInternalFormat(target, level)).compressed;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000545}
546
Geoff Lang8040f572013-07-25 16:49:54 -0400547bool TextureCubeMap::isDepth(GLenum target, GLint level) const
548{
Geoff Lang5d601382014-07-22 15:14:06 -0400549 return GetInternalFormatInfo(getInternalFormat(target, level)).depthBits > 0;
Geoff Lang8040f572013-07-25 16:49:54 -0400550}
551
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000552void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
553{
Brandon Jones0511e802014-07-14 16:27:26 -0700554 mTexture->copyImage(target, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000555}
556
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000557void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size)
558{
Jamie Madill3c0989c2013-10-24 17:49:39 -0400559 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000560
Brandon Jonescef06ff2014-08-05 13:27:48 -0700561 mTexture->storage(GL_TEXTURE_CUBE_MAP, levels, internalformat, size, size, 1);
Jamie Madill2ebab852013-10-24 17:49:42 -0400562}
563
Brandon Jones6053a522014-07-25 16:22:09 -0700564// Tests for texture sampling completeness
565bool TextureCubeMap::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
566{
567 int size = getBaseLevelWidth();
568
569 bool mipmapping = IsMipmapFiltered(samplerState);
570
571 if (!textureCaps.get(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)).filterable && !IsPointSampled(samplerState))
572 {
573 return false;
574 }
575
576 if (!gl::isPow2(size) && !extensions.textureNPOT)
577 {
578 if (samplerState.wrapS != GL_CLAMP_TO_EDGE || samplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping)
579 {
580 return false;
581 }
582 }
583
584 if (!mipmapping)
585 {
586 if (!isCubeComplete())
587 {
588 return false;
589 }
590 }
591 else
592 {
593 if (!isMipmapComplete()) // Also tests for isCubeComplete()
594 {
595 return false;
596 }
597 }
598
599 return true;
600}
601
Brandon Jonescef06ff2014-08-05 13:27:48 -0700602int TextureCubeMap::targetToLayerIndex(GLenum target)
603{
604 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
605 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
606 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
607 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
608 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
609
610 return target - GL_TEXTURE_CUBE_MAP_POSITIVE_X;
611}
612
613GLenum TextureCubeMap::layerIndexToTarget(GLint layer)
614{
615 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
616 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
617 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
618 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
619 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
620
621 return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
Geoff Lang8040f572013-07-25 16:49:54 -0400622}
623
Brandon Jones6053a522014-07-25 16:22:09 -0700624bool TextureCubeMap::isMipmapComplete() const
625{
626 if (isImmutable())
627 {
628 return true;
629 }
630
631 if (!isCubeComplete())
632 {
633 return false;
634 }
635
636 int levelCount = mipLevels();
637
638 for (int face = 0; face < 6; face++)
639 {
640 for (int level = 1; level < levelCount; level++)
641 {
642 if (!isFaceLevelComplete(face, level))
643 {
644 return false;
645 }
646 }
647 }
648
649 return true;
650}
651
652bool TextureCubeMap::isFaceLevelComplete(int faceIndex, int level) const
653{
654 ASSERT(level >= 0 && faceIndex < 6 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, faceIndex) != NULL);
655
656 if (isImmutable())
657 {
658 return true;
659 }
660
661 int baseSize = getBaseLevelWidth();
662
663 if (baseSize <= 0)
664 {
665 return false;
666 }
667
668 // "isCubeComplete" checks for base level completeness and we must call that
669 // to determine if any face at level 0 is complete. We omit that check here
670 // to avoid re-checking cube-completeness for every face at level 0.
671 if (level == 0)
672 {
673 return true;
674 }
675
676 // Check that non-zero levels are consistent with the base level.
677 const rx::Image *faceLevelImage = mTexture->getImage(level, faceIndex);
678
679 if (faceLevelImage->getInternalFormat() != getBaseLevelInternalFormat())
680 {
681 return false;
682 }
683
684 if (faceLevelImage->getWidth() != std::max(1, baseSize >> level))
685 {
686 return false;
687 }
688
689 return true;
690}
691
692
693Texture3D::Texture3D(rx::TextureImpl *impl, GLuint id)
694 : Texture(impl, id, GL_TEXTURE_3D)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000695{
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000696}
697
698Texture3D::~Texture3D()
699{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700700}
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000701
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000702GLsizei Texture3D::getWidth(GLint level) const
703{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700704 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getWidth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000705}
706
707GLsizei Texture3D::getHeight(GLint level) const
708{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700709 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getHeight() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000710}
711
712GLsizei Texture3D::getDepth(GLint level) const
713{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700714 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getDepth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000715}
716
717GLenum Texture3D::getInternalFormat(GLint level) const
718{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700719 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000720}
721
722GLenum Texture3D::getActualFormat(GLint level) const
723{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700724 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getActualFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000725}
726
727bool Texture3D::isCompressed(GLint level) const
728{
Geoff Lang5d601382014-07-22 15:14:06 -0400729 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000730}
731
732bool Texture3D::isDepth(GLint level) const
733{
Geoff Lang5d601382014-07-22 15:14:06 -0400734 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000735}
736
Geoff Lang005df412013-10-16 14:12:50 -0400737void 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 +0000738{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700739 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 +0000740}
741
742void Texture3D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
743{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700744 mTexture->setCompressedImage(GL_TEXTURE_3D, level, format, width, height, depth, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000745}
746
Jamie Madill88f18f42013-09-18 14:36:19 -0400747void 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 +0000748{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700749 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 +0000750}
751
752void Texture3D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
753{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700754 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 +0000755}
756
757void Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
758{
Jamie Madille664e202013-10-24 17:49:40 -0400759 mImmutable = true;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000760
Brandon Jonescef06ff2014-08-05 13:27:48 -0700761 mTexture->storage(GL_TEXTURE_3D, levels, internalformat, width, height, depth);
Jamie Madill2ebab852013-10-24 17:49:42 -0400762}
763
Brandon Jones6053a522014-07-25 16:22:09 -0700764bool Texture3D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
765{
766 GLsizei width = getBaseLevelWidth();
767 GLsizei height = getBaseLevelHeight();
768 GLsizei depth = getBaseLevelDepth();
769
770 if (width <= 0 || height <= 0 || depth <= 0)
771 {
772 return false;
773 }
774
775 if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
776 {
777 return false;
778 }
779
780 if (IsMipmapFiltered(samplerState) && !isMipmapComplete())
781 {
782 return false;
783 }
784
785 return true;
786}
787
Brandon Jones6053a522014-07-25 16:22:09 -0700788bool Texture3D::isMipmapComplete() const
789{
790 int levelCount = mipLevels();
791
792 for (int level = 0; level < levelCount; level++)
793 {
794 if (!isLevelComplete(level))
795 {
796 return false;
797 }
798 }
799
800 return true;
801}
802
803bool Texture3D::isLevelComplete(int level) const
804{
805 ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
806
807 if (isImmutable())
808 {
809 return true;
810 }
811
812 GLsizei width = getBaseLevelWidth();
813 GLsizei height = getBaseLevelHeight();
814 GLsizei depth = getBaseLevelDepth();
815
816 if (width <= 0 || height <= 0 || depth <= 0)
817 {
818 return false;
819 }
820
821 if (level == 0)
822 {
823 return true;
824 }
825
826 rx::Image *levelImage = mTexture->getImage(level, 0);
827
828 if (levelImage->getInternalFormat() != getBaseLevelInternalFormat())
829 {
830 return false;
831 }
832
833 if (levelImage->getWidth() != std::max(1, width >> level))
834 {
835 return false;
836 }
837
838 if (levelImage->getHeight() != std::max(1, height >> level))
839 {
840 return false;
841 }
842
843 if (levelImage->getDepth() != std::max(1, depth >> level))
844 {
845 return false;
846 }
847
848 return true;
849}
850
851Texture2DArray::Texture2DArray(rx::TextureImpl *impl, GLuint id)
852 : Texture(impl, id, GL_TEXTURE_2D_ARRAY)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000853{
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000854}
855
856Texture2DArray::~Texture2DArray()
857{
Jamie Madill884a4622013-10-24 17:49:41 -0400858}
859
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000860GLsizei Texture2DArray::getWidth(GLint level) const
861{
Brandon Jones142ec422014-07-16 10:31:30 -0700862 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 +0000863}
864
865GLsizei Texture2DArray::getHeight(GLint level) const
866{
Brandon Jones142ec422014-07-16 10:31:30 -0700867 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 +0000868}
869
Jamie Madillb8f8b892014-01-07 10:12:50 -0500870GLsizei Texture2DArray::getLayers(GLint level) const
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000871{
Brandon Jones142ec422014-07-16 10:31:30 -0700872 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getLayerCount(level) : 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000873}
874
875GLenum Texture2DArray::getInternalFormat(GLint level) const
876{
Brandon Jones142ec422014-07-16 10:31:30 -0700877 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 +0000878}
879
880GLenum Texture2DArray::getActualFormat(GLint level) const
881{
Brandon Jones142ec422014-07-16 10:31:30 -0700882 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 +0000883}
884
885bool Texture2DArray::isCompressed(GLint level) const
886{
Geoff Lang5d601382014-07-22 15:14:06 -0400887 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000888}
889
890bool Texture2DArray::isDepth(GLint level) const
891{
Geoff Lang5d601382014-07-22 15:14:06 -0400892 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000893}
894
Geoff Lang005df412013-10-16 14:12:50 -0400895void 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 +0000896{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700897 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 +0000898}
899
900void Texture2DArray::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
901{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700902 mTexture->setCompressedImage(GL_TEXTURE_2D_ARRAY, level, format, width, height, depth, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000903}
904
Jamie Madill88f18f42013-09-18 14:36:19 -0400905void 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 +0000906{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700907 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 +0000908}
909
910void Texture2DArray::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
911{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700912 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 +0000913}
914
915void Texture2DArray::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
916{
Jamie Madill884a4622013-10-24 17:49:41 -0400917 mImmutable = true;
Brandon Jones142ec422014-07-16 10:31:30 -0700918
Brandon Jonescef06ff2014-08-05 13:27:48 -0700919 mTexture->storage(GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, depth);
Jamie Madill2ebab852013-10-24 17:49:42 -0400920}
921
Brandon Jones6053a522014-07-25 16:22:09 -0700922bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
923{
924 GLsizei width = getBaseLevelWidth();
925 GLsizei height = getBaseLevelHeight();
926 GLsizei depth = getLayers(0);
927
928 if (width <= 0 || height <= 0 || depth <= 0)
929 {
930 return false;
931 }
932
933 if (!textureCaps.get(getBaseLevelInternalFormat()).filterable && !IsPointSampled(samplerState))
934 {
935 return false;
936 }
937
938 if (IsMipmapFiltered(samplerState) && !isMipmapComplete())
939 {
940 return false;
941 }
942
943 return true;
944}
945
Brandon Jones6053a522014-07-25 16:22:09 -0700946bool Texture2DArray::isMipmapComplete() const
947{
948 int levelCount = mipLevels();
949
950 for (int level = 1; level < levelCount; level++)
951 {
952 if (!isLevelComplete(level))
953 {
954 return false;
955 }
956 }
957
958 return true;
959}
960
961bool Texture2DArray::isLevelComplete(int level) const
962{
963 ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
964
965 if (isImmutable())
966 {
967 return true;
968 }
969
970 GLsizei width = getBaseLevelWidth();
971 GLsizei height = getBaseLevelHeight();
972 GLsizei layers = getLayers(0);
973
974 if (width <= 0 || height <= 0 || layers <= 0)
975 {
976 return false;
977 }
978
979 if (level == 0)
980 {
981 return true;
982 }
983
984 if (getInternalFormat(level) != getInternalFormat(0))
985 {
986 return false;
987 }
988
989 if (getWidth(level) != std::max(1, width >> level))
990 {
991 return false;
992 }
993
994 if (getHeight(level) != std::max(1, height >> level))
995 {
996 return false;
997 }
998
999 if (getLayers(level) != layers)
1000 {
1001 return false;
1002 }
1003
1004 return true;
1005}
1006
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00001007}