Line data Source code
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/. */
5 :
6 : #ifndef WEBGL2CONTEXT_H_
7 : #define WEBGL2CONTEXT_H_
8 :
9 : #include "WebGLContext.h"
10 :
11 : namespace mozilla {
12 :
13 : class ErrorResult;
14 : class WebGLSampler;
15 : class WebGLSync;
16 : class WebGLTransformFeedback;
17 : class WebGLVertexArrayObject;
18 : namespace dom {
19 : class OwningUnsignedLongOrUint32ArrayOrBoolean;
20 : class OwningWebGLBufferOrLongLong;
21 : } // namespace dom
22 :
23 : class WebGL2Context
24 : : public WebGLContext
25 : {
26 : public:
27 :
28 : virtual ~WebGL2Context();
29 :
30 : static bool IsSupported();
31 : static WebGL2Context* Create();
32 :
33 0 : virtual bool IsWebGL2() const override
34 : {
35 0 : return true;
36 : }
37 :
38 : // -------------------------------------------------------------------------
39 : // IMPLEMENT nsWrapperCache
40 :
41 : virtual JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto) override;
42 :
43 : // -------------------------------------------------------------------------
44 : // Buffer objects - WebGL2ContextBuffers.cpp
45 :
46 : void CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
47 : GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
48 :
49 : private:
50 : template<typename BufferT>
51 : void GetBufferSubDataT(GLenum target, GLintptr offset, const BufferT& data);
52 :
53 : public:
54 : void GetBufferSubData(GLenum target, GLintptr srcByteOffset,
55 : const dom::ArrayBufferView& dstData, GLuint dstElemOffset,
56 : GLuint dstElemCountOverride);
57 :
58 : // -------------------------------------------------------------------------
59 : // Framebuffer objects - WebGL2ContextFramebuffers.cpp
60 :
61 : void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
62 : GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
63 : GLbitfield mask, GLenum filter);
64 : void FramebufferTextureLayer(GLenum target, GLenum attachment, WebGLTexture* texture, GLint level, GLint layer);
65 :
66 : virtual JS::Value GetFramebufferAttachmentParameter(JSContext* cx, GLenum target,
67 : GLenum attachment, GLenum pname,
68 : ErrorResult& rv) override;
69 : // Make the inline version from the superclass visible here.
70 : using WebGLContext::GetFramebufferAttachmentParameter;
71 :
72 : void InvalidateFramebuffer(GLenum target, const dom::Sequence<GLenum>& attachments,
73 : ErrorResult& rv);
74 : void InvalidateSubFramebuffer (GLenum target, const dom::Sequence<GLenum>& attachments, GLint x, GLint y,
75 : GLsizei width, GLsizei height, ErrorResult& rv);
76 : void ReadBuffer(GLenum mode);
77 :
78 :
79 : // -------------------------------------------------------------------------
80 : // Renderbuffer objects - WebGL2ContextRenderbuffers.cpp
81 :
82 : void GetInternalformatParameter(JSContext*, GLenum target, GLenum internalformat,
83 : GLenum pname, JS::MutableHandleValue retval,
84 : ErrorResult& rv);
85 : void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat,
86 : GLsizei width, GLsizei height);
87 :
88 :
89 : // -------------------------------------------------------------------------
90 : // Texture objects - WebGL2ContextTextures.cpp
91 :
92 0 : void TexStorage2D(GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width,
93 : GLsizei height)
94 : {
95 0 : const char funcName[] = "TexStorage2D";
96 0 : const uint8_t funcDims = 2;
97 0 : const GLsizei depth = 1;
98 : TexStorage(funcName, funcDims, target, levels, internalFormat, width, height,
99 0 : depth);
100 0 : }
101 :
102 0 : void TexStorage3D(GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width,
103 : GLsizei height, GLsizei depth)
104 : {
105 0 : const char funcName[] = "TexStorage3D";
106 0 : const uint8_t funcDims = 3;
107 : TexStorage(funcName, funcDims, target, levels, internalFormat, width, height,
108 0 : depth);
109 0 : }
110 :
111 : protected:
112 : void TexStorage(const char* funcName, uint8_t funcDims, GLenum target, GLsizei levels,
113 : GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth);
114 :
115 : ////////////////////////////////////
116 :
117 : public:
118 : template<typename T>
119 0 : void CompressedTexImage3D(GLenum target, GLint level, GLenum internalFormat,
120 : GLsizei width, GLsizei height, GLsizei depth, GLint border,
121 : const T& anySrc, GLuint viewElemOffset = 0,
122 : GLuint viewElemLengthOverride = 0)
123 : {
124 0 : const char funcName[] = "compressedTexImage3D";
125 0 : const uint8_t funcDims = 3;
126 0 : const TexImageSourceAdapter src(&anySrc, viewElemOffset, viewElemLengthOverride);
127 0 : CompressedTexImage(funcName, funcDims, target, level, internalFormat, width,
128 : height, depth, border, src);
129 0 : }
130 :
131 : template<typename T>
132 0 : void CompressedTexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
133 : GLint zOffset, GLsizei width, GLsizei height,
134 : GLsizei depth, GLenum unpackFormat, const T& anySrc,
135 : GLuint viewElemOffset = 0,
136 : GLuint viewElemLengthOverride = 0)
137 : {
138 0 : const char funcName[] = "compressedTexSubImage3D";
139 0 : const uint8_t funcDims = 3;
140 0 : const TexImageSourceAdapter src(&anySrc, viewElemOffset, viewElemLengthOverride);
141 0 : CompressedTexSubImage(funcName, funcDims, target, level, xOffset, yOffset,
142 : zOffset, width, height, depth, unpackFormat, src);
143 0 : }
144 :
145 : ////////////////////////////////////
146 :
147 0 : void CopyTexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
148 : GLint zOffset, GLint x, GLint y, GLsizei width,
149 : GLsizei height)
150 : {
151 0 : const char funcName[] = "copyTexSubImage3D";
152 0 : const uint8_t funcDims = 3;
153 0 : CopyTexSubImage(funcName, funcDims, target, level, xOffset, yOffset, zOffset,
154 0 : x, y, width, height);
155 0 : }
156 :
157 : ////////////////////////////////////
158 :
159 : template<typename T>
160 0 : void TexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
161 : GLsizei height, GLsizei depth, GLint border, GLenum unpackFormat,
162 : GLenum unpackType, const T& anySrc, ErrorResult& out_error)
163 : {
164 0 : const TexImageSourceAdapter src(&anySrc, &out_error);
165 0 : TexImage3D(target, level, internalFormat, width, height, depth, border,
166 : unpackFormat, unpackType, src);
167 0 : }
168 :
169 0 : void TexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
170 : GLsizei height, GLsizei depth, GLint border, GLenum unpackFormat,
171 : GLenum unpackType, const dom::ArrayBufferView& view,
172 : GLuint viewElemOffset, ErrorResult&)
173 : {
174 0 : const TexImageSourceAdapter src(&view, viewElemOffset);
175 : TexImage3D(target, level, internalFormat, width, height, depth, border,
176 0 : unpackFormat, unpackType, src);
177 0 : }
178 :
179 : protected:
180 0 : void TexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
181 : GLsizei height, GLsizei depth, GLint border, GLenum unpackFormat,
182 : GLenum unpackType, const TexImageSource& src)
183 : {
184 0 : const char funcName[] = "texImage3D";
185 0 : const uint8_t funcDims = 3;
186 0 : TexImage(funcName, funcDims, target, level, internalFormat, width, height, depth,
187 0 : border, unpackFormat, unpackType, src);
188 0 : }
189 :
190 : ////////////////////////////////////
191 :
192 : public:
193 : template<typename T>
194 0 : void TexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
195 : GLint zOffset, GLsizei width, GLsizei height, GLsizei depth,
196 : GLenum unpackFormat, GLenum unpackType, const T& anySrc,
197 : ErrorResult& out_error)
198 : {
199 0 : const TexImageSourceAdapter src(&anySrc, &out_error);
200 0 : TexSubImage3D(target, level, xOffset, yOffset, zOffset, width, height, depth,
201 : unpackFormat, unpackType, src);
202 0 : }
203 :
204 0 : void TexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
205 : GLint zOffset, GLsizei width, GLsizei height, GLsizei depth,
206 : GLenum unpackFormat, GLenum unpackType,
207 : const dom::Nullable<dom::ArrayBufferView>& maybeSrcView,
208 : GLuint srcElemOffset, ErrorResult&)
209 : {
210 0 : if (IsContextLost())
211 0 : return;
212 :
213 0 : if (!ValidateNonNull("texSubImage3D", maybeSrcView))
214 0 : return;
215 0 : const auto& srcView = maybeSrcView.Value();
216 :
217 0 : const TexImageSourceAdapter src(&srcView, srcElemOffset);
218 : TexSubImage3D(target, level, xOffset, yOffset, zOffset, width, height, depth,
219 0 : unpackFormat, unpackType, src);
220 : }
221 :
222 : protected:
223 0 : void TexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
224 : GLint zOffset, GLsizei width, GLsizei height, GLsizei depth,
225 : GLenum unpackFormat, GLenum unpackType, const TexImageSource& src)
226 : {
227 0 : const char funcName[] = "texSubImage3D";
228 0 : const uint8_t funcDims = 3;
229 0 : TexSubImage(funcName, funcDims, target, level, xOffset, yOffset, zOffset, width,
230 0 : height, depth, unpackFormat, unpackType, src);
231 0 : }
232 :
233 : public:
234 : // -------------------------------------------------------------------------
235 : // Programs and shaders - WebGL2ContextPrograms.cpp
236 : GLint GetFragDataLocation(const WebGLProgram& program, const nsAString& name);
237 :
238 :
239 : // -------------------------------------------------------------------------
240 : // Uniforms and attributes - WebGL2ContextUniforms.cpp
241 :
242 0 : void VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride,
243 : WebGLintptr byteOffset)
244 : {
245 0 : const char funcName[] = "vertexAttribIPointer";
246 0 : const bool isFuncInt = true;
247 0 : const bool normalized = false;
248 0 : VertexAttribAnyPointer(funcName, isFuncInt, index, size, type, normalized, stride,
249 0 : byteOffset);
250 0 : }
251 :
252 : ////////////////
253 :
254 : // GL 3.0 & ES 3.0
255 : void VertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w,
256 : const char* funcName = nullptr);
257 : void VertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w,
258 : const char* funcName = nullptr);
259 :
260 0 : void VertexAttribI4iv(GLuint index, const Int32ListU& list) {
261 0 : const auto& arr = Int32Arr::From(list);
262 0 : if (!ValidateAttribArraySetter("vertexAttribI4iv", 4, arr.elemCount))
263 0 : return;
264 :
265 0 : const auto& itr = arr.elemBytes;
266 0 : VertexAttribI4i(index, itr[0], itr[1], itr[2], itr[3]);
267 : }
268 :
269 0 : void VertexAttribI4uiv(GLuint index, const Uint32ListU& list) {
270 0 : const auto& arr = Uint32Arr::From(list);
271 0 : if (!ValidateAttribArraySetter("vertexAttribI4uiv", 4, arr.elemCount))
272 0 : return;
273 :
274 0 : const auto& itr = arr.elemBytes;
275 0 : VertexAttribI4ui(index, itr[0], itr[1], itr[2], itr[3]);
276 : }
277 :
278 : // -------------------------------------------------------------------------
279 : // Writing to the drawing buffer
280 :
281 : /* Implemented in WebGLContext
282 : void VertexAttribDivisor(GLuint index, GLuint divisor);
283 : void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount);
284 : void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, GLintptr offset, GLsizei instanceCount);
285 : */
286 :
287 0 : void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
288 : GLenum type, WebGLintptr byteOffset)
289 : {
290 0 : const char funcName[] = "drawRangeElements";
291 0 : if (IsContextLost())
292 0 : return;
293 :
294 0 : if (end < start) {
295 0 : ErrorInvalidValue("%s: end must be >= start.", funcName);
296 0 : return;
297 : }
298 :
299 0 : DrawElements(mode, count, type, byteOffset, funcName);
300 : }
301 :
302 : // ------------------------------------------------------------------------
303 : // Multiple Render Targets - WebGL2ContextMRTs.cpp
304 : /* Implemented in WebGLContext
305 : void DrawBuffers(const dom::Sequence<GLenum>& buffers);
306 : */
307 :
308 : private:
309 : bool ValidateClearBuffer(const char* funcName, GLenum buffer, GLint drawBuffer,
310 : size_t availElemCount, GLuint elemOffset, GLenum funcType);
311 :
312 : void ClearBufferfv(GLenum buffer, GLint drawBuffer, const Float32Arr& src,
313 : GLuint srcElemOffset);
314 : void ClearBufferiv(GLenum buffer, GLint drawBuffer, const Int32Arr& src,
315 : GLuint srcElemOffset);
316 : void ClearBufferuiv(GLenum buffer, GLint drawBuffer, const Uint32Arr& src,
317 : GLuint srcElemOffset);
318 :
319 : public:
320 0 : void ClearBufferfv(GLenum buffer, GLint drawBuffer, const Float32ListU& list,
321 : GLuint srcElemOffset)
322 : {
323 0 : ClearBufferfv(buffer, drawBuffer, Float32Arr::From(list), srcElemOffset);
324 0 : }
325 0 : void ClearBufferiv(GLenum buffer, GLint drawBuffer, const Int32ListU& list,
326 : GLuint srcElemOffset)
327 : {
328 0 : ClearBufferiv(buffer, drawBuffer, Int32Arr::From(list), srcElemOffset);
329 0 : }
330 0 : void ClearBufferuiv(GLenum buffer, GLint drawBuffer, const Uint32ListU& list,
331 : GLuint srcElemOffset)
332 : {
333 0 : ClearBufferuiv(buffer, drawBuffer, Uint32Arr::From(list), srcElemOffset);
334 0 : }
335 :
336 : void ClearBufferfi(GLenum buffer, GLint drawBuffer, GLfloat depth, GLint stencil);
337 :
338 : // -------------------------------------------------------------------------
339 : // Sampler Objects - WebGL2ContextSamplers.cpp
340 :
341 : already_AddRefed<WebGLSampler> CreateSampler();
342 : void DeleteSampler(WebGLSampler* sampler);
343 : bool IsSampler(const WebGLSampler* sampler);
344 : void BindSampler(GLuint unit, WebGLSampler* sampler);
345 : void SamplerParameteri(WebGLSampler& sampler, GLenum pname, GLint param);
346 : void SamplerParameterf(WebGLSampler& sampler, GLenum pname, GLfloat param);
347 : void GetSamplerParameter(JSContext*, const WebGLSampler& sampler, GLenum pname,
348 : JS::MutableHandleValue retval);
349 :
350 :
351 : // -------------------------------------------------------------------------
352 : // Sync objects - WebGL2ContextSync.cpp
353 :
354 : const GLuint64 kMaxClientWaitSyncTimeoutNS = 1000 * 1000 * 1000; // 1000ms in ns.
355 :
356 : already_AddRefed<WebGLSync> FenceSync(GLenum condition, GLbitfield flags);
357 : bool IsSync(const WebGLSync* sync);
358 : void DeleteSync(WebGLSync* sync);
359 : GLenum ClientWaitSync(const WebGLSync& sync, GLbitfield flags, GLuint64 timeout);
360 : void WaitSync(const WebGLSync& sync, GLbitfield flags, GLint64 timeout);
361 : void GetSyncParameter(JSContext*, const WebGLSync& sync, GLenum pname,
362 : JS::MutableHandleValue retval);
363 :
364 :
365 : // -------------------------------------------------------------------------
366 : // Transform Feedback - WebGL2ContextTransformFeedback.cpp
367 :
368 : already_AddRefed<WebGLTransformFeedback> CreateTransformFeedback();
369 : void DeleteTransformFeedback(WebGLTransformFeedback* tf);
370 : bool IsTransformFeedback(const WebGLTransformFeedback* tf);
371 : void BindTransformFeedback(GLenum target, WebGLTransformFeedback* tf);
372 : void BeginTransformFeedback(GLenum primitiveMode);
373 : void EndTransformFeedback();
374 : void PauseTransformFeedback();
375 : void ResumeTransformFeedback();
376 : void TransformFeedbackVaryings(WebGLProgram& program,
377 : const dom::Sequence<nsString>& varyings,
378 : GLenum bufferMode);
379 : already_AddRefed<WebGLActiveInfo>
380 : GetTransformFeedbackVarying(const WebGLProgram& program, GLuint index);
381 :
382 :
383 : // -------------------------------------------------------------------------
384 : // Uniform Buffer Objects and Transform Feedback Buffers - WebGL2ContextUniforms.cpp
385 : // TODO(djg): Implemented in WebGLContext
386 : /*
387 : void BindBufferBase(GLenum target, GLuint index, WebGLBuffer* buffer);
388 : void BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buffer, GLintptr offset, GLsizeiptr size);
389 : */
390 : virtual JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) override;
391 : // Make the inline version from the superclass visible here.
392 : using WebGLContext::GetParameter;
393 : void GetIndexedParameter(JSContext* cx, GLenum target, GLuint index,
394 : JS::MutableHandleValue retval, ErrorResult& rv);
395 : void GetUniformIndices(const WebGLProgram& program,
396 : const dom::Sequence<nsString>& uniformNames,
397 : dom::Nullable< nsTArray<GLuint> >& retval);
398 : void GetActiveUniforms(JSContext* cx, const WebGLProgram& program,
399 : const dom::Sequence<GLuint>& uniformIndices, GLenum pname,
400 : JS::MutableHandleValue retval);
401 :
402 : GLuint GetUniformBlockIndex(const WebGLProgram& program,
403 : const nsAString& uniformBlockName);
404 : void GetActiveUniformBlockParameter(JSContext*, const WebGLProgram& program,
405 : GLuint uniformBlockIndex, GLenum pname,
406 : JS::MutableHandleValue retval, ErrorResult& rv);
407 : void GetActiveUniformBlockName(const WebGLProgram& program, GLuint uniformBlockIndex,
408 : nsAString& retval);
409 : void UniformBlockBinding(WebGLProgram& program, GLuint uniformBlockIndex,
410 : GLuint uniformBlockBinding);
411 :
412 :
413 : // -------------------------------------------------------------------------
414 : // Vertex Array Object - WebGL2ContextVAOs.cpp
415 : // TODO(djg): Implemented in WebGLContext
416 : /*
417 : already_AddRefed<WebGLVertexArrayObject> CreateVertexArray();
418 : void DeleteVertexArray(WebGLVertexArrayObject* vertexArray);
419 : bool IsVertexArray(WebGLVertexArrayObject* vertexArray);
420 : void BindVertexArray(WebGLVertexArrayObject* vertexArray);
421 : */
422 :
423 : private:
424 : WebGL2Context();
425 : virtual UniquePtr<webgl::FormatUsageAuthority>
426 : CreateFormatUsage(gl::GLContext* gl) const override;
427 :
428 : virtual bool IsTexParamValid(GLenum pname) const override;
429 :
430 : void UpdateBoundQuery(GLenum target, WebGLQuery* query);
431 :
432 : // CreateVertexArrayImpl is assumed to be infallible.
433 : virtual WebGLVertexArray* CreateVertexArrayImpl() override;
434 : };
435 :
436 : } // namespace mozilla
437 :
438 : #endif
|