2013-07-25 17:38:58 -07: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 "WebGLContext.h"
|
2014-03-17 07:52:56 -07:00
|
|
|
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "mozilla/CheckedInt.h"
|
2013-07-25 17:38:58 -07:00
|
|
|
#include "WebGLBuffer.h"
|
|
|
|
#include "WebGLFramebuffer.h"
|
2013-08-06 17:05:51 -07:00
|
|
|
#include "WebGLProgram.h"
|
2014-03-17 07:52:56 -07:00
|
|
|
#include "WebGLRenderbuffer.h"
|
|
|
|
#include "WebGLShader.h"
|
|
|
|
#include "WebGLTexture.h"
|
|
|
|
#include "WebGLVertexArray.h"
|
|
|
|
#include "WebGLVertexAttribData.h"
|
2013-07-25 17:38:58 -07:00
|
|
|
|
2015-07-20 00:56:17 -07:00
|
|
|
#include "mozilla/Casting.h"
|
|
|
|
|
2015-07-14 17:37:28 -07:00
|
|
|
namespace mozilla {
|
2013-07-25 17:38:58 -07:00
|
|
|
|
2015-07-20 00:56:17 -07:00
|
|
|
void
|
|
|
|
WebGLContext::GetVertexAttribFloat(GLuint index, GLfloat* out_result)
|
|
|
|
{
|
|
|
|
if (index) {
|
|
|
|
gl->fGetVertexAttribfv(index, LOCAL_GL_CURRENT_VERTEX_ATTRIB, out_result);
|
|
|
|
} else {
|
|
|
|
out_result[0] = mVertexAttrib0Vector[0];
|
|
|
|
out_result[1] = mVertexAttrib0Vector[1];
|
|
|
|
out_result[2] = mVertexAttrib0Vector[2];
|
|
|
|
out_result[3] = mVertexAttrib0Vector[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::GetVertexAttribInt(GLuint index, GLint* out_result)
|
|
|
|
{
|
|
|
|
if (index) {
|
|
|
|
gl->fGetVertexAttribIiv(index, LOCAL_GL_CURRENT_VERTEX_ATTRIB, out_result);
|
|
|
|
} else {
|
|
|
|
out_result[0] = BitwiseCast<GLint>(mVertexAttrib0Vector[0]);
|
|
|
|
out_result[1] = BitwiseCast<GLint>(mVertexAttrib0Vector[1]);
|
|
|
|
out_result[2] = BitwiseCast<GLint>(mVertexAttrib0Vector[2]);
|
|
|
|
out_result[3] = BitwiseCast<GLint>(mVertexAttrib0Vector[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::GetVertexAttribUint(GLuint index, GLuint* out_result)
|
|
|
|
{
|
|
|
|
if (index) {
|
|
|
|
gl->fGetVertexAttribIuiv(index, LOCAL_GL_CURRENT_VERTEX_ATTRIB, out_result);
|
|
|
|
} else {
|
|
|
|
out_result[0] = BitwiseCast<GLuint>(mVertexAttrib0Vector[0]);
|
|
|
|
out_result[1] = BitwiseCast<GLuint>(mVertexAttrib0Vector[1]);
|
|
|
|
out_result[2] = BitwiseCast<GLuint>(mVertexAttrib0Vector[2]);
|
|
|
|
out_result[3] = BitwiseCast<GLuint>(mVertexAttrib0Vector[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
WebGLContext::GetVertexAttribFloat32Array(JSContext* cx, GLuint index)
|
|
|
|
{
|
|
|
|
GLfloat attrib[4];
|
|
|
|
GetVertexAttribFloat(index, &attrib[0]);
|
|
|
|
return dom::Float32Array::Create(cx, this, 4, attrib);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
WebGLContext::GetVertexAttribInt32Array(JSContext* cx, GLuint index)
|
|
|
|
{
|
|
|
|
GLint attrib[4];
|
|
|
|
GetVertexAttribInt(index, &attrib[0]);
|
|
|
|
return dom::Int32Array::Create(cx, this, 4, attrib);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
WebGLContext::GetVertexAttribUint32Array(JSContext* cx, GLuint index) {
|
|
|
|
GLuint attrib[4];
|
|
|
|
GetVertexAttribUint(index, &attrib[0]);
|
|
|
|
return dom::Uint32Array::Create(cx, this, 4, attrib);
|
|
|
|
}
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::VertexAttrib1f(GLuint index, GLfloat x0)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttrib1f"))
|
2014-10-23 15:10:57 -07:00
|
|
|
return;
|
|
|
|
|
2015-07-20 00:56:17 -07:00
|
|
|
mVertexAttribType[index] = LOCAL_GL_FLOAT;
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib1f(index, x0);
|
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = x0;
|
|
|
|
mVertexAttrib0Vector[1] = 0;
|
|
|
|
mVertexAttrib0Vector[2] = 0;
|
|
|
|
mVertexAttrib0Vector[3] = 1;
|
2014-03-31 02:10:49 -07:00
|
|
|
if (gl->IsGLES())
|
2013-08-06 17:05:51 -07:00
|
|
|
gl->fVertexAttrib1f(index, x0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::VertexAttrib2f(GLuint index, GLfloat x0, GLfloat x1)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttrib2f"))
|
2014-10-23 15:10:57 -07:00
|
|
|
return;
|
|
|
|
|
2015-07-20 00:56:17 -07:00
|
|
|
mVertexAttribType[index] = LOCAL_GL_FLOAT;
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib2f(index, x0, x1);
|
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = x0;
|
|
|
|
mVertexAttrib0Vector[1] = x1;
|
|
|
|
mVertexAttrib0Vector[2] = 0;
|
|
|
|
mVertexAttrib0Vector[3] = 1;
|
2014-03-31 02:10:49 -07:00
|
|
|
if (gl->IsGLES())
|
2013-08-06 17:05:51 -07:00
|
|
|
gl->fVertexAttrib2f(index, x0, x1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::VertexAttrib3f(GLuint index, GLfloat x0, GLfloat x1, GLfloat x2)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttrib3f"))
|
2014-10-23 15:10:57 -07:00
|
|
|
return;
|
|
|
|
|
2015-07-20 00:56:17 -07:00
|
|
|
mVertexAttribType[index] = LOCAL_GL_FLOAT;
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib3f(index, x0, x1, x2);
|
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = x0;
|
|
|
|
mVertexAttrib0Vector[1] = x1;
|
|
|
|
mVertexAttrib0Vector[2] = x2;
|
|
|
|
mVertexAttrib0Vector[3] = 1;
|
2014-03-31 02:10:49 -07:00
|
|
|
if (gl->IsGLES())
|
2013-08-06 17:05:51 -07:00
|
|
|
gl->fVertexAttrib3f(index, x0, x1, x2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::VertexAttrib4f(GLuint index, GLfloat x0, GLfloat x1,
|
|
|
|
GLfloat x2, GLfloat x3)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttrib4f"))
|
2014-10-23 15:10:57 -07:00
|
|
|
return;
|
|
|
|
|
2015-07-20 00:56:17 -07:00
|
|
|
mVertexAttribType[index] = LOCAL_GL_FLOAT;
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib4f(index, x0, x1, x2, x3);
|
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = x0;
|
|
|
|
mVertexAttrib0Vector[1] = x1;
|
|
|
|
mVertexAttrib0Vector[2] = x2;
|
|
|
|
mVertexAttrib0Vector[3] = x3;
|
2014-03-31 02:10:49 -07:00
|
|
|
if (gl->IsGLES())
|
2013-08-06 17:05:51 -07:00
|
|
|
gl->fVertexAttrib4f(index, x0, x1, x2, x3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2014-10-23 15:10:57 -07:00
|
|
|
WebGLContext::VertexAttrib1fv_base(GLuint index, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLfloat* ptr)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
|
|
|
if (!ValidateAttribArraySetter("VertexAttrib1fv", 1, arrayLength))
|
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttrib1fv"))
|
2014-10-23 15:10:57 -07:00
|
|
|
return;
|
|
|
|
|
2015-07-20 00:56:17 -07:00
|
|
|
mVertexAttribType[index] = LOCAL_GL_FLOAT;
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
MakeContextCurrent();
|
2014-10-23 15:10:57 -07:00
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib1fv(index, ptr);
|
2013-08-06 17:05:51 -07:00
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = ptr[0];
|
2013-09-04 05:14:43 -07:00
|
|
|
mVertexAttrib0Vector[1] = GLfloat(0);
|
|
|
|
mVertexAttrib0Vector[2] = GLfloat(0);
|
|
|
|
mVertexAttrib0Vector[3] = GLfloat(1);
|
2014-03-31 02:10:49 -07:00
|
|
|
if (gl->IsGLES())
|
2014-10-23 15:10:57 -07:00
|
|
|
gl->fVertexAttrib1fv(index, ptr);
|
2013-08-06 17:05:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-23 15:10:57 -07:00
|
|
|
WebGLContext::VertexAttrib2fv_base(GLuint index, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLfloat* ptr)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
|
|
|
if (!ValidateAttribArraySetter("VertexAttrib2fv", 2, arrayLength))
|
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttrib2fv"))
|
2014-10-23 15:10:57 -07:00
|
|
|
return;
|
|
|
|
|
2015-07-20 00:56:17 -07:00
|
|
|
mVertexAttribType[index] = LOCAL_GL_FLOAT;
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
MakeContextCurrent();
|
2014-10-23 15:10:57 -07:00
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib2fv(index, ptr);
|
2013-08-06 17:05:51 -07:00
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = ptr[0];
|
|
|
|
mVertexAttrib0Vector[1] = ptr[1];
|
2013-09-04 05:14:43 -07:00
|
|
|
mVertexAttrib0Vector[2] = GLfloat(0);
|
|
|
|
mVertexAttrib0Vector[3] = GLfloat(1);
|
2014-03-31 02:10:49 -07:00
|
|
|
if (gl->IsGLES())
|
2014-10-23 15:10:57 -07:00
|
|
|
gl->fVertexAttrib2fv(index, ptr);
|
2013-08-06 17:05:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-23 15:10:57 -07:00
|
|
|
WebGLContext::VertexAttrib3fv_base(GLuint index, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLfloat* ptr)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
|
|
|
if (!ValidateAttribArraySetter("VertexAttrib3fv", 3, arrayLength))
|
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttrib3fv"))
|
2014-10-23 15:10:57 -07:00
|
|
|
return;
|
|
|
|
|
2015-07-20 00:56:17 -07:00
|
|
|
mVertexAttribType[index] = LOCAL_GL_FLOAT;
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
MakeContextCurrent();
|
2014-10-23 15:10:57 -07:00
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib3fv(index, ptr);
|
2013-08-06 17:05:51 -07:00
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = ptr[0];
|
|
|
|
mVertexAttrib0Vector[1] = ptr[1];
|
|
|
|
mVertexAttrib0Vector[2] = ptr[2];
|
2013-09-04 05:14:43 -07:00
|
|
|
mVertexAttrib0Vector[3] = GLfloat(1);
|
2014-03-31 02:10:49 -07:00
|
|
|
if (gl->IsGLES())
|
2014-10-23 15:10:57 -07:00
|
|
|
gl->fVertexAttrib3fv(index, ptr);
|
2013-08-06 17:05:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-23 15:10:57 -07:00
|
|
|
WebGLContext::VertexAttrib4fv_base(GLuint index, uint32_t arrayLength,
|
2013-09-04 05:14:43 -07:00
|
|
|
const GLfloat* ptr)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
|
|
|
if (!ValidateAttribArraySetter("VertexAttrib4fv", 4, arrayLength))
|
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttrib4fv"))
|
2014-10-23 15:10:57 -07:00
|
|
|
return;
|
|
|
|
|
2015-07-20 00:56:17 -07:00
|
|
|
mVertexAttribType[index] = LOCAL_GL_FLOAT;
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
MakeContextCurrent();
|
2014-10-23 15:10:57 -07:00
|
|
|
if (index) {
|
|
|
|
gl->fVertexAttrib4fv(index, ptr);
|
2013-08-06 17:05:51 -07:00
|
|
|
} else {
|
|
|
|
mVertexAttrib0Vector[0] = ptr[0];
|
|
|
|
mVertexAttrib0Vector[1] = ptr[1];
|
|
|
|
mVertexAttrib0Vector[2] = ptr[2];
|
|
|
|
mVertexAttrib0Vector[3] = ptr[3];
|
2014-03-31 02:10:49 -07:00
|
|
|
if (gl->IsGLES())
|
2014-10-23 15:10:57 -07:00
|
|
|
gl->fVertexAttrib4fv(index, ptr);
|
2013-08-06 17:05:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::EnableVertexAttribArray(GLuint index)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "enableVertexAttribArray"))
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
InvalidateBufferFetching();
|
|
|
|
|
|
|
|
gl->fEnableVertexAttribArray(index);
|
2014-10-23 15:10:57 -07:00
|
|
|
|
|
|
|
MOZ_ASSERT(mBoundVertexArray);
|
|
|
|
mBoundVertexArray->EnsureAttrib(index);
|
2013-10-11 06:16:44 -07:00
|
|
|
mBoundVertexArray->mAttribs[index].enabled = true;
|
2013-08-06 17:05:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::DisableVertexAttribArray(GLuint index)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "disableVertexAttribArray"))
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
InvalidateBufferFetching();
|
|
|
|
|
2014-03-31 02:10:49 -07:00
|
|
|
if (index || gl->IsGLES())
|
2013-08-06 17:05:51 -07:00
|
|
|
gl->fDisableVertexAttribArray(index);
|
|
|
|
|
2014-10-23 15:10:57 -07:00
|
|
|
MOZ_ASSERT(mBoundVertexArray);
|
|
|
|
mBoundVertexArray->EnsureAttrib(index);
|
2013-10-11 06:16:44 -07:00
|
|
|
mBoundVertexArray->mAttribs[index].enabled = false;
|
2013-08-06 17:05:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
|
2013-08-06 17:05:51 -07:00
|
|
|
ErrorResult& rv)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-06 17:05:51 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "getVertexAttrib"))
|
2013-08-06 17:05:51 -07:00
|
|
|
return JS::NullValue();
|
|
|
|
|
2014-10-23 15:10:57 -07:00
|
|
|
MOZ_ASSERT(mBoundVertexArray);
|
|
|
|
mBoundVertexArray->EnsureAttrib(index);
|
|
|
|
|
2013-08-06 17:05:51 -07:00
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
switch (pname) {
|
2015-07-19 19:55:38 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
|
|
|
|
return WebGLObjectAsJSValue(cx, mBoundVertexArray->mAttribs[index].buf.get(), rv);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2015-07-19 19:55:38 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_STRIDE:
|
|
|
|
return JS::Int32Value(mBoundVertexArray->mAttribs[index].stride);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2015-07-19 19:55:38 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_SIZE:
|
|
|
|
if (!mBoundVertexArray->mAttribs[index].enabled)
|
|
|
|
return JS::Int32Value(4);
|
2013-09-19 15:30:19 -07:00
|
|
|
|
2015-07-19 19:55:38 -07:00
|
|
|
return JS::Int32Value(mBoundVertexArray->mAttribs[index].size);
|
2014-06-10 17:23:50 -07:00
|
|
|
|
2015-07-19 19:55:38 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_TYPE:
|
|
|
|
if (!mBoundVertexArray->mAttribs[index].enabled)
|
|
|
|
return JS::NumberValue(uint32_t(LOCAL_GL_FLOAT));
|
2014-06-10 17:23:50 -07:00
|
|
|
|
2015-07-19 19:55:38 -07:00
|
|
|
return JS::NumberValue(uint32_t(mBoundVertexArray->mAttribs[index].type));
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2016-01-21 17:44:01 -08:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_INTEGER:
|
|
|
|
if (IsWebGL2())
|
|
|
|
return JS::BooleanValue(mBoundVertexArray->mAttribs[index].integer);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2015-07-19 19:55:38 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
|
2015-11-24 20:15:29 -08:00
|
|
|
if (IsWebGL2() ||
|
|
|
|
IsExtensionEnabled(WebGLExtensionID::ANGLE_instanced_arrays))
|
|
|
|
{
|
2015-07-19 19:55:38 -07:00
|
|
|
return JS::Int32Value(mBoundVertexArray->mAttribs[index].divisor);
|
2015-11-24 20:15:29 -08:00
|
|
|
}
|
2015-07-19 19:55:38 -07:00
|
|
|
break;
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2015-07-19 19:55:38 -07:00
|
|
|
case LOCAL_GL_CURRENT_VERTEX_ATTRIB:
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
2015-07-20 00:56:17 -07:00
|
|
|
JS::RootedObject obj(cx);
|
|
|
|
switch (mVertexAttribType[index]) {
|
|
|
|
case LOCAL_GL_FLOAT:
|
|
|
|
obj = GetVertexAttribFloat32Array(cx, index);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_INT:
|
|
|
|
obj = GetVertexAttribInt32Array(cx, index);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOCAL_GL_UNSIGNED_INT:
|
|
|
|
obj = GetVertexAttribUint32Array(cx, index);
|
|
|
|
break;
|
2013-08-06 17:05:51 -07:00
|
|
|
}
|
2015-07-20 00:56:17 -07:00
|
|
|
|
|
|
|
if (!obj)
|
2013-08-06 17:05:51 -07:00
|
|
|
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return JS::ObjectOrNullValue(obj);
|
|
|
|
}
|
|
|
|
|
2015-07-19 19:55:38 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_ENABLED:
|
|
|
|
return JS::BooleanValue(mBoundVertexArray->mAttribs[index].enabled);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2015-07-19 19:55:38 -07:00
|
|
|
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
|
|
|
|
return JS::BooleanValue(mBoundVertexArray->mAttribs[index].normalized);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2015-07-19 19:55:38 -07:00
|
|
|
default:
|
|
|
|
break;
|
2013-08-06 17:05:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ErrorInvalidEnumInfo("getVertexAttrib: parameter", pname);
|
|
|
|
return JS::NullValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
WebGLsizeiptr
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::GetVertexAttribOffset(GLuint index, GLenum pname)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-06 17:05:51 -07:00
|
|
|
return 0;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "getVertexAttribOffset"))
|
2013-08-06 17:05:51 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (pname != LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER) {
|
|
|
|
ErrorInvalidEnum("getVertexAttribOffset: bad parameter");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-23 15:10:57 -07:00
|
|
|
MOZ_ASSERT(mBoundVertexArray);
|
|
|
|
mBoundVertexArray->EnsureAttrib(index);
|
2013-10-11 06:16:44 -07:00
|
|
|
return mBoundVertexArray->mAttribs[index].byteOffset;
|
2013-08-06 17:05:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::VertexAttribPointer(GLuint index, GLint size, GLenum type,
|
|
|
|
WebGLboolean normalized, GLsizei stride,
|
2013-08-06 17:05:51 -07:00
|
|
|
WebGLintptr byteOffset)
|
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttribPointer"))
|
2014-10-23 15:10:57 -07:00
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribPointer(false, index, size, type, normalized, stride, byteOffset, "vertexAttribPointer"))
|
|
|
|
return;
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2014-10-23 15:10:57 -07:00
|
|
|
MOZ_ASSERT(mBoundVertexArray);
|
|
|
|
mBoundVertexArray->EnsureAttrib(index);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
|
|
|
InvalidateBufferFetching();
|
|
|
|
|
|
|
|
/* XXX make work with bufferSubData & heterogeneous types
|
|
|
|
if (type != mBoundArrayBuffer->GLType())
|
|
|
|
return ErrorInvalidOperation("vertexAttribPointer: type must match bound VBO type: %d != %d", type, mBoundArrayBuffer->GLType());
|
|
|
|
*/
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[index];
|
2013-08-06 17:05:51 -07:00
|
|
|
|
|
|
|
vd.buf = mBoundArrayBuffer;
|
|
|
|
vd.stride = stride;
|
|
|
|
vd.size = size;
|
|
|
|
vd.byteOffset = byteOffset;
|
|
|
|
vd.type = type;
|
|
|
|
vd.normalized = normalized;
|
2014-06-23 17:56:21 -07:00
|
|
|
vd.integer = false;
|
2013-08-06 17:05:51 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
2014-06-23 17:56:21 -07:00
|
|
|
gl->fVertexAttribPointer(index, size, type, normalized, stride,
|
2013-08-06 17:05:51 -07:00
|
|
|
reinterpret_cast<void*>(byteOffset));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-04 05:14:43 -07:00
|
|
|
WebGLContext::VertexAttribDivisor(GLuint index, GLuint divisor)
|
2013-08-06 17:05:51 -07:00
|
|
|
{
|
2013-09-04 05:14:44 -07:00
|
|
|
if (IsContextLost())
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (!ValidateAttribIndex(index, "vertexAttribDivisor"))
|
2013-08-06 17:05:51 -07:00
|
|
|
return;
|
2014-10-23 15:10:57 -07:00
|
|
|
|
|
|
|
MOZ_ASSERT(mBoundVertexArray);
|
|
|
|
mBoundVertexArray->EnsureAttrib(index);
|
2013-08-06 17:05:51 -07:00
|
|
|
|
2013-10-11 06:16:44 -07:00
|
|
|
WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[index];
|
2013-08-06 17:05:51 -07:00
|
|
|
vd.divisor = divisor;
|
|
|
|
|
|
|
|
InvalidateBufferFetching();
|
|
|
|
|
|
|
|
MakeContextCurrent();
|
|
|
|
|
|
|
|
gl->fVertexAttribDivisor(index, divisor);
|
|
|
|
}
|
2015-07-14 17:37:28 -07:00
|
|
|
|
|
|
|
} // namespace mozilla
|