2014-06-06 03:38:27 +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 "WebGLVertexArrayFake.h"
|
|
|
|
|
|
|
|
#include "GLContext.h"
|
2014-11-14 07:03:50 +03:00
|
|
|
#include "WebGLContext.h"
|
2014-06-06 03:38:27 +04: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-11 04:23:50 +04:00
|
|
|
WebGLRefPtr<WebGLVertexArray> prevVertexArray = mContext->mBoundVertexArray;
|
|
|
|
|
|
|
|
mContext->mBoundVertexArray = this;
|
|
|
|
|
2014-06-06 03:38:27 +04: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-24 04:56:21 +04: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-06 03:38:27 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
if (vd.enabled)
|
2014-06-06 03:38:27 +04:00
|
|
|
gl->fEnableVertexAttribArray(i);
|
2014-11-14 07:03:50 +03:00
|
|
|
else
|
2014-06-06 03:38:27 +04:00
|
|
|
gl->fDisableVertexAttribArray(i);
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
size_t len = prevVertexArray->mAttribs.Length();
|
|
|
|
for (size_t i = mAttribs.Length(); i < len; ++i) {
|
2014-06-11 04:23:50 +04:00
|
|
|
const WebGLVertexAttribData& vd = prevVertexArray->mAttribs[i];
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
if (vd.enabled)
|
2014-06-11 04:23:50 +04:00
|
|
|
gl->fDisableVertexAttribArray(i);
|
|
|
|
}
|
|
|
|
|
2014-06-06 03:38:27 +04:00
|
|
|
mContext->BindBuffer(LOCAL_GL_ARRAY_BUFFER, prevBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|