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

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

Issue 14860016: Implement OES_texture_float_linear and OES_texture_half_float_linear extensions in WebGL. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 7 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
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 20 matching lines...) Expand all
31 #include "core/html/HTMLCanvasElement.h" 31 #include "core/html/HTMLCanvasElement.h"
32 #include "core/html/HTMLImageElement.h" 32 #include "core/html/HTMLImageElement.h"
33 #include "core/html/HTMLVideoElement.h" 33 #include "core/html/HTMLVideoElement.h"
34 #include "core/html/ImageData.h" 34 #include "core/html/ImageData.h"
35 #include "core/html/canvas/CheckedInt.h" 35 #include "core/html/canvas/CheckedInt.h"
36 #include "core/html/canvas/EXTDrawBuffers.h" 36 #include "core/html/canvas/EXTDrawBuffers.h"
37 #include "core/html/canvas/EXTTextureFilterAnisotropic.h" 37 #include "core/html/canvas/EXTTextureFilterAnisotropic.h"
38 #include "core/html/canvas/OESElementIndexUint.h" 38 #include "core/html/canvas/OESElementIndexUint.h"
39 #include "core/html/canvas/OESStandardDerivatives.h" 39 #include "core/html/canvas/OESStandardDerivatives.h"
40 #include "core/html/canvas/OESTextureFloat.h" 40 #include "core/html/canvas/OESTextureFloat.h"
41 #include "core/html/canvas/OESTextureFloatLinear.h"
41 #include "core/html/canvas/OESTextureHalfFloat.h" 42 #include "core/html/canvas/OESTextureHalfFloat.h"
43 #include "core/html/canvas/OESTextureHalfFloatLinear.h"
42 #include "core/html/canvas/OESVertexArrayObject.h" 44 #include "core/html/canvas/OESVertexArrayObject.h"
43 #include "core/html/canvas/WebGLActiveInfo.h" 45 #include "core/html/canvas/WebGLActiveInfo.h"
44 #include "core/html/canvas/WebGLBuffer.h" 46 #include "core/html/canvas/WebGLBuffer.h"
45 #include "core/html/canvas/WebGLCompressedTextureATC.h" 47 #include "core/html/canvas/WebGLCompressedTextureATC.h"
46 #include "core/html/canvas/WebGLCompressedTexturePVRTC.h" 48 #include "core/html/canvas/WebGLCompressedTexturePVRTC.h"
47 #include "core/html/canvas/WebGLCompressedTextureS3TC.h" 49 #include "core/html/canvas/WebGLCompressedTextureS3TC.h"
48 #include "core/html/canvas/WebGLContextAttributes.h" 50 #include "core/html/canvas/WebGLContextAttributes.h"
49 #include "core/html/canvas/WebGLContextEvent.h" 51 #include "core/html/canvas/WebGLContextEvent.h"
50 #include "core/html/canvas/WebGLContextGroup.h" 52 #include "core/html/canvas/WebGLContextGroup.h"
51 #include "core/html/canvas/WebGLDebugRendererInfo.h" 53 #include "core/html/canvas/WebGLDebugRendererInfo.h"
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 m_maxColorAttachments = 0; 620 m_maxColorAttachments = 0;
619 621
620 m_backDrawBuffer = GraphicsContext3D::BACK; 622 m_backDrawBuffer = GraphicsContext3D::BACK;
621 623
622 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, WebGLVe rtexArrayObjectOES::VaoTypeDefault); 624 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, WebGLVe rtexArrayObjectOES::VaoTypeDefault);
623 addContextObject(m_defaultVertexArrayObject.get()); 625 addContextObject(m_defaultVertexArrayObject.get());
624 m_boundVertexArrayObject = m_defaultVertexArrayObject; 626 m_boundVertexArrayObject = m_defaultVertexArrayObject;
625 627
626 m_vertexAttribValue.resize(m_maxVertexAttribs); 628 m_vertexAttribValue.resize(m_maxVertexAttribs);
627 629
628 if (!isGLES2NPOTStrict()) 630 createFallbackBlackTextures1x1();
629 createFallbackBlackTextures1x1();
630 631
631 IntSize canvasSize = clampedCanvasSize(); 632 IntSize canvasSize = clampedCanvasSize();
632 m_drawingBuffer->reset(canvasSize); 633 m_drawingBuffer->reset(canvasSize);
633 634
634 m_context->viewport(0, 0, canvasSize.width(), canvasSize.height()); 635 m_context->viewport(0, 0, canvasSize.width(), canvasSize.height());
635 m_context->scissor(0, 0, canvasSize.width(), canvasSize.height()); 636 m_context->scissor(0, 0, canvasSize.width(), canvasSize.height());
636 637
637 m_context->setContextLostCallback(adoptPtr(new WebGLRenderingContextLostCall back(this))); 638 m_context->setContextLostCallback(adoptPtr(new WebGLRenderingContextLostCall back(this)));
638 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe ssageCallback(this))); 639 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe ssageCallback(this)));
639 640
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 } 1722 }
1722 1723
1723 const char* reason = "framebuffer incomplete"; 1724 const char* reason = "framebuffer incomplete";
1724 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 1725 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) {
1725 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "dra wArrays", reason); 1726 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "dra wArrays", reason);
1726 return; 1727 return;
1727 } 1728 }
1728 1729
1729 clearIfComposited(); 1730 clearIfComposited();
1730 1731
1731 bool vertexAttrib0Simulated = false; 1732 handleTexturesCompleteness("drawArrays", true);
1732 if (!isGLES2NPOTStrict())
1733 handleNPOTTextures("drawArrays", true);
1734 m_context->drawArrays(mode, first, count); 1733 m_context->drawArrays(mode, first, count);
1735 if (!isGLES2NPOTStrict()) 1734 handleTexturesCompleteness("drawArrays", false);
1736 handleNPOTTextures("drawArrays", false);
1737 markContextChanged(); 1735 markContextChanged();
1738 } 1736 }
1739 1737
1740 void WebGLRenderingContext::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denu m type, long long offset, ExceptionCode& ec) 1738 void WebGLRenderingContext::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denu m type, long long offset, ExceptionCode& ec)
1741 { 1739 {
1742 UNUSED_PARAM(ec); 1740 UNUSED_PARAM(ec);
1743 1741
1744 if (isContextLost() || !validateDrawMode("drawElements", mode)) 1742 if (isContextLost() || !validateDrawMode("drawElements", mode))
1745 return; 1743 return;
1746 1744
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 return; 1780 return;
1783 } 1781 }
1784 1782
1785 const char* reason = "framebuffer incomplete"; 1783 const char* reason = "framebuffer incomplete";
1786 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 1784 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) {
1787 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "dra wElements", reason); 1785 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "dra wElements", reason);
1788 return; 1786 return;
1789 } 1787 }
1790 clearIfComposited(); 1788 clearIfComposited();
1791 1789
1792 if (!isGLES2NPOTStrict()) 1790 handleTexturesCompleteness("drawElements", true);
1793 handleNPOTTextures("drawElements", true);
1794 m_context->drawElements(mode, count, type, static_cast<GC3Dintptr>(offset)); 1791 m_context->drawElements(mode, count, type, static_cast<GC3Dintptr>(offset));
1795 if (!isGLES2NPOTStrict()) 1792 handleTexturesCompleteness("drawElements", false);
1796 handleNPOTTextures("drawElements", false);
1797 markContextChanged(); 1793 markContextChanged();
1798 } 1794 }
1799 1795
1800 void WebGLRenderingContext::enable(GC3Denum cap) 1796 void WebGLRenderingContext::enable(GC3Denum cap)
1801 { 1797 {
1802 if (isContextLost() || !validateCapability("enable", cap)) 1798 if (isContextLost() || !validateCapability("enable", cap))
1803 return; 1799 return;
1804 if (cap == GraphicsContext3D::STENCIL_TEST) { 1800 if (cap == GraphicsContext3D::STENCIL_TEST) {
1805 m_stencilEnabled = true; 1801 m_stencilEnabled = true;
1806 applyStencilTest(); 1802 applyStencilTest();
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 if (getExtensionIfMatch<WebGLCompressedTextureATC>(name, m_webglCompressedTe xtureATC, webkitPrefix, extension)) 2102 if (getExtensionIfMatch<WebGLCompressedTextureATC>(name, m_webglCompressedTe xtureATC, webkitPrefix, extension))
2107 return extension; 2103 return extension;
2108 if (getExtensionIfMatch<WebGLCompressedTexturePVRTC>(name, m_webglCompressed TexturePVRTC, webkitPrefix, extension)) 2104 if (getExtensionIfMatch<WebGLCompressedTexturePVRTC>(name, m_webglCompressed TexturePVRTC, webkitPrefix, extension))
2109 return extension; 2105 return extension;
2110 if (getExtensionIfMatch<WebGLCompressedTextureS3TC>(name, m_webglCompressedT extureS3TC, bothPrefixes, extension)) 2106 if (getExtensionIfMatch<WebGLCompressedTextureS3TC>(name, m_webglCompressedT extureS3TC, bothPrefixes, extension))
2111 return extension; 2107 return extension;
2112 if (getExtensionIfMatch<WebGLDepthTexture>(name, m_webglDepthTexture, bothPr efixes, extension)) 2108 if (getExtensionIfMatch<WebGLDepthTexture>(name, m_webglDepthTexture, bothPr efixes, extension))
2113 return extension; 2109 return extension;
2114 if (getExtensionIfMatch<EXTDrawBuffers>(name, m_extDrawBuffers, unprefixed, extension)) 2110 if (getExtensionIfMatch<EXTDrawBuffers>(name, m_extDrawBuffers, unprefixed, extension))
2115 return extension; 2111 return extension;
2112 if (getExtensionIfMatch<OESTextureFloatLinear>(name, m_oesTextureFloatLinear , unprefixed, extension))
2113 return extension;
2114 if (getExtensionIfMatch<OESTextureHalfFloatLinear>(name, m_oesTextureHalfFlo atLinear, unprefixed, extension))
2115 return extension;
2116 if (allowPrivilegedExtensions()) { 2116 if (allowPrivilegedExtensions()) {
2117 if (getExtensionIfMatch<WebGLDebugRendererInfo>(name, m_webglDebugRender erInfo, unprefixed, extension)) 2117 if (getExtensionIfMatch<WebGLDebugRendererInfo>(name, m_webglDebugRender erInfo, unprefixed, extension))
2118 return extension; 2118 return extension;
2119 if (getExtensionIfMatch<WebGLDebugShaders>(name, m_webglDebugShaders, un prefixed, extension)) 2119 if (getExtensionIfMatch<WebGLDebugShaders>(name, m_webglDebugShaders, un prefixed, extension))
2120 return extension; 2120 return extension;
2121 } 2121 }
2122 2122
2123 return 0; 2123 return 0;
2124 } 2124 }
2125 2125
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2592 { 2592 {
2593 Vector<String> result; 2593 Vector<String> result;
2594 if (isContextLost()) 2594 if (isContextLost())
2595 return result; 2595 return result;
2596 2596
2597 appendIfSupported<EXTDrawBuffers>(result, false); 2597 appendIfSupported<EXTDrawBuffers>(result, false);
2598 appendIfSupported<EXTTextureFilterAnisotropic>(result, true); 2598 appendIfSupported<EXTTextureFilterAnisotropic>(result, true);
2599 appendIfSupported<OESElementIndexUint>(result, false); 2599 appendIfSupported<OESElementIndexUint>(result, false);
2600 appendIfSupported<OESStandardDerivatives>(result, false); 2600 appendIfSupported<OESStandardDerivatives>(result, false);
2601 appendIfSupported<OESTextureFloat>(result, false); 2601 appendIfSupported<OESTextureFloat>(result, false);
2602 appendIfSupported<OESTextureFloatLinear>(result, false);
2603 appendIfSupported<OESTextureHalfFloat>(result, false);
2604 appendIfSupported<OESTextureHalfFloatLinear>(result, false);
2602 appendIfSupported<OESVertexArrayObject>(result, false); 2605 appendIfSupported<OESVertexArrayObject>(result, false);
2603 appendIfSupported<WebGLCompressedTextureATC>(result, true); 2606 appendIfSupported<WebGLCompressedTextureATC>(result, true);
2604 appendIfSupported<WebGLCompressedTexturePVRTC>(result, true); 2607 appendIfSupported<WebGLCompressedTexturePVRTC>(result, true);
2605 appendIfSupported<WebGLCompressedTextureS3TC>(result, true); 2608 appendIfSupported<WebGLCompressedTextureS3TC>(result, true);
2606 appendIfSupported<WebGLDepthTexture>(result, true); 2609 appendIfSupported<WebGLDepthTexture>(result, true);
2607 appendIfSupported<WebGLLoseContext>(result, false); 2610 appendIfSupported<WebGLLoseContext>(result, false);
2608 2611
2609 if (allowPrivilegedExtensions()) { 2612 if (allowPrivilegedExtensions()) {
2610 appendIfSupported<WebGLDebugShaders>(result, false); 2613 appendIfSupported<WebGLDebugShaders>(result, false);
2611 appendIfSupported<WebGLDebugRendererInfo>(result, false); 2614 appendIfSupported<WebGLDebugRendererInfo>(result, false);
(...skipping 1708 matching lines...) Expand 10 before | Expand all | Expand 10 after
4320 case GraphicsContext3D::SCISSOR_BOX: 4323 case GraphicsContext3D::SCISSOR_BOX:
4321 case GraphicsContext3D::VIEWPORT: 4324 case GraphicsContext3D::VIEWPORT:
4322 length = 4; 4325 length = 4;
4323 break; 4326 break;
4324 default: 4327 default:
4325 notImplemented(); 4328 notImplemented();
4326 } 4329 }
4327 return WebGLGetInfo(Int32Array::create(value, length)); 4330 return WebGLGetInfo(Int32Array::create(value, length));
4328 } 4331 }
4329 4332
4330 void WebGLRenderingContext::handleNPOTTextures(const char* functionName, bool pr epareToDraw) 4333 void WebGLRenderingContext::handleTexturesCompleteness(const char* functionName, bool prepareToDraw)
4331 { 4334 {
4332 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4335 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4333 bool resetActiveUnit = false; 4336 bool resetActiveUnit = false;
4337 String msgHint = String();
4334 for (unsigned ii = 0; ii < m_textureUnits.size(); ++ii) { 4338 for (unsigned ii = 0; ii < m_textureUnits.size(); ++ii) {
4335 if ((m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_textu re2DBinding->needToUseBlackTexture()) 4339 GC3Denum target[7] = { GraphicsContext3D::TEXTURE_2D,
Ken Russell (switch to Gerrit) 2013/05/13 20:00:35 Inlining this code here is inefficient and hard to
4336 || (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture())) { 4340 GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X, GraphicsContext3D::T EXTURE_CUBE_MAP_NEGATIVE_X,
4337 if (ii != m_activeTextureUnit) { 4341 GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y, GraphicsContext3D::T EXTURE_CUBE_MAP_NEGATIVE_Y,
4338 m_context->activeTexture(ii); 4342 GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z, GraphicsContext3D::T EXTURE_CUBE_MAP_NEGATIVE_Z };
4339 resetActiveUnit = true; 4343 for (unsigned i = 0; i < 7; i++) {
4340 } else if (resetActiveUnit) { 4344 WebGLTexture* textureBinding =
4341 m_context->activeTexture(ii); 4345 (target[i] == GraphicsContext3D::TEXTURE_2D) ? (m_textureUnits[i i].m_texture2DBinding ? m_textureUnits[ii].m_texture2DBinding.get() : 0)
Ken Russell (switch to Gerrit) 2013/05/13 20:00:35 The test here and below is unnecessary; you can ju
4342 resetActiveUnit = false; 4346 : (m_textureUnits[ii].m_textureCubeMapBinding ? m_textureUni ts[ii].m_textureCubeMapBinding.get() : 0);
4347 if (textureBinding) {
4348 bool needToUseBlackTexture = false;
4349 if (textureBinding->needToUseBlackTexture()) {
4350 needToUseBlackTexture = true;
4351 msgHint.append("It maybe non-power-of-2 and have incompatibl e texture filtering or is not 'texture complete");
4352 }
4353 if ((textureBinding->getType(target[i], 0) == GraphicsContext3D: :FLOAT && !m_oesTextureFloatLinear)
4354 || (textureBinding->getType(target[i], 0) == GraphicsContext 3D::HALF_FLOAT_OES && !m_oesTextureHalfFloatLinear)) {
4355 if (textureBinding->getMagFilter() != GraphicsContext3D::NEA REST
4356 || (textureBinding->getMinFilter() != GraphicsContext3D: :NEAREST && textureBinding->getMinFilter() != GraphicsContext3D::NEAREST_MIPMAP_ NEAREST)) {
4357 needToUseBlackTexture = true;
4358 msgHint.append("the texture is of Float type and require s a linear filtering but the linear filtering extension is disabled or not suppo rted.");
4359 }
4360 }
4361 if (needToUseBlackTexture) {
4362 if (ii != m_activeTextureUnit) {
4363 m_context->activeTexture(ii);
4364 resetActiveUnit = true;
4365 } else if (resetActiveUnit) {
4366 m_context->activeTexture(ii);
4367 resetActiveUnit = false;
4368 }
4369 WebGLTexture* texTemp = 0;
4370 if (prepareToDraw) {
4371 String msg(String("texture bound to texture unit ") + St ring::number(ii)
4372 + " is not renderable: " + msgHint);
4373 printGLWarningToConsole(functionName, msg.utf8().data()) ;
4374 texTemp = (target[i] == GraphicsContext3D::TEXTURE_2D) ? m_blackTexture2D.get() : m_blackTextureCubeMap.get();
4375 } else
4376 texTemp = (target[i] == GraphicsContext3D::TEXTURE_2D) ? m_textureUnits[ii].m_texture2DBinding.get() : m_textureUnits[ii].m_textureCubeM apBinding.get();
4377 m_context->bindTexture((target[i] == GraphicsContext3D::TEXT URE_2D) ? GraphicsContext3D::TEXTURE_2D : GraphicsContext3D::TEXTURE_CUBE_MAP, o bjectOrZero(texTemp));
4378 }
4343 } 4379 }
4344 WebGLTexture* tex2D;
4345 WebGLTexture* texCubeMap;
4346 if (prepareToDraw) {
4347 String msg(String("texture bound to texture unit ") + String::nu mber(ii)
4348 + " is not renderable. It maybe non-power-of-2 and have inco mpatible texture filtering or is not 'texture complete'");
4349 printGLWarningToConsole(functionName, msg.utf8().data());
4350 tex2D = m_blackTexture2D.get();
4351 texCubeMap = m_blackTextureCubeMap.get();
4352 } else {
4353 tex2D = m_textureUnits[ii].m_texture2DBinding.get();
4354 texCubeMap = m_textureUnits[ii].m_textureCubeMapBinding.get();
4355 }
4356 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_te xture2DBinding->needToUseBlackTexture())
4357 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZe ro(tex2D));
4358 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture())
4359 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, obje ctOrZero(texCubeMap));
4360 } 4380 }
4361 } 4381 }
4362 if (resetActiveUnit) 4382 if (resetActiveUnit)
4363 m_context->activeTexture(m_activeTextureUnit); 4383 m_context->activeTexture(m_activeTextureUnit);
4364 } 4384 }
4365 4385
4366 void WebGLRenderingContext::createFallbackBlackTextures1x1() 4386 void WebGLRenderingContext::createFallbackBlackTextures1x1()
4367 { 4387 {
4368 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4388 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4369 unsigned char black[] = {0, 0, 0, 255}; 4389 unsigned char black[] = {0, 0, 0, 255};
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
5450 bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_framebufferBinding.get(), ec); 5470 bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_framebufferBinding.get(), ec);
5451 } 5471 }
5452 5472
5453 void WebGLRenderingContext::restoreCurrentTexture2D() 5473 void WebGLRenderingContext::restoreCurrentTexture2D()
5454 { 5474 {
5455 ExceptionCode ec; 5475 ExceptionCode ec;
5456 bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUni t].m_texture2DBinding.get(), ec); 5476 bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUni t].m_texture2DBinding.get(), ec);
5457 } 5477 }
5458 5478
5459 } // namespace WebCore 5479 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698