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 "WebGLSampler.h"
9 #include "mozilla/dom/WebGL2RenderingContextBinding.h"
10 #include "WebGLContext.h"
14 WebGLSampler::WebGLSampler(WebGLContext
* const webgl
)
15 : WebGLContextBoundObject(webgl
), mGLName([&]() {
17 webgl
->gl
->fGenSamplers(1, &ret
);
21 WebGLSampler::~WebGLSampler() {
22 if (!mContext
) return;
23 mContext
->gl
->fDeleteSamplers(1, &mGLName
);
26 static bool ValidateSamplerParameterParams(WebGLContext
* webgl
, GLenum pname
,
27 const FloatOrInt
& param
) {
28 const auto& paramInt
= param
.i
;
29 bool pnameValid
= true;
31 case LOCAL_GL_TEXTURE_MIN_FILTER
:
33 case LOCAL_GL_NEAREST
:
35 case LOCAL_GL_NEAREST_MIPMAP_NEAREST
:
36 case LOCAL_GL_NEAREST_MIPMAP_LINEAR
:
37 case LOCAL_GL_LINEAR_MIPMAP_NEAREST
:
38 case LOCAL_GL_LINEAR_MIPMAP_LINEAR
:
46 case LOCAL_GL_TEXTURE_MAG_FILTER
:
48 case LOCAL_GL_NEAREST
:
57 case LOCAL_GL_TEXTURE_WRAP_S
:
58 case LOCAL_GL_TEXTURE_WRAP_T
:
59 case LOCAL_GL_TEXTURE_WRAP_R
:
61 case LOCAL_GL_CLAMP_TO_EDGE
:
63 case LOCAL_GL_MIRRORED_REPEAT
:
71 case LOCAL_GL_TEXTURE_MIN_LOD
:
72 case LOCAL_GL_TEXTURE_MAX_LOD
:
75 case LOCAL_GL_TEXTURE_COMPARE_MODE
:
78 case LOCAL_GL_COMPARE_REF_TO_TEXTURE
:
86 case LOCAL_GL_TEXTURE_COMPARE_FUNC
:
91 case LOCAL_GL_GREATER
:
93 case LOCAL_GL_NOTEQUAL
:
103 case LOCAL_GL_TEXTURE_MAX_ANISOTROPY
:
104 if (webgl
->IsExtensionEnabled(
105 WebGLExtensionID::EXT_texture_filter_anisotropic
)) {
117 webgl
->ErrorInvalidEnumInfo("pname", pname
);
121 webgl
->ErrorInvalidEnumInfo("param", paramInt
);
125 void WebGLSampler::SamplerParameter(GLenum pname
, const FloatOrInt
& param
) {
126 if (!ValidateSamplerParameterParams(mContext
, pname
, param
)) return;
128 bool invalidate
= true;
130 case LOCAL_GL_TEXTURE_MIN_FILTER
:
131 mState
.minFilter
= param
.i
;
134 case LOCAL_GL_TEXTURE_MAG_FILTER
:
135 mState
.magFilter
= param
.i
;
138 case LOCAL_GL_TEXTURE_WRAP_S
:
139 mState
.wrapS
= param
.i
;
142 case LOCAL_GL_TEXTURE_WRAP_T
:
143 mState
.wrapT
= param
.i
;
146 case LOCAL_GL_TEXTURE_COMPARE_MODE
:
147 mState
.compareMode
= param
.i
;
162 mContext
->gl
->fSamplerParameterf(mGLName
, pname
, param
.f
);
164 mContext
->gl
->fSamplerParameteri(mGLName
, pname
, param
.i
);
168 } // namespace mozilla