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

Side by Side Diff: gpu/command_buffer/service/feature_info.cc

Issue 2713553005: Add GL_EXT_color_buffer_half_float support (Closed)
Patch Set: Created 3 years, 10 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
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 #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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 validators_.texture_sized_color_renderable_internal_format.AddValue(GL_R16F); 226 validators_.texture_sized_color_renderable_internal_format.AddValue(GL_R16F);
227 validators_.texture_sized_color_renderable_internal_format.AddValue(GL_RG16F); 227 validators_.texture_sized_color_renderable_internal_format.AddValue(GL_RG16F);
228 validators_.texture_sized_color_renderable_internal_format.AddValue( 228 validators_.texture_sized_color_renderable_internal_format.AddValue(
229 GL_RGBA16F); 229 GL_RGBA16F);
230 validators_.texture_sized_color_renderable_internal_format.AddValue(GL_R32F); 230 validators_.texture_sized_color_renderable_internal_format.AddValue(GL_R32F);
231 validators_.texture_sized_color_renderable_internal_format.AddValue(GL_RG32F); 231 validators_.texture_sized_color_renderable_internal_format.AddValue(GL_RG32F);
232 validators_.texture_sized_color_renderable_internal_format.AddValue( 232 validators_.texture_sized_color_renderable_internal_format.AddValue(
233 GL_RGBA32F); 233 GL_RGBA32F);
234 validators_.texture_sized_color_renderable_internal_format.AddValue( 234 validators_.texture_sized_color_renderable_internal_format.AddValue(
235 GL_R11F_G11F_B10F); 235 GL_R11F_G11F_B10F);
236 feature_flags_.enable_color_buffer_float = true; 236 }
237
238 void FeatureInfo::EnableEXTColorBufferHalfFloat() {
239 if (!feature_flags_.enable_color_buffer_half_float)
240 return;
241 AddExtensionString("GL_EXT_color_buffer_half_float");
242 validators_.render_buffer_format.AddValue(GL_R16F);
243 validators_.render_buffer_format.AddValue(GL_RG16F);
244 validators_.render_buffer_format.AddValue(GL_RGB16F);
245 validators_.render_buffer_format.AddValue(GL_RGBA16F);
246 validators_.texture_sized_color_renderable_internal_format.AddValue(GL_R16F);
247 validators_.texture_sized_color_renderable_internal_format.AddValue(GL_RG16F);
248 validators_.texture_sized_color_renderable_internal_format.AddValue(
249 GL_RGB16F);
250 validators_.texture_sized_color_renderable_internal_format.AddValue(
251 GL_RGBA16F);
237 } 252 }
238 253
239 void FeatureInfo::EnableCHROMIUMColorBufferFloatRGBA() { 254 void FeatureInfo::EnableCHROMIUMColorBufferFloatRGBA() {
240 if (!feature_flags_.chromium_color_buffer_float_rgba) 255 if (!feature_flags_.chromium_color_buffer_float_rgba)
241 return; 256 return;
242 validators_.texture_internal_format.AddValue(GL_RGBA32F); 257 validators_.texture_internal_format.AddValue(GL_RGBA32F);
243 validators_.texture_sized_color_renderable_internal_format.AddValue( 258 validators_.texture_sized_color_renderable_internal_format.AddValue(
244 GL_RGBA32F); 259 GL_RGBA32F);
245 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgba"); 260 AddExtensionString("GL_CHROMIUM_color_buffer_float_rgba");
246 } 261 }
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 // Check if we should allow GL_OES_texture_float, GL_OES_texture_half_float, 743 // Check if we should allow GL_OES_texture_float, GL_OES_texture_half_float,
729 // GL_OES_texture_float_linear, GL_OES_texture_half_float_linear 744 // GL_OES_texture_float_linear, GL_OES_texture_half_float_linear
730 bool enable_texture_float = false; 745 bool enable_texture_float = false;
731 bool enable_texture_float_linear = false; 746 bool enable_texture_float_linear = false;
732 bool enable_texture_half_float = false; 747 bool enable_texture_half_float = false;
733 bool enable_texture_half_float_linear = false; 748 bool enable_texture_half_float_linear = false;
734 bool enable_ext_color_buffer_float = false; 749 bool enable_ext_color_buffer_float = false;
735 750
736 bool may_enable_chromium_color_buffer_float = false; 751 bool may_enable_chromium_color_buffer_float = false;
737 752
738 // This extension allows a variety of floating point formats to be 753 // These extensions allow a variety of floating point formats to be
739 // rendered to via framebuffer objects. 754 // rendered to via framebuffer objects.
740 if (extensions.Contains("GL_EXT_color_buffer_float")) { 755 if (extensions.Contains("GL_EXT_color_buffer_float"))
741 enable_ext_color_buffer_float = true; 756 enable_ext_color_buffer_float = true;
742 } 757 if (extensions.Contains("GL_EXT_color_buffer_half_float"))
758 feature_flags_.enable_color_buffer_half_float = true;
743 759
744 if (extensions.Contains("GL_ARB_texture_float") || 760 if (extensions.Contains("GL_ARB_texture_float") ||
745 gl_version_info_->is_desktop_core_profile) { 761 gl_version_info_->is_desktop_core_profile) {
746 enable_texture_float = true; 762 enable_texture_float = true;
747 enable_texture_float_linear = true; 763 enable_texture_float_linear = true;
748 enable_texture_half_float = true; 764 enable_texture_half_float = true;
749 enable_texture_half_float_linear = true; 765 enable_texture_half_float_linear = true;
750 may_enable_chromium_color_buffer_float = true; 766 may_enable_chromium_color_buffer_float = true;
751 } else { 767 } else {
752 // GLES3 adds support for Float type by default but it doesn't support all 768 // GLES3 adds support for Float type by default but it doesn't support all
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 GL_TEXTURE_2D, tex_id, 0); 844 GL_TEXTURE_2D, tex_id, 0);
829 GLenum status_rgba = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 845 GLenum status_rgba = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
830 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, width, 0, GL_RGB, 846 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, width, 0, GL_RGB,
831 GL_FLOAT, NULL); 847 GL_FLOAT, NULL);
832 GLenum status_rgb = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 848 GLenum status_rgb = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
833 849
834 // For desktop systems, check to see if we support rendering to the full 850 // For desktop systems, check to see if we support rendering to the full
835 // range of formats supported by EXT_color_buffer_float 851 // range of formats supported by EXT_color_buffer_float
836 if (status_rgba == GL_FRAMEBUFFER_COMPLETE && enable_es3) { 852 if (status_rgba == GL_FRAMEBUFFER_COMPLETE && enable_es3) {
837 bool full_float_support = true; 853 bool full_float_support = true;
838 854 GLenum internal_formats[] = {
839 glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, width, width, 0, GL_RED, 855 GL_R16F, GL_RG16F, GL_RGBA16F, GL_R32F, GL_RG32F, GL_R11F_G11F_B10F,
840 GL_FLOAT, NULL); 856 };
841 full_float_support &= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) == 857 GLenum formats[] = {
842 GL_FRAMEBUFFER_COMPLETE; 858 GL_RED, GL_RG, GL_RGBA, GL_RED, GL_RG, GL_RGB,
843 glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, width, width, 0, GL_RG, 859 };
844 GL_FLOAT, NULL); 860 DCHECK_EQ(arraysize(internal_formats), arraysize(formats));
845 full_float_support &= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) == 861 for (size_t i = 0; i < arraysize(formats); ++i) {
846 GL_FRAMEBUFFER_COMPLETE; 862 glTexImage2D(GL_TEXTURE_2D, 0, internal_formats[i], width, width, 0,
847 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, width, 0, GL_RGBA, 863 formats[i], GL_FLOAT, NULL);
848 GL_FLOAT, NULL); 864 full_float_support &= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) ==
849 full_float_support &= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) == 865 GL_FRAMEBUFFER_COMPLETE;
850 GL_FRAMEBUFFER_COMPLETE; 866 }
851 glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, width, width, 0, GL_RED,
852 GL_FLOAT, NULL);
853 full_float_support &= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) ==
854 GL_FRAMEBUFFER_COMPLETE;
855 glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32F, width, width, 0, GL_RG,
856 GL_FLOAT, NULL);
857 full_float_support &= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) ==
858 GL_FRAMEBUFFER_COMPLETE;
859 glTexImage2D(GL_TEXTURE_2D, 0, GL_R11F_G11F_B10F, width, width, 0, GL_RGB,
860 GL_FLOAT, NULL);
861 full_float_support &= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) ==
862 GL_FRAMEBUFFER_COMPLETE;
863
864 enable_ext_color_buffer_float = full_float_support; 867 enable_ext_color_buffer_float = full_float_support;
865 } 868 }
869 // Likewise for EXT_color_buffer_half_float on ES2 contexts.
870 if (context_type_ == CONTEXT_TYPE_OPENGLES2 &&
Zhenyao Mo 2017/02/23 00:36:57 or WebGL1 Since you are working on it for interna
ccameron 2017/02/23 02:11:57 Done.
871 !feature_flags_.enable_color_buffer_half_float) {
872 bool full_half_float_support = true;
873 GLenum internal_formats[] = {
874 GL_R16F, GL_RG16F, GL_RGB16F, GL_RGBA16F,
875 };
876 GLenum formats[] = {
877 GL_RED, GL_RG, GL_RGB, GL_RGBA,
878 };
879 DCHECK_EQ(arraysize(internal_formats), arraysize(formats));
880 for (size_t i = 0; i < arraysize(formats); ++i) {
881 glTexImage2D(GL_TEXTURE_2D, 0, internal_formats[i], width, width, 0,
882 formats[i], GL_FLOAT, NULL);
883 full_half_float_support &=
884 glCheckFramebufferStatusEXT(GL_FRAMEBUFFER) ==
885 GL_FRAMEBUFFER_COMPLETE;
886 }
887 feature_flags_.enable_color_buffer_half_float = full_half_float_support;
888 }
866 889
867 glDeleteFramebuffersEXT(1, &fb_id); 890 glDeleteFramebuffersEXT(1, &fb_id);
868 glDeleteTextures(1, &tex_id); 891 glDeleteTextures(1, &tex_id);
869 892
870 glBindFramebufferEXT(GL_FRAMEBUFFER, static_cast<GLuint>(fb_binding)); 893 glBindFramebufferEXT(GL_FRAMEBUFFER, static_cast<GLuint>(fb_binding));
871 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(tex_binding)); 894 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(tex_binding));
872 895
873 DCHECK(glGetError() == GL_NO_ERROR); 896 DCHECK(glGetError() == GL_NO_ERROR);
874 897
875 if (status_rgba == GL_FRAMEBUFFER_COMPLETE) { 898 if (status_rgba == GL_FRAMEBUFFER_COMPLETE) {
876 feature_flags_.chromium_color_buffer_float_rgba = true; 899 feature_flags_.chromium_color_buffer_float_rgba = true;
877 if (!disallowed_features_.chromium_color_buffer_float_rgba) 900 if (!disallowed_features_.chromium_color_buffer_float_rgba)
878 EnableCHROMIUMColorBufferFloatRGBA(); 901 EnableCHROMIUMColorBufferFloatRGBA();
879 } 902 }
880 if (status_rgb == GL_FRAMEBUFFER_COMPLETE) { 903 if (status_rgb == GL_FRAMEBUFFER_COMPLETE) {
881 feature_flags_.chromium_color_buffer_float_rgb = true; 904 feature_flags_.chromium_color_buffer_float_rgb = true;
882 if (!disallowed_features_.chromium_color_buffer_float_rgb) 905 if (!disallowed_features_.chromium_color_buffer_float_rgb)
883 EnableCHROMIUMColorBufferFloatRGB(); 906 EnableCHROMIUMColorBufferFloatRGB();
884 } 907 }
885 } 908 }
886 909
887 // Enable the GL_EXT_color_buffer_float extension for WebGL 2.0 910 // Enable the GL_EXT_color_buffer_float extension for WebGL 2.0
888 if (enable_ext_color_buffer_float && enable_es3) { 911 if (enable_ext_color_buffer_float && enable_es3) {
889 ext_color_buffer_float_available_ = true; 912 ext_color_buffer_float_available_ = true;
890 if (!disallowed_features_.ext_color_buffer_float) 913 if (!disallowed_features_.ext_color_buffer_float)
891 EnableEXTColorBufferFloat(); 914 EnableEXTColorBufferFloat();
892 } 915 }
893 916
917 // Enable GL_EXT_color_buffer_half_float if we have found the capability.
918 EnableEXTColorBufferHalfFloat();
Zhenyao Mo 2017/02/23 00:36:57 You can't enable this by default on WebGL contexts
ccameron 2017/02/23 02:11:57 Disallowed for WebGL 2.
919
894 // Check for multisample support 920 // Check for multisample support
895 if (!workarounds_.disable_chromium_framebuffer_multisample) { 921 if (!workarounds_.disable_chromium_framebuffer_multisample) {
896 bool ext_has_multisample = 922 bool ext_has_multisample =
897 extensions.Contains("GL_EXT_framebuffer_multisample") || 923 extensions.Contains("GL_EXT_framebuffer_multisample") ||
898 gl_version_info_->is_es3 || 924 gl_version_info_->is_es3 ||
899 gl_version_info_->is_desktop_core_profile; 925 gl_version_info_->is_desktop_core_profile;
900 if (gl_version_info_->is_angle) { 926 if (gl_version_info_->is_angle) {
901 feature_flags_.angle_framebuffer_multisample = 927 feature_flags_.angle_framebuffer_multisample =
902 extensions.Contains("GL_ANGLE_framebuffer_multisample"); 928 extensions.Contains("GL_ANGLE_framebuffer_multisample");
903 ext_has_multisample |= feature_flags_.angle_framebuffer_multisample; 929 ext_has_multisample |= feature_flags_.angle_framebuffer_multisample;
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 if (pos == std::string::npos) { 1554 if (pos == std::string::npos) {
1529 extensions_ += (extensions_.empty() ? "" : " ") + str; 1555 extensions_ += (extensions_.empty() ? "" : " ") + str;
1530 } 1556 }
1531 } 1557 }
1532 1558
1533 FeatureInfo::~FeatureInfo() { 1559 FeatureInfo::~FeatureInfo() {
1534 } 1560 }
1535 1561
1536 } // namespace gles2 1562 } // namespace gles2
1537 } // namespace gpu 1563 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/feature_info.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698