blob: 22a6f16af1a71182488308b26db8109a476db5aa [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 Jonescef06ff2014-08-05 13:27:48 -0700355rx::RenderTarget *Texture2D::getDepthStencil(GLint level)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000356{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700357 return mTexture->getDepthStencil(level, 0);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000358}
359
Brandon Jones6053a522014-07-25 16:22:09 -0700360// Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
361bool Texture2D::isMipmapComplete() const
362{
363 int levelCount = mipLevels();
364
365 for (int level = 0; level < levelCount; level++)
366 {
367 if (!isLevelComplete(level))
368 {
369 return false;
370 }
371 }
372
373 return true;
374}
375
376bool Texture2D::isLevelComplete(int level) const
377{
378 if (isImmutable())
379 {
380 return true;
381 }
382
383 const rx::Image *baseImage = getBaseLevelImage();
384
385 GLsizei width = baseImage->getWidth();
386 GLsizei height = baseImage->getHeight();
387
388 if (width <= 0 || height <= 0)
389 {
390 return false;
391 }
392
393 // The base image level is complete if the width and height are positive
394 if (level == 0)
395 {
396 return true;
397 }
398
399 ASSERT(level >= 1 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
400 rx::Image *image = mTexture->getImage(level, 0);
401
402 if (image->getInternalFormat() != baseImage->getInternalFormat())
403 {
404 return false;
405 }
406
407 if (image->getWidth() != std::max(1, width >> level))
408 {
409 return false;
410 }
411
412 if (image->getHeight() != std::max(1, height >> level))
413 {
414 return false;
415 }
416
417 return true;
418}
419
420TextureCubeMap::TextureCubeMap(rx::TextureImpl *impl, GLuint id)
421 : Texture(impl, id, GL_TEXTURE_CUBE_MAP)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000422{
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000423}
424
425TextureCubeMap::~TextureCubeMap()
426{
Brandon Jones0511e802014-07-14 16:27:26 -0700427}
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000428
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000429GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const
430{
431 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700432 return mTexture->getImage(level, targetToLayerIndex(target))->getWidth();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000433 else
434 return 0;
435}
436
437GLsizei TextureCubeMap::getHeight(GLenum target, GLint level) const
438{
439 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700440 return mTexture->getImage(level, targetToLayerIndex(target))->getHeight();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000441 else
442 return 0;
443}
444
445GLenum TextureCubeMap::getInternalFormat(GLenum target, GLint level) const
446{
447 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700448 return mTexture->getImage(level, targetToLayerIndex(target))->getInternalFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000449 else
450 return GL_NONE;
451}
452
daniel@transgaming.com20d36662012-10-31 19:51:43 +0000453GLenum TextureCubeMap::getActualFormat(GLenum target, GLint level) const
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000454{
455 if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
Brandon Jonescef06ff2014-08-05 13:27:48 -0700456 return mTexture->getImage(level, targetToLayerIndex(target))->getActualFormat();
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000457 else
Geoff Langcbf727a2014-02-10 12:50:45 -0500458 return GL_NONE;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000459}
460
Geoff Lang005df412013-10-16 14:12:50 -0400461void 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 +0000462{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700463 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 +0000464}
465
Geoff Lang005df412013-10-16 14:12:50 -0400466void 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 +0000467{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700468 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 +0000469}
470
Geoff Lang005df412013-10-16 14:12:50 -0400471void 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 +0000472{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700473 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 +0000474}
475
Geoff Lang005df412013-10-16 14:12:50 -0400476void 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 +0000477{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700478 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 +0000479}
480
Geoff Lang005df412013-10-16 14:12:50 -0400481void 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 +0000482{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700483 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 +0000484}
485
Geoff Lang005df412013-10-16 14:12:50 -0400486void 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 +0000487{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700488 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 +0000489}
490
Jamie Madill2db197c2013-10-24 17:49:35 -0400491void 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 +0000492{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700493 mTexture->setCompressedImage(target, level, format, width, height, 1, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000494}
495
Jamie Madill88f18f42013-09-18 14:36:19 -0400496void 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 +0000497{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700498 mTexture->subImage(target, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000499}
500
501void TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels)
502{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700503 mTexture->subImageCompressed(target, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, pixels);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000504}
505
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000506// Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
507bool TextureCubeMap::isCubeComplete() const
508{
Brandon Jones6053a522014-07-25 16:22:09 -0700509 int baseWidth = getBaseLevelWidth();
510 int baseHeight = getBaseLevelHeight();
511 GLenum baseFormat = getBaseLevelInternalFormat();
512
513 if (baseWidth <= 0 || baseWidth != baseHeight)
514 {
515 return false;
516 }
517
518 for (int faceIndex = 1; faceIndex < 6; faceIndex++)
519 {
520 const rx::Image *faceBaseImage = mTexture->getImage(0, faceIndex);
521
522 if (faceBaseImage->getWidth() != baseWidth ||
523 faceBaseImage->getHeight() != baseHeight ||
524 faceBaseImage->getInternalFormat() != baseFormat )
525 {
526 return false;
527 }
528 }
529
530 return true;
Jamie Madill07edd442013-07-19 16:36:58 -0400531}
532
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000533bool TextureCubeMap::isCompressed(GLenum target, GLint level) const
534{
Geoff Lang5d601382014-07-22 15:14:06 -0400535 return GetInternalFormatInfo(getInternalFormat(target, level)).compressed;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000536}
537
Geoff Lang8040f572013-07-25 16:49:54 -0400538bool TextureCubeMap::isDepth(GLenum target, GLint level) const
539{
Geoff Lang5d601382014-07-22 15:14:06 -0400540 return GetInternalFormatInfo(getInternalFormat(target, level)).depthBits > 0;
Geoff Lang8040f572013-07-25 16:49:54 -0400541}
542
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000543void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source)
544{
Brandon Jones0511e802014-07-14 16:27:26 -0700545 mTexture->copyImage(target, level, format, x, y, width, height, source);
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000546}
547
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000548void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size)
549{
Jamie Madill3c0989c2013-10-24 17:49:39 -0400550 mImmutable = true;
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000551
Brandon Jonescef06ff2014-08-05 13:27:48 -0700552 mTexture->storage(GL_TEXTURE_CUBE_MAP, levels, internalformat, size, size, 1);
Jamie Madill2ebab852013-10-24 17:49:42 -0400553}
554
Brandon Jones6053a522014-07-25 16:22:09 -0700555// Tests for texture sampling completeness
556bool TextureCubeMap::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
557{
558 int size = getBaseLevelWidth();
559
560 bool mipmapping = IsMipmapFiltered(samplerState);
561
562 if (!textureCaps.get(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)).filterable && !IsPointSampled(samplerState))
563 {
564 return false;
565 }
566
567 if (!gl::isPow2(size) && !extensions.textureNPOT)
568 {
569 if (samplerState.wrapS != GL_CLAMP_TO_EDGE || samplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping)
570 {
571 return false;
572 }
573 }
574
575 if (!mipmapping)
576 {
577 if (!isCubeComplete())
578 {
579 return false;
580 }
581 }
582 else
583 {
584 if (!isMipmapComplete()) // Also tests for isCubeComplete()
585 {
586 return false;
587 }
588 }
589
590 return true;
591}
592
Jamie Madill2db197c2013-10-24 17:49:35 -0400593unsigned int TextureCubeMap::getRenderTargetSerial(GLenum target, GLint level)
Geoff Lang8040f572013-07-25 16:49:54 -0400594{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700595 return mTexture->getRenderTargetSerial(level, targetToLayerIndex(target));
596}
597
598int TextureCubeMap::targetToLayerIndex(GLenum target)
599{
600 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
601 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
602 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
603 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
604 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
605
606 return target - GL_TEXTURE_CUBE_MAP_POSITIVE_X;
607}
608
609GLenum TextureCubeMap::layerIndexToTarget(GLint layer)
610{
611 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1);
612 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2);
613 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3);
614 META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4);
615 META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5);
616
617 return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer;
Geoff Lang8040f572013-07-25 16:49:54 -0400618}
619
620rx::RenderTarget *TextureCubeMap::getRenderTarget(GLenum target, GLint level)
daniel@transgaming.com95a758f2012-07-12 15:17:06 +0000621{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700622 return mTexture->getRenderTarget(level, targetToLayerIndex(target));
Geoff Lang8040f572013-07-25 16:49:54 -0400623}
624
625rx::RenderTarget *TextureCubeMap::getDepthStencil(GLenum target, GLint level)
626{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700627 return mTexture->getDepthStencil(level, targetToLayerIndex(target));
daniel@transgaming.com690d8ae2012-10-31 19:52:08 +0000628}
629
Brandon Jones6053a522014-07-25 16:22:09 -0700630bool TextureCubeMap::isMipmapComplete() const
631{
632 if (isImmutable())
633 {
634 return true;
635 }
636
637 if (!isCubeComplete())
638 {
639 return false;
640 }
641
642 int levelCount = mipLevels();
643
644 for (int face = 0; face < 6; face++)
645 {
646 for (int level = 1; level < levelCount; level++)
647 {
648 if (!isFaceLevelComplete(face, level))
649 {
650 return false;
651 }
652 }
653 }
654
655 return true;
656}
657
658bool TextureCubeMap::isFaceLevelComplete(int faceIndex, int level) const
659{
660 ASSERT(level >= 0 && faceIndex < 6 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, faceIndex) != NULL);
661
662 if (isImmutable())
663 {
664 return true;
665 }
666
667 int baseSize = getBaseLevelWidth();
668
669 if (baseSize <= 0)
670 {
671 return false;
672 }
673
674 // "isCubeComplete" checks for base level completeness and we must call that
675 // to determine if any face at level 0 is complete. We omit that check here
676 // to avoid re-checking cube-completeness for every face at level 0.
677 if (level == 0)
678 {
679 return true;
680 }
681
682 // Check that non-zero levels are consistent with the base level.
683 const rx::Image *faceLevelImage = mTexture->getImage(level, faceIndex);
684
685 if (faceLevelImage->getInternalFormat() != getBaseLevelInternalFormat())
686 {
687 return false;
688 }
689
690 if (faceLevelImage->getWidth() != std::max(1, baseSize >> level))
691 {
692 return false;
693 }
694
695 return true;
696}
697
698
699Texture3D::Texture3D(rx::TextureImpl *impl, GLuint id)
700 : Texture(impl, id, GL_TEXTURE_3D)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000701{
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000702}
703
704Texture3D::~Texture3D()
705{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700706}
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000707
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000708GLsizei Texture3D::getWidth(GLint level) const
709{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700710 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getWidth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000711}
712
713GLsizei Texture3D::getHeight(GLint level) const
714{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700715 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getHeight() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000716}
717
718GLsizei Texture3D::getDepth(GLint level) const
719{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700720 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getDepth() : 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000721}
722
723GLenum Texture3D::getInternalFormat(GLint level) const
724{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700725 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000726}
727
728GLenum Texture3D::getActualFormat(GLint level) const
729{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700730 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getActualFormat() : GL_NONE;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000731}
732
733bool Texture3D::isCompressed(GLint level) const
734{
Geoff Lang5d601382014-07-22 15:14:06 -0400735 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000736}
737
738bool Texture3D::isDepth(GLint level) const
739{
Geoff Lang5d601382014-07-22 15:14:06 -0400740 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000741}
742
Geoff Lang005df412013-10-16 14:12:50 -0400743void 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 +0000744{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700745 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 +0000746}
747
748void Texture3D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
749{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700750 mTexture->setCompressedImage(GL_TEXTURE_3D, level, format, width, height, depth, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000751}
752
Jamie Madill88f18f42013-09-18 14:36:19 -0400753void 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 +0000754{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700755 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 +0000756}
757
758void Texture3D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
759{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700760 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 +0000761}
762
763void Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
764{
Jamie Madille664e202013-10-24 17:49:40 -0400765 mImmutable = true;
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000766
Brandon Jonescef06ff2014-08-05 13:27:48 -0700767 mTexture->storage(GL_TEXTURE_3D, levels, internalformat, width, height, depth);
Jamie Madill2ebab852013-10-24 17:49:42 -0400768}
769
Brandon Jones6053a522014-07-25 16:22:09 -0700770bool Texture3D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
771{
772 GLsizei width = getBaseLevelWidth();
773 GLsizei height = getBaseLevelHeight();
774 GLsizei depth = getBaseLevelDepth();
775
776 if (width <= 0 || height <= 0 || depth <= 0)
777 {
778 return false;
779 }
780
781 if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
782 {
783 return false;
784 }
785
786 if (IsMipmapFiltered(samplerState) && !isMipmapComplete())
787 {
788 return false;
789 }
790
791 return true;
792}
793
Geoff Lang8040f572013-07-25 16:49:54 -0400794unsigned int Texture3D::getRenderTargetSerial(GLint level, GLint layer)
795{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700796 return mTexture->getRenderTargetSerial(level, layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000797}
798
Jamie Madilla2d4e552013-10-10 15:12:01 -0400799
Geoff Lang8040f572013-07-25 16:49:54 -0400800rx::RenderTarget *Texture3D::getRenderTarget(GLint level, GLint layer)
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000801{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700802 return mTexture->getRenderTarget(level, layer);
Geoff Lang8040f572013-07-25 16:49:54 -0400803}
804
805rx::RenderTarget *Texture3D::getDepthStencil(GLint level, GLint layer)
806{
Brandon Jones78b1acd2014-07-15 15:33:07 -0700807 return mTexture->getDepthStencil(level, layer);
shannon.woods%transgaming.com@gtempaccount.com95996562013-04-13 03:44:58 +0000808}
809
Brandon Jones6053a522014-07-25 16:22:09 -0700810bool Texture3D::isMipmapComplete() const
811{
812 int levelCount = mipLevels();
813
814 for (int level = 0; level < levelCount; level++)
815 {
816 if (!isLevelComplete(level))
817 {
818 return false;
819 }
820 }
821
822 return true;
823}
824
825bool Texture3D::isLevelComplete(int level) const
826{
827 ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
828
829 if (isImmutable())
830 {
831 return true;
832 }
833
834 GLsizei width = getBaseLevelWidth();
835 GLsizei height = getBaseLevelHeight();
836 GLsizei depth = getBaseLevelDepth();
837
838 if (width <= 0 || height <= 0 || depth <= 0)
839 {
840 return false;
841 }
842
843 if (level == 0)
844 {
845 return true;
846 }
847
848 rx::Image *levelImage = mTexture->getImage(level, 0);
849
850 if (levelImage->getInternalFormat() != getBaseLevelInternalFormat())
851 {
852 return false;
853 }
854
855 if (levelImage->getWidth() != std::max(1, width >> level))
856 {
857 return false;
858 }
859
860 if (levelImage->getHeight() != std::max(1, height >> level))
861 {
862 return false;
863 }
864
865 if (levelImage->getDepth() != std::max(1, depth >> level))
866 {
867 return false;
868 }
869
870 return true;
871}
872
873Texture2DArray::Texture2DArray(rx::TextureImpl *impl, GLuint id)
874 : Texture(impl, id, GL_TEXTURE_2D_ARRAY)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000875{
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000876}
877
878Texture2DArray::~Texture2DArray()
879{
Jamie Madill884a4622013-10-24 17:49:41 -0400880}
881
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000882GLsizei Texture2DArray::getWidth(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)->getWidth() : 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000885}
886
887GLsizei Texture2DArray::getHeight(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)->getHeight() : 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000890}
891
Jamie Madillb8f8b892014-01-07 10:12:50 -0500892GLsizei Texture2DArray::getLayers(GLint level) const
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000893{
Brandon Jones142ec422014-07-16 10:31:30 -0700894 return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getLayerCount(level) : 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000895}
896
897GLenum Texture2DArray::getInternalFormat(GLint level) const
898{
Brandon Jones142ec422014-07-16 10:31:30 -0700899 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 +0000900}
901
902GLenum Texture2DArray::getActualFormat(GLint level) const
903{
Brandon Jones142ec422014-07-16 10:31:30 -0700904 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 +0000905}
906
907bool Texture2DArray::isCompressed(GLint level) const
908{
Geoff Lang5d601382014-07-22 15:14:06 -0400909 return GetInternalFormatInfo(getInternalFormat(level)).compressed;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000910}
911
912bool Texture2DArray::isDepth(GLint level) const
913{
Geoff Lang5d601382014-07-22 15:14:06 -0400914 return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000915}
916
Geoff Lang005df412013-10-16 14:12:50 -0400917void 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 +0000918{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700919 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 +0000920}
921
922void Texture2DArray::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels)
923{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700924 mTexture->setCompressedImage(GL_TEXTURE_2D_ARRAY, level, format, width, height, depth, imageSize, pixels);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000925}
926
Jamie Madill88f18f42013-09-18 14:36:19 -0400927void 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 +0000928{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700929 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 +0000930}
931
932void Texture2DArray::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels)
933{
Brandon Jonescef06ff2014-08-05 13:27:48 -0700934 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 +0000935}
936
937void Texture2DArray::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
938{
Jamie Madill884a4622013-10-24 17:49:41 -0400939 mImmutable = true;
Brandon Jones142ec422014-07-16 10:31:30 -0700940
Brandon Jonescef06ff2014-08-05 13:27:48 -0700941 mTexture->storage(GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, depth);
Jamie Madill2ebab852013-10-24 17:49:42 -0400942}
943
Brandon Jones6053a522014-07-25 16:22:09 -0700944bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const
945{
946 GLsizei width = getBaseLevelWidth();
947 GLsizei height = getBaseLevelHeight();
948 GLsizei depth = getLayers(0);
949
950 if (width <= 0 || height <= 0 || depth <= 0)
951 {
952 return false;
953 }
954
955 if (!textureCaps.get(getBaseLevelInternalFormat()).filterable && !IsPointSampled(samplerState))
956 {
957 return false;
958 }
959
960 if (IsMipmapFiltered(samplerState) && !isMipmapComplete())
961 {
962 return false;
963 }
964
965 return true;
966}
967
Jamie Madille83d1a92013-10-24 17:49:33 -0400968unsigned int Texture2DArray::getRenderTargetSerial(GLint level, GLint layer)
Geoff Lang8040f572013-07-25 16:49:54 -0400969{
Brandon Jones142ec422014-07-16 10:31:30 -0700970 return mTexture->getRenderTargetSerial(level, layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000971}
972
Geoff Lang8040f572013-07-25 16:49:54 -0400973rx::RenderTarget *Texture2DArray::getRenderTarget(GLint level, GLint layer)
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000974{
Brandon Jones142ec422014-07-16 10:31:30 -0700975 return mTexture->getRenderTarget(level, layer);
Geoff Lang8040f572013-07-25 16:49:54 -0400976}
977
978rx::RenderTarget *Texture2DArray::getDepthStencil(GLint level, GLint layer)
979{
Brandon Jones142ec422014-07-16 10:31:30 -0700980 return mTexture->getDepthStencil(level, layer);
shannon.woods%transgaming.com@gtempaccount.com7625f792013-04-13 03:46:07 +0000981}
982
Brandon Jones6053a522014-07-25 16:22:09 -0700983bool Texture2DArray::isMipmapComplete() const
984{
985 int levelCount = mipLevels();
986
987 for (int level = 1; level < levelCount; level++)
988 {
989 if (!isLevelComplete(level))
990 {
991 return false;
992 }
993 }
994
995 return true;
996}
997
998bool Texture2DArray::isLevelComplete(int level) const
999{
1000 ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
1001
1002 if (isImmutable())
1003 {
1004 return true;
1005 }
1006
1007 GLsizei width = getBaseLevelWidth();
1008 GLsizei height = getBaseLevelHeight();
1009 GLsizei layers = getLayers(0);
1010
1011 if (width <= 0 || height <= 0 || layers <= 0)
1012 {
1013 return false;
1014 }
1015
1016 if (level == 0)
1017 {
1018 return true;
1019 }
1020
1021 if (getInternalFormat(level) != getInternalFormat(0))
1022 {
1023 return false;
1024 }
1025
1026 if (getWidth(level) != std::max(1, width >> level))
1027 {
1028 return false;
1029 }
1030
1031 if (getHeight(level) != std::max(1, height >> level))
1032 {
1033 return false;
1034 }
1035
1036 if (getLayers(level) != layers)
1037 {
1038 return false;
1039 }
1040
1041 return true;
1042}
1043
daniel@transgaming.com95a758f2012-07-12 15:17:06 +00001044}