content/canvas/src/WebGLContextVertexArray.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:3fdeacccda37
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 #include "WebGLBuffer.h"
8 #include "WebGLVertexAttribData.h"
9 #include "WebGLVertexArray.h"
10 #include "GLContext.h"
11
12 using namespace mozilla;
13
14 void
15 WebGLContext::BindVertexArray(WebGLVertexArray *array)
16 {
17 if (IsContextLost())
18 return;
19
20 if (!ValidateObjectAllowDeletedOrNull("bindVertexArrayObject", array))
21 return;
22
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
29 */
30 ErrorInvalidOperation("bindVertexArray: can't bind a deleted array!");
31 return;
32 }
33
34 InvalidateBufferFetching();
35
36 MakeContextCurrent();
37
38 if (array) {
39 gl->fBindVertexArray(array->GLName());
40 array->SetHasEverBeenBound(true);
41 mBoundVertexArray = array;
42 }
43 else {
44 gl->fBindVertexArray(0);
45 mBoundVertexArray = mDefaultVertexArray;
46 }
47 }
48
49 already_AddRefed<WebGLVertexArray>
50 WebGLContext::CreateVertexArray()
51 {
52 if (IsContextLost())
53 return nullptr;
54
55 nsRefPtr<WebGLVertexArray> globj = new WebGLVertexArray(this);
56
57 MakeContextCurrent();
58 gl->fGenVertexArrays(1, &globj->mGLName);
59
60 mVertexArrays.insertBack(globj);
61
62 return globj.forget();
63 }
64
65 void
66 WebGLContext::DeleteVertexArray(WebGLVertexArray *array)
67 {
68 if (IsContextLost())
69 return;
70
71 if (array == nullptr)
72 return;
73
74 if (array->IsDeleted())
75 return;
76
77 if (mBoundVertexArray == array)
78 BindVertexArray(static_cast<WebGLVertexArray*>(nullptr));
79
80 array->RequestDelete();
81 }
82
83 bool
84 WebGLContext::IsVertexArray(WebGLVertexArray *array)
85 {
86 if (IsContextLost())
87 return false;
88
89 if (!array)
90 return false;
91
92 return ValidateObjectAllowDeleted("isVertexArray", array) &&
93 !array->IsDeleted() &&
94 array->HasEverBeenBound();
95 }
96
97

mercurial