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 // A class to emulate GLES2 over command buffers. | 5 // A class to emulate GLES2 over command buffers. |
6 | 6 |
7 #include "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
8 | 8 |
| 9 #include <algorithm> |
9 #include <map> | 10 #include <map> |
| 11 #include <queue> |
10 #include <set> | 12 #include <set> |
11 #include <queue> | |
12 #include <GLES2/gl2ext.h> | 13 #include <GLES2/gl2ext.h> |
13 #include "../client/mapped_memory.h" | 14 #include "../client/mapped_memory.h" |
14 #include "../client/program_info_manager.h" | 15 #include "../client/program_info_manager.h" |
15 #include "../client/query_tracker.h" | 16 #include "../client/query_tracker.h" |
16 #include "../client/transfer_buffer.h" | 17 #include "../client/transfer_buffer.h" |
17 #include "../common/gles2_cmd_utils.h" | 18 #include "../common/gles2_cmd_utils.h" |
18 #include "../common/trace_event.h" | 19 #include "../common/trace_event.h" |
19 | 20 |
20 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 21 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
21 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS | 22 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS |
(...skipping 2061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2083 helper_->SetBucketSize(kResultBucketId, 0); | 2084 helper_->SetBucketSize(kResultBucketId, 0); |
2084 helper_->GetString(name, kResultBucketId); | 2085 helper_->GetString(name, kResultBucketId); |
2085 std::string str; | 2086 std::string str; |
2086 if (GetBucketAsString(kResultBucketId, &str)) { | 2087 if (GetBucketAsString(kResultBucketId, &str)) { |
2087 // Adds extensions implemented on client side only. | 2088 // Adds extensions implemented on client side only. |
2088 switch (name) { | 2089 switch (name) { |
2089 case GL_EXTENSIONS: | 2090 case GL_EXTENSIONS: |
2090 str += std::string(str.empty() ? "" : " ") + | 2091 str += std::string(str.empty() ? "" : " ") + |
2091 "GL_CHROMIUM_map_sub " | 2092 "GL_CHROMIUM_map_sub " |
2092 "GL_CHROMIUM_flipy " | 2093 "GL_CHROMIUM_flipy " |
| 2094 "GL_CHROMIUM_consistent_uniform_locations " |
2093 "GL_EXT_unpack_subimage"; | 2095 "GL_EXT_unpack_subimage"; |
2094 break; | 2096 break; |
2095 default: | 2097 default: |
2096 break; | 2098 break; |
2097 } | 2099 } |
2098 | 2100 |
2099 // Because of WebGL the extensions can change. We have to cache each unique | 2101 // Because of WebGL the extensions can change. We have to cache each unique |
2100 // result since we don't know when the client will stop referring to a | 2102 // result since we don't know when the client will stop referring to a |
2101 // previous one it queries. | 2103 // previous one it queries. |
2102 GLStringMap::iterator it = gl_strings_.find(name); | 2104 GLStringMap::iterator it = gl_strings_.find(name); |
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3269 TRACE_EVENT0("gpu", "GLES2::GenMailboxCHROMIUM"); | 3271 TRACE_EVENT0("gpu", "GLES2::GenMailboxCHROMIUM"); |
3270 | 3272 |
3271 helper_->GenMailboxCHROMIUM(kResultBucketId); | 3273 helper_->GenMailboxCHROMIUM(kResultBucketId); |
3272 | 3274 |
3273 std::vector<GLbyte> result; | 3275 std::vector<GLbyte> result; |
3274 GetBucketContents(kResultBucketId, &result); | 3276 GetBucketContents(kResultBucketId, &result); |
3275 | 3277 |
3276 std::copy(result.begin(), result.end(), mailbox); | 3278 std::copy(result.begin(), result.end(), mailbox); |
3277 } | 3279 } |
3278 | 3280 |
| 3281 namespace { |
| 3282 |
| 3283 class GLUniformDefinitionComparer { |
| 3284 public: |
| 3285 explicit GLUniformDefinitionComparer( |
| 3286 const GLUniformDefinitionCHROMIUM* uniforms) |
| 3287 : uniforms_(uniforms) { |
| 3288 } |
| 3289 |
| 3290 bool operator()(const GLint lhs, const GLint rhs) const { |
| 3291 return strcmp(uniforms_[lhs].name, uniforms_[rhs].name) < 0; |
| 3292 } |
| 3293 |
| 3294 private: |
| 3295 const GLUniformDefinitionCHROMIUM* uniforms_; |
| 3296 }; |
| 3297 |
| 3298 } // anonymous namespace. |
| 3299 |
| 3300 void GLES2Implementation::GetUniformLocationsCHROMIUM( |
| 3301 const GLUniformDefinitionCHROMIUM* uniforms, |
| 3302 GLsizei count, |
| 3303 GLsizei max_locations, |
| 3304 GLint* locations) { |
| 3305 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 3306 GPU_CLIENT_LOG("[" << this << "] glGenUniformLocationsCHROMIUM(" |
| 3307 << static_cast<const void*>(uniforms) << ", " << count << ", " |
| 3308 << max_locations << ", " << static_cast<const void*>(locations) << ")"); |
| 3309 |
| 3310 if (count <= 0) { |
| 3311 SetGLError(GL_INVALID_VALUE, "glGetUniformLocationsCHROMIUM", "count <= 0"); |
| 3312 return; |
| 3313 } |
| 3314 |
| 3315 for (GLsizei ii = 0; ii < count; ++ii) { |
| 3316 const GLUniformDefinitionCHROMIUM& def = uniforms[ii]; |
| 3317 if (def.size <= 0) { |
| 3318 SetGLError( |
| 3319 GL_INVALID_VALUE, "glGetUniformLocationsCHROMIUM", "size <= 0"); |
| 3320 return; |
| 3321 } |
| 3322 } |
| 3323 |
| 3324 scoped_array<GLint> indices(new GLint[count]); |
| 3325 for (GLint ii = 0; ii < count; ++ii) { |
| 3326 indices[ii] = ii; |
| 3327 } |
| 3328 |
| 3329 std::sort(&indices[0], &indices[count], |
| 3330 GLUniformDefinitionComparer(uniforms)); |
| 3331 |
| 3332 scoped_array<GLint> reverse_map(new GLint[count]); |
| 3333 |
| 3334 for (GLint ii = 0; ii < count; ++ii) { |
| 3335 reverse_map[indices[ii]] = ii; |
| 3336 } |
| 3337 |
| 3338 for (GLsizei ii = 0; ii < count; ++ii) { |
| 3339 const GLUniformDefinitionCHROMIUM& def = uniforms[ii]; |
| 3340 GLint base_location = reverse_map[ii]; |
| 3341 for (GLsizei jj = 0; jj < def.size; ++jj) { |
| 3342 if (max_locations <= 0) { |
| 3343 return; |
| 3344 } |
| 3345 *locations++ = GLES2Util::SwizzleLocation( |
| 3346 GLES2Util::MakeFakeLocation(base_location, jj)); |
| 3347 --max_locations; |
| 3348 } |
| 3349 } |
| 3350 } |
| 3351 |
3279 } // namespace gles2 | 3352 } // namespace gles2 |
3280 } // namespace gpu | 3353 } // namespace gpu |
OLD | NEW |