blob: 6dca94af18ae0da835a605079f27c2f1525a8c77 [file] [log] [blame]
Geoff Langf9a6f082015-01-22 13:32:49 -05001//
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 Langc05f7062015-03-10 09:50:57 -070012#include "common/utilities.h"
Jamie Madill67102f02015-03-16 10:41:42 -040013#include "libANGLE/State.h"
Geoff Langc05f7062015-03-10 09:50:57 -070014#include "libANGLE/angletypes.h"
15#include "libANGLE/formatutils.h"
16#include "libANGLE/renderer/gl/BufferGL.h"
Geoff Langfbfa47c2015-03-31 11:26:00 -040017#include "libANGLE/renderer/gl/FramebufferGL.h"
Geoff Langc05f7062015-03-10 09:50:57 -070018#include "libANGLE/renderer/gl/FunctionsGL.h"
19#include "libANGLE/renderer/gl/StateManagerGL.h"
Geoff Lang14389cc2015-07-23 10:57:20 -040020#include "libANGLE/renderer/gl/WorkaroundsGL.h"
Geoff Langfd216c42015-05-27 16:12:30 -040021#include "libANGLE/renderer/gl/formatutilsgl.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050022
23namespace rx
24{
25
Geoff Langc05f7062015-03-10 09:50:57 -070026static bool UseTexImage2D(GLenum textureType)
27{
28 return textureType == GL_TEXTURE_2D || textureType == GL_TEXTURE_CUBE_MAP;
29}
30
31static bool UseTexImage3D(GLenum textureType)
32{
33 return textureType == GL_TEXTURE_2D_ARRAY || textureType == GL_TEXTURE_3D;
34}
35
Geoff Lang968992e2015-03-17 18:01:49 -040036static bool CompatibleTextureTarget(GLenum textureType, GLenum textureTarget)
Geoff Langc05f7062015-03-10 09:50:57 -070037{
38 if (textureType != GL_TEXTURE_CUBE_MAP)
39 {
40 return textureType == textureTarget;
41 }
42 else
43 {
Geoff Langfb2a5592015-03-20 11:25:37 -040044 return gl::IsCubeMapTextureTarget(textureTarget);
Geoff Langc05f7062015-03-10 09:50:57 -070045 }
46}
47
Geoff Lang14389cc2015-07-23 10:57:20 -040048TextureGL::TextureGL(GLenum type,
49 const FunctionsGL *functions,
50 const WorkaroundsGL &workarounds,
51 StateManagerGL *stateManager)
Geoff Langc05f7062015-03-10 09:50:57 -070052 : TextureImpl(),
53 mTextureType(type),
54 mFunctions(functions),
Geoff Lang14389cc2015-07-23 10:57:20 -040055 mWorkarounds(workarounds),
Geoff Langc05f7062015-03-10 09:50:57 -070056 mStateManager(stateManager),
57 mAppliedSamplerState(),
58 mTextureID(0)
59{
60 ASSERT(mFunctions);
61 ASSERT(mStateManager);
62
63 mFunctions->genTextures(1, &mTextureID);
Geoff Lang90d98af2015-05-26 16:41:38 -040064 mStateManager->bindTexture(mTextureType, mTextureID);
Geoff Langc05f7062015-03-10 09:50:57 -070065}
Geoff Langf9a6f082015-01-22 13:32:49 -050066
67TextureGL::~TextureGL()
Geoff Langc05f7062015-03-10 09:50:57 -070068{
Geoff Lang1eb708e2015-05-04 14:58:23 -040069 mStateManager->deleteTexture(mTextureID);
70 mTextureID = 0;
Geoff Langc05f7062015-03-10 09:50:57 -070071}
Geoff Langf9a6f082015-01-22 13:32:49 -050072
73void TextureGL::setUsage(GLenum usage)
74{
Geoff Langc05f7062015-03-10 09:50:57 -070075 // GL_ANGLE_texture_usage not implemented for desktop GL
76 UNREACHABLE();
Geoff Langf9a6f082015-01-22 13:32:49 -050077}
78
79gl::Error TextureGL::setImage(GLenum target, size_t level, GLenum internalFormat, const gl::Extents &size, GLenum format, GLenum type,
80 const gl::PixelUnpackState &unpack, const uint8_t *pixels)
81{
Geoff Langfb2a5592015-03-20 11:25:37 -040082 UNUSED_ASSERTION_VARIABLE(&CompatibleTextureTarget); // Reference this function to avoid warnings.
Geoff Lang968992e2015-03-17 18:01:49 -040083 ASSERT(CompatibleTextureTarget(mTextureType, target));
Geoff Langc05f7062015-03-10 09:50:57 -070084
Geoff Lang23a2ae02015-07-28 12:42:52 -040085 nativegl::TexImageFormat texImageFormat =
86 nativegl::GetTexImageFormat(mFunctions, mWorkarounds, internalFormat, format, type);
Geoff Langfd216c42015-05-27 16:12:30 -040087
Geoff Langc05f7062015-03-10 09:50:57 -070088 mStateManager->bindTexture(mTextureType, mTextureID);
89 if (UseTexImage2D(mTextureType))
Jamie Madill67102f02015-03-16 10:41:42 -040090 {
Geoff Langc05f7062015-03-10 09:50:57 -070091 ASSERT(size.depth == 1);
Geoff Lang23a2ae02015-07-28 12:42:52 -040092 mFunctions->texImage2D(target, level, texImageFormat.internalFormat, size.width,
93 size.height, 0, texImageFormat.format, texImageFormat.type, pixels);
Geoff Langc05f7062015-03-10 09:50:57 -070094 }
95 else if (UseTexImage3D(mTextureType))
96 {
Geoff Lang23a2ae02015-07-28 12:42:52 -040097 mFunctions->texImage3D(target, level, texImageFormat.internalFormat, size.width,
98 size.height, size.depth, 0, texImageFormat.format,
99 texImageFormat.type, pixels);
Geoff Langc05f7062015-03-10 09:50:57 -0700100 }
101 else
102 {
103 UNREACHABLE();
Jamie Madill67102f02015-03-16 10:41:42 -0400104 }
105
Geoff Langc05f7062015-03-10 09:50:57 -0700106 return gl::Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500107}
108
109gl::Error TextureGL::setSubImage(GLenum target, size_t level, const gl::Box &area, GLenum format, GLenum type,
110 const gl::PixelUnpackState &unpack, const uint8_t *pixels)
111{
Geoff Lang968992e2015-03-17 18:01:49 -0400112 ASSERT(CompatibleTextureTarget(mTextureType, target));
Geoff Langc05f7062015-03-10 09:50:57 -0700113
Geoff Lang23a2ae02015-07-28 12:42:52 -0400114 nativegl::TexSubImageFormat texSubImageFormat =
115 nativegl::GetTexSubImageFormat(mFunctions, mWorkarounds, format, type);
116
Geoff Langc05f7062015-03-10 09:50:57 -0700117 mStateManager->bindTexture(mTextureType, mTextureID);
118 if (UseTexImage2D(mTextureType))
Jamie Madill67102f02015-03-16 10:41:42 -0400119 {
Geoff Langc05f7062015-03-10 09:50:57 -0700120 ASSERT(area.z == 0 && area.depth == 1);
Geoff Lang23a2ae02015-07-28 12:42:52 -0400121 mFunctions->texSubImage2D(target, level, area.x, area.y, area.width, area.height,
122 texSubImageFormat.format, texSubImageFormat.type, pixels);
Geoff Langc05f7062015-03-10 09:50:57 -0700123 }
124 else if (UseTexImage3D(mTextureType))
125 {
Geoff Lang23a2ae02015-07-28 12:42:52 -0400126 mFunctions->texSubImage3D(target, level, area.x, area.y, area.z, area.width, area.height,
127 area.depth, texSubImageFormat.format, texSubImageFormat.type,
128 pixels);
Geoff Langc05f7062015-03-10 09:50:57 -0700129 }
130 else
131 {
132 UNREACHABLE();
Jamie Madill67102f02015-03-16 10:41:42 -0400133 }
134
Geoff Langc05f7062015-03-10 09:50:57 -0700135 return gl::Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500136}
137
138gl::Error TextureGL::setCompressedImage(GLenum target, size_t level, GLenum internalFormat, const gl::Extents &size,
Geoff Lang8509d862015-05-20 14:06:13 -0400139 const gl::PixelUnpackState &unpack, size_t imageSize, const uint8_t *pixels)
Geoff Langf9a6f082015-01-22 13:32:49 -0500140{
Geoff Lang968992e2015-03-17 18:01:49 -0400141 ASSERT(CompatibleTextureTarget(mTextureType, target));
Geoff Langc05f7062015-03-10 09:50:57 -0700142
Geoff Lang23a2ae02015-07-28 12:42:52 -0400143 nativegl::CompressedTexImageFormat compressedTexImageFormat =
144 nativegl::GetCompressedTexImageFormat(mFunctions, mWorkarounds, internalFormat);
Geoff Langfd216c42015-05-27 16:12:30 -0400145
Geoff Langc05f7062015-03-10 09:50:57 -0700146 mStateManager->bindTexture(mTextureType, mTextureID);
147 if (UseTexImage2D(mTextureType))
Jamie Madill67102f02015-03-16 10:41:42 -0400148 {
Geoff Langc05f7062015-03-10 09:50:57 -0700149 ASSERT(size.depth == 1);
Geoff Lang23a2ae02015-07-28 12:42:52 -0400150 mFunctions->compressedTexImage2D(target, level, compressedTexImageFormat.internalFormat,
151 size.width, size.height, 0, imageSize, pixels);
Geoff Langc05f7062015-03-10 09:50:57 -0700152 }
153 else if (UseTexImage3D(mTextureType))
154 {
Geoff Lang23a2ae02015-07-28 12:42:52 -0400155 mFunctions->compressedTexImage3D(target, level, compressedTexImageFormat.internalFormat,
156 size.width, size.height, size.depth, 0, imageSize, pixels);
Geoff Langc05f7062015-03-10 09:50:57 -0700157 }
158 else
159 {
160 UNREACHABLE();
Jamie Madill67102f02015-03-16 10:41:42 -0400161 }
162
Geoff Langc05f7062015-03-10 09:50:57 -0700163 return gl::Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500164}
165
166gl::Error TextureGL::setCompressedSubImage(GLenum target, size_t level, const gl::Box &area, GLenum format,
Geoff Lang8509d862015-05-20 14:06:13 -0400167 const gl::PixelUnpackState &unpack, size_t imageSize, const uint8_t *pixels)
Geoff Langf9a6f082015-01-22 13:32:49 -0500168{
Geoff Lang968992e2015-03-17 18:01:49 -0400169 ASSERT(CompatibleTextureTarget(mTextureType, target));
Geoff Langc05f7062015-03-10 09:50:57 -0700170
Geoff Lang23a2ae02015-07-28 12:42:52 -0400171 nativegl::CompressedTexSubImageFormat compressedTexSubImageFormat =
172 nativegl::GetCompressedSubTexImageFormat(mFunctions, mWorkarounds, format);
173
Geoff Langc05f7062015-03-10 09:50:57 -0700174 mStateManager->bindTexture(mTextureType, mTextureID);
175 if (UseTexImage2D(mTextureType))
Jamie Madill67102f02015-03-16 10:41:42 -0400176 {
Geoff Langc05f7062015-03-10 09:50:57 -0700177 ASSERT(area.z == 0 && area.depth == 1);
Geoff Lang14389cc2015-07-23 10:57:20 -0400178 mFunctions->compressedTexSubImage2D(target, level, area.x, area.y, area.width, area.height,
Geoff Lang23a2ae02015-07-28 12:42:52 -0400179 compressedTexSubImageFormat.format, imageSize, pixels);
Geoff Langc05f7062015-03-10 09:50:57 -0700180 }
181 else if (UseTexImage3D(mTextureType))
182 {
Geoff Lang14389cc2015-07-23 10:57:20 -0400183 mFunctions->compressedTexSubImage3D(target, level, area.x, area.y, area.z, area.width,
Geoff Lang23a2ae02015-07-28 12:42:52 -0400184 area.height, area.depth,
185 compressedTexSubImageFormat.format, imageSize, pixels);
Geoff Langc05f7062015-03-10 09:50:57 -0700186 }
187 else
188 {
189 UNREACHABLE();
Jamie Madill67102f02015-03-16 10:41:42 -0400190 }
191
Geoff Langc05f7062015-03-10 09:50:57 -0700192 return gl::Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500193}
194
195gl::Error TextureGL::copyImage(GLenum target, size_t level, const gl::Rectangle &sourceArea, GLenum internalFormat,
196 const gl::Framebuffer *source)
197{
Geoff Langfbfa47c2015-03-31 11:26:00 -0400198 const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(source);
199
200 mStateManager->bindTexture(mTextureType, mTextureID);
201 mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID());
202
Geoff Lang23a2ae02015-07-28 12:42:52 -0400203 nativegl::CopyTexImageImageFormat copyTexImageFormat = nativegl::GetCopyTexImageImageFormat(
204 mFunctions, mWorkarounds, internalFormat, source->getImplementationColorReadType());
205
Geoff Langfbfa47c2015-03-31 11:26:00 -0400206 if (UseTexImage2D(mTextureType))
207 {
Geoff Lang23a2ae02015-07-28 12:42:52 -0400208 mFunctions->copyTexImage2D(target, level, copyTexImageFormat.internalFormat, sourceArea.x,
209 sourceArea.y, sourceArea.width, sourceArea.height, 0);
Geoff Langfbfa47c2015-03-31 11:26:00 -0400210 }
211 else
212 {
213 UNREACHABLE();
214 }
215
216 return gl::Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500217}
218
219gl::Error TextureGL::copySubImage(GLenum target, size_t level, const gl::Offset &destOffset, const gl::Rectangle &sourceArea,
220 const gl::Framebuffer *source)
221{
Geoff Langfbfa47c2015-03-31 11:26:00 -0400222 const FramebufferGL *sourceFramebufferGL = GetImplAs<FramebufferGL>(source);
223
224 mStateManager->bindTexture(mTextureType, mTextureID);
225 mStateManager->bindFramebuffer(GL_READ_FRAMEBUFFER, sourceFramebufferGL->getFramebufferID());
226
227 if (UseTexImage2D(mTextureType))
228 {
229 ASSERT(destOffset.z == 0);
230 mFunctions->copyTexSubImage2D(target, level, destOffset.x, destOffset.y,
231 sourceArea.x, sourceArea.y, sourceArea.width, sourceArea.height);
232 }
233 else if (UseTexImage3D(mTextureType))
234 {
235 mFunctions->copyTexSubImage3D(target, level, destOffset.x, destOffset.y, destOffset.z,
236 sourceArea.x, sourceArea.y, sourceArea.width, sourceArea.height);
237 }
238 else
239 {
240 UNREACHABLE();
241 }
242
243 return gl::Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500244}
245
246gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFormat, const gl::Extents &size)
247{
Geoff Langc05f7062015-03-10 09:50:57 -0700248 // TODO: emulate texture storage with TexImage calls if on GL version <4.2 or the
249 // ARB_texture_storage extension is not available.
250
Geoff Lang23a2ae02015-07-28 12:42:52 -0400251 nativegl::TexStorageFormat texStorageFormat =
252 nativegl::GetTexStorageFormat(mFunctions, mWorkarounds, internalFormat);
Geoff Langfd216c42015-05-27 16:12:30 -0400253
Geoff Langc05f7062015-03-10 09:50:57 -0700254 mStateManager->bindTexture(mTextureType, mTextureID);
255 if (UseTexImage2D(mTextureType))
256 {
257 ASSERT(size.depth == 1);
Geoff Lang1c0ad622015-03-24 10:27:45 -0400258 if (mFunctions->texStorage2D)
259 {
Geoff Lang23a2ae02015-07-28 12:42:52 -0400260 mFunctions->texStorage2D(target, levels, texStorageFormat.internalFormat, size.width,
261 size.height);
Geoff Lang1c0ad622015-03-24 10:27:45 -0400262 }
263 else
264 {
265 // Make sure no pixel unpack buffer is bound
266 mStateManager->bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
267
268 const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat);
269
270 // Internal format must be sized
271 ASSERT(internalFormatInfo.pixelBytes != 0);
272
273 for (size_t level = 0; level < levels; level++)
274 {
275 gl::Extents levelSize(std::max(size.width >> level, 1),
276 std::max(size.height >> level, 1),
277 1);
278
279 if (mTextureType == GL_TEXTURE_2D)
280 {
Geoff Lang42c98f62015-05-20 14:09:25 -0400281 if (internalFormatInfo.compressed)
282 {
283 size_t dataSize = internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, levelSize.width, levelSize.height);
Geoff Lang23a2ae02015-07-28 12:42:52 -0400284 mFunctions->compressedTexImage2D(
285 target, level, texStorageFormat.internalFormat, levelSize.width,
286 levelSize.height, 0, dataSize, nullptr);
Geoff Lang42c98f62015-05-20 14:09:25 -0400287 }
288 else
289 {
Geoff Lang23a2ae02015-07-28 12:42:52 -0400290 mFunctions->texImage2D(target, level, texStorageFormat.internalFormat,
291 levelSize.width, levelSize.height, 0,
292 internalFormatInfo.format, internalFormatInfo.type,
293 nullptr);
Geoff Lang42c98f62015-05-20 14:09:25 -0400294 }
Geoff Lang1c0ad622015-03-24 10:27:45 -0400295 }
296 else if (mTextureType == GL_TEXTURE_CUBE_MAP)
297 {
298 for (GLenum face = gl::FirstCubeMapTextureTarget; face <= gl::LastCubeMapTextureTarget; face++)
299 {
Geoff Lang42c98f62015-05-20 14:09:25 -0400300 if (internalFormatInfo.compressed)
301 {
302 size_t dataSize = internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, levelSize.width, levelSize.height);
Geoff Lang23a2ae02015-07-28 12:42:52 -0400303 mFunctions->compressedTexImage2D(
304 face, level, texStorageFormat.internalFormat, levelSize.width,
305 levelSize.height, 0, dataSize, nullptr);
Geoff Lang42c98f62015-05-20 14:09:25 -0400306 }
307 else
308 {
Geoff Lang23a2ae02015-07-28 12:42:52 -0400309 mFunctions->texImage2D(face, level, texStorageFormat.internalFormat,
310 levelSize.width, levelSize.height, 0,
311 internalFormatInfo.format,
312 internalFormatInfo.type, nullptr);
Geoff Lang42c98f62015-05-20 14:09:25 -0400313 }
Geoff Lang1c0ad622015-03-24 10:27:45 -0400314 }
315 }
316 else
317 {
318 UNREACHABLE();
319 }
320 }
321 }
Geoff Langc05f7062015-03-10 09:50:57 -0700322 }
323 else if (UseTexImage3D(mTextureType))
324 {
Geoff Lang1c0ad622015-03-24 10:27:45 -0400325 if (mFunctions->texStorage3D)
326 {
Geoff Lang23a2ae02015-07-28 12:42:52 -0400327 mFunctions->texStorage3D(target, levels, texStorageFormat.internalFormat, size.width,
328 size.height, size.depth);
Geoff Lang1c0ad622015-03-24 10:27:45 -0400329 }
330 else
331 {
332 // Make sure no pixel unpack buffer is bound
333 mStateManager->bindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
334
335 const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat);
336
337 // Internal format must be sized
338 ASSERT(internalFormatInfo.pixelBytes != 0);
339
340 for (size_t i = 0; i < levels; i++)
341 {
342 gl::Extents levelSize(std::max(size.width >> i, 1),
343 std::max(size.height >> i, 1),
344 mTextureType == GL_TEXTURE_3D ? std::max(size.depth >> i, 1) : size.depth);
345
Geoff Lang42c98f62015-05-20 14:09:25 -0400346 if (internalFormatInfo.compressed)
347 {
348 size_t dataSize = internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, levelSize.width, levelSize.height) * levelSize.depth;
Geoff Lang23a2ae02015-07-28 12:42:52 -0400349 mFunctions->compressedTexImage3D(target, i, texStorageFormat.internalFormat,
350 levelSize.width, levelSize.height,
351 levelSize.depth, 0, dataSize, nullptr);
Geoff Lang42c98f62015-05-20 14:09:25 -0400352 }
353 else
354 {
Geoff Lang23a2ae02015-07-28 12:42:52 -0400355 mFunctions->texImage3D(target, i, texStorageFormat.internalFormat,
356 levelSize.width, levelSize.height, levelSize.depth, 0,
357 internalFormatInfo.format, internalFormatInfo.type,
358 nullptr);
Geoff Lang42c98f62015-05-20 14:09:25 -0400359 }
Geoff Lang1c0ad622015-03-24 10:27:45 -0400360 }
361 }
Geoff Langc05f7062015-03-10 09:50:57 -0700362 }
363 else
364 {
365 UNREACHABLE();
366 }
367
368 return gl::Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500369}
370
Gregoire Payen de La Garanderie752ce192015-04-14 11:11:12 +0100371gl::Error TextureGL::generateMipmaps(const gl::SamplerState &samplerState)
Geoff Langf9a6f082015-01-22 13:32:49 -0500372{
Geoff Langc05f7062015-03-10 09:50:57 -0700373 mStateManager->bindTexture(mTextureType, mTextureID);
374 mFunctions->generateMipmap(mTextureType);
375 return gl::Error(GL_NO_ERROR);
Geoff Langf9a6f082015-01-22 13:32:49 -0500376}
377
378void TextureGL::bindTexImage(egl::Surface *surface)
379{
Geoff Lang03053202015-04-09 11:21:13 -0400380 ASSERT(mTextureType == GL_TEXTURE_2D);
381
382 // Make sure this texture is bound
383 mStateManager->bindTexture(mTextureType, mTextureID);
Geoff Langf9a6f082015-01-22 13:32:49 -0500384}
385
386void TextureGL::releaseTexImage()
387{
Geoff Lang03053202015-04-09 11:21:13 -0400388 // Not all Surface implementations reset the size of mip 0 when releasing, do it manually
389 ASSERT(mTextureType == GL_TEXTURE_2D);
390
391 mStateManager->bindTexture(mTextureType, mTextureID);
392 if (UseTexImage2D(mTextureType))
393 {
394 mFunctions->texImage2D(mTextureType, 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
395 }
396 else
397 {
398 UNREACHABLE();
399 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500400}
401
Geoff Langa8406172015-07-21 16:53:39 -0400402gl::Error TextureGL::setEGLImageTarget(GLenum target, egl::Image *image)
403{
404 UNIMPLEMENTED();
405 return gl::Error(GL_INVALID_OPERATION);
406}
407
Geoff Langc05f7062015-03-10 09:50:57 -0700408template <typename T>
409static inline void SyncSamplerStateMember(const FunctionsGL *functions, const gl::SamplerState &newState,
410 gl::SamplerState &curState, GLenum textureType, GLenum name,
411 T(gl::SamplerState::*samplerMember))
412{
413 if (curState.*samplerMember != newState.*samplerMember)
414 {
415 curState.*samplerMember = newState.*samplerMember;
Minmin Gong794e0002015-04-07 18:31:54 -0700416 functions->texParameterf(textureType, name, static_cast<GLfloat>(curState.*samplerMember));
Geoff Langc05f7062015-03-10 09:50:57 -0700417 }
418}
419
420void TextureGL::syncSamplerState(const gl::SamplerState &samplerState) const
421{
422 if (mAppliedSamplerState != samplerState)
423 {
424 mStateManager->bindTexture(mTextureType, mTextureID);
425 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MIN_FILTER, &gl::SamplerState::minFilter);
426 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MAG_FILTER, &gl::SamplerState::magFilter);
427 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_WRAP_S, &gl::SamplerState::wrapS);
428 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_WRAP_T, &gl::SamplerState::wrapT);
429 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_WRAP_R, &gl::SamplerState::wrapR);
430 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MAX_ANISOTROPY_EXT, &gl::SamplerState::maxAnisotropy);
431 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_BASE_LEVEL, &gl::SamplerState::baseLevel);
432 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MAX_LEVEL, &gl::SamplerState::maxLevel);
433 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MIN_LOD, &gl::SamplerState::minLod);
434 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_MAX_LOD, &gl::SamplerState::maxLod);
435 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_COMPARE_MODE, &gl::SamplerState::compareMode);
436 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_COMPARE_FUNC, &gl::SamplerState::compareFunc);
437 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_SWIZZLE_R, &gl::SamplerState::swizzleRed);
438 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_SWIZZLE_G, &gl::SamplerState::swizzleGreen);
439 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_SWIZZLE_B, &gl::SamplerState::swizzleBlue);
440 SyncSamplerStateMember(mFunctions, samplerState, mAppliedSamplerState, mTextureType, GL_TEXTURE_SWIZZLE_A, &gl::SamplerState::swizzleAlpha);
441 }
442}
443
444GLuint TextureGL::getTextureID() const
445{
446 return mTextureID;
447}
448
Geoff Langf9a6f082015-01-22 13:32:49 -0500449}