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