OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return id_; | 266 return id_; |
267 } | 267 } |
268 | 268 |
269 private: | 269 private: |
270 GLES2DecoderImpl* decoder_; | 270 GLES2DecoderImpl* decoder_; |
271 GLuint id_; | 271 GLuint id_; |
272 DISALLOW_COPY_AND_ASSIGN(FrameBuffer); | 272 DISALLOW_COPY_AND_ASSIGN(FrameBuffer); |
273 }; | 273 }; |
274 | 274 |
275 #if defined(GLES2_GPU_SERVICE_TRANSLATE_SHADER) | 275 #if defined(GLES2_GPU_SERVICE_TRANSLATE_SHADER) |
276 void FinalizeShaderTranslator(void*) { | 276 void FinalizeShaderTranslator(void* /* dummy */) { |
277 ShFinalize(); | 277 ShFinalize(); |
278 } | 278 } |
279 | 279 |
280 bool InitializeShaderTranslator() { | 280 bool InitializeShaderTranslator() { |
281 static bool initialized = false; | 281 static bool initialized = false; |
282 if (!initialized && ShInitialize()) { | 282 if (!initialized && ShInitialize()) { |
283 base::AtExitManager::RegisterCallback(&FinalizeShaderTranslator, NULL); | 283 base::AtExitManager::RegisterCallback(&FinalizeShaderTranslator, NULL); |
284 initialized = true; | 284 initialized = true; |
285 } | 285 } |
286 return initialized; | 286 return initialized; |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 GLsizei attrib_0_size_; | 1219 GLsizei attrib_0_size_; |
1220 | 1220 |
1221 // Current active texture by 0 - n index. | 1221 // Current active texture by 0 - n index. |
1222 // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would | 1222 // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would |
1223 // be 2. | 1223 // be 2. |
1224 GLuint active_texture_unit_; | 1224 GLuint active_texture_unit_; |
1225 | 1225 |
1226 // Which textures are bound to texture units through glActiveTexture. | 1226 // Which textures are bound to texture units through glActiveTexture. |
1227 scoped_array<TextureUnit> texture_units_; | 1227 scoped_array<TextureUnit> texture_units_; |
1228 | 1228 |
1229 // Black (0,0,0,1) textures for when non-renderable textures are used. | |
1230 // NOTE: There is no corresponding TextureInfo for these textures. | |
1231 // TextureInfos are only for textures the client side can access. | |
1232 GLuint black_2d_texture_id_; | |
1233 GLuint black_cube_texture_id_; | |
1234 | |
1235 // state saved for clearing so we can clear render buffers and then | 1229 // state saved for clearing so we can clear render buffers and then |
1236 // restore to these values. | 1230 // restore to these values. |
1237 GLclampf clear_red_; | 1231 GLclampf clear_red_; |
1238 GLclampf clear_green_; | 1232 GLclampf clear_green_; |
1239 GLclampf clear_blue_; | 1233 GLclampf clear_blue_; |
1240 GLclampf clear_alpha_; | 1234 GLclampf clear_alpha_; |
1241 GLboolean mask_red_; | 1235 GLboolean mask_red_; |
1242 GLboolean mask_green_; | 1236 GLboolean mask_green_; |
1243 GLboolean mask_blue_; | 1237 GLboolean mask_blue_; |
1244 GLboolean mask_alpha_; | 1238 GLboolean mask_alpha_; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 | 1512 |
1519 GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) | 1513 GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
1520 : GLES2Decoder(group), | 1514 : GLES2Decoder(group), |
1521 error_bits_(0), | 1515 error_bits_(0), |
1522 util_(0), // TODO(gman): Set to actual num compress texture formats. | 1516 util_(0), // TODO(gman): Set to actual num compress texture formats. |
1523 pack_alignment_(4), | 1517 pack_alignment_(4), |
1524 unpack_alignment_(4), | 1518 unpack_alignment_(4), |
1525 attrib_0_buffer_id_(0), | 1519 attrib_0_buffer_id_(0), |
1526 attrib_0_size_(0), | 1520 attrib_0_size_(0), |
1527 active_texture_unit_(0), | 1521 active_texture_unit_(0), |
1528 black_2d_texture_id_(0), | |
1529 black_cube_texture_id_(0), | |
1530 clear_red_(0), | 1522 clear_red_(0), |
1531 clear_green_(0), | 1523 clear_green_(0), |
1532 clear_blue_(0), | 1524 clear_blue_(0), |
1533 clear_alpha_(0), | 1525 clear_alpha_(0), |
1534 mask_red_(true), | 1526 mask_red_(true), |
1535 mask_green_(true), | 1527 mask_green_(true), |
1536 mask_blue_(true), | 1528 mask_blue_(true), |
1537 mask_alpha_(true), | 1529 mask_alpha_(true), |
1538 clear_stencil_(0), | 1530 clear_stencil_(0), |
1539 mask_stencil_front_(-1), | 1531 mask_stencil_front_(-1), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 // OpenGL ES 2.0 does not have this issue. | 1601 // OpenGL ES 2.0 does not have this issue. |
1610 glEnableVertexAttribArray(0); | 1602 glEnableVertexAttribArray(0); |
1611 glGenBuffersARB(1, &attrib_0_buffer_id_); | 1603 glGenBuffersARB(1, &attrib_0_buffer_id_); |
1612 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); | 1604 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
1613 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); | 1605 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); |
1614 glBindBuffer(GL_ARRAY_BUFFER, 0); | 1606 glBindBuffer(GL_ARRAY_BUFFER, 0); |
1615 | 1607 |
1616 texture_units_.reset( | 1608 texture_units_.reset( |
1617 new TextureUnit[group_->max_texture_units()]); | 1609 new TextureUnit[group_->max_texture_units()]); |
1618 for (uint32 tt = 0; tt < group_->max_texture_units(); ++tt) { | 1610 for (uint32 tt = 0; tt < group_->max_texture_units(); ++tt) { |
1619 texture_units_[tt].bound_texture_2d = | 1611 glActiveTexture(GL_TEXTURE0 + tt); |
1620 texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); | 1612 // Do cube map first because we want the last bind to be 2D. |
1621 texture_units_[tt].bound_texture_cube_map = | 1613 TextureManager::TextureInfo* info = |
1622 texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); | 1614 texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); |
| 1615 texture_units_[tt].bound_texture_cube_map = info; |
| 1616 glBindTexture(GL_TEXTURE_CUBE_MAP, info->service_id()); |
| 1617 info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
| 1618 texture_units_[tt].bound_texture_2d = info; |
| 1619 glBindTexture(GL_TEXTURE_2D, info->service_id()); |
1623 } | 1620 } |
1624 | 1621 glActiveTexture(GL_TEXTURE0); |
1625 GLuint ids[2]; | |
1626 glGenTextures(2, ids); | |
1627 // Make black textures for replacing non-renderable textures. | |
1628 black_2d_texture_id_ = ids[0]; | |
1629 black_cube_texture_id_ = ids[1]; | |
1630 static uint8 black[] = {0, 0, 0, 255}; | |
1631 glBindTexture(GL_TEXTURE_2D, black_2d_texture_id_); | |
1632 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, | |
1633 GL_UNSIGNED_BYTE, black); | |
1634 glBindTexture(GL_TEXTURE_2D, 0); | |
1635 glBindTexture(GL_TEXTURE_CUBE_MAP, black_cube_texture_id_); | |
1636 for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { | |
1637 glTexImage2D(GLES2Util::IndexToGLFaceTarget(ii), 0, GL_RGBA, 1, 1, 0, | |
1638 GL_RGBA, GL_UNSIGNED_BYTE, black); | |
1639 } | |
1640 glBindTexture(GL_TEXTURE_CUBE_MAP, 0); | |
1641 CHECK_GL_ERROR(); | 1622 CHECK_GL_ERROR(); |
1642 | 1623 |
1643 if (context_->IsOffscreen()) { | 1624 if (context_->IsOffscreen()) { |
1644 // Create the target frame buffer. This is the one that the client renders | 1625 // Create the target frame buffer. This is the one that the client renders |
1645 // directly to. | 1626 // directly to. |
1646 offscreen_target_frame_buffer_.reset(new FrameBuffer(this)); | 1627 offscreen_target_frame_buffer_.reset(new FrameBuffer(this)); |
1647 offscreen_target_frame_buffer_->Create(); | 1628 offscreen_target_frame_buffer_->Create(); |
1648 offscreen_target_color_texture_.reset(new Texture(this)); | 1629 offscreen_target_color_texture_.reset(new Texture(this)); |
1649 offscreen_target_color_texture_->Create(); | 1630 offscreen_target_color_texture_->Create(); |
1650 offscreen_target_depth_render_buffer_.reset( | 1631 offscreen_target_depth_render_buffer_.reset( |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 } | 2089 } |
2109 if (fragment_compiler_ != NULL) { | 2090 if (fragment_compiler_ != NULL) { |
2110 ShDestruct(fragment_compiler_); | 2091 ShDestruct(fragment_compiler_); |
2111 fragment_compiler_ = NULL; | 2092 fragment_compiler_ = NULL; |
2112 } | 2093 } |
2113 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER) | 2094 #endif // GLES2_GPU_SERVICE_TRANSLATE_SHADER) |
2114 | 2095 |
2115 if (context_.get()) { | 2096 if (context_.get()) { |
2116 MakeCurrent(); | 2097 MakeCurrent(); |
2117 | 2098 |
2118 if (black_2d_texture_id_) { | |
2119 glDeleteTextures(1, &black_2d_texture_id_); | |
2120 } | |
2121 if (black_cube_texture_id_) { | |
2122 glDeleteTextures(1, &black_cube_texture_id_); | |
2123 } | |
2124 if (attrib_0_buffer_id_) { | 2099 if (attrib_0_buffer_id_) { |
2125 glDeleteBuffersARB(1, &attrib_0_buffer_id_); | 2100 glDeleteBuffersARB(1, &attrib_0_buffer_id_); |
2126 } | 2101 } |
2127 | 2102 |
2128 // Remove the saved frame buffer mapping from the parent decoder. The | 2103 // Remove the saved frame buffer mapping from the parent decoder. The |
2129 // parent pointer is a weak pointer so it will be null if the parent has | 2104 // parent pointer is a weak pointer so it will be null if the parent has |
2130 // already been destroyed. | 2105 // already been destroyed. |
2131 if (parent_) { | 2106 if (parent_) { |
2132 // First check the texture has been mapped into the parent. This might not | 2107 // First check the texture has been mapped into the parent. This might not |
2133 // be the case if initialization failed midway through. | 2108 // be the case if initialization failed midway through. |
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3457 TextureManager::TextureInfo* texture_info = | 3432 TextureManager::TextureInfo* texture_info = |
3458 uniform_info->type == GL_SAMPLER_2D ? | 3433 uniform_info->type == GL_SAMPLER_2D ? |
3459 texture_unit.bound_texture_2d : | 3434 texture_unit.bound_texture_2d : |
3460 texture_unit.bound_texture_cube_map; | 3435 texture_unit.bound_texture_cube_map; |
3461 if (!texture_info || !texture_info->CanRender(texture_manager())) { | 3436 if (!texture_info || !texture_info->CanRender(texture_manager())) { |
3462 textures_set = true; | 3437 textures_set = true; |
3463 glActiveTexture(GL_TEXTURE0 + texture_unit_index); | 3438 glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
3464 glBindTexture( | 3439 glBindTexture( |
3465 uniform_info->type == GL_SAMPLER_2D ? GL_TEXTURE_2D : | 3440 uniform_info->type == GL_SAMPLER_2D ? GL_TEXTURE_2D : |
3466 GL_TEXTURE_CUBE_MAP, | 3441 GL_TEXTURE_CUBE_MAP, |
3467 uniform_info->type == GL_SAMPLER_2D ? black_2d_texture_id_ : | 3442 texture_manager()->black_texture_id(uniform_info->type)); |
3468 black_cube_texture_id_); | |
3469 } | 3443 } |
3470 } | 3444 } |
3471 // else: should this be an error? | 3445 // else: should this be an error? |
3472 } | 3446 } |
3473 } | 3447 } |
3474 return textures_set; | 3448 return textures_set; |
3475 } | 3449 } |
3476 | 3450 |
3477 void GLES2DecoderImpl::RestoreStateForNonRenderableTextures() { | 3451 void GLES2DecoderImpl::RestoreStateForNonRenderableTextures() { |
3478 DCHECK(current_program_); | 3452 DCHECK(current_program_); |
(...skipping 1882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5361 return error::kNoError; | 5335 return error::kNoError; |
5362 } | 5336 } |
5363 | 5337 |
5364 // Include the auto-generated part of this file. We split this because it means | 5338 // Include the auto-generated part of this file. We split this because it means |
5365 // we can easily edit the non-auto generated parts right here in this file | 5339 // we can easily edit the non-auto generated parts right here in this file |
5366 // instead of having to edit some template or the code generator. | 5340 // instead of having to edit some template or the code generator. |
5367 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 5341 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
5368 | 5342 |
5369 } // namespace gles2 | 5343 } // namespace gles2 |
5370 } // namespace gpu | 5344 } // namespace gpu |
OLD | NEW |