Chromium Code Reviews| 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/feature_info.h" | 5 #include "gpu/command_buffer/service/feature_info.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 ~ScopedPixelUnpackBufferOverride() { | 99 ~ScopedPixelUnpackBufferOverride() { |
| 100 if (orig_binding_ != -1) { | 100 if (orig_binding_ != -1) { |
| 101 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, static_cast<GLuint>(orig_binding_)); | 101 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, static_cast<GLuint>(orig_binding_)); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 GLint orig_binding_; | 106 GLint orig_binding_; |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 bool IsWebGLDrawBuffersSupported(bool has_depth_texture, | |
| 110 bool has_depth_stencil_texture) { | |
| 111 // This is called after we make sure GL_EXT_draw_buffers is supported. | |
| 112 | |
| 113 GLint fb_binding = 0; | |
| 114 GLint tex_binding = 0; | |
| 115 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fb_binding); | |
| 116 glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex_binding); | |
| 117 | |
| 118 GLint max_draw_buffers = 0; | |
| 119 GLint max_color_attachments = 0; | |
| 120 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max_draw_buffers); | |
| 121 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &max_color_attachments); | |
| 122 if (max_draw_buffers < 4 || max_color_attachments < 4) | |
| 123 return false; | |
| 124 | |
| 125 GLuint fbo; | |
| 126 glGenFramebuffersEXT(1, &fbo); | |
| 127 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo); | |
| 128 | |
| 129 GLuint depth_stencil = 0; | |
| 130 if (has_depth_stencil_texture) { | |
| 131 glGenTextures(1, &depth_stencil); | |
| 132 glBindTexture(GL_TEXTURE_2D, depth_stencil); | |
| 133 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL, 1, 1, 0, GL_DEPTH_STENCIL, | |
|
Zhenyao Mo
2017/02/23 00:12:43
Juts want to make sure this (unsized internal form
Ken Russell (switch to Gerrit)
2017/02/23 01:46:26
I don't remember exactly at this point -- but grep
| |
| 134 GL_UNSIGNED_INT_24_8, nullptr); | |
| 135 } | |
| 136 | |
| 137 GLuint depth = 0; | |
| 138 if (has_depth_texture) { | |
| 139 glGenTextures(1, &depth); | |
| 140 glBindTexture(GL_TEXTURE_2D, depth); | |
| 141 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1, 1, 0, | |
|
Zhenyao Mo
2017/02/23 00:12:43
Same here.
| |
| 142 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); | |
| 143 } | |
| 144 | |
| 145 GLint max_allowed_buffers = std::min(max_draw_buffers, max_color_attachments); | |
| 146 std::vector<GLuint> colors(max_allowed_buffers, 0); | |
| 147 glGenTextures(max_allowed_buffers, colors.data()); | |
| 148 | |
| 149 bool result = true; | |
| 150 for (GLint i = 0; i < max_allowed_buffers; ++i) { | |
| 151 GLint color = colors[i]; | |
| 152 glBindTexture(GL_TEXTURE_2D, color); | |
| 153 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, | |
| 154 nullptr); | |
| 155 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, | |
| 156 GL_TEXTURE_2D, color, 0); | |
| 157 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) != | |
| 158 GL_FRAMEBUFFER_COMPLETE) { | |
| 159 result = false; | |
| 160 break; | |
| 161 } | |
| 162 if (has_depth_texture) { | |
| 163 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | |
| 164 GL_TEXTURE_2D, depth, 0); | |
| 165 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) != | |
| 166 GL_FRAMEBUFFER_COMPLETE) { | |
| 167 result = false; | |
| 168 break; | |
| 169 } | |
| 170 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | |
| 171 GL_TEXTURE_2D, 0, 0); | |
| 172 } | |
| 173 if (has_depth_stencil_texture) { | |
| 174 // For ES 2.0 contexts DEPTH_STENCIL is not available natively, so we | |
| 175 // emulate it at the command buffer level for WebGL contexts. | |
| 176 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, | |
| 177 GL_TEXTURE_2D, depth_stencil, 0); | |
| 178 if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) != | |
| 179 GL_FRAMEBUFFER_COMPLETE) { | |
| 180 result = false; | |
| 181 break; | |
| 182 } | |
| 183 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, | |
| 184 GL_TEXTURE_2D, 0, 0); | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 glBindFramebufferEXT(GL_FRAMEBUFFER, static_cast<GLuint>(fb_binding)); | |
| 189 glDeleteFramebuffersEXT(1, &fbo); | |
| 190 | |
| 191 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(tex_binding)); | |
| 192 if (has_depth_texture) { | |
| 193 glDeleteTextures(1, &depth); | |
| 194 } | |
| 195 if (has_depth_stencil_texture) { | |
| 196 glDeleteTextures(1, &depth_stencil); | |
| 197 } | |
| 198 glDeleteTextures(colors.size(), colors.data()); | |
| 199 | |
| 200 DCHECK(glGetError() == GL_NO_ERROR); | |
| 201 | |
| 202 return result; | |
| 203 } | |
| 204 | |
| 109 } // anonymous namespace. | 205 } // anonymous namespace. |
| 110 | 206 |
| 111 FeatureInfo::FeatureFlags::FeatureFlags() {} | 207 FeatureInfo::FeatureFlags::FeatureFlags() {} |
| 112 | 208 |
| 113 FeatureInfo::FeatureInfo() { | 209 FeatureInfo::FeatureInfo() { |
| 114 InitializeBasicState(base::CommandLine::InitializedForCurrentProcess() | 210 InitializeBasicState(base::CommandLine::InitializedForCurrentProcess() |
| 115 ? base::CommandLine::ForCurrentProcess() | 211 ? base::CommandLine::ForCurrentProcess() |
| 116 : nullptr); | 212 : nullptr); |
| 117 } | 213 } |
| 118 | 214 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 AddExtensionString("GL_CHROMIUM_depth_texture"); | 557 AddExtensionString("GL_CHROMIUM_depth_texture"); |
| 462 AddExtensionString("GL_GOOGLE_depth_texture"); | 558 AddExtensionString("GL_GOOGLE_depth_texture"); |
| 463 validators_.texture_internal_format.AddValue(GL_DEPTH_COMPONENT); | 559 validators_.texture_internal_format.AddValue(GL_DEPTH_COMPONENT); |
| 464 validators_.texture_format.AddValue(GL_DEPTH_COMPONENT); | 560 validators_.texture_format.AddValue(GL_DEPTH_COMPONENT); |
| 465 validators_.pixel_type.AddValue(GL_UNSIGNED_SHORT); | 561 validators_.pixel_type.AddValue(GL_UNSIGNED_SHORT); |
| 466 validators_.pixel_type.AddValue(GL_UNSIGNED_INT); | 562 validators_.pixel_type.AddValue(GL_UNSIGNED_INT); |
| 467 validators_.texture_depth_renderable_internal_format.AddValue( | 563 validators_.texture_depth_renderable_internal_format.AddValue( |
| 468 GL_DEPTH_COMPONENT); | 564 GL_DEPTH_COMPONENT); |
| 469 } | 565 } |
| 470 | 566 |
| 567 bool enable_depth_stencil_texture = false; | |
| 471 if (extensions.Contains("GL_EXT_packed_depth_stencil") || | 568 if (extensions.Contains("GL_EXT_packed_depth_stencil") || |
| 472 extensions.Contains("GL_OES_packed_depth_stencil") || | 569 extensions.Contains("GL_OES_packed_depth_stencil") || |
| 473 gl_version_info_->is_es3 || | 570 gl_version_info_->is_es3 || |
| 474 gl_version_info_->is_desktop_core_profile) { | 571 gl_version_info_->is_desktop_core_profile) { |
| 475 AddExtensionString("GL_OES_packed_depth_stencil"); | 572 AddExtensionString("GL_OES_packed_depth_stencil"); |
| 476 feature_flags_.packed_depth24_stencil8 = true; | 573 feature_flags_.packed_depth24_stencil8 = true; |
| 477 if (enable_depth_texture) { | 574 if (enable_depth_texture) { |
| 575 enable_depth_stencil_texture = true; | |
| 478 validators_.texture_internal_format.AddValue(GL_DEPTH_STENCIL); | 576 validators_.texture_internal_format.AddValue(GL_DEPTH_STENCIL); |
| 479 validators_.texture_format.AddValue(GL_DEPTH_STENCIL); | 577 validators_.texture_format.AddValue(GL_DEPTH_STENCIL); |
| 480 validators_.pixel_type.AddValue(GL_UNSIGNED_INT_24_8); | 578 validators_.pixel_type.AddValue(GL_UNSIGNED_INT_24_8); |
| 481 validators_.texture_depth_renderable_internal_format.AddValue( | 579 validators_.texture_depth_renderable_internal_format.AddValue( |
| 482 GL_DEPTH_STENCIL); | 580 GL_DEPTH_STENCIL); |
| 483 validators_.texture_stencil_renderable_internal_format.AddValue( | 581 validators_.texture_stencil_renderable_internal_format.AddValue( |
| 484 GL_DEPTH_STENCIL); | 582 GL_DEPTH_STENCIL); |
| 485 } | 583 } |
| 486 validators_.render_buffer_format.AddValue(GL_DEPTH24_STENCIL8); | 584 validators_.render_buffer_format.AddValue(GL_DEPTH24_STENCIL8); |
| 487 if (context_type_ == CONTEXT_TYPE_WEBGL1) { | 585 if (context_type_ == CONTEXT_TYPE_WEBGL1) { |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1154 feature_flags_.angle_instanced_arrays = true; | 1252 feature_flags_.angle_instanced_arrays = true; |
| 1155 validators_.vertex_attribute.AddValue(GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE); | 1253 validators_.vertex_attribute.AddValue(GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE); |
| 1156 } | 1254 } |
| 1157 | 1255 |
| 1158 bool have_es2_draw_buffers_vendor_agnostic = | 1256 bool have_es2_draw_buffers_vendor_agnostic = |
| 1159 gl_version_info_->is_desktop_core_profile || | 1257 gl_version_info_->is_desktop_core_profile || |
| 1160 extensions.Contains("GL_ARB_draw_buffers") || | 1258 extensions.Contains("GL_ARB_draw_buffers") || |
| 1161 extensions.Contains("GL_EXT_draw_buffers"); | 1259 extensions.Contains("GL_EXT_draw_buffers"); |
| 1162 bool can_emulate_es2_draw_buffers_on_es3_nv = | 1260 bool can_emulate_es2_draw_buffers_on_es3_nv = |
| 1163 gl_version_info_->is_es3 && extensions.Contains("GL_NV_draw_buffers"); | 1261 gl_version_info_->is_es3 && extensions.Contains("GL_NV_draw_buffers"); |
| 1164 bool have_es2_draw_buffers = !workarounds_.disable_ext_draw_buffers && | 1262 bool have_es2_draw_buffers = |
| 1165 IsWebGL1OrES2Context() && | 1263 !workarounds_.disable_ext_draw_buffers && |
| 1166 (have_es2_draw_buffers_vendor_agnostic || | 1264 (have_es2_draw_buffers_vendor_agnostic || |
| 1167 can_emulate_es2_draw_buffers_on_es3_nv); | 1265 can_emulate_es2_draw_buffers_on_es3_nv) && |
| 1266 (context_type_ == CONTEXT_TYPE_OPENGLES2 || | |
| 1267 (context_type_ == CONTEXT_TYPE_WEBGL1 && | |
| 1268 IsWebGLDrawBuffersSupported(enable_depth_texture, | |
| 1269 enable_depth_stencil_texture))); | |
| 1168 if (have_es2_draw_buffers) { | 1270 if (have_es2_draw_buffers) { |
| 1169 AddExtensionString("GL_EXT_draw_buffers"); | 1271 AddExtensionString("GL_EXT_draw_buffers"); |
| 1170 feature_flags_.ext_draw_buffers = true; | 1272 feature_flags_.ext_draw_buffers = true; |
| 1171 | 1273 |
| 1172 // This flag is set to enable emulation of EXT_draw_buffers when we're | 1274 // This flag is set to enable emulation of EXT_draw_buffers when we're |
| 1173 // running on GLES 3.0+, NV_draw_buffers extension is supported and | 1275 // running on GLES 3.0+, NV_draw_buffers extension is supported and |
| 1174 // glDrawBuffers from GLES 3.0 core has been bound. It toggles using the | 1276 // glDrawBuffers from GLES 3.0 core has been bound. It toggles using the |
| 1175 // NV_draw_buffers extension directive instead of EXT_draw_buffers extension | 1277 // NV_draw_buffers extension directive instead of EXT_draw_buffers extension |
| 1176 // directive in ESSL 100 shaders translated by ANGLE, enabling them to write | 1278 // directive in ESSL 100 shaders translated by ANGLE, enabling them to write |
| 1177 // into multiple gl_FragData values, which is not by default possible in | 1279 // into multiple gl_FragData values, which is not by default possible in |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1550 if (pos == std::string::npos) { | 1652 if (pos == std::string::npos) { |
| 1551 extensions_ += (extensions_.empty() ? "" : " ") + str; | 1653 extensions_ += (extensions_.empty() ? "" : " ") + str; |
| 1552 } | 1654 } |
| 1553 } | 1655 } |
| 1554 | 1656 |
| 1555 FeatureInfo::~FeatureInfo() { | 1657 FeatureInfo::~FeatureInfo() { |
| 1556 } | 1658 } |
| 1557 | 1659 |
| 1558 } // namespace gles2 | 1660 } // namespace gles2 |
| 1559 } // namespace gpu | 1661 } // namespace gpu |
| OLD | NEW |