2014-09-18 02:08:41 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebGL2Context.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
|
2014-09-18 02:08:41 +04:00
|
|
|
#include "GLContext.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "mozilla/dom/WebGL2RenderingContextBinding.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-07-15 03:37:28 +03:00
|
|
|
#include "WebGLBuffer.h"
|
2014-12-16 08:20:15 +03:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
#include "WebGLProgram.h"
|
2016-07-14 22:13:47 +03:00
|
|
|
#include "WebGLUniformLocation.h"
|
2014-06-24 04:56:21 +04:00
|
|
|
#include "WebGLVertexArray.h"
|
|
|
|
#include "WebGLVertexAttribData.h"
|
2014-09-18 02:08:41 +04:00
|
|
|
|
2015-03-18 06:30:52 +03:00
|
|
|
namespace mozilla {
|
2014-09-18 02:08:41 +04:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
2015-07-20 06:51:59 +03:00
|
|
|
// Uniforms
|
2014-09-18 02:08:41 +04:00
|
|
|
|
|
|
|
void
|
2016-10-14 02:15:16 +03:00
|
|
|
WebGLContext::Uniform1ui(WebGLUniformLocation* loc, GLuint v0)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
if (!ValidateUniformSetter(loc, 1, LOCAL_GL_UNSIGNED_INT, "uniform1ui"))
|
2015-03-23 05:13:10 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform1ui(loc->mLoc, v0);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-14 02:15:16 +03:00
|
|
|
WebGLContext::Uniform2ui(WebGLUniformLocation* loc, GLuint v0, GLuint v1)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
if (!ValidateUniformSetter(loc, 2, LOCAL_GL_UNSIGNED_INT, "uniform2ui"))
|
2015-03-23 05:13:10 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform2ui(loc->mLoc, v0, v1);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-14 02:15:16 +03:00
|
|
|
WebGLContext::Uniform3ui(WebGLUniformLocation* loc, GLuint v0, GLuint v1, GLuint v2)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
if (!ValidateUniformSetter(loc, 3, LOCAL_GL_UNSIGNED_INT, "uniform3ui"))
|
2015-03-23 05:13:10 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform3ui(loc->mLoc, v0, v1, v2);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-14 02:15:16 +03:00
|
|
|
WebGLContext::Uniform4ui(WebGLUniformLocation* loc, GLuint v0, GLuint v1, GLuint v2,
|
|
|
|
GLuint v3)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2016-07-14 22:13:47 +03:00
|
|
|
if (!ValidateUniformSetter(loc, 4, LOCAL_GL_UNSIGNED_INT, "uniform4ui"))
|
2015-03-23 05:13:10 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
2016-07-14 22:13:47 +03:00
|
|
|
gl->fUniform4ui(loc->mLoc, v0, v1, v2, v3);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Uniform Buffer Objects and Transform Feedback Buffers
|
2016-09-10 07:02:54 +03:00
|
|
|
|
2014-09-18 02:08:41 +04:00
|
|
|
void
|
2016-10-15 01:59:27 +03:00
|
|
|
WebGL2Context::GetIndexedParameter(JSContext* cx, GLenum target, GLuint index,
|
|
|
|
JS::MutableHandleValue retval, ErrorResult& out_error)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2016-09-10 07:02:54 +03:00
|
|
|
const char funcName[] = "getIndexedParameter";
|
2016-10-15 01:59:27 +03:00
|
|
|
retval.set(JS::NullValue());
|
2014-12-16 08:20:15 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
const std::vector<IndexedBufferBinding>* bindings;
|
2014-12-16 08:20:15 +03:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
|
2016-09-10 07:02:54 +03:00
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
|
|
|
|
bindings = &(mBoundTransformFeedback->mIndexedBindings);
|
|
|
|
break;
|
2014-12-16 08:20:15 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER_BINDING:
|
2016-09-10 07:02:54 +03:00
|
|
|
case LOCAL_GL_UNIFORM_BUFFER_START:
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER_SIZE:
|
|
|
|
bindings = &mIndexedUniformBufferBindings;
|
|
|
|
break;
|
2014-12-16 08:20:15 +03:00
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
default:
|
|
|
|
ErrorInvalidEnumInfo("getIndexedParameter: target", target);
|
2014-12-16 08:20:15 +03:00
|
|
|
return;
|
2016-09-10 07:02:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (index >= bindings->size()) {
|
|
|
|
ErrorInvalidValue("%s: `index` must be < %s.", funcName,
|
|
|
|
"MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto& binding = (*bindings)[index];
|
|
|
|
|
2016-10-15 01:59:27 +03:00
|
|
|
JS::Value ret = JS::NullValue();
|
|
|
|
|
2016-09-10 07:02:54 +03:00
|
|
|
switch (target) {
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER_BINDING:
|
|
|
|
if (binding.mBufferBinding) {
|
2016-10-15 01:59:27 +03:00
|
|
|
ret = WebGLObjectAsJSValue(cx, binding.mBufferBinding.get(), out_error);
|
2016-09-10 07:02:54 +03:00
|
|
|
}
|
|
|
|
break;
|
2014-12-16 08:20:15 +03:00
|
|
|
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_START:
|
|
|
|
case LOCAL_GL_UNIFORM_BUFFER_START:
|
2016-10-15 01:59:27 +03:00
|
|
|
ret = JS::NumberValue(binding.mRangeStart);
|
2016-09-10 07:02:54 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
|
2014-12-16 08:20:15 +03:00
|
|
|
case LOCAL_GL_UNIFORM_BUFFER_SIZE:
|
2016-10-15 01:59:27 +03:00
|
|
|
ret = JS::NumberValue(binding.mRangeSize);
|
2016-09-10 07:02:54 +03:00
|
|
|
break;
|
2014-12-16 08:20:15 +03:00
|
|
|
}
|
2016-10-15 01:59:27 +03:00
|
|
|
|
|
|
|
retval.set(ret);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGL2Context::GetUniformIndices(const WebGLProgram& program,
|
2014-09-18 02:08:41 +04:00
|
|
|
const dom::Sequence<nsString>& uniformNames,
|
|
|
|
dom::Nullable< nsTArray<GLuint> >& retval)
|
|
|
|
{
|
2014-12-16 08:20:15 +03:00
|
|
|
retval.SetNull();
|
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getUniformIndices: program", program))
|
2014-12-16 08:20:15 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!uniformNames.Length())
|
|
|
|
return;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
program.GetUniformIndices(uniformNames, retval);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
2016-02-15 17:14:00 +03:00
|
|
|
static bool
|
|
|
|
ValidateUniformEnum(WebGLContext* webgl, GLenum pname, const char* info)
|
|
|
|
{
|
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_UNIFORM_TYPE:
|
|
|
|
case LOCAL_GL_UNIFORM_SIZE:
|
|
|
|
case LOCAL_GL_UNIFORM_BLOCK_INDEX:
|
|
|
|
case LOCAL_GL_UNIFORM_OFFSET:
|
|
|
|
case LOCAL_GL_UNIFORM_ARRAY_STRIDE:
|
|
|
|
case LOCAL_GL_UNIFORM_MATRIX_STRIDE:
|
|
|
|
case LOCAL_GL_UNIFORM_IS_ROW_MAJOR:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2016-12-22 06:42:07 +03:00
|
|
|
webgl->ErrorInvalidEnumArg(info, "pname", pname);
|
2016-02-15 17:14:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-18 02:08:41 +04:00
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGL2Context::GetActiveUniforms(JSContext* cx, const WebGLProgram& program,
|
2014-09-18 02:08:41 +04:00
|
|
|
const dom::Sequence<GLuint>& uniformIndices,
|
2016-11-02 00:58:07 +03:00
|
|
|
GLenum pname, JS::MutableHandleValue retval)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2016-11-02 00:58:07 +03:00
|
|
|
const char funcName[] = "getActiveUniforms";
|
|
|
|
retval.setNull();
|
2014-12-16 08:20:15 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
if (!ValidateUniformEnum(this, pname, funcName))
|
2015-12-01 05:16:12 +03:00
|
|
|
return;
|
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getActiveUniforms: program", program))
|
2014-12-16 08:20:15 +03:00
|
|
|
return;
|
|
|
|
|
2016-12-20 10:47:55 +03:00
|
|
|
const auto& numActiveUniforms = program.LinkInfo()->uniforms.size();
|
|
|
|
for (const auto& curIndex : uniformIndices) {
|
|
|
|
if (curIndex >= numActiveUniforms) {
|
|
|
|
ErrorInvalidValue("%s: Too-large active uniform index queried.", funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
const auto& count = uniformIndices.Length();
|
2014-12-16 08:20:15 +03:00
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
JS::Rooted<JSObject*> array(cx, JS_NewArrayObject(cx, count));
|
|
|
|
UniquePtr<GLint[]> samples(new GLint[count]);
|
|
|
|
if (!array || !samples) {
|
|
|
|
ErrorOutOfMemory("%s: Failed to allocate buffers.", funcName);
|
2016-02-15 17:14:00 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-11-02 00:58:07 +03:00
|
|
|
retval.setObject(*array);
|
2014-12-16 08:20:15 +03:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
2016-11-02 00:58:07 +03:00
|
|
|
gl->fGetActiveUniformsiv(program.mGLName, count, uniformIndices.Elements(), pname,
|
|
|
|
samples.get());
|
2016-02-15 17:14:00 +03:00
|
|
|
|
|
|
|
switch (pname) {
|
|
|
|
case LOCAL_GL_UNIFORM_TYPE:
|
|
|
|
case LOCAL_GL_UNIFORM_SIZE:
|
|
|
|
case LOCAL_GL_UNIFORM_BLOCK_INDEX:
|
|
|
|
case LOCAL_GL_UNIFORM_OFFSET:
|
|
|
|
case LOCAL_GL_UNIFORM_ARRAY_STRIDE:
|
|
|
|
case LOCAL_GL_UNIFORM_MATRIX_STRIDE:
|
2016-11-02 00:58:07 +03:00
|
|
|
for (size_t i = 0; i < count; ++i) {
|
2016-02-15 17:14:00 +03:00
|
|
|
JS::RootedValue value(cx);
|
|
|
|
value = JS::Int32Value(samples[i]);
|
2016-11-02 00:58:07 +03:00
|
|
|
if (!JS_DefineElement(cx, array, i, value, JSPROP_ENUMERATE))
|
2016-02-15 17:14:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOCAL_GL_UNIFORM_IS_ROW_MAJOR:
|
2016-11-02 00:58:07 +03:00
|
|
|
for (size_t i = 0; i < count; ++i) {
|
2016-02-15 17:14:00 +03:00
|
|
|
JS::RootedValue value(cx);
|
|
|
|
value = JS::BooleanValue(samples[i]);
|
2016-11-02 00:58:07 +03:00
|
|
|
if (!JS_DefineElement(cx, array, i, value, JSPROP_ENUMERATE))
|
2016-02-15 17:14:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-11-02 00:58:07 +03:00
|
|
|
MOZ_CRASH("Invalid pname");
|
2016-02-15 17:14:00 +03:00
|
|
|
}
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
GLuint
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGL2Context::GetUniformBlockIndex(const WebGLProgram& program,
|
2014-12-16 08:20:15 +03:00
|
|
|
const nsAString& uniformBlockName)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2014-12-16 08:20:15 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return 0;
|
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getUniformBlockIndex: program", program))
|
2014-12-16 08:20:15 +03:00
|
|
|
return 0;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
return program.GetUniformBlockIndex(uniformBlockName);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGL2Context::GetActiveUniformBlockParameter(JSContext* cx, const WebGLProgram& program,
|
2014-09-18 02:08:41 +04:00
|
|
|
GLuint uniformBlockIndex, GLenum pname,
|
2016-10-15 01:59:27 +03:00
|
|
|
JS::MutableHandleValue out_retval,
|
|
|
|
ErrorResult& out_error)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2016-11-02 00:58:07 +03:00
|
|
|
out_retval.setNull();
|
2014-12-16 08:20:15 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getActiveUniformBlockParameter: program", program))
|
2014-12-16 08:20:15 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
switch(pname) {
|
|
|
|
case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
|
|
|
|
case LOCAL_GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
|
|
|
|
case LOCAL_GL_UNIFORM_BLOCK_BINDING:
|
|
|
|
case LOCAL_GL_UNIFORM_BLOCK_DATA_SIZE:
|
|
|
|
case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
|
2016-11-02 00:58:07 +03:00
|
|
|
out_retval.set(program.GetActiveUniformBlockParam(uniformBlockIndex, pname));
|
2014-12-16 08:20:15 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
|
2016-11-02 00:58:07 +03:00
|
|
|
out_retval.set(program.GetActiveUniformBlockActiveUniforms(cx, uniformBlockIndex,
|
|
|
|
&out_error));
|
2014-12-16 08:20:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorInvalidEnumInfo("getActiveUniformBlockParameter: parameter", pname);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGL2Context::GetActiveUniformBlockName(const WebGLProgram& program,
|
|
|
|
GLuint uniformBlockIndex, nsAString& retval)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2016-07-29 01:21:00 +03:00
|
|
|
retval.SetIsVoid(true);
|
2014-12-16 08:20:15 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("getActiveUniformBlockName: program", program))
|
2014-12-16 08:20:15 +03:00
|
|
|
return;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
program.GetActiveUniformBlockName(uniformBlockIndex, retval);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-02 00:58:07 +03:00
|
|
|
WebGL2Context::UniformBlockBinding(WebGLProgram& program, GLuint uniformBlockIndex,
|
2014-12-16 08:20:15 +03:00
|
|
|
GLuint uniformBlockBinding)
|
2014-09-18 02:08:41 +04:00
|
|
|
{
|
2014-12-16 08:20:15 +03:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
2016-11-30 05:30:28 +03:00
|
|
|
if (!ValidateObject("uniformBlockBinding: program", program))
|
2014-12-16 08:20:15 +03:00
|
|
|
return;
|
|
|
|
|
2016-11-02 00:58:07 +03:00
|
|
|
program.UniformBlockBinding(uniformBlockIndex, uniformBlockBinding);
|
2014-09-18 02:08:41 +04:00
|
|
|
}
|
2015-03-18 06:30:52 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|