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 "WebGLContext.h"
7 :
8 : #include "GLContext.h"
9 : #include "WebGLBuffer.h"
10 : #include "WebGLVertexArray.h"
11 : #include "WebGLVertexAttribData.h"
12 :
13 : namespace mozilla {
14 :
15 : void
16 0 : WebGLContext::BindVertexArray(WebGLVertexArray* array)
17 : {
18 0 : if (IsContextLost())
19 0 : return;
20 :
21 0 : if (array && !ValidateObject("bindVertexArrayObject", *array))
22 0 : return;
23 :
24 0 : InvalidateBufferFetching();
25 :
26 0 : MakeContextCurrent();
27 :
28 0 : if (mBoundVertexArray) {
29 0 : mBoundVertexArray->AddBufferBindCounts(-1);
30 : }
31 :
32 0 : if (array == nullptr) {
33 0 : array = mDefaultVertexArray;
34 : }
35 :
36 0 : array->BindVertexArray();
37 :
38 0 : MOZ_ASSERT(mBoundVertexArray == array);
39 0 : if (mBoundVertexArray) {
40 0 : mBoundVertexArray->AddBufferBindCounts(+1);
41 : }
42 : }
43 :
44 : already_AddRefed<WebGLVertexArray>
45 0 : WebGLContext::CreateVertexArray()
46 : {
47 0 : if (IsContextLost())
48 0 : return nullptr;
49 :
50 0 : RefPtr<WebGLVertexArray> globj = CreateVertexArrayImpl();
51 :
52 0 : MakeContextCurrent();
53 0 : globj->GenVertexArray();
54 :
55 0 : return globj.forget();
56 : }
57 :
58 : WebGLVertexArray*
59 0 : WebGLContext::CreateVertexArrayImpl()
60 : {
61 0 : return WebGLVertexArray::Create(this);
62 : }
63 :
64 : void
65 0 : WebGLContext::DeleteVertexArray(WebGLVertexArray* array)
66 : {
67 0 : if (!ValidateDeleteObject("deleteVertexArray", array))
68 0 : return;
69 :
70 0 : if (mBoundVertexArray == array)
71 0 : BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));
72 :
73 0 : array->RequestDelete();
74 : }
75 :
76 : bool
77 0 : WebGLContext::IsVertexArray(const WebGLVertexArray* array)
78 : {
79 0 : if (!ValidateIsObject("isVertexArray", array))
80 0 : return false;
81 :
82 0 : MakeContextCurrent();
83 0 : return array->IsVertexArray();
84 : }
85 :
86 : } // namespace mozilla
|