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