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), |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame^] | 57 | mTarget(target), |
| 58 | mBoundSurface(NULL) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 59 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | Texture::~Texture() |
| 63 | { |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame^] | 64 | if (mBoundSurface) |
| 65 | { |
| 66 | mBoundSurface->releaseTexImage(EGL_BACK_BUFFER); |
| 67 | mBoundSurface = NULL; |
| 68 | } |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 69 | SafeDelete(mTexture); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Geoff Lang | 4907f2c | 2013-07-25 12:53:57 -0400 | [diff] [blame] | 72 | GLenum Texture::getTarget() const |
| 73 | { |
| 74 | return mTarget; |
| 75 | } |
| 76 | |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 77 | void Texture::setUsage(GLenum usage) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 78 | { |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 79 | mUsage = usage; |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 80 | getImplementation()->setUsage(usage); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 81 | } |
| 82 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 83 | GLenum Texture::getUsage() const |
| 84 | { |
| 85 | return mUsage; |
| 86 | } |
| 87 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 88 | size_t Texture::getWidth(GLenum target, size_t level) const |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 89 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 90 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 91 | return getImageDesc(ImageIdentifier(target, level)).size.width; |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 92 | } |
| 93 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 94 | size_t Texture::getHeight(GLenum target, size_t level) const |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 95 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 96 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 97 | return getImageDesc(ImageIdentifier(target, level)).size.height; |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 100 | size_t Texture::getDepth(GLenum target, size_t level) const |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 101 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 102 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 103 | return getImageDesc(ImageIdentifier(target, level)).size.depth; |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 106 | GLenum Texture::getInternalFormat(GLenum target, size_t level) const |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 107 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 108 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 109 | return getImageDesc(ImageIdentifier(target, level)).internalFormat; |
Jamie Madill | 945f732 | 2014-09-03 15:07:14 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Jamie Madill | 10ef215 | 2014-10-20 17:04:34 -0400 | [diff] [blame] | 112 | unsigned int Texture::getTextureSerial() const |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 113 | { |
Jamie Madill | 10ef215 | 2014-10-20 17:04:34 -0400 | [diff] [blame] | 114 | return mTextureSerial; |
| 115 | } |
| 116 | |
| 117 | unsigned int Texture::issueTextureSerial() |
| 118 | { |
| 119 | return mCurrentTextureSerial++; |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | bool Texture::isImmutable() const |
| 123 | { |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 124 | return (mImmutableLevelCount > 0); |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | int Texture::immutableLevelCount() |
| 128 | { |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 129 | return mImmutableLevelCount; |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 132 | Error Texture::setImage(GLenum target, size_t level, GLenum internalFormat, const Extents &size, GLenum format, GLenum type, |
| 133 | const PixelUnpackState &unpack, const uint8_t *pixels) |
| 134 | { |
| 135 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 136 | |
| 137 | Error error = mTexture->setImage(target, level, internalFormat, size, format, type, unpack, pixels); |
| 138 | if (error.isError()) |
| 139 | { |
| 140 | return error; |
| 141 | } |
| 142 | |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame^] | 143 | releaseTexImage(); |
| 144 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 145 | setImageDesc(ImageIdentifier(target, level), ImageDesc(size, GetSizedInternalFormat(internalFormat, type))); |
| 146 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 147 | return Error(GL_NO_ERROR); |
| 148 | } |
| 149 | |
| 150 | Error Texture::setSubImage(GLenum target, size_t level, const Box &area, GLenum format, GLenum type, |
| 151 | const PixelUnpackState &unpack, const uint8_t *pixels) |
| 152 | { |
| 153 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 154 | |
| 155 | return mTexture->setSubImage(target, level, area, format, type, unpack, pixels); |
| 156 | } |
| 157 | |
| 158 | Error Texture::setCompressedImage(GLenum target, size_t level, GLenum internalFormat, const Extents &size, |
| 159 | const PixelUnpackState &unpack, const uint8_t *pixels) |
| 160 | { |
| 161 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 162 | |
| 163 | Error error = mTexture->setCompressedImage(target, level, internalFormat, size, unpack, pixels); |
| 164 | if (error.isError()) |
| 165 | { |
| 166 | return error; |
| 167 | } |
| 168 | |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame^] | 169 | releaseTexImage(); |
| 170 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 171 | setImageDesc(ImageIdentifier(target, level), ImageDesc(size, GetSizedInternalFormat(internalFormat, GL_UNSIGNED_BYTE))); |
| 172 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 173 | return Error(GL_NO_ERROR); |
| 174 | } |
| 175 | |
| 176 | Error Texture::setCompressedSubImage(GLenum target, size_t level, const Box &area, GLenum format, |
| 177 | const PixelUnpackState &unpack, const uint8_t *pixels) |
| 178 | { |
| 179 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 180 | |
| 181 | return mTexture->setCompressedSubImage(target, level, area, format, unpack, pixels); |
| 182 | } |
| 183 | |
| 184 | Error Texture::copyImage(GLenum target, size_t level, const Rectangle &sourceArea, GLenum internalFormat, |
| 185 | const Framebuffer *source) |
| 186 | { |
| 187 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 188 | |
| 189 | Error error = mTexture->copyImage(target, level, sourceArea, internalFormat, source); |
| 190 | if (error.isError()) |
| 191 | { |
| 192 | return error; |
| 193 | } |
| 194 | |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame^] | 195 | releaseTexImage(); |
| 196 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 197 | setImageDesc(ImageIdentifier(target, level), ImageDesc(Extents(sourceArea.width, sourceArea.height, 1), |
| 198 | GetSizedInternalFormat(internalFormat, GL_UNSIGNED_BYTE))); |
| 199 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 200 | return Error(GL_NO_ERROR); |
| 201 | } |
| 202 | |
| 203 | Error Texture::copySubImage(GLenum target, size_t level, const Offset &destOffset, const Rectangle &sourceArea, |
| 204 | const Framebuffer *source) |
| 205 | { |
| 206 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 207 | |
| 208 | return mTexture->copySubImage(target, level, destOffset, sourceArea, source); |
| 209 | } |
| 210 | |
| 211 | Error Texture::setStorage(GLenum target, size_t levels, GLenum internalFormat, const Extents &size) |
| 212 | { |
| 213 | ASSERT(target == mTarget); |
| 214 | |
| 215 | Error error = mTexture->setStorage(target, levels, internalFormat, size); |
| 216 | if (error.isError()) |
| 217 | { |
| 218 | return error; |
| 219 | } |
| 220 | |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame^] | 221 | releaseTexImage(); |
| 222 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 223 | mImmutableLevelCount = levels; |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 224 | clearImageDescs(); |
| 225 | setImageDescChain(levels, size, internalFormat); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 226 | |
| 227 | return Error(GL_NO_ERROR); |
| 228 | } |
| 229 | |
| 230 | |
| 231 | Error Texture::generateMipmaps() |
| 232 | { |
| 233 | Error error = mTexture->generateMipmaps(); |
| 234 | if (error.isError()) |
| 235 | { |
| 236 | return error; |
| 237 | } |
| 238 | |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame^] | 239 | releaseTexImage(); |
| 240 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 241 | ImageIdentifier baseLevel(mTarget == GL_TEXTURE_CUBE_MAP ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : mTarget, 0); |
| 242 | const ImageDesc &baseImageInfo = getImageDesc(baseLevel); |
| 243 | size_t mipLevels = log2(std::max(std::max(baseImageInfo.size.width, baseImageInfo.size.height), baseImageInfo.size.depth)) + 1; |
| 244 | setImageDescChain(mipLevels, baseImageInfo.size, baseImageInfo.internalFormat); |
| 245 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 246 | return Error(GL_NO_ERROR); |
| 247 | } |
| 248 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 249 | void Texture::setImageDescChain(size_t levels, Extents baseSize, GLenum sizedInternalFormat) |
| 250 | { |
| 251 | for (size_t level = 0; level < levels; level++) |
| 252 | { |
| 253 | Extents levelSize(std::max<size_t>(baseSize.width >> level, 1), |
| 254 | std::max<size_t>(baseSize.height >> level, 1), |
| 255 | (mTarget == GL_TEXTURE_2D_ARRAY) ? baseSize.depth : std::max<size_t>(baseSize.depth >> level, 1)); |
| 256 | ImageDesc levelInfo(levelSize, sizedInternalFormat); |
| 257 | |
| 258 | if (mTarget == GL_TEXTURE_CUBE_MAP) |
| 259 | { |
| 260 | for (size_t face = GL_TEXTURE_CUBE_MAP_POSITIVE_X; face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; face++) |
| 261 | { |
| 262 | setImageDesc(ImageIdentifier(face, level), levelInfo); |
| 263 | } |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | setImageDesc(ImageIdentifier(mTarget, level), levelInfo); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | Texture::ImageIdentifier::ImageIdentifier() |
| 273 | : ImageIdentifier(GL_TEXTURE_2D, 0) |
| 274 | { |
| 275 | } |
| 276 | |
| 277 | Texture::ImageIdentifier::ImageIdentifier(GLenum target, size_t level) |
| 278 | : target(target), |
| 279 | level(level) |
| 280 | { |
| 281 | } |
| 282 | |
| 283 | bool Texture::ImageIdentifier::operator<(const ImageIdentifier &other) const |
| 284 | { |
| 285 | return (target != other.target) ? target < other.target : level < other.level; |
| 286 | } |
| 287 | |
| 288 | Texture::ImageDesc::ImageDesc() |
| 289 | : ImageDesc(Extents(0, 0, 0), GL_NONE) |
| 290 | { |
| 291 | } |
| 292 | |
| 293 | Texture::ImageDesc::ImageDesc(const Extents &size, GLenum internalFormat) |
| 294 | : size(size), |
| 295 | internalFormat(internalFormat) |
| 296 | { |
| 297 | } |
| 298 | |
| 299 | const Texture::ImageDesc &Texture::getImageDesc(const ImageIdentifier& index) const |
| 300 | { |
| 301 | static const Texture::ImageDesc defaultDesc; |
| 302 | ImageDescMap::const_iterator iter = mImageDescs.find(index); |
| 303 | return (iter != mImageDescs.end()) ? iter->second : defaultDesc; |
| 304 | } |
| 305 | |
| 306 | void Texture::setImageDesc(const ImageIdentifier& index, const ImageDesc &desc) |
| 307 | { |
| 308 | mImageDescs[index] = desc; |
| 309 | } |
| 310 | |
| 311 | void Texture::clearImageDescs() |
| 312 | { |
| 313 | mImageDescs.clear(); |
| 314 | } |
| 315 | |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame^] | 316 | void Texture::bindTexImage(egl::Surface *surface) |
| 317 | { |
| 318 | releaseTexImage(); |
| 319 | mTexture->bindTexImage(surface); |
| 320 | mBoundSurface = surface; |
| 321 | } |
| 322 | |
| 323 | void Texture::releaseTexImage() |
| 324 | { |
| 325 | if (mBoundSurface) |
| 326 | { |
| 327 | mBoundSurface = NULL; |
| 328 | mTexture->releaseTexImage(); |
| 329 | } |
| 330 | } |
| 331 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 332 | Texture2D::Texture2D(rx::TextureImpl *impl, GLuint id) |
| 333 | : Texture(impl, id, GL_TEXTURE_2D) |
Jamie Madill | 22f843a | 2013-10-24 17:49:36 -0400 | [diff] [blame] | 334 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | Texture2D::~Texture2D() |
| 338 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 341 | // Tests for 2D texture sampling completeness. [OpenGL ES 2.0.24] section 3.8.2 page 85. |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 342 | bool Texture2D::isSamplerComplete(const SamplerState &samplerState, const Data &data) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 343 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 344 | size_t width = getWidth(GL_TEXTURE_2D, 0); |
| 345 | size_t height = getHeight(GL_TEXTURE_2D, 0); |
| 346 | if (width == 0 || height == 0) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 347 | { |
| 348 | return false; |
| 349 | } |
| 350 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 351 | GLenum internalFormat = getInternalFormat(GL_TEXTURE_2D, 0); |
| 352 | if (!data.textureCaps->get(internalFormat).filterable && !IsPointSampled(samplerState)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 353 | { |
| 354 | return false; |
| 355 | } |
| 356 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 357 | bool npotSupport = data.extensions->textureNPOT; |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 358 | if (!npotSupport) |
| 359 | { |
| 360 | if ((samplerState.wrapS != GL_CLAMP_TO_EDGE && !gl::isPow2(width)) || |
| 361 | (samplerState.wrapT != GL_CLAMP_TO_EDGE && !gl::isPow2(height))) |
| 362 | { |
| 363 | return false; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if (IsMipmapFiltered(samplerState)) |
| 368 | { |
| 369 | if (!npotSupport) |
| 370 | { |
| 371 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 372 | { |
| 373 | return false; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | if (!isMipmapComplete()) |
| 378 | { |
| 379 | return false; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | // OpenGLES 3.0.2 spec section 3.8.13 states that a texture is not mipmap complete if: |
| 384 | // The internalformat specified for the texture arrays is a sized internal depth or |
| 385 | // depth and stencil format (see table 3.13), the value of TEXTURE_COMPARE_- |
| 386 | // MODE is NONE, and either the magnification filter is not NEAREST or the mini- |
| 387 | // fication filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST. |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 388 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 389 | if (formatInfo.depthBits > 0 && data.clientVersion > 2) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 390 | { |
| 391 | if (samplerState.compareMode == GL_NONE) |
| 392 | { |
| 393 | if ((samplerState.minFilter != GL_NEAREST && samplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST) || |
| 394 | samplerState.magFilter != GL_NEAREST) |
| 395 | { |
| 396 | return false; |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | return true; |
| 402 | } |
| 403 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 404 | // Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. |
| 405 | bool Texture2D::isMipmapComplete() const |
| 406 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 407 | size_t width = getWidth(GL_TEXTURE_2D, 0); |
| 408 | size_t height = getHeight(GL_TEXTURE_2D, 0); |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 409 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 410 | size_t expectedMipLevels = log2(std::max(width, height)) + 1; |
| 411 | for (size_t level = 0; level < expectedMipLevels; level++) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 412 | { |
| 413 | if (!isLevelComplete(level)) |
| 414 | { |
| 415 | return false; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | return true; |
| 420 | } |
| 421 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 422 | bool Texture2D::isLevelComplete(size_t level) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 423 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 424 | ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS); |
| 425 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 426 | if (isImmutable()) |
| 427 | { |
| 428 | return true; |
| 429 | } |
| 430 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 431 | size_t width = getWidth(GL_TEXTURE_2D, 0); |
| 432 | size_t height = getHeight(GL_TEXTURE_2D, 0); |
| 433 | if (width == 0 || height == 0) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 434 | { |
| 435 | return false; |
| 436 | } |
| 437 | |
| 438 | // The base image level is complete if the width and height are positive |
| 439 | if (level == 0) |
| 440 | { |
| 441 | return true; |
| 442 | } |
| 443 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 444 | if (getInternalFormat(GL_TEXTURE_2D, level) != getInternalFormat(GL_TEXTURE_2D, 0)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 445 | { |
| 446 | return false; |
| 447 | } |
| 448 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 449 | if (getWidth(GL_TEXTURE_2D, level) != std::max<size_t>(1, width >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 450 | { |
| 451 | return false; |
| 452 | } |
| 453 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 454 | if (getHeight(GL_TEXTURE_2D, level) != std::max<size_t>(1, height >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 455 | { |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | return true; |
| 460 | } |
| 461 | |
| 462 | TextureCubeMap::TextureCubeMap(rx::TextureImpl *impl, GLuint id) |
| 463 | : Texture(impl, id, GL_TEXTURE_CUBE_MAP) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 464 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | TextureCubeMap::~TextureCubeMap() |
| 468 | { |
Brandon Jones | 0511e80 | 2014-07-14 16:27:26 -0700 | [diff] [blame] | 469 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 470 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 471 | // Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. |
| 472 | bool TextureCubeMap::isCubeComplete() const |
| 473 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 474 | size_t width = getWidth(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
| 475 | size_t height = getWidth(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
| 476 | if (width == 0 || width != height) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 477 | { |
| 478 | return false; |
| 479 | } |
| 480 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 481 | GLenum internalFormat = getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
| 482 | for (GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + 1; face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; face++) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 483 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 484 | if (getWidth(face, 0) != width || |
| 485 | getHeight(face, 0) != height || |
| 486 | getInternalFormat(face, 0) != internalFormat) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 487 | { |
| 488 | return false; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | return true; |
Jamie Madill | 07edd44 | 2013-07-19 16:36:58 -0400 | [diff] [blame] | 493 | } |
| 494 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 495 | // Tests for texture sampling completeness |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 496 | bool TextureCubeMap::isSamplerComplete(const SamplerState &samplerState, const Data &data) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 497 | { |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 498 | bool mipmapping = IsMipmapFiltered(samplerState); |
| 499 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 500 | GLenum internalFormat = getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
| 501 | if (!data.textureCaps->get(internalFormat).filterable && !IsPointSampled(samplerState)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 502 | { |
| 503 | return false; |
| 504 | } |
| 505 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 506 | size_t size = getWidth(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0); |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 507 | if (!gl::isPow2(size) && !data.extensions->textureNPOT) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 508 | { |
| 509 | if (samplerState.wrapS != GL_CLAMP_TO_EDGE || samplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping) |
| 510 | { |
| 511 | return false; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | if (!mipmapping) |
| 516 | { |
| 517 | if (!isCubeComplete()) |
| 518 | { |
| 519 | return false; |
| 520 | } |
| 521 | } |
| 522 | else |
| 523 | { |
| 524 | if (!isMipmapComplete()) // Also tests for isCubeComplete() |
| 525 | { |
| 526 | return false; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | return true; |
| 531 | } |
| 532 | |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 533 | int TextureCubeMap::targetToLayerIndex(GLenum target) |
| 534 | { |
| 535 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1); |
| 536 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2); |
| 537 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3); |
| 538 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4); |
| 539 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5); |
| 540 | |
| 541 | return target - GL_TEXTURE_CUBE_MAP_POSITIVE_X; |
| 542 | } |
| 543 | |
| 544 | GLenum TextureCubeMap::layerIndexToTarget(GLint layer) |
| 545 | { |
| 546 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1); |
| 547 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2); |
| 548 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3); |
| 549 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4); |
| 550 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5); |
| 551 | |
| 552 | return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 553 | } |
| 554 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 555 | bool TextureCubeMap::isMipmapComplete() const |
| 556 | { |
| 557 | if (isImmutable()) |
| 558 | { |
| 559 | return true; |
| 560 | } |
| 561 | |
| 562 | if (!isCubeComplete()) |
| 563 | { |
| 564 | return false; |
| 565 | } |
| 566 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 567 | size_t width = getWidth(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0); |
| 568 | size_t height = getHeight(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0); |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 569 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 570 | size_t expectedMipLevels = log2(std::max(width, height)) + 1; |
| 571 | for (GLenum face = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; face++) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 572 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 573 | for (size_t level = 1; level < expectedMipLevels; level++) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 574 | { |
| 575 | if (!isFaceLevelComplete(face, level)) |
| 576 | { |
| 577 | return false; |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | return true; |
| 583 | } |
| 584 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 585 | bool TextureCubeMap::isFaceLevelComplete(GLenum target, size_t level) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 586 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 587 | ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && IsCubemapTextureTarget(target)); |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 588 | |
| 589 | if (isImmutable()) |
| 590 | { |
| 591 | return true; |
| 592 | } |
| 593 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 594 | size_t baseSize = getWidth(target, 0); |
| 595 | if (baseSize == 0) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 596 | { |
| 597 | return false; |
| 598 | } |
| 599 | |
| 600 | // "isCubeComplete" checks for base level completeness and we must call that |
| 601 | // to determine if any face at level 0 is complete. We omit that check here |
| 602 | // to avoid re-checking cube-completeness for every face at level 0. |
| 603 | if (level == 0) |
| 604 | { |
| 605 | return true; |
| 606 | } |
| 607 | |
| 608 | // Check that non-zero levels are consistent with the base level. |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 609 | if (getInternalFormat(target, level) != getInternalFormat(target, 0)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 610 | { |
| 611 | return false; |
| 612 | } |
| 613 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 614 | if (getWidth(target, level) != std::max<size_t>(1, baseSize >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 615 | { |
| 616 | return false; |
| 617 | } |
| 618 | |
| 619 | return true; |
| 620 | } |
| 621 | |
| 622 | |
| 623 | Texture3D::Texture3D(rx::TextureImpl *impl, GLuint id) |
| 624 | : Texture(impl, id, GL_TEXTURE_3D) |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 625 | { |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | Texture3D::~Texture3D() |
| 629 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 630 | } |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 631 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 632 | bool Texture3D::isSamplerComplete(const SamplerState &samplerState, const Data &data) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 633 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 634 | size_t width = getWidth(GL_TEXTURE_3D, 0); |
| 635 | size_t height = getHeight(GL_TEXTURE_3D, 0); |
| 636 | size_t depth = getDepth(GL_TEXTURE_3D, 0); |
| 637 | if (width == 0 || height == 0 || depth == 0) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 638 | { |
| 639 | return false; |
| 640 | } |
| 641 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 642 | GLenum internalFormat = getInternalFormat(GL_TEXTURE_3D, 0); |
| 643 | if (!data.textureCaps->get(internalFormat).filterable && !IsPointSampled(samplerState)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 644 | { |
| 645 | return false; |
| 646 | } |
| 647 | |
| 648 | if (IsMipmapFiltered(samplerState) && !isMipmapComplete()) |
| 649 | { |
| 650 | return false; |
| 651 | } |
| 652 | |
| 653 | return true; |
| 654 | } |
| 655 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 656 | bool Texture3D::isMipmapComplete() const |
| 657 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 658 | size_t width = getWidth(GL_TEXTURE_2D_ARRAY, 0); |
| 659 | size_t height = getHeight(GL_TEXTURE_2D_ARRAY, 0); |
| 660 | size_t depth = getDepth(GL_TEXTURE_3D, 0); |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 661 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 662 | size_t expectedMipLevels = log2(std::max(std::max(width, height), depth)) + 1; |
| 663 | for (size_t level = 0; level < expectedMipLevels; level++) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 664 | { |
| 665 | if (!isLevelComplete(level)) |
| 666 | { |
| 667 | return false; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | return true; |
| 672 | } |
| 673 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 674 | bool Texture3D::isLevelComplete(size_t level) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 675 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 676 | ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS); |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 677 | |
| 678 | if (isImmutable()) |
| 679 | { |
| 680 | return true; |
| 681 | } |
| 682 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 683 | size_t width = getWidth(GL_TEXTURE_3D, level); |
| 684 | size_t height = getHeight(GL_TEXTURE_3D, level); |
| 685 | size_t depth = getDepth(GL_TEXTURE_3D, level); |
| 686 | if (width == 0 || height == 0 || depth == 0) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 687 | { |
| 688 | return false; |
| 689 | } |
| 690 | |
| 691 | if (level == 0) |
| 692 | { |
| 693 | return true; |
| 694 | } |
| 695 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 696 | if (getInternalFormat(GL_TEXTURE_3D, level) != getInternalFormat(GL_TEXTURE_3D, 0)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 697 | { |
| 698 | return false; |
| 699 | } |
| 700 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 701 | if (getWidth(GL_TEXTURE_3D, level) != std::max<size_t>(1, width >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 702 | { |
| 703 | return false; |
| 704 | } |
| 705 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 706 | if (getHeight(GL_TEXTURE_3D, level) != std::max<size_t>(1, height >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 707 | { |
| 708 | return false; |
| 709 | } |
| 710 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 711 | if (getDepth(GL_TEXTURE_3D, level) != std::max<size_t>(1, depth >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 712 | { |
| 713 | return false; |
| 714 | } |
| 715 | |
| 716 | return true; |
| 717 | } |
| 718 | |
| 719 | Texture2DArray::Texture2DArray(rx::TextureImpl *impl, GLuint id) |
| 720 | : Texture(impl, id, GL_TEXTURE_2D_ARRAY) |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 721 | { |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | Texture2DArray::~Texture2DArray() |
| 725 | { |
Jamie Madill | 884a462 | 2013-10-24 17:49:41 -0400 | [diff] [blame] | 726 | } |
| 727 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 728 | bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState, const Data &data) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 729 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 730 | size_t width = getWidth(GL_TEXTURE_2D_ARRAY, 0); |
| 731 | size_t height = getHeight(GL_TEXTURE_2D_ARRAY, 0); |
| 732 | size_t depth = getDepth(GL_TEXTURE_2D_ARRAY, 0); |
| 733 | if (width == 0 || height == 0 || depth == 0) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 734 | { |
| 735 | return false; |
| 736 | } |
| 737 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 738 | GLenum internalFormat = getInternalFormat(GL_TEXTURE_2D_ARRAY, 0); |
| 739 | if (!data.textureCaps->get(internalFormat).filterable && !IsPointSampled(samplerState)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 740 | { |
| 741 | return false; |
| 742 | } |
| 743 | |
| 744 | if (IsMipmapFiltered(samplerState) && !isMipmapComplete()) |
| 745 | { |
| 746 | return false; |
| 747 | } |
| 748 | |
| 749 | return true; |
| 750 | } |
| 751 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 752 | bool Texture2DArray::isMipmapComplete() const |
| 753 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 754 | size_t width = getWidth(GL_TEXTURE_2D_ARRAY, 0); |
| 755 | size_t height = getHeight(GL_TEXTURE_2D_ARRAY, 0); |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 756 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 757 | size_t expectedMipLevels = log2(std::max(width, height)) + 1; |
| 758 | for (size_t level = 1; level < expectedMipLevels; level++) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 759 | { |
| 760 | if (!isLevelComplete(level)) |
| 761 | { |
| 762 | return false; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | return true; |
| 767 | } |
| 768 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 769 | bool Texture2DArray::isLevelComplete(size_t level) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 770 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 771 | ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS); |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 772 | |
| 773 | if (isImmutable()) |
| 774 | { |
| 775 | return true; |
| 776 | } |
| 777 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 778 | size_t width = getWidth(GL_TEXTURE_2D_ARRAY, level); |
| 779 | size_t height = getHeight(GL_TEXTURE_2D_ARRAY, level); |
| 780 | size_t layers = getDepth(GL_TEXTURE_2D_ARRAY, 0); |
| 781 | if (width == 0 || height == 0 || layers == 0) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 782 | { |
| 783 | return false; |
| 784 | } |
| 785 | |
| 786 | if (level == 0) |
| 787 | { |
| 788 | return true; |
| 789 | } |
| 790 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 791 | if (getInternalFormat(GL_TEXTURE_2D_ARRAY, level) != getInternalFormat(GL_TEXTURE_2D_ARRAY, 0)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 792 | { |
| 793 | return false; |
| 794 | } |
| 795 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 796 | if (getWidth(GL_TEXTURE_2D_ARRAY, level) != std::max<size_t>(1, width >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 797 | { |
| 798 | return false; |
| 799 | } |
| 800 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 801 | if (getHeight(GL_TEXTURE_2D_ARRAY, level) != std::max<size_t>(1, height >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 802 | { |
| 803 | return false; |
| 804 | } |
| 805 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 806 | if (getDepth(GL_TEXTURE_2D_ARRAY, level) != layers) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 807 | { |
| 808 | return false; |
| 809 | } |
| 810 | |
| 811 | return true; |
| 812 | } |
| 813 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 814 | } |