daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 3 | // 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 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame^] | 11 | #include "libANGLE/Texture.h" |
| 12 | #include "libANGLE/Context.h" |
| 13 | #include "libANGLE/formatutils.h" |
| 14 | #include "libANGLE/ImageIndex.h" |
| 15 | #include "libANGLE/Renderbuffer.h" |
| 16 | #include "libANGLE/renderer/Image.h" |
| 17 | #include "libANGLE/renderer/d3d/TextureStorage.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 18 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame^] | 19 | #include "libANGLE/Surface.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 20 | |
| 21 | #include "common/mathutil.h" |
| 22 | #include "common/utilities.h" |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 23 | |
| 24 | namespace gl |
| 25 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 26 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 27 | bool IsMipmapFiltered(const gl::SamplerState &samplerState) |
| 28 | { |
| 29 | switch (samplerState.minFilter) |
| 30 | { |
| 31 | case GL_NEAREST: |
| 32 | case GL_LINEAR: |
| 33 | return false; |
| 34 | case GL_NEAREST_MIPMAP_NEAREST: |
| 35 | case GL_LINEAR_MIPMAP_NEAREST: |
| 36 | case GL_NEAREST_MIPMAP_LINEAR: |
| 37 | case GL_LINEAR_MIPMAP_LINEAR: |
| 38 | return true; |
| 39 | default: UNREACHABLE(); |
| 40 | return false; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | bool IsPointSampled(const gl::SamplerState &samplerState) |
| 45 | { |
| 46 | return (samplerState.magFilter == GL_NEAREST && (samplerState.minFilter == GL_NEAREST || samplerState.minFilter == GL_NEAREST_MIPMAP_NEAREST)); |
| 47 | } |
| 48 | |
Jamie Madill | 10ef215 | 2014-10-20 17:04:34 -0400 | [diff] [blame] | 49 | unsigned int Texture::mCurrentTextureSerial = 1; |
| 50 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 51 | Texture::Texture(rx::TextureImpl *impl, GLuint id, GLenum target) |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 52 | : RefCountObject(id), |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 53 | mTexture(impl), |
Jamie Madill | 10ef215 | 2014-10-20 17:04:34 -0400 | [diff] [blame] | 54 | mTextureSerial(issueTextureSerial()), |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 55 | mUsage(GL_NONE), |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 56 | mImmutableLevelCount(0), |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 57 | mTarget(target) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 58 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | Texture::~Texture() |
| 62 | { |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 63 | SafeDelete(mTexture); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Geoff Lang | 4907f2c | 2013-07-25 12:53:57 -0400 | [diff] [blame] | 66 | GLenum Texture::getTarget() const |
| 67 | { |
| 68 | return mTarget; |
| 69 | } |
| 70 | |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 71 | void Texture::setUsage(GLenum usage) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 72 | { |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 73 | mUsage = usage; |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 74 | getImplementation()->setUsage(usage); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 75 | } |
| 76 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 77 | GLenum Texture::getUsage() const |
| 78 | { |
| 79 | return mUsage; |
| 80 | } |
| 81 | |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 82 | GLint Texture::getBaseLevelWidth() const |
| 83 | { |
| 84 | const rx::Image *baseImage = getBaseLevelImage(); |
| 85 | return (baseImage ? baseImage->getWidth() : 0); |
| 86 | } |
| 87 | |
| 88 | GLint Texture::getBaseLevelHeight() const |
| 89 | { |
| 90 | const rx::Image *baseImage = getBaseLevelImage(); |
| 91 | return (baseImage ? baseImage->getHeight() : 0); |
| 92 | } |
| 93 | |
| 94 | GLint Texture::getBaseLevelDepth() const |
| 95 | { |
| 96 | const rx::Image *baseImage = getBaseLevelImage(); |
| 97 | return (baseImage ? baseImage->getDepth() : 0); |
| 98 | } |
| 99 | |
Jamie Madill | b8f8b89 | 2014-01-07 10:12:50 -0500 | [diff] [blame] | 100 | // Note: "base level image" is loosely defined to be any image from the base level, |
| 101 | // where in the base of 2D array textures and cube maps there are several. Don't use |
| 102 | // the base level image for anything except querying texture format and size. |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 103 | GLenum Texture::getBaseLevelInternalFormat() const |
| 104 | { |
| 105 | const rx::Image *baseImage = getBaseLevelImage(); |
| 106 | return (baseImage ? baseImage->getInternalFormat() : GL_NONE); |
| 107 | } |
| 108 | |
Jamie Madill | 945f732 | 2014-09-03 15:07:14 -0400 | [diff] [blame] | 109 | GLsizei Texture::getWidth(const ImageIndex &index) const |
| 110 | { |
Jamie Madill | feda4d2 | 2014-09-17 13:03:29 -0400 | [diff] [blame] | 111 | rx::Image *image = mTexture->getImage(index); |
Jamie Madill | 945f732 | 2014-09-03 15:07:14 -0400 | [diff] [blame] | 112 | return image->getWidth(); |
| 113 | } |
| 114 | |
| 115 | GLsizei Texture::getHeight(const ImageIndex &index) const |
| 116 | { |
Jamie Madill | feda4d2 | 2014-09-17 13:03:29 -0400 | [diff] [blame] | 117 | rx::Image *image = mTexture->getImage(index); |
Jamie Madill | 945f732 | 2014-09-03 15:07:14 -0400 | [diff] [blame] | 118 | return image->getHeight(); |
| 119 | } |
| 120 | |
| 121 | GLenum Texture::getInternalFormat(const ImageIndex &index) const |
| 122 | { |
Jamie Madill | feda4d2 | 2014-09-17 13:03:29 -0400 | [diff] [blame] | 123 | rx::Image *image = mTexture->getImage(index); |
Jamie Madill | 945f732 | 2014-09-03 15:07:14 -0400 | [diff] [blame] | 124 | return image->getInternalFormat(); |
| 125 | } |
| 126 | |
| 127 | GLenum Texture::getActualFormat(const ImageIndex &index) const |
| 128 | { |
Jamie Madill | feda4d2 | 2014-09-17 13:03:29 -0400 | [diff] [blame] | 129 | rx::Image *image = mTexture->getImage(index); |
Jamie Madill | 945f732 | 2014-09-03 15:07:14 -0400 | [diff] [blame] | 130 | return image->getActualFormat(); |
| 131 | } |
| 132 | |
Geoff Lang | 06ecf3d | 2014-09-23 16:39:50 -0400 | [diff] [blame] | 133 | Error Texture::generateMipmaps() |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 134 | { |
Geoff Lang | 06ecf3d | 2014-09-23 16:39:50 -0400 | [diff] [blame] | 135 | return getImplementation()->generateMipmaps(); |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Geoff Lang | ef7b016 | 2014-09-04 13:29:23 -0400 | [diff] [blame] | 138 | Error Texture::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, |
| 139 | GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) |
Brandon Jones | 6b19b00 | 2014-07-16 14:32:05 -0700 | [diff] [blame] | 140 | { |
Geoff Lang | ef7b016 | 2014-09-04 13:29:23 -0400 | [diff] [blame] | 141 | return mTexture->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, source); |
Brandon Jones | 6b19b00 | 2014-07-16 14:32:05 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Jamie Madill | 10ef215 | 2014-10-20 17:04:34 -0400 | [diff] [blame] | 144 | unsigned int Texture::getTextureSerial() const |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 145 | { |
Jamie Madill | 10ef215 | 2014-10-20 17:04:34 -0400 | [diff] [blame] | 146 | return mTextureSerial; |
| 147 | } |
| 148 | |
| 149 | unsigned int Texture::issueTextureSerial() |
| 150 | { |
| 151 | return mCurrentTextureSerial++; |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | bool Texture::isImmutable() const |
| 155 | { |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 156 | return (mImmutableLevelCount > 0); |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | int Texture::immutableLevelCount() |
| 160 | { |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 161 | return mImmutableLevelCount; |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | int Texture::mipLevels() const |
| 165 | { |
| 166 | return log2(std::max(std::max(getBaseLevelWidth(), getBaseLevelHeight()), getBaseLevelDepth())) + 1; |
| 167 | } |
| 168 | |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 169 | const rx::Image *Texture::getBaseLevelImage() const |
| 170 | { |
| 171 | return (getImplementation()->getLayerCount(0) > 0 ? getImplementation()->getImage(0, 0) : NULL); |
| 172 | } |
| 173 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 174 | Texture2D::Texture2D(rx::TextureImpl *impl, GLuint id) |
| 175 | : Texture(impl, id, GL_TEXTURE_2D) |
Jamie Madill | 22f843a | 2013-10-24 17:49:36 -0400 | [diff] [blame] | 176 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 177 | mSurface = NULL; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | Texture2D::~Texture2D() |
| 181 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 182 | if (mSurface) |
| 183 | { |
| 184 | mSurface->setBoundTexture(NULL); |
| 185 | mSurface = NULL; |
| 186 | } |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 187 | } |
daniel@transgaming.com | d9ec902 | 2012-12-20 20:52:16 +0000 | [diff] [blame] | 188 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 189 | GLsizei Texture2D::getWidth(GLint level) const |
| 190 | { |
| 191 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 192 | return mTexture->getImage(level, 0)->getWidth(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 193 | else |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | GLsizei Texture2D::getHeight(GLint level) const |
| 198 | { |
| 199 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 200 | return mTexture->getImage(level, 0)->getHeight(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 201 | else |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | GLenum Texture2D::getInternalFormat(GLint level) const |
| 206 | { |
| 207 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 208 | return mTexture->getImage(level, 0)->getInternalFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 209 | else |
| 210 | return GL_NONE; |
| 211 | } |
| 212 | |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 213 | GLenum Texture2D::getActualFormat(GLint level) const |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 214 | { |
| 215 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 216 | return mTexture->getImage(level, 0)->getActualFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 217 | else |
Geoff Lang | cbf727a | 2014-02-10 12:50:45 -0500 | [diff] [blame] | 218 | return GL_NONE; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 221 | Error Texture2D::setImage(GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 222 | { |
| 223 | releaseTexImage(); |
shannon.woods@transgaming.com | 8a40668 | 2013-02-28 23:15:26 +0000 | [diff] [blame] | 224 | |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 225 | return mTexture->setImage(GL_TEXTURE_2D, level, width, height, 1, internalFormat, format, type, unpack, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | void Texture2D::bindTexImage(egl::Surface *surface) |
| 229 | { |
| 230 | releaseTexImage(); |
| 231 | |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 232 | mTexture->bindTexImage(surface); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 233 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 234 | mSurface = surface; |
| 235 | mSurface->setBoundTexture(this); |
| 236 | } |
| 237 | |
| 238 | void Texture2D::releaseTexImage() |
| 239 | { |
| 240 | if (mSurface) |
| 241 | { |
| 242 | mSurface->setBoundTexture(NULL); |
| 243 | mSurface = NULL; |
| 244 | |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 245 | mTexture->releaseTexImage(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
Geoff Lang | b534833 | 2014-09-02 13:16:34 -0400 | [diff] [blame] | 249 | Error Texture2D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 250 | const PixelUnpackState &unpack, const void *pixels) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 251 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 252 | releaseTexImage(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 253 | |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 254 | return mTexture->setCompressedImage(GL_TEXTURE_2D, level, format, width, height, 1, imageSize, unpack, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 257 | Error Texture2D::subImage(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 258 | { |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 259 | return mTexture->subImage(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Geoff Lang | b534833 | 2014-09-02 13:16:34 -0400 | [diff] [blame] | 262 | Error Texture2D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 263 | GLenum format, GLsizei imageSize, const PixelUnpackState &unpack, const void *pixels) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 264 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 265 | return mTexture->subImageCompressed(GL_TEXTURE_2D, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, unpack, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Geoff Lang | ef7b016 | 2014-09-04 13:29:23 -0400 | [diff] [blame] | 268 | Error Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, |
| 269 | Framebuffer *source) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 270 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 271 | releaseTexImage(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 272 | |
Geoff Lang | ef7b016 | 2014-09-04 13:29:23 -0400 | [diff] [blame] | 273 | return mTexture->copyImage(GL_TEXTURE_2D, level, format, x, y, width, height, source); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 276 | Error Texture2D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 277 | { |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 278 | Error error = mTexture->storage(GL_TEXTURE_2D, levels, internalformat, width, height, 1); |
| 279 | if (error.isError()) |
| 280 | { |
| 281 | return error; |
| 282 | } |
| 283 | |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 284 | mImmutableLevelCount = levels; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 285 | |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 286 | return Error(GL_NO_ERROR); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 289 | // Tests for 2D texture sampling completeness. [OpenGL ES 2.0.24] section 3.8.2 page 85. |
| 290 | bool Texture2D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const |
| 291 | { |
| 292 | GLsizei width = getBaseLevelWidth(); |
| 293 | GLsizei height = getBaseLevelHeight(); |
| 294 | |
| 295 | if (width <= 0 || height <= 0) |
| 296 | { |
| 297 | return false; |
| 298 | } |
| 299 | |
| 300 | if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState)) |
| 301 | { |
| 302 | return false; |
| 303 | } |
| 304 | |
| 305 | bool npotSupport = extensions.textureNPOT; |
| 306 | |
| 307 | if (!npotSupport) |
| 308 | { |
| 309 | if ((samplerState.wrapS != GL_CLAMP_TO_EDGE && !gl::isPow2(width)) || |
| 310 | (samplerState.wrapT != GL_CLAMP_TO_EDGE && !gl::isPow2(height))) |
| 311 | { |
| 312 | return false; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | if (IsMipmapFiltered(samplerState)) |
| 317 | { |
| 318 | if (!npotSupport) |
| 319 | { |
| 320 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 321 | { |
| 322 | return false; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | if (!isMipmapComplete()) |
| 327 | { |
| 328 | return false; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | // OpenGLES 3.0.2 spec section 3.8.13 states that a texture is not mipmap complete if: |
| 333 | // The internalformat specified for the texture arrays is a sized internal depth or |
| 334 | // depth and stencil format (see table 3.13), the value of TEXTURE_COMPARE_- |
| 335 | // MODE is NONE, and either the magnification filter is not NEAREST or the mini- |
| 336 | // fication filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST. |
| 337 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(getInternalFormat(0)); |
| 338 | if (formatInfo.depthBits > 0 && clientVersion > 2) |
| 339 | { |
| 340 | if (samplerState.compareMode == GL_NONE) |
| 341 | { |
| 342 | if ((samplerState.minFilter != GL_NEAREST && samplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST) || |
| 343 | samplerState.magFilter != GL_NEAREST) |
| 344 | { |
| 345 | return false; |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | return true; |
| 351 | } |
| 352 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 353 | bool Texture2D::isCompressed(GLint level) const |
| 354 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 355 | return GetInternalFormatInfo(getInternalFormat(level)).compressed; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | bool Texture2D::isDepth(GLint level) const |
| 359 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 360 | return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Geoff Lang | 06ecf3d | 2014-09-23 16:39:50 -0400 | [diff] [blame] | 363 | Error Texture2D::generateMipmaps() |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 364 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 365 | releaseTexImage(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 366 | |
Geoff Lang | 06ecf3d | 2014-09-23 16:39:50 -0400 | [diff] [blame] | 367 | return mTexture->generateMipmaps(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 370 | // Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. |
| 371 | bool Texture2D::isMipmapComplete() const |
| 372 | { |
| 373 | int levelCount = mipLevels(); |
| 374 | |
| 375 | for (int level = 0; level < levelCount; level++) |
| 376 | { |
| 377 | if (!isLevelComplete(level)) |
| 378 | { |
| 379 | return false; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | bool Texture2D::isLevelComplete(int level) const |
| 387 | { |
| 388 | if (isImmutable()) |
| 389 | { |
| 390 | return true; |
| 391 | } |
| 392 | |
| 393 | const rx::Image *baseImage = getBaseLevelImage(); |
| 394 | |
| 395 | GLsizei width = baseImage->getWidth(); |
| 396 | GLsizei height = baseImage->getHeight(); |
| 397 | |
| 398 | if (width <= 0 || height <= 0) |
| 399 | { |
| 400 | return false; |
| 401 | } |
| 402 | |
| 403 | // The base image level is complete if the width and height are positive |
| 404 | if (level == 0) |
| 405 | { |
| 406 | return true; |
| 407 | } |
| 408 | |
| 409 | ASSERT(level >= 1 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL); |
| 410 | rx::Image *image = mTexture->getImage(level, 0); |
| 411 | |
| 412 | if (image->getInternalFormat() != baseImage->getInternalFormat()) |
| 413 | { |
| 414 | return false; |
| 415 | } |
| 416 | |
| 417 | if (image->getWidth() != std::max(1, width >> level)) |
| 418 | { |
| 419 | return false; |
| 420 | } |
| 421 | |
| 422 | if (image->getHeight() != std::max(1, height >> level)) |
| 423 | { |
| 424 | return false; |
| 425 | } |
| 426 | |
| 427 | return true; |
| 428 | } |
| 429 | |
| 430 | TextureCubeMap::TextureCubeMap(rx::TextureImpl *impl, GLuint id) |
| 431 | : Texture(impl, id, GL_TEXTURE_CUBE_MAP) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 432 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | TextureCubeMap::~TextureCubeMap() |
| 436 | { |
Brandon Jones | 0511e80 | 2014-07-14 16:27:26 -0700 | [diff] [blame] | 437 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 438 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 439 | GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const |
| 440 | { |
| 441 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 442 | return mTexture->getImage(level, targetToLayerIndex(target))->getWidth(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 443 | else |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | GLsizei TextureCubeMap::getHeight(GLenum target, GLint level) const |
| 448 | { |
| 449 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 450 | return mTexture->getImage(level, targetToLayerIndex(target))->getHeight(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 451 | else |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | GLenum TextureCubeMap::getInternalFormat(GLenum target, GLint level) const |
| 456 | { |
| 457 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 458 | return mTexture->getImage(level, targetToLayerIndex(target))->getInternalFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 459 | else |
| 460 | return GL_NONE; |
| 461 | } |
| 462 | |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 463 | GLenum TextureCubeMap::getActualFormat(GLenum target, GLint level) const |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 464 | { |
| 465 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 466 | return mTexture->getImage(level, targetToLayerIndex(target))->getActualFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 467 | else |
Geoff Lang | cbf727a | 2014-02-10 12:50:45 -0500 | [diff] [blame] | 468 | return GL_NONE; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Geoff Lang | 8376cea | 2014-09-02 11:47:07 -0400 | [diff] [blame] | 471 | Error TextureCubeMap::setImage(GLenum target, GLint level, GLsizei width, GLsizei height, GLenum internalFormat, GLenum format, GLenum type, const PixelUnpackState &unpack, const void *pixels) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 472 | { |
Geoff Lang | 8376cea | 2014-09-02 11:47:07 -0400 | [diff] [blame] | 473 | return mTexture->setImage(target, level, width, height, 1, internalFormat, format, type, unpack, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Geoff Lang | b534833 | 2014-09-02 13:16:34 -0400 | [diff] [blame] | 476 | Error TextureCubeMap::setCompressedImage(GLenum target, GLint level, GLenum format, GLsizei width, GLsizei height, |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 477 | GLsizei imageSize, const PixelUnpackState &unpack, const void *pixels) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 478 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 479 | return mTexture->setCompressedImage(target, level, format, width, height, 1, imageSize, unpack, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 482 | Error 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.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 483 | { |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 484 | return mTexture->subImage(target, level, xoffset, yoffset, 0, width, height, 1, format, type, unpack, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Geoff Lang | b534833 | 2014-09-02 13:16:34 -0400 | [diff] [blame] | 487 | Error TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 488 | GLsizei width, GLsizei height, GLenum format, |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 489 | GLsizei imageSize, const PixelUnpackState &unpack, const void *pixels) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 490 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 491 | return mTexture->subImageCompressed(target, level, xoffset, yoffset, 0, width, height, 1, format, imageSize, unpack, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 492 | } |
| 493 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 494 | // Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. |
| 495 | bool TextureCubeMap::isCubeComplete() const |
| 496 | { |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 497 | int baseWidth = getBaseLevelWidth(); |
| 498 | int baseHeight = getBaseLevelHeight(); |
| 499 | GLenum baseFormat = getBaseLevelInternalFormat(); |
| 500 | |
| 501 | if (baseWidth <= 0 || baseWidth != baseHeight) |
| 502 | { |
| 503 | return false; |
| 504 | } |
| 505 | |
| 506 | for (int faceIndex = 1; faceIndex < 6; faceIndex++) |
| 507 | { |
| 508 | const rx::Image *faceBaseImage = mTexture->getImage(0, faceIndex); |
| 509 | |
| 510 | if (faceBaseImage->getWidth() != baseWidth || |
| 511 | faceBaseImage->getHeight() != baseHeight || |
| 512 | faceBaseImage->getInternalFormat() != baseFormat ) |
| 513 | { |
| 514 | return false; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | return true; |
Jamie Madill | 07edd44 | 2013-07-19 16:36:58 -0400 | [diff] [blame] | 519 | } |
| 520 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 521 | bool TextureCubeMap::isCompressed(GLenum target, GLint level) const |
| 522 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 523 | return GetInternalFormatInfo(getInternalFormat(target, level)).compressed; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 526 | bool TextureCubeMap::isDepth(GLenum target, GLint level) const |
| 527 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 528 | return GetInternalFormatInfo(getInternalFormat(target, level)).depthBits > 0; |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 529 | } |
| 530 | |
Geoff Lang | ef7b016 | 2014-09-04 13:29:23 -0400 | [diff] [blame] | 531 | Error TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, |
| 532 | GLsizei width, GLsizei height, Framebuffer *source) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 533 | { |
Geoff Lang | ef7b016 | 2014-09-04 13:29:23 -0400 | [diff] [blame] | 534 | return mTexture->copyImage(target, level, format, x, y, width, height, source); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 537 | Error TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 538 | { |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 539 | Error error = mTexture->storage(GL_TEXTURE_CUBE_MAP, levels, internalformat, size, size, 1); |
| 540 | if (error.isError()) |
| 541 | { |
| 542 | return error; |
| 543 | } |
| 544 | |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 545 | mImmutableLevelCount = levels; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 546 | |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 547 | return Error(GL_NO_ERROR); |
Jamie Madill | 2ebab85 | 2013-10-24 17:49:42 -0400 | [diff] [blame] | 548 | } |
| 549 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 550 | // Tests for texture sampling completeness |
| 551 | bool 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 | |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 588 | int TextureCubeMap::targetToLayerIndex(GLenum target) |
| 589 | { |
| 590 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1); |
| 591 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2); |
| 592 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3); |
| 593 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4); |
| 594 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5); |
| 595 | |
| 596 | return target - GL_TEXTURE_CUBE_MAP_POSITIVE_X; |
| 597 | } |
| 598 | |
| 599 | GLenum TextureCubeMap::layerIndexToTarget(GLint layer) |
| 600 | { |
| 601 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1); |
| 602 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2); |
| 603 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3); |
| 604 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4); |
| 605 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5); |
| 606 | |
| 607 | return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 608 | } |
| 609 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 610 | bool TextureCubeMap::isMipmapComplete() const |
| 611 | { |
| 612 | if (isImmutable()) |
| 613 | { |
| 614 | return true; |
| 615 | } |
| 616 | |
| 617 | if (!isCubeComplete()) |
| 618 | { |
| 619 | return false; |
| 620 | } |
| 621 | |
| 622 | int levelCount = mipLevels(); |
| 623 | |
| 624 | for (int face = 0; face < 6; face++) |
| 625 | { |
| 626 | for (int level = 1; level < levelCount; level++) |
| 627 | { |
| 628 | if (!isFaceLevelComplete(face, level)) |
| 629 | { |
| 630 | return false; |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | return true; |
| 636 | } |
| 637 | |
| 638 | bool TextureCubeMap::isFaceLevelComplete(int faceIndex, int level) const |
| 639 | { |
| 640 | ASSERT(level >= 0 && faceIndex < 6 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, faceIndex) != NULL); |
| 641 | |
| 642 | if (isImmutable()) |
| 643 | { |
| 644 | return true; |
| 645 | } |
| 646 | |
| 647 | int baseSize = getBaseLevelWidth(); |
| 648 | |
| 649 | if (baseSize <= 0) |
| 650 | { |
| 651 | return false; |
| 652 | } |
| 653 | |
| 654 | // "isCubeComplete" checks for base level completeness and we must call that |
| 655 | // to determine if any face at level 0 is complete. We omit that check here |
| 656 | // to avoid re-checking cube-completeness for every face at level 0. |
| 657 | if (level == 0) |
| 658 | { |
| 659 | return true; |
| 660 | } |
| 661 | |
| 662 | // Check that non-zero levels are consistent with the base level. |
| 663 | const rx::Image *faceLevelImage = mTexture->getImage(level, faceIndex); |
| 664 | |
| 665 | if (faceLevelImage->getInternalFormat() != getBaseLevelInternalFormat()) |
| 666 | { |
| 667 | return false; |
| 668 | } |
| 669 | |
| 670 | if (faceLevelImage->getWidth() != std::max(1, baseSize >> level)) |
| 671 | { |
| 672 | return false; |
| 673 | } |
| 674 | |
| 675 | return true; |
| 676 | } |
| 677 | |
| 678 | |
| 679 | Texture3D::Texture3D(rx::TextureImpl *impl, GLuint id) |
| 680 | : Texture(impl, id, GL_TEXTURE_3D) |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 681 | { |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | Texture3D::~Texture3D() |
| 685 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 686 | } |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 687 | |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 688 | GLsizei Texture3D::getWidth(GLint level) const |
| 689 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 690 | return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getWidth() : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | GLsizei Texture3D::getHeight(GLint level) const |
| 694 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 695 | return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getHeight() : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | GLsizei Texture3D::getDepth(GLint level) const |
| 699 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 700 | return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getDepth() : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | GLenum Texture3D::getInternalFormat(GLint level) const |
| 704 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 705 | return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | GLenum Texture3D::getActualFormat(GLint level) const |
| 709 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 710 | return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getActualFormat() : GL_NONE; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | bool Texture3D::isCompressed(GLint level) const |
| 714 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 715 | return GetInternalFormatInfo(getInternalFormat(level)).compressed; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | bool Texture3D::isDepth(GLint level) const |
| 719 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 720 | return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 723 | Error 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.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 724 | { |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 725 | return mTexture->setImage(GL_TEXTURE_3D, level, width, height, depth, internalFormat, format, type, unpack, pixels); |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Geoff Lang | b534833 | 2014-09-02 13:16:34 -0400 | [diff] [blame] | 728 | Error Texture3D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 729 | GLsizei imageSize, const PixelUnpackState &unpack, const void *pixels) |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 730 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 731 | return mTexture->setCompressedImage(GL_TEXTURE_3D, level, format, width, height, depth, imageSize, unpack, pixels); |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 732 | } |
| 733 | |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 734 | Error 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.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 735 | { |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 736 | return mTexture->subImage(GL_TEXTURE_3D, level, xoffset, yoffset, zoffset, width, height, depth, format, type, unpack, pixels); |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 737 | } |
| 738 | |
Geoff Lang | b534833 | 2014-09-02 13:16:34 -0400 | [diff] [blame] | 739 | Error Texture3D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, |
| 740 | GLsizei width, GLsizei height, GLsizei depth, GLenum format, |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 741 | GLsizei imageSize, const PixelUnpackState &unpack, const void *pixels) |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 742 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 743 | return mTexture->subImageCompressed(GL_TEXTURE_3D, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, unpack, pixels); |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 746 | Error Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 747 | { |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 748 | Error error = mTexture->storage(GL_TEXTURE_3D, levels, internalformat, width, height, depth); |
| 749 | if (error.isError()) |
| 750 | { |
| 751 | return error; |
| 752 | } |
| 753 | |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 754 | mImmutableLevelCount = levels; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 755 | |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 756 | return Error(GL_NO_ERROR); |
Jamie Madill | 2ebab85 | 2013-10-24 17:49:42 -0400 | [diff] [blame] | 757 | } |
| 758 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 759 | bool Texture3D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const |
| 760 | { |
| 761 | GLsizei width = getBaseLevelWidth(); |
| 762 | GLsizei height = getBaseLevelHeight(); |
| 763 | GLsizei depth = getBaseLevelDepth(); |
| 764 | |
| 765 | if (width <= 0 || height <= 0 || depth <= 0) |
| 766 | { |
| 767 | return false; |
| 768 | } |
| 769 | |
| 770 | if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState)) |
| 771 | { |
| 772 | return false; |
| 773 | } |
| 774 | |
| 775 | if (IsMipmapFiltered(samplerState) && !isMipmapComplete()) |
| 776 | { |
| 777 | return false; |
| 778 | } |
| 779 | |
| 780 | return true; |
| 781 | } |
| 782 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 783 | bool Texture3D::isMipmapComplete() const |
| 784 | { |
| 785 | int levelCount = mipLevels(); |
| 786 | |
| 787 | for (int level = 0; level < levelCount; level++) |
| 788 | { |
| 789 | if (!isLevelComplete(level)) |
| 790 | { |
| 791 | return false; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | return true; |
| 796 | } |
| 797 | |
| 798 | bool Texture3D::isLevelComplete(int level) const |
| 799 | { |
| 800 | ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL); |
| 801 | |
| 802 | if (isImmutable()) |
| 803 | { |
| 804 | return true; |
| 805 | } |
| 806 | |
| 807 | GLsizei width = getBaseLevelWidth(); |
| 808 | GLsizei height = getBaseLevelHeight(); |
| 809 | GLsizei depth = getBaseLevelDepth(); |
| 810 | |
| 811 | if (width <= 0 || height <= 0 || depth <= 0) |
| 812 | { |
| 813 | return false; |
| 814 | } |
| 815 | |
| 816 | if (level == 0) |
| 817 | { |
| 818 | return true; |
| 819 | } |
| 820 | |
| 821 | rx::Image *levelImage = mTexture->getImage(level, 0); |
| 822 | |
| 823 | if (levelImage->getInternalFormat() != getBaseLevelInternalFormat()) |
| 824 | { |
| 825 | return false; |
| 826 | } |
| 827 | |
| 828 | if (levelImage->getWidth() != std::max(1, width >> level)) |
| 829 | { |
| 830 | return false; |
| 831 | } |
| 832 | |
| 833 | if (levelImage->getHeight() != std::max(1, height >> level)) |
| 834 | { |
| 835 | return false; |
| 836 | } |
| 837 | |
| 838 | if (levelImage->getDepth() != std::max(1, depth >> level)) |
| 839 | { |
| 840 | return false; |
| 841 | } |
| 842 | |
| 843 | return true; |
| 844 | } |
| 845 | |
| 846 | Texture2DArray::Texture2DArray(rx::TextureImpl *impl, GLuint id) |
| 847 | : Texture(impl, id, GL_TEXTURE_2D_ARRAY) |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 848 | { |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | Texture2DArray::~Texture2DArray() |
| 852 | { |
Jamie Madill | 884a462 | 2013-10-24 17:49:41 -0400 | [diff] [blame] | 853 | } |
| 854 | |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 855 | GLsizei Texture2DArray::getWidth(GLint level) const |
| 856 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 857 | return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getWidth() : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | GLsizei Texture2DArray::getHeight(GLint level) const |
| 861 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 862 | return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getHeight() : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Jamie Madill | b8f8b89 | 2014-01-07 10:12:50 -0500 | [diff] [blame] | 865 | GLsizei Texture2DArray::getLayers(GLint level) const |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 866 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 867 | return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getLayerCount(level) : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | GLenum Texture2DArray::getInternalFormat(GLint level) const |
| 871 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 872 | return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | GLenum Texture2DArray::getActualFormat(GLint level) const |
| 876 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 877 | return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getActualFormat() : GL_NONE; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | bool Texture2DArray::isCompressed(GLint level) const |
| 881 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 882 | return GetInternalFormatInfo(getInternalFormat(level)).compressed; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | bool Texture2DArray::isDepth(GLint level) const |
| 886 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 887 | return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 890 | Error 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.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 891 | { |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 892 | return mTexture->setImage(GL_TEXTURE_2D_ARRAY, level, width, height, depth, internalFormat, format, type, unpack, pixels); |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Geoff Lang | b534833 | 2014-09-02 13:16:34 -0400 | [diff] [blame] | 895 | Error Texture2DArray::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 896 | GLsizei imageSize, const PixelUnpackState &unpack, const void *pixels) |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 897 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 898 | return mTexture->setCompressedImage(GL_TEXTURE_2D_ARRAY, level, format, width, height, depth, imageSize, unpack, pixels); |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 901 | Error 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.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 902 | { |
Geoff Lang | 1ba6b8d | 2014-08-28 10:57:31 -0400 | [diff] [blame] | 903 | return mTexture->subImage(GL_TEXTURE_2D_ARRAY, level, xoffset, yoffset, zoffset, width, height, depth, format, type, unpack, pixels); |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Geoff Lang | b534833 | 2014-09-02 13:16:34 -0400 | [diff] [blame] | 906 | Error Texture2DArray::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, |
| 907 | GLsizei width, GLsizei height, GLsizei depth, GLenum format, |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 908 | GLsizei imageSize, const PixelUnpackState &unpack, const void *pixels) |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 909 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 910 | return mTexture->subImageCompressed(GL_TEXTURE_2D_ARRAY, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, unpack, pixels); |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 913 | Error Texture2DArray::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 914 | { |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 915 | Error error = mTexture->storage(GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, depth); |
| 916 | if (error.isError()) |
| 917 | { |
| 918 | return error; |
| 919 | } |
| 920 | |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 921 | mImmutableLevelCount = levels; |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 922 | |
Geoff Lang | 1f8532b | 2014-09-05 09:46:13 -0400 | [diff] [blame] | 923 | return Error(GL_NO_ERROR); |
Jamie Madill | 2ebab85 | 2013-10-24 17:49:42 -0400 | [diff] [blame] | 924 | } |
| 925 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 926 | bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const |
| 927 | { |
| 928 | GLsizei width = getBaseLevelWidth(); |
| 929 | GLsizei height = getBaseLevelHeight(); |
| 930 | GLsizei depth = getLayers(0); |
| 931 | |
| 932 | if (width <= 0 || height <= 0 || depth <= 0) |
| 933 | { |
| 934 | return false; |
| 935 | } |
| 936 | |
| 937 | if (!textureCaps.get(getBaseLevelInternalFormat()).filterable && !IsPointSampled(samplerState)) |
| 938 | { |
| 939 | return false; |
| 940 | } |
| 941 | |
| 942 | if (IsMipmapFiltered(samplerState) && !isMipmapComplete()) |
| 943 | { |
| 944 | return false; |
| 945 | } |
| 946 | |
| 947 | return true; |
| 948 | } |
| 949 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 950 | bool Texture2DArray::isMipmapComplete() const |
| 951 | { |
| 952 | int levelCount = mipLevels(); |
| 953 | |
| 954 | for (int level = 1; level < levelCount; level++) |
| 955 | { |
| 956 | if (!isLevelComplete(level)) |
| 957 | { |
| 958 | return false; |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | return true; |
| 963 | } |
| 964 | |
| 965 | bool Texture2DArray::isLevelComplete(int level) const |
| 966 | { |
| 967 | ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS); |
| 968 | |
| 969 | if (isImmutable()) |
| 970 | { |
| 971 | return true; |
| 972 | } |
| 973 | |
| 974 | GLsizei width = getBaseLevelWidth(); |
| 975 | GLsizei height = getBaseLevelHeight(); |
| 976 | GLsizei layers = getLayers(0); |
| 977 | |
| 978 | if (width <= 0 || height <= 0 || layers <= 0) |
| 979 | { |
| 980 | return false; |
| 981 | } |
| 982 | |
| 983 | if (level == 0) |
| 984 | { |
| 985 | return true; |
| 986 | } |
| 987 | |
| 988 | if (getInternalFormat(level) != getInternalFormat(0)) |
| 989 | { |
| 990 | return false; |
| 991 | } |
| 992 | |
| 993 | if (getWidth(level) != std::max(1, width >> level)) |
| 994 | { |
| 995 | return false; |
| 996 | } |
| 997 | |
| 998 | if (getHeight(level) != std::max(1, height >> level)) |
| 999 | { |
| 1000 | return false; |
| 1001 | } |
| 1002 | |
| 1003 | if (getLayers(level) != layers) |
| 1004 | { |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
| 1008 | return true; |
| 1009 | } |
| 1010 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 1011 | } |