Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
[gecko.git] / dom / canvas / WebGLContextVertexArray.cpp
blobb4ece82b8ea99eedb02ba1c96812dbf9b7057049
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"
7 #include "WebGLBuffer.h"
8 #include "WebGLVertexAttribData.h"
9 #include "WebGLVertexArray.h"
10 #include "GLContext.h"
12 using namespace mozilla;
14 void
15 WebGLContext::BindVertexArray(WebGLVertexArray *array)
17 if (IsContextLost())
18 return;
20 if (!ValidateObjectAllowDeletedOrNull("bindVertexArrayObject", array))
21 return;
23 if (array && array->IsDeleted()) {
24 /* http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt
25 * BindVertexArrayOES fails and an INVALID_OPERATION error is
26 * generated if array is not a name returned from a previous call to
27 * GenVertexArraysOES, or if such a name has since been deleted with
28 * DeleteVertexArraysOES
30 ErrorInvalidOperation("bindVertexArray: can't bind a deleted array!");
31 return;
34 InvalidateBufferFetching();
36 MakeContextCurrent();
38 if (array == nullptr) {
39 array = mDefaultVertexArray;
42 array->BindVertexArray();
44 MOZ_ASSERT(mBoundVertexArray == array);
47 already_AddRefed<WebGLVertexArray>
48 WebGLContext::CreateVertexArray()
50 if (IsContextLost())
51 return nullptr;
53 nsRefPtr<WebGLVertexArray> globj = WebGLVertexArray::Create(this);
55 MakeContextCurrent();
56 globj->GenVertexArray();
58 return globj.forget();
61 void
62 WebGLContext::DeleteVertexArray(WebGLVertexArray *array)
64 if (IsContextLost())
65 return;
67 if (array == nullptr)
68 return;
70 if (array->IsDeleted())
71 return;
73 if (mBoundVertexArray == array)
74 BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));
76 array->RequestDelete();
79 bool
80 WebGLContext::IsVertexArray(WebGLVertexArray *array)
82 if (IsContextLost())
83 return false;
85 if (!array)
86 return false;
88 return ValidateObjectAllowDeleted("isVertexArray", array) &&
89 !array->IsDeleted() &&
90 array->HasEverBeenBound();