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

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 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 m_maxColorAttachments = 0; 629 m_maxColorAttachments = 0;
628 630
629 m_backDrawBuffer = GraphicsContext3D::BACK; 631 m_backDrawBuffer = GraphicsContext3D::BACK;
630 632
631 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, WebGLVe rtexArrayObjectOES::VaoTypeDefault); 633 m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::create(this, WebGLVe rtexArrayObjectOES::VaoTypeDefault);
632 addContextObject(m_defaultVertexArrayObject.get()); 634 addContextObject(m_defaultVertexArrayObject.get());
633 m_boundVertexArrayObject = m_defaultVertexArrayObject; 635 m_boundVertexArrayObject = m_defaultVertexArrayObject;
634 636
635 m_vertexAttribValue.resize(m_maxVertexAttribs); 637 m_vertexAttribValue.resize(m_maxVertexAttribs);
636 638
637 if (!isGLES2NPOTStrict()) 639 createFallbackBlackTextures1x1();
638 createFallbackBlackTextures1x1();
639 640
640 IntSize canvasSize = clampedCanvasSize(); 641 IntSize canvasSize = clampedCanvasSize();
641 m_drawingBuffer->reset(canvasSize); 642 m_drawingBuffer->reset(canvasSize);
642 643
643 m_context->viewport(0, 0, canvasSize.width(), canvasSize.height()); 644 m_context->viewport(0, 0, canvasSize.width(), canvasSize.height());
644 m_context->scissor(0, 0, canvasSize.width(), canvasSize.height()); 645 m_context->scissor(0, 0, canvasSize.width(), canvasSize.height());
645 646
646 m_context->setContextLostCallback(adoptPtr(new WebGLRenderingContextLostCall back(this))); 647 m_context->setContextLostCallback(adoptPtr(new WebGLRenderingContextLostCall back(this)));
647 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe ssageCallback(this))); 648 m_context->setErrorMessageCallback(adoptPtr(new WebGLRenderingContextErrorMe ssageCallback(this)));
648 649
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 } 1744 }
1744 1745
1745 const char* reason = "framebuffer incomplete"; 1746 const char* reason = "framebuffer incomplete";
1746 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 1747 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) {
1747 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "dra wArrays", reason); 1748 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "dra wArrays", reason);
1748 return; 1749 return;
1749 } 1750 }
1750 1751
1751 clearIfComposited(); 1752 clearIfComposited();
1752 1753
1753 bool vertexAttrib0Simulated = false; 1754 handleTextureCompleteness("drawArrays", true);
1754 if (!isGLES2NPOTStrict())
1755 handleNPOTTextures("drawArrays", true);
1756 m_context->drawArrays(mode, first, count); 1755 m_context->drawArrays(mode, first, count);
1757 if (!isGLES2NPOTStrict()) 1756 handleTextureCompleteness("drawArrays", false);
1758 handleNPOTTextures("drawArrays", false);
1759 markContextChanged(); 1757 markContextChanged();
1760 } 1758 }
1761 1759
1762 void WebGLRenderingContext::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denu m type, long long offset, ExceptionCode& ec) 1760 void WebGLRenderingContext::drawElements(GC3Denum mode, GC3Dsizei count, GC3Denu m type, long long offset, ExceptionCode& ec)
1763 { 1761 {
1764 UNUSED_PARAM(ec); 1762 UNUSED_PARAM(ec);
1765 1763
1766 if (isContextLost() || !validateDrawMode("drawElements", mode)) 1764 if (isContextLost() || !validateDrawMode("drawElements", mode))
1767 return; 1765 return;
1768 1766
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 return; 1802 return;
1805 } 1803 }
1806 1804
1807 const char* reason = "framebuffer incomplete"; 1805 const char* reason = "framebuffer incomplete";
1808 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) { 1806 if (m_framebufferBinding && !m_framebufferBinding->onAccess(graphicsContext3 D(), &reason)) {
1809 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "dra wElements", reason); 1807 synthesizeGLError(GraphicsContext3D::INVALID_FRAMEBUFFER_OPERATION, "dra wElements", reason);
1810 return; 1808 return;
1811 } 1809 }
1812 clearIfComposited(); 1810 clearIfComposited();
1813 1811
1814 if (!isGLES2NPOTStrict()) 1812 handleTextureCompleteness("drawElements", true);
1815 handleNPOTTextures("drawElements", true);
1816 m_context->drawElements(mode, count, type, static_cast<GC3Dintptr>(offset)); 1813 m_context->drawElements(mode, count, type, static_cast<GC3Dintptr>(offset));
1817 if (!isGLES2NPOTStrict()) 1814 handleTextureCompleteness("drawElements", false);
1818 handleNPOTTextures("drawElements", false);
1819 markContextChanged(); 1815 markContextChanged();
1820 } 1816 }
1821 1817
1822 void WebGLRenderingContext::enable(GC3Denum cap) 1818 void WebGLRenderingContext::enable(GC3Denum cap)
1823 { 1819 {
1824 if (isContextLost() || !validateCapability("enable", cap)) 1820 if (isContextLost() || !validateCapability("enable", cap))
1825 return; 1821 return;
1826 if (cap == GraphicsContext3D::STENCIL_TEST) { 1822 if (cap == GraphicsContext3D::STENCIL_TEST) {
1827 m_stencilEnabled = true; 1823 m_stencilEnabled = true;
1828 applyStencilTest(); 1824 applyStencilTest();
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 if (getExtensionIfMatch<WebGLCompressedTextureATC>(name, m_webglCompressedTe xtureATC, webkitPrefix, extension)) 2124 if (getExtensionIfMatch<WebGLCompressedTextureATC>(name, m_webglCompressedTe xtureATC, webkitPrefix, extension))
2129 return extension; 2125 return extension;
2130 if (getExtensionIfMatch<WebGLCompressedTexturePVRTC>(name, m_webglCompressed TexturePVRTC, webkitPrefix, extension)) 2126 if (getExtensionIfMatch<WebGLCompressedTexturePVRTC>(name, m_webglCompressed TexturePVRTC, webkitPrefix, extension))
2131 return extension; 2127 return extension;
2132 if (getExtensionIfMatch<WebGLCompressedTextureS3TC>(name, m_webglCompressedT extureS3TC, bothPrefixes, extension)) 2128 if (getExtensionIfMatch<WebGLCompressedTextureS3TC>(name, m_webglCompressedT extureS3TC, bothPrefixes, extension))
2133 return extension; 2129 return extension;
2134 if (getExtensionIfMatch<WebGLDepthTexture>(name, m_webglDepthTexture, bothPr efixes, extension)) 2130 if (getExtensionIfMatch<WebGLDepthTexture>(name, m_webglDepthTexture, bothPr efixes, extension))
2135 return extension; 2131 return extension;
2136 if (getExtensionIfMatch<EXTDrawBuffers>(name, m_extDrawBuffers, unprefixed, extension)) 2132 if (getExtensionIfMatch<EXTDrawBuffers>(name, m_extDrawBuffers, unprefixed, extension))
2137 return extension; 2133 return extension;
2134 if (getExtensionIfMatch<OESTextureFloatLinear>(name, m_oesTextureFloatLinear , unprefixed, extension))
2135 return extension;
2136 if (getExtensionIfMatch<OESTextureHalfFloatLinear>(name, m_oesTextureHalfFlo atLinear, unprefixed, extension))
2137 return extension;
2138 if (allowPrivilegedExtensions()) { 2138 if (allowPrivilegedExtensions()) {
2139 if (getExtensionIfMatch<WebGLDebugRendererInfo>(name, m_webglDebugRender erInfo, unprefixed, extension)) 2139 if (getExtensionIfMatch<WebGLDebugRendererInfo>(name, m_webglDebugRender erInfo, unprefixed, extension))
2140 return extension; 2140 return extension;
2141 if (getExtensionIfMatch<WebGLDebugShaders>(name, m_webglDebugShaders, un prefixed, extension)) 2141 if (getExtensionIfMatch<WebGLDebugShaders>(name, m_webglDebugShaders, un prefixed, extension))
2142 return extension; 2142 return extension;
2143 } 2143 }
2144 2144
2145 return 0; 2145 return 0;
2146 } 2146 }
2147 2147
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2614 { 2614 {
2615 Vector<String> result; 2615 Vector<String> result;
2616 if (isContextLost()) 2616 if (isContextLost())
2617 return result; 2617 return result;
2618 2618
2619 appendIfSupported<EXTDrawBuffers>(result, false); 2619 appendIfSupported<EXTDrawBuffers>(result, false);
2620 appendIfSupported<EXTTextureFilterAnisotropic>(result, true); 2620 appendIfSupported<EXTTextureFilterAnisotropic>(result, true);
2621 appendIfSupported<OESElementIndexUint>(result, false); 2621 appendIfSupported<OESElementIndexUint>(result, false);
2622 appendIfSupported<OESStandardDerivatives>(result, false); 2622 appendIfSupported<OESStandardDerivatives>(result, false);
2623 appendIfSupported<OESTextureFloat>(result, false); 2623 appendIfSupported<OESTextureFloat>(result, false);
2624 appendIfSupported<OESTextureFloatLinear>(result, false);
2625 appendIfSupported<OESTextureHalfFloat>(result, false);
2626 appendIfSupported<OESTextureHalfFloatLinear>(result, false);
2624 appendIfSupported<OESVertexArrayObject>(result, false); 2627 appendIfSupported<OESVertexArrayObject>(result, false);
2625 appendIfSupported<WebGLCompressedTextureATC>(result, true); 2628 appendIfSupported<WebGLCompressedTextureATC>(result, true);
2626 appendIfSupported<WebGLCompressedTexturePVRTC>(result, true); 2629 appendIfSupported<WebGLCompressedTexturePVRTC>(result, true);
2627 appendIfSupported<WebGLCompressedTextureS3TC>(result, true); 2630 appendIfSupported<WebGLCompressedTextureS3TC>(result, true);
2628 appendIfSupported<WebGLDepthTexture>(result, true); 2631 appendIfSupported<WebGLDepthTexture>(result, true);
2629 appendIfSupported<WebGLLoseContext>(result, false); 2632 appendIfSupported<WebGLLoseContext>(result, false);
2630 2633
2631 if (allowPrivilegedExtensions()) { 2634 if (allowPrivilegedExtensions()) {
2632 appendIfSupported<WebGLDebugShaders>(result, false); 2635 appendIfSupported<WebGLDebugShaders>(result, false);
2633 appendIfSupported<WebGLDebugRendererInfo>(result, false); 2636 appendIfSupported<WebGLDebugRendererInfo>(result, false);
(...skipping 1708 matching lines...) Expand 10 before | Expand all | Expand 10 after
4342 case GraphicsContext3D::SCISSOR_BOX: 4345 case GraphicsContext3D::SCISSOR_BOX:
4343 case GraphicsContext3D::VIEWPORT: 4346 case GraphicsContext3D::VIEWPORT:
4344 length = 4; 4347 length = 4;
4345 break; 4348 break;
4346 default: 4349 default:
4347 notImplemented(); 4350 notImplemented();
4348 } 4351 }
4349 return WebGLGetInfo(Int32Array::create(value, length)); 4352 return WebGLGetInfo(Int32Array::create(value, length));
4350 } 4353 }
4351 4354
4352 void WebGLRenderingContext::handleNPOTTextures(const char* functionName, bool pr epareToDraw) 4355 void WebGLRenderingContext::handleTextureCompleteness(const char* functionName, bool prepareToDraw)
4353 { 4356 {
4354 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4357 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4355 bool resetActiveUnit = false; 4358 bool resetActiveUnit = false;
4359 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>((m_oesTextureFloatLinear ? WebGLTexture::TextureFloatLinearExtensi onEnabled : 0)
4360 | (m_oesTextureHalfFloatLinear ? WebGLTexture::TextureHalfFloatLinearExt ensionEnabled : 0));
4356 for (unsigned ii = 0; ii < m_textureUnits.size(); ++ii) { 4361 for (unsigned ii = 0; ii < m_textureUnits.size(); ++ii) {
4357 if ((m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_textu re2DBinding->needToUseBlackTexture()) 4362 if ((m_textureUnits[ii].m_texture2DBinding.get() && m_textureUnits[ii].m _texture2DBinding->needToUseBlackTexture(flag))
4358 || (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture())) { 4363 || (m_textureUnits[ii].m_textureCubeMapBinding.get() && m_textureUni ts[ii].m_textureCubeMapBinding->needToUseBlackTexture(flag))) {
4359 if (ii != m_activeTextureUnit) { 4364 if (ii != m_activeTextureUnit) {
4360 m_context->activeTexture(ii); 4365 m_context->activeTexture(ii);
4361 resetActiveUnit = true; 4366 resetActiveUnit = true;
4362 } else if (resetActiveUnit) { 4367 } else if (resetActiveUnit) {
4363 m_context->activeTexture(ii); 4368 m_context->activeTexture(ii);
4364 resetActiveUnit = false; 4369 resetActiveUnit = false;
4365 } 4370 }
4366 WebGLTexture* tex2D; 4371 WebGLTexture* tex2D;
4367 WebGLTexture* texCubeMap; 4372 WebGLTexture* texCubeMap;
4368 if (prepareToDraw) { 4373 if (prepareToDraw) {
4369 String msg(String("texture bound to texture unit ") + String::nu mber(ii) 4374 String msg(String("texture bound to texture unit ") + String::nu mber(ii)
4370 + " is not renderable. It maybe non-power-of-2 and have inco mpatible texture filtering or is not 'texture complete'"); 4375 + " is not renderable. It maybe non-power-of-2 and have inco mpatible texture filtering or is not 'texture complete'."
4376 + " Or the texture is Float or Half Float type with linear f iltering while OES_float_linear or OES_half_float_linear extension is not enable d.");
4371 printGLWarningToConsole(functionName, msg.utf8().data()); 4377 printGLWarningToConsole(functionName, msg.utf8().data());
4372 tex2D = m_blackTexture2D.get(); 4378 tex2D = m_blackTexture2D.get();
4373 texCubeMap = m_blackTextureCubeMap.get(); 4379 texCubeMap = m_blackTextureCubeMap.get();
4374 } else { 4380 } else {
4375 tex2D = m_textureUnits[ii].m_texture2DBinding.get(); 4381 tex2D = m_textureUnits[ii].m_texture2DBinding.get();
4376 texCubeMap = m_textureUnits[ii].m_textureCubeMapBinding.get(); 4382 texCubeMap = m_textureUnits[ii].m_textureCubeMapBinding.get();
4377 } 4383 }
4378 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_te xture2DBinding->needToUseBlackTexture()) 4384 if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_te xture2DBinding->needToUseBlackTexture(flag))
4379 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZe ro(tex2D)); 4385 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZe ro(tex2D));
4380 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture()) 4386 if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii] .m_textureCubeMapBinding->needToUseBlackTexture(flag))
4381 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, obje ctOrZero(texCubeMap)); 4387 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, obje ctOrZero(texCubeMap));
4382 } 4388 }
4383 } 4389 }
4384 if (resetActiveUnit) 4390 if (resetActiveUnit)
4385 m_context->activeTexture(m_activeTextureUnit); 4391 m_context->activeTexture(m_activeTextureUnit);
4386 } 4392 }
4387 4393
4388 void WebGLRenderingContext::createFallbackBlackTextures1x1() 4394 void WebGLRenderingContext::createFallbackBlackTextures1x1()
4389 { 4395 {
4390 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4396 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
5486 5492
5487 void WebGLRenderingContext::multisamplingChanged(bool enabled) 5493 void WebGLRenderingContext::multisamplingChanged(bool enabled)
5488 { 5494 {
5489 if (m_multisamplingAllowed != enabled) { 5495 if (m_multisamplingAllowed != enabled) {
5490 m_multisamplingAllowed = enabled; 5496 m_multisamplingAllowed = enabled;
5491 forceLostContext(WebGLRenderingContext::AutoRecoverSyntheticLostContext) ; 5497 forceLostContext(WebGLRenderingContext::AutoRecoverSyntheticLostContext) ;
5492 } 5498 }
5493 } 5499 }
5494 5500
5495 } // namespace WebCore 5501 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698