2013-08-27 01:12:53 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; 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 "WebGLContext.h"
|
|
|
|
#include "WebGLContextUtils.h"
|
|
|
|
#include "WebGLExtensions.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
#include "gfxPrefs.h"
|
2013-08-27 01:12:53 +04:00
|
|
|
#include "GLContext.h"
|
|
|
|
|
2013-08-27 01:12:53 +04:00
|
|
|
#include "nsString.h"
|
2013-09-07 06:13:37 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2016-11-16 22:10:22 +03:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2013-08-27 01:12:53 +04:00
|
|
|
#include "AccessCheck.h"
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2013-08-27 01:12:53 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
/*static*/ const char*
|
2013-08-27 01:12:53 +04:00
|
|
|
WebGLContext::GetExtensionString(WebGLExtensionID ext)
|
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
typedef EnumeratedArray<WebGLExtensionID, WebGLExtensionID::Max,
|
|
|
|
const char*> names_array_t;
|
2014-05-31 00:21:23 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
static names_array_t sExtensionNamesEnumeratedArray;
|
2014-05-31 00:21:23 +04:00
|
|
|
static bool initialized = false;
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
initialized = true;
|
|
|
|
|
|
|
|
#define WEBGL_EXTENSION_IDENTIFIER(x) \
|
|
|
|
sExtensionNamesEnumeratedArray[WebGLExtensionID::x] = #x;
|
|
|
|
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(ANGLE_instanced_arrays)
|
2014-06-14 20:07:53 +04:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_blend_minmax)
|
2016-05-05 02:39:02 +03:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_color_buffer_float)
|
2014-05-31 00:21:23 +04:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_color_buffer_half_float)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_frag_depth)
|
2014-07-24 19:58:43 +04:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_shader_texture_lod)
|
2015-01-08 03:28:05 +03:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_sRGB)
|
2014-05-31 00:21:23 +04:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_texture_filter_anisotropic)
|
2015-05-27 14:12:00 +03:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_disjoint_timer_query)
|
2017-01-31 05:58:52 +03:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(MOZ_debug_get)
|
2014-05-31 00:21:23 +04:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(OES_element_index_uint)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(OES_standard_derivatives)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(OES_texture_float)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(OES_texture_float_linear)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(OES_texture_half_float)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(OES_texture_half_float_linear)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(OES_vertex_array_object)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_color_buffer_float)
|
2016-11-23 05:59:35 +03:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_astc)
|
2014-05-31 00:21:23 +04:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_atc)
|
2016-11-11 03:37:03 +03:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_etc)
|
2014-05-31 00:21:23 +04:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_etc1)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_pvrtc)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_s3tc)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_debug_renderer_info)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_debug_shaders)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_depth_texture)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_draw_buffers)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_lose_context)
|
|
|
|
|
|
|
|
#undef WEBGL_EXTENSION_IDENTIFIER
|
|
|
|
}
|
2014-04-26 06:34:07 +04:00
|
|
|
|
2014-05-31 00:21:23 +04:00
|
|
|
return sExtensionNamesEnumeratedArray[ext];
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
|
|
|
|
2013-08-27 01:12:53 +04:00
|
|
|
bool
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLContext::IsExtensionEnabled(WebGLExtensionID ext) const
|
|
|
|
{
|
2014-04-26 06:34:07 +04:00
|
|
|
return mExtensions[ext];
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
|
|
|
|
2016-11-16 22:10:22 +03:00
|
|
|
bool WebGLContext::IsExtensionSupported(dom::CallerType callerType,
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLExtensionID ext) const
|
2013-08-27 01:12:53 +04:00
|
|
|
{
|
2014-02-12 02:37:05 +04:00
|
|
|
bool allowPrivilegedExts = false;
|
|
|
|
|
2013-08-27 01:12:53 +04:00
|
|
|
// Chrome contexts need access to debug information even when
|
|
|
|
// webgl.disable-extensions is set. This is used in the graphics
|
2015-10-12 06:21:03 +03:00
|
|
|
// section of about:support
|
2016-11-16 22:10:22 +03:00
|
|
|
if (callerType == dom::CallerType::System) {
|
2014-02-12 02:37:05 +04:00
|
|
|
allowPrivilegedExts = true;
|
2015-10-12 06:21:03 +03:00
|
|
|
}
|
2014-02-12 02:37:05 +04:00
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
if (gfxPrefs::WebGLPrivilegedExtensionsEnabled()) {
|
2014-02-12 02:37:05 +04:00
|
|
|
allowPrivilegedExts = true;
|
2015-10-12 06:21:03 +03:00
|
|
|
}
|
2014-02-12 02:37:05 +04:00
|
|
|
|
|
|
|
if (allowPrivilegedExts) {
|
2013-08-27 01:12:53 +04:00
|
|
|
switch (ext) {
|
2017-01-31 05:58:52 +03:00
|
|
|
case WebGLExtensionID::MOZ_debug_get:
|
|
|
|
return true;
|
2014-11-14 07:03:50 +03:00
|
|
|
case WebGLExtensionID::WEBGL_debug_renderer_info:
|
|
|
|
return true;
|
|
|
|
case WebGLExtensionID::WEBGL_debug_shaders:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
// For warnings-as-errors.
|
|
|
|
break;
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return IsExtensionSupported(ext);
|
|
|
|
}
|
|
|
|
|
2015-01-08 03:28:05 +03:00
|
|
|
bool
|
|
|
|
WebGLContext::IsExtensionSupported(WebGLExtensionID ext) const
|
2013-08-27 01:12:53 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
if (mDisableExtensions)
|
2013-08-27 01:12:53 +04:00
|
|
|
return false;
|
|
|
|
|
2015-11-25 07:15:29 +03:00
|
|
|
// Extensions for both WebGL 1 and 2.
|
2015-11-24 08:55:59 +03:00
|
|
|
switch (ext) {
|
2015-11-25 07:15:29 +03:00
|
|
|
// In alphabetical order
|
2015-01-08 03:28:05 +03:00
|
|
|
// EXT_
|
2016-11-05 01:55:06 +03:00
|
|
|
case WebGLExtensionID::EXT_disjoint_timer_query:
|
|
|
|
return WebGLExtensionDisjointTimerQuery::IsSupported(this);
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::EXT_texture_filter_anisotropic:
|
|
|
|
return gl->IsExtensionSupported(gl::GLContext::EXT_texture_filter_anisotropic);
|
|
|
|
|
|
|
|
// OES_
|
2014-11-14 07:03:50 +03:00
|
|
|
case WebGLExtensionID::OES_texture_float_linear:
|
|
|
|
return gl->IsSupported(gl::GLFeature::texture_float_linear);
|
|
|
|
|
2015-01-08 03:28:05 +03:00
|
|
|
// WEBGL_
|
2016-11-23 05:59:35 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_astc:
|
|
|
|
return WebGLExtensionCompressedTextureASTC::IsSupported(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_atc:
|
|
|
|
return gl->IsExtensionSupported(gl::GLContext::AMD_compressed_ATC_texture);
|
2016-11-11 03:37:03 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_etc:
|
2017-01-26 01:13:15 +03:00
|
|
|
return gl->IsSupported(gl::GLFeature::ES3_compatibility) &&
|
|
|
|
!gl->IsANGLE();
|
2014-11-14 07:03:50 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_etc1:
|
2017-01-26 01:13:15 +03:00
|
|
|
return gl->IsExtensionSupported(gl::GLContext::OES_compressed_ETC1_RGB8_texture) &&
|
|
|
|
!gl->IsANGLE();
|
2014-11-14 07:03:50 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_pvrtc:
|
|
|
|
return gl->IsExtensionSupported(gl::GLContext::IMG_texture_compression_pvrtc);
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_s3tc:
|
|
|
|
if (gl->IsExtensionSupported(gl::GLContext::EXT_texture_compression_s3tc))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return gl->IsExtensionSupported(gl::GLContext::EXT_texture_compression_dxt1) &&
|
|
|
|
gl->IsExtensionSupported(gl::GLContext::ANGLE_texture_compression_dxt3) &&
|
|
|
|
gl->IsExtensionSupported(gl::GLContext::ANGLE_texture_compression_dxt5);
|
2015-07-22 03:41:57 +03:00
|
|
|
|
|
|
|
case WebGLExtensionID::WEBGL_debug_renderer_info:
|
2015-08-11 00:57:15 +03:00
|
|
|
return Preferences::GetBool("webgl.enable-debug-renderer-info", false);
|
2015-07-22 03:41:57 +03:00
|
|
|
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::WEBGL_lose_context:
|
|
|
|
// We always support this extension.
|
|
|
|
return true;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
// For warnings-as-errors.
|
|
|
|
break;
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
2014-06-14 20:07:53 +04:00
|
|
|
|
2016-05-05 02:39:02 +03:00
|
|
|
if (IsWebGL2()) {
|
|
|
|
// WebGL2-only extensions
|
|
|
|
switch (ext) {
|
|
|
|
// EXT_
|
|
|
|
case WebGLExtensionID::EXT_color_buffer_float:
|
|
|
|
return WebGLExtensionEXTColorBufferFloat::IsSupported(this);
|
|
|
|
|
|
|
|
default:
|
|
|
|
// For warnings-as-errors.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2015-11-25 07:15:29 +03:00
|
|
|
// WebGL1-only extensions
|
2013-08-27 01:12:53 +04:00
|
|
|
switch (ext) {
|
2015-11-25 07:15:29 +03:00
|
|
|
// ANGLE_
|
|
|
|
case WebGLExtensionID::ANGLE_instanced_arrays:
|
|
|
|
return WebGLExtensionInstancedArrays::IsSupported(this);
|
|
|
|
|
|
|
|
// EXT_
|
|
|
|
case WebGLExtensionID::EXT_blend_minmax:
|
|
|
|
return WebGLExtensionBlendMinMax::IsSupported(this);
|
2016-05-27 02:34:49 +03:00
|
|
|
case WebGLExtensionID::EXT_color_buffer_half_float:
|
|
|
|
return WebGLExtensionColorBufferHalfFloat::IsSupported(this);
|
2015-11-25 07:15:29 +03:00
|
|
|
case WebGLExtensionID::EXT_frag_depth:
|
|
|
|
return WebGLExtensionFragDepth::IsSupported(this);
|
|
|
|
case WebGLExtensionID::EXT_shader_texture_lod:
|
2016-06-01 03:22:30 +03:00
|
|
|
return gl->IsSupported(gl::GLFeature::shader_texture_lod);
|
2015-11-25 07:15:29 +03:00
|
|
|
case WebGLExtensionID::EXT_sRGB:
|
|
|
|
return WebGLExtensionSRGB::IsSupported(this);
|
|
|
|
|
|
|
|
// OES_
|
|
|
|
case WebGLExtensionID::OES_element_index_uint:
|
|
|
|
return gl->IsSupported(gl::GLFeature::element_index_uint);
|
|
|
|
case WebGLExtensionID::OES_standard_derivatives:
|
|
|
|
return gl->IsSupported(gl::GLFeature::standard_derivatives);
|
|
|
|
case WebGLExtensionID::OES_texture_float:
|
|
|
|
return WebGLExtensionTextureFloat::IsSupported(this);
|
|
|
|
case WebGLExtensionID::OES_texture_half_float:
|
|
|
|
return WebGLExtensionTextureHalfFloat::IsSupported(this);
|
2016-05-09 22:00:10 +03:00
|
|
|
case WebGLExtensionID::OES_texture_half_float_linear:
|
|
|
|
return gl->IsSupported(gl::GLFeature::texture_half_float_linear);
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
case WebGLExtensionID::OES_vertex_array_object:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// WEBGL_
|
2016-05-27 02:34:49 +03:00
|
|
|
case WebGLExtensionID::WEBGL_color_buffer_float:
|
|
|
|
return WebGLExtensionColorBufferFloat::IsSupported(this);
|
2015-11-25 07:15:29 +03:00
|
|
|
case WebGLExtensionID::WEBGL_depth_texture:
|
|
|
|
// WEBGL_depth_texture supports DEPTH_STENCIL textures
|
|
|
|
if (!gl->IsSupported(gl::GLFeature::packed_depth_stencil))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return gl->IsSupported(gl::GLFeature::depth_texture) ||
|
|
|
|
gl->IsExtensionSupported(gl::GLContext::ANGLE_depth_texture);
|
|
|
|
case WebGLExtensionID::WEBGL_draw_buffers:
|
|
|
|
return WebGLExtensionDrawBuffers::IsSupported(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
default:
|
|
|
|
// For warnings-as-errors.
|
|
|
|
break;
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
2015-11-25 07:15:29 +03:00
|
|
|
|
|
|
|
if (gfxPrefs::WebGLDraftExtensionsEnabled()) {
|
2016-11-05 01:55:06 +03:00
|
|
|
/*
|
2015-11-25 07:15:29 +03:00
|
|
|
switch (ext) {
|
|
|
|
default:
|
|
|
|
// For warnings-as-errors.
|
|
|
|
break;
|
|
|
|
}
|
2016-11-05 01:55:06 +03:00
|
|
|
*/
|
2015-11-25 07:15:29 +03:00
|
|
|
}
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2014-11-14 07:03:50 +03:00
|
|
|
CompareWebGLExtensionName(const nsACString& name, const char* other)
|
2013-08-27 01:12:53 +04:00
|
|
|
{
|
|
|
|
return name.Equals(other, nsCaseInsensitiveCStringComparator());
|
|
|
|
}
|
|
|
|
|
2014-11-22 02:04:08 +03:00
|
|
|
WebGLExtensionBase*
|
2016-11-16 22:10:22 +03:00
|
|
|
WebGLContext::EnableSupportedExtension(dom::CallerType callerType,
|
|
|
|
WebGLExtensionID ext)
|
2014-11-22 02:04:08 +03:00
|
|
|
{
|
|
|
|
if (!IsExtensionEnabled(ext)) {
|
2016-11-16 22:10:22 +03:00
|
|
|
if (!IsExtensionSupported(callerType, ext))
|
2014-11-22 02:04:08 +03:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
EnableExtension(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mExtensions[ext];
|
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void
|
2016-11-16 22:10:22 +03:00
|
|
|
WebGLContext::GetExtension(JSContext* cx,
|
|
|
|
const nsAString& wideName,
|
|
|
|
JS::MutableHandle<JSObject*> retval,
|
|
|
|
dom::CallerType callerType,
|
|
|
|
ErrorResult& rv)
|
2013-08-27 01:12:53 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
retval.set(nullptr);
|
|
|
|
|
|
|
|
if (IsContextLost())
|
2014-06-12 00:26:52 +04:00
|
|
|
return;
|
2013-08-27 01:12:53 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
NS_LossyConvertUTF16toASCII name(wideName);
|
2013-08-27 01:12:53 +04:00
|
|
|
|
2014-04-26 06:34:07 +04:00
|
|
|
WebGLExtensionID ext = WebGLExtensionID::Unknown;
|
2013-08-27 01:12:53 +04:00
|
|
|
|
|
|
|
// step 1: figure what extension is wanted
|
2014-11-22 02:04:08 +03:00
|
|
|
for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) {
|
2013-08-27 01:12:53 +04:00
|
|
|
WebGLExtensionID extension = WebGLExtensionID(i);
|
2014-02-12 02:37:05 +04:00
|
|
|
|
2013-08-27 01:12:53 +04:00
|
|
|
if (CompareWebGLExtensionName(name, GetExtensionString(extension))) {
|
|
|
|
ext = extension;
|
|
|
|
break;
|
|
|
|
}
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
2013-08-27 01:12:53 +04:00
|
|
|
|
2014-11-22 02:04:08 +03:00
|
|
|
if (ext == WebGLExtensionID::Unknown) {
|
2014-11-14 07:03:50 +03:00
|
|
|
// We keep backward compatibility for these deprecated vendor-prefixed
|
|
|
|
// alias. Do not add new ones anymore. Hide it behind the
|
|
|
|
// webgl.enable-draft-extensions flag instead.
|
|
|
|
|
2013-08-27 01:12:53 +04:00
|
|
|
if (CompareWebGLExtensionName(name, "MOZ_WEBGL_lose_context")) {
|
2014-04-26 06:34:07 +04:00
|
|
|
ext = WebGLExtensionID::WEBGL_lose_context;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_s3tc")) {
|
2014-04-26 06:34:07 +04:00
|
|
|
ext = WebGLExtensionID::WEBGL_compressed_texture_s3tc;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_atc")) {
|
2014-04-26 06:34:07 +04:00
|
|
|
ext = WebGLExtensionID::WEBGL_compressed_texture_atc;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_pvrtc")) {
|
2014-04-26 06:34:07 +04:00
|
|
|
ext = WebGLExtensionID::WEBGL_compressed_texture_pvrtc;
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_depth_texture")) {
|
2014-04-26 06:34:07 +04:00
|
|
|
ext = WebGLExtensionID::WEBGL_depth_texture;
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
2013-10-11 17:16:43 +04:00
|
|
|
|
2014-04-26 06:34:07 +04:00
|
|
|
if (ext != WebGLExtensionID::Unknown) {
|
2014-11-14 07:03:50 +03:00
|
|
|
GenerateWarning("getExtension('%s'): MOZ_ prefixed WebGL extension"
|
|
|
|
" strings are deprecated. Support for them will be"
|
|
|
|
" removed in the future. Use unprefixed extension"
|
|
|
|
" strings. To get draft extensions, set the"
|
|
|
|
" webgl.enable-draft-extensions preference.",
|
2013-10-11 17:16:43 +04:00
|
|
|
name.get());
|
|
|
|
}
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
if (ext == WebGLExtensionID::Unknown)
|
2014-06-12 00:26:52 +04:00
|
|
|
return;
|
2013-08-27 01:12:53 +04:00
|
|
|
|
|
|
|
// step 2: check if the extension is supported
|
2016-11-16 22:10:22 +03:00
|
|
|
if (!IsExtensionSupported(callerType, ext))
|
2014-06-12 00:26:52 +04:00
|
|
|
return;
|
2013-08-27 01:12:53 +04:00
|
|
|
|
|
|
|
// step 3: if the extension hadn't been previously been created, create it now, thus enabling it
|
2016-11-16 22:10:22 +03:00
|
|
|
WebGLExtensionBase* extObj = EnableSupportedExtension(callerType, ext);
|
2014-11-14 07:03:50 +03:00
|
|
|
if (!extObj)
|
2014-11-22 02:04:08 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Step 4: Enable any implied extensions.
|
|
|
|
switch (ext) {
|
|
|
|
case WebGLExtensionID::OES_texture_float:
|
2016-11-16 22:10:22 +03:00
|
|
|
EnableSupportedExtension(callerType,
|
|
|
|
WebGLExtensionID::WEBGL_color_buffer_float);
|
2014-11-22 02:04:08 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WebGLExtensionID::OES_texture_half_float:
|
2016-11-16 22:10:22 +03:00
|
|
|
EnableSupportedExtension(callerType,
|
|
|
|
WebGLExtensionID::EXT_color_buffer_half_float);
|
2014-11-22 02:04:08 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
retval.set(WebGLObjectAsJSObject(cx, extObj, rv));
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::EnableExtension(WebGLExtensionID ext)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsExtensionEnabled(ext) == false);
|
|
|
|
|
|
|
|
WebGLExtensionBase* obj = nullptr;
|
|
|
|
switch (ext) {
|
2015-01-08 03:28:05 +03:00
|
|
|
// ANGLE_
|
|
|
|
case WebGLExtensionID::ANGLE_instanced_arrays:
|
|
|
|
obj = new WebGLExtensionInstancedArrays(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
|
|
|
|
// EXT_
|
|
|
|
case WebGLExtensionID::EXT_blend_minmax:
|
|
|
|
obj = new WebGLExtensionBlendMinMax(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2016-05-05 02:39:02 +03:00
|
|
|
case WebGLExtensionID::EXT_color_buffer_float:
|
|
|
|
obj = new WebGLExtensionEXTColorBufferFloat(this);
|
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::EXT_color_buffer_half_float:
|
|
|
|
obj = new WebGLExtensionColorBufferHalfFloat(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-05-27 14:12:00 +03:00
|
|
|
case WebGLExtensionID::EXT_disjoint_timer_query:
|
|
|
|
obj = new WebGLExtensionDisjointTimerQuery(this);
|
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::EXT_frag_depth:
|
|
|
|
obj = new WebGLExtensionFragDepth(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::EXT_shader_texture_lod:
|
|
|
|
obj = new WebGLExtensionShaderTextureLod(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::EXT_sRGB:
|
|
|
|
obj = new WebGLExtensionSRGB(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::EXT_texture_filter_anisotropic:
|
|
|
|
obj = new WebGLExtensionTextureFilterAnisotropic(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
|
2017-01-31 05:58:52 +03:00
|
|
|
// MOZ_
|
|
|
|
case WebGLExtensionID::MOZ_debug_get:
|
|
|
|
obj = new WebGLExtensionDebugGet(this);
|
|
|
|
break;
|
|
|
|
|
2015-01-08 03:28:05 +03:00
|
|
|
// OES_
|
|
|
|
case WebGLExtensionID::OES_element_index_uint:
|
|
|
|
obj = new WebGLExtensionElementIndexUint(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::OES_standard_derivatives:
|
|
|
|
obj = new WebGLExtensionStandardDerivatives(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
|
|
|
case WebGLExtensionID::OES_texture_float:
|
|
|
|
obj = new WebGLExtensionTextureFloat(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::OES_texture_float_linear:
|
|
|
|
obj = new WebGLExtensionTextureFloatLinear(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::OES_texture_half_float:
|
|
|
|
obj = new WebGLExtensionTextureHalfFloat(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::OES_texture_half_float_linear:
|
|
|
|
obj = new WebGLExtensionTextureHalfFloatLinear(this);
|
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::OES_vertex_array_object:
|
|
|
|
obj = new WebGLExtensionVertexArray(this);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// WEBGL_
|
2014-11-14 07:03:50 +03:00
|
|
|
case WebGLExtensionID::WEBGL_color_buffer_float:
|
|
|
|
obj = new WebGLExtensionColorBufferFloat(this);
|
|
|
|
break;
|
2016-11-23 05:59:35 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_astc:
|
|
|
|
obj = new WebGLExtensionCompressedTextureASTC(this);
|
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_atc:
|
|
|
|
obj = new WebGLExtensionCompressedTextureATC(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2016-11-11 03:37:03 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_etc:
|
2016-01-08 05:12:22 +03:00
|
|
|
obj = new WebGLExtensionCompressedTextureES3(this);
|
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_etc1:
|
|
|
|
obj = new WebGLExtensionCompressedTextureETC1(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_pvrtc:
|
|
|
|
obj = new WebGLExtensionCompressedTexturePVRTC(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_s3tc:
|
|
|
|
obj = new WebGLExtensionCompressedTextureS3TC(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::WEBGL_debug_renderer_info:
|
|
|
|
obj = new WebGLExtensionDebugRendererInfo(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::WEBGL_debug_shaders:
|
|
|
|
obj = new WebGLExtensionDebugShaders(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::WEBGL_depth_texture:
|
|
|
|
obj = new WebGLExtensionDepthTexture(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
case WebGLExtensionID::WEBGL_draw_buffers:
|
|
|
|
obj = new WebGLExtensionDrawBuffers(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::WEBGL_lose_context:
|
|
|
|
obj = new WebGLExtensionLoseContext(this);
|
2014-11-14 07:03:50 +03:00
|
|
|
break;
|
2015-01-08 03:28:05 +03:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "should not get there.");
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mExtensions[ext] = obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-16 22:10:22 +03:00
|
|
|
WebGLContext::GetSupportedExtensions(dom::Nullable< nsTArray<nsString> >& retval,
|
|
|
|
dom::CallerType callerType)
|
2013-08-27 01:12:53 +04:00
|
|
|
{
|
|
|
|
retval.SetNull();
|
2013-09-04 16:14:44 +04:00
|
|
|
if (IsContextLost())
|
2013-08-27 01:12:53 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsTArray<nsString>& arr = retval.SetValue();
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) {
|
2013-08-27 01:12:53 +04:00
|
|
|
WebGLExtensionID extension = WebGLExtensionID(i);
|
|
|
|
|
2016-11-16 22:10:22 +03:00
|
|
|
if (IsExtensionSupported(callerType, extension)) {
|
2014-11-14 07:03:50 +03:00
|
|
|
const char* extStr = GetExtensionString(extension);
|
|
|
|
arr.AppendElement(NS_ConvertUTF8toUTF16(extStr));
|
2013-08-27 01:12:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We keep backward compatibility for these deprecated vendor-prefixed
|
|
|
|
* alias. Do not add new ones anymore. Hide it behind the
|
|
|
|
* webgl.enable-draft-extensions flag instead.
|
|
|
|
*/
|
2016-11-16 22:10:22 +03:00
|
|
|
if (IsExtensionSupported(callerType, WebGLExtensionID::WEBGL_lose_context))
|
2013-08-27 01:12:53 +04:00
|
|
|
arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_lose_context"));
|
2016-11-16 22:10:22 +03:00
|
|
|
if (IsExtensionSupported(callerType,
|
|
|
|
WebGLExtensionID::WEBGL_compressed_texture_s3tc))
|
2013-08-27 01:12:53 +04:00
|
|
|
arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_s3tc"));
|
2016-11-16 22:10:22 +03:00
|
|
|
if (IsExtensionSupported(callerType,
|
|
|
|
WebGLExtensionID::WEBGL_compressed_texture_atc))
|
2013-08-27 01:12:53 +04:00
|
|
|
arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_atc"));
|
2016-11-16 22:10:22 +03:00
|
|
|
if (IsExtensionSupported(callerType,
|
|
|
|
WebGLExtensionID::WEBGL_compressed_texture_pvrtc))
|
2013-08-27 01:12:53 +04:00
|
|
|
arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_pvrtc"));
|
2016-11-16 22:10:22 +03:00
|
|
|
if (IsExtensionSupported(callerType,
|
|
|
|
WebGLExtensionID::WEBGL_depth_texture))
|
2013-08-27 01:12:53 +04:00
|
|
|
arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_depth_texture"));
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
} // namespace mozilla
|