blob: 624f6ee11ebf3436203cab9a267d222be6f05b75 [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
Geoff Langef7b0162014-09-04 13:29:23 -0400151Error Texture::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
152 GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
Brandon Jones6b19b002014-07-16 14:32:05 -0700153{
Geoff Langef7b0162014-09-04 13:29:23 -0400154 return mTexture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, source);
Brandon Jones6b19b002014-07-16 14:32:05 -0700155}
156
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700157unsigned int Texture::getTextureSerial()
158{
Jamie Madill2f06dbf2014-09-18 15:08:50 -0400159 rx::TextureStorage *texture = getNativeTexture();
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700160 return texture ? texture->getTextureSerial() : 0;
161}
162
163bool Texture::isImmutable() const
164{
165 return mImmutable;
166}
167
168int Texture::immutableLevelCount()
169{
Jamie Madill2f06dbf2014-09-18 15:08:50 -0400170 return (mImmutable ? getNativeTexture()->getLevelCount() : 0);
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700171}
172
173int Texture::mipLevels() const
174{
175 return log2(std::max(std::max(getBaseLevelWidth(), getBaseLevelHeight()), getBaseLevelDepth())) + 1;
176}
177
Brandon Jonescef06ff2014-08-05 13:27:48 -0700178const rx::Image *Texture::getBaseLevelImage() const
179{
180 return (getImplementation()->getLayerCount(0) > 0 ? getImplementation()->getImage(0, 0) : NULL);
181}
182
Brandon Jones6053a522014-07-25 16:22:09 -0700183Texture2D::Texture2D(rx::TextureImpl *impl, GLuint id)
184 : Texture(impl, id, GL_TEXTURE_2D)
Jamie Madill22f843a2013-10-24 17:49:36 -0400185{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000186 mSurface = NULL;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000187}
188
189Texture2D::~Texture2D()
190{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000191 if (mSurface)
192 {
193 mSurface->setBoundTexture(NULL);
194 mSurface = NULL;
195 }
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700196}
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000197
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000198GLsizei Texture2D::getWidth(GLint level) const
199{
200 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700201 return mTexture->getImage(level, 0)->getWidth();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000202 else
203 return 0;
204}
205
206GLsizei Texture2D::getHeight(GLint level) const
207{
208 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700209 return mTexture->getImage(level, 0)->getHeight();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000210 else
211 return 0;
212}
213
214GLenum Texture2D::getInternalFormat(GLint level) const
215{
216 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700217 return mTexture->getImage(level, 0)->getInternalFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000218 else
219 return GL_NONE;
220}
221
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000222GLenum Texture2D::getActualFormat(GLint level) const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000223{
224 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700225 return mTexture->getImage(level, 0)->getActualFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000226 else
Geoff Langcbf727a2014-02-10 12:50:45 -0500227 return GL_NONE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000228}
229
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400230Error 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 +0000231{
232 releaseTexImage();
shannon.woods@transgaming.com8a406682013-02-28 23:15:26 +0000233
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400234 return mTexture->setImage(GL_TEXTURE_2D, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000235}
236
237void Texture2D::bindTexImage(egl::Surface *surface)
238{
239 releaseTexImage();
240
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700241 mTexture->bindTexImage(surface);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000242
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000243 mSurface = surface;
244 mSurface->setBoundTexture(this);
245}
246
247void Texture2D::releaseTexImage()
248{
249 if (mSurface)
250 {
251 mSurface->setBoundTexture(NULL);
252 mSurface = NULL;
253
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700254 mTexture->releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000255 }
256}
257
Geoff Langb5348332014-09-02 13:16:34 -0400258Error Texture2D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize,
259 const void *pixels)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000260{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700261 releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000262
Geoff Langb5348332014-09-02 13:16:34 -0400263 return mTexture->setCompressedImage(GL_TEXTURE_2D, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000264}
265
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400266Error 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 +0000267{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400268 return mTexture->subImage(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000269}
270
Geoff Langb5348332014-09-02 13:16:34 -0400271Error Texture2D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
272 GLenum format, GLsizei imageSize, const void *pixels)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000273{
Geoff Langb5348332014-09-02 13:16:34 -0400274 return mTexture->subImageCompressed(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000275}
276
Geoff Langef7b0162014-09-04 13:29:23 -0400277Error Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height,
278 Framebuffer *source)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000279{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700280 releaseTexImage();
Geoff Lang5d601382014-07-22 15:14:06 -0400281
Geoff Langef7b0162014-09-04 13:29:23 -0400282 return mTexture->copyImage(GL_TEXTURE_2D, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000283}
284
Geoff Lang1f8532b2014-09-05 09:46:13 -0400285Error Texture2D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000286{
Geoff Lang1f8532b2014-09-05 09:46:13 -0400287 Error error = mTexture->storage(GL_TEXTURE_2D, levels, internalformat, width, height, 1);
288 if (error.isError())
289 {
290 return error;
291 }
292
Jamie Madill73b5d062013-10-24 17:49:38 -0400293 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000294
Geoff Lang1f8532b2014-09-05 09:46:13 -0400295 return Error(GL_NO_ERROR);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000296}
297
Brandon Jones6053a522014-07-25 16:22:09 -0700298// Tests for 2D texture sampling completeness. [OpenGL ES 2.0.24] section 3.8.2 page 85.
299bool Texture2D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
300{
301 GLsizei width = getBaseLevelWidth();
302 GLsizei height = getBaseLevelHeight();
303
304 if (width <= 0 || height <= 0)
305 {
306 return false;
307 }
308
309 if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
310 {
311 return false;
312 }
313
314 bool npotSupport = extensions.textureNPOT;
315
316 if (!npotSupport)
317 {
318 if ((samplerState.wrapS != GL_CLAMP_TO_EDGE && !gl::isPow2(width)) ||
319 (samplerState.wrapT != GL_CLAMP_TO_EDGE && !gl::isPow2(height)))
320 {
321 return false;
322 }
323 }
324
325 if (IsMipmapFiltered(samplerState))
326 {
327 if (!npotSupport)
328 {
329 if (!gl::isPow2(width) || !gl::isPow2(height))
330 {
331 return false;
332 }
333 }
334
335 if (!isMipmapComplete())
336 {
337 return false;
338 }
339 }
340
341 // OpenGLES 3.0.2 spec section 3.8.13 states that a texture is not mipmap complete if:
342 // The internalformat specified for the texture arrays is a sized internal depth or
343 // depth and stencil format (see table 3.13), the value of TEXTURE_COMPARE_-
344 // MODE is NONE, and either the magnification filter is not NEAREST or the mini-
345 // fication filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST.
346 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(getInternalFormat(0));
347 if (formatInfo.depthBits > 0 && clientVersion > 2)
348 {
349 if (samplerState.compareMode == GL_NONE)
350 {
351 if ((samplerState.minFilter != GL_NEAREST && samplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST) ||
352 samplerState.magFilter != GL_NEAREST)
353 {
354 return false;
355 }
356 }
357 }
358
359 return true;
360}
361
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000362bool Texture2D::isCompressed(GLint level) const
363{
Geoff Lang5d601382014-07-22 15:14:06 -0400364 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000365}
366
367bool Texture2D::isDepth(GLint level) const
368{
Geoff Lang5d601382014-07-22 15:14:06 -0400369 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000370}
371
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000372void Texture2D::generateMipmaps()
373{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700374 releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000375
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700376 mTexture->generateMipmaps();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000377}
378
Brandon Jones6053a522014-07-25 16:22:09 -0700379// Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
380bool Texture2D::isMipmapComplete() const
381{
382 int levelCount = mipLevels();
383
384 for (int level = 0; level < levelCount; level++)
385 {
386 if (!isLevelComplete(level))
387 {
388 return false;
389 }
390 }
391
392 return true;
393}
394
395bool Texture2D::isLevelComplete(int level) const
396{
397 if (isImmutable())
398 {
399 return true;
400 }
401
402 const rx::Image *baseImage = getBaseLevelImage();
403
404 GLsizei width = baseImage->getWidth();
405 GLsizei height = baseImage->getHeight();
406
407 if (width <= 0 || height <= 0)
408 {
409 return false;
410 }
411
412 // The base image level is complete if the width and height are positive
413 if (level == 0)
414 {
415 return true;
416 }
417
418 ASSERT(level >= 1 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
419 rx::Image *image = mTexture->getImage(level, 0);
420
421 if (image->getInternalFormat() != baseImage->getInternalFormat())
422 {
423 return false;
424 }
425
426 if (image->getWidth() != std::max(1, width >> level))
427 {
428 return false;
429 }
430
431 if (image->getHeight() != std::max(1, height >> level))
432 {
433 return false;
434 }
435
436 return true;
437}
438
439TextureCubeMap::TextureCubeMap(rx::TextureImpl *impl, GLuint id)
440 : Texture(impl, id, GL_TEXTURE_CUBE_MAP)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000441{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000442}
443
444TextureCubeMap::~TextureCubeMap()
445{
Brandon Jones0511e802014-07-14 16:27:26 -0700446}
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000447
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000448GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const
449{
450 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700451 return mTexture->getImage(level, targetToLayerIndex(target))->getWidth();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000452 else
453 return 0;
454}
455
456GLsizei TextureCubeMap::getHeight(GLenum target, GLint level) const
457{
458 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700459 return mTexture->getImage(level, targetToLayerIndex(target))->getHeight();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000460 else
461 return 0;
462}
463
464GLenum TextureCubeMap::getInternalFormat(GLenum target, GLint level) const
465{
466 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700467 return mTexture->getImage(level, targetToLayerIndex(target))->getInternalFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000468 else
469 return GL_NONE;
470}
471
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000472GLenum TextureCubeMap::getActualFormat(GLenum target, GLint level) const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000473{
474 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700475 return mTexture->getImage(level, targetToLayerIndex(target))->getActualFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000476 else
Geoff Langcbf727a2014-02-10 12:50:45 -0500477 return GL_NONE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000478}
479
Geoff Lang8376cea2014-09-02 11:47:07 -0400480Error TextureCubeMap::setImage(GLenum target, 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{
Geoff Lang8376cea2014-09-02 11:47:07 -0400482 return mTexture->setImage(target, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000483}
484
Geoff Langb5348332014-09-02 13:16:34 -0400485Error TextureCubeMap::setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height,
486 GLsizei imageSize, const void *pixels)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000487{
Geoff Langb5348332014-09-02 13:16:34 -0400488 return mTexture->setCompressedImage(target, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000489}
490
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400491Error 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 +0000492{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400493 return mTexture->subImage(target, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000494}
495
Geoff Langb5348332014-09-02 13:16:34 -0400496Error TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset,
497 GLsizei width, GLsizei height, GLenum format,
498 GLsizei imageSize, const void *pixels)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000499{
Geoff Langb5348332014-09-02 13:16:34 -0400500 return mTexture->subImageCompressed(target, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000501}
502
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000503// Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
504bool TextureCubeMap::isCubeComplete() const
505{
Brandon Jones6053a522014-07-25 16:22:09 -0700506 int baseWidth = getBaseLevelWidth();
507 int baseHeight = getBaseLevelHeight();
508 GLenum baseFormat = getBaseLevelInternalFormat();
509
510 if (baseWidth <= 0 || baseWidth != baseHeight)
511 {
512 return false;
513 }
514
515 for (int faceIndex = 1; faceIndex < 6; faceIndex++)
516 {
517 const rx::Image *faceBaseImage = mTexture->getImage(0, faceIndex);
518
519 if (faceBaseImage->getWidth() != baseWidth ||
520 faceBaseImage->getHeight() != baseHeight ||
521 faceBaseImage->getInternalFormat() != baseFormat )
522 {
523 return false;
524 }
525 }
526
527 return true;
Jamie Madill07edd442013-07-19 16:36:58 -0400528}
529
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000530bool TextureCubeMap::isCompressed(GLenum target, GLint level) const
531{
Geoff Lang5d601382014-07-22 15:14:06 -0400532 return GetInternalFormatInfo(getInternalFormat(target, level)).compressed;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000533}
534
Geoff Lang8040f572013-07-25 16:49:54 -0400535bool TextureCubeMap::isDepth(GLenum target, GLint level) const
536{
Geoff Lang5d601382014-07-22 15:14:06 -0400537 return GetInternalFormatInfo(getInternalFormat(target, level)).depthBits > 0;
Geoff Lang8040f572013-07-25 16:49:54 -0400538}
539
Geoff Langef7b0162014-09-04 13:29:23 -0400540Error TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y,
541 GLsizei width, GLsizei height, Framebuffer *source)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000542{
Geoff Langef7b0162014-09-04 13:29:23 -0400543 return mTexture->copyImage(target, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000544}
545
Geoff Lang1f8532b2014-09-05 09:46:13 -0400546Error TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000547{
Geoff Lang1f8532b2014-09-05 09:46:13 -0400548 Error error = mTexture->storage(GL_TEXTURE_CUBE_MAP, levels, internalformat, size, size, 1);
549 if (error.isError())
550 {
551 return error;
552 }
553
Jamie Madill3c0989c2013-10-24 17:49:39 -0400554 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000555
Geoff Lang1f8532b2014-09-05 09:46:13 -0400556 return Error(GL_NO_ERROR);
Jamie Madill2ebab852013-10-24 17:49:42 -0400557}
558
Brandon Jones6053a522014-07-25 16:22:09 -0700559// Tests for texture sampling completeness
560bool TextureCubeMap::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
561{
562 int size = getBaseLevelWidth();
563
564 bool mipmapping = IsMipmapFiltered(samplerState);
565
566 if (!textureCaps.get(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)).filterable && !IsPointSampled(samplerState))
567 {
568 return false;
569 }
570
571 if (!gl::isPow2(size) && !extensions.textureNPOT)
572 {
573 if (samplerState.wrapS != GL_CLAMP_TO_EDGE || samplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping)
574 {
575 return false;
576 }
577 }
578
579 if (!mipmapping)
580 {
581 if (!isCubeComplete())
582 {
583 return false;
584 }
585 }
586 else
587 {
588 if (!isMipmapComplete()) // Also tests for isCubeComplete()
589 {
590 return false;
591 }
592 }
593
594 return true;
595}
596
Brandon Jonescef06ff2014-08-05 13:27:48 -0700597int TextureCubeMap::targetToLayerIndex(GLenum target)
598{
599 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
600 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
601 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
602 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
603 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
604
605 return target - GL_TEXTURE_CUBE_MAP_POSITIVE_X;
606}
607
608GLenum TextureCubeMap::layerIndexToTarget(GLint layer)
609{
610 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
611 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
612 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
613 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
614 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
615
616 return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
Geoff Lang8040f572013-07-25 16:49:54 -0400617}
618
Brandon Jones6053a522014-07-25 16:22:09 -0700619bool TextureCubeMap::isMipmapComplete() const
620{
621 if (isImmutable())
622 {
623 return true;
624 }
625
626 if (!isCubeComplete())
627 {
628 return false;
629 }
630
631 int levelCount = mipLevels();
632
633 for (int face = 0; face < 6; face++)
634 {
635 for (int level = 1; level < levelCount; level++)
636 {
637 if (!isFaceLevelComplete(face, level))
638 {
639 return false;
640 }
641 }
642 }
643
644 return true;
645}
646
647bool TextureCubeMap::isFaceLevelComplete(int faceIndex, int level) const
648{
649 ASSERT(level >= 0 && faceIndex < 6 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, faceIndex) != NULL);
650
651 if (isImmutable())
652 {
653 return true;
654 }
655
656 int baseSize = getBaseLevelWidth();
657
658 if (baseSize <= 0)
659 {
660 return false;
661 }
662
663 // "isCubeComplete" checks for base level completeness and we must call that
664 // to determine if any face at level 0 is complete. We omit that check here
665 // to avoid re-checking cube-completeness for every face at level 0.
666 if (level == 0)
667 {
668 return true;
669 }
670
671 // Check that non-zero levels are consistent with the base level.
672 const rx::Image *faceLevelImage = mTexture->getImage(level, faceIndex);
673
674 if (faceLevelImage->getInternalFormat() != getBaseLevelInternalFormat())
675 {
676 return false;
677 }
678
679 if (faceLevelImage->getWidth() != std::max(1, baseSize >> level))
680 {
681 return false;
682 }
683
684 return true;
685}
686
687
688Texture3D::Texture3D(rx::TextureImpl *impl, GLuint id)
689 : Texture(impl, id, GL_TEXTURE_3D)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000690{
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000691}
692
693Texture3D::~Texture3D()
694{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700695}
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000696
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000697GLsizei Texture3D::getWidth(GLint level) const
698{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700699 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getWidth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000700}
701
702GLsizei Texture3D::getHeight(GLint level) const
703{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700704 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getHeight() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000705}
706
707GLsizei Texture3D::getDepth(GLint level) const
708{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700709 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getDepth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000710}
711
712GLenum Texture3D::getInternalFormat(GLint level) const
713{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700714 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000715}
716
717GLenum Texture3D::getActualFormat(GLint level) const
718{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700719 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getActualFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000720}
721
722bool Texture3D::isCompressed(GLint level) const
723{
Geoff Lang5d601382014-07-22 15:14:06 -0400724 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000725}
726
727bool Texture3D::isDepth(GLint level) const
728{
Geoff Lang5d601382014-07-22 15:14:06 -0400729 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000730}
731
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400732Error 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 +0000733{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400734 return 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 +0000735}
736
Geoff Langb5348332014-09-02 13:16:34 -0400737Error Texture3D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth,
738 GLsizei imageSize, const void *pixels)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000739{
Geoff Langb5348332014-09-02 13:16:34 -0400740 return mTexture->setCompressedImage(GL_TEXTURE_3D, level, format, width, height, depth, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000741}
742
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400743Error 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 +0000744{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400745 return 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 +0000746}
747
Geoff Langb5348332014-09-02 13:16:34 -0400748Error Texture3D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
749 GLsizei width, GLsizei height, GLsizei depth, GLenum format,
750 GLsizei imageSize, const void *pixels)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000751{
Geoff Langb5348332014-09-02 13:16:34 -0400752 return 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 +0000753}
754
Geoff Lang1f8532b2014-09-05 09:46:13 -0400755Error Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000756{
Geoff Lang1f8532b2014-09-05 09:46:13 -0400757 Error error = mTexture->storage(GL_TEXTURE_3D, levels, internalformat, width, height, depth);
758 if (error.isError())
759 {
760 return error;
761 }
762
Jamie Madille664e202013-10-24 17:49:40 -0400763 mImmutable = true;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000764
Geoff Lang1f8532b2014-09-05 09:46:13 -0400765 return Error(GL_NO_ERROR);
Jamie Madill2ebab852013-10-24 17:49:42 -0400766}
767
Brandon Jones6053a522014-07-25 16:22:09 -0700768bool Texture3D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
769{
770 GLsizei width = getBaseLevelWidth();
771 GLsizei height = getBaseLevelHeight();
772 GLsizei depth = getBaseLevelDepth();
773
774 if (width <= 0 || height <= 0 || depth <= 0)
775 {
776 return false;
777 }
778
779 if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
780 {
781 return false;
782 }
783
784 if (IsMipmapFiltered(samplerState) && !isMipmapComplete())
785 {
786 return false;
787 }
788
789 return true;
790}
791
Brandon Jones6053a522014-07-25 16:22:09 -0700792bool Texture3D::isMipmapComplete() const
793{
794 int levelCount = mipLevels();
795
796 for (int level = 0; level < levelCount; level++)
797 {
798 if (!isLevelComplete(level))
799 {
800 return false;
801 }
802 }
803
804 return true;
805}
806
807bool Texture3D::isLevelComplete(int level) const
808{
809 ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
810
811 if (isImmutable())
812 {
813 return true;
814 }
815
816 GLsizei width = getBaseLevelWidth();
817 GLsizei height = getBaseLevelHeight();
818 GLsizei depth = getBaseLevelDepth();
819
820 if (width <= 0 || height <= 0 || depth <= 0)
821 {
822 return false;
823 }
824
825 if (level == 0)
826 {
827 return true;
828 }
829
830 rx::Image *levelImage = mTexture->getImage(level, 0);
831
832 if (levelImage->getInternalFormat() != getBaseLevelInternalFormat())
833 {
834 return false;
835 }
836
837 if (levelImage->getWidth() != std::max(1, width >> level))
838 {
839 return false;
840 }
841
842 if (levelImage->getHeight() != std::max(1, height >> level))
843 {
844 return false;
845 }
846
847 if (levelImage->getDepth() != std::max(1, depth >> level))
848 {
849 return false;
850 }
851
852 return true;
853}
854
855Texture2DArray::Texture2DArray(rx::TextureImpl *impl, GLuint id)
856 : Texture(impl, id, GL_TEXTURE_2D_ARRAY)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000857{
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000858}
859
860Texture2DArray::~Texture2DArray()
861{
Jamie Madill884a4622013-10-24 17:49:41 -0400862}
863
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000864GLsizei Texture2DArray::getWidth(GLint level) const
865{
Brandon Jones142ec422014-07-16 10:31:30 -0700866 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 +0000867}
868
869GLsizei Texture2DArray::getHeight(GLint level) const
870{
Brandon Jones142ec422014-07-16 10:31:30 -0700871 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 +0000872}
873
Jamie Madillb8f8b892014-01-07 10:12:50 -0500874GLsizei Texture2DArray::getLayers(GLint level) const
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000875{
Brandon Jones142ec422014-07-16 10:31:30 -0700876 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getLayerCount(level) : 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000877}
878
879GLenum Texture2DArray::getInternalFormat(GLint level) const
880{
Brandon Jones142ec422014-07-16 10:31:30 -0700881 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 +0000882}
883
884GLenum Texture2DArray::getActualFormat(GLint level) const
885{
Brandon Jones142ec422014-07-16 10:31:30 -0700886 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 +0000887}
888
889bool Texture2DArray::isCompressed(GLint level) const
890{
Geoff Lang5d601382014-07-22 15:14:06 -0400891 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000892}
893
894bool Texture2DArray::isDepth(GLint level) const
895{
Geoff Lang5d601382014-07-22 15:14:06 -0400896 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000897}
898
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400899Error 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 +0000900{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400901 return 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 +0000902}
903
Geoff Langb5348332014-09-02 13:16:34 -0400904Error Texture2DArray::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth,
905 GLsizei imageSize, const void *pixels)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000906{
Geoff Langb5348332014-09-02 13:16:34 -0400907 return mTexture->setCompressedImage(GL_TEXTURE_2D_ARRAY, level, format, width, height, depth, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000908}
909
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400910Error 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 +0000911{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400912 return 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 +0000913}
914
Geoff Langb5348332014-09-02 13:16:34 -0400915Error Texture2DArray::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
916 GLsizei width, GLsizei height, GLsizei depth, GLenum format,
917 GLsizei imageSize, const void *pixels)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000918{
Geoff Langb5348332014-09-02 13:16:34 -0400919 return 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 +0000920}
921
Geoff Lang1f8532b2014-09-05 09:46:13 -0400922Error Texture2DArray::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000923{
Geoff Lang1f8532b2014-09-05 09:46:13 -0400924 Error error = mTexture->storage(GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, depth);
925 if (error.isError())
926 {
927 return error;
928 }
929
Jamie Madill884a4622013-10-24 17:49:41 -0400930 mImmutable = true;
Brandon Jones142ec422014-07-16 10:31:30 -0700931
Geoff Lang1f8532b2014-09-05 09:46:13 -0400932 return Error(GL_NO_ERROR);
Jamie Madill2ebab852013-10-24 17:49:42 -0400933}
934
Brandon Jones6053a522014-07-25 16:22:09 -0700935bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
936{
937 GLsizei width = getBaseLevelWidth();
938 GLsizei height = getBaseLevelHeight();
939 GLsizei depth = getLayers(0);
940
941 if (width <= 0 || height <= 0 || depth <= 0)
942 {
943 return false;
944 }
945
946 if (!textureCaps.get(getBaseLevelInternalFormat()).filterable && !IsPointSampled(samplerState))
947 {
948 return false;
949 }
950
951 if (IsMipmapFiltered(samplerState) && !isMipmapComplete())
952 {
953 return false;
954 }
955
956 return true;
957}
958
Brandon Jones6053a522014-07-25 16:22:09 -0700959bool Texture2DArray::isMipmapComplete() const
960{
961 int levelCount = mipLevels();
962
963 for (int level = 1; level < levelCount; level++)
964 {
965 if (!isLevelComplete(level))
966 {
967 return false;
968 }
969 }
970
971 return true;
972}
973
974bool Texture2DArray::isLevelComplete(int level) const
975{
976 ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
977
978 if (isImmutable())
979 {
980 return true;
981 }
982
983 GLsizei width = getBaseLevelWidth();
984 GLsizei height = getBaseLevelHeight();
985 GLsizei layers = getLayers(0);
986
987 if (width <= 0 || height <= 0 || layers <= 0)
988 {
989 return false;
990 }
991
992 if (level == 0)
993 {
994 return true;
995 }
996
997 if (getInternalFormat(level) != getInternalFormat(0))
998 {
999 return false;
1000 }
1001
1002 if (getWidth(level) != std::max(1, width >> level))
1003 {
1004 return false;
1005 }
1006
1007 if (getHeight(level) != std::max(1, height >> level))
1008 {
1009 return false;
1010 }
1011
1012 if (getLayers(level) != layers)
1013 {
1014 return false;
1015 }
1016
1017 return true;
1018}
1019
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00001020}