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 {
|
|
|
|
|
2015-05-21 02:58:36 +03:00
|
|
|
WebGLVertexArrayFake::WebGLVertexArrayFake(WebGLContext* webgl)
|
|
|
|
: WebGLVertexArray(webgl)
|
|
|
|
, mIsVAO(false)
|
|
|
|
{ }
|
|
|
|
|
2014-06-06 03:38:27 +04:00
|
|
|
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);
|
|
|
|
|
2016-09-24 03:28:58 +03:00
|
|
|
size_t i = 0;
|
|
|
|
for (const auto& vd : mAttribs) {
|
|
|
|
mContext->BindBuffer(LOCAL_GL_ARRAY_BUFFER, vd.mBuf);
|
|
|
|
vd.DoVertexAttribPointer(gl, i);
|
2014-06-06 03:38:27 +04:00
|
|
|
|
2016-09-24 03:28:58 +03:00
|
|
|
if (vd.mEnabled) {
|
2014-06-06 03:38:27 +04:00
|
|
|
gl->fEnableVertexAttribArray(i);
|
2016-09-24 03:28:58 +03:00
|
|
|
} else {
|
2014-06-06 03:38:27 +04:00
|
|
|
gl->fDisableVertexAttribArray(i);
|
2016-09-24 03:28:58 +03:00
|
|
|
}
|
|
|
|
++i;
|
2014-06-06 03:38:27 +04:00
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
size_t len = prevVertexArray->mAttribs.Length();
|
2016-09-24 03:28:58 +03:00
|
|
|
for (; i < len; ++i) {
|
|
|
|
const auto& vd = prevVertexArray->mAttribs[i];
|
2014-06-11 04:23:50 +04:00
|
|
|
|
2016-09-24 03:28:58 +03:00
|
|
|
if (vd.mEnabled) {
|
2014-06-11 04:23:50 +04:00
|
|
|
gl->fDisableVertexAttribArray(i);
|
2016-09-24 03:28:58 +03:00
|
|
|
}
|
2014-06-11 04:23:50 +04:00
|
|
|
}
|
|
|
|
|
2014-06-06 03:38:27 +04:00
|
|
|
mContext->BindBuffer(LOCAL_GL_ARRAY_BUFFER, prevBuffer);
|
2015-05-21 02:58:36 +03:00
|
|
|
mIsVAO = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLVertexArrayFake::DeleteImpl()
|
|
|
|
{
|
|
|
|
mIsVAO = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-11-30 05:30:28 +03:00
|
|
|
WebGLVertexArrayFake::IsVertexArrayImpl() const
|
2015-05-21 02:58:36 +03:00
|
|
|
{
|
|
|
|
return mIsVAO;
|
2014-06-06 03:38:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|