shannon.woods@transgaming.com | bdf2d80 | 2013-02-28 23:16:20 +0000 | [diff] [blame] | 1 | #include "precompiled.h" |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 2 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 3 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
| 8 | // Texture.cpp: Implements the gl::Texture class and its derived classes |
| 9 | // Texture2D and TextureCubeMap. Implements GL texture objects and related |
| 10 | // functionality. [OpenGL ES 2.0.24] section 3.7 page 63. |
| 11 | |
| 12 | #include "libGLESv2/Texture.h" |
| 13 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 14 | #include "libGLESv2/main.h" |
shannonwoods@chromium.org | a2ecfcc | 2013-05-30 00:11:59 +0000 | [diff] [blame] | 15 | #include "common/mathutil.h" |
| 16 | #include "common/utilities.h" |
shannonwoods@chromium.org | 4ad58e0 | 2013-05-30 00:08:11 +0000 | [diff] [blame] | 17 | #include "libGLESv2/formatutils.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 18 | #include "libGLESv2/Renderbuffer.h" |
| 19 | #include "libGLESv2/renderer/Image.h" |
Brandon Jones | 6518fe2 | 2014-07-08 15:16:52 -0700 | [diff] [blame] | 20 | #include "libGLESv2/renderer/d3d/TextureStorage.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 21 | #include "libEGL/Surface.h" |
Jamie Madill | 0e0510f | 2013-10-10 15:46:23 -0400 | [diff] [blame] | 22 | #include "libGLESv2/renderer/RenderTarget.h" |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 23 | |
| 24 | namespace gl |
| 25 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 26 | |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 27 | Texture::Texture(GLuint id, GLenum target) |
| 28 | : RefCountObject(id), |
| 29 | mUsage(GL_NONE), |
| 30 | mImmutable(false), |
| 31 | mTarget(target) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 32 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | Texture::~Texture() |
| 36 | { |
| 37 | } |
| 38 | |
Geoff Lang | 4907f2c | 2013-07-25 12:53:57 -0400 | [diff] [blame] | 39 | GLenum Texture::getTarget() const |
| 40 | { |
| 41 | return mTarget; |
| 42 | } |
| 43 | |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 44 | void Texture::setUsage(GLenum usage) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 45 | { |
Geoff Lang | 63b5f1f | 2013-09-23 14:52:14 -0400 | [diff] [blame] | 46 | mUsage = usage; |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 47 | getImplementation()->setUsage(usage); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Brandon Jones | a328d56 | 2014-07-01 13:52:40 -0700 | [diff] [blame] | 50 | void Texture::getSamplerStateWithNativeOffset(SamplerState *sampler) |
daniel@transgaming.com | ebf139f | 2012-10-31 18:07:32 +0000 | [diff] [blame] | 51 | { |
| 52 | *sampler = mSamplerState; |
Nicolas Capens | 8de6828 | 2014-04-04 11:10:27 -0400 | [diff] [blame] | 53 | |
| 54 | // Offset the effective base level by the texture storage's top level |
| 55 | rx::TextureStorageInterface *texture = getNativeTexture(); |
| 56 | int topLevel = texture ? texture->getTopLevel() : 0; |
| 57 | sampler->baseLevel = topLevel + mSamplerState.baseLevel; |
daniel@transgaming.com | 07ab841 | 2012-07-12 15:17:09 +0000 | [diff] [blame] | 58 | } |
| 59 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 60 | GLenum Texture::getUsage() const |
| 61 | { |
| 62 | return mUsage; |
| 63 | } |
| 64 | |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 65 | GLint Texture::getBaseLevelWidth() const |
| 66 | { |
| 67 | const rx::Image *baseImage = getBaseLevelImage(); |
| 68 | return (baseImage ? baseImage->getWidth() : 0); |
| 69 | } |
| 70 | |
| 71 | GLint Texture::getBaseLevelHeight() const |
| 72 | { |
| 73 | const rx::Image *baseImage = getBaseLevelImage(); |
| 74 | return (baseImage ? baseImage->getHeight() : 0); |
| 75 | } |
| 76 | |
| 77 | GLint Texture::getBaseLevelDepth() const |
| 78 | { |
| 79 | const rx::Image *baseImage = getBaseLevelImage(); |
| 80 | return (baseImage ? baseImage->getDepth() : 0); |
| 81 | } |
| 82 | |
Jamie Madill | b8f8b89 | 2014-01-07 10:12:50 -0500 | [diff] [blame] | 83 | // Note: "base level image" is loosely defined to be any image from the base level, |
| 84 | // where in the base of 2D array textures and cube maps there are several. Don't use |
| 85 | // the base level image for anything except querying texture format and size. |
Jamie Madill | d3d2a34 | 2013-10-07 10:46:35 -0400 | [diff] [blame] | 86 | GLenum Texture::getBaseLevelInternalFormat() const |
| 87 | { |
| 88 | const rx::Image *baseImage = getBaseLevelImage(); |
| 89 | return (baseImage ? baseImage->getInternalFormat() : GL_NONE); |
| 90 | } |
| 91 | |
Brandon Jones | 6b19b00 | 2014-07-16 14:32:05 -0700 | [diff] [blame] | 92 | // Tests for texture sampling completeness |
| 93 | bool Texture::isSamplerComplete(const SamplerState &samplerState) const |
| 94 | { |
| 95 | return getImplementation()->isSamplerComplete(samplerState); |
| 96 | } |
| 97 | |
| 98 | rx::TextureStorageInterface *Texture::getNativeTexture() |
| 99 | { |
| 100 | return getImplementation()->getNativeTexture(); |
| 101 | } |
| 102 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 103 | void Texture::generateMipmaps() |
| 104 | { |
| 105 | getImplementation()->generateMipmaps(); |
| 106 | } |
| 107 | |
Brandon Jones | 6b19b00 | 2014-07-16 14:32:05 -0700 | [diff] [blame] | 108 | void Texture::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) |
| 109 | { |
| 110 | getImplementation()->copySubImage(target, level, xoffset, yoffset, zoffset, x, y, width, height, source); |
| 111 | } |
| 112 | |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 113 | unsigned int Texture::getTextureSerial() |
| 114 | { |
| 115 | rx::TextureStorageInterface *texture = getNativeTexture(); |
| 116 | return texture ? texture->getTextureSerial() : 0; |
| 117 | } |
| 118 | |
| 119 | bool Texture::isImmutable() const |
| 120 | { |
| 121 | return mImmutable; |
| 122 | } |
| 123 | |
| 124 | int Texture::immutableLevelCount() |
| 125 | { |
| 126 | return (mImmutable ? getNativeTexture()->getStorageInstance()->getLevelCount() : 0); |
| 127 | } |
| 128 | |
| 129 | int Texture::mipLevels() const |
| 130 | { |
| 131 | return log2(std::max(std::max(getBaseLevelWidth(), getBaseLevelHeight()), getBaseLevelDepth())) + 1; |
| 132 | } |
| 133 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 134 | const rx::Image *Texture::getBaseLevelImage() const |
| 135 | { |
| 136 | return (getImplementation()->getLayerCount(0) > 0 ? getImplementation()->getImage(0, 0) : NULL); |
| 137 | } |
| 138 | |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 139 | Texture2D::Texture2D(rx::Texture2DImpl *impl, GLuint id) |
| 140 | : Texture(id, GL_TEXTURE_2D), |
| 141 | mTexture(impl) |
Jamie Madill | 22f843a | 2013-10-24 17:49:36 -0400 | [diff] [blame] | 142 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 143 | mSurface = NULL; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | Texture2D::~Texture2D() |
| 147 | { |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 148 | SafeDelete(mTexture); |
| 149 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 150 | if (mSurface) |
| 151 | { |
| 152 | mSurface->setBoundTexture(NULL); |
| 153 | mSurface = NULL; |
| 154 | } |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 155 | } |
daniel@transgaming.com | d9ec902 | 2012-12-20 20:52:16 +0000 | [diff] [blame] | 156 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 157 | GLsizei Texture2D::getWidth(GLint level) const |
| 158 | { |
| 159 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 160 | return mTexture->getImage(level, 0)->getWidth(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 161 | else |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | GLsizei Texture2D::getHeight(GLint level) const |
| 166 | { |
| 167 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 168 | return mTexture->getImage(level, 0)->getHeight(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 169 | else |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | GLenum Texture2D::getInternalFormat(GLint level) const |
| 174 | { |
| 175 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 176 | return mTexture->getImage(level, 0)->getInternalFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 177 | else |
| 178 | return GL_NONE; |
| 179 | } |
| 180 | |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 181 | GLenum Texture2D::getActualFormat(GLint level) const |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 182 | { |
| 183 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 184 | return mTexture->getImage(level, 0)->getActualFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 185 | else |
Geoff Lang | cbf727a | 2014-02-10 12:50:45 -0500 | [diff] [blame] | 186 | return GL_NONE; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 189 | 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] | 190 | { |
| 191 | releaseTexImage(); |
shannon.woods@transgaming.com | 8a40668 | 2013-02-28 23:15:26 +0000 | [diff] [blame] | 192 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 193 | 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] | 194 | } |
| 195 | |
| 196 | void Texture2D::bindTexImage(egl::Surface *surface) |
| 197 | { |
| 198 | releaseTexImage(); |
| 199 | |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 200 | mTexture->bindTexImage(surface); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 201 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 202 | mSurface = surface; |
| 203 | mSurface->setBoundTexture(this); |
| 204 | } |
| 205 | |
| 206 | void Texture2D::releaseTexImage() |
| 207 | { |
| 208 | if (mSurface) |
| 209 | { |
| 210 | mSurface->setBoundTexture(NULL); |
| 211 | mSurface = NULL; |
| 212 | |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 213 | mTexture->releaseTexImage(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | void Texture2D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei imageSize, const void *pixels) |
| 218 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 219 | releaseTexImage(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 220 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 221 | 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] | 222 | } |
| 223 | |
Jamie Madill | 88f18f4 | 2013-09-18 14:36:19 -0400 | [diff] [blame] | 224 | 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] | 225 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 226 | 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] | 227 | } |
| 228 | |
| 229 | void Texture2D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels) |
| 230 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 231 | 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] | 232 | } |
| 233 | |
| 234 | void Texture2D::copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) |
| 235 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 236 | releaseTexImage(); |
shannon.woods@transgaming.com | 8a40668 | 2013-02-28 23:15:26 +0000 | [diff] [blame] | 237 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 238 | 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] | 239 | } |
| 240 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 241 | void Texture2D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height) |
| 242 | { |
Jamie Madill | 73b5d06 | 2013-10-24 17:49:38 -0400 | [diff] [blame] | 243 | mImmutable = true; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 244 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 245 | mTexture->storage(GL_TEXTURE_2D, levels, internalformat, width, height, 1); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 246 | } |
| 247 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 248 | bool Texture2D::isCompressed(GLint level) const |
| 249 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 250 | return IsFormatCompressed(getInternalFormat(level)); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | bool Texture2D::isDepth(GLint level) const |
| 254 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 255 | return GetDepthBits(getInternalFormat(level)) > 0; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 256 | } |
| 257 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 258 | void Texture2D::generateMipmaps() |
| 259 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 260 | releaseTexImage(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 261 | |
Brandon Jones | f47bebc | 2014-07-09 14:28:42 -0700 | [diff] [blame] | 262 | mTexture->generateMipmaps(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 265 | unsigned int Texture2D::getRenderTargetSerial(GLint level) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 266 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 267 | return mTexture->getRenderTargetSerial(level, 0); |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | rx::RenderTarget *Texture2D::getRenderTarget(GLint level) |
| 271 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 272 | return mTexture->getRenderTarget(level, 0); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 275 | rx::RenderTarget *Texture2D::getDepthStencil(GLint level) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 276 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 277 | return mTexture->getDepthStencil(level, 0); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Brandon Jones | 0511e80 | 2014-07-14 16:27:26 -0700 | [diff] [blame] | 280 | TextureCubeMap::TextureCubeMap(rx::TextureCubeImpl *impl, GLuint id) |
| 281 | : Texture(id, GL_TEXTURE_CUBE_MAP), |
| 282 | mTexture(impl) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 283 | { |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | TextureCubeMap::~TextureCubeMap() |
| 287 | { |
Brandon Jones | 0511e80 | 2014-07-14 16:27:26 -0700 | [diff] [blame] | 288 | SafeDelete(mTexture); |
| 289 | } |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 290 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 291 | GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const |
| 292 | { |
| 293 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 294 | return mTexture->getImage(level, targetToLayerIndex(target))->getWidth(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 295 | else |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | GLsizei TextureCubeMap::getHeight(GLenum target, GLint level) const |
| 300 | { |
| 301 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 302 | return mTexture->getImage(level, targetToLayerIndex(target))->getHeight(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 303 | else |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | GLenum TextureCubeMap::getInternalFormat(GLenum target, GLint level) const |
| 308 | { |
| 309 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 310 | return mTexture->getImage(level, targetToLayerIndex(target))->getInternalFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 311 | else |
| 312 | return GL_NONE; |
| 313 | } |
| 314 | |
daniel@transgaming.com | 20d3666 | 2012-10-31 19:51:43 +0000 | [diff] [blame] | 315 | GLenum TextureCubeMap::getActualFormat(GLenum target, GLint level) const |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 316 | { |
| 317 | if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 318 | return mTexture->getImage(level, targetToLayerIndex(target))->getActualFormat(); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 319 | else |
Geoff Lang | cbf727a | 2014-02-10 12:50:45 -0500 | [diff] [blame] | 320 | return GL_NONE; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 323 | 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] | 324 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 325 | 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] | 326 | } |
| 327 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 328 | 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] | 329 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 330 | 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] | 331 | } |
| 332 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 333 | 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] | 334 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 335 | 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] | 336 | } |
| 337 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 338 | 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] | 339 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 340 | 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] | 341 | } |
| 342 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 343 | 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] | 344 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 345 | mTexture->setImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, width, height, 4, internalFormat, format, type, unpack, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 348 | 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] | 349 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 350 | mTexture->setImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, width, height, 5, internalFormat, format, type, unpack, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Jamie Madill | 2db197c | 2013-10-24 17:49:35 -0400 | [diff] [blame] | 353 | 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] | 354 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 355 | mTexture->setCompressedImage(target, level, format, width, height, 1, imageSize, pixels); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Jamie Madill | 88f18f4 | 2013-09-18 14:36:19 -0400 | [diff] [blame] | 358 | 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] | 359 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 360 | 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] | 361 | } |
| 362 | |
| 363 | void TextureCubeMap::subImageCompressed(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *pixels) |
| 364 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 365 | 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] | 366 | } |
| 367 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 368 | // Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. |
| 369 | bool TextureCubeMap::isCubeComplete() const |
| 370 | { |
Brandon Jones | 0511e80 | 2014-07-14 16:27:26 -0700 | [diff] [blame] | 371 | return mTexture->isCubeComplete(); |
Jamie Madill | 07edd44 | 2013-07-19 16:36:58 -0400 | [diff] [blame] | 372 | } |
| 373 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 374 | bool TextureCubeMap::isCompressed(GLenum target, GLint level) const |
| 375 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 376 | return IsFormatCompressed(getInternalFormat(target, level)); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 379 | bool TextureCubeMap::isDepth(GLenum target, GLint level) const |
| 380 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 381 | return GetDepthBits(getInternalFormat(target, level)) > 0; |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 382 | } |
| 383 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 384 | void TextureCubeMap::copyImage(GLenum target, GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source) |
| 385 | { |
Brandon Jones | 0511e80 | 2014-07-14 16:27:26 -0700 | [diff] [blame] | 386 | mTexture->copyImage(target, level, format, x, y, width, height, source); |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 387 | } |
| 388 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 389 | void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size) |
| 390 | { |
Jamie Madill | 3c0989c | 2013-10-24 17:49:39 -0400 | [diff] [blame] | 391 | mImmutable = true; |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 392 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 393 | mTexture->storage(GL_TEXTURE_CUBE_MAP, levels, internalformat, size, size, 1); |
Jamie Madill | 2ebab85 | 2013-10-24 17:49:42 -0400 | [diff] [blame] | 394 | } |
| 395 | |
Jamie Madill | 2db197c | 2013-10-24 17:49:35 -0400 | [diff] [blame] | 396 | unsigned int TextureCubeMap::getRenderTargetSerial(GLenum target, GLint level) |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 397 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 398 | return mTexture->getRenderTargetSerial(level, targetToLayerIndex(target)); |
| 399 | } |
| 400 | |
| 401 | int TextureCubeMap::targetToLayerIndex(GLenum target) |
| 402 | { |
| 403 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1); |
| 404 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2); |
| 405 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3); |
| 406 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4); |
| 407 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5); |
| 408 | |
| 409 | return target - GL_TEXTURE_CUBE_MAP_POSITIVE_X; |
| 410 | } |
| 411 | |
| 412 | GLenum TextureCubeMap::layerIndexToTarget(GLint layer) |
| 413 | { |
| 414 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_X - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 1); |
| 415 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 2); |
| 416 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 3); |
| 417 | META_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 4); |
| 418 | META_ASSERT(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - GL_TEXTURE_CUBE_MAP_POSITIVE_X == 5); |
| 419 | |
| 420 | return GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | rx::RenderTarget *TextureCubeMap::getRenderTarget(GLenum target, GLint level) |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 424 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 425 | return mTexture->getRenderTarget(level, targetToLayerIndex(target)); |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | rx::RenderTarget *TextureCubeMap::getDepthStencil(GLenum target, GLint level) |
| 429 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 430 | return mTexture->getDepthStencil(level, targetToLayerIndex(target)); |
daniel@transgaming.com | 690d8ae | 2012-10-31 19:52:08 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 433 | Texture3D::Texture3D(rx::Texture3DImpl *impl, GLuint id) |
| 434 | : Texture(id, GL_TEXTURE_3D), |
| 435 | mTexture(impl) |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 436 | { |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | Texture3D::~Texture3D() |
| 440 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 441 | SafeDelete(mTexture); |
| 442 | } |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 443 | |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 444 | GLsizei Texture3D::getWidth(GLint level) const |
| 445 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 446 | 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] | 447 | } |
| 448 | |
| 449 | GLsizei Texture3D::getHeight(GLint level) const |
| 450 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 451 | 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] | 452 | } |
| 453 | |
| 454 | GLsizei Texture3D::getDepth(GLint level) const |
| 455 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 456 | 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] | 457 | } |
| 458 | |
| 459 | GLenum Texture3D::getInternalFormat(GLint level) const |
| 460 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 461 | 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] | 462 | } |
| 463 | |
| 464 | GLenum Texture3D::getActualFormat(GLint level) const |
| 465 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 466 | 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] | 467 | } |
| 468 | |
| 469 | bool Texture3D::isCompressed(GLint level) const |
| 470 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 471 | return IsFormatCompressed(getInternalFormat(level)); |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | bool Texture3D::isDepth(GLint level) const |
| 475 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 476 | return GetDepthBits(getInternalFormat(level)) > 0; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 479 | 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] | 480 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 481 | 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] | 482 | } |
| 483 | |
| 484 | void Texture3D::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels) |
| 485 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 486 | 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] | 487 | } |
| 488 | |
Jamie Madill | 88f18f4 | 2013-09-18 14:36:19 -0400 | [diff] [blame] | 489 | 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] | 490 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 491 | 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] | 492 | } |
| 493 | |
| 494 | void Texture3D::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels) |
| 495 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 496 | 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] | 497 | } |
| 498 | |
| 499 | void Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) |
| 500 | { |
Jamie Madill | e664e20 | 2013-10-24 17:49:40 -0400 | [diff] [blame] | 501 | mImmutable = true; |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 502 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 503 | mTexture->storage(GL_TEXTURE_3D, levels, internalformat, width, height, depth); |
Jamie Madill | 2ebab85 | 2013-10-24 17:49:42 -0400 | [diff] [blame] | 504 | } |
| 505 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 506 | unsigned int Texture3D::getRenderTargetSerial(GLint level, GLint layer) |
| 507 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 508 | return mTexture->getRenderTargetSerial(level, layer); |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Jamie Madill | a2d4e55 | 2013-10-10 15:12:01 -0400 | [diff] [blame] | 511 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 512 | rx::RenderTarget *Texture3D::getRenderTarget(GLint level, GLint layer) |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 513 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 514 | return mTexture->getRenderTarget(level, layer); |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | rx::RenderTarget *Texture3D::getDepthStencil(GLint level, GLint layer) |
| 518 | { |
Brandon Jones | 78b1acd | 2014-07-15 15:33:07 -0700 | [diff] [blame] | 519 | return mTexture->getDepthStencil(level, layer); |
shannon.woods%transgaming.com@gtempaccount.com | 9599656 | 2013-04-13 03:44:58 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 522 | Texture2DArray::Texture2DArray(rx::Texture2DArrayImpl *impl, GLuint id) |
| 523 | : Texture(id, GL_TEXTURE_2D_ARRAY), |
| 524 | mTexture(impl) |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 525 | { |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | Texture2DArray::~Texture2DArray() |
| 529 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 530 | SafeDelete(mTexture); |
Jamie Madill | 884a462 | 2013-10-24 17:49:41 -0400 | [diff] [blame] | 531 | } |
| 532 | |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 533 | GLsizei Texture2DArray::getWidth(GLint level) const |
| 534 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 535 | 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] | 536 | } |
| 537 | |
| 538 | GLsizei Texture2DArray::getHeight(GLint level) const |
| 539 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 540 | 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] | 541 | } |
| 542 | |
Jamie Madill | b8f8b89 | 2014-01-07 10:12:50 -0500 | [diff] [blame] | 543 | GLsizei Texture2DArray::getLayers(GLint level) const |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 544 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 545 | 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] | 546 | } |
| 547 | |
| 548 | GLenum Texture2DArray::getInternalFormat(GLint level) const |
| 549 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 550 | 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] | 551 | } |
| 552 | |
| 553 | GLenum Texture2DArray::getActualFormat(GLint level) const |
| 554 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 555 | 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] | 556 | } |
| 557 | |
| 558 | bool Texture2DArray::isCompressed(GLint level) const |
| 559 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 560 | return IsFormatCompressed(getInternalFormat(level)); |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | bool Texture2DArray::isDepth(GLint level) const |
| 564 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 565 | return GetDepthBits(getInternalFormat(level)) > 0; |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Geoff Lang | 005df41 | 2013-10-16 14:12:50 -0400 | [diff] [blame] | 568 | 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] | 569 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 570 | 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] | 571 | } |
| 572 | |
| 573 | void Texture2DArray::setCompressedImage(GLint level, GLenum format, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels) |
| 574 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 575 | 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] | 576 | } |
| 577 | |
Jamie Madill | 88f18f4 | 2013-09-18 14:36:19 -0400 | [diff] [blame] | 578 | 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] | 579 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 580 | 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] | 581 | } |
| 582 | |
| 583 | void Texture2DArray::subImageCompressed(GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *pixels) |
| 584 | { |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 585 | 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] | 586 | } |
| 587 | |
| 588 | void Texture2DArray::storage(GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) |
| 589 | { |
Jamie Madill | 884a462 | 2013-10-24 17:49:41 -0400 | [diff] [blame] | 590 | mImmutable = true; |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 591 | |
Brandon Jones | 8c9038d | 2014-07-21 09:43:22 -0700 | [diff] [blame^] | 592 | mTexture->storage(GL_TEXTURE_2D_ARRAY, levels, internalformat, width, height, depth); |
Jamie Madill | 2ebab85 | 2013-10-24 17:49:42 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Jamie Madill | e83d1a9 | 2013-10-24 17:49:33 -0400 | [diff] [blame] | 595 | unsigned int Texture2DArray::getRenderTargetSerial(GLint level, GLint layer) |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 596 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 597 | return mTexture->getRenderTargetSerial(level, layer); |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 598 | } |
| 599 | |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 600 | rx::RenderTarget *Texture2DArray::getRenderTarget(GLint level, GLint layer) |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 601 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 602 | return mTexture->getRenderTarget(level, layer); |
Geoff Lang | 8040f57 | 2013-07-25 16:49:54 -0400 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | rx::RenderTarget *Texture2DArray::getDepthStencil(GLint level, GLint layer) |
| 606 | { |
Brandon Jones | 142ec42 | 2014-07-16 10:31:30 -0700 | [diff] [blame] | 607 | return mTexture->getDepthStencil(level, layer); |
shannon.woods%transgaming.com@gtempaccount.com | 7625f79 | 2013-04-13 03:46:07 +0000 | [diff] [blame] | 608 | } |
| 609 | |
daniel@transgaming.com | 95a758f | 2012-07-12 15:17:06 +0000 | [diff] [blame] | 610 | } |