2013-08-26 21:12:53 +00: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"
|
|
|
|
#include "GLContext.h"
|
|
|
|
|
2013-08-26 21:12:53 +00:00
|
|
|
#include "nsString.h"
|
2013-09-07 02:13:37 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-08-26 21:12:53 +00:00
|
|
|
#include "AccessCheck.h"
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
namespace mozilla {
|
2013-08-26 21:12:53 +00:00
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
/*static*/ const char*
|
2013-08-26 21:12:53 +00:00
|
|
|
WebGLContext::GetExtensionString(WebGLExtensionID ext)
|
|
|
|
{
|
2014-11-14 04:03:50 +00:00
|
|
|
typedef EnumeratedArray<WebGLExtensionID, WebGLExtensionID::Max,
|
|
|
|
const char*> names_array_t;
|
2014-05-30 20:21:23 +00:00
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
static names_array_t sExtensionNamesEnumeratedArray;
|
2014-05-30 20:21:23 +00: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 16:07:53 +00:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_blend_minmax)
|
2014-05-30 20:21:23 +00:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_color_buffer_half_float)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_frag_depth)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_sRGB)
|
2014-07-24 15:58:43 +00:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_shader_texture_lod)
|
2014-05-30 20:21:23 +00:00
|
|
|
WEBGL_EXTENSION_IDENTIFIER(EXT_texture_filter_anisotropic)
|
|
|
|
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)
|
|
|
|
WEBGL_EXTENSION_IDENTIFIER(WEBGL_compressed_texture_atc)
|
|
|
|
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 02:34:07 +00:00
|
|
|
|
2014-05-30 20:21:23 +00:00
|
|
|
return sExtensionNamesEnumeratedArray[ext];
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-26 21:12:53 +00:00
|
|
|
bool
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLContext::IsExtensionEnabled(WebGLExtensionID ext) const
|
|
|
|
{
|
2014-04-26 02:34:07 +00:00
|
|
|
return mExtensions[ext];
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
bool WebGLContext::IsExtensionSupported(JSContext* cx,
|
|
|
|
WebGLExtensionID ext) const
|
2013-08-26 21:12:53 +00:00
|
|
|
{
|
2014-02-11 22:37:05 +00:00
|
|
|
bool allowPrivilegedExts = false;
|
|
|
|
|
2013-08-26 21:12:53 +00:00
|
|
|
// Chrome contexts need access to debug information even when
|
|
|
|
// webgl.disable-extensions is set. This is used in the graphics
|
|
|
|
// section of about:support.
|
2014-02-11 22:37:05 +00:00
|
|
|
if (xpc::AccessCheck::isChrome(js::GetContextCompartment(cx)))
|
|
|
|
allowPrivilegedExts = true;
|
|
|
|
|
|
|
|
if (Preferences::GetBool("webgl.enable-privileged-extensions", false))
|
|
|
|
allowPrivilegedExts = true;
|
|
|
|
|
|
|
|
if (allowPrivilegedExts) {
|
2013-08-26 21:12:53 +00:00
|
|
|
switch (ext) {
|
2014-11-14 04:03:50 +00:00
|
|
|
case WebGLExtensionID::WEBGL_debug_renderer_info:
|
|
|
|
return true;
|
|
|
|
case WebGLExtensionID::WEBGL_debug_shaders:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
// For warnings-as-errors.
|
|
|
|
break;
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return IsExtensionSupported(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebGLContext::IsExtensionSupported(WebGLExtensionID ext) const
|
|
|
|
{
|
2014-11-14 04:03:50 +00:00
|
|
|
if (mDisableExtensions)
|
2013-08-26 21:12:53 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (ext) {
|
2014-11-14 04:03:50 +00:00
|
|
|
case WebGLExtensionID::OES_vertex_array_object:
|
|
|
|
case WebGLExtensionID::WEBGL_lose_context:
|
|
|
|
// Always supported.
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case WebGLExtensionID::EXT_blend_minmax:
|
|
|
|
return WebGLExtensionBlendMinMax::IsSupported(this);
|
|
|
|
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 gl->IsSupported(gl::GLFeature::texture_float);
|
|
|
|
case WebGLExtensionID::OES_texture_float_linear:
|
|
|
|
return gl->IsSupported(gl::GLFeature::texture_float_linear);
|
|
|
|
case WebGLExtensionID::OES_texture_half_float:
|
|
|
|
// If we have Feature::texture_half_float, we must not be on ES2
|
|
|
|
// and need to translate HALF_FLOAT_OES -> HALF_FLOAT. We do that
|
|
|
|
// right before making the relevant calls.
|
|
|
|
return gl->IsExtensionSupported(gl::GLContext::OES_texture_half_float) ||
|
|
|
|
gl->IsSupported(gl::GLFeature::texture_half_float);
|
|
|
|
|
|
|
|
case WebGLExtensionID::OES_texture_half_float_linear:
|
|
|
|
return gl->IsSupported(gl::GLFeature::texture_half_float_linear);
|
|
|
|
case WebGLExtensionID::EXT_texture_filter_anisotropic:
|
|
|
|
return gl->IsExtensionSupported(gl::GLContext::EXT_texture_filter_anisotropic);
|
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_s3tc:
|
|
|
|
if (gl->IsExtensionSupported(gl::GLContext::EXT_texture_compression_s3tc))
|
2013-08-26 21:12:53 +00:00
|
|
|
return true;
|
2014-11-14 04:03:50 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_atc:
|
|
|
|
return gl->IsExtensionSupported(gl::GLContext::AMD_compressed_ATC_texture);
|
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_etc1:
|
|
|
|
return gl->IsExtensionSupported(gl::GLContext::OES_compressed_ETC1_RGB8_texture);
|
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_pvrtc:
|
|
|
|
return gl->IsExtensionSupported(gl::GLContext::IMG_texture_compression_pvrtc);
|
|
|
|
case WebGLExtensionID::WEBGL_depth_texture:
|
|
|
|
// WEBGL_depth_texture supports DEPTH_STENCIL textures
|
|
|
|
if (!gl->IsSupported(gl::GLFeature::packed_depth_stencil))
|
2013-08-26 21:12:53 +00:00
|
|
|
return false;
|
2014-11-14 04:03:50 +00:00
|
|
|
|
|
|
|
return gl->IsSupported(gl::GLFeature::depth_texture) ||
|
|
|
|
gl->IsExtensionSupported(gl::GLContext::ANGLE_depth_texture);
|
|
|
|
|
|
|
|
case WebGLExtensionID::ANGLE_instanced_arrays:
|
|
|
|
return WebGLExtensionInstancedArrays::IsSupported(this);
|
|
|
|
case WebGLExtensionID::EXT_sRGB:
|
|
|
|
return WebGLExtensionSRGB::IsSupported(this);
|
|
|
|
case WebGLExtensionID::WEBGL_draw_buffers:
|
|
|
|
return WebGLExtensionDrawBuffers::IsSupported(this);
|
|
|
|
case WebGLExtensionID::EXT_frag_depth:
|
|
|
|
return WebGLExtensionFragDepth::IsSupported(this);
|
|
|
|
case WebGLExtensionID::EXT_shader_texture_lod:
|
|
|
|
return gl->IsExtensionSupported(gl::GLContext::EXT_shader_texture_lod);
|
|
|
|
|
|
|
|
default:
|
|
|
|
// For warnings-as-errors.
|
|
|
|
break;
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
2014-06-14 16:07:53 +00:00
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
if (Preferences::GetBool("webgl.enable-draft-extensions", false) ||
|
|
|
|
IsWebGL2())
|
|
|
|
{
|
2013-08-26 21:12:53 +00:00
|
|
|
switch (ext) {
|
2014-11-14 04:03:50 +00:00
|
|
|
case WebGLExtensionID::EXT_color_buffer_half_float:
|
|
|
|
return WebGLExtensionColorBufferHalfFloat::IsSupported(this);
|
|
|
|
case WebGLExtensionID::WEBGL_color_buffer_float:
|
|
|
|
return WebGLExtensionColorBufferFloat::IsSupported(this);
|
|
|
|
default:
|
|
|
|
// For warnings-as-errors.
|
|
|
|
break;
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2014-11-14 04:03:50 +00:00
|
|
|
CompareWebGLExtensionName(const nsACString& name, const char* other)
|
2013-08-26 21:12:53 +00:00
|
|
|
{
|
|
|
|
return name.Equals(other, nsCaseInsensitiveCStringComparator());
|
|
|
|
}
|
|
|
|
|
2014-11-21 23:04:08 +00:00
|
|
|
WebGLExtensionBase*
|
|
|
|
WebGLContext::EnableSupportedExtension(JSContext* js, WebGLExtensionID ext)
|
|
|
|
{
|
|
|
|
if (!IsExtensionEnabled(ext)) {
|
|
|
|
if (!IsExtensionSupported(js, ext))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
EnableExtension(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mExtensions[ext];
|
|
|
|
}
|
|
|
|
|
2014-06-11 20:26:52 +00:00
|
|
|
void
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLContext::GetExtension(JSContext* cx, const nsAString& wideName,
|
|
|
|
JS::MutableHandle<JSObject*> retval, ErrorResult& rv)
|
2013-08-26 21:12:53 +00:00
|
|
|
{
|
2014-11-14 04:03:50 +00:00
|
|
|
retval.set(nullptr);
|
|
|
|
|
|
|
|
if (IsContextLost())
|
2014-06-11 20:26:52 +00:00
|
|
|
return;
|
2013-08-26 21:12:53 +00:00
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
NS_LossyConvertUTF16toASCII name(wideName);
|
2013-08-26 21:12:53 +00:00
|
|
|
|
2014-04-26 02:34:07 +00:00
|
|
|
WebGLExtensionID ext = WebGLExtensionID::Unknown;
|
2013-08-26 21:12:53 +00:00
|
|
|
|
|
|
|
// step 1: figure what extension is wanted
|
2014-11-21 23:04:08 +00:00
|
|
|
for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) {
|
2013-08-26 21:12:53 +00:00
|
|
|
WebGLExtensionID extension = WebGLExtensionID(i);
|
2014-02-11 22:37:05 +00:00
|
|
|
|
2013-08-26 21:12:53 +00:00
|
|
|
if (CompareWebGLExtensionName(name, GetExtensionString(extension))) {
|
|
|
|
ext = extension;
|
|
|
|
break;
|
|
|
|
}
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
2013-08-26 21:12:53 +00:00
|
|
|
|
2014-11-21 23:04:08 +00:00
|
|
|
if (ext == WebGLExtensionID::Unknown) {
|
2014-11-14 04:03:50 +00: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-26 21:12:53 +00:00
|
|
|
if (CompareWebGLExtensionName(name, "MOZ_WEBGL_lose_context")) {
|
2014-04-26 02:34:07 +00:00
|
|
|
ext = WebGLExtensionID::WEBGL_lose_context;
|
2014-11-14 04:03:50 +00:00
|
|
|
|
|
|
|
} else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_s3tc")) {
|
2014-04-26 02:34:07 +00:00
|
|
|
ext = WebGLExtensionID::WEBGL_compressed_texture_s3tc;
|
2014-11-14 04:03:50 +00:00
|
|
|
|
|
|
|
} else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_atc")) {
|
2014-04-26 02:34:07 +00:00
|
|
|
ext = WebGLExtensionID::WEBGL_compressed_texture_atc;
|
2014-11-14 04:03:50 +00:00
|
|
|
|
|
|
|
} else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_compressed_texture_pvrtc")) {
|
2014-04-26 02:34:07 +00:00
|
|
|
ext = WebGLExtensionID::WEBGL_compressed_texture_pvrtc;
|
2014-11-14 04:03:50 +00:00
|
|
|
|
|
|
|
} else if (CompareWebGLExtensionName(name, "MOZ_WEBGL_depth_texture")) {
|
2014-04-26 02:34:07 +00:00
|
|
|
ext = WebGLExtensionID::WEBGL_depth_texture;
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
2013-10-11 13:16:43 +00:00
|
|
|
|
2014-04-26 02:34:07 +00:00
|
|
|
if (ext != WebGLExtensionID::Unknown) {
|
2014-11-14 04:03:50 +00: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 13:16:43 +00:00
|
|
|
name.get());
|
|
|
|
}
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
if (ext == WebGLExtensionID::Unknown)
|
2014-06-11 20:26:52 +00:00
|
|
|
return;
|
2013-08-26 21:12:53 +00:00
|
|
|
|
|
|
|
// step 2: check if the extension is supported
|
2014-11-14 04:03:50 +00:00
|
|
|
if (!IsExtensionSupported(cx, ext))
|
2014-06-11 20:26:52 +00:00
|
|
|
return;
|
2013-08-26 21:12:53 +00:00
|
|
|
|
|
|
|
// step 3: if the extension hadn't been previously been created, create it now, thus enabling it
|
2014-11-21 23:04:08 +00:00
|
|
|
WebGLExtensionBase* extObj = EnableSupportedExtension(cx, ext);
|
2014-11-14 04:03:50 +00:00
|
|
|
if (!extObj)
|
2014-11-21 23:04:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Step 4: Enable any implied extensions.
|
|
|
|
switch (ext) {
|
|
|
|
case WebGLExtensionID::OES_texture_float:
|
|
|
|
EnableSupportedExtension(cx, WebGLExtensionID::WEBGL_color_buffer_float);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WebGLExtensionID::OES_texture_half_float:
|
|
|
|
EnableSupportedExtension(cx, WebGLExtensionID::EXT_color_buffer_half_float);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
retval.set(WebGLObjectAsJSObject(cx, extObj, rv));
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::EnableExtension(WebGLExtensionID ext)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsExtensionEnabled(ext) == false);
|
|
|
|
|
|
|
|
WebGLExtensionBase* obj = nullptr;
|
|
|
|
switch (ext) {
|
2014-11-14 04:03:50 +00:00
|
|
|
case WebGLExtensionID::OES_element_index_uint:
|
|
|
|
obj = new WebGLExtensionElementIndexUint(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::OES_standard_derivatives:
|
|
|
|
obj = new WebGLExtensionStandardDerivatives(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::EXT_texture_filter_anisotropic:
|
|
|
|
obj = new WebGLExtensionTextureFilterAnisotropic(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::WEBGL_lose_context:
|
|
|
|
obj = new WebGLExtensionLoseContext(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_s3tc:
|
|
|
|
obj = new WebGLExtensionCompressedTextureS3TC(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_atc:
|
|
|
|
obj = new WebGLExtensionCompressedTextureATC(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_etc1:
|
|
|
|
obj = new WebGLExtensionCompressedTextureETC1(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::WEBGL_compressed_texture_pvrtc:
|
|
|
|
obj = new WebGLExtensionCompressedTexturePVRTC(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::WEBGL_debug_renderer_info:
|
|
|
|
obj = new WebGLExtensionDebugRendererInfo(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::WEBGL_debug_shaders:
|
|
|
|
obj = new WebGLExtensionDebugShaders(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::WEBGL_depth_texture:
|
|
|
|
obj = new WebGLExtensionDepthTexture(this);
|
|
|
|
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;
|
|
|
|
case WebGLExtensionID::WEBGL_color_buffer_float:
|
|
|
|
obj = new WebGLExtensionColorBufferFloat(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::EXT_color_buffer_half_float:
|
|
|
|
obj = new WebGLExtensionColorBufferHalfFloat(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::WEBGL_draw_buffers:
|
|
|
|
obj = new WebGLExtensionDrawBuffers(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::OES_vertex_array_object:
|
|
|
|
obj = new WebGLExtensionVertexArray(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::ANGLE_instanced_arrays:
|
|
|
|
obj = new WebGLExtensionInstancedArrays(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::EXT_sRGB:
|
|
|
|
obj = new WebGLExtensionSRGB(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::EXT_frag_depth:
|
|
|
|
obj = new WebGLExtensionFragDepth(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::EXT_blend_minmax:
|
|
|
|
obj = new WebGLExtensionBlendMinMax(this);
|
|
|
|
break;
|
|
|
|
case WebGLExtensionID::EXT_shader_texture_lod:
|
|
|
|
obj = new WebGLExtensionShaderTextureLod(this);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "should not get there.");
|
|
|
|
break;
|
2013-08-26 21:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mExtensions[ext] = obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLContext::GetSupportedExtensions(JSContext* cx,
|
|
|
|
Nullable< nsTArray<nsString> >& retval)
|
2013-08-26 21:12:53 +00:00
|
|
|
{
|
|
|
|
retval.SetNull();
|
2013-09-04 12:14:44 +00:00
|
|
|
if (IsContextLost())
|
2013-08-26 21:12:53 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsTArray<nsString>& arr = retval.SetValue();
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
for (size_t i = 0; i < size_t(WebGLExtensionID::Max); i++) {
|
2013-08-26 21:12:53 +00:00
|
|
|
WebGLExtensionID extension = WebGLExtensionID(i);
|
|
|
|
|
|
|
|
if (IsExtensionSupported(cx, extension)) {
|
2014-11-14 04:03:50 +00:00
|
|
|
const char* extStr = GetExtensionString(extension);
|
|
|
|
arr.AppendElement(NS_ConvertUTF8toUTF16(extStr));
|
2013-08-26 21:12:53 +00: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.
|
|
|
|
*/
|
2014-04-26 02:34:07 +00:00
|
|
|
if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_lose_context))
|
2013-08-26 21:12:53 +00:00
|
|
|
arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_lose_context"));
|
2014-04-26 02:34:07 +00:00
|
|
|
if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_compressed_texture_s3tc))
|
2013-08-26 21:12:53 +00:00
|
|
|
arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_s3tc"));
|
2014-04-26 02:34:07 +00:00
|
|
|
if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_compressed_texture_atc))
|
2013-08-26 21:12:53 +00:00
|
|
|
arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_atc"));
|
2014-04-26 02:34:07 +00:00
|
|
|
if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_compressed_texture_pvrtc))
|
2013-08-26 21:12:53 +00:00
|
|
|
arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_pvrtc"));
|
2014-04-26 02:34:07 +00:00
|
|
|
if (IsExtensionSupported(cx, WebGLExtensionID::WEBGL_depth_texture))
|
2013-08-26 21:12:53 +00:00
|
|
|
arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_depth_texture"));
|
|
|
|
}
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
} // namespace mozilla
|