1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "WebGLExtensions.h"
9 #include "mozilla/dom/WebGLRenderingContextBinding.h"
10 #include "WebGLContext.h"
14 WebGLExtensionDepthTexture::WebGLExtensionDepthTexture(
15 WebGLContext
* const webgl
)
16 : WebGLExtensionBase(webgl
) {
17 auto& fua
= webgl
->mFormatUsage
;
19 const auto fnAdd
= [&fua
](webgl::EffectiveFormat effFormat
,
20 GLenum unpackFormat
, GLenum unpackType
) {
21 auto usage
= fua
->EditUsage(effFormat
);
22 MOZ_ASSERT(usage
->isFilterable
);
23 MOZ_ASSERT(usage
->IsRenderable());
25 const webgl::PackingInfo pi
= {unpackFormat
, unpackType
};
26 const webgl::DriverUnpackInfo dui
= {unpackFormat
, unpackFormat
,
28 fua
->AddTexUnpack(usage
, pi
, dui
);
29 fua
->AllowUnsizedTexFormat(pi
, usage
);
32 fnAdd(webgl::EffectiveFormat::DEPTH_COMPONENT16
, LOCAL_GL_DEPTH_COMPONENT
,
33 LOCAL_GL_UNSIGNED_SHORT
);
34 fnAdd(webgl::EffectiveFormat::DEPTH_COMPONENT24
, LOCAL_GL_DEPTH_COMPONENT
,
35 LOCAL_GL_UNSIGNED_INT
);
36 fnAdd(webgl::EffectiveFormat::DEPTH24_STENCIL8
, LOCAL_GL_DEPTH_STENCIL
,
37 LOCAL_GL_UNSIGNED_INT_24_8
);
40 bool WebGLExtensionDepthTexture::IsSupported(const WebGLContext
* const webgl
) {
41 if (webgl
->IsWebGL2()) return false;
43 // WEBGL_depth_texture supports DEPTH_STENCIL textures
44 const auto& gl
= webgl
->gl
;
45 if (!gl
->IsSupported(gl::GLFeature::packed_depth_stencil
)) return false;
47 return gl
->IsSupported(gl::GLFeature::depth_texture
) ||
48 gl
->IsExtensionSupported(gl::GLContext::ANGLE_depth_texture
);
51 } // namespace mozilla