Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLVertexArrayObjectBase.cpp

Issue 2019513004: Validate bound buffer for draw calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: private function Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLVertexArrayObjectBase.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/webgl/WebGLVertexArrayObjectBase.h" 5 #include "modules/webgl/WebGLVertexArrayObjectBase.h"
6 6
7 #include "gpu/command_buffer/client/gles2_interface.h" 7 #include "gpu/command_buffer/client/gles2_interface.h"
8 #include "modules/webgl/WebGLRenderingContextBase.h" 8 #include "modules/webgl/WebGLRenderingContextBase.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase(WebGLRenderingContextBase * ctx, VaoType type) 12 WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase(WebGLRenderingContextBase * ctx, VaoType type)
13 : WebGLContextObject(ctx) 13 : WebGLContextObject(ctx)
14 , m_object(0) 14 , m_object(0)
15 , m_type(type) 15 , m_type(type)
16 , m_hasEverBeenBound(false) 16 , m_hasEverBeenBound(false)
17 , m_destructionInProgress(false) 17 , m_destructionInProgress(false)
18 , m_boundElementArrayBuffer(nullptr) 18 , m_boundElementArrayBuffer(nullptr)
19 , m_isAllEnabledAttribBufferBound(true)
19 { 20 {
20 m_arrayBufferList.resize(ctx->maxVertexAttribs()); 21 m_arrayBufferList.resize(ctx->maxVertexAttribs());
22 m_attribEnabled.resize(ctx->maxVertexAttribs());
23 for (size_t i = 0; i < m_attribEnabled.size(); ++i) {
24 m_attribEnabled[i] = false;
25 }
21 26
22 switch (m_type) { 27 switch (m_type) {
23 case VaoTypeDefault: 28 case VaoTypeDefault:
24 break; 29 break;
25 default: 30 default:
26 context()->contextGL()->GenVertexArraysOES(1, &m_object); 31 context()->contextGL()->GenVertexArraysOES(1, &m_object);
27 break; 32 break;
28 } 33 }
29 } 34 }
30 35
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 { 78 {
74 if (buffer) 79 if (buffer)
75 buffer->onAttached(); 80 buffer->onAttached();
76 if (m_boundElementArrayBuffer) 81 if (m_boundElementArrayBuffer)
77 m_boundElementArrayBuffer->onDetached(context()->contextGL()); 82 m_boundElementArrayBuffer->onDetached(context()->contextGL());
78 m_boundElementArrayBuffer = buffer; 83 m_boundElementArrayBuffer = buffer;
79 } 84 }
80 85
81 WebGLBuffer* WebGLVertexArrayObjectBase::getArrayBufferForAttrib(size_t index) 86 WebGLBuffer* WebGLVertexArrayObjectBase::getArrayBufferForAttrib(size_t index)
82 { 87 {
83 ASSERT(index < context()->maxVertexAttribs()); 88 DCHECK(index < context()->maxVertexAttribs());
84 return m_arrayBufferList[index].get(); 89 return m_arrayBufferList[index].get();
85 } 90 }
86 91
87 void WebGLVertexArrayObjectBase::setArrayBufferForAttrib(GLuint index, WebGLBuff er* buffer) 92 void WebGLVertexArrayObjectBase::setArrayBufferForAttrib(GLuint index, WebGLBuff er* buffer)
88 { 93 {
89 if (buffer) 94 if (buffer)
90 buffer->onAttached(); 95 buffer->onAttached();
91 if (m_arrayBufferList[index]) 96 if (m_arrayBufferList[index])
92 m_arrayBufferList[index]->onDetached(context()->contextGL()); 97 m_arrayBufferList[index]->onDetached(context()->contextGL());
93 98
94 m_arrayBufferList[index] = buffer; 99 m_arrayBufferList[index] = buffer;
100 updateAttribBufferBoundStatus();
101 }
102
103 void WebGLVertexArrayObjectBase::setAttribEnabled(GLuint index, bool enabled)
104 {
105 DCHECK(index < context()->maxVertexAttribs());
106 m_attribEnabled[index] = enabled;
107 updateAttribBufferBoundStatus();
108 }
109
110 bool WebGLVertexArrayObjectBase::getAttribEnabled(GLuint index) const
111 {
112 DCHECK(index < context()->maxVertexAttribs());
113 return m_attribEnabled[index];
114 }
115
116 void WebGLVertexArrayObjectBase::updateAttribBufferBoundStatus()
117 {
118 m_isAllEnabledAttribBufferBound = true;
119 for (size_t i = 0; i < m_attribEnabled.size(); ++i) {
120 if (m_attribEnabled[i] && !m_arrayBufferList[i]) {
121 m_isAllEnabledAttribBufferBound = false;
122 return;
123 }
124 }
95 } 125 }
96 126
97 void WebGLVertexArrayObjectBase::unbindBuffer(WebGLBuffer* buffer) 127 void WebGLVertexArrayObjectBase::unbindBuffer(WebGLBuffer* buffer)
98 { 128 {
99 if (m_boundElementArrayBuffer == buffer) { 129 if (m_boundElementArrayBuffer == buffer) {
100 m_boundElementArrayBuffer->onDetached(context()->contextGL()); 130 m_boundElementArrayBuffer->onDetached(context()->contextGL());
101 m_boundElementArrayBuffer = nullptr; 131 m_boundElementArrayBuffer = nullptr;
102 } 132 }
103 133
104 for (size_t i = 0; i < m_arrayBufferList.size(); ++i) { 134 for (size_t i = 0; i < m_arrayBufferList.size(); ++i) {
105 if (m_arrayBufferList[i] == buffer) { 135 if (m_arrayBufferList[i] == buffer) {
106 m_arrayBufferList[i]->onDetached(context()->contextGL()); 136 m_arrayBufferList[i]->onDetached(context()->contextGL());
107 m_arrayBufferList[i] = nullptr; 137 m_arrayBufferList[i] = nullptr;
108 } 138 }
109 } 139 }
140 updateAttribBufferBoundStatus();
110 } 141 }
111 142
112 ScopedPersistent<v8::Array>* WebGLVertexArrayObjectBase::getPersistentCache() 143 ScopedPersistent<v8::Array>* WebGLVertexArrayObjectBase::getPersistentCache()
113 { 144 {
114 return &m_arrayBufferWrappers; 145 return &m_arrayBufferWrappers;
115 } 146 }
116 147
117 DEFINE_TRACE(WebGLVertexArrayObjectBase) 148 DEFINE_TRACE(WebGLVertexArrayObjectBase)
118 { 149 {
119 visitor->trace(m_boundElementArrayBuffer); 150 visitor->trace(m_boundElementArrayBuffer);
120 visitor->trace(m_arrayBufferList); 151 visitor->trace(m_arrayBufferList);
121 WebGLContextObject::trace(visitor); 152 WebGLContextObject::trace(visitor);
122 } 153 }
123 154
124 } // namespace blink 155 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLVertexArrayObjectBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698