1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
10 using namespace mozilla
;
11 using namespace mozilla::dom
;
13 already_AddRefed
<WebGLSampler
>
14 WebGL2Context::CreateSampler()
21 gl
->fGenSamplers(1, &sampler
);
23 nsRefPtr
<WebGLSampler
> globj
= new WebGLSampler(this, sampler
);
24 return globj
.forget();
28 WebGL2Context::DeleteSampler(WebGLSampler
* sampler
)
33 if (!ValidateObjectAllowDeletedOrNull("deleteSampler", sampler
))
36 if (!sampler
|| sampler
->IsDeleted())
39 sampler
->RequestDelete();
43 WebGL2Context::IsSampler(WebGLSampler
* sampler
)
51 if (!ValidateObjectAllowDeleted("isSampler", sampler
))
54 if (sampler
->IsDeleted())
57 return !sampler
->HasEverBeenBound();
61 WebGL2Context::BindSampler(GLuint unit
, WebGLSampler
* sampler
)
66 if (!ValidateObjectAllowDeletedOrNull("bindSampler", sampler
))
69 if (GLint(unit
) >= mGLMaxTextureUnits
)
70 return ErrorInvalidValue("bindSampler: unit must be < %d", mGLMaxTextureUnits
);
72 if (sampler
&& sampler
->IsDeleted())
73 return ErrorInvalidOperation("bindSampler: binding deleted sampler");
75 WebGLContextUnchecked::BindSampler(unit
, sampler
);
79 WebGL2Context::SamplerParameteri(WebGLSampler
* sampler
, GLenum pname
, GLint param
)
84 if (!sampler
|| sampler
->IsDeleted())
85 return ErrorInvalidOperation("samplerParameteri: invalid sampler");
87 if (!ValidateSamplerParameterParams(pname
, WebGLIntOrFloat(param
), "samplerParameteri"))
90 WebGLContextUnchecked::SamplerParameteri(sampler
, pname
, param
);
94 WebGL2Context::SamplerParameteriv(WebGLSampler
* sampler
, GLenum pname
, const dom::Int32Array
& param
)
99 if (!sampler
|| sampler
->IsDeleted())
100 return ErrorInvalidOperation("samplerParameteriv: invalid sampler");
102 param
.ComputeLengthAndData();
103 if (param
.Length() < 1)
104 return /* TODO(djg): Error message */;
106 /* TODO(djg): All of these calls in ES3 only take 1 param */
107 if (!ValidateSamplerParameterParams(pname
, WebGLIntOrFloat(param
.Data()[0]), "samplerParameteriv"))
110 WebGLContextUnchecked::SamplerParameteriv(sampler
, pname
, param
.Data());
114 WebGL2Context::SamplerParameteriv(WebGLSampler
* sampler
, GLenum pname
, const dom::Sequence
<GLint
>& param
)
119 if (!sampler
|| sampler
->IsDeleted())
120 return ErrorInvalidOperation("samplerParameteriv: invalid sampler");
122 if (param
.Length() < 1)
123 return /* TODO(djg): Error message */;
125 /* TODO(djg): All of these calls in ES3 only take 1 param */
126 if (!ValidateSamplerParameterParams(pname
, WebGLIntOrFloat(param
[0]), "samplerParameteriv"))
129 WebGLContextUnchecked::SamplerParameteriv(sampler
, pname
, param
.Elements());
133 WebGL2Context::SamplerParameterf(WebGLSampler
* sampler
, GLenum pname
, GLfloat param
)
138 if (!sampler
|| sampler
->IsDeleted())
139 return ErrorInvalidOperation("samplerParameterf: invalid sampler");
141 if (!ValidateSamplerParameterParams(pname
, WebGLIntOrFloat(param
), "samplerParameterf"))
144 WebGLContextUnchecked::SamplerParameterf(sampler
, pname
, param
);
148 WebGL2Context::SamplerParameterfv(WebGLSampler
* sampler
, GLenum pname
, const dom::Float32Array
& param
)
153 if (!sampler
|| sampler
->IsDeleted())
154 return ErrorInvalidOperation("samplerParameterfv: invalid sampler");
156 param
.ComputeLengthAndData();
157 if (param
.Length() < 1)
158 return /* TODO(djg): Error message */;
160 /* TODO(djg): All of these calls in ES3 only take 1 param */
161 if (!ValidateSamplerParameterParams(pname
, WebGLIntOrFloat(param
.Data()[0]), "samplerParameterfv"))
164 WebGLContextUnchecked::SamplerParameterfv(sampler
, pname
, param
.Data());
168 WebGL2Context::SamplerParameterfv(WebGLSampler
* sampler
, GLenum pname
, const dom::Sequence
<GLfloat
>& param
)
173 if (!sampler
|| sampler
->IsDeleted())
174 return ErrorInvalidOperation("samplerParameterfv: invalid sampler");
176 if (param
.Length() < 1)
177 return /* TODO(djg): Error message */;
179 /* TODO(djg): All of these calls in ES3 only take 1 param */
180 if (!ValidateSamplerParameterParams(pname
, WebGLIntOrFloat(param
[0]), "samplerParameterfv"))
183 WebGLContextUnchecked::SamplerParameterfv(sampler
, pname
, param
.Elements());
187 WebGL2Context::GetSamplerParameter(JSContext
*, WebGLSampler
* sampler
, GLenum pname
, JS::MutableHandleValue retval
)
192 if (!sampler
|| sampler
->IsDeleted())
193 return ErrorInvalidOperation("getSamplerParameter: invalid sampler");
195 if (!ValidateSamplerParameterName(pname
, "getSamplerParameter"))
198 retval
.set(JS::NullValue());
201 case LOCAL_GL_TEXTURE_MIN_FILTER
:
202 case LOCAL_GL_TEXTURE_MAG_FILTER
:
203 case LOCAL_GL_TEXTURE_WRAP_S
:
204 case LOCAL_GL_TEXTURE_WRAP_T
:
205 case LOCAL_GL_TEXTURE_WRAP_R
:
206 case LOCAL_GL_TEXTURE_COMPARE_MODE
:
207 case LOCAL_GL_TEXTURE_COMPARE_FUNC
:
208 retval
.set(JS::Int32Value(
209 WebGLContextUnchecked::GetSamplerParameteriv(sampler
, pname
)));
212 case LOCAL_GL_TEXTURE_MIN_LOD
:
213 case LOCAL_GL_TEXTURE_MAX_LOD
:
214 retval
.set(JS::Float32Value(
215 WebGLContextUnchecked::GetSamplerParameterfv(sampler
, pname
)));