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/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; | 98 const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
99 const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; | 99 const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; |
100 const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; | 100 const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; |
101 const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod"; | 101 const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod"; |
102 | 102 |
103 const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, | 103 const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
104 0.0f, 1.0f, 0.0f, 0.0f, | 104 0.0f, 1.0f, 0.0f, 0.0f, |
105 0.0f, 0.0f, 1.0f, 0.0f, | 105 0.0f, 0.0f, 1.0f, 0.0f, |
106 0.0f, 0.0f, 0.0f, 1.0f}; | 106 0.0f, 0.0f, 0.0f, 1.0f}; |
107 | 107 |
108 bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, | |
109 GLint rangeMax, | |
110 GLint precision) { | |
111 return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16); | |
112 } | |
113 | |
114 void GetShaderPrecisionFormatImpl(const gl::GLVersionInfo& gl_version_info, | |
115 GLenum shader_type, | |
116 GLenum precision_type, | |
117 GLint* range, | |
118 GLint* precision) { | |
119 switch (precision_type) { | |
120 case GL_LOW_INT: | |
121 case GL_MEDIUM_INT: | |
122 case GL_HIGH_INT: | |
123 // These values are for a 32-bit twos-complement integer format. | |
124 range[0] = 31; | |
125 range[1] = 30; | |
126 *precision = 0; | |
127 break; | |
128 case GL_LOW_FLOAT: | |
129 case GL_MEDIUM_FLOAT: | |
130 case GL_HIGH_FLOAT: | |
131 // These values are for an IEEE single-precision floating-point format. | |
132 range[0] = 127; | |
133 range[1] = 127; | |
134 *precision = 23; | |
135 break; | |
136 default: | |
137 NOTREACHED(); | |
138 break; | |
139 } | |
140 | |
141 if (gl_version_info.is_es) { | |
142 // This function is sometimes defined even though it's really just | |
143 // a stub, so we need to set range and precision as if it weren't | |
144 // defined before calling it. | |
145 // On Mac OS with some GPUs, calling this generates a | |
146 // GL_INVALID_OPERATION error. Avoid calling it on non-GLES2 | |
147 // platforms. | |
148 glGetShaderPrecisionFormat(shader_type, precision_type, | |
149 range, precision); | |
150 | |
151 // TODO(brianderson): Make the following official workarounds. | |
152 | |
153 // Some drivers have bugs where they report the ranges as a negative number. | |
154 // Taking the absolute value here shouldn't hurt because negative numbers | |
155 // aren't expected anyway. | |
156 range[0] = abs(range[0]); | |
157 range[1] = abs(range[1]); | |
158 | |
159 // If the driver reports a precision for highp float that isn't actually | |
160 // highp, don't pretend like it's supported because shader compilation will | |
161 // fail anyway. | |
162 if (precision_type == GL_HIGH_FLOAT && | |
163 !PrecisionMeetsSpecForHighpFloat(range[0], range[1], *precision)) { | |
164 range[0] = 0; | |
165 range[1] = 0; | |
166 *precision = 0; | |
167 } | |
168 } | |
169 } | |
170 | |
171 gfx::OverlayTransform GetGFXOverlayTransform(GLenum plane_transform) { | 108 gfx::OverlayTransform GetGFXOverlayTransform(GLenum plane_transform) { |
172 switch (plane_transform) { | 109 switch (plane_transform) { |
173 case GL_OVERLAY_TRANSFORM_NONE_CHROMIUM: | 110 case GL_OVERLAY_TRANSFORM_NONE_CHROMIUM: |
174 return gfx::OVERLAY_TRANSFORM_NONE; | 111 return gfx::OVERLAY_TRANSFORM_NONE; |
175 case GL_OVERLAY_TRANSFORM_FLIP_HORIZONTAL_CHROMIUM: | 112 case GL_OVERLAY_TRANSFORM_FLIP_HORIZONTAL_CHROMIUM: |
176 return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL; | 113 return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL; |
177 case GL_OVERLAY_TRANSFORM_FLIP_VERTICAL_CHROMIUM: | 114 case GL_OVERLAY_TRANSFORM_FLIP_VERTICAL_CHROMIUM: |
178 return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL; | 115 return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL; |
179 case GL_OVERLAY_TRANSFORM_ROTATE_90_CHROMIUM: | 116 case GL_OVERLAY_TRANSFORM_ROTATE_90_CHROMIUM: |
180 return gfx::OVERLAY_TRANSFORM_ROTATE_90; | 117 return gfx::OVERLAY_TRANSFORM_ROTATE_90; |
(...skipping 3325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3506 | 3443 |
3507 Capabilities GLES2DecoderImpl::GetCapabilities() { | 3444 Capabilities GLES2DecoderImpl::GetCapabilities() { |
3508 DCHECK(initialized()); | 3445 DCHECK(initialized()); |
3509 Capabilities caps; | 3446 Capabilities caps; |
3510 const gl::GLVersionInfo& version_info = gl_version_info(); | 3447 const gl::GLVersionInfo& version_info = gl_version_info(); |
3511 caps.VisitPrecisions([&version_info]( | 3448 caps.VisitPrecisions([&version_info]( |
3512 GLenum shader, GLenum type, | 3449 GLenum shader, GLenum type, |
3513 Capabilities::ShaderPrecision* shader_precision) { | 3450 Capabilities::ShaderPrecision* shader_precision) { |
3514 GLint range[2] = {0, 0}; | 3451 GLint range[2] = {0, 0}; |
3515 GLint precision = 0; | 3452 GLint precision = 0; |
3516 GetShaderPrecisionFormatImpl(version_info, shader, type, range, | 3453 QueryShaderPrecisionFormat(version_info, shader, type, range, &precision); |
3517 &precision); | |
3518 shader_precision->min_range = range[0]; | 3454 shader_precision->min_range = range[0]; |
3519 shader_precision->max_range = range[1]; | 3455 shader_precision->max_range = range[1]; |
3520 shader_precision->precision = precision; | 3456 shader_precision->precision = precision; |
3521 }); | 3457 }); |
3522 DoGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, | 3458 DoGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, |
3523 &caps.max_combined_texture_image_units); | 3459 &caps.max_combined_texture_image_units); |
3524 DoGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &caps.max_cube_map_texture_size); | 3460 DoGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &caps.max_cube_map_texture_size); |
3525 DoGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, | 3461 DoGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
3526 &caps.max_fragment_uniform_vectors); | 3462 &caps.max_fragment_uniform_vectors); |
3527 DoGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &caps.max_renderbuffer_size); | 3463 DoGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &caps.max_renderbuffer_size); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3699 resources.MaxVertexOutputVectors = | 3635 resources.MaxVertexOutputVectors = |
3700 group_->max_vertex_output_components() / 4; | 3636 group_->max_vertex_output_components() / 4; |
3701 resources.MaxFragmentInputVectors = | 3637 resources.MaxFragmentInputVectors = |
3702 group_->max_fragment_input_components() / 4; | 3638 group_->max_fragment_input_components() / 4; |
3703 resources.MaxProgramTexelOffset = group_->max_program_texel_offset(); | 3639 resources.MaxProgramTexelOffset = group_->max_program_texel_offset(); |
3704 resources.MinProgramTexelOffset = group_->min_program_texel_offset(); | 3640 resources.MinProgramTexelOffset = group_->min_program_texel_offset(); |
3705 } | 3641 } |
3706 | 3642 |
3707 GLint range[2] = { 0, 0 }; | 3643 GLint range[2] = { 0, 0 }; |
3708 GLint precision = 0; | 3644 GLint precision = 0; |
3709 GetShaderPrecisionFormatImpl(gl_version_info(), GL_FRAGMENT_SHADER, | 3645 QueryShaderPrecisionFormat(gl_version_info(), GL_FRAGMENT_SHADER, |
3710 GL_HIGH_FLOAT, range, &precision); | 3646 GL_HIGH_FLOAT, range, &precision); |
3711 resources.FragmentPrecisionHigh = | 3647 resources.FragmentPrecisionHigh = |
3712 PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision); | 3648 PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision); |
3713 | 3649 |
3714 ShShaderSpec shader_spec; | 3650 ShShaderSpec shader_spec; |
3715 switch (feature_info_->context_type()) { | 3651 switch (feature_info_->context_type()) { |
3716 case CONTEXT_TYPE_WEBGL1: | 3652 case CONTEXT_TYPE_WEBGL1: |
3717 shader_spec = SH_WEBGL_SPEC; | 3653 shader_spec = SH_WEBGL_SPEC; |
3718 resources.OES_standard_derivatives = derivatives_explicitly_enabled_; | 3654 resources.OES_standard_derivatives = derivatives_explicitly_enabled_; |
3719 resources.EXT_frag_depth = frag_depth_explicitly_enabled_; | 3655 resources.EXT_frag_depth = frag_depth_explicitly_enabled_; |
3720 resources.EXT_draw_buffers = draw_buffers_explicitly_enabled_; | 3656 resources.EXT_draw_buffers = draw_buffers_explicitly_enabled_; |
(...skipping 10110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13831 if (!validators_->shader_precision.IsValid(precision_type)) { | 13767 if (!validators_->shader_precision.IsValid(precision_type)) { |
13832 LOCAL_SET_GL_ERROR_INVALID_ENUM( | 13768 LOCAL_SET_GL_ERROR_INVALID_ENUM( |
13833 "glGetShaderPrecisionFormat", precision_type, "precision_type"); | 13769 "glGetShaderPrecisionFormat", precision_type, "precision_type"); |
13834 return error::kNoError; | 13770 return error::kNoError; |
13835 } | 13771 } |
13836 | 13772 |
13837 result->success = 1; // true | 13773 result->success = 1; // true |
13838 | 13774 |
13839 GLint range[2] = { 0, 0 }; | 13775 GLint range[2] = { 0, 0 }; |
13840 GLint precision = 0; | 13776 GLint precision = 0; |
13841 GetShaderPrecisionFormatImpl(gl_version_info(), shader_type, precision_type, | 13777 QueryShaderPrecisionFormat(gl_version_info(), shader_type, precision_type, |
13842 range, &precision); | 13778 range, &precision); |
13843 | 13779 |
13844 result->min_range = range[0]; | 13780 result->min_range = range[0]; |
13845 result->max_range = range[1]; | 13781 result->max_range = range[1]; |
13846 result->precision = precision; | 13782 result->precision = precision; |
13847 | 13783 |
13848 return error::kNoError; | 13784 return error::kNoError; |
13849 } | 13785 } |
13850 | 13786 |
13851 error::Error GLES2DecoderImpl::HandleGetAttachedShaders( | 13787 error::Error GLES2DecoderImpl::HandleGetAttachedShaders( |
13852 uint32_t immediate_data_size, | 13788 uint32_t immediate_data_size, |
(...skipping 4081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17934 } | 17870 } |
17935 | 17871 |
17936 // Include the auto-generated part of this file. We split this because it means | 17872 // Include the auto-generated part of this file. We split this because it means |
17937 // we can easily edit the non-auto generated parts right here in this file | 17873 // we can easily edit the non-auto generated parts right here in this file |
17938 // instead of having to edit some template or the code generator. | 17874 // instead of having to edit some template or the code generator. |
17939 #include "base/macros.h" | 17875 #include "base/macros.h" |
17940 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 17876 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
17941 | 17877 |
17942 } // namespace gles2 | 17878 } // namespace gles2 |
17943 } // namespace gpu | 17879 } // namespace gpu |
OLD | NEW |