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 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 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 "config.h" |
27 | #include "OESVertexArrayObject.h" |
28 | |
29 | #if ENABLE(WEBGL) |
30 | |
31 | #include "Extensions3D.h" |
32 | #include "WebGLRenderingContext.h" |
33 | |
34 | namespace WebCore { |
35 | |
36 | OESVertexArrayObject::OESVertexArrayObject(WebGLRenderingContextBase& context) |
37 | : WebGLExtension(context) |
38 | { |
39 | } |
40 | |
41 | WebGLExtension::ExtensionName OESVertexArrayObject::getName() const |
42 | { |
43 | return OESVertexArrayObjectName; |
44 | } |
45 | |
46 | RefPtr<WebGLVertexArrayObjectOES> OESVertexArrayObject::createVertexArrayOES() |
47 | { |
48 | if (m_context.isContextLost()) |
49 | return nullptr; |
50 | |
51 | auto object = WebGLVertexArrayObjectOES::create(m_context, WebGLVertexArrayObjectOES::Type::User); |
52 | m_context.addContextObject(object.get()); |
53 | return object; |
54 | } |
55 | |
56 | void OESVertexArrayObject::deleteVertexArrayOES(WebGLVertexArrayObjectOES* arrayObject) |
57 | { |
58 | if (!arrayObject || m_context.isContextLost()) |
59 | return; |
60 | |
61 | if (!arrayObject->isDefaultObject() && arrayObject == static_cast<WebGLRenderingContext&>(m_context).m_boundVertexArrayObject) |
62 | static_cast<WebGLRenderingContext&>(m_context).setBoundVertexArrayObject(nullptr); |
63 | |
64 | arrayObject->deleteObject(m_context.graphicsContext3D()); |
65 | } |
66 | |
67 | GC3Dboolean OESVertexArrayObject::isVertexArrayOES(WebGLVertexArrayObjectOES* arrayObject) |
68 | { |
69 | return arrayObject && !m_context.isContextLost() && arrayObject->hasEverBeenBound() |
70 | && m_context.graphicsContext3D()->getExtensions().isVertexArrayOES(arrayObject->object()); |
71 | } |
72 | |
73 | void OESVertexArrayObject::bindVertexArrayOES(WebGLVertexArrayObjectOES* arrayObject) |
74 | { |
75 | if (m_context.isContextLost()) |
76 | return; |
77 | |
78 | if (arrayObject && (arrayObject->isDeleted() || !arrayObject->validate(nullptr, context()))) { |
79 | m_context.graphicsContext3D()->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); |
80 | return; |
81 | } |
82 | |
83 | auto& extensions = m_context.graphicsContext3D()->getExtensions(); |
84 | auto& context = downcast<WebGLRenderingContext>(m_context); |
85 | if (arrayObject && !arrayObject->isDefaultObject() && arrayObject->object()) { |
86 | extensions.bindVertexArrayOES(arrayObject->object()); |
87 | arrayObject->setHasEverBeenBound(); |
88 | context.setBoundVertexArrayObject(arrayObject); |
89 | } else { |
90 | extensions.bindVertexArrayOES(0); |
91 | context.setBoundVertexArrayObject(nullptr); |
92 | } |
93 | } |
94 | |
95 | } // namespace WebCore |
96 | |
97 | #endif // ENABLE(WEBGL) |
98 | |