Bumping manifests a=b2g-bump
[gecko.git] / dom / canvas / WebGLContextVertexArray.cpp
blob5e90abf754ace8dfceff675ee02b4b244f6852d4
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/. */
6 #include "WebGLContext.h"
8 #include "GLContext.h"
9 #include "WebGLBuffer.h"
10 #include "WebGLVertexArray.h"
11 #include "WebGLVertexAttribData.h"
13 namespace mozilla {
15 void
16 WebGLContext::BindVertexArray(WebGLVertexArray* array)
18 if (IsContextLost())
19 return;
21 if (!ValidateObjectAllowDeletedOrNull("bindVertexArrayObject", array))
22 return;
24 if (array && array->IsDeleted()) {
25 /* http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt
26 * BindVertexArrayOES fails and an INVALID_OPERATION error is
27 * generated if array is not a name returned from a previous call to
28 * GenVertexArraysOES, or if such a name has since been deleted with
29 * DeleteVertexArraysOES
31 ErrorInvalidOperation("bindVertexArray: can't bind a deleted array!");
32 return;
35 InvalidateBufferFetching();
37 MakeContextCurrent();
39 if (array == nullptr) {
40 array = mDefaultVertexArray;
43 array->BindVertexArray();
45 MOZ_ASSERT(mBoundVertexArray == array);
48 already_AddRefed<WebGLVertexArray>
49 WebGLContext::CreateVertexArray()
51 if (IsContextLost())
52 return nullptr;
54 nsRefPtr<WebGLVertexArray> globj = WebGLVertexArray::Create(this);
56 MakeContextCurrent();
57 globj->GenVertexArray();
59 return globj.forget();
62 void
63 WebGLContext::DeleteVertexArray(WebGLVertexArray* array)
65 if (IsContextLost())
66 return;
68 if (array == nullptr)
69 return;
71 if (array->IsDeleted())
72 return;
74 if (mBoundVertexArray == array)
75 BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));
77 array->RequestDelete();
80 bool
81 WebGLContext::IsVertexArray(WebGLVertexArray* array)
83 if (IsContextLost())
84 return false;
86 if (!array)
87 return false;
89 return ValidateObjectAllowDeleted("isVertexArray", array) &&
90 !array->IsDeleted() &&
91 array->HasEverBeenBound();
94 } // namespace mozilla