1 /* -*- Mode: C++; tab-width: 4; 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 "WebGL2Context.h"
7 #include "WebGLSampler.h"
12 RefPtr
<WebGLSampler
> WebGL2Context::CreateSampler() {
13 const FuncScope
funcScope(*this, "createSampler");
14 if (IsContextLost()) return nullptr;
16 return new WebGLSampler(this);
19 void WebGL2Context::BindSampler(GLuint unit
, WebGLSampler
* sampler
) {
20 FuncScope
funcScope(*this, "bindSampler");
21 if (IsContextLost()) return;
22 funcScope
.mBindFailureGuard
= true;
24 if (sampler
&& !ValidateObject("sampler", *sampler
)) return;
26 if (unit
>= mBoundSamplers
.Length())
27 return ErrorInvalidValue("unit must be < %u", mBoundSamplers
.Length());
31 gl
->fBindSampler(unit
, sampler
? sampler
->mGLName
: 0);
33 mBoundSamplers
[unit
] = sampler
;
35 funcScope
.mBindFailureGuard
= false;
38 void WebGL2Context::SamplerParameteri(WebGLSampler
& sampler
, GLenum pname
,
40 const FuncScope
funcScope(*this, "samplerParameteri");
41 if (IsContextLost()) return;
43 if (!ValidateObject("sampler", sampler
)) return;
45 sampler
.SamplerParameter(pname
, FloatOrInt(param
));
48 void WebGL2Context::SamplerParameterf(WebGLSampler
& sampler
, GLenum pname
,
50 const FuncScope
funcScope(*this, "samplerParameterf");
51 if (IsContextLost()) return;
53 if (!ValidateObject("sampler", sampler
)) return;
55 sampler
.SamplerParameter(pname
, FloatOrInt(param
));
58 Maybe
<double> WebGL2Context::GetSamplerParameter(const WebGLSampler
& sampler
,
60 const FuncScope
funcScope(*this, "getSamplerParameter");
61 if (IsContextLost()) return {};
63 if (!ValidateObject("sampler", sampler
)) return {};
67 const auto fnAsFloat
= [&]() {
69 gl
->fGetSamplerParameterfv(sampler
.mGLName
, pname
, ¶m
);
74 case LOCAL_GL_TEXTURE_MIN_FILTER
:
75 case LOCAL_GL_TEXTURE_MAG_FILTER
:
76 case LOCAL_GL_TEXTURE_WRAP_S
:
77 case LOCAL_GL_TEXTURE_WRAP_T
:
78 case LOCAL_GL_TEXTURE_WRAP_R
:
79 case LOCAL_GL_TEXTURE_COMPARE_MODE
:
80 case LOCAL_GL_TEXTURE_COMPARE_FUNC
: {
82 gl
->fGetSamplerParameteriv(sampler
.mGLName
, pname
, ¶m
);
85 case LOCAL_GL_TEXTURE_MIN_LOD
:
86 case LOCAL_GL_TEXTURE_MAX_LOD
:
87 return Some(fnAsFloat());
89 case LOCAL_GL_TEXTURE_MAX_ANISOTROPY
:
90 if (!IsExtensionEnabled(
91 WebGLExtensionID::EXT_texture_filter_anisotropic
)) {
94 return Some(fnAsFloat());
99 ErrorInvalidEnumInfo("pname", pname
);
103 } // namespace mozilla