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

Side by Side Diff: Source/core/html/canvas/WebGLTexture.cpp

Issue 16437002: Add check on Cube Completeness for Cube textures and improve the efficiency of checks associated wi… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Change code to make it more clear Created 7 years, 6 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/core/html/canvas/WebGLTexture.h ('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 26 matching lines...) Expand all
37 } 37 }
38 38
39 WebGLTexture::WebGLTexture(WebGLRenderingContext* ctx) 39 WebGLTexture::WebGLTexture(WebGLRenderingContext* ctx)
40 : WebGLSharedObject(ctx) 40 : WebGLSharedObject(ctx)
41 , m_target(0) 41 , m_target(0)
42 , m_minFilter(GraphicsContext3D::NEAREST_MIPMAP_LINEAR) 42 , m_minFilter(GraphicsContext3D::NEAREST_MIPMAP_LINEAR)
43 , m_magFilter(GraphicsContext3D::LINEAR) 43 , m_magFilter(GraphicsContext3D::LINEAR)
44 , m_wrapS(GraphicsContext3D::REPEAT) 44 , m_wrapS(GraphicsContext3D::REPEAT)
45 , m_wrapT(GraphicsContext3D::REPEAT) 45 , m_wrapT(GraphicsContext3D::REPEAT)
46 , m_isNPOT(false) 46 , m_isNPOT(false)
47 , m_isCubeComplete(false)
47 , m_isComplete(false) 48 , m_isComplete(false)
48 , m_needToUseBlackTexture(false) 49 , m_needToUseBlackTexture(false)
49 , m_isFloatType(false) 50 , m_isFloatType(false)
50 , m_isHalfFloatType(false) 51 , m_isHalfFloatType(false)
51 { 52 {
52 ScriptWrappable::init(this); 53 ScriptWrappable::init(this);
53 setObject(ctx->graphicsContext3D()->createTexture()); 54 setObject(ctx->graphicsContext3D()->createTexture());
54 } 55 }
55 56
56 WebGLTexture::~WebGLTexture() 57 WebGLTexture::~WebGLTexture()
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 276
276 bool WebGLTexture::canGenerateMipmaps() 277 bool WebGLTexture::canGenerateMipmaps()
277 { 278 {
278 if (isNPOT()) 279 if (isNPOT())
279 return false; 280 return false;
280 const LevelInfo& first = m_info[0][0]; 281 const LevelInfo& first = m_info[0][0];
281 for (size_t ii = 0; ii < m_info.size(); ++ii) { 282 for (size_t ii = 0; ii < m_info.size(); ++ii) {
282 const LevelInfo& info = m_info[ii][0]; 283 const LevelInfo& info = m_info[ii][0];
283 if (!info.valid 284 if (!info.valid
284 || info.width != first.width || info.height != first.height 285 || info.width != first.width || info.height != first.height
285 || info.internalFormat != first.internalFormat || info.type != first .type) 286 || info.internalFormat != first.internalFormat || info.type != first .type
287 || (m_info.size() > 1 && !m_isCubeComplete))
286 return false; 288 return false;
287 } 289 }
288 return true; 290 return true;
289 } 291 }
290 292
291 GC3Dint WebGLTexture::computeLevelCount(GC3Dsizei width, GC3Dsizei height) 293 GC3Dint WebGLTexture::computeLevelCount(GC3Dsizei width, GC3Dsizei height)
292 { 294 {
293 // return 1 + log2Floor(std::max(width, height)); 295 // return 1 + log2Floor(std::max(width, height));
294 GC3Dsizei n = std::max(width, height); 296 GC3Dsizei n = std::max(width, height);
295 if (n <= 0) 297 if (n <= 0)
(...skipping 15 matching lines...) Expand all
311 void WebGLTexture::update() 313 void WebGLTexture::update()
312 { 314 {
313 m_isNPOT = false; 315 m_isNPOT = false;
314 for (size_t ii = 0; ii < m_info.size(); ++ii) { 316 for (size_t ii = 0; ii < m_info.size(); ++ii) {
315 if (isNPOT(m_info[ii][0].width, m_info[ii][0].height)) { 317 if (isNPOT(m_info[ii][0].width, m_info[ii][0].height)) {
316 m_isNPOT = true; 318 m_isNPOT = true;
317 break; 319 break;
318 } 320 }
319 } 321 }
320 m_isComplete = true; 322 m_isComplete = true;
323 m_isCubeComplete = true;
321 const LevelInfo& first = m_info[0][0]; 324 const LevelInfo& first = m_info[0][0];
322 GC3Dint levelCount = computeLevelCount(first.width, first.height); 325 GC3Dint levelCount = computeLevelCount(first.width, first.height);
323 if (levelCount < 1) 326 if (levelCount < 1)
324 m_isComplete = false; 327 m_isComplete = false;
325 else { 328 else {
326 for (size_t ii = 0; ii < m_info.size() && m_isComplete; ++ii) { 329 for (size_t ii = 0; ii < m_info.size() && m_isComplete; ++ii) {
327 const LevelInfo& info0 = m_info[ii][0]; 330 const LevelInfo& info0 = m_info[ii][0];
328 if (!info0.valid 331 if (!info0.valid
329 || info0.width != first.width || info0.height != first.height 332 || info0.width != first.width || info0.height != first.height
330 || info0.internalFormat != first.internalFormat || info0.type != first.type) { 333 || info0.internalFormat != first.internalFormat || info0.type != first.type
334 || (m_info.size() > 1 && info0.width != info0.height)) {
335 if (m_info.size() > 1)
336 m_isCubeComplete = false;
331 m_isComplete = false; 337 m_isComplete = false;
332 break; 338 break;
333 } 339 }
334 GC3Dsizei width = info0.width; 340 GC3Dsizei width = info0.width;
335 GC3Dsizei height = info0.height; 341 GC3Dsizei height = info0.height;
336 for (GC3Dint level = 1; level < levelCount; ++level) { 342 for (GC3Dint level = 1; level < levelCount; ++level) {
337 width = std::max(1, width >> 1); 343 width = std::max(1, width >> 1);
338 height = std::max(1, height >> 1); 344 height = std::max(1, height >> 1);
339 const LevelInfo& info = m_info[ii][level]; 345 const LevelInfo& info = m_info[ii][level];
340 if (!info.valid 346 if (!info.valid
341 || info.width != width || info.height != height 347 || info.width != width || info.height != height
342 || info.internalFormat != info0.internalFormat || info.type != info0.type) { 348 || info.internalFormat != info0.internalFormat || info.type != info0.type) {
343 m_isComplete = false; 349 m_isComplete = false;
344 break; 350 break;
345 } 351 }
346 352
347 } 353 }
348 } 354 }
349 } 355 }
350 m_isFloatType = false; 356 m_isFloatType = m_info[0][0].type == GraphicsContext3D::FLOAT;
351 if (m_isComplete) 357 m_isHalfFloatType = m_info[0][0].type == GraphicsContext3D::HALF_FLOAT_OES;
352 m_isFloatType = m_info[0][0].type == GraphicsContext3D::FLOAT;
353 else {
354 for (size_t ii = 0; ii < m_info.size(); ++ii) {
355 if (m_info[ii][0].type == GraphicsContext3D::FLOAT) {
356 m_isFloatType = true;
357 break;
358 }
359 }
360 }
361 m_isHalfFloatType = false;
362 if (m_isComplete)
363 m_isHalfFloatType = m_info[0][0].type == GraphicsContext3D::HALF_FLOAT_O ES;
364 else {
365 for (size_t ii = 0; ii < m_info.size(); ++ii) {
366 if (m_info[ii][0].type == GraphicsContext3D::HALF_FLOAT_OES) {
367 m_isHalfFloatType = true;
368 break;
369 }
370 }
371 }
372 358
373 m_needToUseBlackTexture = false; 359 m_needToUseBlackTexture = false;
374 // NPOT 360 // NPOT
375 if (m_isNPOT && ((m_minFilter != GraphicsContext3D::NEAREST && m_minFilter ! = GraphicsContext3D::LINEAR) 361 if (m_isNPOT && ((m_minFilter != GraphicsContext3D::NEAREST && m_minFilter ! = GraphicsContext3D::LINEAR)
376 || m_wrapS != GraphicsContext3D::CLAMP_TO_EDGE || m_wrapT ! = GraphicsContext3D::CLAMP_TO_EDGE)) 362 || m_wrapS != GraphicsContext3D::CLAMP_TO_EDGE || m_wrapT ! = GraphicsContext3D::CLAMP_TO_EDGE))
377 m_needToUseBlackTexture = true; 363 m_needToUseBlackTexture = true;
364 // If it is a Cube texture, check Cube Completeness first
365 if (m_info.size() > 1 && !m_isCubeComplete)
366 m_needToUseBlackTexture = true;
378 // Completeness 367 // Completeness
379 if (!m_isComplete && m_minFilter != GraphicsContext3D::NEAREST && m_minFilte r != GraphicsContext3D::LINEAR) 368 if (!m_isComplete && m_minFilter != GraphicsContext3D::NEAREST && m_minFilte r != GraphicsContext3D::LINEAR)
380 m_needToUseBlackTexture = true; 369 m_needToUseBlackTexture = true;
381 } 370 }
382 371
383 const WebGLTexture::LevelInfo* WebGLTexture::getLevelInfo(GC3Denum target, GC3Di nt level) const 372 const WebGLTexture::LevelInfo* WebGLTexture::getLevelInfo(GC3Denum target, GC3Di nt level) const
384 { 373 {
385 if (!object() || !m_target) 374 if (!object() || !m_target)
386 return 0; 375 return 0;
387 int targetIndex = mapTargetToIndex(target); 376 int targetIndex = mapTargetToIndex(target);
388 if (targetIndex < 0 || targetIndex >= static_cast<int>(m_info.size())) 377 if (targetIndex < 0 || targetIndex >= static_cast<int>(m_info.size()))
389 return 0; 378 return 0;
390 if (level < 0 || level >= static_cast<GC3Dint>(m_info[targetIndex].size())) 379 if (level < 0 || level >= static_cast<GC3Dint>(m_info[targetIndex].size()))
391 return 0; 380 return 0;
392 return &(m_info[targetIndex][level]); 381 return &(m_info[targetIndex][level]);
393 } 382 }
394 383
395 } 384 }
OLDNEW
« no previous file with comments | « Source/core/html/canvas/WebGLTexture.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698