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

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

Issue 11301006: automate more GL state handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
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/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 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 int height, 930 int height,
931 bool is_texture_immutable) OVERRIDE; 931 bool is_texture_immutable) OVERRIDE;
932 932
933 // Restore all GL state that affects clearing. 933 // Restore all GL state that affects clearing.
934 void RestoreClearState(); 934 void RestoreClearState();
935 935
936 // Remembers the state of some capabilities. 936 // Remembers the state of some capabilities.
937 // Returns: true if glEnable/glDisable should actually be called. 937 // Returns: true if glEnable/glDisable should actually be called.
938 bool SetCapabilityState(GLenum cap, bool enabled); 938 bool SetCapabilityState(GLenum cap, bool enabled);
939 939
940 // Initalizes all the glEnable/glDisable settings.
941 void InitCapabilities();
942
943 // Initializes all the state.
944 void InitState();
945
940 // Check that the currently bound framebuffers are valid. 946 // Check that the currently bound framebuffers are valid.
941 // Generates GL error if not. 947 // Generates GL error if not.
942 bool CheckBoundFramebuffersValid(const char* func_name); 948 bool CheckBoundFramebuffersValid(const char* func_name);
943 949
944 // Check if a framebuffer meets our requirements. 950 // Check if a framebuffer meets our requirements.
945 bool CheckFramebufferValid( 951 bool CheckFramebufferValid(
946 FramebufferManager::FramebufferInfo* framebuffer, 952 FramebufferManager::FramebufferInfo* framebuffer,
947 GLenum target, 953 GLenum target,
948 const char* func_name); 954 const char* func_name);
949 955
(...skipping 14 matching lines...) Expand all
964 // does not overflow the uniform. 970 // does not overflow the uniform.
965 bool PrepForSetUniformByLocation( 971 bool PrepForSetUniformByLocation(
966 GLint fake_location, const char* function_name, 972 GLint fake_location, const char* function_name,
967 GLint* real_location, GLenum* type, GLsizei* count); 973 GLint* real_location, GLenum* type, GLsizei* count);
968 974
969 // Gets the service id for any simulated backbuffer fbo. 975 // Gets the service id for any simulated backbuffer fbo.
970 GLuint GetBackbufferServiceId(); 976 GLuint GetBackbufferServiceId();
971 977
972 // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv 978 // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv
973 bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); 979 bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written);
980 // Same as GetHealper except for auto-generated state.
apatrick_chromium 2012/10/29 19:50:03 GetHealper -> GetHelper
981 bool GetState(GLenum pname, GLint* params, GLsizei* num_written);
974 982
975 // Wrapper for glCreateProgram 983 // Wrapper for glCreateProgram
976 bool CreateProgramHelper(GLuint client_id); 984 bool CreateProgramHelper(GLuint client_id);
977 985
978 // Wrapper for glCreateShader 986 // Wrapper for glCreateShader
979 bool CreateShaderHelper(GLenum type, GLuint client_id); 987 bool CreateShaderHelper(GLenum type, GLuint client_id);
980 988
981 // Wrapper for glActiveTexture 989 // Wrapper for glActiveTexture
982 void DoActiveTexture(GLenum texture_unit); 990 void DoActiveTexture(GLenum texture_unit);
983 991
(...skipping 29 matching lines...) Expand all
1013 // Wrapper for glBufferSubData. 1021 // Wrapper for glBufferSubData.
1014 void DoBufferSubData( 1022 void DoBufferSubData(
1015 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); 1023 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data);
1016 1024
1017 // Wrapper for glCheckFramebufferStatus 1025 // Wrapper for glCheckFramebufferStatus
1018 GLenum DoCheckFramebufferStatus(GLenum target); 1026 GLenum DoCheckFramebufferStatus(GLenum target);
1019 1027
1020 // Wrapper for glClear 1028 // Wrapper for glClear
1021 error::Error DoClear(GLbitfield mask); 1029 error::Error DoClear(GLbitfield mask);
1022 1030
1023 // Wrappers for clear and mask settings functions.
1024 void DoStencilMask(GLuint mask);
1025 void DoStencilMaskSeparate(GLenum face, GLuint mask);
1026 void DoStencilFunc(GLenum func, GLint ref, GLuint mask);
1027 void DoStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
1028 void DoStencilOp(GLenum fail, GLenum zfail, GLenum zpass);
1029 void DoStencilOpSeparate(
1030 GLenum face, GLenum fail, GLenum zfail, GLenum zpass);
1031
1032 // Wrappers for various state. 1031 // Wrappers for various state.
1033 void DoBlendEquation(GLenum mode);
1034 void DoBlendFunc(GLenum sfactor, GLenum dfactor);
1035 void DoDepthRangef(GLclampf znear, GLclampf zfar); 1032 void DoDepthRangef(GLclampf znear, GLclampf zfar);
1036 void DoHint(GLenum target, GLenum mode); 1033 void DoHint(GLenum target, GLenum mode);
1037 void DoSampleCoverage (GLclampf value, GLboolean invert); 1034 void DoSampleCoverage (GLclampf value, GLboolean invert);
1038 1035
1039 // Wrapper for glCompileShader. 1036 // Wrapper for glCompileShader.
1040 void DoCompileShader(GLuint shader); 1037 void DoCompileShader(GLuint shader);
1041 1038
1042 // Helper for DeleteSharedIdsCHROMIUM commands. 1039 // Helper for DeleteSharedIdsCHROMIUM commands.
1043 void DoDeleteSharedIdsCHROMIUM( 1040 void DoDeleteSharedIdsCHROMIUM(
1044 GLuint namespace_id, GLsizei n, const GLuint* ids); 1041 GLuint namespace_id, GLsizei n, const GLuint* ids);
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 } 1670 }
1674 glBindFramebufferEXT(GL_FRAMEBUFFER, targetid); 1671 glBindFramebufferEXT(GL_FRAMEBUFFER, targetid);
1675 } 1672 }
1676 1673
1677 ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() { 1674 ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() {
1678 if (!resolve_and_bind_) 1675 if (!resolve_and_bind_)
1679 return; 1676 return;
1680 1677
1681 ScopedGLErrorSuppressor suppressor(decoder_); 1678 ScopedGLErrorSuppressor suppressor(decoder_);
1682 decoder_->RestoreCurrentFramebufferBindings(); 1679 decoder_->RestoreCurrentFramebufferBindings();
1683 if (decoder_->state_.enable_scissor_test) { 1680 if (decoder_->state_.enable_flags.scissor_test) {
1684 glEnable(GL_SCISSOR_TEST); 1681 glEnable(GL_SCISSOR_TEST);
1685 } 1682 }
1686 } 1683 }
1687 1684
1688 ScopedTextureUploadTimer::ScopedTextureUploadTimer(GLES2DecoderImpl* decoder) 1685 ScopedTextureUploadTimer::ScopedTextureUploadTimer(GLES2DecoderImpl* decoder)
1689 : decoder_(decoder), 1686 : decoder_(decoder),
1690 begin_time_(base::TimeTicks::HighResNow()) { 1687 begin_time_(base::TimeTicks::HighResNow()) {
1691 } 1688 }
1692 1689
1693 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { 1690 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() {
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
2233 has_robustness_extension_ = 2230 has_robustness_extension_ =
2234 context->HasExtension("GL_ARB_robustness") || 2231 context->HasExtension("GL_ARB_robustness") ||
2235 context->HasExtension("GL_EXT_robustness"); 2232 context->HasExtension("GL_EXT_robustness");
2236 2233
2237 if (!InitializeShaderTranslator()) { 2234 if (!InitializeShaderTranslator()) {
2238 return false; 2235 return false;
2239 } 2236 }
2240 2237
2241 state_.viewport_width = size.width(); 2238 state_.viewport_width = size.width();
2242 state_.viewport_height = size.height(); 2239 state_.viewport_height = size.height();
2243 glViewport(
2244 state_.viewport_x, state_.viewport_y,
2245 state_.viewport_width, state_.viewport_height);
2246 2240
2247 GLint viewport_params[4] = { 0 }; 2241 GLint viewport_params[4] = { 0 };
2248 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params); 2242 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params);
2249 state_.viewport_max_width = viewport_params[0]; 2243 state_.viewport_max_width = viewport_params[0];
2250 state_.viewport_max_height = viewport_params[1]; 2244 state_.viewport_max_height = viewport_params[1];
2251 2245
2252 state_.scissor_width = state_.viewport_width; 2246 state_.scissor_width = state_.viewport_width;
2253 state_.scissor_height = state_.viewport_height; 2247 state_.scissor_height = state_.viewport_height;
2254 2248
2255 // Set all the default state because some GL drivers get it wrong. 2249 // Set all the default state because some GL drivers get it wrong.
2250 InitCapabilities();
2251 InitState();
2256 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); 2252 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit);
2257 EnableDisable(GL_BLEND, state_.enable_blend);
2258 glBlendColor(
2259 state_.blend_color_red,
2260 state_.blend_color_green,
2261 state_.blend_color_blue,
2262 state_.blend_color_alpha);
2263 glBlendFunc(
2264 state_.blend_source_rgb,
2265 state_.blend_dest_rgb);
2266 glBlendFuncSeparate(
2267 state_.blend_source_rgb,
2268 state_.blend_dest_rgb,
2269 state_.blend_source_alpha,
2270 state_.blend_dest_alpha);
2271 glBlendEquation(
2272 state_.blend_equation_rgb);
2273 glBlendEquationSeparate(
2274 state_.blend_equation_rgb, state_.blend_equation_alpha);
2275 glClearColor(
2276 state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue,
2277 state_.color_clear_alpha);
2278 glColorMask(
2279 state_.color_mask_red, state_.color_mask_green, state_.color_mask_blue,
2280 state_.color_mask_alpha);
2281 EnableDisable(GL_CULL_FACE, state_.enable_cull_face);
2282 glCullFace(state_.cull_mode);
2283 glClearDepth(state_.depth_clear);
2284 glDepthFunc(state_.depth_func);
2285 glDepthRange(state_.z_near, state_.z_far);
2286 EnableDisable(GL_DEPTH_TEST, state_.enable_depth_test);
2287 EnableDisable(GL_DITHER, state_.enable_dither);
2288 glFrontFace(state_.front_face);
2289 glHint(GL_GENERATE_MIPMAP_HINT, state_.hint_generate_mipmap); 2253 glHint(GL_GENERATE_MIPMAP_HINT, state_.hint_generate_mipmap);
2290 glLineWidth(state_.line_width);
2291 glPixelStorei(GL_PACK_ALIGNMENT, state_.pack_alignment); 2254 glPixelStorei(GL_PACK_ALIGNMENT, state_.pack_alignment);
2292 glPolygonOffset(state_.polygon_offset_factor, state_.polygon_offset_units);
2293 EnableDisable(GL_POLYGON_OFFSET_FILL, state_.enable_polygon_offset_fill);
2294 EnableDisable(
2295 GL_SAMPLE_ALPHA_TO_COVERAGE, state_.enable_sample_alpha_to_coverage);
2296 EnableDisable(GL_SAMPLE_COVERAGE, state_.enable_sample_coverage);
2297 glSampleCoverage(state_.sample_coverage_value, state_.sample_coverage_invert);
2298 glScissor(
2299 state_.scissor_x, state_.scissor_y,
2300 state_.scissor_width, state_.scissor_height);
2301 EnableDisable(GL_SCISSOR_TEST, state_.enable_scissor_test);
2302 EnableDisable(GL_STENCIL_TEST, state_.enable_stencil_test);
2303 glClearStencil(state_.stencil_clear);
2304 glStencilFuncSeparate(
2305 GL_FRONT,
2306 state_.stencil_front_func,
2307 state_.stencil_front_ref,
2308 state_.stencil_front_mask);
2309 glStencilFuncSeparate(
2310 GL_BACK,
2311 state_.stencil_back_func,
2312 state_.stencil_back_ref,
2313 state_.stencil_back_mask);
2314 glStencilOpSeparate(
2315 GL_FRONT,
2316 state_.stencil_front_fail_op,
2317 state_.stencil_front_z_fail_op,
2318 state_.stencil_front_z_pass_op);
2319 glStencilOpSeparate(
2320 GL_BACK,
2321 state_.stencil_back_fail_op,
2322 state_.stencil_back_z_fail_op,
2323 state_.stencil_back_z_pass_op);
2324 glStencilMaskSeparate(GL_FRONT, state_.stencil_front_writemask);
2325 glStencilMaskSeparate(GL_BACK, state_.stencil_back_writemask);
2326 glPixelStorei(GL_UNPACK_ALIGNMENT, state_.unpack_alignment); 2255 glPixelStorei(GL_UNPACK_ALIGNMENT, state_.unpack_alignment);
2327 2256
2328 DoBindBuffer(GL_ARRAY_BUFFER, 0); 2257 DoBindBuffer(GL_ARRAY_BUFFER, 0);
2329 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 2258 DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
2330 DoBindFramebuffer(GL_FRAMEBUFFER, 0); 2259 DoBindFramebuffer(GL_FRAMEBUFFER, 0);
2331 DoBindRenderbuffer(GL_RENDERBUFFER, 0); 2260 DoBindRenderbuffer(GL_RENDERBUFFER, 0);
2332 2261
2333 // AMD and Intel drivers on Mac OS apparently get gl_PointCoord 2262 // AMD and Intel drivers on Mac OS apparently get gl_PointCoord
2334 // backward from the spec and this setting makes them work 2263 // backward from the spec and this setting makes them work
2335 // correctly. rdar://problem/11883495 2264 // correctly. rdar://problem/11883495
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
3393 } 3322 }
3394 3323
3395 void GLES2DecoderImpl::ApplyDirtyState() { 3324 void GLES2DecoderImpl::ApplyDirtyState() {
3396 if (clear_state_dirty_) { 3325 if (clear_state_dirty_) {
3397 glColorMask( 3326 glColorMask(
3398 state_.color_mask_red, state_.color_mask_green, state_.color_mask_blue, 3327 state_.color_mask_red, state_.color_mask_green, state_.color_mask_blue,
3399 state_.color_mask_alpha && 3328 state_.color_mask_alpha &&
3400 BoundFramebufferHasColorAttachmentWithAlpha()); 3329 BoundFramebufferHasColorAttachmentWithAlpha());
3401 bool have_depth = BoundFramebufferHasDepthAttachment(); 3330 bool have_depth = BoundFramebufferHasDepthAttachment();
3402 glDepthMask(state_.depth_mask && have_depth); 3331 glDepthMask(state_.depth_mask && have_depth);
3403 EnableDisable(GL_DEPTH_TEST, state_.enable_depth_test && have_depth); 3332 EnableDisable(GL_DEPTH_TEST, state_.enable_flags.depth_test && have_depth);
3404 bool have_stencil = BoundFramebufferHasStencilAttachment(); 3333 bool have_stencil = BoundFramebufferHasStencilAttachment();
3405 glStencilMaskSeparate( 3334 glStencilMaskSeparate(
3406 GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0); 3335 GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0);
3407 glStencilMaskSeparate( 3336 glStencilMaskSeparate(
3408 GL_BACK, have_stencil ? state_.stencil_back_writemask : 0); 3337 GL_BACK, have_stencil ? state_.stencil_back_writemask : 0);
3409 EnableDisable(GL_STENCIL_TEST, state_.enable_stencil_test && have_stencil); 3338 EnableDisable(
3410 EnableDisable(GL_CULL_FACE, state_.enable_cull_face); 3339 GL_STENCIL_TEST, state_.enable_flags.stencil_test && have_stencil);
3411 EnableDisable(GL_SCISSOR_TEST, state_.enable_scissor_test); 3340 EnableDisable(GL_CULL_FACE, state_.enable_flags.cull_face);
3412 EnableDisable(GL_BLEND, state_.enable_blend); 3341 EnableDisable(GL_SCISSOR_TEST, state_.enable_flags.scissor_test);
3342 EnableDisable(GL_BLEND, state_.enable_flags.blend);
3413 clear_state_dirty_ = false; 3343 clear_state_dirty_ = false;
3414 } 3344 }
3415 } 3345 }
3416 3346
3417 void GLES2DecoderImpl::BindAndApplyTextureParameters( 3347 void GLES2DecoderImpl::BindAndApplyTextureParameters(
3418 TextureManager::TextureInfo* info) { 3348 TextureManager::TextureInfo* info) {
3419 glBindTexture(info->target(), info->service_id()); 3349 glBindTexture(info->target(), info->service_id());
3420 glTexParameteri(info->target(), GL_TEXTURE_MIN_FILTER, info->min_filter()); 3350 glTexParameteri(info->target(), GL_TEXTURE_MIN_FILTER, info->min_filter());
3421 glTexParameteri(info->target(), GL_TEXTURE_MAG_FILTER, info->mag_filter()); 3351 glTexParameteri(info->target(), GL_TEXTURE_MAG_FILTER, info->mag_filter());
3422 glTexParameteri(info->target(), GL_TEXTURE_WRAP_S, info->wrap_s()); 3352 glTexParameteri(info->target(), GL_TEXTURE_WRAP_S, info->wrap_s());
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
3656 } 3586 }
3657 return true; 3587 return true;
3658 case GL_MAX_VERTEX_UNIFORM_VECTORS: 3588 case GL_MAX_VERTEX_UNIFORM_VECTORS:
3659 *num_written = 1; 3589 *num_written = 1;
3660 if (params) { 3590 if (params) {
3661 *params = group_->max_vertex_uniform_vectors(); 3591 *params = group_->max_vertex_uniform_vectors();
3662 } 3592 }
3663 return true; 3593 return true;
3664 } 3594 }
3665 } 3595 }
3596 if (GetState(pname, params, num_written)) {
3597 return true;
3598 }
3666 switch (pname) { 3599 switch (pname) {
3667 case GL_MAX_VIEWPORT_DIMS: 3600 case GL_MAX_VIEWPORT_DIMS:
3668 if (offscreen_target_frame_buffer_.get()) { 3601 if (offscreen_target_frame_buffer_.get()) {
3669 *num_written = 2; 3602 *num_written = 2;
3670 if (params) { 3603 if (params) {
3671 params[0] = renderbuffer_manager()->max_renderbuffer_size(); 3604 params[0] = renderbuffer_manager()->max_renderbuffer_size();
3672 params[1] = renderbuffer_manager()->max_renderbuffer_size(); 3605 params[1] = renderbuffer_manager()->max_renderbuffer_size();
3673 } 3606 }
3674 return true; 3607 return true;
3675 } 3608 }
(...skipping 15 matching lines...) Expand all
3691 if (params) { 3624 if (params) {
3692 params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_2D); 3625 params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_2D);
3693 } 3626 }
3694 return true; 3627 return true;
3695 case GL_MAX_CUBE_MAP_TEXTURE_SIZE: 3628 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
3696 *num_written = 1; 3629 *num_written = 1;
3697 if (params) { 3630 if (params) {
3698 params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP); 3631 params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP);
3699 } 3632 }
3700 return true; 3633 return true;
3701 case GL_COLOR_WRITEMASK:
3702 *num_written = 4;
3703 if (params) {
3704 params[0] = state_.color_mask_red;
3705 params[1] = state_.color_mask_green;
3706 params[2] = state_.color_mask_blue;
3707 params[3] = state_.color_mask_alpha;
3708 }
3709 return true;
3710 case GL_DEPTH_WRITEMASK:
3711 *num_written = 1;
3712 if (params) {
3713 params[0] = state_.depth_mask;
3714 }
3715 return true;
3716 case GL_STENCIL_BACK_WRITEMASK:
3717 *num_written = 1;
3718 if (params) {
3719 params[0] = state_.stencil_back_writemask;
3720 }
3721 return true;
3722 case GL_STENCIL_WRITEMASK:
3723 *num_written = 1;
3724 if (params) {
3725 params[0] = state_.stencil_front_writemask;
3726 }
3727 return true;
3728 case GL_DEPTH_TEST:
3729 *num_written = 1;
3730 if (params) {
3731 params[0] = state_.enable_depth_test;
3732 }
3733 return true;
3734 case GL_STENCIL_TEST:
3735 *num_written = 1;
3736 if (params) {
3737 params[0] = state_.enable_stencil_test;
3738 }
3739 return true;
3740 case GL_ALPHA_BITS: 3634 case GL_ALPHA_BITS:
3741 *num_written = 1; 3635 *num_written = 1;
3742 if (params) { 3636 if (params) {
3743 GLint v = 0; 3637 GLint v = 0;
3744 glGetIntegerv(GL_ALPHA_BITS, &v); 3638 glGetIntegerv(GL_ALPHA_BITS, &v);
3745 params[0] = BoundFramebufferHasColorAttachmentWithAlpha() ? v : 0; 3639 params[0] = BoundFramebufferHasColorAttachmentWithAlpha() ? v : 0;
3746 } 3640 }
3747 return true; 3641 return true;
3748 case GL_DEPTH_BITS: 3642 case GL_DEPTH_BITS:
3749 *num_written = 1; 3643 *num_written = 1;
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
4341 target, attachment, renderbuffertarget, service_id); 4235 target, attachment, renderbuffertarget, service_id);
4342 GLenum error = PeekGLError(); 4236 GLenum error = PeekGLError();
4343 if (error == GL_NO_ERROR) { 4237 if (error == GL_NO_ERROR) {
4344 framebuffer_info->AttachRenderbuffer(attachment, info); 4238 framebuffer_info->AttachRenderbuffer(attachment, info);
4345 } 4239 }
4346 if (framebuffer_info == state_.bound_draw_framebuffer) { 4240 if (framebuffer_info == state_.bound_draw_framebuffer) {
4347 clear_state_dirty_ = true; 4241 clear_state_dirty_ = true;
4348 } 4242 }
4349 } 4243 }
4350 4244
4351 bool GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) {
4352 switch (cap) {
4353 case GL_BLEND:
4354 state_.enable_blend = enabled;
4355 return true;
4356 case GL_CULL_FACE:
4357 state_.enable_cull_face = enabled;
4358 return true;
4359 case GL_SCISSOR_TEST:
4360 state_.enable_scissor_test = enabled;
4361 return true;
4362 case GL_DEPTH_TEST: {
4363 if (state_.enable_depth_test != enabled) {
4364 state_.enable_depth_test = enabled;
4365 clear_state_dirty_ = true;
4366 }
4367 return false;
4368 }
4369 case GL_STENCIL_TEST:
4370 if (state_.enable_stencil_test != enabled) {
4371 state_.enable_stencil_test = enabled;
4372 clear_state_dirty_ = true;
4373 }
4374 return false;
4375 case GL_POLYGON_OFFSET_FILL:
4376 state_.enable_polygon_offset_fill = enabled;
4377 case GL_DITHER:
4378 state_.enable_dither = enabled;
4379 case GL_SAMPLE_ALPHA_TO_COVERAGE:
4380 state_.enable_sample_alpha_to_coverage = enabled;
4381 case GL_SAMPLE_COVERAGE:
4382 state_.enable_sample_coverage = enabled;
4383 default:
4384 return true;
4385 }
4386 }
4387
4388 void GLES2DecoderImpl::DoDisable(GLenum cap) { 4245 void GLES2DecoderImpl::DoDisable(GLenum cap) {
4389 if (SetCapabilityState(cap, false)) { 4246 if (SetCapabilityState(cap, false)) {
4390 glDisable(cap); 4247 glDisable(cap);
4391 } 4248 }
4392 } 4249 }
4393 4250
4394 void GLES2DecoderImpl::DoEnable(GLenum cap) { 4251 void GLES2DecoderImpl::DoEnable(GLenum cap) {
4395 if (SetCapabilityState(cap, true)) { 4252 if (SetCapabilityState(cap, true)) {
4396 glEnable(cap); 4253 glEnable(cap);
4397 } 4254 }
4398 } 4255 }
4399 4256
4400 bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) {
4401 switch (cap) {
4402 case GL_BLEND:
4403 return state_.enable_blend;
4404 case GL_CULL_FACE:
4405 return state_.enable_cull_face;
4406 case GL_SCISSOR_TEST:
4407 return state_.enable_scissor_test;
4408 case GL_DEPTH_TEST:
4409 return state_.enable_depth_test;
4410 case GL_STENCIL_TEST:
4411 return state_.enable_stencil_test;
4412 case GL_POLYGON_OFFSET_FILL:
4413 return state_.enable_polygon_offset_fill;
4414 case GL_DITHER:
4415 return state_.enable_dither;
4416 case GL_SAMPLE_ALPHA_TO_COVERAGE:
4417 return state_.enable_sample_alpha_to_coverage;
4418 case GL_SAMPLE_COVERAGE:
4419 return state_.enable_sample_coverage;
4420 default:
4421 return glIsEnabled(cap) != 0;
4422 }
4423 }
4424
4425 void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) { 4257 void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) {
4426 state_.z_near = std::min(1.0f, std::max(0.0f, znear)); 4258 state_.z_near = std::min(1.0f, std::max(0.0f, znear));
4427 state_.z_far = std::min(1.0f, std::max(0.0f, zfar)); 4259 state_.z_far = std::min(1.0f, std::max(0.0f, zfar));
4428 glDepthRange(znear, zfar); 4260 glDepthRange(znear, zfar);
4429 } 4261 }
4430 4262
4431 void GLES2DecoderImpl::DoStencilMask(GLuint mask) {
4432 state_.stencil_front_writemask = mask;
4433 state_.stencil_back_writemask = mask;
4434 clear_state_dirty_ = true;
4435 }
4436
4437 void GLES2DecoderImpl::DoStencilMaskSeparate(GLenum face, GLuint mask) {
4438 if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
4439 state_.stencil_front_writemask = mask;
4440 }
4441 if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
4442 state_.stencil_back_writemask = mask;
4443 }
4444 clear_state_dirty_ = true;
4445 }
4446
4447 void GLES2DecoderImpl::DoStencilFunc(GLenum func, GLint ref, GLuint mask) {
4448 state_.stencil_front_func = func;
4449 state_.stencil_front_ref = ref;
4450 state_.stencil_front_mask = mask;
4451 state_.stencil_back_func = func;
4452 state_.stencil_back_ref = ref;
4453 state_.stencil_back_mask = mask;
4454 glStencilFunc(func, ref, mask);
4455 }
4456
4457 void GLES2DecoderImpl::DoStencilFuncSeparate(
4458 GLenum face, GLenum func, GLint ref, GLuint mask) {
4459 if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
4460 state_.stencil_front_func = func;
4461 state_.stencil_front_ref = ref;
4462 state_.stencil_front_mask = mask;
4463 }
4464 if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
4465 state_.stencil_back_func = func;
4466 state_.stencil_back_ref = ref;
4467 state_.stencil_back_mask = mask;
4468 }
4469 glStencilFuncSeparate(face, func, ref, mask);
4470 }
4471
4472 void GLES2DecoderImpl::DoStencilOp(
4473 GLenum fail, GLenum zfail, GLenum zpass) {
4474 state_.stencil_front_fail_op = fail;
4475 state_.stencil_front_z_fail_op = zfail;
4476 state_.stencil_front_z_pass_op = zpass;
4477 state_.stencil_back_fail_op = fail;
4478 state_.stencil_back_z_fail_op = zfail;
4479 state_.stencil_back_z_pass_op = zpass;
4480 glStencilOp(fail, zfail, zpass);
4481 }
4482
4483 void GLES2DecoderImpl::DoStencilOpSeparate(
4484 GLenum face, GLenum fail, GLenum zfail, GLenum zpass) {
4485 if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
4486 state_.stencil_front_fail_op = fail;
4487 state_.stencil_front_z_fail_op = zfail;
4488 state_.stencil_front_z_pass_op = zpass;
4489 }
4490 if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
4491 state_.stencil_back_fail_op = fail;
4492 state_.stencil_back_z_fail_op = zfail;
4493 state_.stencil_back_z_pass_op = zpass;
4494 }
4495 glStencilOpSeparate(face, fail, zfail, zpass);
4496 }
4497
4498 void GLES2DecoderImpl::DoBlendEquation(GLenum mode) {
4499 state_.blend_equation_rgb = mode;
4500 state_.blend_equation_alpha = mode;
4501 glBlendEquation(mode);
4502 }
4503
4504 void GLES2DecoderImpl::DoBlendFunc(GLenum sfactor, GLenum dfactor) {
4505 state_.blend_source_rgb = sfactor;
4506 state_.blend_dest_rgb = dfactor;
4507 state_.blend_source_alpha = sfactor;
4508 state_.blend_dest_alpha = dfactor;
4509 glBlendFunc(sfactor, dfactor);
4510 }
4511
4512 void GLES2DecoderImpl::DoHint(GLenum target, GLenum mode) { 4263 void GLES2DecoderImpl::DoHint(GLenum target, GLenum mode) {
4513 switch (target) { 4264 switch (target) {
4514 case GL_GENERATE_MIPMAP_HINT: 4265 case GL_GENERATE_MIPMAP_HINT:
4515 state_.hint_generate_mipmap = mode; 4266 state_.hint_generate_mipmap = mode;
4516 break; 4267 break;
4517 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: 4268 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
4518 state_.hint_fragment_shader_derivative = mode; 4269 state_.hint_fragment_shader_derivative = mode;
4519 break; 4270 break;
4520 default: 4271 default:
4521 NOTREACHED(); 4272 NOTREACHED();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
4582 } 4333 }
4583 } 4334 }
4584 4335
4585 void GLES2DecoderImpl::RestoreClearState() { 4336 void GLES2DecoderImpl::RestoreClearState() {
4586 clear_state_dirty_ = true; 4337 clear_state_dirty_ = true;
4587 glClearColor( 4338 glClearColor(
4588 state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue, 4339 state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue,
4589 state_.color_clear_alpha); 4340 state_.color_clear_alpha);
4590 glClearStencil(state_.stencil_clear); 4341 glClearStencil(state_.stencil_clear);
4591 glClearDepth(state_.depth_clear); 4342 glClearDepth(state_.depth_clear);
4592 if (state_.enable_scissor_test) { 4343 if (state_.enable_flags.scissor_test) {
4593 glEnable(GL_SCISSOR_TEST); 4344 glEnable(GL_SCISSOR_TEST);
4594 } 4345 }
4595 } 4346 }
4596 4347
4597 GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { 4348 GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) {
4598 FramebufferManager::FramebufferInfo* framebuffer = 4349 FramebufferManager::FramebufferInfo* framebuffer =
4599 GetFramebufferInfoForTarget(target); 4350 GetFramebufferInfoForTarget(target);
4600 if (!framebuffer) { 4351 if (!framebuffer) {
4601 return GL_FRAMEBUFFER_COMPLETE; 4352 return GL_FRAMEBUFFER_COMPLETE;
4602 } 4353 }
(...skipping 4935 matching lines...) Expand 10 before | Expand all | Expand 10 after
9538 GL_RGBA, GL_UNSIGNED_BYTE, false); 9289 GL_RGBA, GL_UNSIGNED_BYTE, false);
9539 } 9290 }
9540 9291
9541 // Include the auto-generated part of this file. We split this because it means 9292 // Include the auto-generated part of this file. We split this because it means
9542 // we can easily edit the non-auto generated parts right here in this file 9293 // we can easily edit the non-auto generated parts right here in this file
9543 // instead of having to edit some template or the code generator. 9294 // instead of having to edit some template or the code generator.
9544 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 9295 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
9545 9296
9546 } // namespace gles2 9297 } // namespace gles2
9547 } // namespace gpu 9298 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/context_state_impl_autogen.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698