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 | |
Jamie Madill | 10ef215 | 2014-10-20 17:04:34 -0400 | [diff] [blame] | 127 | unsigned int Texture::getTextureSerial() const |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 128 | { |
Jamie Madill | 10ef215 | 2014-10-20 17:04:34 -0400 | [diff] [blame] | 129 | return mTextureSerial; |
| 130 | } |
| 131 | |
| 132 | unsigned int Texture::issueTextureSerial() |
| 133 | { |
| 134 | return mCurrentTextureSerial++; |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | bool Texture::isImmutable() const |
| 138 | { |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 139 | return (mImmutableLevelCount > 0); |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | int Texture::immutableLevelCount() |
| 143 | { |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 144 | return mImmutableLevelCount; |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | int Texture::mipLevels() const |
| 148 | { |
| 149 | return log2(std::max(std::max(getBaseLevelWidth(), getBaseLevelHeight()), getBaseLevelDepth())) + 1; |
| 150 | } |
| 151 | |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 152 | const rx::Image *Texture::getBaseLevelImage() const |
| 153 | { |
| 154 | return (getImplementation()->getLayerCount(0) > 0 ? getImplementation()->getImage(0, 0) : NULL); |
| 155 | } |
| 156 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 157 | Error Texture::setImage(GLenum target, size_t level, GLenum internalFormat, const Extents &size, GLenum format, GLenum type, |
| 158 | const PixelUnpackState &unpack, const uint8_t *pixels) |
| 159 | { |
| 160 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 161 | |
| 162 | Error error = mTexture->setImage(target, level, internalFormat, size, format, type, unpack, pixels); |
| 163 | if (error.isError()) |
| 164 | { |
| 165 | return error; |
| 166 | } |
| 167 | |
| 168 | return Error(GL_NO_ERROR); |
| 169 | } |
| 170 | |
| 171 | Error Texture::setSubImage(GLenum target, size_t level, const Box &area, GLenum format, GLenum type, |
| 172 | const PixelUnpackState &unpack, const uint8_t *pixels) |
| 173 | { |
| 174 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 175 | |
| 176 | return mTexture->setSubImage(target, level, area, format, type, unpack, pixels); |
| 177 | } |
| 178 | |
| 179 | Error Texture::setCompressedImage(GLenum target, size_t level, GLenum internalFormat, const Extents &size, |
| 180 | const PixelUnpackState &unpack, const uint8_t *pixels) |
| 181 | { |
| 182 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 183 | |
| 184 | Error error = mTexture->setCompressedImage(target, level, internalFormat, size, unpack, pixels); |
| 185 | if (error.isError()) |
| 186 | { |
| 187 | return error; |
| 188 | } |
| 189 | |
| 190 | return Error(GL_NO_ERROR); |
| 191 | } |
| 192 | |
| 193 | Error Texture::setCompressedSubImage(GLenum target, size_t level, const Box &area, GLenum format, |
| 194 | const PixelUnpackState &unpack, const uint8_t *pixels) |
| 195 | { |
| 196 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 197 | |
| 198 | return mTexture->setCompressedSubImage(target, level, area, format, unpack, pixels); |
| 199 | } |
| 200 | |
| 201 | Error Texture::copyImage(GLenum target, size_t level, const Rectangle &sourceArea, GLenum internalFormat, |
| 202 | const Framebuffer *source) |
| 203 | { |
| 204 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 205 | |
| 206 | Error error = mTexture->copyImage(target, level, sourceArea, internalFormat, source); |
| 207 | if (error.isError()) |
| 208 | { |
| 209 | return error; |
| 210 | } |
| 211 | |
| 212 | return Error(GL_NO_ERROR); |
| 213 | } |
| 214 | |
| 215 | Error Texture::copySubImage(GLenum target, size_t level, const Offset &destOffset, const Rectangle &sourceArea, |
| 216 | const Framebuffer *source) |
| 217 | { |
| 218 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target))); |
| 219 | |
| 220 | return mTexture->copySubImage(target, level, destOffset, sourceArea, source); |
| 221 | } |
| 222 | |
| 223 | Error Texture::setStorage(GLenum target, size_t levels, GLenum internalFormat, const Extents &size) |
| 224 | { |
| 225 | ASSERT(target == mTarget); |
| 226 | |
| 227 | Error error = mTexture->setStorage(target, levels, internalFormat, size); |
| 228 | if (error.isError()) |
| 229 | { |
| 230 | return error; |
| 231 | } |
| 232 | |
| 233 | mImmutableLevelCount = levels; |
| 234 | |
| 235 | return Error(GL_NO_ERROR); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | Error Texture::generateMipmaps() |
| 240 | { |
| 241 | Error error = mTexture->generateMipmaps(); |
| 242 | if (error.isError()) |
| 243 | { |
| 244 | return error; |
| 245 | } |
| 246 | |
| 247 | return Error(GL_NO_ERROR); |
| 248 | } |
| 249 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 250 | Texture2D::Texture2D(rx::TextureImpl *impl, GLuint id) |
| 251 | : Texture(impl, id, GL_TEXTURE_2D) |
Jamie Madill | 22f843a | 2013-10-24 17:49:36 -0400 | [diff] [blame] | 252 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 253 | mSurface = NULL; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | Texture2D::~Texture2D() |
| 257 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 258 | if (mSurface) |
| 259 | { |
Jamie Madill | fb0580a | 2014-11-27 14:03:52 -0500 | [diff] [blame] | 260 | mSurface->releaseTexImage(EGL_BACK_BUFFER); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 261 | mSurface = NULL; |
| 262 | } |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 263 | } |
daniel@transgaming.com | d9ec902 | 2012-12-20 20:52:16 +0000 | [diff] [blame] | 264 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 265 | GLsizei Texture2D::getWidth(GLint level) const |
| 266 | { |
| 267 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 268 | return mTexture->getImage(level, 0)->getWidth(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 269 | else |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | GLsizei Texture2D::getHeight(GLint level) const |
| 274 | { |
| 275 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 276 | return mTexture->getImage(level, 0)->getHeight(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 277 | else |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | GLenum Texture2D::getInternalFormat(GLint level) const |
| 282 | { |
| 283 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 284 | return mTexture->getImage(level, 0)->getInternalFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 285 | else |
| 286 | return GL_NONE; |
| 287 | } |
| 288 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 289 | Error Texture2D::setImage(GLenum target, size_t level, GLenum internalFormat, const Extents &size, GLenum format, GLenum type, |
| 290 | const PixelUnpackState &unpack, const uint8_t *pixels) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 291 | { |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 292 | Error error = Texture::setImage(target, level, internalFormat, size, format, type, unpack, pixels); |
| 293 | if (error.isError()) |
| 294 | { |
| 295 | return error; |
| 296 | } |
| 297 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 298 | releaseTexImage(); |
shannon.woods@transgaming.com | 8a40668 | 2013-02-28 23:15:26 +0000 | [diff] [blame] | 299 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 300 | return Error(GL_NO_ERROR); |
| 301 | } |
| 302 | |
| 303 | Error Texture2D::setCompressedImage(GLenum target, size_t level, GLenum internalFormat, const Extents &size, |
| 304 | const PixelUnpackState &unpack, const uint8_t *pixels) |
| 305 | { |
| 306 | Error error = Texture::setCompressedImage(target, level, internalFormat, size, unpack, pixels); |
| 307 | if (error.isError()) |
| 308 | { |
| 309 | return error; |
| 310 | } |
| 311 | |
| 312 | releaseTexImage(); |
| 313 | |
| 314 | return Error(GL_NO_ERROR); |
| 315 | } |
| 316 | |
| 317 | Error Texture2D::copyImage(GLenum target, size_t level, const Rectangle &sourceArea, GLenum internalFormat, |
| 318 | const Framebuffer *source) |
| 319 | { |
| 320 | Error error = Texture::copyImage(target, level, sourceArea, internalFormat, source); |
| 321 | if (error.isError()) |
| 322 | { |
| 323 | return error; |
| 324 | } |
| 325 | |
| 326 | releaseTexImage(); |
| 327 | |
| 328 | return Error(GL_NO_ERROR); |
| 329 | } |
| 330 | |
| 331 | Error Texture2D::setStorage(GLenum target, size_t levels, GLenum internalFormat, const Extents &size) |
| 332 | { |
| 333 | Error error = Texture::setStorage(target, levels, internalFormat, size); |
| 334 | if (error.isError()) |
| 335 | { |
| 336 | return error; |
| 337 | } |
| 338 | |
| 339 | releaseTexImage(); |
| 340 | |
| 341 | return Error(GL_NO_ERROR); |
| 342 | } |
| 343 | |
| 344 | Error Texture2D::generateMipmaps() |
| 345 | { |
| 346 | Error error = Texture::generateMipmaps(); |
| 347 | if (error.isError()) |
| 348 | { |
| 349 | return error; |
| 350 | } |
| 351 | |
| 352 | releaseTexImage(); |
| 353 | |
| 354 | return Error(GL_NO_ERROR); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | void Texture2D::bindTexImage(egl::Surface *surface) |
| 358 | { |
| 359 | releaseTexImage(); |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 360 | mTexture->bindTexImage(surface); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 361 | mSurface = surface; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | void Texture2D::releaseTexImage() |
| 365 | { |
| 366 | if (mSurface) |
| 367 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 368 | mSurface = NULL; |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 369 | mTexture->releaseTexImage(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 373 | // 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] | 374 | bool Texture2D::isSamplerComplete(const SamplerState &samplerState, const Data &data) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 375 | { |
| 376 | GLsizei width = getBaseLevelWidth(); |
| 377 | GLsizei height = getBaseLevelHeight(); |
| 378 | |
| 379 | if (width <= 0 || height <= 0) |
| 380 | { |
| 381 | return false; |
| 382 | } |
| 383 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 384 | if (!data.textureCaps->get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 385 | { |
| 386 | return false; |
| 387 | } |
| 388 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 389 | bool npotSupport = data.extensions->textureNPOT; |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 390 | if (!npotSupport) |
| 391 | { |
| 392 | if ((samplerState.wrapS != GL_CLAMP_TO_EDGE && !gl::isPow2(width)) || |
| 393 | (samplerState.wrapT != GL_CLAMP_TO_EDGE && !gl::isPow2(height))) |
| 394 | { |
| 395 | return false; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | if (IsMipmapFiltered(samplerState)) |
| 400 | { |
| 401 | if (!npotSupport) |
| 402 | { |
| 403 | if (!gl::isPow2(width) || !gl::isPow2(height)) |
| 404 | { |
| 405 | return false; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | if (!isMipmapComplete()) |
| 410 | { |
| 411 | return false; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | // OpenGLES 3.0.2 spec section 3.8.13 states that a texture is not mipmap complete if: |
| 416 | // The internalformat specified for the texture arrays is a sized internal depth or |
| 417 | // depth and stencil format (see table 3.13), the value of TEXTURE_COMPARE_- |
| 418 | // MODE is NONE, and either the magnification filter is not NEAREST or the mini- |
| 419 | // fication filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST. |
| 420 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(getInternalFormat(0)); |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 421 | if (formatInfo.depthBits > 0 && data.clientVersion > 2) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 422 | { |
| 423 | if (samplerState.compareMode == GL_NONE) |
| 424 | { |
| 425 | if ((samplerState.minFilter != GL_NEAREST && samplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST) || |
| 426 | samplerState.magFilter != GL_NEAREST) |
| 427 | { |
| 428 | return false; |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | return true; |
| 434 | } |
| 435 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 436 | bool Texture2D::isCompressed(GLint level) const |
| 437 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 438 | return GetInternalFormatInfo(getInternalFormat(level)).compressed; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | bool Texture2D::isDepth(GLint level) const |
| 442 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 443 | return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 446 | // Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. |
| 447 | bool Texture2D::isMipmapComplete() const |
| 448 | { |
| 449 | int levelCount = mipLevels(); |
| 450 | |
| 451 | for (int level = 0; level < levelCount; level++) |
| 452 | { |
| 453 | if (!isLevelComplete(level)) |
| 454 | { |
| 455 | return false; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | return true; |
| 460 | } |
| 461 | |
| 462 | bool Texture2D::isLevelComplete(int level) const |
| 463 | { |
| 464 | if (isImmutable()) |
| 465 | { |
| 466 | return true; |
| 467 | } |
| 468 | |
| 469 | const rx::Image *baseImage = getBaseLevelImage(); |
| 470 | |
| 471 | GLsizei width = baseImage->getWidth(); |
| 472 | GLsizei height = baseImage->getHeight(); |
| 473 | |
| 474 | if (width <= 0 || height <= 0) |
| 475 | { |
| 476 | return false; |
| 477 | } |
| 478 | |
| 479 | // The base image level is complete if the width and height are positive |
| 480 | if (level == 0) |
| 481 | { |
| 482 | return true; |
| 483 | } |
| 484 | |
| 485 | ASSERT(level >= 1 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL); |
| 486 | rx::Image *image = mTexture->getImage(level, 0); |
| 487 | |
| 488 | if (image->getInternalFormat() != baseImage->getInternalFormat()) |
| 489 | { |
| 490 | return false; |
| 491 | } |
| 492 | |
| 493 | if (image->getWidth() != std::max(1, width >> level)) |
| 494 | { |
| 495 | return false; |
| 496 | } |
| 497 | |
| 498 | if (image->getHeight() != std::max(1, height >> level)) |
| 499 | { |
| 500 | return false; |
| 501 | } |
| 502 | |
| 503 | return true; |
| 504 | } |
| 505 | |
| 506 | TextureCubeMap::TextureCubeMap(rx::TextureImpl *impl, GLuint id) |
| 507 | : Texture(impl, id, GL_TEXTURE_CUBE_MAP) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 508 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | TextureCubeMap::~TextureCubeMap() |
| 512 | { |
Brandon Jones | 0511e80 | 2014-07-14 16:27:26 -0700 | [diff] [blame] | 513 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 514 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 515 | GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const |
| 516 | { |
| 517 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 518 | return mTexture->getImage(level, targetToLayerIndex(target))->getWidth(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 519 | else |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | GLsizei TextureCubeMap::getHeight(GLenum target, GLint level) const |
| 524 | { |
| 525 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 526 | return mTexture->getImage(level, targetToLayerIndex(target))->getHeight(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 527 | else |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | GLenum TextureCubeMap::getInternalFormat(GLenum target, GLint level) const |
| 532 | { |
| 533 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 534 | return mTexture->getImage(level, targetToLayerIndex(target))->getInternalFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 535 | else |
| 536 | return GL_NONE; |
| 537 | } |
| 538 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 539 | // Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. |
| 540 | bool TextureCubeMap::isCubeComplete() const |
| 541 | { |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 542 | int baseWidth = getBaseLevelWidth(); |
| 543 | int baseHeight = getBaseLevelHeight(); |
| 544 | GLenum baseFormat = getBaseLevelInternalFormat(); |
| 545 | |
| 546 | if (baseWidth <= 0 || baseWidth != baseHeight) |
| 547 | { |
| 548 | return false; |
| 549 | } |
| 550 | |
| 551 | for (int faceIndex = 1; faceIndex < 6; faceIndex++) |
| 552 | { |
| 553 | const rx::Image *faceBaseImage = mTexture->getImage(0, faceIndex); |
| 554 | |
| 555 | if (faceBaseImage->getWidth() != baseWidth || |
| 556 | faceBaseImage->getHeight() != baseHeight || |
| 557 | faceBaseImage->getInternalFormat() != baseFormat ) |
| 558 | { |
| 559 | return false; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | return true; |
Jamie Madill | 07edd44 | 2013-07-19 16:36:58 -0400 | [diff] [blame] | 564 | } |
| 565 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 566 | bool TextureCubeMap::isCompressed(GLenum target, GLint level) const |
| 567 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 568 | return GetInternalFormatInfo(getInternalFormat(target, level)).compressed; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 571 | bool TextureCubeMap::isDepth(GLenum target, GLint level) const |
| 572 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 573 | return GetInternalFormatInfo(getInternalFormat(target, level)).depthBits > 0; |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 574 | } |
| 575 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 576 | // Tests for texture sampling completeness |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 577 | bool TextureCubeMap::isSamplerComplete(const SamplerState &samplerState, const Data &data) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 578 | { |
| 579 | int size = getBaseLevelWidth(); |
| 580 | |
| 581 | bool mipmapping = IsMipmapFiltered(samplerState); |
| 582 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 583 | if (!data.textureCaps->get(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)).filterable && !IsPointSampled(samplerState)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 584 | { |
| 585 | return false; |
| 586 | } |
| 587 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 588 | if (!gl::isPow2(size) && !data.extensions->textureNPOT) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 589 | { |
| 590 | if (samplerState.wrapS != GL_CLAMP_TO_EDGE || samplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping) |
| 591 | { |
| 592 | return false; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | if (!mipmapping) |
| 597 | { |
| 598 | if (!isCubeComplete()) |
| 599 | { |
| 600 | return false; |
| 601 | } |
| 602 | } |
| 603 | else |
| 604 | { |
| 605 | if (!isMipmapComplete()) // Also tests for isCubeComplete() |
| 606 | { |
| 607 | return false; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | return true; |
| 612 | } |
| 613 | |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 614 | int TextureCubeMap::targetToLayerIndex(GLenum target) |
| 615 | { |
| 616 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1); |
| 617 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2); |
| 618 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3); |
| 619 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4); |
| 620 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5); |
| 621 | |
| 622 | return target - GL_TEXTURE_CUBE_MAP_POSITIVE_X; |
| 623 | } |
| 624 | |
| 625 | GLenum TextureCubeMap::layerIndexToTarget(GLint layer) |
| 626 | { |
| 627 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1); |
| 628 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2); |
| 629 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3); |
| 630 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4); |
| 631 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5); |
| 632 | |
| 633 | return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 634 | } |
| 635 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 636 | bool TextureCubeMap::isMipmapComplete() const |
| 637 | { |
| 638 | if (isImmutable()) |
| 639 | { |
| 640 | return true; |
| 641 | } |
| 642 | |
| 643 | if (!isCubeComplete()) |
| 644 | { |
| 645 | return false; |
| 646 | } |
| 647 | |
| 648 | int levelCount = mipLevels(); |
| 649 | |
| 650 | for (int face = 0; face < 6; face++) |
| 651 | { |
| 652 | for (int level = 1; level < levelCount; level++) |
| 653 | { |
| 654 | if (!isFaceLevelComplete(face, level)) |
| 655 | { |
| 656 | return false; |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | return true; |
| 662 | } |
| 663 | |
| 664 | bool TextureCubeMap::isFaceLevelComplete(int faceIndex, int level) const |
| 665 | { |
| 666 | ASSERT(level >= 0 && faceIndex < 6 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, faceIndex) != NULL); |
| 667 | |
| 668 | if (isImmutable()) |
| 669 | { |
| 670 | return true; |
| 671 | } |
| 672 | |
| 673 | int baseSize = getBaseLevelWidth(); |
| 674 | |
| 675 | if (baseSize <= 0) |
| 676 | { |
| 677 | return false; |
| 678 | } |
| 679 | |
| 680 | // "isCubeComplete" checks for base level completeness and we must call that |
| 681 | // to determine if any face at level 0 is complete. We omit that check here |
| 682 | // to avoid re-checking cube-completeness for every face at level 0. |
| 683 | if (level == 0) |
| 684 | { |
| 685 | return true; |
| 686 | } |
| 687 | |
| 688 | // Check that non-zero levels are consistent with the base level. |
| 689 | const rx::Image *faceLevelImage = mTexture->getImage(level, faceIndex); |
| 690 | |
| 691 | if (faceLevelImage->getInternalFormat() != getBaseLevelInternalFormat()) |
| 692 | { |
| 693 | return false; |
| 694 | } |
| 695 | |
| 696 | if (faceLevelImage->getWidth() != std::max(1, baseSize >> level)) |
| 697 | { |
| 698 | return false; |
| 699 | } |
| 700 | |
| 701 | return true; |
| 702 | } |
| 703 | |
| 704 | |
| 705 | Texture3D::Texture3D(rx::TextureImpl *impl, GLuint id) |
| 706 | : Texture(impl, id, GL_TEXTURE_3D) |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 707 | { |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | Texture3D::~Texture3D() |
| 711 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 712 | } |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 713 | |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 714 | GLsizei Texture3D::getWidth(GLint level) const |
| 715 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 716 | 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] | 717 | } |
| 718 | |
| 719 | GLsizei Texture3D::getHeight(GLint level) const |
| 720 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 721 | 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] | 722 | } |
| 723 | |
| 724 | GLsizei Texture3D::getDepth(GLint level) const |
| 725 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 726 | 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] | 727 | } |
| 728 | |
| 729 | GLenum Texture3D::getInternalFormat(GLint level) const |
| 730 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 731 | 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] | 732 | } |
| 733 | |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 734 | bool Texture3D::isCompressed(GLint level) const |
| 735 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 736 | return GetInternalFormatInfo(getInternalFormat(level)).compressed; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | bool Texture3D::isDepth(GLint level) const |
| 740 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 741 | return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 744 | bool Texture3D::isSamplerComplete(const SamplerState &samplerState, const Data &data) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 745 | { |
| 746 | GLsizei width = getBaseLevelWidth(); |
| 747 | GLsizei height = getBaseLevelHeight(); |
| 748 | GLsizei depth = getBaseLevelDepth(); |
| 749 | |
| 750 | if (width <= 0 || height <= 0 || depth <= 0) |
| 751 | { |
| 752 | return false; |
| 753 | } |
| 754 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 755 | if (!data.textureCaps->get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 756 | { |
| 757 | return false; |
| 758 | } |
| 759 | |
| 760 | if (IsMipmapFiltered(samplerState) && !isMipmapComplete()) |
| 761 | { |
| 762 | return false; |
| 763 | } |
| 764 | |
| 765 | return true; |
| 766 | } |
| 767 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 768 | bool Texture3D::isMipmapComplete() const |
| 769 | { |
| 770 | int levelCount = mipLevels(); |
| 771 | |
| 772 | for (int level = 0; level < levelCount; level++) |
| 773 | { |
| 774 | if (!isLevelComplete(level)) |
| 775 | { |
| 776 | return false; |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | return true; |
| 781 | } |
| 782 | |
| 783 | bool Texture3D::isLevelComplete(int level) const |
| 784 | { |
| 785 | ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL); |
| 786 | |
| 787 | if (isImmutable()) |
| 788 | { |
| 789 | return true; |
| 790 | } |
| 791 | |
| 792 | GLsizei width = getBaseLevelWidth(); |
| 793 | GLsizei height = getBaseLevelHeight(); |
| 794 | GLsizei depth = getBaseLevelDepth(); |
| 795 | |
| 796 | if (width <= 0 || height <= 0 || depth <= 0) |
| 797 | { |
| 798 | return false; |
| 799 | } |
| 800 | |
| 801 | if (level == 0) |
| 802 | { |
| 803 | return true; |
| 804 | } |
| 805 | |
| 806 | rx::Image *levelImage = mTexture->getImage(level, 0); |
| 807 | |
| 808 | if (levelImage->getInternalFormat() != getBaseLevelInternalFormat()) |
| 809 | { |
| 810 | return false; |
| 811 | } |
| 812 | |
| 813 | if (levelImage->getWidth() != std::max(1, width >> level)) |
| 814 | { |
| 815 | return false; |
| 816 | } |
| 817 | |
| 818 | if (levelImage->getHeight() != std::max(1, height >> level)) |
| 819 | { |
| 820 | return false; |
| 821 | } |
| 822 | |
| 823 | if (levelImage->getDepth() != std::max(1, depth >> level)) |
| 824 | { |
| 825 | return false; |
| 826 | } |
| 827 | |
| 828 | return true; |
| 829 | } |
| 830 | |
| 831 | Texture2DArray::Texture2DArray(rx::TextureImpl *impl, GLuint id) |
| 832 | : Texture(impl, id, GL_TEXTURE_2D_ARRAY) |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 833 | { |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | Texture2DArray::~Texture2DArray() |
| 837 | { |
Jamie Madill | 884a462 | 2013-10-24 17:49:41 -0400 | [diff] [blame] | 838 | } |
| 839 | |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 840 | GLsizei Texture2DArray::getWidth(GLint level) const |
| 841 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 842 | 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] | 843 | } |
| 844 | |
| 845 | GLsizei Texture2DArray::getHeight(GLint level) const |
| 846 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 847 | 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] | 848 | } |
| 849 | |
Jamie Madill | b8f8b89 | 2014-01-07 10:12:50 -0500 | [diff] [blame] | 850 | GLsizei Texture2DArray::getLayers(GLint level) const |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 851 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 852 | 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] | 853 | } |
| 854 | |
| 855 | GLenum Texture2DArray::getInternalFormat(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)->getInternalFormat() : GL_NONE; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 858 | } |
| 859 | |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 860 | bool Texture2DArray::isCompressed(GLint level) const |
| 861 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 862 | return GetInternalFormatInfo(getInternalFormat(level)).compressed; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | bool Texture2DArray::isDepth(GLint level) const |
| 866 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 867 | return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 870 | bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState, const Data &data) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 871 | { |
| 872 | GLsizei width = getBaseLevelWidth(); |
| 873 | GLsizei height = getBaseLevelHeight(); |
| 874 | GLsizei depth = getLayers(0); |
| 875 | |
| 876 | if (width <= 0 || height <= 0 || depth <= 0) |
| 877 | { |
| 878 | return false; |
| 879 | } |
| 880 | |
Geoff Lang | f4134d2 | 2014-12-15 10:29:47 -0500 | [diff] [blame] | 881 | if (!data.textureCaps->get(getBaseLevelInternalFormat()).filterable && !IsPointSampled(samplerState)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 882 | { |
| 883 | return false; |
| 884 | } |
| 885 | |
| 886 | if (IsMipmapFiltered(samplerState) && !isMipmapComplete()) |
| 887 | { |
| 888 | return false; |
| 889 | } |
| 890 | |
| 891 | return true; |
| 892 | } |
| 893 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 894 | bool Texture2DArray::isMipmapComplete() const |
| 895 | { |
| 896 | int levelCount = mipLevels(); |
| 897 | |
| 898 | for (int level = 1; level < levelCount; level++) |
| 899 | { |
| 900 | if (!isLevelComplete(level)) |
| 901 | { |
| 902 | return false; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | return true; |
| 907 | } |
| 908 | |
| 909 | bool Texture2DArray::isLevelComplete(int level) const |
| 910 | { |
| 911 | ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS); |
| 912 | |
| 913 | if (isImmutable()) |
| 914 | { |
| 915 | return true; |
| 916 | } |
| 917 | |
| 918 | GLsizei width = getBaseLevelWidth(); |
| 919 | GLsizei height = getBaseLevelHeight(); |
| 920 | GLsizei layers = getLayers(0); |
| 921 | |
| 922 | if (width <= 0 || height <= 0 || layers <= 0) |
| 923 | { |
| 924 | return false; |
| 925 | } |
| 926 | |
| 927 | if (level == 0) |
| 928 | { |
| 929 | return true; |
| 930 | } |
| 931 | |
| 932 | if (getInternalFormat(level) != getInternalFormat(0)) |
| 933 | { |
| 934 | return false; |
| 935 | } |
| 936 | |
| 937 | if (getWidth(level) != std::max(1, width >> level)) |
| 938 | { |
| 939 | return false; |
| 940 | } |
| 941 | |
| 942 | if (getHeight(level) != std::max(1, height >> level)) |
| 943 | { |
| 944 | return false; |
| 945 | } |
| 946 | |
| 947 | if (getLayers(level) != layers) |
| 948 | { |
| 949 | return false; |
| 950 | } |
| 951 | |
| 952 | return true; |
| 953 | } |
| 954 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 955 | } |