OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 m_immutable = true; | 207 m_immutable = true; |
208 } | 208 } |
209 | 209 |
210 void WebGLTexture::generateMipmapLevelInfo() | 210 void WebGLTexture::generateMipmapLevelInfo() |
211 { | 211 { |
212 if (!object() || !m_target) | 212 if (!object() || !m_target) |
213 return; | 213 return; |
214 if (!canGenerateMipmaps()) | 214 if (!canGenerateMipmaps()) |
215 return; | 215 return; |
216 if (!m_isComplete) { | 216 if (!m_isComplete) { |
217 size_t baseLevel = std::min(m_baseLevel, m_info[0].size() - 1); | |
218 for (size_t ii = 0; ii < m_info.size(); ++ii) { | 217 for (size_t ii = 0; ii < m_info.size(); ++ii) { |
219 const LevelInfo& info0 = m_info[ii][baseLevel]; | 218 const LevelInfo& info0 = m_info[ii][m_baseLevel]; |
220 GLsizei width = info0.width; | 219 GLsizei width = info0.width; |
221 GLsizei height = info0.height; | 220 GLsizei height = info0.height; |
222 GLsizei depth = info0.depth; | 221 GLsizei depth = info0.depth; |
223 GLint levelCount = computeLevelCount(width, height, depth); | 222 GLint levelCount = computeLevelCount(width, height, depth); |
224 size_t maxLevel = m_isWebGL2OrHigher ? std::min(m_maxLevel, baseLeve l + levelCount - 1) : baseLevel + levelCount - 1; | 223 size_t maxLevel = m_isWebGL2OrHigher ? std::min(m_maxLevel, m_baseLe vel + levelCount - 1) : m_baseLevel + levelCount - 1; |
225 for (size_t level = baseLevel + 1; level <= maxLevel; ++level) { | 224 for (size_t level = m_baseLevel + 1; level <= maxLevel; ++level) { |
226 width = std::max(1, width >> 1); | 225 width = std::max(1, width >> 1); |
227 height = std::max(1, height >> 1); | 226 height = std::max(1, height >> 1); |
228 depth = std::max(1, depth >> 1); | 227 depth = std::max(1, depth >> 1); |
229 LevelInfo& info = m_info[ii][level]; | 228 LevelInfo& info = m_info[ii][level]; |
230 info.setInfo(info0.internalFormat, width, height, depth, info0.t ype); | 229 info.setInfo(info0.internalFormat, width, height, depth, info0.t ype); |
231 } | 230 } |
232 } | 231 } |
233 m_isComplete = true; | 232 m_isComplete = true; |
234 } | 233 } |
235 m_needToUseBlackTexture = false; | 234 m_needToUseBlackTexture = false; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 return 0; | 346 return 0; |
348 } | 347 } |
349 return -1; | 348 return -1; |
350 } | 349 } |
351 | 350 |
352 bool WebGLTexture::canGenerateMipmaps() | 351 bool WebGLTexture::canGenerateMipmaps() |
353 { | 352 { |
354 if (!m_isWebGL2OrHigher && isNPOT()) | 353 if (!m_isWebGL2OrHigher && isNPOT()) |
355 return false; | 354 return false; |
356 | 355 |
357 size_t baseLevel = std::min(m_baseLevel, m_info[0].size() - 1); | 356 if (m_baseLevel >= m_info[0].size()) |
358 const LevelInfo& base = m_info[0][baseLevel]; | 357 return false; |
358 const LevelInfo& base = m_info[0][m_baseLevel]; | |
359 for (size_t ii = 0; ii < m_info.size(); ++ii) { | 359 for (size_t ii = 0; ii < m_info.size(); ++ii) { |
360 const LevelInfo& info = m_info[ii][baseLevel]; | 360 const LevelInfo& info = m_info[ii][m_baseLevel]; |
361 if (!info.valid | 361 if (!info.valid |
362 || info.width != base.width || info.height != base.height || info.de pth != base.depth | 362 || info.width != base.width || info.height != base.height || info.de pth != base.depth |
363 || info.internalFormat != base.internalFormat || info.type != base.t ype | 363 || info.internalFormat != base.internalFormat || info.type != base.t ype |
364 || (m_info.size() > 1 && !m_isCubeComplete)) | 364 || (m_info.size() > 1 && !m_isCubeComplete)) |
365 return false; | 365 return false; |
366 } | 366 } |
367 return true; | 367 return true; |
368 } | 368 } |
369 | 369 |
370 GLint WebGLTexture::computeLevelCount(GLsizei width, GLsizei height, GLsizei dep th) | 370 GLint WebGLTexture::computeLevelCount(GLsizei width, GLsizei height, GLsizei dep th) |
(...skipping 21 matching lines...) Expand all Loading... | |
392 m_isNPOT = false; | 392 m_isNPOT = false; |
393 for (size_t ii = 0; ii < m_info.size(); ++ii) { | 393 for (size_t ii = 0; ii < m_info.size(); ++ii) { |
394 if (isNPOT(m_info[ii][0].width, m_info[ii][0].height)) { | 394 if (isNPOT(m_info[ii][0].width, m_info[ii][0].height)) { |
395 m_isNPOT = true; | 395 m_isNPOT = true; |
396 break; | 396 break; |
397 } | 397 } |
398 } | 398 } |
399 m_isComplete = true; | 399 m_isComplete = true; |
400 m_isCubeComplete = true; | 400 m_isCubeComplete = true; |
401 | 401 |
402 size_t baseLevel = std::min(m_baseLevel, m_info[0].size() - 1); | 402 if (m_baseLevel >= m_info[0].size()) |
403 const LevelInfo& base = m_info[0][baseLevel]; | 403 return; |
Zhenyao Mo
2015/09/07 21:35:17
should m_isComplete be set to false?
qiankun
2015/09/08 03:35:06
Done.
| |
404 const LevelInfo& base = m_info[0][m_baseLevel]; | |
404 size_t levelCount = computeLevelCount(base.width, base.height, base.depth); | 405 size_t levelCount = computeLevelCount(base.width, base.height, base.depth); |
405 size_t maxLevel = m_isWebGL2OrHigher ? std::min(m_maxLevel, baseLevel + leve lCount - 1) : baseLevel + levelCount - 1; | 406 size_t maxLevel = m_isWebGL2OrHigher ? std::min(m_maxLevel, m_baseLevel + le velCount - 1) : m_baseLevel + levelCount - 1; |
406 | 407 |
407 if (baseLevel > maxLevel) { | 408 if (m_baseLevel > maxLevel) { |
Zhenyao Mo
2015/09/07 21:35:18
As I mentioned in the other CL, my reading of the
qiankun
2015/09/08 03:35:06
Just set m_isComplete as false here other than ret
Zhenyao Mo
2015/09/08 20:45:24
So I read the ES spec 3.0.4 one more time, here ar
Zhenyao Mo
2015/09/08 21:11:17
In Section 3.9.2 Shader Execution, Texture Access,
| |
408 m_isComplete = false; | 409 m_isComplete = false; |
409 } | 410 } |
410 else { | 411 else { |
411 for (size_t ii = 0; ii < m_info.size() && m_isComplete; ++ii) { | 412 for (size_t ii = 0; ii < m_info.size() && m_isComplete; ++ii) { |
412 const LevelInfo& info0 = m_info[ii][baseLevel]; | 413 const LevelInfo& info0 = m_info[ii][m_baseLevel]; |
413 if (!info0.valid | 414 if (!info0.valid |
414 || info0.width != base.width || info0.height != base.height || i nfo0.depth != base.depth | 415 || info0.width != base.width || info0.height != base.height || i nfo0.depth != base.depth |
415 || info0.internalFormat != base.internalFormat || info0.type != base.type | 416 || info0.internalFormat != base.internalFormat || info0.type != base.type |
416 || (m_info.size() > 1 && info0.width != info0.height)) { | 417 || (m_info.size() > 1 && info0.width != info0.height)) { |
417 if (m_info.size() > 1) | 418 if (m_info.size() > 1) |
418 m_isCubeComplete = false; | 419 m_isCubeComplete = false; |
419 m_isComplete = false; | 420 m_isComplete = false; |
420 break; | 421 break; |
421 } | 422 } |
422 GLsizei width = info0.width; | 423 GLsizei width = info0.width; |
423 GLsizei height = info0.height; | 424 GLsizei height = info0.height; |
424 GLsizei depth = info0.depth; | 425 GLsizei depth = info0.depth; |
425 for (size_t level = baseLevel + 1; level <= maxLevel; ++level) { | 426 for (size_t level = m_baseLevel + 1; level <= maxLevel; ++level) { |
426 width = std::max(1, width >> 1); | 427 width = std::max(1, width >> 1); |
427 height = std::max(1, height >> 1); | 428 height = std::max(1, height >> 1); |
428 depth = std::max(1, depth >> 1); | 429 depth = std::max(1, depth >> 1); |
429 const LevelInfo& info = m_info[ii][level]; | 430 const LevelInfo& info = m_info[ii][level]; |
430 if (!info.valid | 431 if (!info.valid |
431 || info.width != width || info.height != height || info.dept h != depth | 432 || info.width != width || info.height != height || info.dept h != depth |
432 || info.internalFormat != info0.internalFormat || info.type != info0.type) { | 433 || info.internalFormat != info0.internalFormat || info.type != info0.type) { |
433 m_isComplete = false; | 434 m_isComplete = false; |
434 break; | 435 break; |
435 } | 436 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: | 591 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
591 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: | 592 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
592 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: | 593 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
593 return GL_UNSIGNED_BYTE; | 594 return GL_UNSIGNED_BYTE; |
594 default: | 595 default: |
595 return GL_NONE; | 596 return GL_NONE; |
596 } | 597 } |
597 } | 598 } |
598 | 599 |
599 } // namespace blink | 600 } // namespace blink |
OLD | NEW |