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

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

Issue 894143002: Adding Blink bindings for WebGL 2 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed @kbr's feedback Created 5 years, 10 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 visitor->trace(m_context); 569 visitor->trace(m_context);
570 } 570 }
571 571
572 private: 572 private:
573 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContextBase * context) 573 explicit WebGLRenderingContextErrorMessageCallback(WebGLRenderingContextBase * context)
574 : m_context(context) { } 574 : m_context(context) { }
575 575
576 RawPtrWillBeMember<WebGLRenderingContextBase> m_context; 576 RawPtrWillBeMember<WebGLRenderingContextBase> m_context;
577 }; 577 };
578 578
579 static bool shouldFailContextCreationForTesting = false;
dshwang 2015/02/04 14:05:22 how about defining it in anonymous namespace at th
580
581 PassOwnPtr<blink::WebGraphicsContext3D> WebGLRenderingContextBase::createWebGrap hicsContext3D(HTMLCanvasElement* canvas, WebGLContextAttributes attributes, unsi gned webGLVersion)
582 {
583 Document& document = canvas->document();
584 LocalFrame* frame = document.frame();
585 if (!frame) {
586 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext."));
587 return nullptr;
588 }
589 Settings* settings = frame->settings();
590
591 // The FrameLoaderClient might block creation of a new WebGL context despite the page settings; in
592 // particular, if WebGL contexts were lost one or more times via the GL_ARB_ robustness extension.
593 if (!frame->loader().client()->allowWebGL(settings && settings->webGLEnabled ())) {
594 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, "Web page was not allowed to create a WebGL cont ext."));
595 return nullptr;
596 }
597
598 blink::WebGraphicsContext3D::Attributes wgc3dAttributes = toWebGraphicsConte xt3DAttributes(attributes, document.topDocument().url().string(), settings, webG LVersion);
599 blink::WebGLInfo glInfo;
600 OwnPtr<blink::WebGraphicsContext3D> context = adoptPtr(blink::Platform::curr ent()->createOffscreenGraphicsContext3D(wgc3dAttributes, 0, &glInfo));
601 if (!context || shouldFailContextCreationForTesting) {
602 shouldFailContextCreationForTesting = false;
603 String statusMessage;
604 if (!glInfo.contextInfoCollectionFailure.isEmpty()) {
605 statusMessage.append("Could not create a WebGL context.");
606 statusMessage.append(glInfo.contextInfoCollectionFailure);
607 } else {
608 statusMessage.append("Could not create a WebGL context");
609 if (!glInfo.vendorInfo.isEmpty()) {
610 statusMessage.append(" VendorInfo = ");
611 statusMessage.append(glInfo.vendorInfo);
612 } else {
613 statusMessage.append(" VendorInfo = Not Available");
614 }
615 if (!glInfo.rendererInfo.isEmpty()) {
616 statusMessage.append(", RendererInfo = ");
617 statusMessage.append(glInfo.rendererInfo);
618 } else {
619 statusMessage.append(", RendererInfo = Not Available");
620 }
621 if (!glInfo.driverVersion.isEmpty()) {
622 statusMessage.append(", DriverInfo = ");
623 statusMessage.append(glInfo.driverVersion);
624 } else {
625 statusMessage.append(", DriverInfo = Not Available");
626 }
627 statusMessage.append(".");
628 }
629 canvas->dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcon textcreationerror, false, true, statusMessage));
630 return nullptr;
631 }
632
633 return context.release();
634 }
635
636 void WebGLRenderingContextBase::forceNextWebGLContextCreationToFail()
637 {
638 shouldFailContextCreationForTesting = true;
639 }
640
579 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<blink::WebGraphicsContext3D> context, const WebGLContextAttribu tes& requestedAttributes) 641 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<blink::WebGraphicsContext3D> context, const WebGLContextAttribu tes& requestedAttributes)
580 : CanvasRenderingContext(passedCanvas) 642 : CanvasRenderingContext(passedCanvas)
581 , ActiveDOMObject(&passedCanvas->document()) 643 , ActiveDOMObject(&passedCanvas->document())
582 , m_contextLostMode(NotLostContext) 644 , m_contextLostMode(NotLostContext)
583 , m_autoRecoveryMethod(Manual) 645 , m_autoRecoveryMethod(Manual)
584 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) 646 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent)
585 , m_restoreAllowed(false) 647 , m_restoreAllowed(false)
586 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) 648 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext)
587 , m_generatedImageCache(4) 649 , m_generatedImageCache(4)
588 , m_requestedAttributes(requestedAttributes) 650 , m_requestedAttributes(requestedAttributes)
(...skipping 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 return WebGLAny(scriptState, m_unpackPremultiplyAlpha); 2521 return WebGLAny(scriptState, m_unpackPremultiplyAlpha);
2460 case GC3D_UNPACK_COLORSPACE_CONVERSION_WEBGL: 2522 case GC3D_UNPACK_COLORSPACE_CONVERSION_WEBGL:
2461 return WebGLAny(scriptState, m_unpackColorspaceConversion); 2523 return WebGLAny(scriptState, m_unpackColorspaceConversion);
2462 case GL_VENDOR: 2524 case GL_VENDOR:
2463 return WebGLAny(scriptState, String("WebKit")); 2525 return WebGLAny(scriptState, String("WebKit"));
2464 case GL_VERSION: 2526 case GL_VERSION:
2465 return WebGLAny(scriptState, "WebGL 1.0 (" + String(webContext()->getStr ing(GL_VERSION)) + ")"); 2527 return WebGLAny(scriptState, "WebGL 1.0 (" + String(webContext()->getStr ing(GL_VERSION)) + ")");
2466 case GL_VIEWPORT: 2528 case GL_VIEWPORT:
2467 return getWebGLIntArrayParameter(scriptState, pname); 2529 return getWebGLIntArrayParameter(scriptState, pname);
2468 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives 2530 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives
2469 if (extensionEnabled(OESStandardDerivativesName)) 2531 if (extensionEnabled(OESStandardDerivativesName) || isWebGL2OrHigher())
2470 return getUnsignedIntParameter(scriptState, GL_FRAGMENT_SHADER_DERIV ATIVE_HINT_OES); 2532 return getUnsignedIntParameter(scriptState, GL_FRAGMENT_SHADER_DERIV ATIVE_HINT_OES);
2471 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_standard_derivatives not enabled"); 2533 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_standard_derivatives not enabled");
2472 return ScriptValue::createNull(scriptState); 2534 return ScriptValue::createNull(scriptState);
2473 case WebGLDebugRendererInfo::UNMASKED_RENDERER_WEBGL: 2535 case WebGLDebugRendererInfo::UNMASKED_RENDERER_WEBGL:
2474 if (extensionEnabled(WebGLDebugRendererInfoName)) 2536 if (extensionEnabled(WebGLDebugRendererInfoName))
2475 return WebGLAny(scriptState, webContext()->getString(GL_RENDERER)); 2537 return WebGLAny(scriptState, webContext()->getString(GL_RENDERER));
2476 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled"); 2538 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled");
2477 return ScriptValue::createNull(scriptState); 2539 return ScriptValue::createNull(scriptState);
2478 case WebGLDebugRendererInfo::UNMASKED_VENDOR_WEBGL: 2540 case WebGLDebugRendererInfo::UNMASKED_VENDOR_WEBGL:
2479 if (extensionEnabled(WebGLDebugRendererInfoName)) 2541 if (extensionEnabled(WebGLDebugRendererInfoName))
2480 return WebGLAny(scriptState, webContext()->getString(GL_VENDOR)); 2542 return WebGLAny(scriptState, webContext()->getString(GL_VENDOR));
2481 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled"); 2543 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_debug_renderer_info not enabled");
2482 return ScriptValue::createNull(scriptState); 2544 return ScriptValue::createNull(scriptState);
2483 case GL_VERTEX_ARRAY_BINDING_OES: // OES_vertex_array_object 2545 case GL_VERTEX_ARRAY_BINDING_OES: // OES_vertex_array_object
2484 if (extensionEnabled(OESVertexArrayObjectName)) { 2546 if (extensionEnabled(OESVertexArrayObjectName) || isWebGL2OrHigher()) {
2485 if (!m_boundVertexArrayObject->isDefaultObject()) 2547 if (!m_boundVertexArrayObject->isDefaultObject())
2486 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject> (m_boundVertexArrayObject.get())); 2548 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject> (m_boundVertexArrayObject.get()));
2487 return ScriptValue::createNull(scriptState); 2549 return ScriptValue::createNull(scriptState);
2488 } 2550 }
2489 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_vertex_array_object not enabled"); 2551 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, OES_vertex_array_object not enabled");
2490 return ScriptValue::createNull(scriptState); 2552 return ScriptValue::createNull(scriptState);
2491 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic 2553 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic
2492 if (extensionEnabled(EXTTextureFilterAnisotropicName)) 2554 if (extensionEnabled(EXTTextureFilterAnisotropicName) || isWebGL2OrHighe r())
2493 return getUnsignedIntParameter(scriptState, GL_MAX_TEXTURE_MAX_ANISO TROPY_EXT); 2555 return getUnsignedIntParameter(scriptState, GL_MAX_TEXTURE_MAX_ANISO TROPY_EXT);
2494 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, EXT_texture_filter_anisotropic not enabled"); 2556 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, EXT_texture_filter_anisotropic not enabled");
2495 return ScriptValue::createNull(scriptState); 2557 return ScriptValue::createNull(scriptState);
2496 case GL_MAX_COLOR_ATTACHMENTS_EXT: // EXT_draw_buffers BEGIN 2558 case GL_MAX_COLOR_ATTACHMENTS_EXT: // EXT_draw_buffers BEGIN
2497 if (extensionEnabled(WebGLDrawBuffersName)) 2559 if (extensionEnabled(WebGLDrawBuffersName) || isWebGL2OrHigher())
2498 return WebGLAny(scriptState, maxColorAttachments()); 2560 return WebGLAny(scriptState, maxColorAttachments());
2499 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_draw_buffers not enabled"); 2561 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_draw_buffers not enabled");
2500 return ScriptValue::createNull(scriptState); 2562 return ScriptValue::createNull(scriptState);
2501 case GL_MAX_DRAW_BUFFERS_EXT: 2563 case GL_MAX_DRAW_BUFFERS_EXT:
2502 if (extensionEnabled(WebGLDrawBuffersName)) 2564 if (extensionEnabled(WebGLDrawBuffersName) || isWebGL2OrHigher())
2503 return WebGLAny(scriptState, maxDrawBuffers()); 2565 return WebGLAny(scriptState, maxDrawBuffers());
2504 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_draw_buffers not enabled"); 2566 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me, WEBGL_draw_buffers not enabled");
2505 return ScriptValue::createNull(scriptState); 2567 return ScriptValue::createNull(scriptState);
2506 default: 2568 default:
2507 if (extensionEnabled(WebGLDrawBuffersName) 2569 if ((extensionEnabled(WebGLDrawBuffersName) || isWebGL2OrHigher())
2508 && pname >= GL_DRAW_BUFFER0_EXT 2570 && pname >= GL_DRAW_BUFFER0_EXT
2509 && pname < static_cast<GLenum>(GL_DRAW_BUFFER0_EXT + maxDrawBuffers( ))) { 2571 && pname < static_cast<GLenum>(GL_DRAW_BUFFER0_EXT + maxDrawBuffers( ))) {
2510 GLint value = GL_NONE; 2572 GLint value = GL_NONE;
2511 if (m_framebufferBinding) 2573 if (m_framebufferBinding)
2512 value = m_framebufferBinding->getDrawBuffer(pname); 2574 value = m_framebufferBinding->getDrawBuffer(pname);
2513 else // emulated backbuffer 2575 else // emulated backbuffer
2514 value = m_backDrawBuffer; 2576 value = m_backDrawBuffer;
2515 return WebGLAny(scriptState, value); 2577 return WebGLAny(scriptState, value);
2516 } 2578 }
2517 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me"); 2579 synthesizeGLError(GL_INVALID_ENUM, "getParameter", "invalid parameter na me");
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 case GL_TEXTURE_MAG_FILTER: 2751 case GL_TEXTURE_MAG_FILTER:
2690 case GL_TEXTURE_MIN_FILTER: 2752 case GL_TEXTURE_MIN_FILTER:
2691 case GL_TEXTURE_WRAP_S: 2753 case GL_TEXTURE_WRAP_S:
2692 case GL_TEXTURE_WRAP_T: 2754 case GL_TEXTURE_WRAP_T:
2693 { 2755 {
2694 GLint value = 0; 2756 GLint value = 0;
2695 webContext()->getTexParameteriv(target, pname, &value); 2757 webContext()->getTexParameteriv(target, pname, &value);
2696 return WebGLAny(scriptState, static_cast<unsigned>(value)); 2758 return WebGLAny(scriptState, static_cast<unsigned>(value));
2697 } 2759 }
2698 case GL_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic 2760 case GL_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic
2699 if (extensionEnabled(EXTTextureFilterAnisotropicName)) { 2761 if (extensionEnabled(EXTTextureFilterAnisotropicName) || isWebGL2OrHighe r()) {
2700 GLfloat value = 0.f; 2762 GLfloat value = 0.f;
2701 webContext()->getTexParameterfv(target, pname, &value); 2763 webContext()->getTexParameterfv(target, pname, &value);
2702 return WebGLAny(scriptState, value); 2764 return WebGLAny(scriptState, value);
2703 } 2765 }
2704 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name, EXT_texture_filter_anisotropic not enabled"); 2766 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name, EXT_texture_filter_anisotropic not enabled");
2705 return ScriptValue::createNull(scriptState); 2767 return ScriptValue::createNull(scriptState);
2706 default: 2768 default:
2707 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name"); 2769 synthesizeGLError(GL_INVALID_ENUM, "getTexParameter", "invalid parameter name");
2708 return ScriptValue::createNull(scriptState); 2770 return ScriptValue::createNull(scriptState);
2709 } 2771 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2877 ScriptValue WebGLRenderingContextBase::getVertexAttrib(ScriptState* scriptState, GLuint index, GLenum pname) 2939 ScriptValue WebGLRenderingContextBase::getVertexAttrib(ScriptState* scriptState, GLuint index, GLenum pname)
2878 { 2940 {
2879 if (isContextLost()) 2941 if (isContextLost())
2880 return ScriptValue::createNull(scriptState); 2942 return ScriptValue::createNull(scriptState);
2881 if (index >= m_maxVertexAttribs) { 2943 if (index >= m_maxVertexAttribs) {
2882 synthesizeGLError(GL_INVALID_VALUE, "getVertexAttrib", "index out of ran ge"); 2944 synthesizeGLError(GL_INVALID_VALUE, "getVertexAttrib", "index out of ran ge");
2883 return ScriptValue::createNull(scriptState); 2945 return ScriptValue::createNull(scriptState);
2884 } 2946 }
2885 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArr ayObject->getVertexAttribState(index); 2947 const WebGLVertexArrayObjectOES::VertexAttribState& state = m_boundVertexArr ayObject->getVertexAttribState(index);
2886 2948
2887 if (extensionEnabled(ANGLEInstancedArraysName) && pname == GL_VERTEX_ATTRIB_ ARRAY_DIVISOR_ANGLE) 2949 if ((extensionEnabled(ANGLEInstancedArraysName) || isWebGL2OrHigher())
2950 && pname == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE)
2888 return WebGLAny(scriptState, state.divisor); 2951 return WebGLAny(scriptState, state.divisor);
2889 2952
2890 switch (pname) { 2953 switch (pname) {
2891 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: 2954 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
2892 if (!state.bufferBinding || !state.bufferBinding->object()) 2955 if (!state.bufferBinding || !state.bufferBinding->object())
2893 return ScriptValue::createNull(scriptState); 2956 return ScriptValue::createNull(scriptState);
2894 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(state.b ufferBinding.get())); 2957 return WebGLAny(scriptState, PassRefPtrWillBeRawPtr<WebGLObject>(state.b ufferBinding.get()));
2895 case GL_VERTEX_ATTRIB_ARRAY_ENABLED: 2958 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
2896 return WebGLAny(scriptState, state.enabled); 2959 return WebGLAny(scriptState, state.enabled);
2897 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: 2960 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
(...skipping 27 matching lines...) Expand all
2925 void WebGLRenderingContextBase::hint(GLenum target, GLenum mode) 2988 void WebGLRenderingContextBase::hint(GLenum target, GLenum mode)
2926 { 2989 {
2927 if (isContextLost()) 2990 if (isContextLost())
2928 return; 2991 return;
2929 bool isValid = false; 2992 bool isValid = false;
2930 switch (target) { 2993 switch (target) {
2931 case GL_GENERATE_MIPMAP_HINT: 2994 case GL_GENERATE_MIPMAP_HINT:
2932 isValid = true; 2995 isValid = true;
2933 break; 2996 break;
2934 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives 2997 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: // OES_standard_derivatives
2935 if (extensionEnabled(OESStandardDerivativesName)) 2998 if (extensionEnabled(OESStandardDerivativesName) || isWebGL2OrHigher())
2936 isValid = true; 2999 isValid = true;
2937 break; 3000 break;
2938 } 3001 }
2939 if (!isValid) { 3002 if (!isValid) {
2940 synthesizeGLError(GL_INVALID_ENUM, "hint", "invalid target"); 3003 synthesizeGLError(GL_INVALID_ENUM, "hint", "invalid target");
2941 return; 3004 return;
2942 } 3005 }
2943 webContext()->hint(target, mode); 3006 webContext()->hint(target, mode);
2944 } 3007 }
2945 3008
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
3759 break; 3822 break;
3760 case GL_TEXTURE_WRAP_S: 3823 case GL_TEXTURE_WRAP_S:
3761 case GL_TEXTURE_WRAP_T: 3824 case GL_TEXTURE_WRAP_T:
3762 if ((isFloat && paramf != GL_CLAMP_TO_EDGE && paramf != GL_MIRRORED_REPE AT && paramf != GL_REPEAT) 3825 if ((isFloat && paramf != GL_CLAMP_TO_EDGE && paramf != GL_MIRRORED_REPE AT && paramf != GL_REPEAT)
3763 || (!isFloat && parami != GL_CLAMP_TO_EDGE && parami != GL_MIRRORED_ REPEAT && parami != GL_REPEAT)) { 3826 || (!isFloat && parami != GL_CLAMP_TO_EDGE && parami != GL_MIRRORED_ REPEAT && parami != GL_REPEAT)) {
3764 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid paramete r"); 3827 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid paramete r");
3765 return; 3828 return;
3766 } 3829 }
3767 break; 3830 break;
3768 case GL_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic 3831 case GL_TEXTURE_MAX_ANISOTROPY_EXT: // EXT_texture_filter_anisotropic
3769 if (!extensionEnabled(EXTTextureFilterAnisotropicName)) { 3832 if (!extensionEnabled(EXTTextureFilterAnisotropicName) || isWebGL2OrHigh er()) {
3770 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid paramete r, EXT_texture_filter_anisotropic not enabled"); 3833 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid paramete r, EXT_texture_filter_anisotropic not enabled");
3771 return; 3834 return;
3772 } 3835 }
3773 break; 3836 break;
3774 default: 3837 default:
3775 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid parameter na me"); 3838 synthesizeGLError(GL_INVALID_ENUM, "texParameter", "invalid parameter na me");
3776 return; 3839 return;
3777 } 3840 }
3778 if (isFloat) { 3841 if (isFloat) {
3779 tex->setParameterf(pname, paramf); 3842 tex->setParameterf(pname, paramf);
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
4600 default: 4663 default:
4601 notImplemented(); 4664 notImplemented();
4602 } 4665 }
4603 return WebGLAny(scriptState, DOMInt32Array::create(value, length)); 4666 return WebGLAny(scriptState, DOMInt32Array::create(value, length));
4604 } 4667 }
4605 4668
4606 void WebGLRenderingContextBase::handleTextureCompleteness(const char* functionNa me, bool prepareToDraw) 4669 void WebGLRenderingContextBase::handleTextureCompleteness(const char* functionNa me, bool prepareToDraw)
4607 { 4670 {
4608 // All calling functions check isContextLost, so a duplicate check is not ne eded here. 4671 // All calling functions check isContextLost, so a duplicate check is not ne eded here.
4609 bool resetActiveUnit = false; 4672 bool resetActiveUnit = false;
4610 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>((extensionEnabled(OESTextureFloatLinearName) ? WebGLTexture::Textu reFloatLinearExtensionEnabled : 0) 4673 WebGLTexture::TextureExtensionFlag flag = static_cast<WebGLTexture::TextureE xtensionFlag>(((extensionEnabled(OESTextureFloatLinearName) || isWebGL2OrHigher( )) ? WebGLTexture::TextureFloatLinearExtensionEnabled : 0)
4611 | (extensionEnabled(OESTextureHalfFloatLinearName) ? WebGLTexture::Textu reHalfFloatLinearExtensionEnabled : 0)); 4674 | ((extensionEnabled(OESTextureHalfFloatLinearName) || isWebGL2OrHigher( )) ? WebGLTexture::TextureHalfFloatLinearExtensionEnabled : 0));
4612 for (unsigned ii = 0; ii < m_onePlusMaxNonDefaultTextureUnit; ++ii) { 4675 for (unsigned ii = 0; ii < m_onePlusMaxNonDefaultTextureUnit; ++ii) {
4613 if ((m_textureUnits[ii].m_texture2DBinding.get() && m_textureUnits[ii].m _texture2DBinding->needToUseBlackTexture(flag)) 4676 if ((m_textureUnits[ii].m_texture2DBinding.get() && m_textureUnits[ii].m _texture2DBinding->needToUseBlackTexture(flag))
4614 || (m_textureUnits[ii].m_textureCubeMapBinding.get() && m_textureUni ts[ii].m_textureCubeMapBinding->needToUseBlackTexture(flag))) { 4677 || (m_textureUnits[ii].m_textureCubeMapBinding.get() && m_textureUni ts[ii].m_textureCubeMapBinding->needToUseBlackTexture(flag))) {
4615 if (ii != m_activeTextureUnit) { 4678 if (ii != m_activeTextureUnit) {
4616 webContext()->activeTexture(GL_TEXTURE0 + ii); 4679 webContext()->activeTexture(GL_TEXTURE0 + ii);
4617 resetActiveUnit = true; 4680 resetActiveUnit = true;
4618 } else if (resetActiveUnit) { 4681 } else if (resetActiveUnit) {
4619 webContext()->activeTexture(GL_TEXTURE0 + ii); 4682 webContext()->activeTexture(GL_TEXTURE0 + ii);
4620 resetActiveUnit = false; 4683 resetActiveUnit = false;
4621 } 4684 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
4753 { 4816 {
4754 switch (format) { 4817 switch (format) {
4755 case GL_ALPHA: 4818 case GL_ALPHA:
4756 case GL_LUMINANCE: 4819 case GL_LUMINANCE:
4757 case GL_LUMINANCE_ALPHA: 4820 case GL_LUMINANCE_ALPHA:
4758 case GL_RGB: 4821 case GL_RGB:
4759 case GL_RGBA: 4822 case GL_RGBA:
4760 break; 4823 break;
4761 case GL_DEPTH_STENCIL_OES: 4824 case GL_DEPTH_STENCIL_OES:
4762 case GL_DEPTH_COMPONENT: 4825 case GL_DEPTH_COMPONENT:
4763 if (extensionEnabled(WebGLDepthTextureName)) 4826 if (extensionEnabled(WebGLDepthTextureName) || isWebGL2OrHigher())
4764 break; 4827 break;
4765 synthesizeGLError(GL_INVALID_ENUM, functionName, "depth texture formats not enabled"); 4828 synthesizeGLError(GL_INVALID_ENUM, functionName, "depth texture formats not enabled");
4766 return false; 4829 return false;
4767 case GL_SRGB_EXT: 4830 case GL_SRGB_EXT:
4768 case GL_SRGB_ALPHA_EXT: 4831 case GL_SRGB_ALPHA_EXT:
4769 if (extensionEnabled(EXTsRGBName)) 4832 if (extensionEnabled(EXTsRGBName))
4770 break; 4833 break;
4771 synthesizeGLError(GL_INVALID_ENUM, functionName, "sRGB texture formats n ot enabled"); 4834 synthesizeGLError(GL_INVALID_ENUM, functionName, "sRGB texture formats n ot enabled");
4772 return false; 4835 return false;
4773 default: 4836 default:
4774 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture format "); 4837 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture format ");
4775 return false; 4838 return false;
4776 } 4839 }
4777 4840
4778 switch (type) { 4841 switch (type) {
4779 case GL_UNSIGNED_BYTE: 4842 case GL_UNSIGNED_BYTE:
4780 case GL_UNSIGNED_SHORT_5_6_5: 4843 case GL_UNSIGNED_SHORT_5_6_5:
4781 case GL_UNSIGNED_SHORT_4_4_4_4: 4844 case GL_UNSIGNED_SHORT_4_4_4_4:
4782 case GL_UNSIGNED_SHORT_5_5_5_1: 4845 case GL_UNSIGNED_SHORT_5_5_5_1:
4783 break; 4846 break;
4784 case GL_FLOAT: 4847 case GL_FLOAT:
4785 if (extensionEnabled(OESTextureFloatName)) 4848 if (extensionEnabled(OESTextureFloatName) || isWebGL2OrHigher())
4786 break; 4849 break;
4787 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ; 4850 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ;
4788 return false; 4851 return false;
4789 case GL_HALF_FLOAT_OES: 4852 case GL_HALF_FLOAT_OES:
4790 if (extensionEnabled(OESTextureHalfFloatName)) 4853 if (extensionEnabled(OESTextureHalfFloatName) || isWebGL2OrHigher())
4791 break; 4854 break;
4792 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ; 4855 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ;
4793 return false; 4856 return false;
4794 case GL_UNSIGNED_INT: 4857 case GL_UNSIGNED_INT:
4795 case GL_UNSIGNED_INT_24_8_OES: 4858 case GL_UNSIGNED_INT_24_8_OES:
4796 case GL_UNSIGNED_SHORT: 4859 case GL_UNSIGNED_SHORT:
4797 if (extensionEnabled(WebGLDepthTextureName)) 4860 if (extensionEnabled(WebGLDepthTextureName) || isWebGL2OrHigher())
4798 break; 4861 break;
4799 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ; 4862 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ;
4800 return false; 4863 return false;
4801 default: 4864 default:
4802 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ; 4865 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid texture type") ;
4803 return false; 4866 return false;
4804 } 4867 }
4805 4868
4806 // Verify that the combination of format and type is supported. 4869 // Verify that the combination of format and type is supported.
4807 switch (format) { 4870 switch (format) {
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
5282 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); 5345 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target");
5283 return false; 5346 return false;
5284 } 5347 }
5285 switch (attachment) { 5348 switch (attachment) {
5286 case GL_COLOR_ATTACHMENT0: 5349 case GL_COLOR_ATTACHMENT0:
5287 case GL_DEPTH_ATTACHMENT: 5350 case GL_DEPTH_ATTACHMENT:
5288 case GL_STENCIL_ATTACHMENT: 5351 case GL_STENCIL_ATTACHMENT:
5289 case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL: 5352 case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL:
5290 break; 5353 break;
5291 default: 5354 default:
5292 if (extensionEnabled(WebGLDrawBuffersName) 5355 if ((extensionEnabled(WebGLDrawBuffersName) || isWebGL2OrHigher())
5293 && attachment > GL_COLOR_ATTACHMENT0 5356 && attachment > GL_COLOR_ATTACHMENT0
5294 && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxColorA ttachments())) 5357 && attachment < static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + maxColorA ttachments()))
5295 break; 5358 break;
5296 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment"); 5359 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid attachment");
5297 return false; 5360 return false;
5298 } 5361 }
5299 return true; 5362 return true;
5300 } 5363 }
5301 5364
5302 bool WebGLRenderingContextBase::validateBlendEquation(const char* functionName, GLenum mode) 5365 bool WebGLRenderingContextBase::validateBlendEquation(const char* functionName, GLenum mode)
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
5508 return false; 5571 return false;
5509 5572
5510 if (!validateStencilSettings(functionName)) 5573 if (!validateStencilSettings(functionName))
5511 return false; 5574 return false;
5512 5575
5513 switch (type) { 5576 switch (type) {
5514 case GL_UNSIGNED_BYTE: 5577 case GL_UNSIGNED_BYTE:
5515 case GL_UNSIGNED_SHORT: 5578 case GL_UNSIGNED_SHORT:
5516 break; 5579 break;
5517 case GL_UNSIGNED_INT: 5580 case GL_UNSIGNED_INT:
5518 if (extensionEnabled(OESElementIndexUintName)) 5581 if (extensionEnabled(OESElementIndexUintName) || isWebGL2OrHigher())
5519 break; 5582 break;
5520 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid type"); 5583 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid type");
5521 return false; 5584 return false;
5522 default: 5585 default:
5523 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid type"); 5586 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid type");
5524 return false; 5587 return false;
5525 } 5588 }
5526 5589
5527 if (count < 0) { 5590 if (count < 0) {
5528 synthesizeGLError(GL_INVALID_VALUE, functionName, "count < 0"); 5591 synthesizeGLError(GL_INVALID_VALUE, functionName, "count < 0");
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
5844 } 5907 }
5845 5908
5846 IntSize WebGLRenderingContextBase::clampedCanvasSize() 5909 IntSize WebGLRenderingContextBase::clampedCanvasSize()
5847 { 5910 {
5848 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), 5911 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]),
5849 clamp(canvas()->height(), 1, m_maxViewportDims[1])); 5912 clamp(canvas()->height(), 1, m_maxViewportDims[1]));
5850 } 5913 }
5851 5914
5852 GLint WebGLRenderingContextBase::maxDrawBuffers() 5915 GLint WebGLRenderingContextBase::maxDrawBuffers()
5853 { 5916 {
5854 if (isContextLost() || !extensionEnabled(WebGLDrawBuffersName)) 5917 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher()))
5855 return 0; 5918 return 0;
5856 if (!m_maxDrawBuffers) 5919 if (!m_maxDrawBuffers)
5857 webContext()->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers); 5920 webContext()->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers);
5858 if (!m_maxColorAttachments) 5921 if (!m_maxColorAttachments)
5859 webContext()->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttac hments); 5922 webContext()->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttac hments);
5860 // WEBGL_draw_buffers requires MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS. 5923 // WEBGL_draw_buffers requires MAX_COLOR_ATTACHMENTS >= MAX_DRAW_BUFFERS.
5861 return std::min(m_maxDrawBuffers, m_maxColorAttachments); 5924 return std::min(m_maxDrawBuffers, m_maxColorAttachments);
5862 } 5925 }
5863 5926
5864 GLint WebGLRenderingContextBase::maxColorAttachments() 5927 GLint WebGLRenderingContextBase::maxColorAttachments()
5865 { 5928 {
5866 if (isContextLost() || !extensionEnabled(WebGLDrawBuffersName)) 5929 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher()))
5867 return 0; 5930 return 0;
5868 if (!m_maxColorAttachments) 5931 if (!m_maxColorAttachments)
5869 webContext()->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttac hments); 5932 webContext()->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttac hments);
5870 return m_maxColorAttachments; 5933 return m_maxColorAttachments;
5871 } 5934 }
5872 5935
5873 void WebGLRenderingContextBase::setBackDrawBuffer(GLenum buf) 5936 void WebGLRenderingContextBase::setBackDrawBuffer(GLenum buf)
5874 { 5937 {
5875 m_backDrawBuffer = buf; 5938 m_backDrawBuffer = buf;
5876 } 5939 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
5974 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB uffer() : 0; 6037 return m_sharedWebGraphicsContext3D ? m_sharedWebGraphicsContext3D->drawingB uffer() : 0;
5975 } 6038 }
5976 #else 6039 #else
5977 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6040 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
5978 { 6041 {
5979 return m_drawingBuffer.get(); 6042 return m_drawingBuffer.get();
5980 } 6043 }
5981 #endif 6044 #endif
5982 6045
5983 } // namespace blink 6046 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698