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