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 | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 355 | rx::RenderTarget *Texture2D::getDepthStencil(GLint level) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 356 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 357 | return mTexture->getDepthStencil(level, 0); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 360 | // Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. |
| 361 | bool Texture2D::isMipmapComplete() const |
| 362 | { |
| 363 | int levelCount = mipLevels(); |
| 364 | |
| 365 | for (int level = 0; level < levelCount; level++) |
| 366 | { |
| 367 | if (!isLevelComplete(level)) |
| 368 | { |
| 369 | return false; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | return true; |
| 374 | } |
| 375 | |
| 376 | bool Texture2D::isLevelComplete(int level) const |
| 377 | { |
| 378 | if (isImmutable()) |
| 379 | { |
| 380 | return true; |
| 381 | } |
| 382 | |
| 383 | const rx::Image *baseImage = getBaseLevelImage(); |
| 384 | |
| 385 | GLsizei width = baseImage->getWidth(); |
| 386 | GLsizei height = baseImage->getHeight(); |
| 387 | |
| 388 | if (width <= 0 || height <= 0) |
| 389 | { |
| 390 | return false; |
| 391 | } |
| 392 | |
| 393 | // The base image level is complete if the width and height are positive |
| 394 | if (level == 0) |
| 395 | { |
| 396 | return true; |
| 397 | } |
| 398 | |
| 399 | ASSERT(level >= 1 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL); |
| 400 | rx::Image *image = mTexture->getImage(level, 0); |
| 401 | |
| 402 | if (image->getInternalFormat() != baseImage->getInternalFormat()) |
| 403 | { |
| 404 | return false; |
| 405 | } |
| 406 | |
| 407 | if (image->getWidth() != std::max(1, width >> level)) |
| 408 | { |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | if (image->getHeight() != std::max(1, height >> level)) |
| 413 | { |
| 414 | return false; |
| 415 | } |
| 416 | |
| 417 | return true; |
| 418 | } |
| 419 | |
| 420 | TextureCubeMap::TextureCubeMap(rx::TextureImpl *impl, GLuint id) |
| 421 | : Texture(impl, id, GL_TEXTURE_CUBE_MAP) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 422 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | TextureCubeMap::~TextureCubeMap() |
| 426 | { |
Brandon Jones | 0511e80 | 2014-07-14 16:27:26 -0700 | [diff] [blame] | 427 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 428 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 429 | GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const |
| 430 | { |
| 431 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 432 | return mTexture->getImage(level, targetToLayerIndex(target))->getWidth(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 433 | else |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | GLsizei TextureCubeMap::getHeight(GLenum target, GLint level) const |
| 438 | { |
| 439 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 440 | return mTexture->getImage(level, targetToLayerIndex(target))->getHeight(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 441 | else |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | GLenum TextureCubeMap::getInternalFormat(GLenum target, GLint level) const |
| 446 | { |
| 447 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 448 | return mTexture->getImage(level, targetToLayerIndex(target))->getInternalFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 449 | else |
| 450 | return GL_NONE; |
| 451 | } |
| 452 | |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 453 | GLenum TextureCubeMap::getActualFormat(GLenum target, GLint level) const |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 454 | { |
| 455 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 456 | return mTexture->getImage(level, targetToLayerIndex(target))->getActualFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 457 | else |
Geoff Lang | cbf727a | 2014-02-10 12:50:45 -0500 | [diff] [blame] | 458 | return GL_NONE; |
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::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] | 462 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 463 | 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] | 464 | } |
| 465 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 466 | 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] | 467 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 468 | 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] | 469 | } |
| 470 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 471 | 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] | 472 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 473 | 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] | 474 | } |
| 475 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 476 | 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] | 477 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 478 | 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] | 479 | } |
| 480 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 481 | 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] | 482 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 483 | 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] | 484 | } |
| 485 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 486 | 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] | 487 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 488 | 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] | 489 | } |
| 490 | |
Jamie Madill | 2db197c | 2013-10-24 17:49:35 -0400 | [diff] [blame] | 491 | 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] | 492 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 493 | mTexture->setCompressedImage(target, level, format, width, height, 1, imageSize, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Jamie Madill | 88f18f4 | 2013-09-18 14:36:19 -0400 | [diff] [blame] | 496 | 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] | 497 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 498 | 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] | 499 | } |
| 500 | |
| 501 | void TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels) |
| 502 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 503 | 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] | 504 | } |
| 505 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 506 | // Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. |
| 507 | bool TextureCubeMap::isCubeComplete() const |
| 508 | { |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 509 | int baseWidth = getBaseLevelWidth(); |
| 510 | int baseHeight = getBaseLevelHeight(); |
| 511 | GLenum baseFormat = getBaseLevelInternalFormat(); |
| 512 | |
| 513 | if (baseWidth <= 0 || baseWidth != baseHeight) |
| 514 | { |
| 515 | return false; |
| 516 | } |
| 517 | |
| 518 | for (int faceIndex = 1; faceIndex < 6; faceIndex++) |
| 519 | { |
| 520 | const rx::Image *faceBaseImage = mTexture->getImage(0, faceIndex); |
| 521 | |
| 522 | if (faceBaseImage->getWidth() != baseWidth || |
| 523 | faceBaseImage->getHeight() != baseHeight || |
| 524 | faceBaseImage->getInternalFormat() != baseFormat ) |
| 525 | { |
| 526 | return false; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | return true; |
Jamie Madill | 07edd44 | 2013-07-19 16:36:58 -0400 | [diff] [blame] | 531 | } |
| 532 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 533 | bool TextureCubeMap::isCompressed(GLenum target, GLint level) const |
| 534 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 535 | return GetInternalFormatInfo(getInternalFormat(target, level)).compressed; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 538 | bool TextureCubeMap::isDepth(GLenum target, GLint level) const |
| 539 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 540 | return GetInternalFormatInfo(getInternalFormat(target, level)).depthBits > 0; |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 541 | } |
| 542 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 543 | void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) |
| 544 | { |
Brandon Jones | 0511e80 | 2014-07-14 16:27:26 -0700 | [diff] [blame] | 545 | mTexture->copyImage(target, level, format, x, y, width, height, source); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 546 | } |
| 547 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 548 | void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size) |
| 549 | { |
Jamie Madill | 3c0989c | 2013-10-24 17:49:39 -0400 | [diff] [blame] | 550 | mImmutable = true; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 551 | |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 552 | mTexture->storage(GL_TEXTURE_CUBE_MAP, levels, internalformat, size, size, 1); |
Jamie Madill | 2ebab85 | 2013-10-24 17:49:42 -0400 | [diff] [blame] | 553 | } |
| 554 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 555 | // Tests for texture sampling completeness |
| 556 | bool TextureCubeMap::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const |
| 557 | { |
| 558 | int size = getBaseLevelWidth(); |
| 559 | |
| 560 | bool mipmapping = IsMipmapFiltered(samplerState); |
| 561 | |
| 562 | if (!textureCaps.get(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)).filterable && !IsPointSampled(samplerState)) |
| 563 | { |
| 564 | return false; |
| 565 | } |
| 566 | |
| 567 | if (!gl::isPow2(size) && !extensions.textureNPOT) |
| 568 | { |
| 569 | if (samplerState.wrapS != GL_CLAMP_TO_EDGE || samplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping) |
| 570 | { |
| 571 | return false; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | if (!mipmapping) |
| 576 | { |
| 577 | if (!isCubeComplete()) |
| 578 | { |
| 579 | return false; |
| 580 | } |
| 581 | } |
| 582 | else |
| 583 | { |
| 584 | if (!isMipmapComplete()) // Also tests for isCubeComplete() |
| 585 | { |
| 586 | return false; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | return true; |
| 591 | } |
| 592 | |
Jamie Madill | 2db197c | 2013-10-24 17:49:35 -0400 | [diff] [blame] | 593 | unsigned int TextureCubeMap::getRenderTargetSerial(GLenum target, GLint level) |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 594 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 595 | return mTexture->getRenderTargetSerial(level, targetToLayerIndex(target)); |
| 596 | } |
| 597 | |
| 598 | int TextureCubeMap::targetToLayerIndex(GLenum target) |
| 599 | { |
| 600 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1); |
| 601 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2); |
| 602 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3); |
| 603 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4); |
| 604 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5); |
| 605 | |
| 606 | return target - GL_TEXTURE_CUBE_MAP_POSITIVE_X; |
| 607 | } |
| 608 | |
| 609 | GLenum TextureCubeMap::layerIndexToTarget(GLint layer) |
| 610 | { |
| 611 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1); |
| 612 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2); |
| 613 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3); |
| 614 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4); |
| 615 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5); |
| 616 | |
| 617 | return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | rx::RenderTarget *TextureCubeMap::getRenderTarget(GLenum target, GLint level) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 621 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 622 | return mTexture->getRenderTarget(level, targetToLayerIndex(target)); |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | rx::RenderTarget *TextureCubeMap::getDepthStencil(GLenum target, GLint level) |
| 626 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 627 | return mTexture->getDepthStencil(level, targetToLayerIndex(target)); |
daniel@transgaming.com | 690d8ae | 2012-10-31 19:52:08 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 630 | bool TextureCubeMap::isMipmapComplete() const |
| 631 | { |
| 632 | if (isImmutable()) |
| 633 | { |
| 634 | return true; |
| 635 | } |
| 636 | |
| 637 | if (!isCubeComplete()) |
| 638 | { |
| 639 | return false; |
| 640 | } |
| 641 | |
| 642 | int levelCount = mipLevels(); |
| 643 | |
| 644 | for (int face = 0; face < 6; face++) |
| 645 | { |
| 646 | for (int level = 1; level < levelCount; level++) |
| 647 | { |
| 648 | if (!isFaceLevelComplete(face, level)) |
| 649 | { |
| 650 | return false; |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | return true; |
| 656 | } |
| 657 | |
| 658 | bool TextureCubeMap::isFaceLevelComplete(int faceIndex, int level) const |
| 659 | { |
| 660 | ASSERT(level >= 0 && faceIndex < 6 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, faceIndex) != NULL); |
| 661 | |
| 662 | if (isImmutable()) |
| 663 | { |
| 664 | return true; |
| 665 | } |
| 666 | |
| 667 | int baseSize = getBaseLevelWidth(); |
| 668 | |
| 669 | if (baseSize <= 0) |
| 670 | { |
| 671 | return false; |
| 672 | } |
| 673 | |
| 674 | // "isCubeComplete" checks for base level completeness and we must call that |
| 675 | // to determine if any face at level 0 is complete. We omit that check here |
| 676 | // to avoid re-checking cube-completeness for every face at level 0. |
| 677 | if (level == 0) |
| 678 | { |
| 679 | return true; |
| 680 | } |
| 681 | |
| 682 | // Check that non-zero levels are consistent with the base level. |
| 683 | const rx::Image *faceLevelImage = mTexture->getImage(level, faceIndex); |
| 684 | |
| 685 | if (faceLevelImage->getInternalFormat() != getBaseLevelInternalFormat()) |
| 686 | { |
| 687 | return false; |
| 688 | } |
| 689 | |
| 690 | if (faceLevelImage->getWidth() != std::max(1, baseSize >> level)) |
| 691 | { |
| 692 | return false; |
| 693 | } |
| 694 | |
| 695 | return true; |
| 696 | } |
| 697 | |
| 698 | |
| 699 | Texture3D::Texture3D(rx::TextureImpl *impl, GLuint id) |
| 700 | : Texture(impl, id, GL_TEXTURE_3D) |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 701 | { |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | Texture3D::~Texture3D() |
| 705 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 706 | } |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 707 | |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 708 | GLsizei Texture3D::getWidth(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)->getWidth() : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | GLsizei Texture3D::getHeight(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)->getHeight() : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | GLsizei Texture3D::getDepth(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)->getDepth() : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | GLenum Texture3D::getInternalFormat(GLint level) const |
| 724 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 725 | 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] | 726 | } |
| 727 | |
| 728 | GLenum Texture3D::getActualFormat(GLint level) const |
| 729 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 730 | 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] | 731 | } |
| 732 | |
| 733 | bool Texture3D::isCompressed(GLint level) const |
| 734 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 735 | return GetInternalFormatInfo(getInternalFormat(level)).compressed; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | bool Texture3D::isDepth(GLint level) const |
| 739 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 740 | return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 741 | } |
| 742 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 743 | 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] | 744 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 745 | 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] | 746 | } |
| 747 | |
| 748 | void Texture3D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels) |
| 749 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 750 | 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] | 751 | } |
| 752 | |
Jamie Madill | 88f18f4 | 2013-09-18 14:36:19 -0400 | [diff] [blame] | 753 | 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] | 754 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 755 | 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] | 756 | } |
| 757 | |
| 758 | void Texture3D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels) |
| 759 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 760 | 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] | 761 | } |
| 762 | |
| 763 | void Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) |
| 764 | { |
Jamie Madill | e664e20 | 2013-10-24 17:49:40 -0400 | [diff] [blame] | 765 | mImmutable = true; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 766 | |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 767 | mTexture->storage(GL_TEXTURE_3D, levels, internalformat, width, height, depth); |
Jamie Madill | 2ebab85 | 2013-10-24 17:49:42 -0400 | [diff] [blame] | 768 | } |
| 769 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 770 | bool Texture3D::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const |
| 771 | { |
| 772 | GLsizei width = getBaseLevelWidth(); |
| 773 | GLsizei height = getBaseLevelHeight(); |
| 774 | GLsizei depth = getBaseLevelDepth(); |
| 775 | |
| 776 | if (width <= 0 || height <= 0 || depth <= 0) |
| 777 | { |
| 778 | return false; |
| 779 | } |
| 780 | |
| 781 | if (!textureCaps.get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState)) |
| 782 | { |
| 783 | return false; |
| 784 | } |
| 785 | |
| 786 | if (IsMipmapFiltered(samplerState) && !isMipmapComplete()) |
| 787 | { |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | return true; |
| 792 | } |
| 793 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 794 | unsigned int Texture3D::getRenderTargetSerial(GLint level, GLint layer) |
| 795 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 796 | return mTexture->getRenderTargetSerial(level, layer); |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Jamie Madill | a2d4e55 | 2013-10-10 15:12:01 -0400 | [diff] [blame] | 799 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 800 | rx::RenderTarget *Texture3D::getRenderTarget(GLint level, GLint layer) |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 801 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 802 | return mTexture->getRenderTarget(level, layer); |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | rx::RenderTarget *Texture3D::getDepthStencil(GLint level, GLint layer) |
| 806 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 807 | return mTexture->getDepthStencil(level, layer); |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 810 | bool Texture3D::isMipmapComplete() const |
| 811 | { |
| 812 | int levelCount = mipLevels(); |
| 813 | |
| 814 | for (int level = 0; level < levelCount; level++) |
| 815 | { |
| 816 | if (!isLevelComplete(level)) |
| 817 | { |
| 818 | return false; |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | return true; |
| 823 | } |
| 824 | |
| 825 | bool Texture3D::isLevelComplete(int level) const |
| 826 | { |
| 827 | ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL); |
| 828 | |
| 829 | if (isImmutable()) |
| 830 | { |
| 831 | return true; |
| 832 | } |
| 833 | |
| 834 | GLsizei width = getBaseLevelWidth(); |
| 835 | GLsizei height = getBaseLevelHeight(); |
| 836 | GLsizei depth = getBaseLevelDepth(); |
| 837 | |
| 838 | if (width <= 0 || height <= 0 || depth <= 0) |
| 839 | { |
| 840 | return false; |
| 841 | } |
| 842 | |
| 843 | if (level == 0) |
| 844 | { |
| 845 | return true; |
| 846 | } |
| 847 | |
| 848 | rx::Image *levelImage = mTexture->getImage(level, 0); |
| 849 | |
| 850 | if (levelImage->getInternalFormat() != getBaseLevelInternalFormat()) |
| 851 | { |
| 852 | return false; |
| 853 | } |
| 854 | |
| 855 | if (levelImage->getWidth() != std::max(1, width >> level)) |
| 856 | { |
| 857 | return false; |
| 858 | } |
| 859 | |
| 860 | if (levelImage->getHeight() != std::max(1, height >> level)) |
| 861 | { |
| 862 | return false; |
| 863 | } |
| 864 | |
| 865 | if (levelImage->getDepth() != std::max(1, depth >> level)) |
| 866 | { |
| 867 | return false; |
| 868 | } |
| 869 | |
| 870 | return true; |
| 871 | } |
| 872 | |
| 873 | Texture2DArray::Texture2DArray(rx::TextureImpl *impl, GLuint id) |
| 874 | : Texture(impl, id, GL_TEXTURE_2D_ARRAY) |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 875 | { |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | Texture2DArray::~Texture2DArray() |
| 879 | { |
Jamie Madill | 884a462 | 2013-10-24 17:49:41 -0400 | [diff] [blame] | 880 | } |
| 881 | |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 882 | GLsizei Texture2DArray::getWidth(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)->getWidth() : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | GLsizei Texture2DArray::getHeight(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)->getHeight() : 0; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 890 | } |
| 891 | |
Jamie Madill | b8f8b89 | 2014-01-07 10:12:50 -0500 | [diff] [blame] | 892 | GLsizei Texture2DArray::getLayers(GLint level) const |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 893 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 894 | 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] | 895 | } |
| 896 | |
| 897 | GLenum Texture2DArray::getInternalFormat(GLint level) const |
| 898 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 899 | 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] | 900 | } |
| 901 | |
| 902 | GLenum Texture2DArray::getActualFormat(GLint level) const |
| 903 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 904 | 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] | 905 | } |
| 906 | |
| 907 | bool Texture2DArray::isCompressed(GLint level) const |
| 908 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 909 | return GetInternalFormatInfo(getInternalFormat(level)).compressed; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | bool Texture2DArray::isDepth(GLint level) const |
| 913 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 914 | return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 917 | 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] | 918 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 919 | 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] | 920 | } |
| 921 | |
| 922 | void Texture2DArray::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels) |
| 923 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 924 | 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] | 925 | } |
| 926 | |
Jamie Madill | 88f18f4 | 2013-09-18 14:36:19 -0400 | [diff] [blame] | 927 | 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] | 928 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 929 | 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] | 930 | } |
| 931 | |
| 932 | void Texture2DArray::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels) |
| 933 | { |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 934 | 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] | 935 | } |
| 936 | |
| 937 | void Texture2DArray::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) |
| 938 | { |
Jamie Madill | 884a462 | 2013-10-24 17:49:41 -0400 | [diff] [blame] | 939 | mImmutable = true; |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 940 | |
Brandon Jones | cef06ff | 2014-08-05 13:27:48 -0700 | [diff] [blame] | 941 | mTexture->storage(GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, depth); |
Jamie Madill | 2ebab85 | 2013-10-24 17:49:42 -0400 | [diff] [blame] | 942 | } |
| 943 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 944 | bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState, const TextureCapsMap &textureCaps, const Extensions &extensions, int clientVersion) const |
| 945 | { |
| 946 | GLsizei width = getBaseLevelWidth(); |
| 947 | GLsizei height = getBaseLevelHeight(); |
| 948 | GLsizei depth = getLayers(0); |
| 949 | |
| 950 | if (width <= 0 || height <= 0 || depth <= 0) |
| 951 | { |
| 952 | return false; |
| 953 | } |
| 954 | |
| 955 | if (!textureCaps.get(getBaseLevelInternalFormat()).filterable && !IsPointSampled(samplerState)) |
| 956 | { |
| 957 | return false; |
| 958 | } |
| 959 | |
| 960 | if (IsMipmapFiltered(samplerState) && !isMipmapComplete()) |
| 961 | { |
| 962 | return false; |
| 963 | } |
| 964 | |
| 965 | return true; |
| 966 | } |
| 967 | |
Jamie Madill | e83d1a9 | 2013-10-24 17:49:33 -0400 | [diff] [blame] | 968 | unsigned int Texture2DArray::getRenderTargetSerial(GLint level, GLint layer) |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 969 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 970 | return mTexture->getRenderTargetSerial(level, layer); |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 971 | } |
| 972 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 973 | rx::RenderTarget *Texture2DArray::getRenderTarget(GLint level, GLint layer) |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 974 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 975 | return mTexture->getRenderTarget(level, layer); |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | rx::RenderTarget *Texture2DArray::getDepthStencil(GLint level, GLint layer) |
| 979 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 980 | return mTexture->getDepthStencil(level, layer); |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Brandon Jones | 6053a52 | 2014-07-25 16:22:09 -0700 | [diff] [blame] | 983 | bool Texture2DArray::isMipmapComplete() const |
| 984 | { |
| 985 | int levelCount = mipLevels(); |
| 986 | |
| 987 | for (int level = 1; level < levelCount; level++) |
| 988 | { |
| 989 | if (!isLevelComplete(level)) |
| 990 | { |
| 991 | return false; |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | return true; |
| 996 | } |
| 997 | |
| 998 | bool Texture2DArray::isLevelComplete(int level) const |
| 999 | { |
| 1000 | ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS); |
| 1001 | |
| 1002 | if (isImmutable()) |
| 1003 | { |
| 1004 | return true; |
| 1005 | } |
| 1006 | |
| 1007 | GLsizei width = getBaseLevelWidth(); |
| 1008 | GLsizei height = getBaseLevelHeight(); |
| 1009 | GLsizei layers = getLayers(0); |
| 1010 | |
| 1011 | if (width <= 0 || height <= 0 || layers <= 0) |
| 1012 | { |
| 1013 | return false; |
| 1014 | } |
| 1015 | |
| 1016 | if (level == 0) |
| 1017 | { |
| 1018 | return true; |
| 1019 | } |
| 1020 | |
| 1021 | if (getInternalFormat(level) != getInternalFormat(0)) |
| 1022 | { |
| 1023 | return false; |
| 1024 | } |
| 1025 | |
| 1026 | if (getWidth(level) != std::max(1, width >> level)) |
| 1027 | { |
| 1028 | return false; |
| 1029 | } |
| 1030 | |
| 1031 | if (getHeight(level) != std::max(1, height >> level)) |
| 1032 | { |
| 1033 | return false; |
| 1034 | } |
| 1035 | |
| 1036 | if (getLayers(level) != layers) |
| 1037 | { |
| 1038 | return false; |
| 1039 | } |
| 1040 | |
| 1041 | return true; |
| 1042 | } |
| 1043 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 1044 | } |