Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "WebGL2Context.h" |
michael@0 | 7 | #include "GLContext.h" |
michael@0 | 8 | #include "mozilla/dom/WebGL2RenderingContextBinding.h" |
michael@0 | 9 | #include "mozilla/Preferences.h" |
michael@0 | 10 | #include "mozilla/Telemetry.h" |
michael@0 | 11 | |
michael@0 | 12 | using namespace mozilla; |
michael@0 | 13 | using namespace mozilla::gl; |
michael@0 | 14 | |
michael@0 | 15 | // ----------------------------------------------------------------------------- |
michael@0 | 16 | // CONSTRUCTOR & DESTRUCTOR |
michael@0 | 17 | |
michael@0 | 18 | WebGL2Context::WebGL2Context() |
michael@0 | 19 | : WebGLContext() |
michael@0 | 20 | { |
michael@0 | 21 | MOZ_ASSERT(IsSupported(), "not supposed to create a WebGL2Context" |
michael@0 | 22 | "context when not supported"); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | WebGL2Context::~WebGL2Context() |
michael@0 | 26 | { |
michael@0 | 27 | |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | |
michael@0 | 31 | // ----------------------------------------------------------------------------- |
michael@0 | 32 | // STATIC FUNCTIONS |
michael@0 | 33 | |
michael@0 | 34 | bool |
michael@0 | 35 | WebGL2Context::IsSupported() |
michael@0 | 36 | { |
michael@0 | 37 | return Preferences::GetBool("webgl.enable-prototype-webgl2", false); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | WebGL2Context* |
michael@0 | 41 | WebGL2Context::Create() |
michael@0 | 42 | { |
michael@0 | 43 | return new WebGL2Context(); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | |
michael@0 | 47 | // ----------------------------------------------------------------------------- |
michael@0 | 48 | // IMPLEMENT nsWrapperCache |
michael@0 | 49 | |
michael@0 | 50 | JSObject* |
michael@0 | 51 | WebGL2Context::WrapObject(JSContext *cx) |
michael@0 | 52 | { |
michael@0 | 53 | return dom::WebGL2RenderingContextBinding::Wrap(cx, this); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | |
michael@0 | 57 | // ----------------------------------------------------------------------------- |
michael@0 | 58 | // WebGL 2 initialisation |
michael@0 | 59 | |
michael@0 | 60 | bool |
michael@0 | 61 | WebGLContext::InitWebGL2() |
michael@0 | 62 | { |
michael@0 | 63 | MOZ_ASSERT(IsWebGL2(), "WebGLContext is not a WebGL 2 context!"); |
michael@0 | 64 | |
michael@0 | 65 | const WebGLExtensionID sExtensionNativelySupportedArr[] = { |
michael@0 | 66 | WebGLExtensionID::ANGLE_instanced_arrays, |
michael@0 | 67 | WebGLExtensionID::OES_element_index_uint, |
michael@0 | 68 | WebGLExtensionID::OES_standard_derivatives, |
michael@0 | 69 | WebGLExtensionID::OES_texture_float, |
michael@0 | 70 | WebGLExtensionID::OES_texture_float_linear, |
michael@0 | 71 | WebGLExtensionID::OES_vertex_array_object, |
michael@0 | 72 | WebGLExtensionID::WEBGL_depth_texture, |
michael@0 | 73 | WebGLExtensionID::WEBGL_draw_buffers |
michael@0 | 74 | }; |
michael@0 | 75 | const GLFeature sFeatureRequiredArr[] = { |
michael@0 | 76 | GLFeature::blend_minmax, |
michael@0 | 77 | GLFeature::instanced_non_arrays, |
michael@0 | 78 | GLFeature::transform_feedback |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | // check WebGL extensions that are supposed to be natively supported |
michael@0 | 82 | for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sExtensionNativelySupportedArr)); i++) |
michael@0 | 83 | { |
michael@0 | 84 | WebGLExtensionID extension = sExtensionNativelySupportedArr[i]; |
michael@0 | 85 | |
michael@0 | 86 | if (!IsExtensionSupported(extension)) { |
michael@0 | 87 | GenerateWarning("WebGL 2 requires %s!", GetExtensionString(extension)); |
michael@0 | 88 | return false; |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | // check required OpenGL extensions |
michael@0 | 93 | if (!gl->IsExtensionSupported(GLContext::EXT_gpu_shader4)) { |
michael@0 | 94 | GenerateWarning("WebGL 2 requires GL_EXT_gpu_shader4!"); |
michael@0 | 95 | return false; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | // check OpenGL features |
michael@0 | 99 | if (!gl->IsSupported(GLFeature::occlusion_query) && |
michael@0 | 100 | !gl->IsSupported(GLFeature::occlusion_query_boolean)) |
michael@0 | 101 | { |
michael@0 | 102 | /* |
michael@0 | 103 | * on desktop, we fake occlusion_query_boolean with occlusion_query if |
michael@0 | 104 | * necessary. See WebGLContextAsyncQueries.cpp. |
michael@0 | 105 | */ |
michael@0 | 106 | GenerateWarning("WebGL 2 requires occlusion queries!"); |
michael@0 | 107 | return false; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sFeatureRequiredArr)); i++) |
michael@0 | 111 | { |
michael@0 | 112 | if (!gl->IsSupported(sFeatureRequiredArr[i])) { |
michael@0 | 113 | GenerateWarning("WebGL 2 requires GLFeature::%s!", GLContext::GetFeatureName(sFeatureRequiredArr[i])); |
michael@0 | 114 | return false; |
michael@0 | 115 | } |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | // ok WebGL 2 is compatible, we can enable natively supported extensions. |
michael@0 | 119 | for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sExtensionNativelySupportedArr)); i++) { |
michael@0 | 120 | EnableExtension(sExtensionNativelySupportedArr[i]); |
michael@0 | 121 | |
michael@0 | 122 | MOZ_ASSERT(IsExtensionEnabled(sExtensionNativelySupportedArr[i])); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | // we initialise WebGL 2 related stuff. |
michael@0 | 126 | gl->GetUIntegerv(LOCAL_GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &mGLMaxTransformFeedbackSeparateAttribs); |
michael@0 | 127 | |
michael@0 | 128 | return true; |
michael@0 | 129 | } |