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