2013-07-17 06:58:09 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebGL2Context.h"
|
2013-09-04 05:14:52 -07:00
|
|
|
#include "GLContext.h"
|
2013-07-17 06:58:09 -07:00
|
|
|
#include "mozilla/dom/WebGL2RenderingContextBinding.h"
|
2013-09-06 19:13:37 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-07-17 06:58:09 -07:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-08-26 14:12:54 -07:00
|
|
|
using namespace mozilla::gl;
|
2013-07-17 06:58:09 -07:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// CONSTRUCTOR & DESTRUCTOR
|
|
|
|
|
|
|
|
WebGL2Context::WebGL2Context()
|
|
|
|
: WebGLContext()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsSupported(), "not supposed to create a WebGL2Context"
|
|
|
|
"context when not supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGL2Context::~WebGL2Context()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// STATIC FUNCTIONS
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGL2Context::IsSupported()
|
|
|
|
{
|
|
|
|
return Preferences::GetBool("webgl.enable-prototype-webgl2", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGL2Context*
|
|
|
|
WebGL2Context::Create()
|
|
|
|
{
|
|
|
|
return new WebGL2Context();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// IMPLEMENT nsWrapperCache
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
WebGL2Context::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope)
|
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return dom::WebGL2RenderingContextBinding::Wrap(cx, this);
|
2013-07-17 06:58:09 -07:00
|
|
|
}
|
|
|
|
|
2013-08-26 14:12:54 -07:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// WebGL 2 initialisation
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::InitWebGL2()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsWebGL2(), "WebGLContext is not a WebGL 2 context!");
|
|
|
|
|
|
|
|
const WebGLExtensionID sExtensionNativelySupportedArr[] = {
|
|
|
|
ANGLE_instanced_arrays,
|
2013-08-26 14:12:54 -07:00
|
|
|
OES_element_index_uint,
|
|
|
|
OES_standard_derivatives,
|
|
|
|
OES_texture_float,
|
|
|
|
OES_texture_float_linear,
|
2013-08-26 14:12:54 -07:00
|
|
|
OES_vertex_array_object,
|
2013-08-26 14:12:54 -07:00
|
|
|
WEBGL_depth_texture,
|
2013-08-26 14:12:54 -07:00
|
|
|
WEBGL_draw_buffers
|
|
|
|
};
|
2014-01-10 10:55:23 -08:00
|
|
|
const GLFeature sFeatureRequiredArr[] = {
|
2013-08-26 14:12:54 -07:00
|
|
|
GLFeature::blend_minmax,
|
2013-09-19 15:33:22 -07:00
|
|
|
GLFeature::instanced_non_arrays,
|
2013-08-26 14:12:54 -07:00
|
|
|
GLFeature::transform_feedback
|
|
|
|
};
|
|
|
|
|
|
|
|
// check WebGL extensions that are supposed to be natively supported
|
|
|
|
for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sExtensionNativelySupportedArr)); i++)
|
|
|
|
{
|
|
|
|
WebGLExtensionID extension = sExtensionNativelySupportedArr[i];
|
|
|
|
|
|
|
|
if (!IsExtensionSupported(extension)) {
|
|
|
|
GenerateWarning("WebGL 2 requires %s!", GetExtensionString(extension));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check required OpenGL extensions
|
|
|
|
if (!gl->IsExtensionSupported(GLContext::EXT_gpu_shader4)) {
|
|
|
|
GenerateWarning("WebGL 2 requires GL_EXT_gpu_shader4!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check OpenGL features
|
|
|
|
if (!gl->IsSupported(GLFeature::occlusion_query) &&
|
|
|
|
!gl->IsSupported(GLFeature::occlusion_query_boolean))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* on desktop, we fake occlusion_query_boolean with occlusion_query if
|
|
|
|
* necessary. See WebGLContextAsyncQueries.cpp.
|
|
|
|
*/
|
|
|
|
GenerateWarning("WebGL 2 requires occlusion queries!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sFeatureRequiredArr)); i++)
|
|
|
|
{
|
|
|
|
if (!gl->IsSupported(sFeatureRequiredArr[i])) {
|
|
|
|
GenerateWarning("WebGL 2 requires GLFeature::%s!", GLContext::GetFeatureName(sFeatureRequiredArr[i]));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ok WebGL 2 is compatible, we can enable natively supported extensions.
|
|
|
|
for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sExtensionNativelySupportedArr)); i++) {
|
|
|
|
EnableExtension(sExtensionNativelySupportedArr[i]);
|
|
|
|
|
|
|
|
MOZ_ASSERT(IsExtensionEnabled(sExtensionNativelySupportedArr[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
// we initialise WebGL 2 related stuff.
|
|
|
|
gl->GetUIntegerv(LOCAL_GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &mGLMaxTransformFeedbackSeparateAttribs);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|