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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation.cc

Issue 10635011: Add glBindUniformLocationCHROMIUM (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
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 // 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 <algorithm>
10 #include <map> 10 #include <map>
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 void GLES2Implementation::BindAttribLocation( 1155 void GLES2Implementation::BindAttribLocation(
1156 GLuint program, GLuint index, const char* name) { 1156 GLuint program, GLuint index, const char* name) {
1157 GPU_CLIENT_SINGLE_THREAD_CHECK(); 1157 GPU_CLIENT_SINGLE_THREAD_CHECK();
1158 GPU_CLIENT_LOG("[" << this << "] glBindAttribLocation(" << program << ", " 1158 GPU_CLIENT_LOG("[" << this << "] glBindAttribLocation(" << program << ", "
1159 << index << ", " << name << ")"); 1159 << index << ", " << name << ")");
1160 SetBucketAsString(kResultBucketId, name); 1160 SetBucketAsString(kResultBucketId, name);
1161 helper_->BindAttribLocationBucket(program, index, kResultBucketId); 1161 helper_->BindAttribLocationBucket(program, index, kResultBucketId);
1162 helper_->SetBucketSize(kResultBucketId, 0); 1162 helper_->SetBucketSize(kResultBucketId, 0);
1163 } 1163 }
1164 1164
1165 void GLES2Implementation::BindUniformLocationCHROMIUM(
1166 GLuint program, GLint location, const char* name) {
1167 GPU_CLIENT_SINGLE_THREAD_CHECK();
1168 GPU_CLIENT_LOG("[" << this << "] glBindUniformLocationCHROMIUM("
1169 << program << ", " << location << ", " << name << ")");
1170 SetBucketAsString(kResultBucketId, name);
1171 helper_->BindUniformLocationCHROMIUMBucket(
1172 program, location, kResultBucketId);
1173 helper_->SetBucketSize(kResultBucketId, 0);
1174 }
1175
1165 void GLES2Implementation::GetVertexAttribPointerv( 1176 void GLES2Implementation::GetVertexAttribPointerv(
1166 GLuint index, GLenum pname, void** ptr) { 1177 GLuint index, GLenum pname, void** ptr) {
1167 GPU_CLIENT_SINGLE_THREAD_CHECK(); 1178 GPU_CLIENT_SINGLE_THREAD_CHECK();
1168 GPU_CLIENT_LOG("[" << this << "] glGetVertexAttribPointer(" << index << ", " 1179 GPU_CLIENT_LOG("[" << this << "] glGetVertexAttribPointer(" << index << ", "
1169 << GLES2Util::GetStringVertexPointer(pname) << ", " 1180 << GLES2Util::GetStringVertexPointer(pname) << ", "
1170 << static_cast<void*>(ptr) << ")"); 1181 << static_cast<void*>(ptr) << ")");
1171 1182
1172 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) 1183 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
1173 // If it's a client side buffer the client has the data. 1184 // If it's a client side buffer the client has the data.
1174 if (client_side_buffer_helper_->GetAttribPointer(index, pname, ptr)) { 1185 if (client_side_buffer_helper_->GetAttribPointer(index, pname, ptr)) {
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
2084 helper_->SetBucketSize(kResultBucketId, 0); 2095 helper_->SetBucketSize(kResultBucketId, 0);
2085 helper_->GetString(name, kResultBucketId); 2096 helper_->GetString(name, kResultBucketId);
2086 std::string str; 2097 std::string str;
2087 if (GetBucketAsString(kResultBucketId, &str)) { 2098 if (GetBucketAsString(kResultBucketId, &str)) {
2088 // Adds extensions implemented on client side only. 2099 // Adds extensions implemented on client side only.
2089 switch (name) { 2100 switch (name) {
2090 case GL_EXTENSIONS: 2101 case GL_EXTENSIONS:
2091 str += std::string(str.empty() ? "" : " ") + 2102 str += std::string(str.empty() ? "" : " ") +
2092 "GL_CHROMIUM_map_sub " 2103 "GL_CHROMIUM_map_sub "
2093 "GL_CHROMIUM_flipy " 2104 "GL_CHROMIUM_flipy "
2094 "GL_CHROMIUM_consistent_uniform_locations "
2095 "GL_EXT_unpack_subimage"; 2105 "GL_EXT_unpack_subimage";
2096 break; 2106 break;
2097 default: 2107 default:
2098 break; 2108 break;
2099 } 2109 }
2100 2110
2101 // Because of WebGL the extensions can change. We have to cache each unique 2111 // Because of WebGL the extensions can change. We have to cache each unique
2102 // result since we don't know when the client will stop referring to a 2112 // result since we don't know when the client will stop referring to a
2103 // previous one it queries. 2113 // previous one it queries.
2104 GLStringMap::iterator it = gl_strings_.find(name); 2114 GLStringMap::iterator it = gl_strings_.find(name);
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after
3271 TRACE_EVENT0("gpu", "GLES2::GenMailboxCHROMIUM"); 3281 TRACE_EVENT0("gpu", "GLES2::GenMailboxCHROMIUM");
3272 3282
3273 helper_->GenMailboxCHROMIUM(kResultBucketId); 3283 helper_->GenMailboxCHROMIUM(kResultBucketId);
3274 3284
3275 std::vector<GLbyte> result; 3285 std::vector<GLbyte> result;
3276 GetBucketContents(kResultBucketId, &result); 3286 GetBucketContents(kResultBucketId, &result);
3277 3287
3278 std::copy(result.begin(), result.end(), mailbox); 3288 std::copy(result.begin(), result.end(), mailbox);
3279 } 3289 }
3280 3290
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
3299
3300 } // anonymous namespace.
3301
3302 void GLES2Implementation::GetUniformLocationsCHROMIUM(
3303 GLuint program,
3304 const GLUniformDefinitionCHROMIUM* uniforms,
3305 GLsizei count,
3306 GLsizei max_locations,
3307 GLint* locations) {
3308 (void)program; // To keep the compiler happy as it's unused in release.
3309
3310 GPU_CLIENT_SINGLE_THREAD_CHECK();
3311 GPU_CLIENT_LOG("[" << this << "] glGenUniformLocationsCHROMIUM("
3312 << static_cast<const void*>(uniforms) << ", " << count << ", "
3313 << max_locations << ", " << static_cast<const void*>(locations) << ")");
3314
3315 if (count <= 0) {
3316 SetGLError(GL_INVALID_VALUE, "glGetUniformLocationsCHROMIUM", "count <= 0");
3317 return;
3318 }
3319
3320 for (GLsizei ii = 0; ii < count; ++ii) {
3321 const GLUniformDefinitionCHROMIUM& def = uniforms[ii];
3322 if (def.size <= 0) {
3323 SetGLError(
3324 GL_INVALID_VALUE, "glGetUniformLocationsCHROMIUM", "size <= 0");
3325 return;
3326 }
3327 }
3328
3329 scoped_array<GLint> indices(new GLint[count]);
3330 for (GLint ii = 0; ii < count; ++ii) {
3331 indices[ii] = ii;
3332 }
3333
3334 std::sort(&indices[0], &indices[count],
3335 GLUniformDefinitionComparer(uniforms));
3336
3337 scoped_array<GLint> reverse_map(new GLint[count]);
3338
3339 for (GLint ii = 0; ii < count; ++ii) {
3340 reverse_map[indices[ii]] = ii;
3341 }
3342
3343 for (GLsizei ii = 0; ii < count; ++ii) {
3344 const GLUniformDefinitionCHROMIUM& def = uniforms[ii];
3345 GLint base_location = reverse_map[ii];
3346 for (GLsizei jj = 0; jj < def.size; ++jj) {
3347 if (max_locations <= 0) {
3348 return;
3349 }
3350 GLint location = GLES2Util::SwizzleLocation(
3351 GLES2Util::MakeFakeLocation(base_location, jj));
3352 *locations++ = location;
3353 #if defined(GPU_CLIENT_DEBUG)
3354 std::string name(def.name);
3355 if (jj > 0) {
3356 char buf[20];
3357 sprintf(buf, "%d", jj);
3358 name = name + "[" + buf + "]";
3359 }
3360 GPU_DCHECK_EQ(
3361 location,
3362 share_group_->program_info_manager()->GetUniformLocation(
3363 this, program, name.c_str()));
3364 #endif
3365 --max_locations;
3366
3367 }
3368 }
3369 }
3370
3371 } // namespace gles2 3291 } // namespace gles2
3372 } // namespace gpu 3292 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_cmd_helper_autogen.h ('k') | gpu/command_buffer/client/gles2_implementation_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698