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 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 7 | // Texture.cpp: Implements the gl::Texture class. [OpenGL ES 2.0.24] section 3.7 page 63. |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/Texture.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 10 | |
| 11 | #include "common/mathutil.h" |
| 12 | #include "common/utilities.h" |
Jamie Madill | 79481d6 | 2015-04-14 08:13:47 -0400 | [diff] [blame] | 13 | #include "libANGLE/Config.h" |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 14 | #include "libANGLE/Context.h" |
Jamie Madill | 79481d6 | 2015-04-14 08:13:47 -0400 | [diff] [blame] | 15 | #include "libANGLE/Data.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 16 | #include "libANGLE/Image.h" |
Jamie Madill | 79481d6 | 2015-04-14 08:13:47 -0400 | [diff] [blame] | 17 | #include "libANGLE/Surface.h" |
| 18 | #include "libANGLE/formatutils.h" |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 19 | |
| 20 | namespace gl |
| 21 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 22 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 23 | bool IsMipmapFiltered(const gl::SamplerState &samplerState) |
| 24 | { |
| 25 | switch (samplerState.minFilter) |
| 26 | { |
| 27 | case GL_NEAREST: |
| 28 | case GL_LINEAR: |
| 29 | return false; |
| 30 | case GL_NEAREST_MIPMAP_NEAREST: |
| 31 | case GL_LINEAR_MIPMAP_NEAREST: |
| 32 | case GL_NEAREST_MIPMAP_LINEAR: |
| 33 | case GL_LINEAR_MIPMAP_LINEAR: |
| 34 | return true; |
| 35 | default: UNREACHABLE(); |
| 36 | return false; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | bool IsPointSampled(const gl::SamplerState &samplerState) |
| 41 | { |
| 42 | return (samplerState.magFilter == GL_NEAREST && (samplerState.minFilter == GL_NEAREST || samplerState.minFilter == GL_NEAREST_MIPMAP_NEAREST)); |
| 43 | } |
| 44 | |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 45 | static size_t GetImageDescIndex(GLenum target, size_t level) |
| 46 | { |
| 47 | return IsCubeMapTextureTarget(target) ? ((level * 6) + CubeMapTextureTargetToLayerIndex(target)) : level; |
| 48 | } |
| 49 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 50 | Texture::Texture(rx::TextureImpl *impl, GLuint id, GLenum target) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 51 | : egl::ImageSibling(id), |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 52 | mTexture(impl), |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 53 | mUsage(GL_NONE), |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 54 | mImmutableLevelCount(0), |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame] | 55 | mTarget(target), |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 56 | mImageDescs(IMPLEMENTATION_MAX_TEXTURE_LEVELS * (target == GL_TEXTURE_CUBE_MAP ? 6 : 1)), |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 57 | mCompletenessCache(), |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame] | 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 | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 90 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubeMapTextureTarget(target))); |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 91 | return getImageDesc(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 | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 96 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubeMapTextureTarget(target))); |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 97 | return getImageDesc(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 | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 102 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubeMapTextureTarget(target))); |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 103 | return getImageDesc(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 | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 108 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubeMapTextureTarget(target))); |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 109 | return getImageDesc(target, level).internalFormat; |
Jamie Madill | 945f732 | 2014-09-03 15:07:14 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 112 | bool Texture::isSamplerComplete(const SamplerState &samplerState, const Data &data) const |
| 113 | { |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 114 | const ImageDesc &baseImageDesc = getImageDesc(getBaseImageTarget(), samplerState.baseLevel); |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 115 | const TextureCaps &textureCaps = data.textureCaps->get(baseImageDesc.internalFormat); |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 116 | if (!mCompletenessCache.cacheValid || |
| 117 | mCompletenessCache.samplerState != samplerState || |
| 118 | mCompletenessCache.filterable != textureCaps.filterable || |
| 119 | mCompletenessCache.clientVersion != data.clientVersion || |
| 120 | mCompletenessCache.supportsNPOT != data.extensions->textureNPOT) |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 121 | { |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 122 | mCompletenessCache.cacheValid = true; |
| 123 | mCompletenessCache.samplerState = samplerState; |
| 124 | mCompletenessCache.filterable = textureCaps.filterable; |
| 125 | mCompletenessCache.clientVersion = data.clientVersion; |
| 126 | mCompletenessCache.supportsNPOT = data.extensions->textureNPOT; |
| 127 | mCompletenessCache.samplerComplete = computeSamplerCompleteness(samplerState, data); |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 128 | } |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 129 | return mCompletenessCache.samplerComplete; |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 130 | } |
| 131 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 132 | bool Texture::isMipmapComplete() const |
| 133 | { |
| 134 | return computeMipmapCompleteness(mSamplerState); |
| 135 | } |
| 136 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 137 | // Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. |
| 138 | bool Texture::isCubeComplete() const |
| 139 | { |
| 140 | ASSERT(mTarget == GL_TEXTURE_CUBE_MAP); |
| 141 | |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 142 | const ImageDesc &baseImageDesc = getImageDesc(FirstCubeMapTextureTarget, 0); |
| 143 | if (baseImageDesc.size.width == 0 || baseImageDesc.size.width != baseImageDesc.size.height) |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 144 | { |
| 145 | return false; |
| 146 | } |
| 147 | |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 148 | for (GLenum face = FirstCubeMapTextureTarget + 1; face <= LastCubeMapTextureTarget; face++) |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 149 | { |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 150 | const ImageDesc &faceImageDesc = getImageDesc(face, 0); |
| 151 | if (faceImageDesc.size.width != baseImageDesc.size.width || |
| 152 | faceImageDesc.size.height != baseImageDesc.size.height || |
| 153 | faceImageDesc.internalFormat != baseImageDesc.internalFormat) |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 154 | { |
| 155 | return false; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return true; |
| 160 | } |
| 161 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 162 | size_t Texture::getMipCompleteLevels() const |
| 163 | { |
| 164 | const ImageDesc &baseImageDesc = getImageDesc(getBaseImageTarget(), 0); |
| 165 | if (mTarget == GL_TEXTURE_3D) |
| 166 | { |
Cooper Partin | c5cf9bc | 2015-08-06 10:46:48 -0700 | [diff] [blame^] | 167 | const int maxDim = std::max(std::max(baseImageDesc.size.width, baseImageDesc.size.height), |
| 168 | baseImageDesc.size.depth); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 169 | return log2(maxDim) + 1; |
| 170 | } |
| 171 | else |
| 172 | { |
| 173 | return log2(std::max(baseImageDesc.size.width, baseImageDesc.size.height)) + 1; |
| 174 | } |
| 175 | } |
| 176 | |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 177 | bool Texture::isImmutable() const |
| 178 | { |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 179 | return (mImmutableLevelCount > 0); |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | int Texture::immutableLevelCount() |
| 183 | { |
Jamie Madill | 6948e30 | 2014-10-20 17:04:33 -0400 | [diff] [blame] | 184 | return mImmutableLevelCount; |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 187 | egl::Surface *Texture::getBoundSurface() const |
| 188 | { |
| 189 | return mBoundSurface; |
| 190 | } |
| 191 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 192 | Error Texture::setImage(Context *context, |
| 193 | GLenum target, |
| 194 | size_t level, |
| 195 | GLenum internalFormat, |
| 196 | const Extents &size, |
| 197 | GLenum format, |
| 198 | GLenum type, |
| 199 | const uint8_t *pixels) |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 200 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 201 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubeMapTextureTarget(target))); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 202 | |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 203 | // Release from previous calls to eglBindTexImage, to avoid calling the Impl after |
| 204 | releaseTexImageInternal(); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 205 | orphanImages(); |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 206 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 207 | // Hack: allow nullptr for testing |
| 208 | if (context != nullptr) |
| 209 | { |
| 210 | // Sync the unpack state |
| 211 | context->syncRendererState(context->getState().unpackStateBitMask()); |
| 212 | } |
| 213 | |
| 214 | const PixelUnpackState &unpack = |
| 215 | context ? context->getState().getUnpackState() : PixelUnpackState(); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 216 | Error error = mTexture->setImage(target, level, internalFormat, size, format, type, unpack, pixels); |
| 217 | if (error.isError()) |
| 218 | { |
| 219 | return error; |
| 220 | } |
| 221 | |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 222 | setImageDesc(target, level, ImageDesc(size, GetSizedInternalFormat(internalFormat, type))); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 223 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 224 | return Error(GL_NO_ERROR); |
| 225 | } |
| 226 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 227 | Error Texture::setSubImage(Context *context, |
| 228 | GLenum target, |
| 229 | size_t level, |
| 230 | const Box &area, |
| 231 | GLenum format, |
| 232 | GLenum type, |
| 233 | const uint8_t *pixels) |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 234 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 235 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubeMapTextureTarget(target))); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 236 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 237 | // Sync the unpack state |
| 238 | context->syncRendererState(context->getState().unpackStateBitMask()); |
| 239 | |
| 240 | const PixelUnpackState &unpack = context->getState().getUnpackState(); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 241 | return mTexture->setSubImage(target, level, area, format, type, unpack, pixels); |
| 242 | } |
| 243 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 244 | Error Texture::setCompressedImage(Context *context, |
| 245 | GLenum target, |
| 246 | size_t level, |
| 247 | GLenum internalFormat, |
| 248 | const Extents &size, |
| 249 | size_t imageSize, |
| 250 | const uint8_t *pixels) |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 251 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 252 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubeMapTextureTarget(target))); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 253 | |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 254 | // Release from previous calls to eglBindTexImage, to avoid calling the Impl after |
| 255 | releaseTexImageInternal(); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 256 | orphanImages(); |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 257 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 258 | // Sync the unpack state |
| 259 | context->syncRendererState(context->getState().unpackStateBitMask()); |
| 260 | |
| 261 | const PixelUnpackState &unpack = context->getState().getUnpackState(); |
Geoff Lang | 8509d86 | 2015-05-20 14:06:13 -0400 | [diff] [blame] | 262 | Error error = mTexture->setCompressedImage(target, level, internalFormat, size, unpack, imageSize, pixels); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 263 | if (error.isError()) |
| 264 | { |
| 265 | return error; |
| 266 | } |
| 267 | |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 268 | setImageDesc(target, level, ImageDesc(size, GetSizedInternalFormat(internalFormat, GL_UNSIGNED_BYTE))); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 269 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 270 | return Error(GL_NO_ERROR); |
| 271 | } |
| 272 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 273 | Error Texture::setCompressedSubImage(Context *context, |
| 274 | GLenum target, |
| 275 | size_t level, |
| 276 | const Box &area, |
| 277 | GLenum format, |
| 278 | size_t imageSize, |
| 279 | const uint8_t *pixels) |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 280 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 281 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubeMapTextureTarget(target))); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 282 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 283 | // Sync the unpack state |
| 284 | context->syncRendererState(context->getState().unpackStateBitMask()); |
| 285 | |
| 286 | const PixelUnpackState &unpack = context->getState().getUnpackState(); |
Geoff Lang | 8509d86 | 2015-05-20 14:06:13 -0400 | [diff] [blame] | 287 | return mTexture->setCompressedSubImage(target, level, area, format, unpack, imageSize, pixels); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | Error Texture::copyImage(GLenum target, size_t level, const Rectangle &sourceArea, GLenum internalFormat, |
| 291 | const Framebuffer *source) |
| 292 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 293 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubeMapTextureTarget(target))); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 294 | |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 295 | // Release from previous calls to eglBindTexImage, to avoid calling the Impl after |
| 296 | releaseTexImageInternal(); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 297 | orphanImages(); |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 298 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 299 | Error error = mTexture->copyImage(target, level, sourceArea, internalFormat, source); |
| 300 | if (error.isError()) |
| 301 | { |
| 302 | return error; |
| 303 | } |
| 304 | |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 305 | setImageDesc(target, level, ImageDesc(Extents(sourceArea.width, sourceArea.height, 1), |
| 306 | GetSizedInternalFormat(internalFormat, GL_UNSIGNED_BYTE))); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 307 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 308 | return Error(GL_NO_ERROR); |
| 309 | } |
| 310 | |
| 311 | Error Texture::copySubImage(GLenum target, size_t level, const Offset &destOffset, const Rectangle &sourceArea, |
| 312 | const Framebuffer *source) |
| 313 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 314 | ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubeMapTextureTarget(target))); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 315 | |
| 316 | return mTexture->copySubImage(target, level, destOffset, sourceArea, source); |
| 317 | } |
| 318 | |
| 319 | Error Texture::setStorage(GLenum target, size_t levels, GLenum internalFormat, const Extents &size) |
| 320 | { |
| 321 | ASSERT(target == mTarget); |
| 322 | |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 323 | // Release from previous calls to eglBindTexImage, to avoid calling the Impl after |
| 324 | releaseTexImageInternal(); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 325 | orphanImages(); |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 326 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 327 | Error error = mTexture->setStorage(target, levels, internalFormat, size); |
| 328 | if (error.isError()) |
| 329 | { |
| 330 | return error; |
| 331 | } |
| 332 | |
Cooper Partin | c5cf9bc | 2015-08-06 10:46:48 -0700 | [diff] [blame^] | 333 | mImmutableLevelCount = static_cast<GLsizei>(levels); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 334 | clearImageDescs(); |
| 335 | setImageDescChain(levels, size, internalFormat); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 336 | |
| 337 | return Error(GL_NO_ERROR); |
| 338 | } |
| 339 | |
| 340 | |
| 341 | Error Texture::generateMipmaps() |
| 342 | { |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 343 | // Release from previous calls to eglBindTexImage, to avoid calling the Impl after |
| 344 | releaseTexImageInternal(); |
| 345 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 346 | // EGL_KHR_gl_image states that images are only orphaned when generating mipmaps if the texture |
| 347 | // is not mip complete. |
| 348 | if (!isMipmapComplete()) |
| 349 | { |
| 350 | orphanImages(); |
| 351 | } |
| 352 | |
Gregoire Payen de La Garanderie | 752ce19 | 2015-04-14 11:11:12 +0100 | [diff] [blame] | 353 | Error error = mTexture->generateMipmaps(getSamplerState()); |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 354 | if (error.isError()) |
| 355 | { |
| 356 | return error; |
| 357 | } |
| 358 | |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 359 | const ImageDesc &baseImageInfo = getImageDesc(getBaseImageTarget(), 0); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 360 | size_t mipLevels = log2(std::max(std::max(baseImageInfo.size.width, baseImageInfo.size.height), baseImageInfo.size.depth)) + 1; |
| 361 | setImageDescChain(mipLevels, baseImageInfo.size, baseImageInfo.internalFormat); |
| 362 | |
Geoff Lang | 0a4f1e2 | 2014-12-17 12:33:26 -0500 | [diff] [blame] | 363 | return Error(GL_NO_ERROR); |
| 364 | } |
| 365 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 366 | void Texture::setImageDescChain(size_t levels, Extents baseSize, GLenum sizedInternalFormat) |
| 367 | { |
Cooper Partin | c5cf9bc | 2015-08-06 10:46:48 -0700 | [diff] [blame^] | 368 | for (int level = 0; level < static_cast<int>(levels); level++) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 369 | { |
Cooper Partin | c5cf9bc | 2015-08-06 10:46:48 -0700 | [diff] [blame^] | 370 | Extents levelSize( |
| 371 | std::max<int>(baseSize.width >> level, 1), std::max<int>(baseSize.height >> level, 1), |
| 372 | (mTarget == GL_TEXTURE_2D_ARRAY) ? baseSize.depth |
| 373 | : std::max<int>(baseSize.depth >> level, 1)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 374 | ImageDesc levelInfo(levelSize, sizedInternalFormat); |
| 375 | |
| 376 | if (mTarget == GL_TEXTURE_CUBE_MAP) |
| 377 | { |
Cooper Partin | c5cf9bc | 2015-08-06 10:46:48 -0700 | [diff] [blame^] | 378 | for (GLenum face = FirstCubeMapTextureTarget; face <= LastCubeMapTextureTarget; face++) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 379 | { |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 380 | setImageDesc(face, level, levelInfo); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | else |
| 384 | { |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 385 | setImageDesc(mTarget, level, levelInfo); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 390 | Texture::ImageDesc::ImageDesc() |
| 391 | : ImageDesc(Extents(0, 0, 0), GL_NONE) |
| 392 | { |
| 393 | } |
| 394 | |
| 395 | Texture::ImageDesc::ImageDesc(const Extents &size, GLenum internalFormat) |
| 396 | : size(size), |
| 397 | internalFormat(internalFormat) |
| 398 | { |
| 399 | } |
| 400 | |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 401 | const Texture::ImageDesc &Texture::getImageDesc(GLenum target, size_t level) const |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 402 | { |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 403 | size_t descIndex = GetImageDescIndex(target, level); |
| 404 | ASSERT(descIndex < mImageDescs.size()); |
| 405 | return mImageDescs[descIndex]; |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 406 | } |
| 407 | |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 408 | void Texture::setImageDesc(GLenum target, size_t level, const ImageDesc &desc) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 409 | { |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 410 | size_t descIndex = GetImageDescIndex(target, level); |
| 411 | ASSERT(descIndex < mImageDescs.size()); |
| 412 | mImageDescs[descIndex] = desc; |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 413 | mCompletenessCache.cacheValid = false; |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 414 | } |
| 415 | |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 416 | void Texture::clearImageDesc(GLenum target, size_t level) |
Geoff Lang | b926627 | 2015-01-29 13:25:14 +0000 | [diff] [blame] | 417 | { |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 418 | setImageDesc(target, level, ImageDesc()); |
Geoff Lang | b926627 | 2015-01-29 13:25:14 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 421 | void Texture::clearImageDescs() |
| 422 | { |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 423 | for (size_t descIndex = 0; descIndex < mImageDescs.size(); descIndex++) |
| 424 | { |
| 425 | mImageDescs[descIndex] = ImageDesc(); |
| 426 | } |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 427 | mCompletenessCache.cacheValid = false; |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 428 | } |
| 429 | |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 430 | void Texture::bindTexImageFromSurface(egl::Surface *surface) |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame] | 431 | { |
Geoff Lang | b926627 | 2015-01-29 13:25:14 +0000 | [diff] [blame] | 432 | ASSERT(surface); |
| 433 | |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 434 | if (mBoundSurface) |
| 435 | { |
| 436 | releaseTexImageFromSurface(); |
| 437 | } |
| 438 | |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame] | 439 | mTexture->bindTexImage(surface); |
| 440 | mBoundSurface = surface; |
Geoff Lang | b926627 | 2015-01-29 13:25:14 +0000 | [diff] [blame] | 441 | |
| 442 | // Set the image info to the size and format of the surface |
| 443 | ASSERT(mTarget == GL_TEXTURE_2D); |
| 444 | Extents size(surface->getWidth(), surface->getHeight(), 1); |
Geoff Lang | c223dc6 | 2015-01-09 13:10:01 -0500 | [diff] [blame] | 445 | ImageDesc desc(size, surface->getConfig()->renderTargetFormat); |
Geoff Lang | 866dd2d | 2015-02-10 11:08:32 -0500 | [diff] [blame] | 446 | setImageDesc(mTarget, 0, desc); |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame] | 447 | } |
| 448 | |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 449 | void Texture::releaseTexImageFromSurface() |
| 450 | { |
| 451 | ASSERT(mBoundSurface); |
| 452 | mBoundSurface = nullptr; |
| 453 | mTexture->releaseTexImage(); |
| 454 | |
| 455 | // Erase the image info for level 0 |
| 456 | ASSERT(mTarget == GL_TEXTURE_2D); |
| 457 | clearImageDesc(mTarget, 0); |
| 458 | } |
| 459 | |
| 460 | void Texture::releaseTexImageInternal() |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame] | 461 | { |
| 462 | if (mBoundSurface) |
| 463 | { |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 464 | // Notify the surface |
| 465 | mBoundSurface->releaseTexImageFromTexture(); |
Geoff Lang | b926627 | 2015-01-29 13:25:14 +0000 | [diff] [blame] | 466 | |
Jamie Madill | bb714f7 | 2015-05-20 10:22:18 -0400 | [diff] [blame] | 467 | // Then, call the same method as from the surface |
| 468 | releaseTexImageFromSurface(); |
Geoff Lang | 7c973ea | 2014-12-19 15:58:28 -0500 | [diff] [blame] | 469 | } |
| 470 | } |
| 471 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 472 | Error Texture::setEGLImageTarget(GLenum target, egl::Image *imageTarget) |
| 473 | { |
| 474 | ASSERT(target == mTarget); |
| 475 | ASSERT(target == GL_TEXTURE_2D); |
| 476 | |
| 477 | // Release from previous calls to eglBindTexImage, to avoid calling the Impl after |
| 478 | releaseTexImageInternal(); |
| 479 | orphanImages(); |
| 480 | |
| 481 | Error error = mTexture->setEGLImageTarget(target, imageTarget); |
| 482 | if (error.isError()) |
| 483 | { |
| 484 | return error; |
| 485 | } |
| 486 | |
| 487 | setTargetImage(imageTarget); |
| 488 | |
Cooper Partin | c5cf9bc | 2015-08-06 10:46:48 -0700 | [diff] [blame^] | 489 | Extents size(static_cast<int>(imageTarget->getWidth()), |
| 490 | static_cast<int>(imageTarget->getHeight()), 1); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 491 | GLenum internalFormat = imageTarget->getInternalFormat(); |
| 492 | GLenum type = GetInternalFormatInfo(internalFormat).type; |
| 493 | |
| 494 | clearImageDescs(); |
| 495 | setImageDesc(target, 0, ImageDesc(size, GetSizedInternalFormat(internalFormat, type))); |
| 496 | |
| 497 | return Error(GL_NO_ERROR); |
| 498 | } |
| 499 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 500 | GLenum Texture::getBaseImageTarget() const |
Jamie Madill | 22f843a | 2013-10-24 17:49:36 -0400 | [diff] [blame] | 501 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 502 | return mTarget == GL_TEXTURE_CUBE_MAP ? FirstCubeMapTextureTarget : mTarget; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 505 | bool Texture::computeSamplerCompleteness(const SamplerState &samplerState, const Data &data) const |
| 506 | { |
| 507 | const ImageDesc &baseImageDesc = getImageDesc(getBaseImageTarget(), samplerState.baseLevel); |
| 508 | if (baseImageDesc.size.width == 0 || baseImageDesc.size.height == 0 || baseImageDesc.size.depth == 0) |
| 509 | { |
| 510 | return false; |
| 511 | } |
| 512 | |
| 513 | if (mTarget == GL_TEXTURE_CUBE_MAP && baseImageDesc.size.width != baseImageDesc.size.height) |
| 514 | { |
| 515 | return false; |
| 516 | } |
| 517 | |
| 518 | const TextureCaps &textureCaps = data.textureCaps->get(baseImageDesc.internalFormat); |
| 519 | if (!textureCaps.filterable && !IsPointSampled(samplerState)) |
| 520 | { |
| 521 | return false; |
| 522 | } |
| 523 | |
| 524 | bool npotSupport = data.extensions->textureNPOT || data.clientVersion >= 3; |
| 525 | if (!npotSupport) |
| 526 | { |
| 527 | if ((samplerState.wrapS != GL_CLAMP_TO_EDGE && !gl::isPow2(baseImageDesc.size.width)) || |
| 528 | (samplerState.wrapT != GL_CLAMP_TO_EDGE && !gl::isPow2(baseImageDesc.size.height))) |
| 529 | { |
| 530 | return false; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | if (IsMipmapFiltered(samplerState)) |
| 535 | { |
| 536 | if (!npotSupport) |
| 537 | { |
| 538 | if (!gl::isPow2(baseImageDesc.size.width) || !gl::isPow2(baseImageDesc.size.height)) |
| 539 | { |
| 540 | return false; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | if (!computeMipmapCompleteness(samplerState)) |
| 545 | { |
| 546 | return false; |
| 547 | } |
| 548 | } |
| 549 | else |
| 550 | { |
| 551 | if (mTarget == GL_TEXTURE_CUBE_MAP && !isCubeComplete()) |
| 552 | { |
| 553 | return false; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | // OpenGLES 3.0.2 spec section 3.8.13 states that a texture is not mipmap complete if: |
| 558 | // The internalformat specified for the texture arrays is a sized internal depth or |
| 559 | // depth and stencil format (see table 3.13), the value of TEXTURE_COMPARE_- |
| 560 | // MODE is NONE, and either the magnification filter is not NEAREST or the mini- |
| 561 | // fication filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST. |
| 562 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(baseImageDesc.internalFormat); |
| 563 | if (formatInfo.depthBits > 0 && data.clientVersion > 2) |
| 564 | { |
| 565 | if (samplerState.compareMode == GL_NONE) |
| 566 | { |
| 567 | if ((samplerState.minFilter != GL_NEAREST && samplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST) || |
| 568 | samplerState.magFilter != GL_NEAREST) |
| 569 | { |
| 570 | return false; |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | return true; |
| 576 | } |
| 577 | |
| 578 | bool Texture::computeMipmapCompleteness(const gl::SamplerState &samplerState) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 579 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 580 | size_t expectedMipLevels = getMipCompleteLevels(); |
Jamie Madill | 19d438d | 2015-01-19 13:42:12 -0500 | [diff] [blame] | 581 | |
| 582 | size_t maxLevel = std::min<size_t>(expectedMipLevels, samplerState.maxLevel + 1); |
| 583 | |
| 584 | for (size_t level = samplerState.baseLevel; level < maxLevel; level++) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 585 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 586 | if (mTarget == GL_TEXTURE_CUBE_MAP) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 587 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 588 | for (GLenum face = FirstCubeMapTextureTarget; face <= LastCubeMapTextureTarget; face++) |
| 589 | { |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 590 | if (!computeLevelCompleteness(face, level, samplerState)) |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 591 | { |
| 592 | return false; |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | else |
| 597 | { |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 598 | if (!computeLevelCompleteness(mTarget, level, samplerState)) |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 599 | { |
| 600 | return false; |
| 601 | } |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
| 605 | return true; |
| 606 | } |
| 607 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 608 | |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 609 | bool Texture::computeLevelCompleteness(GLenum target, size_t level, const gl::SamplerState &samplerState) const |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 610 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 611 | ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS); |
| 612 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 613 | if (isImmutable()) |
| 614 | { |
| 615 | return true; |
| 616 | } |
| 617 | |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 618 | const ImageDesc &baseImageDesc = getImageDesc(getBaseImageTarget(), samplerState.baseLevel); |
| 619 | if (baseImageDesc.size.width == 0 || baseImageDesc.size.height == 0 || baseImageDesc.size.depth == 0) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 620 | { |
| 621 | return false; |
| 622 | } |
| 623 | |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 624 | const ImageDesc &levelImageDesc = getImageDesc(target, level); |
| 625 | if (levelImageDesc.size.width == 0 || levelImageDesc.size.height == 0 || |
| 626 | levelImageDesc.size.depth == 0) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 627 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 628 | return false; |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 631 | if (levelImageDesc.internalFormat != baseImageDesc.internalFormat) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 632 | { |
| 633 | return false; |
| 634 | } |
| 635 | |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 636 | if (levelImageDesc.size.width != std::max(1, baseImageDesc.size.width >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 637 | { |
| 638 | return false; |
| 639 | } |
| 640 | |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 641 | if (levelImageDesc.size.height != std::max(1, baseImageDesc.size.height >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 642 | { |
| 643 | return false; |
| 644 | } |
| 645 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 646 | if (mTarget == GL_TEXTURE_3D) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 647 | { |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 648 | if (levelImageDesc.size.depth != std::max(1, baseImageDesc.size.depth >> level)) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 649 | { |
| 650 | return false; |
| 651 | } |
| 652 | } |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 653 | else if (mTarget == GL_TEXTURE_2D_ARRAY) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 654 | { |
Geoff Lang | b0eecdf | 2015-02-10 11:09:12 -0500 | [diff] [blame] | 655 | if (levelImageDesc.size.depth != baseImageDesc.size.depth) |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 656 | { |
| 657 | return false; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | return true; |
| 662 | } |
| 663 | |
Geoff Lang | 0fe4053 | 2015-02-10 12:01:27 -0500 | [diff] [blame] | 664 | Texture::SamplerCompletenessCache::SamplerCompletenessCache() |
| 665 | : cacheValid(false), |
| 666 | samplerState(), |
| 667 | filterable(false), |
| 668 | clientVersion(0), |
| 669 | supportsNPOT(false), |
| 670 | samplerComplete(false) |
| 671 | { |
| 672 | } |
| 673 | |
Jamie Madill | 79481d6 | 2015-04-14 08:13:47 -0400 | [diff] [blame] | 674 | GLsizei Texture::getAttachmentWidth(const gl::FramebufferAttachment::Target &target) const |
| 675 | { |
Cooper Partin | c5cf9bc | 2015-08-06 10:46:48 -0700 | [diff] [blame^] | 676 | return static_cast<GLsizei>( |
| 677 | getWidth(target.textureIndex().type, target.textureIndex().mipIndex)); |
Jamie Madill | 79481d6 | 2015-04-14 08:13:47 -0400 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | GLsizei Texture::getAttachmentHeight(const gl::FramebufferAttachment::Target &target) const |
| 681 | { |
Cooper Partin | c5cf9bc | 2015-08-06 10:46:48 -0700 | [diff] [blame^] | 682 | return static_cast<GLsizei>( |
| 683 | getHeight(target.textureIndex().type, target.textureIndex().mipIndex)); |
Jamie Madill | 79481d6 | 2015-04-14 08:13:47 -0400 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | GLenum Texture::getAttachmentInternalFormat(const gl::FramebufferAttachment::Target &target) const |
| 687 | { |
| 688 | return getInternalFormat(target.textureIndex().type, target.textureIndex().mipIndex); |
| 689 | } |
| 690 | |
| 691 | GLsizei Texture::getAttachmentSamples(const gl::FramebufferAttachment::Target &/*target*/) const |
| 692 | { |
| 693 | // Multisample textures not currently supported |
| 694 | return 0; |
| 695 | } |
| 696 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 697 | } |