2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-07-17 13:58:09 +00:00
|
|
|
/* 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"
|
2014-11-14 04:03:50 +00:00
|
|
|
|
2019-07-26 01:10:23 +00:00
|
|
|
#include "mozilla/StaticPrefs_webgl.h"
|
2013-09-04 12:14:52 +00:00
|
|
|
#include "GLContext.h"
|
2013-07-17 13:58:09 +00:00
|
|
|
#include "mozilla/dom/WebGL2RenderingContextBinding.h"
|
2014-10-26 23:36:26 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-07-17 13:58:09 +00:00
|
|
|
#include "mozilla/Telemetry.h"
|
2016-05-28 04:40:37 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2015-07-10 23:34:45 +00:00
|
|
|
#include "WebGLBuffer.h"
|
|
|
|
#include "WebGLFormats.h"
|
|
|
|
#include "WebGLTransformFeedback.h"
|
2013-07-17 13:58:09 +00:00
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
namespace mozilla {
|
2013-07-17 13:58:09 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
UniquePtr<webgl::FormatUsageAuthority> WebGL2Context::CreateFormatUsage(
|
|
|
|
gl::GLContext* gl) const {
|
|
|
|
return webgl::FormatUsageAuthority::CreateForWebGL2(gl);
|
2013-07-17 13:58:09 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-08-26 21:12:54 +00:00
|
|
|
// WebGL 2 initialisation
|
|
|
|
|
2014-10-26 23:36:26 +00:00
|
|
|
static const gl::GLFeature kRequiredFeatures[] = {
|
|
|
|
gl::GLFeature::blend_minmax,
|
|
|
|
gl::GLFeature::clear_buffers,
|
|
|
|
gl::GLFeature::copy_buffer,
|
|
|
|
gl::GLFeature::depth_texture,
|
|
|
|
gl::GLFeature::draw_instanced,
|
|
|
|
gl::GLFeature::element_index_uint,
|
|
|
|
gl::GLFeature::frag_color_float,
|
|
|
|
gl::GLFeature::frag_depth,
|
2015-07-03 01:55:43 +00:00
|
|
|
gl::GLFeature::framebuffer_object,
|
2014-10-26 23:36:26 +00:00
|
|
|
gl::GLFeature::get_integer_indexed,
|
|
|
|
gl::GLFeature::get_integer64_indexed,
|
|
|
|
gl::GLFeature::gpu_shader4,
|
|
|
|
gl::GLFeature::instanced_arrays,
|
|
|
|
gl::GLFeature::instanced_non_arrays,
|
2016-05-09 19:00:10 +00:00
|
|
|
gl::GLFeature::map_buffer_range, // Used by GetBufferSubData.
|
2014-10-26 23:36:26 +00:00
|
|
|
gl::GLFeature::occlusion_query2,
|
|
|
|
gl::GLFeature::packed_depth_stencil,
|
|
|
|
gl::GLFeature::query_objects,
|
2017-09-28 02:38:04 +00:00
|
|
|
gl::GLFeature::sRGB,
|
2014-10-26 23:36:26 +00:00
|
|
|
gl::GLFeature::sampler_objects,
|
|
|
|
gl::GLFeature::standard_derivatives,
|
|
|
|
gl::GLFeature::texture_3D,
|
|
|
|
gl::GLFeature::texture_3D_compressed,
|
|
|
|
gl::GLFeature::texture_3D_copy,
|
|
|
|
gl::GLFeature::texture_float,
|
|
|
|
gl::GLFeature::texture_half_float,
|
|
|
|
gl::GLFeature::texture_half_float_linear,
|
|
|
|
gl::GLFeature::texture_non_power_of_two,
|
|
|
|
gl::GLFeature::texture_storage,
|
|
|
|
gl::GLFeature::transform_feedback2,
|
|
|
|
gl::GLFeature::uniform_buffer_object,
|
|
|
|
gl::GLFeature::uniform_matrix_nonsquare,
|
|
|
|
gl::GLFeature::vertex_array_object};
|
|
|
|
|
2016-06-21 03:42:10 +00:00
|
|
|
bool WebGLContext::InitWebGL2(FailureReason* const out_failReason) {
|
2013-08-26 21:12:54 +00:00
|
|
|
MOZ_ASSERT(IsWebGL2(), "WebGLContext is not a WebGL 2 context!");
|
|
|
|
|
2015-03-24 07:11:10 +00:00
|
|
|
std::vector<gl::GLFeature> missingList;
|
|
|
|
|
2016-07-29 00:14:47 +00:00
|
|
|
const auto fnGatherMissing = [&](gl::GLFeature cur) {
|
|
|
|
if (!gl->IsSupported(cur)) {
|
|
|
|
missingList.push_back(cur);
|
2016-05-11 23:45:43 +00:00
|
|
|
}
|
2016-07-29 00:14:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto fnGatherMissing2 = [&](gl::GLFeature main, gl::GLFeature alt) {
|
|
|
|
if (!gl->IsSupported(main) && !gl->IsSupported(alt)) {
|
|
|
|
missingList.push_back(main);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
for (const auto& cur : kRequiredFeatures) {
|
|
|
|
fnGatherMissing(cur);
|
2015-03-24 07:11:10 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 00:14:47 +00:00
|
|
|
// On desktop, we fake occlusion_query_boolean with occlusion_query if
|
|
|
|
// necessary. (See WebGL2ContextQueries.cpp)
|
|
|
|
fnGatherMissing2(gl::GLFeature::occlusion_query_boolean,
|
|
|
|
gl::GLFeature::occlusion_query);
|
|
|
|
|
2015-01-29 05:29:45 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// On OSX, GL core profile is used. This requires texture swizzle
|
|
|
|
// support to emulate legacy texture formats: ALPHA, LUMINANCE,
|
|
|
|
// and LUMINANCE_ALPHA.
|
2016-07-29 00:14:47 +00:00
|
|
|
fnGatherMissing(gl::GLFeature::texture_swizzle);
|
2015-01-29 05:29:45 +00:00
|
|
|
#endif
|
|
|
|
|
2016-07-27 03:05:45 +00:00
|
|
|
fnGatherMissing2(gl::GLFeature::prim_restart_fixed,
|
|
|
|
gl::GLFeature::prim_restart);
|
|
|
|
|
2016-07-29 00:14:47 +00:00
|
|
|
////
|
|
|
|
|
2017-08-03 10:01:38 +00:00
|
|
|
if (!missingList.empty()) {
|
2015-03-24 07:11:10 +00:00
|
|
|
nsAutoCString exts;
|
|
|
|
for (auto itr = missingList.begin(); itr != missingList.end(); ++itr) {
|
|
|
|
exts.AppendLiteral("\n ");
|
|
|
|
exts.Append(gl::GLContext::GetFeatureName(*itr));
|
2013-08-26 21:12:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsPrintfCString reason(
|
|
|
|
"WebGL 2 requires support for the following"
|
|
|
|
" features: %s",
|
2014-11-14 04:03:50 +00:00
|
|
|
exts.BeginReading());
|
|
|
|
*out_failReason = FailureReason("FEATURE_FAILURE_WEBGL2_OCCL", reason);
|
2014-12-05 07:04:55 +00:00
|
|
|
return false;
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2014-12-05 07:04:55 +00:00
|
|
|
|
2019-02-07 22:50:14 +00:00
|
|
|
mGLMinProgramTexelOffset =
|
|
|
|
gl->GetIntAs<uint32_t>(LOCAL_GL_MIN_PROGRAM_TEXEL_OFFSET);
|
|
|
|
mGLMaxProgramTexelOffset =
|
|
|
|
gl->GetIntAs<uint32_t>(LOCAL_GL_MAX_PROGRAM_TEXEL_OFFSET);
|
2019-02-05 03:36:03 +00:00
|
|
|
|
2020-01-08 22:19:16 +00:00
|
|
|
mIndexedUniformBufferBindings.resize(mLimits->maxUniformBufferBindings);
|
2014-11-26 02:00:06 +00:00
|
|
|
|
2016-12-29 08:08:39 +00:00
|
|
|
mDefaultTransformFeedback = new WebGLTransformFeedback(this, 0);
|
2014-11-26 02:00:06 +00:00
|
|
|
mBoundTransformFeedback = mDefaultTransformFeedback;
|
2016-12-29 08:08:39 +00:00
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
gl->fGenTransformFeedbacks(1, &mEmptyTFO);
|
2016-07-27 03:05:45 +00:00
|
|
|
|
2015-11-25 04:15:29 +00:00
|
|
|
////
|
|
|
|
|
|
|
|
if (!gl->IsGLES()) {
|
|
|
|
// Desktop OpenGL requires the following to be enabled in order to
|
|
|
|
// support sRGB operations on framebuffers.
|
|
|
|
gl->fEnable(LOCAL_GL_FRAMEBUFFER_SRGB_EXT);
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 03:05:45 +00:00
|
|
|
if (gl->IsSupported(gl::GLFeature::prim_restart_fixed)) {
|
|
|
|
gl->fEnable(LOCAL_GL_PRIMITIVE_RESTART_FIXED_INDEX);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(gl->IsSupported(gl::GLFeature::prim_restart));
|
|
|
|
}
|
|
|
|
|
2016-07-08 19:30:17 +00:00
|
|
|
//////
|
|
|
|
|
2013-08-26 21:12:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-11-14 04:03:50 +00:00
|
|
|
|
2020-01-08 22:19:16 +00:00
|
|
|
// -
|
|
|
|
|
|
|
|
/*virtual*/
|
|
|
|
bool WebGL2Context::IsTexParamValid(GLenum pname) const {
|
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_TEXTURE_BASE_LEVEL:
|
|
|
|
case LOCAL_GL_TEXTURE_COMPARE_FUNC:
|
|
|
|
case LOCAL_GL_TEXTURE_COMPARE_MODE:
|
|
|
|
case LOCAL_GL_TEXTURE_IMMUTABLE_FORMAT:
|
|
|
|
case LOCAL_GL_TEXTURE_IMMUTABLE_LEVELS:
|
|
|
|
case LOCAL_GL_TEXTURE_MAX_LEVEL:
|
|
|
|
case LOCAL_GL_TEXTURE_WRAP_R:
|
|
|
|
case LOCAL_GL_TEXTURE_MAX_LOD:
|
|
|
|
case LOCAL_GL_TEXTURE_MIN_LOD:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return WebGLContext::IsTexParamValid(pname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
} // namespace mozilla
|