Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "WebGLVertexArrayFake.h"
7 :
8 : #include "GLContext.h"
9 : #include "WebGLContext.h"
10 :
11 : namespace mozilla {
12 :
13 0 : WebGLVertexArrayFake::WebGLVertexArrayFake(WebGLContext* webgl)
14 : : WebGLVertexArray(webgl)
15 0 : , mIsVAO(false)
16 0 : { }
17 :
18 : void
19 0 : WebGLVertexArrayFake::BindVertexArrayImpl()
20 : {
21 : // Go through and re-bind all buffers and setup all
22 : // vertex attribute pointers
23 0 : gl::GLContext* gl = mContext->gl;
24 :
25 0 : WebGLRefPtr<WebGLVertexArray> prevVertexArray = mContext->mBoundVertexArray;
26 :
27 0 : mContext->mBoundVertexArray = this;
28 :
29 0 : WebGLRefPtr<WebGLBuffer> prevBuffer = mContext->mBoundArrayBuffer;
30 0 : mContext->BindBuffer(LOCAL_GL_ELEMENT_ARRAY_BUFFER, mElementArrayBuffer);
31 :
32 0 : size_t i = 0;
33 0 : for (const auto& vd : mAttribs) {
34 0 : mContext->BindBuffer(LOCAL_GL_ARRAY_BUFFER, vd.mBuf);
35 0 : vd.DoVertexAttribPointer(gl, i);
36 :
37 0 : if (vd.mEnabled) {
38 0 : gl->fEnableVertexAttribArray(i);
39 : } else {
40 0 : gl->fDisableVertexAttribArray(i);
41 : }
42 0 : ++i;
43 : }
44 :
45 0 : size_t len = prevVertexArray->mAttribs.Length();
46 0 : for (; i < len; ++i) {
47 0 : const auto& vd = prevVertexArray->mAttribs[i];
48 :
49 0 : if (vd.mEnabled) {
50 0 : gl->fDisableVertexAttribArray(i);
51 : }
52 : }
53 :
54 0 : mContext->BindBuffer(LOCAL_GL_ARRAY_BUFFER, prevBuffer);
55 0 : mIsVAO = true;
56 0 : }
57 :
58 : void
59 0 : WebGLVertexArrayFake::DeleteImpl()
60 : {
61 0 : mIsVAO = false;
62 0 : }
63 :
64 : bool
65 0 : WebGLVertexArrayFake::IsVertexArrayImpl() const
66 : {
67 0 : return mIsVAO;
68 : }
69 :
70 9 : } // namespace mozilla
|