no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / canvas / WebGL2ContextSamplers.cpp
blob9656e52471f6951f23a35241cf66d80842c110b6
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"
8 #include "GLContext.h"
10 namespace mozilla {
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());
29 ////
31 gl->fBindSampler(unit, sampler ? sampler->mGLName : 0);
33 mBoundSamplers[unit] = sampler;
35 funcScope.mBindFailureGuard = false;
38 void WebGL2Context::SamplerParameteri(WebGLSampler& sampler, GLenum pname,
39 GLint param) {
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,
49 GLfloat param) {
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,
59 GLenum pname) const {
60 const FuncScope funcScope(*this, "getSamplerParameter");
61 if (IsContextLost()) return {};
63 if (!ValidateObject("sampler", sampler)) return {};
65 ////
67 const auto fnAsFloat = [&]() {
68 GLfloat param = 0;
69 gl->fGetSamplerParameterfv(sampler.mGLName, pname, &param);
70 return param;
73 switch (pname) {
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: {
81 GLint param = 0;
82 gl->fGetSamplerParameteriv(sampler.mGLName, pname, &param);
83 return Some(param);
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)) {
92 break;
94 return Some(fnAsFloat());
96 default:
97 break;
99 ErrorInvalidEnumInfo("pname", pname);
100 return {};
103 } // namespace mozilla