blob: e7331c2b420023957241b16e84dd4c94ab27fa86 [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
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400229Error 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
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400233 return 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
Geoff Langb5348332014-09-02 13:16:34 -0400257Error Texture2D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize,
258 const void *pixels)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000259{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700260 releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000261
Geoff Langb5348332014-09-02 13:16:34 -0400262 return mTexture->setCompressedImage(GL_TEXTURE_2D, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000263}
264
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400265Error 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 +0000266{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400267 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 +0000268}
269
Geoff Langb5348332014-09-02 13:16:34 -0400270Error Texture2D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
271 GLenum format, GLsizei imageSize, const void *pixels)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000272{
Geoff Langb5348332014-09-02 13:16:34 -0400273 return mTexture->subImageCompressed(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000274}
275
276void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
277{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700278 releaseTexImage();
Geoff Lang5d601382014-07-22 15:14:06 -0400279
Brandon Jonescef06ff2014-08-05 13:27:48 -0700280 mTexture->copyImage(GL_TEXTURE_2D, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000281}
282
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000283void Texture2D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
284{
Jamie Madill73b5d062013-10-24 17:49:38 -0400285 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000286
Brandon Jonescef06ff2014-08-05 13:27:48 -0700287 mTexture->storage(GL_TEXTURE_2D, levels, internalformat, width, height, 1);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000288}
289
Brandon Jones6053a522014-07-25 16:22:09 -0700290// Tests for 2D texture sampling completeness. [OpenGL ES 2.0.24] section 3.8.2 page 85.
291bool Texture2D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
292{
293 GLsizei width = getBaseLevelWidth();
294 GLsizei height = getBaseLevelHeight();
295
296 if (width <= 0 || height <= 0)
297 {
298 return false;
299 }
300
301 if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
302 {
303 return false;
304 }
305
306 bool npotSupport = extensions.textureNPOT;
307
308 if (!npotSupport)
309 {
310 if ((samplerState.wrapS != GL_CLAMP_TO_EDGE && !gl::isPow2(width)) ||
311 (samplerState.wrapT != GL_CLAMP_TO_EDGE && !gl::isPow2(height)))
312 {
313 return false;
314 }
315 }
316
317 if (IsMipmapFiltered(samplerState))
318 {
319 if (!npotSupport)
320 {
321 if (!gl::isPow2(width) || !gl::isPow2(height))
322 {
323 return false;
324 }
325 }
326
327 if (!isMipmapComplete())
328 {
329 return false;
330 }
331 }
332
333 // OpenGLES 3.0.2 spec section 3.8.13 states that a texture is not mipmap complete if:
334 // The internalformat specified for the texture arrays is a sized internal depth or
335 // depth and stencil format (see table 3.13), the value of TEXTURE_COMPARE_-
336 // MODE is NONE, and either the magnification filter is not NEAREST or the mini-
337 // fication filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST.
338 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(getInternalFormat(0));
339 if (formatInfo.depthBits > 0 && clientVersion > 2)
340 {
341 if (samplerState.compareMode == GL_NONE)
342 {
343 if ((samplerState.minFilter != GL_NEAREST && samplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST) ||
344 samplerState.magFilter != GL_NEAREST)
345 {
346 return false;
347 }
348 }
349 }
350
351 return true;
352}
353
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000354bool Texture2D::isCompressed(GLint level) const
355{
Geoff Lang5d601382014-07-22 15:14:06 -0400356 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000357}
358
359bool Texture2D::isDepth(GLint level) const
360{
Geoff Lang5d601382014-07-22 15:14:06 -0400361 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000362}
363
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000364void Texture2D::generateMipmaps()
365{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700366 releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000367
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700368 mTexture->generateMipmaps();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000369}
370
Brandon Jones6053a522014-07-25 16:22:09 -0700371// Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
372bool Texture2D::isMipmapComplete() const
373{
374 int levelCount = mipLevels();
375
376 for (int level = 0; level < levelCount; level++)
377 {
378 if (!isLevelComplete(level))
379 {
380 return false;
381 }
382 }
383
384 return true;
385}
386
387bool Texture2D::isLevelComplete(int level) const
388{
389 if (isImmutable())
390 {
391 return true;
392 }
393
394 const rx::Image *baseImage = getBaseLevelImage();
395
396 GLsizei width = baseImage->getWidth();
397 GLsizei height = baseImage->getHeight();
398
399 if (width <= 0 || height <= 0)
400 {
401 return false;
402 }
403
404 // The base image level is complete if the width and height are positive
405 if (level == 0)
406 {
407 return true;
408 }
409
410 ASSERT(level >= 1 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
411 rx::Image *image = mTexture->getImage(level, 0);
412
413 if (image->getInternalFormat() != baseImage->getInternalFormat())
414 {
415 return false;
416 }
417
418 if (image->getWidth() != std::max(1, width >> level))
419 {
420 return false;
421 }
422
423 if (image->getHeight() != std::max(1, height >> level))
424 {
425 return false;
426 }
427
428 return true;
429}
430
431TextureCubeMap::TextureCubeMap(rx::TextureImpl *impl, GLuint id)
432 : Texture(impl, id, GL_TEXTURE_CUBE_MAP)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000433{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000434}
435
436TextureCubeMap::~TextureCubeMap()
437{
Brandon Jones0511e802014-07-14 16:27:26 -0700438}
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000439
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000440GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const
441{
442 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700443 return mTexture->getImage(level, targetToLayerIndex(target))->getWidth();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000444 else
445 return 0;
446}
447
448GLsizei TextureCubeMap::getHeight(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))->getHeight();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000452 else
453 return 0;
454}
455
456GLenum TextureCubeMap::getInternalFormat(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))->getInternalFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000460 else
461 return GL_NONE;
462}
463
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000464GLenum TextureCubeMap::getActualFormat(GLenum target, GLint level) const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000465{
466 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700467 return mTexture->getImage(level, targetToLayerIndex(target))->getActualFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000468 else
Geoff Langcbf727a2014-02-10 12:50:45 -0500469 return GL_NONE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000470}
471
Geoff Lang8376cea2014-09-02 11:47:07 -0400472Error 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 +0000473{
Geoff Lang8376cea2014-09-02 11:47:07 -0400474 return mTexture->setImage(target, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000475}
476
Geoff Langb5348332014-09-02 13:16:34 -0400477Error TextureCubeMap::setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height,
478 GLsizei imageSize, const void *pixels)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000479{
Geoff Langb5348332014-09-02 13:16:34 -0400480 return mTexture->setCompressedImage(target, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000481}
482
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400483Error 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 +0000484{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400485 return mTexture->subImage(target, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000486}
487
Geoff Langb5348332014-09-02 13:16:34 -0400488Error TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset,
489 GLsizei width, GLsizei height, GLenum format,
490 GLsizei imageSize, const void *pixels)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000491{
Geoff Langb5348332014-09-02 13:16:34 -0400492 return mTexture->subImageCompressed(target, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000493}
494
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000495// Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
496bool TextureCubeMap::isCubeComplete() const
497{
Brandon Jones6053a522014-07-25 16:22:09 -0700498 int baseWidth = getBaseLevelWidth();
499 int baseHeight = getBaseLevelHeight();
500 GLenum baseFormat = getBaseLevelInternalFormat();
501
502 if (baseWidth <= 0 || baseWidth != baseHeight)
503 {
504 return false;
505 }
506
507 for (int faceIndex = 1; faceIndex < 6; faceIndex++)
508 {
509 const rx::Image *faceBaseImage = mTexture->getImage(0, faceIndex);
510
511 if (faceBaseImage->getWidth() != baseWidth ||
512 faceBaseImage->getHeight() != baseHeight ||
513 faceBaseImage->getInternalFormat() != baseFormat )
514 {
515 return false;
516 }
517 }
518
519 return true;
Jamie Madill07edd442013-07-19 16:36:58 -0400520}
521
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000522bool TextureCubeMap::isCompressed(GLenum target, GLint level) const
523{
Geoff Lang5d601382014-07-22 15:14:06 -0400524 return GetInternalFormatInfo(getInternalFormat(target, level)).compressed;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000525}
526
Geoff Lang8040f572013-07-25 16:49:54 -0400527bool TextureCubeMap::isDepth(GLenum target, GLint level) const
528{
Geoff Lang5d601382014-07-22 15:14:06 -0400529 return GetInternalFormatInfo(getInternalFormat(target, level)).depthBits > 0;
Geoff Lang8040f572013-07-25 16:49:54 -0400530}
531
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000532void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
533{
Brandon Jones0511e802014-07-14 16:27:26 -0700534 mTexture->copyImage(target, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000535}
536
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000537void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size)
538{
Jamie Madill3c0989c2013-10-24 17:49:39 -0400539 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000540
Brandon Jonescef06ff2014-08-05 13:27:48 -0700541 mTexture->storage(GL_TEXTURE_CUBE_MAP, levels, internalformat, size, size, 1);
Jamie Madill2ebab852013-10-24 17:49:42 -0400542}
543
Brandon Jones6053a522014-07-25 16:22:09 -0700544// Tests for texture sampling completeness
545bool TextureCubeMap::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
546{
547 int size = getBaseLevelWidth();
548
549 bool mipmapping = IsMipmapFiltered(samplerState);
550
551 if (!textureCaps.get(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)).filterable && !IsPointSampled(samplerState))
552 {
553 return false;
554 }
555
556 if (!gl::isPow2(size) && !extensions.textureNPOT)
557 {
558 if (samplerState.wrapS != GL_CLAMP_TO_EDGE || samplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping)
559 {
560 return false;
561 }
562 }
563
564 if (!mipmapping)
565 {
566 if (!isCubeComplete())
567 {
568 return false;
569 }
570 }
571 else
572 {
573 if (!isMipmapComplete()) // Also tests for isCubeComplete()
574 {
575 return false;
576 }
577 }
578
579 return true;
580}
581
Brandon Jonescef06ff2014-08-05 13:27:48 -0700582int TextureCubeMap::targetToLayerIndex(GLenum target)
583{
584 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
585 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
586 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
587 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
588 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
589
590 return target - GL_TEXTURE_CUBE_MAP_POSITIVE_X;
591}
592
593GLenum TextureCubeMap::layerIndexToTarget(GLint layer)
594{
595 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
596 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
597 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
598 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
599 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
600
601 return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
Geoff Lang8040f572013-07-25 16:49:54 -0400602}
603
Brandon Jones6053a522014-07-25 16:22:09 -0700604bool TextureCubeMap::isMipmapComplete() const
605{
606 if (isImmutable())
607 {
608 return true;
609 }
610
611 if (!isCubeComplete())
612 {
613 return false;
614 }
615
616 int levelCount = mipLevels();
617
618 for (int face = 0; face < 6; face++)
619 {
620 for (int level = 1; level < levelCount; level++)
621 {
622 if (!isFaceLevelComplete(face, level))
623 {
624 return false;
625 }
626 }
627 }
628
629 return true;
630}
631
632bool TextureCubeMap::isFaceLevelComplete(int faceIndex, int level) const
633{
634 ASSERT(level >= 0 && faceIndex < 6 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, faceIndex) != NULL);
635
636 if (isImmutable())
637 {
638 return true;
639 }
640
641 int baseSize = getBaseLevelWidth();
642
643 if (baseSize <= 0)
644 {
645 return false;
646 }
647
648 // "isCubeComplete" checks for base level completeness and we must call that
649 // to determine if any face at level 0 is complete. We omit that check here
650 // to avoid re-checking cube-completeness for every face at level 0.
651 if (level == 0)
652 {
653 return true;
654 }
655
656 // Check that non-zero levels are consistent with the base level.
657 const rx::Image *faceLevelImage = mTexture->getImage(level, faceIndex);
658
659 if (faceLevelImage->getInternalFormat() != getBaseLevelInternalFormat())
660 {
661 return false;
662 }
663
664 if (faceLevelImage->getWidth() != std::max(1, baseSize >> level))
665 {
666 return false;
667 }
668
669 return true;
670}
671
672
673Texture3D::Texture3D(rx::TextureImpl *impl, GLuint id)
674 : Texture(impl, id, GL_TEXTURE_3D)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000675{
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000676}
677
678Texture3D::~Texture3D()
679{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700680}
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000681
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000682GLsizei Texture3D::getWidth(GLint level) const
683{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700684 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getWidth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000685}
686
687GLsizei Texture3D::getHeight(GLint level) const
688{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700689 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getHeight() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000690}
691
692GLsizei Texture3D::getDepth(GLint level) const
693{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700694 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getDepth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000695}
696
697GLenum Texture3D::getInternalFormat(GLint level) const
698{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700699 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000700}
701
702GLenum Texture3D::getActualFormat(GLint level) const
703{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700704 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getActualFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000705}
706
707bool Texture3D::isCompressed(GLint level) const
708{
Geoff Lang5d601382014-07-22 15:14:06 -0400709 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000710}
711
712bool Texture3D::isDepth(GLint level) const
713{
Geoff Lang5d601382014-07-22 15:14:06 -0400714 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000715}
716
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400717Error 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 +0000718{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400719 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 +0000720}
721
Geoff Langb5348332014-09-02 13:16:34 -0400722Error Texture3D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth,
723 GLsizei imageSize, const void *pixels)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000724{
Geoff Langb5348332014-09-02 13:16:34 -0400725 return mTexture->setCompressedImage(GL_TEXTURE_3D, level, format, width, height, depth, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000726}
727
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400728Error 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 +0000729{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400730 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 +0000731}
732
Geoff Langb5348332014-09-02 13:16:34 -0400733Error Texture3D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
734 GLsizei width, GLsizei height, GLsizei depth, GLenum format,
735 GLsizei imageSize, const void *pixels)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000736{
Geoff Langb5348332014-09-02 13:16:34 -0400737 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 +0000738}
739
740void Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
741{
Jamie Madille664e202013-10-24 17:49:40 -0400742 mImmutable = true;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000743
Brandon Jonescef06ff2014-08-05 13:27:48 -0700744 mTexture->storage(GL_TEXTURE_3D, levels, internalformat, width, height, depth);
Jamie Madill2ebab852013-10-24 17:49:42 -0400745}
746
Brandon Jones6053a522014-07-25 16:22:09 -0700747bool Texture3D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
748{
749 GLsizei width = getBaseLevelWidth();
750 GLsizei height = getBaseLevelHeight();
751 GLsizei depth = getBaseLevelDepth();
752
753 if (width <= 0 || height <= 0 || depth <= 0)
754 {
755 return false;
756 }
757
758 if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
759 {
760 return false;
761 }
762
763 if (IsMipmapFiltered(samplerState) && !isMipmapComplete())
764 {
765 return false;
766 }
767
768 return true;
769}
770
Brandon Jones6053a522014-07-25 16:22:09 -0700771bool Texture3D::isMipmapComplete() const
772{
773 int levelCount = mipLevels();
774
775 for (int level = 0; level < levelCount; level++)
776 {
777 if (!isLevelComplete(level))
778 {
779 return false;
780 }
781 }
782
783 return true;
784}
785
786bool Texture3D::isLevelComplete(int level) const
787{
788 ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
789
790 if (isImmutable())
791 {
792 return true;
793 }
794
795 GLsizei width = getBaseLevelWidth();
796 GLsizei height = getBaseLevelHeight();
797 GLsizei depth = getBaseLevelDepth();
798
799 if (width <= 0 || height <= 0 || depth <= 0)
800 {
801 return false;
802 }
803
804 if (level == 0)
805 {
806 return true;
807 }
808
809 rx::Image *levelImage = mTexture->getImage(level, 0);
810
811 if (levelImage->getInternalFormat() != getBaseLevelInternalFormat())
812 {
813 return false;
814 }
815
816 if (levelImage->getWidth() != std::max(1, width >> level))
817 {
818 return false;
819 }
820
821 if (levelImage->getHeight() != std::max(1, height >> level))
822 {
823 return false;
824 }
825
826 if (levelImage->getDepth() != std::max(1, depth >> level))
827 {
828 return false;
829 }
830
831 return true;
832}
833
834Texture2DArray::Texture2DArray(rx::TextureImpl *impl, GLuint id)
835 : Texture(impl, id, GL_TEXTURE_2D_ARRAY)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000836{
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000837}
838
839Texture2DArray::~Texture2DArray()
840{
Jamie Madill884a4622013-10-24 17:49:41 -0400841}
842
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000843GLsizei Texture2DArray::getWidth(GLint level) const
844{
Brandon Jones142ec422014-07-16 10:31:30 -0700845 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 +0000846}
847
848GLsizei Texture2DArray::getHeight(GLint level) const
849{
Brandon Jones142ec422014-07-16 10:31:30 -0700850 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 +0000851}
852
Jamie Madillb8f8b892014-01-07 10:12:50 -0500853GLsizei Texture2DArray::getLayers(GLint level) const
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000854{
Brandon Jones142ec422014-07-16 10:31:30 -0700855 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getLayerCount(level) : 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000856}
857
858GLenum Texture2DArray::getInternalFormat(GLint level) const
859{
Brandon Jones142ec422014-07-16 10:31:30 -0700860 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 +0000861}
862
863GLenum Texture2DArray::getActualFormat(GLint level) const
864{
Brandon Jones142ec422014-07-16 10:31:30 -0700865 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 +0000866}
867
868bool Texture2DArray::isCompressed(GLint level) const
869{
Geoff Lang5d601382014-07-22 15:14:06 -0400870 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000871}
872
873bool Texture2DArray::isDepth(GLint level) const
874{
Geoff Lang5d601382014-07-22 15:14:06 -0400875 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000876}
877
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400878Error 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 +0000879{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400880 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 +0000881}
882
Geoff Langb5348332014-09-02 13:16:34 -0400883Error Texture2DArray::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth,
884 GLsizei imageSize, const void *pixels)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000885{
Geoff Langb5348332014-09-02 13:16:34 -0400886 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 +0000887}
888
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400889Error 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 +0000890{
Geoff Lang1ba6b8d2014-08-28 10:57:31 -0400891 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 +0000892}
893
Geoff Langb5348332014-09-02 13:16:34 -0400894Error Texture2DArray::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
895 GLsizei width, GLsizei height, GLsizei depth, GLenum format,
896 GLsizei imageSize, const void *pixels)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000897{
Geoff Langb5348332014-09-02 13:16:34 -0400898 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 +0000899}
900
901void Texture2DArray::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
902{
Jamie Madill884a4622013-10-24 17:49:41 -0400903 mImmutable = true;
Brandon Jones142ec422014-07-16 10:31:30 -0700904
Brandon Jonescef06ff2014-08-05 13:27:48 -0700905 mTexture->storage(GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, depth);
Jamie Madill2ebab852013-10-24 17:49:42 -0400906}
907
Brandon Jones6053a522014-07-25 16:22:09 -0700908bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
909{
910 GLsizei width = getBaseLevelWidth();
911 GLsizei height = getBaseLevelHeight();
912 GLsizei depth = getLayers(0);
913
914 if (width <= 0 || height <= 0 || depth <= 0)
915 {
916 return false;
917 }
918
919 if (!textureCaps.get(getBaseLevelInternalFormat()).filterable && !IsPointSampled(samplerState))
920 {
921 return false;
922 }
923
924 if (IsMipmapFiltered(samplerState) && !isMipmapComplete())
925 {
926 return false;
927 }
928
929 return true;
930}
931
Brandon Jones6053a522014-07-25 16:22:09 -0700932bool Texture2DArray::isMipmapComplete() const
933{
934 int levelCount = mipLevels();
935
936 for (int level = 1; level < levelCount; level++)
937 {
938 if (!isLevelComplete(level))
939 {
940 return false;
941 }
942 }
943
944 return true;
945}
946
947bool Texture2DArray::isLevelComplete(int level) const
948{
949 ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
950
951 if (isImmutable())
952 {
953 return true;
954 }
955
956 GLsizei width = getBaseLevelWidth();
957 GLsizei height = getBaseLevelHeight();
958 GLsizei layers = getLayers(0);
959
960 if (width <= 0 || height <= 0 || layers <= 0)
961 {
962 return false;
963 }
964
965 if (level == 0)
966 {
967 return true;
968 }
969
970 if (getInternalFormat(level) != getInternalFormat(0))
971 {
972 return false;
973 }
974
975 if (getWidth(level) != std::max(1, width >> level))
976 {
977 return false;
978 }
979
980 if (getHeight(level) != std::max(1, height >> level))
981 {
982 return false;
983 }
984
985 if (getLayers(level) != layers)
986 {
987 return false;
988 }
989
990 return true;
991}
992
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000993}