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

Side by Side Diff: gpu/command_buffer/service/vertex_attrib_manager.cc

Issue 2174173002: current program can be null in ES2/ES3 contexts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update per piman review Created 4 years, 4 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 | « gpu/command_buffer/service/vertex_attrib_manager.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/vertex_attrib_manager.h" 5 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <list> 9 #include <list>
10 10
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 glDeleteVertexArraysOES(1, &service_id_); 120 glDeleteVertexArraysOES(1, &service_id_);
121 } 121 }
122 manager_->StopTracking(this); 122 manager_->StopTracking(this);
123 manager_ = NULL; 123 manager_ = NULL;
124 } 124 }
125 } 125 }
126 126
127 void VertexAttribManager::Initialize(uint32_t max_vertex_attribs, 127 void VertexAttribManager::Initialize(uint32_t max_vertex_attribs,
128 bool init_attribs) { 128 bool init_attribs) {
129 vertex_attribs_.resize(max_vertex_attribs); 129 vertex_attribs_.resize(max_vertex_attribs);
130 max_vertex_attribs_ = max_vertex_attribs; 130 uint32_t packed_size = (max_vertex_attribs + 15) / 16;
131 uint32_t packed_size = max_vertex_attribs_ / 16;
132 packed_size += (max_vertex_attribs_ % 16 == 0) ? 0 : 1;
133 attrib_base_type_mask_.resize(packed_size); 131 attrib_base_type_mask_.resize(packed_size);
134 attrib_enabled_mask_.resize(packed_size); 132 attrib_enabled_mask_.resize(packed_size);
135 133
136 for (uint32_t ii = 0; ii < packed_size; ++ii) { 134 for (uint32_t ii = 0; ii < packed_size; ++ii) {
137 attrib_enabled_mask_[ii] = 0u; 135 attrib_enabled_mask_[ii] = 0u;
138 attrib_base_type_mask_[ii] = 0u; 136 attrib_base_type_mask_[ii] = 0u;
139 } 137 }
140 138
141 for (uint32_t vv = 0; vv < vertex_attribs_.size(); ++vv) { 139 for (uint32_t vv = 0; vv < vertex_attribs_.size(); ++vv) {
142 vertex_attribs_[vv].set_index(vv); 140 vertex_attribs_[vv].set_index(vv);
143 vertex_attribs_[vv].SetList(&disabled_vertex_attribs_); 141 vertex_attribs_[vv].SetList(&disabled_vertex_attribs_);
144 142
145 if (init_attribs) { 143 if (init_attribs) {
146 glVertexAttrib4f(vv, 0.0f, 0.0f, 0.0f, 1.0f); 144 glVertexAttrib4f(vv, 0.0f, 0.0f, 0.0f, 1.0f);
147 } 145 }
148 } 146 }
149 } 147 }
150 148
151 void VertexAttribManager::SetElementArrayBuffer(Buffer* buffer) { 149 void VertexAttribManager::SetElementArrayBuffer(Buffer* buffer) {
152 element_array_buffer_ = buffer; 150 element_array_buffer_ = buffer;
153 } 151 }
154 152
155 bool VertexAttribManager::Enable(GLuint index, bool enable) { 153 bool VertexAttribManager::Enable(GLuint index, bool enable) {
156 if (index >= vertex_attribs_.size()) { 154 if (index >= vertex_attribs_.size()) {
157 return false; 155 return false;
158 } 156 }
159 157
160 DCHECK(index < max_vertex_attribs_);
161 GLuint shift_bits = (index % 16) * 2;
162 if (enable) {
163 attrib_enabled_mask_[index / 16] |= (0x3 << shift_bits);
164 } else {
165 attrib_enabled_mask_[index / 16] &= ~(0x3 << shift_bits);
166 }
167
168 VertexAttrib& info = vertex_attribs_[index]; 158 VertexAttrib& info = vertex_attribs_[index];
169 if (info.enabled() != enable) { 159 if (info.enabled() != enable) {
170 info.set_enabled(enable); 160 info.set_enabled(enable);
171 info.SetList(enable ? &enabled_vertex_attribs_ : &disabled_vertex_attribs_); 161 info.SetList(enable ? &enabled_vertex_attribs_ : &disabled_vertex_attribs_);
162 GLuint shift_bits = (index % 16) * 2;
163 if (enable) {
164 attrib_enabled_mask_[index / 16] |= (0x3 << shift_bits);
165 } else {
166 attrib_enabled_mask_[index / 16] &= ~(0x3 << shift_bits);
167 }
172 } 168 }
173 return true; 169 return true;
174 } 170 }
175 171
176 void VertexAttribManager::Unbind(Buffer* buffer) { 172 void VertexAttribManager::Unbind(Buffer* buffer) {
177 if (element_array_buffer_.get() == buffer) { 173 if (element_array_buffer_.get() == buffer) {
178 element_array_buffer_ = NULL; 174 element_array_buffer_ = NULL;
179 } 175 }
180 for (uint32_t vv = 0; vv < vertex_attribs_.size(); ++vv) { 176 for (uint32_t vv = 0; vv < vertex_attribs_.size(); ++vv) {
181 vertex_attribs_[vv].Unbind(buffer); 177 vertex_attribs_[vv].Unbind(buffer);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 if (current_buffer_id != kInitialBufferId) { 290 if (current_buffer_id != kInitialBufferId) {
295 // Restore the buffer binding. 291 // Restore the buffer binding.
296 decoder->RestoreBufferBindings(); 292 decoder->RestoreBufferBindings();
297 } 293 }
298 294
299 return true; 295 return true;
300 } 296 }
301 297
302 } // namespace gles2 298 } // namespace gles2
303 } // namespace gpu 299 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/vertex_attrib_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698