Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 The ANGLE Project Authors. All rights reserved. |
| 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 | // TextureGL.cpp: Implements the class methods for TextureGL. |
| 8 | |
| 9 | #include "libANGLE/renderer/gl/TextureGL.h" |
| 10 | |
| 11 | #include "common/debug.h" |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 12 | #include "common/utilities.h" |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 13 | #include "libANGLE/State.h" |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 14 | #include "libANGLE/angletypes.h" |
| 15 | #include "libANGLE/formatutils.h" |
| 16 | #include "libANGLE/renderer/gl/BufferGL.h" |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 17 | #include "libANGLE/renderer/gl/FramebufferGL.h" |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 18 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
| 19 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 20 | |
| 21 | namespace rx |
| 22 | { |
| 23 | |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 24 | static void SetUnpackStateForTexImage(StateManagerGL *stateManager, const gl::PixelUnpackState &unpack) |
| 25 | { |
| 26 | const gl::Buffer *unpackBuffer = unpack.pixelBuffer.get(); |
| 27 | if (unpackBuffer != nullptr) |
| 28 | { |
| 29 | UNIMPLEMENTED(); |
| 30 | } |
| 31 | if (unpack.skipRows != 0 || unpack.skipPixels != 0 || unpack.imageHeight != 0 || unpack.skipImages != 0) |
| 32 | { |
| 33 | UNIMPLEMENTED(); |
| 34 | } |
| 35 | stateManager->setPixelUnpackState(unpack.alignment, unpack.rowLength); |
| 36 | } |
| 37 | |
| 38 | static bool UseTexImage2D(GLenum textureType) |
| 39 | { |
| 40 | return textureType == GL_TEXTURE_2D || textureType == GL_TEXTURE_CUBE_MAP; |
| 41 | } |
| 42 | |
| 43 | static bool UseTexImage3D(GLenum textureType) |
| 44 | { |
| 45 | return textureType == GL_TEXTURE_2D_ARRAY || textureType == GL_TEXTURE_3D; |
| 46 | } |
| 47 | |
Geoff Lang | 968992e | 2015-03-17 18:01:49 -0400 | [diff] [blame] | 48 | static bool CompatibleTextureTarget(GLenum textureType, GLenum textureTarget) |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 49 | { |
| 50 | if (textureType != GL_TEXTURE_CUBE_MAP) |
| 51 | { |
| 52 | return textureType == textureTarget; |
| 53 | } |
| 54 | else |
| 55 | { |
Geoff Lang | fb2a559 | 2015-03-20 11:25:37 -0400 | [diff] [blame] | 56 | return gl::IsCubeMapTextureTarget(textureTarget); |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
| 60 | TextureGL::TextureGL(GLenum type, const FunctionsGL *functions, StateManagerGL *stateManager) |
| 61 | : TextureImpl(), |
| 62 | mTextureType(type), |
| 63 | mFunctions(functions), |
| 64 | mStateManager(stateManager), |
| 65 | mAppliedSamplerState(), |
| 66 | mTextureID(0) |
| 67 | { |
| 68 | ASSERT(mFunctions); |
| 69 | ASSERT(mStateManager); |
| 70 | |
| 71 | mFunctions->genTextures(1, &mTextureID); |
| 72 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 73 | |
| 74 | TextureGL::~TextureGL() |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 75 | { |
Geoff Lang | 1eb708e | 2015-05-04 14:58:23 -0400 | [diff] [blame^] | 76 | mStateManager->deleteTexture(mTextureID); |
| 77 | mTextureID = 0; |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 78 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 79 | |
| 80 | void TextureGL::setUsage(GLenum usage) |
| 81 | { |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 82 | // GL_ANGLE_texture_usage not implemented for desktop GL |
| 83 | UNREACHABLE(); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | gl::Error TextureGL::setImage(GLenum target, size_t level, GLenum internalFormat, const gl::Extents &size, GLenum format, GLenum type, |
| 87 | const gl::PixelUnpackState &unpack, const uint8_t *pixels) |
| 88 | { |
Geoff Lang | fb2a559 | 2015-03-20 11:25:37 -0400 | [diff] [blame] | 89 | UNUSED_ASSERTION_VARIABLE(&CompatibleTextureTarget); // Reference this function to avoid warnings. |
Geoff Lang | 968992e | 2015-03-17 18:01:49 -0400 | [diff] [blame] | 90 | ASSERT(CompatibleTextureTarget(mTextureType, target)); |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 91 | |
| 92 | SetUnpackStateForTexImage(mStateManager, unpack); |
| 93 | |
| 94 | mStateManager->bindTexture(mTextureType, mTextureID); |
| 95 | if (UseTexImage2D(mTextureType)) |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 96 | { |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 97 | ASSERT(size.depth == 1); |
| 98 | mFunctions->texImage2D(target, level, internalFormat, size.width, size.height, 0, format, type, pixels); |
| 99 | } |
| 100 | else if (UseTexImage3D(mTextureType)) |
| 101 | { |
| 102 | mFunctions->texImage3D(target, level, internalFormat, size.width, size.height, size.depth, 0, format, type, pixels); |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | UNREACHABLE(); |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 109 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | gl::Error TextureGL::setSubImage(GLenum target, size_t level, const gl::Box &area, GLenum format, GLenum type, |
| 113 | const gl::PixelUnpackState &unpack, const uint8_t *pixels) |
| 114 | { |
Geoff Lang | 968992e | 2015-03-17 18:01:49 -0400 | [diff] [blame] | 115 | ASSERT(CompatibleTextureTarget(mTextureType, target)); |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 116 | |
| 117 | SetUnpackStateForTexImage(mStateManager, unpack); |
| 118 | |
| 119 | mStateManager->bindTexture(mTextureType, mTextureID); |
| 120 | if (UseTexImage2D(mTextureType)) |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 121 | { |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 122 | ASSERT(area.z == 0 && area.depth == 1); |
| 123 | mFunctions->texSubImage2D(target, level, area.x, area.y, area.width, area.height, format, type, pixels); |
| 124 | } |
| 125 | else if (UseTexImage3D(mTextureType)) |
| 126 | { |
| 127 | mFunctions->texSubImage3D(target, level, area.x, area.y, area.z, area.width, area.height, area.depth, |
| 128 | format, type, pixels); |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | UNREACHABLE(); |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 135 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | gl::Error TextureGL::setCompressedImage(GLenum target, size_t level, GLenum internalFormat, const gl::Extents &size, |
| 139 | const gl::PixelUnpackState &unpack, const uint8_t *pixels) |
| 140 | { |
Geoff Lang | 968992e | 2015-03-17 18:01:49 -0400 | [diff] [blame] | 141 | ASSERT(CompatibleTextureTarget(mTextureType, target)); |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 142 | |
| 143 | SetUnpackStateForTexImage(mStateManager, unpack); |
| 144 | |
| 145 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 146 | size_t depthPitch = internalFormatInfo.computeDepthPitch(GL_UNSIGNED_BYTE, size.width, size.height, |
| 147 | unpack.alignment, unpack.rowLength); |
| 148 | size_t dataSize = internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, size.width, size.height) * depthPitch; |
| 149 | |
| 150 | mStateManager->bindTexture(mTextureType, mTextureID); |
| 151 | if (UseTexImage2D(mTextureType)) |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 152 | { |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 153 | ASSERT(size.depth == 1); |
| 154 | mFunctions->compressedTexImage2D(target, level, internalFormat, size.width, size.height, 0, dataSize, pixels); |
| 155 | } |
| 156 | else if (UseTexImage3D(mTextureType)) |
| 157 | { |
| 158 | mFunctions->compressedTexImage3D(target, level, internalFormat, size.width, size.height, size.depth, 0, |
| 159 | dataSize, pixels); |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | UNREACHABLE(); |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 166 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | gl::Error TextureGL::setCompressedSubImage(GLenum target, size_t level, const gl::Box &area, GLenum format, |
| 170 | const gl::PixelUnpackState &unpack, const uint8_t *pixels) |
| 171 | { |
Geoff Lang | 968992e | 2015-03-17 18:01:49 -0400 | [diff] [blame] | 172 | ASSERT(CompatibleTextureTarget(mTextureType, target)); |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 173 | |
| 174 | SetUnpackStateForTexImage(mStateManager, unpack); |
| 175 | |
| 176 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(format); |
| 177 | size_t depthPitch = internalFormatInfo.computeDepthPitch(GL_UNSIGNED_BYTE, area.width, area.height, |
| 178 | unpack.alignment, unpack.rowLength); |
| 179 | size_t dataSize = internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, area.width, area.height) * depthPitch; |
| 180 | |
| 181 | mStateManager->bindTexture(mTextureType, mTextureID); |
| 182 | if (UseTexImage2D(mTextureType)) |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 183 | { |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 184 | ASSERT(area.z == 0 && area.depth == 1); |
| 185 | mFunctions->compressedTexSubImage2D(target, level, area.x, area.y, area.width, area.height, format, dataSize, |
| 186 | pixels); |
| 187 | } |
| 188 | else if (UseTexImage3D(mTextureType)) |
| 189 | { |
| 190 | mFunctions->compressedTexSubImage3D(target, level, area.x, area.y, area.z, area.width, area.height, area.depth, |
| 191 | format, dataSize, pixels); |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | UNREACHABLE(); |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 196 | } |
| 197 | |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 198 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | gl::Error TextureGL::copyImage(GLenum target, size_t level, const gl::Rectangle &sourceArea, GLenum internalFormat, |
| 202 | const gl::Framebuffer *source) |
| 203 | { |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 204 | const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(source); |
| 205 | |
| 206 | mStateManager->bindTexture(mTextureType, mTextureID); |
| 207 | mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID()); |
| 208 | |
| 209 | if (UseTexImage2D(mTextureType)) |
| 210 | { |
| 211 | mFunctions->copyTexImage2D(target, level, internalFormat, sourceArea.x, sourceArea.y, |
| 212 | sourceArea.width, sourceArea.height, 0); |
| 213 | } |
| 214 | else |
| 215 | { |
| 216 | UNREACHABLE(); |
| 217 | } |
| 218 | |
| 219 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | gl::Error TextureGL::copySubImage(GLenum target, size_t level, const gl::Offset &destOffset, const gl::Rectangle &sourceArea, |
| 223 | const gl::Framebuffer *source) |
| 224 | { |
Geoff Lang | fbfa47c | 2015-03-31 11:26:00 -0400 | [diff] [blame] | 225 | const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(source); |
| 226 | |
| 227 | mStateManager->bindTexture(mTextureType, mTextureID); |
| 228 | mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID()); |
| 229 | |
| 230 | if (UseTexImage2D(mTextureType)) |
| 231 | { |
| 232 | ASSERT(destOffset.z == 0); |
| 233 | mFunctions->copyTexSubImage2D(target, level, destOffset.x, destOffset.y, |
| 234 | sourceArea.x, sourceArea.y, sourceArea.width, sourceArea.height); |
| 235 | } |
| 236 | else if (UseTexImage3D(mTextureType)) |
| 237 | { |
| 238 | mFunctions->copyTexSubImage3D(target, level, destOffset.x, destOffset.y, destOffset.z, |
| 239 | sourceArea.x, sourceArea.y, sourceArea.width, sourceArea.height); |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | UNREACHABLE(); |
| 244 | } |
| 245 | |
| 246 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFormat, const gl::Extents &size) |
| 250 | { |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 251 | // TODO: emulate texture storage with TexImage calls if on GL version <4.2 or the |
| 252 | // ARB_texture_storage extension is not available. |
| 253 | |
| 254 | mStateManager->bindTexture(mTextureType, mTextureID); |
| 255 | if (UseTexImage2D(mTextureType)) |
| 256 | { |
| 257 | ASSERT(size.depth == 1); |
Geoff Lang | 1c0ad62 | 2015-03-24 10:27:45 -0400 | [diff] [blame] | 258 | if (mFunctions->texStorage2D) |
| 259 | { |
| 260 | mFunctions->texStorage2D(target, levels, internalFormat, size.width, size.height); |
| 261 | } |
| 262 | else |
| 263 | { |
| 264 | // Make sure no pixel unpack buffer is bound |
| 265 | mStateManager->bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); |
| 266 | |
| 267 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 268 | |
| 269 | // Internal format must be sized |
| 270 | ASSERT(internalFormatInfo.pixelBytes != 0); |
| 271 | |
| 272 | for (size_t level = 0; level < levels; level++) |
| 273 | { |
| 274 | gl::Extents levelSize(std::max(size.width >> level, 1), |
| 275 | std::max(size.height >> level, 1), |
| 276 | 1); |
| 277 | |
| 278 | if (mTextureType == GL_TEXTURE_2D) |
| 279 | { |
| 280 | mFunctions->texImage2D(target, level, internalFormat, levelSize.width, levelSize.height, |
| 281 | 0, internalFormatInfo.format, internalFormatInfo.type, nullptr); |
| 282 | } |
| 283 | else if (mTextureType == GL_TEXTURE_CUBE_MAP) |
| 284 | { |
| 285 | for (GLenum face = gl::FirstCubeMapTextureTarget; face <= gl::LastCubeMapTextureTarget; face++) |
| 286 | { |
| 287 | mFunctions->texImage2D(face, level, internalFormat, levelSize.width, levelSize.height, |
| 288 | 0, internalFormatInfo.format, internalFormatInfo.type, nullptr); |
| 289 | } |
| 290 | } |
| 291 | else |
| 292 | { |
| 293 | UNREACHABLE(); |
| 294 | } |
| 295 | } |
| 296 | } |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 297 | } |
| 298 | else if (UseTexImage3D(mTextureType)) |
| 299 | { |
Geoff Lang | 1c0ad62 | 2015-03-24 10:27:45 -0400 | [diff] [blame] | 300 | if (mFunctions->texStorage3D) |
| 301 | { |
| 302 | mFunctions->texStorage3D(target, levels, internalFormat, size.width, size.height, size.depth); |
| 303 | } |
| 304 | else |
| 305 | { |
| 306 | // Make sure no pixel unpack buffer is bound |
| 307 | mStateManager->bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); |
| 308 | |
| 309 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 310 | |
| 311 | // Internal format must be sized |
| 312 | ASSERT(internalFormatInfo.pixelBytes != 0); |
| 313 | |
| 314 | for (size_t i = 0; i < levels; i++) |
| 315 | { |
| 316 | gl::Extents levelSize(std::max(size.width >> i, 1), |
| 317 | std::max(size.height >> i, 1), |
| 318 | mTextureType == GL_TEXTURE_3D ? std::max(size.depth >> i, 1) : size.depth); |
| 319 | |
| 320 | mFunctions->texImage3D(target, i, internalFormat, levelSize.width, levelSize.height, levelSize.depth, |
| 321 | 0, internalFormatInfo.format, internalFormatInfo.type, nullptr); |
| 322 | } |
| 323 | } |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 324 | } |
| 325 | else |
| 326 | { |
| 327 | UNREACHABLE(); |
| 328 | } |
| 329 | |
| 330 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 331 | } |
| 332 | |
Gregoire Payen de La Garanderie | 752ce19 | 2015-04-14 11:11:12 +0100 | [diff] [blame] | 333 | gl::Error TextureGL::generateMipmaps(const gl::SamplerState &samplerState) |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 334 | { |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 335 | mStateManager->bindTexture(mTextureType, mTextureID); |
| 336 | mFunctions->generateMipmap(mTextureType); |
| 337 | return gl::Error(GL_NO_ERROR); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | void TextureGL::bindTexImage(egl::Surface *surface) |
| 341 | { |
Geoff Lang | 0305320 | 2015-04-09 11:21:13 -0400 | [diff] [blame] | 342 | ASSERT(mTextureType == GL_TEXTURE_2D); |
| 343 | |
| 344 | // Make sure this texture is bound |
| 345 | mStateManager->bindTexture(mTextureType, mTextureID); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | void TextureGL::releaseTexImage() |
| 349 | { |
Geoff Lang | 0305320 | 2015-04-09 11:21:13 -0400 | [diff] [blame] | 350 | // Not all Surface implementations reset the size of mip 0 when releasing, do it manually |
| 351 | ASSERT(mTextureType == GL_TEXTURE_2D); |
| 352 | |
| 353 | mStateManager->bindTexture(mTextureType, mTextureID); |
| 354 | if (UseTexImage2D(mTextureType)) |
| 355 | { |
| 356 | mFunctions->texImage2D(mTextureType, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 357 | } |
| 358 | else |
| 359 | { |
| 360 | UNREACHABLE(); |
| 361 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 362 | } |
| 363 | |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 364 | template <typename T> |
| 365 | static inline void SyncSamplerStateMember(const FunctionsGL *functions, const gl::SamplerState &newState, |
| 366 | gl::SamplerState &curState, GLenum textureType, GLenum name, |
| 367 | T(gl::SamplerState::*samplerMember)) |
| 368 | { |
| 369 | if (curState.*samplerMember != newState.*samplerMember) |
| 370 | { |
| 371 | curState.*samplerMember = newState.*samplerMember; |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 372 | functions->texParameterf(textureType, name, static_cast<GLfloat>(curState.*samplerMember)); |
Geoff Lang | c05f706 | 2015-03-10 09:50:57 -0700 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
| 376 | void TextureGL::syncSamplerState(const gl::SamplerState &samplerState) const |
| 377 | { |
| 378 | if (mAppliedSamplerState != samplerState) |
| 379 | { |
| 380 | mStateManager->bindTexture(mTextureType, mTextureID); |
| 381 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MIN_FILTER, &gl::SamplerState::minFilter); |
| 382 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MAG_FILTER, &gl::SamplerState::magFilter); |
| 383 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_WRAP_S, &gl::SamplerState::wrapS); |
| 384 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_WRAP_T, &gl::SamplerState::wrapT); |
| 385 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_WRAP_R, &gl::SamplerState::wrapR); |
| 386 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MAX_ANISOTROPY_EXT, &gl::SamplerState::maxAnisotropy); |
| 387 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_BASE_LEVEL, &gl::SamplerState::baseLevel); |
| 388 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MAX_LEVEL, &gl::SamplerState::maxLevel); |
| 389 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MIN_LOD, &gl::SamplerState::minLod); |
| 390 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MAX_LOD, &gl::SamplerState::maxLod); |
| 391 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_COMPARE_MODE, &gl::SamplerState::compareMode); |
| 392 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_COMPARE_FUNC, &gl::SamplerState::compareFunc); |
| 393 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_SWIZZLE_R, &gl::SamplerState::swizzleRed); |
| 394 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_SWIZZLE_G, &gl::SamplerState::swizzleGreen); |
| 395 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_SWIZZLE_B, &gl::SamplerState::swizzleBlue); |
| 396 | SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_SWIZZLE_A, &gl::SamplerState::swizzleAlpha); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | GLuint TextureGL::getTextureID() const |
| 401 | { |
| 402 | return mTextureID; |
| 403 | } |
| 404 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 405 | } |