1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "third_party/blink/renderer/modules/webgl/oes_vertex_array_object.h"
27
28 #include "gpu/command_buffer/client/gles2_interface.h"
29 #include "third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h"
30 #include "third_party/blink/renderer/modules/webgl/webgl_vertex_array_object_oes.h"
31 #include "third_party/blink/renderer/platform/bindings/exception_state.h"
32 #include "third_party/blink/renderer/platform/heap/heap.h"
33
34 namespace blink {
35
OESVertexArrayObject(WebGLRenderingContextBase * context)36 OESVertexArrayObject::OESVertexArrayObject(WebGLRenderingContextBase* context)
37 : WebGLExtension(context) {
38 context->ExtensionsUtil()->EnsureExtensionEnabled(
39 "GL_OES_vertex_array_object");
40 }
41
GetName() const42 WebGLExtensionName OESVertexArrayObject::GetName() const {
43 return kOESVertexArrayObjectName;
44 }
45
createVertexArrayOES()46 WebGLVertexArrayObjectOES* OESVertexArrayObject::createVertexArrayOES() {
47 WebGLExtensionScopedContext scoped(this);
48 if (scoped.IsLost())
49 return nullptr;
50
51 return MakeGarbageCollected<WebGLVertexArrayObjectOES>(
52 scoped.Context(), WebGLVertexArrayObjectOES::kVaoTypeUser);
53 }
54
deleteVertexArrayOES(WebGLVertexArrayObjectOES * array_object)55 void OESVertexArrayObject::deleteVertexArrayOES(
56 WebGLVertexArrayObjectOES* array_object) {
57 WebGLExtensionScopedContext scoped(this);
58 if (!array_object || scoped.IsLost())
59 return;
60
61 if (!array_object->IsDefaultObject() &&
62 array_object == scoped.Context()->bound_vertex_array_object_)
63 scoped.Context()->SetBoundVertexArrayObject(nullptr);
64
65 array_object->DeleteObject(scoped.Context()->ContextGL());
66 }
67
isVertexArrayOES(WebGLVertexArrayObjectOES * array_object)68 GLboolean OESVertexArrayObject::isVertexArrayOES(
69 WebGLVertexArrayObjectOES* array_object) {
70 WebGLExtensionScopedContext scoped(this);
71 if (!array_object || scoped.IsLost())
72 return 0;
73
74 if (!array_object->HasEverBeenBound())
75 return 0;
76 if (array_object->MarkedForDeletion())
77 return 0;
78
79 return scoped.Context()->ContextGL()->IsVertexArrayOES(
80 array_object->Object());
81 }
82
bindVertexArrayOES(WebGLVertexArrayObjectOES * array_object)83 void OESVertexArrayObject::bindVertexArrayOES(
84 WebGLVertexArrayObjectOES* array_object) {
85 WebGLExtensionScopedContext scoped(this);
86 if (scoped.IsLost())
87 return;
88
89 if (!scoped.Context()->ValidateNullableWebGLObject(
90 "OESVertexArrayObject.bindVertexArrayOES", array_object))
91 return;
92
93 if (array_object && !array_object->IsDefaultObject() &&
94 array_object->Object()) {
95 scoped.Context()->ContextGL()->BindVertexArrayOES(array_object->Object());
96
97 array_object->SetHasEverBeenBound();
98 scoped.Context()->SetBoundVertexArrayObject(array_object);
99 } else {
100 scoped.Context()->ContextGL()->BindVertexArrayOES(0);
101 scoped.Context()->SetBoundVertexArrayObject(nullptr);
102 }
103 }
104
Supported(WebGLRenderingContextBase * context)105 bool OESVertexArrayObject::Supported(WebGLRenderingContextBase* context) {
106 return context->ExtensionsUtil()->SupportsExtension(
107 "GL_OES_vertex_array_object");
108 }
109
ExtensionName()110 const char* OESVertexArrayObject::ExtensionName() {
111 return "OES_vertex_array_object";
112 }
113
114 } // namespace blink
115