Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: Source/modules/webgl/WebGLTexture.cpp

Issue 1306343007: Fix base level for generateMipmap in blink (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add assertion Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/modules/webgl/WebGLRenderingContextBase.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 ASSERT(maxLevel < m_info[ii].size());
225 for (size_t level = m_baseLevel + 1; level <= maxLevel; ++level) {
226 width = std::max(1, width >> 1); 226 width = std::max(1, width >> 1);
227 height = std::max(1, height >> 1); 227 height = std::max(1, height >> 1);
228 depth = std::max(1, depth >> 1); 228 depth = std::max(1, depth >> 1);
229 LevelInfo& info = m_info[ii][level]; 229 LevelInfo& info = m_info[ii][level];
230 info.setInfo(info0.internalFormat, width, height, depth, info0.t ype); 230 info.setInfo(info0.internalFormat, width, height, depth, info0.t ype);
231 } 231 }
232 } 232 }
233 m_isComplete = true; 233 m_isComplete = true;
234 } 234 }
235 m_needToUseBlackTexture = false; 235 m_needToUseBlackTexture = false;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return 0; 347 return 0;
348 } 348 }
349 return -1; 349 return -1;
350 } 350 }
351 351
352 bool WebGLTexture::canGenerateMipmaps() 352 bool WebGLTexture::canGenerateMipmaps()
353 { 353 {
354 if (!m_isWebGL2OrHigher && isNPOT()) 354 if (!m_isWebGL2OrHigher && isNPOT())
355 return false; 355 return false;
356 356
357 size_t baseLevel = std::min(m_baseLevel, m_info[0].size() - 1); 357 if (m_baseLevel >= m_info[0].size())
358 const LevelInfo& base = m_info[0][baseLevel]; 358 return false;
359 const LevelInfo& base = m_info[0][m_baseLevel];
359 for (size_t ii = 0; ii < m_info.size(); ++ii) { 360 for (size_t ii = 0; ii < m_info.size(); ++ii) {
360 const LevelInfo& info = m_info[ii][baseLevel]; 361 const LevelInfo& info = m_info[ii][m_baseLevel];
361 if (!info.valid 362 if (!info.valid
362 || info.width != base.width || info.height != base.height || info.de pth != base.depth 363 || info.width != base.width || info.height != base.height || info.de pth != base.depth
363 || info.internalFormat != base.internalFormat || info.type != base.t ype 364 || info.internalFormat != base.internalFormat || info.type != base.t ype
364 || (m_info.size() > 1 && !m_isCubeComplete)) 365 || (m_info.size() > 1 && !m_isCubeComplete))
365 return false; 366 return false;
366 } 367 }
367 return true; 368 return true;
368 } 369 }
369 370
370 GLint WebGLTexture::computeLevelCount(GLsizei width, GLsizei height, GLsizei dep th) 371 GLint WebGLTexture::computeLevelCount(GLsizei width, GLsizei height, GLsizei dep th)
(...skipping 21 matching lines...) Expand all
392 m_isNPOT = false; 393 m_isNPOT = false;
393 for (size_t ii = 0; ii < m_info.size(); ++ii) { 394 for (size_t ii = 0; ii < m_info.size(); ++ii) {
394 if (isNPOT(m_info[ii][0].width, m_info[ii][0].height)) { 395 if (isNPOT(m_info[ii][0].width, m_info[ii][0].height)) {
395 m_isNPOT = true; 396 m_isNPOT = true;
396 break; 397 break;
397 } 398 }
398 } 399 }
399 m_isComplete = true; 400 m_isComplete = true;
400 m_isCubeComplete = true; 401 m_isCubeComplete = true;
401 402
402 size_t baseLevel = std::min(m_baseLevel, m_info[0].size() - 1); 403 if (m_baseLevel > m_maxLevel || m_baseLevel >= m_info[0].size()) {
403 const LevelInfo& base = m_info[0][baseLevel];
404 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
407 if (baseLevel > maxLevel) {
408 m_isComplete = false; 404 m_isComplete = false;
409 } 405 }
410 else { 406 else {
407 const LevelInfo& base = m_info[0][m_baseLevel];
408 size_t levelCount = computeLevelCount(base.width, base.height, base.dept h);
409 size_t maxLevel = m_isWebGL2OrHigher ? std::min(m_maxLevel, m_baseLevel + levelCount - 1) : m_baseLevel + levelCount - 1;
411 for (size_t ii = 0; ii < m_info.size() && m_isComplete; ++ii) { 410 for (size_t ii = 0; ii < m_info.size() && m_isComplete; ++ii) {
412 const LevelInfo& info0 = m_info[ii][baseLevel]; 411 const LevelInfo& info0 = m_info[ii][m_baseLevel];
413 if (!info0.valid 412 if (!info0.valid
414 || info0.width != base.width || info0.height != base.height || i nfo0.depth != base.depth 413 || info0.width != base.width || info0.height != base.height || i nfo0.depth != base.depth
415 || info0.internalFormat != base.internalFormat || info0.type != base.type 414 || info0.internalFormat != base.internalFormat || info0.type != base.type
416 || (m_info.size() > 1 && info0.width != info0.height)) { 415 || (m_info.size() > 1 && info0.width != info0.height)) {
417 if (m_info.size() > 1) 416 if (m_info.size() > 1)
418 m_isCubeComplete = false; 417 m_isCubeComplete = false;
419 m_isComplete = false; 418 m_isComplete = false;
420 break; 419 break;
421 } 420 }
422 GLsizei width = info0.width; 421 GLsizei width = info0.width;
423 GLsizei height = info0.height; 422 GLsizei height = info0.height;
424 GLsizei depth = info0.depth; 423 GLsizei depth = info0.depth;
425 for (size_t level = baseLevel + 1; level <= maxLevel; ++level) { 424 ASSERT(maxLevel < m_info[ii].size());
425 for (size_t level = m_baseLevel + 1; level <= maxLevel; ++level) {
426 width = std::max(1, width >> 1); 426 width = std::max(1, width >> 1);
427 height = std::max(1, height >> 1); 427 height = std::max(1, height >> 1);
428 depth = std::max(1, depth >> 1); 428 depth = std::max(1, depth >> 1);
429 const LevelInfo& info = m_info[ii][level]; 429 const LevelInfo& info = m_info[ii][level];
430 if (!info.valid 430 if (!info.valid
431 || info.width != width || info.height != height || info.dept h != depth 431 || info.width != width || info.height != height || info.dept h != depth
432 || info.internalFormat != info0.internalFormat || info.type != info0.type) { 432 || info.internalFormat != info0.internalFormat || info.type != info0.type) {
433 m_isComplete = false; 433 m_isComplete = false;
434 break; 434 break;
435 } 435 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 590 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
591 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 591 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
592 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 592 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
593 return GL_UNSIGNED_BYTE; 593 return GL_UNSIGNED_BYTE;
594 default: 594 default:
595 return GL_NONE; 595 return GL_NONE;
596 } 596 }
597 } 597 }
598 598
599 } // namespace blink 599 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webgl/WebGLRenderingContextBase.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698