Bumping manifests a=b2g-bump
[gecko.git] / dom / canvas / WebGL2ContextSamplers.cpp
blob922ed4ad15f13638ac991275f9e9b233b52929a4
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"
8 #include "GLContext.h"
10 using namespace mozilla;
11 using namespace mozilla::dom;
13 already_AddRefed<WebGLSampler>
14 WebGL2Context::CreateSampler()
16 if (IsContextLost())
17 return nullptr;
19 GLuint sampler;
20 MakeContextCurrent();
21 gl->fGenSamplers(1, &sampler);
23 nsRefPtr<WebGLSampler> globj = new WebGLSampler(this, sampler);
24 return globj.forget();
27 void
28 WebGL2Context::DeleteSampler(WebGLSampler* sampler)
30 if (IsContextLost())
31 return;
33 if (!ValidateObjectAllowDeletedOrNull("deleteSampler", sampler))
34 return;
36 if (!sampler || sampler->IsDeleted())
37 return;
39 sampler->RequestDelete();
42 bool
43 WebGL2Context::IsSampler(WebGLSampler* sampler)
45 if (IsContextLost())
46 return false;
48 if (!sampler)
49 return false;
51 if (!ValidateObjectAllowDeleted("isSampler", sampler))
52 return false;
54 if (sampler->IsDeleted())
55 return false;
57 return !sampler->HasEverBeenBound();
60 void
61 WebGL2Context::BindSampler(GLuint unit, WebGLSampler* sampler)
63 if (IsContextLost())
64 return;
66 if (!ValidateObjectAllowDeletedOrNull("bindSampler", sampler))
67 return;
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);
78 void
79 WebGL2Context::SamplerParameteri(WebGLSampler* sampler, GLenum pname, GLint param)
81 if (IsContextLost())
82 return;
84 if (!sampler || sampler->IsDeleted())
85 return ErrorInvalidOperation("samplerParameteri: invalid sampler");
87 if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param), "samplerParameteri"))
88 return;
90 WebGLContextUnchecked::SamplerParameteri(sampler, pname, param);
93 void
94 WebGL2Context::SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Int32Array& param)
96 if (IsContextLost())
97 return;
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"))
108 return;
110 WebGLContextUnchecked::SamplerParameteriv(sampler, pname, param.Data());
113 void
114 WebGL2Context::SamplerParameteriv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLint>& param)
116 if (IsContextLost())
117 return;
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"))
127 return;
129 WebGLContextUnchecked::SamplerParameteriv(sampler, pname, param.Elements());
132 void
133 WebGL2Context::SamplerParameterf(WebGLSampler* sampler, GLenum pname, GLfloat param)
135 if (IsContextLost())
136 return;
138 if (!sampler || sampler->IsDeleted())
139 return ErrorInvalidOperation("samplerParameterf: invalid sampler");
141 if (!ValidateSamplerParameterParams(pname, WebGLIntOrFloat(param), "samplerParameterf"))
142 return;
144 WebGLContextUnchecked::SamplerParameterf(sampler, pname, param);
147 void
148 WebGL2Context::SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Float32Array& param)
150 if (IsContextLost())
151 return;
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"))
162 return;
164 WebGLContextUnchecked::SamplerParameterfv(sampler, pname, param.Data());
167 void
168 WebGL2Context::SamplerParameterfv(WebGLSampler* sampler, GLenum pname, const dom::Sequence<GLfloat>& param)
170 if (IsContextLost())
171 return;
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"))
181 return;
183 WebGLContextUnchecked::SamplerParameterfv(sampler, pname, param.Elements());
186 void
187 WebGL2Context::GetSamplerParameter(JSContext*, WebGLSampler* sampler, GLenum pname, JS::MutableHandleValue retval)
189 if (IsContextLost())
190 return;
192 if (!sampler || sampler->IsDeleted())
193 return ErrorInvalidOperation("getSamplerParameter: invalid sampler");
195 if (!ValidateSamplerParameterName(pname, "getSamplerParameter"))
196 return;
198 retval.set(JS::NullValue());
200 switch (pname) {
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)));
210 return;
212 case LOCAL_GL_TEXTURE_MIN_LOD:
213 case LOCAL_GL_TEXTURE_MAX_LOD:
214 retval.set(JS::Float32Value(
215 WebGLContextUnchecked::GetSamplerParameterfv(sampler, pname)));
216 return;