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