OLD | NEW |
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 <list> | 7 #include <list> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #define GLES2_GPU_SERVICE 1 | 14 #define GLES2_GPU_SERVICE 1 |
15 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 15 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
16 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 16 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
17 #include "gpu/command_buffer/service/buffer_manager.h" | 17 #include "gpu/command_buffer/service/buffer_manager.h" |
| 18 #include "gpu/command_buffer/service/error_state.h" |
18 #include "gpu/command_buffer/service/feature_info.h" | 19 #include "gpu/command_buffer/service/feature_info.h" |
19 #include "gpu/command_buffer/service/gl_utils.h" | 20 #include "gpu/command_buffer/service/gl_utils.h" |
20 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 21 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
21 #include "gpu/command_buffer/service/gpu_switches.h" | 22 #include "gpu/command_buffer/service/gpu_switches.h" |
22 #include "gpu/command_buffer/service/program_manager.h" | 23 #include "gpu/command_buffer/service/program_manager.h" |
23 #include "gpu/command_buffer/service/vertex_array_manager.h" | 24 #include "gpu/command_buffer/service/vertex_array_manager.h" |
24 | 25 |
25 namespace gpu { | 26 namespace gpu { |
26 namespace gles2 { | 27 namespace gles2 { |
27 | 28 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 160 } |
160 } | 161 } |
161 | 162 |
162 bool VertexAttribManager::ValidateBindings( | 163 bool VertexAttribManager::ValidateBindings( |
163 const char* function_name, | 164 const char* function_name, |
164 GLES2Decoder* decoder, | 165 GLES2Decoder* decoder, |
165 FeatureInfo* feature_info, | 166 FeatureInfo* feature_info, |
166 Program* current_program, | 167 Program* current_program, |
167 GLuint max_vertex_accessed, | 168 GLuint max_vertex_accessed, |
168 GLsizei primcount) { | 169 GLsizei primcount) { |
| 170 ErrorState* error_state = decoder->GetErrorState(); |
169 // true if any enabled, used divisor is zero | 171 // true if any enabled, used divisor is zero |
170 bool divisor0 = false; | 172 bool divisor0 = false; |
171 const GLuint kInitialBufferId = 0xFFFFFFFFU; | 173 const GLuint kInitialBufferId = 0xFFFFFFFFU; |
172 GLuint current_buffer_id = kInitialBufferId; | 174 GLuint current_buffer_id = kInitialBufferId; |
173 bool use_client_side_arrays_for_stream_buffers = feature_info->workarounds( | 175 bool use_client_side_arrays_for_stream_buffers = feature_info->workarounds( |
174 ).use_client_side_arrays_for_stream_buffers; | 176 ).use_client_side_arrays_for_stream_buffers; |
175 // Validate all attribs currently enabled. If they are used by the current | 177 // Validate all attribs currently enabled. If they are used by the current |
176 // program then check that they have enough elements to handle the draw call. | 178 // program then check that they have enough elements to handle the draw call. |
177 // If they are not used by the current program check that they have a buffer | 179 // If they are not used by the current program check that they have a buffer |
178 // assigned. | 180 // assigned. |
179 for (VertexAttribList::iterator it = enabled_vertex_attribs_.begin(); | 181 for (VertexAttribList::iterator it = enabled_vertex_attribs_.begin(); |
180 it != enabled_vertex_attribs_.end(); ++it) { | 182 it != enabled_vertex_attribs_.end(); ++it) { |
181 VertexAttrib* attrib = *it; | 183 VertexAttrib* attrib = *it; |
182 const Program::VertexAttrib* attrib_info = | 184 const Program::VertexAttrib* attrib_info = |
183 current_program->GetAttribInfoByLocation(attrib->index()); | 185 current_program->GetAttribInfoByLocation(attrib->index()); |
184 if (attrib_info) { | 186 if (attrib_info) { |
185 divisor0 |= (attrib->divisor() == 0); | 187 divisor0 |= (attrib->divisor() == 0); |
186 GLuint count = attrib->MaxVertexAccessed(primcount, max_vertex_accessed); | 188 GLuint count = attrib->MaxVertexAccessed(primcount, max_vertex_accessed); |
187 // This attrib is used in the current program. | 189 // This attrib is used in the current program. |
188 if (!attrib->CanAccess(count)) { | 190 if (!attrib->CanAccess(count)) { |
189 GLESDECODER_SET_GL_ERROR( | 191 ERRORSTATE_SET_GL_ERROR( |
190 decoder, GL_INVALID_OPERATION, function_name, | 192 error_state, GL_INVALID_OPERATION, function_name, |
191 (std::string( | 193 (std::string( |
192 "attempt to access out of range vertices in attribute ") + | 194 "attempt to access out of range vertices in attribute ") + |
193 base::IntToString(attrib->index())).c_str()); | 195 base::IntToString(attrib->index())).c_str()); |
194 return false; | 196 return false; |
195 } | 197 } |
196 if (use_client_side_arrays_for_stream_buffers) { | 198 if (use_client_side_arrays_for_stream_buffers) { |
197 Buffer* buffer = attrib->buffer(); | 199 Buffer* buffer = attrib->buffer(); |
198 glEnableVertexAttribArray(attrib->index()); | 200 glEnableVertexAttribArray(attrib->index()); |
199 if (buffer->IsClientSideArray()) { | 201 if (buffer->IsClientSideArray()) { |
200 if (current_buffer_id != 0) { | 202 if (current_buffer_id != 0) { |
(...skipping 23 matching lines...) Expand all Loading... |
224 attrib->size(), | 226 attrib->size(), |
225 attrib->type(), | 227 attrib->type(), |
226 attrib->normalized(), | 228 attrib->normalized(), |
227 attrib->gl_stride(), | 229 attrib->gl_stride(), |
228 ptr); | 230 ptr); |
229 } | 231 } |
230 } | 232 } |
231 } else { | 233 } else { |
232 // This attrib is not used in the current program. | 234 // This attrib is not used in the current program. |
233 if (!attrib->buffer()) { | 235 if (!attrib->buffer()) { |
234 GLESDECODER_SET_GL_ERROR( | 236 ERRORSTATE_SET_GL_ERROR( |
235 decoder, GL_INVALID_OPERATION, function_name, | 237 error_state, GL_INVALID_OPERATION, function_name, |
236 (std::string( | 238 (std::string( |
237 "attempt to render with no buffer attached to " | 239 "attempt to render with no buffer attached to " |
238 "enabled attribute ") + | 240 "enabled attribute ") + |
239 base::IntToString(attrib->index())).c_str()); | 241 base::IntToString(attrib->index())).c_str()); |
240 return false; | 242 return false; |
241 } else if (use_client_side_arrays_for_stream_buffers) { | 243 } else if (use_client_side_arrays_for_stream_buffers) { |
242 Buffer* buffer = attrib->buffer(); | 244 Buffer* buffer = attrib->buffer(); |
243 // Disable client side arrays for unused attributes else we'll | 245 // Disable client side arrays for unused attributes else we'll |
244 // read bad memory | 246 // read bad memory |
245 if (buffer->IsClientSideArray()) { | 247 if (buffer->IsClientSideArray()) { |
246 // Don't disable attrib 0 since it's special. | 248 // Don't disable attrib 0 since it's special. |
247 if (attrib->index() > 0) { | 249 if (attrib->index() > 0) { |
248 glDisableVertexAttribArray(attrib->index()); | 250 glDisableVertexAttribArray(attrib->index()); |
249 } | 251 } |
250 } | 252 } |
251 } | 253 } |
252 } | 254 } |
253 } | 255 } |
254 | 256 |
255 if (primcount && !divisor0) { | 257 if (primcount && !divisor0) { |
256 GLESDECODER_SET_GL_ERROR( | 258 ERRORSTATE_SET_GL_ERROR( |
257 decoder, GL_INVALID_OPERATION, function_name, | 259 error_state, GL_INVALID_OPERATION, function_name, |
258 "attempt instanced render with all attributes having " | 260 "attempt instanced render with all attributes having " |
259 "non-zero divisors"); | 261 "non-zero divisors"); |
260 return false; | 262 return false; |
261 } | 263 } |
262 | 264 |
263 if (current_buffer_id != kInitialBufferId) { | 265 if (current_buffer_id != kInitialBufferId) { |
264 // Restore the buffer binding. | 266 // Restore the buffer binding. |
265 decoder->RestoreBufferBindings(); | 267 decoder->RestoreBufferBindings(); |
266 } | 268 } |
267 | 269 |
268 return true; | 270 return true; |
269 } | 271 } |
270 | 272 |
271 } // namespace gles2 | 273 } // namespace gles2 |
272 } // namespace gpu | 274 } // namespace gpu |
OLD | NEW |