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 "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
8 | 8 |
9 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
10 #include <GLES2/gl2extchromium.h> | 10 #include <GLES2/gl2extchromium.h> |
(...skipping 2276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2287 const GLuint* /* valuebuffers */) { | 2287 const GLuint* /* valuebuffers */) { |
2288 } | 2288 } |
2289 | 2289 |
2290 // NOTE #1: On old versions of OpenGL, calling glBindXXX with an unused id | 2290 // NOTE #1: On old versions of OpenGL, calling glBindXXX with an unused id |
2291 // generates a new resource. On newer versions of OpenGL they don't. The code | 2291 // generates a new resource. On newer versions of OpenGL they don't. The code |
2292 // related to binding below will need to change if we switch to the new OpenGL | 2292 // related to binding below will need to change if we switch to the new OpenGL |
2293 // model. Specifically it assumes a bind will succeed which is always true in | 2293 // model. Specifically it assumes a bind will succeed which is always true in |
2294 // the old model but possibly not true in the new model if another context has | 2294 // the old model but possibly not true in the new model if another context has |
2295 // deleted the resource. | 2295 // deleted the resource. |
2296 | 2296 |
2297 bool GLES2Implementation::BindBufferHelper( | 2297 void GLES2Implementation::BindBufferHelper( |
2298 GLenum target, GLuint buffer_id) { | 2298 GLenum target, GLuint buffer_id) { |
2299 // TODO(gman): See note #1 above. | 2299 // TODO(gman): See note #1 above. |
2300 bool changed = false; | 2300 bool changed = false; |
2301 switch (target) { | 2301 switch (target) { |
2302 case GL_ARRAY_BUFFER: | 2302 case GL_ARRAY_BUFFER: |
2303 if (bound_array_buffer_id_ != buffer_id) { | 2303 if (bound_array_buffer_id_ != buffer_id) { |
2304 bound_array_buffer_id_ = buffer_id; | 2304 bound_array_buffer_id_ = buffer_id; |
2305 changed = true; | 2305 changed = true; |
2306 } | 2306 } |
2307 break; | 2307 break; |
2308 case GL_ELEMENT_ARRAY_BUFFER: | 2308 case GL_ELEMENT_ARRAY_BUFFER: |
2309 changed = vertex_array_object_manager_->BindElementArray(buffer_id); | 2309 changed = vertex_array_object_manager_->BindElementArray(buffer_id); |
2310 break; | 2310 break; |
2311 case GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM: | 2311 case GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM: |
2312 bound_pixel_pack_transfer_buffer_id_ = buffer_id; | 2312 bound_pixel_pack_transfer_buffer_id_ = buffer_id; |
2313 break; | 2313 break; |
2314 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: | 2314 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: |
2315 bound_pixel_unpack_transfer_buffer_id_ = buffer_id; | 2315 bound_pixel_unpack_transfer_buffer_id_ = buffer_id; |
2316 break; | 2316 break; |
2317 default: | 2317 default: |
2318 changed = true; | 2318 changed = true; |
2319 break; | 2319 break; |
2320 } | 2320 } |
2321 // TODO(gman): There's a bug here. If the target is invalid the ID will not be | 2321 // TODO(gman): There's a bug here. If the target is invalid the ID will not be |
2322 // used even though it's marked it as used here. | 2322 // used even though it's marked it as used here. |
2323 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind(buffer_id); | 2323 if (changed) { |
2324 return changed; | 2324 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind( |
| 2325 this, target, buffer_id, &GLES2Implementation::BindBufferStub); |
| 2326 } |
2325 } | 2327 } |
2326 | 2328 |
2327 bool GLES2Implementation::BindFramebufferHelper( | 2329 void GLES2Implementation::BindBufferStub(GLenum target, GLuint buffer) { |
| 2330 helper_->BindBuffer(target, buffer); |
| 2331 if (share_group_->bind_generates_resource()) |
| 2332 helper_->CommandBufferHelper::Flush(); |
| 2333 } |
| 2334 |
| 2335 void GLES2Implementation::BindFramebufferHelper( |
2328 GLenum target, GLuint framebuffer) { | 2336 GLenum target, GLuint framebuffer) { |
2329 // TODO(gman): See note #1 above. | 2337 // TODO(gman): See note #1 above. |
2330 bool changed = false; | 2338 bool changed = false; |
2331 switch (target) { | 2339 switch (target) { |
2332 case GL_FRAMEBUFFER: | 2340 case GL_FRAMEBUFFER: |
2333 if (bound_framebuffer_ != framebuffer || | 2341 if (bound_framebuffer_ != framebuffer || |
2334 bound_read_framebuffer_ != framebuffer) { | 2342 bound_read_framebuffer_ != framebuffer) { |
2335 bound_framebuffer_ = framebuffer; | 2343 bound_framebuffer_ = framebuffer; |
2336 bound_read_framebuffer_ = framebuffer; | 2344 bound_read_framebuffer_ = framebuffer; |
2337 changed = true; | 2345 changed = true; |
2338 } | 2346 } |
2339 break; | 2347 break; |
2340 case GL_READ_FRAMEBUFFER: | 2348 case GL_READ_FRAMEBUFFER: |
2341 if (!IsChromiumFramebufferMultisampleAvailable()) { | 2349 if (!IsChromiumFramebufferMultisampleAvailable()) { |
2342 SetGLErrorInvalidEnum("glBindFramebuffer", target, "target"); | 2350 SetGLErrorInvalidEnum("glBindFramebuffer", target, "target"); |
2343 return false; | 2351 return; |
2344 } | 2352 } |
2345 if (bound_read_framebuffer_ != framebuffer) { | 2353 if (bound_read_framebuffer_ != framebuffer) { |
2346 bound_read_framebuffer_ = framebuffer; | 2354 bound_read_framebuffer_ = framebuffer; |
2347 changed = true; | 2355 changed = true; |
2348 } | 2356 } |
2349 break; | 2357 break; |
2350 case GL_DRAW_FRAMEBUFFER: | 2358 case GL_DRAW_FRAMEBUFFER: |
2351 if (!IsChromiumFramebufferMultisampleAvailable()) { | 2359 if (!IsChromiumFramebufferMultisampleAvailable()) { |
2352 SetGLErrorInvalidEnum("glBindFramebuffer", target, "target"); | 2360 SetGLErrorInvalidEnum("glBindFramebuffer", target, "target"); |
2353 return false; | 2361 return; |
2354 } | 2362 } |
2355 if (bound_framebuffer_ != framebuffer) { | 2363 if (bound_framebuffer_ != framebuffer) { |
2356 bound_framebuffer_ = framebuffer; | 2364 bound_framebuffer_ = framebuffer; |
2357 changed = true; | 2365 changed = true; |
2358 } | 2366 } |
2359 break; | 2367 break; |
2360 default: | 2368 default: |
2361 SetGLErrorInvalidEnum("glBindFramebuffer", target, "target"); | 2369 SetGLErrorInvalidEnum("glBindFramebuffer", target, "target"); |
2362 return false; | 2370 return; |
2363 } | 2371 } |
2364 GetIdHandler(id_namespaces::kFramebuffers)->MarkAsUsedForBind(framebuffer); | 2372 |
2365 return changed; | 2373 if (changed) { |
| 2374 GetIdHandler(id_namespaces::kFramebuffers)->MarkAsUsedForBind( |
| 2375 this, target, framebuffer, &GLES2Implementation::BindFramebufferStub); |
| 2376 } |
2366 } | 2377 } |
2367 | 2378 |
2368 bool GLES2Implementation::BindRenderbufferHelper( | 2379 void GLES2Implementation::BindFramebufferStub(GLenum target, |
| 2380 GLuint framebuffer) { |
| 2381 helper_->BindFramebuffer(target, framebuffer); |
| 2382 if (share_group_->bind_generates_resource()) |
| 2383 helper_->CommandBufferHelper::Flush(); |
| 2384 } |
| 2385 |
| 2386 void GLES2Implementation::BindRenderbufferHelper( |
2369 GLenum target, GLuint renderbuffer) { | 2387 GLenum target, GLuint renderbuffer) { |
2370 // TODO(gman): See note #1 above. | 2388 // TODO(gman): See note #1 above. |
2371 bool changed = false; | 2389 bool changed = false; |
2372 switch (target) { | 2390 switch (target) { |
2373 case GL_RENDERBUFFER: | 2391 case GL_RENDERBUFFER: |
2374 if (bound_renderbuffer_ != renderbuffer) { | 2392 if (bound_renderbuffer_ != renderbuffer) { |
2375 bound_renderbuffer_ = renderbuffer; | 2393 bound_renderbuffer_ = renderbuffer; |
2376 changed = true; | 2394 changed = true; |
2377 } | 2395 } |
2378 break; | 2396 break; |
2379 default: | 2397 default: |
2380 changed = true; | 2398 changed = true; |
2381 break; | 2399 break; |
2382 } | 2400 } |
2383 // TODO(gman): There's a bug here. If the target is invalid the ID will not be | 2401 // TODO(gman): There's a bug here. If the target is invalid the ID will not be |
2384 // used even though it's marked it as used here. | 2402 // used even though it's marked it as used here. |
2385 GetIdHandler(id_namespaces::kRenderbuffers)->MarkAsUsedForBind(renderbuffer); | 2403 if (changed) { |
2386 return changed; | 2404 GetIdHandler(id_namespaces::kRenderbuffers)->MarkAsUsedForBind( |
| 2405 this, target, renderbuffer, |
| 2406 &GLES2Implementation::BindRenderbufferStub); |
| 2407 } |
2387 } | 2408 } |
2388 | 2409 |
2389 bool GLES2Implementation::BindTextureHelper(GLenum target, GLuint texture) { | 2410 void GLES2Implementation::BindRenderbufferStub(GLenum target, |
| 2411 GLuint renderbuffer) { |
| 2412 helper_->BindRenderbuffer(target, renderbuffer); |
| 2413 if (share_group_->bind_generates_resource()) |
| 2414 helper_->CommandBufferHelper::Flush(); |
| 2415 } |
| 2416 |
| 2417 void GLES2Implementation::BindTextureHelper(GLenum target, GLuint texture) { |
2390 // TODO(gman): See note #1 above. | 2418 // TODO(gman): See note #1 above. |
2391 // TODO(gman): Change this to false once we figure out why it's failing | 2419 // TODO(gman): Change this to false once we figure out why it's failing |
2392 // on daisy. | 2420 // on daisy. |
2393 bool changed = true; | 2421 bool changed = true; |
2394 TextureUnit& unit = texture_units_[active_texture_unit_]; | 2422 TextureUnit& unit = texture_units_[active_texture_unit_]; |
2395 switch (target) { | 2423 switch (target) { |
2396 case GL_TEXTURE_2D: | 2424 case GL_TEXTURE_2D: |
2397 if (unit.bound_texture_2d != texture) { | 2425 if (unit.bound_texture_2d != texture) { |
2398 unit.bound_texture_2d = texture; | 2426 unit.bound_texture_2d = texture; |
2399 changed = true; | 2427 changed = true; |
(...skipping 10 matching lines...) Expand all Loading... |
2410 unit.bound_texture_external_oes = texture; | 2438 unit.bound_texture_external_oes = texture; |
2411 changed = true; | 2439 changed = true; |
2412 } | 2440 } |
2413 break; | 2441 break; |
2414 default: | 2442 default: |
2415 changed = true; | 2443 changed = true; |
2416 break; | 2444 break; |
2417 } | 2445 } |
2418 // TODO(gman): There's a bug here. If the target is invalid the ID will not be | 2446 // TODO(gman): There's a bug here. If the target is invalid the ID will not be |
2419 // used. even though it's marked it as used here. | 2447 // used. even though it's marked it as used here. |
2420 GetIdHandler(id_namespaces::kTextures)->MarkAsUsedForBind(texture); | 2448 if (changed) { |
2421 return changed; | 2449 GetIdHandler(id_namespaces::kTextures)->MarkAsUsedForBind( |
| 2450 this, target, texture, &GLES2Implementation::BindTextureStub); |
| 2451 } |
2422 } | 2452 } |
2423 | 2453 |
2424 bool GLES2Implementation::BindVertexArrayOESHelper(GLuint array) { | 2454 void GLES2Implementation::BindTextureStub(GLenum target, GLuint texture) { |
| 2455 helper_->BindTexture(target, texture); |
| 2456 if (share_group_->bind_generates_resource()) |
| 2457 helper_->CommandBufferHelper::Flush(); |
| 2458 } |
| 2459 |
| 2460 void GLES2Implementation::BindVertexArrayOESHelper(GLuint array) { |
2425 // TODO(gman): See note #1 above. | 2461 // TODO(gman): See note #1 above. |
2426 bool changed = false; | 2462 bool changed = false; |
2427 if (!vertex_array_object_manager_->BindVertexArray(array, &changed)) { | 2463 if (vertex_array_object_manager_->BindVertexArray(array, &changed)) { |
| 2464 if (changed) { |
| 2465 // Unlike other BindXXXHelpers we don't call MarkAsUsedForBind |
| 2466 // because unlike other resources VertexArrayObject ids must |
| 2467 // be generated by GenVertexArrays. A random id to Bind will not |
| 2468 // generate a new object. |
| 2469 helper_->BindVertexArrayOES(array); |
| 2470 } |
| 2471 } else { |
2428 SetGLError( | 2472 SetGLError( |
2429 GL_INVALID_OPERATION, "glBindVertexArrayOES", | 2473 GL_INVALID_OPERATION, "glBindVertexArrayOES", |
2430 "id was not generated with glGenVertexArrayOES"); | 2474 "id was not generated with glGenVertexArrayOES"); |
2431 } | 2475 } |
2432 // Unlike other BindXXXHelpers we don't call MarkAsUsedForBind | |
2433 // because unlike other resources VertexArrayObject ids must | |
2434 // be generated by GenVertexArrays. A random id to Bind will not | |
2435 // generate a new object. | |
2436 return changed; | |
2437 } | 2476 } |
2438 | 2477 |
2439 bool GLES2Implementation::BindValuebufferCHROMIUMHelper(GLenum target, | 2478 void GLES2Implementation::BindValuebufferCHROMIUMHelper(GLenum target, |
2440 GLuint valuebuffer) { | 2479 GLuint valuebuffer) { |
2441 bool changed = false; | 2480 bool changed = false; |
2442 switch (target) { | 2481 switch (target) { |
2443 case GL_SUBSCRIBED_VALUES_BUFFER_CHROMIUM: | 2482 case GL_SUBSCRIBED_VALUES_BUFFER_CHROMIUM: |
2444 if (bound_valuebuffer_ != valuebuffer) { | 2483 if (bound_valuebuffer_ != valuebuffer) { |
2445 bound_valuebuffer_ = valuebuffer; | 2484 bound_valuebuffer_ = valuebuffer; |
2446 changed = true; | 2485 changed = true; |
2447 } | 2486 } |
2448 break; | 2487 break; |
2449 default: | 2488 default: |
2450 changed = true; | 2489 changed = true; |
2451 break; | 2490 break; |
2452 } | 2491 } |
2453 // TODO(gman): There's a bug here. If the target is invalid the ID will not be | 2492 // TODO(gman): There's a bug here. If the target is invalid the ID will not be |
2454 // used even though it's marked it as used here. | 2493 // used even though it's marked it as used here. |
2455 GetIdHandler(id_namespaces::kValuebuffers)->MarkAsUsedForBind(valuebuffer); | 2494 if (changed) { |
2456 return changed; | 2495 GetIdHandler(id_namespaces::kValuebuffers)->MarkAsUsedForBind( |
| 2496 this, target, valuebuffer, |
| 2497 &GLES2Implementation::BindValuebufferCHROMIUMStub); |
| 2498 } |
2457 } | 2499 } |
2458 | 2500 |
2459 bool GLES2Implementation::UseProgramHelper(GLuint program) { | 2501 void GLES2Implementation::BindValuebufferCHROMIUMStub(GLenum target, |
2460 bool changed = false; | 2502 GLuint valuebuffer) { |
| 2503 helper_->BindValuebufferCHROMIUM(target, valuebuffer); |
| 2504 if (share_group_->bind_generates_resource()) |
| 2505 helper_->CommandBufferHelper::Flush(); |
| 2506 } |
| 2507 |
| 2508 void GLES2Implementation::UseProgramHelper(GLuint program) { |
2461 if (current_program_ != program) { | 2509 if (current_program_ != program) { |
2462 current_program_ = program; | 2510 current_program_ = program; |
2463 changed = true; | 2511 helper_->UseProgram(program); |
2464 } | 2512 } |
2465 return changed; | |
2466 } | 2513 } |
2467 | 2514 |
2468 bool GLES2Implementation::IsBufferReservedId(GLuint id) { | 2515 bool GLES2Implementation::IsBufferReservedId(GLuint id) { |
2469 return vertex_array_object_manager_->IsReservedId(id); | 2516 return vertex_array_object_manager_->IsReservedId(id); |
2470 } | 2517 } |
2471 | 2518 |
2472 void GLES2Implementation::DeleteBuffersHelper( | 2519 void GLES2Implementation::DeleteBuffersHelper( |
2473 GLsizei n, const GLuint* buffers) { | 2520 GLsizei n, const GLuint* buffers) { |
2474 if (!GetIdHandler(id_namespaces::kBuffers)->FreeIds( | 2521 if (!GetIdHandler(id_namespaces::kBuffers)->FreeIds( |
2475 this, n, buffers, &GLES2Implementation::DeleteBuffersStub)) { | 2522 this, n, buffers, &GLES2Implementation::DeleteBuffersStub)) { |
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3905 return true; | 3952 return true; |
3906 } | 3953 } |
3907 | 3954 |
3908 // Include the auto-generated part of this file. We split this because it means | 3955 // Include the auto-generated part of this file. We split this because it means |
3909 // we can easily edit the non-auto generated parts right here in this file | 3956 // we can easily edit the non-auto generated parts right here in this file |
3910 // instead of having to edit some template or the code generator. | 3957 // instead of having to edit some template or the code generator. |
3911 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 3958 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
3912 | 3959 |
3913 } // namespace gles2 | 3960 } // namespace gles2 |
3914 } // namespace gpu | 3961 } // namespace gpu |
OLD | NEW |