2014-06-05 16:38:27 -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 "WebGLVertexArrayFake.h"
|
|
|
|
|
|
|
|
#include "GLContext.h"
|
2014-11-13 20:03:50 -08:00
|
|
|
#include "WebGLContext.h"
|
2014-06-05 16:38:27 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLVertexArrayFake::BindVertexArrayImpl()
|
|
|
|
{
|
|
|
|
// Go through and re-bind all buffers and setup all
|
|
|
|
// vertex attribute pointers
|
|
|
|
gl::GLContext* gl = mContext->gl;
|
|
|
|
|
2014-06-10 17:23:50 -07:00
|
|
|
WebGLRefPtr<WebGLVertexArray> prevVertexArray = mContext->mBoundVertexArray;
|
|
|
|
|
|
|
|
mContext->mBoundVertexArray = this;
|
|
|
|
|
2014-06-05 16:38:27 -07:00
|
|
|
WebGLRefPtr<WebGLBuffer> prevBuffer = mContext->mBoundArrayBuffer;
|
|
|
|
mContext->BindBuffer(LOCAL_GL_ELEMENT_ARRAY_BUFFER, mElementArrayBuffer);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < mAttribs.Length(); ++i) {
|
|
|
|
const WebGLVertexAttribData& vd = mAttribs[i];
|
|
|
|
|
|
|
|
mContext->BindBuffer(LOCAL_GL_ARRAY_BUFFER, vd.buf);
|
|
|
|
|
2014-06-23 17:56:21 -07:00
|
|
|
if (vd.integer) {
|
|
|
|
gl->fVertexAttribIPointer(i, vd.size, vd.type, vd.stride,
|
|
|
|
reinterpret_cast<const GLvoid*>(vd.byteOffset));
|
|
|
|
} else {
|
|
|
|
gl->fVertexAttribPointer(i, vd.size, vd.type, vd.normalized, vd.stride,
|
|
|
|
reinterpret_cast<const GLvoid*>(vd.byteOffset));
|
|
|
|
}
|
2014-06-05 16:38:27 -07:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
if (vd.enabled)
|
2014-06-05 16:38:27 -07:00
|
|
|
gl->fEnableVertexAttribArray(i);
|
2014-11-13 20:03:50 -08:00
|
|
|
else
|
2014-06-05 16:38:27 -07:00
|
|
|
gl->fDisableVertexAttribArray(i);
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
size_t len = prevVertexArray->mAttribs.Length();
|
|
|
|
for (size_t i = mAttribs.Length(); i < len; ++i) {
|
2014-06-10 17:23:50 -07:00
|
|
|
const WebGLVertexAttribData& vd = prevVertexArray->mAttribs[i];
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
if (vd.enabled)
|
2014-06-10 17:23:50 -07:00
|
|
|
gl->fDisableVertexAttribArray(i);
|
|
|
|
}
|
|
|
|
|
2014-06-05 16:38:27 -07:00
|
|
|
mContext->BindBuffer(LOCAL_GL_ARRAY_BUFFER, prevBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|