blob: 4f7453282d2c2e1db0ee87a58fd4e0bec5652b4c [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"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000015#include "libGLESv2/Renderbuffer.h"
16#include "libGLESv2/renderer/Image.h"
Jamie Madill0e0510f2013-10-10 15:46:23 -040017#include "libGLESv2/renderer/RenderTarget.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
80 rx::TextureStorageInterface *texture = getNativeTexture();
81 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
Brandon Jones6b19b002014-07-16 14:32:05 -0700117rx::TextureStorageInterface *Texture::getNativeTexture()
118{
119 return getImplementation()->getNativeTexture();
120}
121
Brandon Jonescef06ff2014-08-05 13:27:48 -0700122void Texture::generateMipmaps()
123{
124 getImplementation()->generateMipmaps();
125}
126
Brandon Jones6b19b002014-07-16 14:32:05 -0700127void Texture::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
128{
129 getImplementation()->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, source);
130}
131
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700132unsigned int Texture::getTextureSerial()
133{
134 rx::TextureStorageInterface *texture = getNativeTexture();
135 return texture ? texture->getTextureSerial() : 0;
136}
137
138bool Texture::isImmutable() const
139{
140 return mImmutable;
141}
142
143int Texture::immutableLevelCount()
144{
145 return (mImmutable ? getNativeTexture()->getStorageInstance()->getLevelCount() : 0);
146}
147
148int Texture::mipLevels() const
149{
150 return log2(std::max(std::max(getBaseLevelWidth(), getBaseLevelHeight()), getBaseLevelDepth())) + 1;
151}
152
Brandon Jonescef06ff2014-08-05 13:27:48 -0700153const rx::Image *Texture::getBaseLevelImage() const
154{
155 return (getImplementation()->getLayerCount(0) > 0 ? getImplementation()->getImage(0, 0) : NULL);
156}
157
Brandon Jones6053a522014-07-25 16:22:09 -0700158Texture2D::Texture2D(rx::TextureImpl *impl, GLuint id)
159 : Texture(impl, id, GL_TEXTURE_2D)
Jamie Madill22f843a2013-10-24 17:49:36 -0400160{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000161 mSurface = NULL;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000162}
163
164Texture2D::~Texture2D()
165{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000166 if (mSurface)
167 {
168 mSurface->setBoundTexture(NULL);
169 mSurface = NULL;
170 }
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700171}
daniel@transgaming.comd9ec9022012-12-20 20:52:16 +0000172
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000173GLsizei Texture2D::getWidth(GLint level) const
174{
175 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700176 return mTexture->getImage(level, 0)->getWidth();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000177 else
178 return 0;
179}
180
181GLsizei Texture2D::getHeight(GLint level) const
182{
183 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700184 return mTexture->getImage(level, 0)->getHeight();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000185 else
186 return 0;
187}
188
189GLenum Texture2D::getInternalFormat(GLint level) const
190{
191 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700192 return mTexture->getImage(level, 0)->getInternalFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000193 else
194 return GL_NONE;
195}
196
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000197GLenum Texture2D::getActualFormat(GLint level) const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000198{
199 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700200 return mTexture->getImage(level, 0)->getActualFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000201 else
Geoff Langcbf727a2014-02-10 12:50:45 -0500202 return GL_NONE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000203}
204
Brandon Jonescef06ff2014-08-05 13:27:48 -0700205void 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 +0000206{
207 releaseTexImage();
shannon.woods@transgaming.com8a406682013-02-28 23:15:26 +0000208
Brandon Jonescef06ff2014-08-05 13:27:48 -0700209 mTexture->setImage(GL_TEXTURE_2D, level, width, height, 1, internalFormat, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000210}
211
212void Texture2D::bindTexImage(egl::Surface *surface)
213{
214 releaseTexImage();
215
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700216 mTexture->bindTexImage(surface);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000217
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000218 mSurface = surface;
219 mSurface->setBoundTexture(this);
220}
221
222void Texture2D::releaseTexImage()
223{
224 if (mSurface)
225 {
226 mSurface->setBoundTexture(NULL);
227 mSurface = NULL;
228
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700229 mTexture->releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000230 }
231}
232
233void Texture2D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels)
234{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700235 releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000236
Brandon Jonescef06ff2014-08-05 13:27:48 -0700237 mTexture->setCompressedImage(GL_TEXTURE_2D, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000238}
239
Jamie Madill88f18f42013-09-18 14:36:19 -0400240void 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 +0000241{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700242 mTexture->subImage(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000243}
244
245void Texture2D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels)
246{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700247 mTexture->subImageCompressed(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000248}
249
250void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
251{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700252 releaseTexImage();
Geoff Lang5d601382014-07-22 15:14:06 -0400253
Brandon Jonescef06ff2014-08-05 13:27:48 -0700254 mTexture->copyImage(GL_TEXTURE_2D, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000255}
256
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000257void Texture2D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
258{
Jamie Madill73b5d062013-10-24 17:49:38 -0400259 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000260
Brandon Jonescef06ff2014-08-05 13:27:48 -0700261 mTexture->storage(GL_TEXTURE_2D, levels, internalformat, width, height, 1);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000262}
263
Brandon Jones6053a522014-07-25 16:22:09 -0700264// Tests for 2D texture sampling completeness. [OpenGL ES 2.0.24] section 3.8.2 page 85.
265bool Texture2D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
266{
267 GLsizei width = getBaseLevelWidth();
268 GLsizei height = getBaseLevelHeight();
269
270 if (width <= 0 || height <= 0)
271 {
272 return false;
273 }
274
275 if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
276 {
277 return false;
278 }
279
280 bool npotSupport = extensions.textureNPOT;
281
282 if (!npotSupport)
283 {
284 if ((samplerState.wrapS != GL_CLAMP_TO_EDGE && !gl::isPow2(width)) ||
285 (samplerState.wrapT != GL_CLAMP_TO_EDGE && !gl::isPow2(height)))
286 {
287 return false;
288 }
289 }
290
291 if (IsMipmapFiltered(samplerState))
292 {
293 if (!npotSupport)
294 {
295 if (!gl::isPow2(width) || !gl::isPow2(height))
296 {
297 return false;
298 }
299 }
300
301 if (!isMipmapComplete())
302 {
303 return false;
304 }
305 }
306
307 // OpenGLES 3.0.2 spec section 3.8.13 states that a texture is not mipmap complete if:
308 // The internalformat specified for the texture arrays is a sized internal depth or
309 // depth and stencil format (see table 3.13), the value of TEXTURE_COMPARE_-
310 // MODE is NONE, and either the magnification filter is not NEAREST or the mini-
311 // fication filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST.
312 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(getInternalFormat(0));
313 if (formatInfo.depthBits > 0 && clientVersion > 2)
314 {
315 if (samplerState.compareMode == GL_NONE)
316 {
317 if ((samplerState.minFilter != GL_NEAREST && samplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST) ||
318 samplerState.magFilter != GL_NEAREST)
319 {
320 return false;
321 }
322 }
323 }
324
325 return true;
326}
327
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000328bool Texture2D::isCompressed(GLint level) const
329{
Geoff Lang5d601382014-07-22 15:14:06 -0400330 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000331}
332
333bool Texture2D::isDepth(GLint level) const
334{
Geoff Lang5d601382014-07-22 15:14:06 -0400335 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000336}
337
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000338void Texture2D::generateMipmaps()
339{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700340 releaseTexImage();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000341
Brandon Jonesf47bebc2014-07-09 14:28:42 -0700342 mTexture->generateMipmaps();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000343}
344
Geoff Lang8040f572013-07-25 16:49:54 -0400345unsigned int Texture2D::getRenderTargetSerial(GLint level)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000346{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700347 return mTexture->getRenderTargetSerial(level, 0);
Geoff Lang8040f572013-07-25 16:49:54 -0400348}
349
350rx::RenderTarget *Texture2D::getRenderTarget(GLint level)
351{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700352 return mTexture->getRenderTarget(level, 0);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000353}
354
Brandon Jones6053a522014-07-25 16:22:09 -0700355// Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
356bool Texture2D::isMipmapComplete() const
357{
358 int levelCount = mipLevels();
359
360 for (int level = 0; level < levelCount; level++)
361 {
362 if (!isLevelComplete(level))
363 {
364 return false;
365 }
366 }
367
368 return true;
369}
370
371bool Texture2D::isLevelComplete(int level) const
372{
373 if (isImmutable())
374 {
375 return true;
376 }
377
378 const rx::Image *baseImage = getBaseLevelImage();
379
380 GLsizei width = baseImage->getWidth();
381 GLsizei height = baseImage->getHeight();
382
383 if (width <= 0 || height <= 0)
384 {
385 return false;
386 }
387
388 // The base image level is complete if the width and height are positive
389 if (level == 0)
390 {
391 return true;
392 }
393
394 ASSERT(level >= 1 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
395 rx::Image *image = mTexture->getImage(level, 0);
396
397 if (image->getInternalFormat() != baseImage->getInternalFormat())
398 {
399 return false;
400 }
401
402 if (image->getWidth() != std::max(1, width >> level))
403 {
404 return false;
405 }
406
407 if (image->getHeight() != std::max(1, height >> level))
408 {
409 return false;
410 }
411
412 return true;
413}
414
415TextureCubeMap::TextureCubeMap(rx::TextureImpl *impl, GLuint id)
416 : Texture(impl, id, GL_TEXTURE_CUBE_MAP)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000417{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000418}
419
420TextureCubeMap::~TextureCubeMap()
421{
Brandon Jones0511e802014-07-14 16:27:26 -0700422}
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000423
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000424GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const
425{
426 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700427 return mTexture->getImage(level, targetToLayerIndex(target))->getWidth();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000428 else
429 return 0;
430}
431
432GLsizei TextureCubeMap::getHeight(GLenum target, GLint level) const
433{
434 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700435 return mTexture->getImage(level, targetToLayerIndex(target))->getHeight();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000436 else
437 return 0;
438}
439
440GLenum TextureCubeMap::getInternalFormat(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))->getInternalFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000444 else
445 return GL_NONE;
446}
447
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000448GLenum TextureCubeMap::getActualFormat(GLenum target, GLint level) const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000449{
450 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700451 return mTexture->getImage(level, targetToLayerIndex(target))->getActualFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000452 else
Geoff Langcbf727a2014-02-10 12:50:45 -0500453 return GL_NONE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000454}
455
Geoff Lang005df412013-10-16 14:12:50 -0400456void 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 +0000457{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700458 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 +0000459}
460
Geoff Lang005df412013-10-16 14:12:50 -0400461void 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 +0000462{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700463 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 +0000464}
465
Geoff Lang005df412013-10-16 14:12:50 -0400466void 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 +0000467{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700468 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 +0000469}
470
Geoff Lang005df412013-10-16 14:12:50 -0400471void 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 +0000472{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700473 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 +0000474}
475
Geoff Lang005df412013-10-16 14:12:50 -0400476void 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 +0000477{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700478 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 +0000479}
480
Geoff Lang005df412013-10-16 14:12:50 -0400481void 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 +0000482{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700483 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 +0000484}
485
Jamie Madill2db197c2013-10-24 17:49:35 -0400486void 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 +0000487{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700488 mTexture->setCompressedImage(target, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000489}
490
Jamie Madill88f18f42013-09-18 14:36:19 -0400491void 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{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700493 mTexture->subImage(target, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000494}
495
496void TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels)
497{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700498 mTexture->subImageCompressed(target, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000499}
500
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000501// Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
502bool TextureCubeMap::isCubeComplete() const
503{
Brandon Jones6053a522014-07-25 16:22:09 -0700504 int baseWidth = getBaseLevelWidth();
505 int baseHeight = getBaseLevelHeight();
506 GLenum baseFormat = getBaseLevelInternalFormat();
507
508 if (baseWidth <= 0 || baseWidth != baseHeight)
509 {
510 return false;
511 }
512
513 for (int faceIndex = 1; faceIndex < 6; faceIndex++)
514 {
515 const rx::Image *faceBaseImage = mTexture->getImage(0, faceIndex);
516
517 if (faceBaseImage->getWidth() != baseWidth ||
518 faceBaseImage->getHeight() != baseHeight ||
519 faceBaseImage->getInternalFormat() != baseFormat )
520 {
521 return false;
522 }
523 }
524
525 return true;
Jamie Madill07edd442013-07-19 16:36:58 -0400526}
527
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000528bool TextureCubeMap::isCompressed(GLenum target, GLint level) const
529{
Geoff Lang5d601382014-07-22 15:14:06 -0400530 return GetInternalFormatInfo(getInternalFormat(target, level)).compressed;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000531}
532
Geoff Lang8040f572013-07-25 16:49:54 -0400533bool TextureCubeMap::isDepth(GLenum target, GLint level) const
534{
Geoff Lang5d601382014-07-22 15:14:06 -0400535 return GetInternalFormatInfo(getInternalFormat(target, level)).depthBits > 0;
Geoff Lang8040f572013-07-25 16:49:54 -0400536}
537
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000538void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
539{
Brandon Jones0511e802014-07-14 16:27:26 -0700540 mTexture->copyImage(target, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000541}
542
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000543void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size)
544{
Jamie Madill3c0989c2013-10-24 17:49:39 -0400545 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000546
Brandon Jonescef06ff2014-08-05 13:27:48 -0700547 mTexture->storage(GL_TEXTURE_CUBE_MAP, levels, internalformat, size, size, 1);
Jamie Madill2ebab852013-10-24 17:49:42 -0400548}
549
Brandon Jones6053a522014-07-25 16:22:09 -0700550// Tests for texture sampling completeness
551bool TextureCubeMap::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
552{
553 int size = getBaseLevelWidth();
554
555 bool mipmapping = IsMipmapFiltered(samplerState);
556
557 if (!textureCaps.get(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)).filterable && !IsPointSampled(samplerState))
558 {
559 return false;
560 }
561
562 if (!gl::isPow2(size) && !extensions.textureNPOT)
563 {
564 if (samplerState.wrapS != GL_CLAMP_TO_EDGE || samplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping)
565 {
566 return false;
567 }
568 }
569
570 if (!mipmapping)
571 {
572 if (!isCubeComplete())
573 {
574 return false;
575 }
576 }
577 else
578 {
579 if (!isMipmapComplete()) // Also tests for isCubeComplete()
580 {
581 return false;
582 }
583 }
584
585 return true;
586}
587
Jamie Madill2db197c2013-10-24 17:49:35 -0400588unsigned int TextureCubeMap::getRenderTargetSerial(GLenum target, GLint level)
Geoff Lang8040f572013-07-25 16:49:54 -0400589{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700590 return mTexture->getRenderTargetSerial(level, targetToLayerIndex(target));
591}
592
593int TextureCubeMap::targetToLayerIndex(GLenum target)
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 target - GL_TEXTURE_CUBE_MAP_POSITIVE_X;
602}
603
604GLenum TextureCubeMap::layerIndexToTarget(GLint layer)
605{
606 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
607 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
608 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
609 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
610 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
611
612 return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
Geoff Lang8040f572013-07-25 16:49:54 -0400613}
614
615rx::RenderTarget *TextureCubeMap::getRenderTarget(GLenum target, GLint level)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000616{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700617 return mTexture->getRenderTarget(level, targetToLayerIndex(target));
Geoff Lang8040f572013-07-25 16:49:54 -0400618}
619
Brandon Jones6053a522014-07-25 16:22:09 -0700620bool TextureCubeMap::isMipmapComplete() const
621{
622 if (isImmutable())
623 {
624 return true;
625 }
626
627 if (!isCubeComplete())
628 {
629 return false;
630 }
631
632 int levelCount = mipLevels();
633
634 for (int face = 0; face < 6; face++)
635 {
636 for (int level = 1; level < levelCount; level++)
637 {
638 if (!isFaceLevelComplete(face, level))
639 {
640 return false;
641 }
642 }
643 }
644
645 return true;
646}
647
648bool TextureCubeMap::isFaceLevelComplete(int faceIndex, int level) const
649{
650 ASSERT(level >= 0 && faceIndex < 6 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, faceIndex) != NULL);
651
652 if (isImmutable())
653 {
654 return true;
655 }
656
657 int baseSize = getBaseLevelWidth();
658
659 if (baseSize <= 0)
660 {
661 return false;
662 }
663
664 // "isCubeComplete" checks for base level completeness and we must call that
665 // to determine if any face at level 0 is complete. We omit that check here
666 // to avoid re-checking cube-completeness for every face at level 0.
667 if (level == 0)
668 {
669 return true;
670 }
671
672 // Check that non-zero levels are consistent with the base level.
673 const rx::Image *faceLevelImage = mTexture->getImage(level, faceIndex);
674
675 if (faceLevelImage->getInternalFormat() != getBaseLevelInternalFormat())
676 {
677 return false;
678 }
679
680 if (faceLevelImage->getWidth() != std::max(1, baseSize >> level))
681 {
682 return false;
683 }
684
685 return true;
686}
687
688
689Texture3D::Texture3D(rx::TextureImpl *impl, GLuint id)
690 : Texture(impl, id, GL_TEXTURE_3D)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000691{
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000692}
693
694Texture3D::~Texture3D()
695{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700696}
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000697
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000698GLsizei Texture3D::getWidth(GLint level) const
699{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700700 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getWidth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000701}
702
703GLsizei Texture3D::getHeight(GLint level) const
704{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700705 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getHeight() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000706}
707
708GLsizei Texture3D::getDepth(GLint level) const
709{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700710 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getDepth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000711}
712
713GLenum Texture3D::getInternalFormat(GLint level) const
714{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700715 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000716}
717
718GLenum Texture3D::getActualFormat(GLint level) const
719{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700720 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getActualFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000721}
722
723bool Texture3D::isCompressed(GLint level) const
724{
Geoff Lang5d601382014-07-22 15:14:06 -0400725 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000726}
727
728bool Texture3D::isDepth(GLint level) const
729{
Geoff Lang5d601382014-07-22 15:14:06 -0400730 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000731}
732
Geoff Lang005df412013-10-16 14:12:50 -0400733void 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 +0000734{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700735 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 +0000736}
737
738void Texture3D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
739{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700740 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
Jamie Madill88f18f42013-09-18 14:36:19 -0400743void 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{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700745 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
748void Texture3D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
749{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700750 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 +0000751}
752
753void Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
754{
Jamie Madille664e202013-10-24 17:49:40 -0400755 mImmutable = true;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000756
Brandon Jonescef06ff2014-08-05 13:27:48 -0700757 mTexture->storage(GL_TEXTURE_3D, levels, internalformat, width, height, depth);
Jamie Madill2ebab852013-10-24 17:49:42 -0400758}
759
Brandon Jones6053a522014-07-25 16:22:09 -0700760bool Texture3D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
761{
762 GLsizei width = getBaseLevelWidth();
763 GLsizei height = getBaseLevelHeight();
764 GLsizei depth = getBaseLevelDepth();
765
766 if (width <= 0 || height <= 0 || depth <= 0)
767 {
768 return false;
769 }
770
771 if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
772 {
773 return false;
774 }
775
776 if (IsMipmapFiltered(samplerState) && !isMipmapComplete())
777 {
778 return false;
779 }
780
781 return true;
782}
783
Geoff Lang8040f572013-07-25 16:49:54 -0400784unsigned int Texture3D::getRenderTargetSerial(GLint level, GLint layer)
785{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700786 return mTexture->getRenderTargetSerial(level, layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000787}
788
Jamie Madilla2d4e552013-10-10 15:12:01 -0400789
Geoff Lang8040f572013-07-25 16:49:54 -0400790rx::RenderTarget *Texture3D::getRenderTarget(GLint level, GLint layer)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000791{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700792 return mTexture->getRenderTarget(level, layer);
Geoff Lang8040f572013-07-25 16:49:54 -0400793}
794
Brandon Jones6053a522014-07-25 16:22:09 -0700795bool Texture3D::isMipmapComplete() const
796{
797 int levelCount = mipLevels();
798
799 for (int level = 0; level < levelCount; level++)
800 {
801 if (!isLevelComplete(level))
802 {
803 return false;
804 }
805 }
806
807 return true;
808}
809
810bool Texture3D::isLevelComplete(int level) const
811{
812 ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
813
814 if (isImmutable())
815 {
816 return true;
817 }
818
819 GLsizei width = getBaseLevelWidth();
820 GLsizei height = getBaseLevelHeight();
821 GLsizei depth = getBaseLevelDepth();
822
823 if (width <= 0 || height <= 0 || depth <= 0)
824 {
825 return false;
826 }
827
828 if (level == 0)
829 {
830 return true;
831 }
832
833 rx::Image *levelImage = mTexture->getImage(level, 0);
834
835 if (levelImage->getInternalFormat() != getBaseLevelInternalFormat())
836 {
837 return false;
838 }
839
840 if (levelImage->getWidth() != std::max(1, width >> level))
841 {
842 return false;
843 }
844
845 if (levelImage->getHeight() != std::max(1, height >> level))
846 {
847 return false;
848 }
849
850 if (levelImage->getDepth() != std::max(1, depth >> level))
851 {
852 return false;
853 }
854
855 return true;
856}
857
858Texture2DArray::Texture2DArray(rx::TextureImpl *impl, GLuint id)
859 : Texture(impl, id, GL_TEXTURE_2D_ARRAY)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000860{
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000861}
862
863Texture2DArray::~Texture2DArray()
864{
Jamie Madill884a4622013-10-24 17:49:41 -0400865}
866
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000867GLsizei Texture2DArray::getWidth(GLint level) const
868{
Brandon Jones142ec422014-07-16 10:31:30 -0700869 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 +0000870}
871
872GLsizei Texture2DArray::getHeight(GLint level) const
873{
Brandon Jones142ec422014-07-16 10:31:30 -0700874 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 +0000875}
876
Jamie Madillb8f8b892014-01-07 10:12:50 -0500877GLsizei Texture2DArray::getLayers(GLint level) const
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000878{
Brandon Jones142ec422014-07-16 10:31:30 -0700879 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getLayerCount(level) : 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000880}
881
882GLenum Texture2DArray::getInternalFormat(GLint level) const
883{
Brandon Jones142ec422014-07-16 10:31:30 -0700884 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 +0000885}
886
887GLenum Texture2DArray::getActualFormat(GLint level) const
888{
Brandon Jones142ec422014-07-16 10:31:30 -0700889 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 +0000890}
891
892bool Texture2DArray::isCompressed(GLint level) const
893{
Geoff Lang5d601382014-07-22 15:14:06 -0400894 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000895}
896
897bool Texture2DArray::isDepth(GLint level) const
898{
Geoff Lang5d601382014-07-22 15:14:06 -0400899 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000900}
901
Geoff Lang005df412013-10-16 14:12:50 -0400902void 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 +0000903{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700904 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 +0000905}
906
907void Texture2DArray::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
908{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700909 mTexture->setCompressedImage(GL_TEXTURE_2D_ARRAY, level, format, width, height, depth, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000910}
911
Jamie Madill88f18f42013-09-18 14:36:19 -0400912void 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 +0000913{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700914 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 +0000915}
916
917void Texture2DArray::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
918{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700919 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
922void Texture2DArray::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
923{
Jamie Madill884a4622013-10-24 17:49:41 -0400924 mImmutable = true;
Brandon Jones142ec422014-07-16 10:31:30 -0700925
Brandon Jonescef06ff2014-08-05 13:27:48 -0700926 mTexture->storage(GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, depth);
Jamie Madill2ebab852013-10-24 17:49:42 -0400927}
928
Brandon Jones6053a522014-07-25 16:22:09 -0700929bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
930{
931 GLsizei width = getBaseLevelWidth();
932 GLsizei height = getBaseLevelHeight();
933 GLsizei depth = getLayers(0);
934
935 if (width <= 0 || height <= 0 || depth <= 0)
936 {
937 return false;
938 }
939
940 if (!textureCaps.get(getBaseLevelInternalFormat()).filterable && !IsPointSampled(samplerState))
941 {
942 return false;
943 }
944
945 if (IsMipmapFiltered(samplerState) && !isMipmapComplete())
946 {
947 return false;
948 }
949
950 return true;
951}
952
Jamie Madille83d1a92013-10-24 17:49:33 -0400953unsigned int Texture2DArray::getRenderTargetSerial(GLint level, GLint layer)
Geoff Lang8040f572013-07-25 16:49:54 -0400954{
Brandon Jones142ec422014-07-16 10:31:30 -0700955 return mTexture->getRenderTargetSerial(level, layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000956}
957
Geoff Lang8040f572013-07-25 16:49:54 -0400958rx::RenderTarget *Texture2DArray::getRenderTarget(GLint level, GLint layer)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000959{
Brandon Jones142ec422014-07-16 10:31:30 -0700960 return mTexture->getRenderTarget(level, layer);
Geoff Lang8040f572013-07-25 16:49:54 -0400961}
962
Brandon Jones6053a522014-07-25 16:22:09 -0700963bool Texture2DArray::isMipmapComplete() const
964{
965 int levelCount = mipLevels();
966
967 for (int level = 1; level < levelCount; level++)
968 {
969 if (!isLevelComplete(level))
970 {
971 return false;
972 }
973 }
974
975 return true;
976}
977
978bool Texture2DArray::isLevelComplete(int level) const
979{
980 ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
981
982 if (isImmutable())
983 {
984 return true;
985 }
986
987 GLsizei width = getBaseLevelWidth();
988 GLsizei height = getBaseLevelHeight();
989 GLsizei layers = getLayers(0);
990
991 if (width <= 0 || height <= 0 || layers <= 0)
992 {
993 return false;
994 }
995
996 if (level == 0)
997 {
998 return true;
999 }
1000
1001 if (getInternalFormat(level) != getInternalFormat(0))
1002 {
1003 return false;
1004 }
1005
1006 if (getWidth(level) != std::max(1, width >> level))
1007 {
1008 return false;
1009 }
1010
1011 if (getHeight(level) != std::max(1, height >> level))
1012 {
1013 return false;
1014 }
1015
1016 if (getLayers(level) != layers)
1017 {
1018 return false;
1019 }
1020
1021 return true;
1022}
1023
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00001024}