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 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 const std::string& name_str); | 824 const std::string& name_str); |
825 | 825 |
826 error::Error GetUniformLocationHelper( | 826 error::Error GetUniformLocationHelper( |
827 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, | 827 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
828 const std::string& name_str); | 828 const std::string& name_str); |
829 | 829 |
830 // Helper for glShaderSource. | 830 // Helper for glShaderSource. |
831 error::Error ShaderSourceHelper( | 831 error::Error ShaderSourceHelper( |
832 GLuint client_id, const char* data, uint32 data_size); | 832 GLuint client_id, const char* data, uint32 data_size); |
833 | 833 |
| 834 // Clears any uncleared render buffers attached to the given frame buffer. |
| 835 void ClearUnclearedRenderbuffers(FramebufferManager::FramebufferInfo* info); |
| 836 |
| 837 // Remembers the state of some capabilities. |
| 838 void SetCapabilityState(GLenum cap, bool enabled); |
| 839 |
834 // Checks if the current program exists and is valid. If not generates the | 840 // Checks if the current program exists and is valid. If not generates the |
835 // appropriate GL error. Returns true if the current program is in a usable | 841 // appropriate GL error. Returns true if the current program is in a usable |
836 // state. | 842 // state. |
837 bool CheckCurrentProgram(const char* function_name); | 843 bool CheckCurrentProgram(const char* function_name); |
838 | 844 |
839 // Checks if the current program exists and is valid and that location is not | 845 // Checks if the current program exists and is valid and that location is not |
840 // -1. If the current program is not valid generates the appropriate GL | 846 // -1. If the current program is not valid generates the appropriate GL |
841 // error. Returns true if the current program is in a usable state and | 847 // error. Returns true if the current program is in a usable state and |
842 // location is not -1. | 848 // location is not -1. |
843 bool CheckCurrentProgramForUniform(GLint location, const char* function_name); | 849 bool CheckCurrentProgramForUniform(GLint location, const char* function_name); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 void DoBufferData( | 885 void DoBufferData( |
880 GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); | 886 GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); |
881 | 887 |
882 // Wrapper for glBufferSubData. | 888 // Wrapper for glBufferSubData. |
883 void DoBufferSubData( | 889 void DoBufferSubData( |
884 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); | 890 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); |
885 | 891 |
886 // Wrapper for glCheckFramebufferStatus | 892 // Wrapper for glCheckFramebufferStatus |
887 GLenum DoCheckFramebufferStatus(GLenum target); | 893 GLenum DoCheckFramebufferStatus(GLenum target); |
888 | 894 |
| 895 // Wrappers for clear and mask settings functions. |
| 896 void DoClearColor( |
| 897 GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha); |
| 898 void DoClearDepthf(GLclampf depth); |
| 899 void DoClearStencil(GLint s); |
| 900 void DoColorMask( |
| 901 GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); |
| 902 void DoDepthMask(GLboolean depth); |
| 903 void DoStencilMask(GLuint mask); |
| 904 void DoStencilMaskSeparate(GLenum face, GLuint mask); |
| 905 |
889 // Wrapper for glCompileShader. | 906 // Wrapper for glCompileShader. |
890 void DoCompileShader(GLuint shader); | 907 void DoCompileShader(GLuint shader); |
891 | 908 |
892 // Helper for DeleteSharedIds commands. | 909 // Helper for DeleteSharedIds commands. |
893 void DoDeleteSharedIds(GLuint namespace_id, GLsizei n, const GLuint* ids); | 910 void DoDeleteSharedIds(GLuint namespace_id, GLsizei n, const GLuint* ids); |
894 | 911 |
895 // Wrapper for glDetachShader | 912 // Wrapper for glDetachShader |
896 void DoDetachShader(GLuint client_program_id, GLint client_shader_id); | 913 void DoDetachShader(GLuint client_program_id, GLint client_shader_id); |
897 | 914 |
898 // Wrapper for glDrawArrays. | 915 // Wrapper for glDrawArrays. |
899 void DoDrawArrays(GLenum mode, GLint first, GLsizei count); | 916 void DoDrawArrays(GLenum mode, GLint first, GLsizei count); |
900 | 917 |
| 918 // Wrapper for glDisable |
| 919 void DoDisable(GLenum cap); |
| 920 |
901 // Wrapper for glDisableVertexAttribArray. | 921 // Wrapper for glDisableVertexAttribArray. |
902 void DoDisableVertexAttribArray(GLuint index); | 922 void DoDisableVertexAttribArray(GLuint index); |
903 | 923 |
| 924 // Wrapper for glEnable |
| 925 void DoEnable(GLenum cap); |
| 926 |
904 // Wrapper for glEnableVertexAttribArray. | 927 // Wrapper for glEnableVertexAttribArray. |
905 void DoEnableVertexAttribArray(GLuint index); | 928 void DoEnableVertexAttribArray(GLuint index); |
906 | 929 |
907 // Wrapper for glFramebufferRenderbufffer. | 930 // Wrapper for glFramebufferRenderbufffer. |
908 void DoFramebufferRenderbuffer( | 931 void DoFramebufferRenderbuffer( |
909 GLenum target, GLenum attachment, GLenum renderbuffertarget, | 932 GLenum target, GLenum attachment, GLenum renderbuffertarget, |
910 GLuint renderbuffer); | 933 GLuint renderbuffer); |
911 | 934 |
912 // Wrapper for glFramebufferTexture2D. | 935 // Wrapper for glFramebufferTexture2D. |
913 void DoFramebufferTexture2D( | 936 void DoFramebufferTexture2D( |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 | 1176 |
1154 // Which textures are bound to texture units through glActiveTexture. | 1177 // Which textures are bound to texture units through glActiveTexture. |
1155 scoped_array<TextureUnit> texture_units_; | 1178 scoped_array<TextureUnit> texture_units_; |
1156 | 1179 |
1157 // Black (0,0,0,1) textures for when non-renderable textures are used. | 1180 // Black (0,0,0,1) textures for when non-renderable textures are used. |
1158 // NOTE: There is no corresponding TextureInfo for these textures. | 1181 // NOTE: There is no corresponding TextureInfo for these textures. |
1159 // TextureInfos are only for textures the client side can access. | 1182 // TextureInfos are only for textures the client side can access. |
1160 GLuint black_2d_texture_id_; | 1183 GLuint black_2d_texture_id_; |
1161 GLuint black_cube_texture_id_; | 1184 GLuint black_cube_texture_id_; |
1162 | 1185 |
| 1186 // state saved for clearing so we can clear render buffers and then |
| 1187 // restore to these values. |
| 1188 GLclampf clear_red_; |
| 1189 GLclampf clear_green_; |
| 1190 GLclampf clear_blue_; |
| 1191 GLclampf clear_alpha_; |
| 1192 GLboolean mask_red_; |
| 1193 GLboolean mask_green_; |
| 1194 GLboolean mask_blue_; |
| 1195 GLboolean mask_alpha_; |
| 1196 GLint clear_stencil_; |
| 1197 GLuint mask_stencil_front_; |
| 1198 GLuint mask_stencil_back_; |
| 1199 GLclampf clear_depth_; |
| 1200 GLboolean mask_depth_; |
| 1201 bool enable_scissor_test_; |
| 1202 |
1163 // The program in use by glUseProgram | 1203 // The program in use by glUseProgram |
1164 ProgramManager::ProgramInfo::Ref current_program_; | 1204 ProgramManager::ProgramInfo::Ref current_program_; |
1165 | 1205 |
1166 // The currently bound framebuffer | 1206 // The currently bound framebuffer |
1167 FramebufferManager::FramebufferInfo::Ref bound_framebuffer_; | 1207 FramebufferManager::FramebufferInfo::Ref bound_framebuffer_; |
1168 | 1208 |
1169 // The currently bound renderbuffer | 1209 // The currently bound renderbuffer |
1170 RenderbufferManager::RenderbufferInfo::Ref bound_renderbuffer_; | 1210 RenderbufferManager::RenderbufferInfo::Ref bound_renderbuffer_; |
1171 | 1211 |
1172 bool anti_aliased_; | 1212 bool anti_aliased_; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1450 : GLES2Decoder(group), | 1490 : GLES2Decoder(group), |
1451 error_bits_(0), | 1491 error_bits_(0), |
1452 util_(0), // TODO(gman): Set to actual num compress texture formats. | 1492 util_(0), // TODO(gman): Set to actual num compress texture formats. |
1453 pack_alignment_(4), | 1493 pack_alignment_(4), |
1454 unpack_alignment_(4), | 1494 unpack_alignment_(4), |
1455 attrib_0_buffer_id_(0), | 1495 attrib_0_buffer_id_(0), |
1456 attrib_0_size_(0), | 1496 attrib_0_size_(0), |
1457 active_texture_unit_(0), | 1497 active_texture_unit_(0), |
1458 black_2d_texture_id_(0), | 1498 black_2d_texture_id_(0), |
1459 black_cube_texture_id_(0), | 1499 black_cube_texture_id_(0), |
| 1500 clear_red_(0), |
| 1501 clear_green_(0), |
| 1502 clear_blue_(0), |
| 1503 clear_alpha_(0), |
| 1504 mask_red_(true), |
| 1505 mask_green_(true), |
| 1506 mask_blue_(true), |
| 1507 mask_alpha_(true), |
| 1508 clear_stencil_(0), |
| 1509 mask_stencil_front_(-1), |
| 1510 mask_stencil_back_(-1), |
| 1511 clear_depth_(1.0f), |
| 1512 mask_depth_(true), |
| 1513 enable_scissor_test_(false), |
1460 anti_aliased_(false), | 1514 anti_aliased_(false), |
1461 use_shader_translator_(true), | 1515 use_shader_translator_(true), |
1462 vertex_compiler_(NULL), | 1516 vertex_compiler_(NULL), |
1463 fragment_compiler_(NULL), | 1517 fragment_compiler_(NULL), |
1464 validators_(group->validators()), | 1518 validators_(group->validators()), |
1465 depth24_stencil8_oes_supported_(false) { | 1519 depth24_stencil8_oes_supported_(false) { |
1466 attrib_0_value_.v[0] = 0.0f; | 1520 attrib_0_value_.v[0] = 0.0f; |
1467 attrib_0_value_.v[1] = 0.0f; | 1521 attrib_0_value_.v[1] = 0.0f; |
1468 attrib_0_value_.v[2] = 0.0f; | 1522 attrib_0_value_.v[2] = 0.0f; |
1469 attrib_0_value_.v[3] = 1.0f; | 1523 attrib_0_value_.v[3] = 1.0f; |
(...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2734 | 2788 |
2735 void GLES2DecoderImpl::DoFramebufferRenderbuffer( | 2789 void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
2736 GLenum target, GLenum attachment, GLenum renderbuffertarget, | 2790 GLenum target, GLenum attachment, GLenum renderbuffertarget, |
2737 GLuint client_renderbuffer_id) { | 2791 GLuint client_renderbuffer_id) { |
2738 if (!bound_framebuffer_) { | 2792 if (!bound_framebuffer_) { |
2739 SetGLError(GL_INVALID_OPERATION, | 2793 SetGLError(GL_INVALID_OPERATION, |
2740 "glFramebufferRenderbuffer: no framebuffer bound"); | 2794 "glFramebufferRenderbuffer: no framebuffer bound"); |
2741 return; | 2795 return; |
2742 } | 2796 } |
2743 GLuint service_id = 0; | 2797 GLuint service_id = 0; |
| 2798 RenderbufferManager::RenderbufferInfo* info = NULL; |
2744 if (client_renderbuffer_id) { | 2799 if (client_renderbuffer_id) { |
2745 RenderbufferManager::RenderbufferInfo* info = | 2800 info = GetRenderbufferInfo(client_renderbuffer_id); |
2746 GetRenderbufferInfo(client_renderbuffer_id); | |
2747 if (!info) { | 2801 if (!info) { |
2748 SetGLError(GL_INVALID_OPERATION, | 2802 SetGLError(GL_INVALID_OPERATION, |
2749 "glFramebufferRenderbuffer: unknown renderbuffer"); | 2803 "glFramebufferRenderbuffer: unknown renderbuffer"); |
2750 return; | 2804 return; |
2751 } | 2805 } |
2752 service_id = info->service_id(); | 2806 service_id = info->service_id(); |
2753 } | 2807 } |
2754 glFramebufferRenderbufferEXT( | 2808 glFramebufferRenderbufferEXT( |
2755 target, attachment, renderbuffertarget, service_id); | 2809 target, attachment, renderbuffertarget, service_id); |
| 2810 if (service_id == 0 || |
| 2811 glCheckFramebufferStatusEXT(target) == GL_FRAMEBUFFER_COMPLETE) { |
| 2812 bound_framebuffer_->AttachRenderbuffer(attachment, info); |
| 2813 if (info) { |
| 2814 ClearUnclearedRenderbuffers(bound_framebuffer_); |
| 2815 } |
| 2816 } |
| 2817 } |
| 2818 |
| 2819 void GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) { |
| 2820 switch (cap) { |
| 2821 case GL_SCISSOR_TEST: |
| 2822 enable_scissor_test_ = enabled; |
| 2823 break; |
| 2824 default: |
| 2825 break; |
| 2826 } |
| 2827 } |
| 2828 |
| 2829 void GLES2DecoderImpl::DoDisable(GLenum cap) { |
| 2830 SetCapabilityState(cap, false); |
| 2831 glDisable(cap); |
| 2832 } |
| 2833 |
| 2834 void GLES2DecoderImpl::DoEnable(GLenum cap) { |
| 2835 SetCapabilityState(cap, true); |
| 2836 glEnable(cap); |
| 2837 } |
| 2838 |
| 2839 void GLES2DecoderImpl::DoClearColor( |
| 2840 GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) { |
| 2841 clear_red_ = red; |
| 2842 clear_green_ = green; |
| 2843 clear_blue_ = blue; |
| 2844 clear_alpha_ = alpha; |
| 2845 glClearColor(red, green, blue, alpha); |
| 2846 } |
| 2847 |
| 2848 void GLES2DecoderImpl::DoClearDepthf(GLclampf depth) { |
| 2849 clear_depth_ = depth; |
| 2850 glClearDepth(depth); |
| 2851 } |
| 2852 |
| 2853 void GLES2DecoderImpl::DoClearStencil(GLint s) { |
| 2854 clear_stencil_ = s; |
| 2855 glClearStencil(s); |
| 2856 } |
| 2857 |
| 2858 void GLES2DecoderImpl::DoColorMask( |
| 2859 GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { |
| 2860 mask_red_ = red; |
| 2861 mask_green_ = green; |
| 2862 mask_blue_ = blue; |
| 2863 mask_alpha_ = alpha; |
| 2864 glColorMask(red, green, blue, alpha); |
| 2865 } |
| 2866 |
| 2867 void GLES2DecoderImpl::DoDepthMask(GLboolean depth) { |
| 2868 mask_depth_ = depth; |
| 2869 glDepthMask(depth); |
| 2870 } |
| 2871 |
| 2872 void GLES2DecoderImpl::DoStencilMask(GLuint mask) { |
| 2873 mask_stencil_front_ = mask; |
| 2874 mask_stencil_back_ = mask; |
| 2875 glStencilMask(mask); |
| 2876 } |
| 2877 |
| 2878 void GLES2DecoderImpl::DoStencilMaskSeparate(GLenum face, GLuint mask) { |
| 2879 if (face == GL_FRONT) { |
| 2880 mask_stencil_front_ = mask; |
| 2881 } else { |
| 2882 mask_stencil_back_ = mask; |
| 2883 } |
| 2884 glStencilMaskSeparate(face, mask); |
| 2885 } |
| 2886 |
| 2887 // NOTE: There's an assumption here that Texture attachments |
| 2888 // are cleared because they are textures so we only need to clear |
| 2889 // the renderbuffers. |
| 2890 void GLES2DecoderImpl::ClearUnclearedRenderbuffers( |
| 2891 FramebufferManager::FramebufferInfo* info) { |
| 2892 GLbitfield clear_bits = 0; |
| 2893 if (info->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)) { |
| 2894 glClearColor(0, 0, 0, 0); |
| 2895 glColorMask(true, true, true, true); |
| 2896 clear_bits |= GL_COLOR_BUFFER_BIT; |
| 2897 } |
| 2898 |
| 2899 if (info->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || |
| 2900 info->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
| 2901 glClearStencil(0); |
| 2902 glStencilMask(-1); |
| 2903 clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 2904 } |
| 2905 |
| 2906 if (info->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || |
| 2907 info->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
| 2908 glClearDepth(1.0f); |
| 2909 glDepthMask(true); |
| 2910 clear_bits |= GL_DEPTH_BUFFER_BIT; |
| 2911 } |
| 2912 |
| 2913 glDisable(GL_SCISSOR_TEST); |
| 2914 glClear(clear_bits); |
| 2915 |
| 2916 info->MarkAttachedRenderbuffersAsCleared(); |
| 2917 |
| 2918 // reset clear color |
| 2919 glClearColor(clear_red_, clear_green_, clear_blue_, clear_alpha_); |
| 2920 glColorMask(mask_red_, mask_green_, mask_blue_, mask_alpha_); |
| 2921 glClearStencil(clear_stencil_); |
| 2922 glStencilMaskSeparate(GL_FRONT, mask_stencil_front_); |
| 2923 glStencilMaskSeparate(GL_BACK, mask_stencil_back_); |
| 2924 glClearDepth(clear_depth_); |
| 2925 glDepthMask(mask_depth_); |
| 2926 if (enable_scissor_test_) { |
| 2927 glEnable(GL_SCISSOR_TEST); |
| 2928 } |
2756 } | 2929 } |
2757 | 2930 |
2758 GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { | 2931 GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { |
2759 if (!bound_framebuffer_) { | 2932 if (!bound_framebuffer_) { |
2760 return GL_FRAMEBUFFER_COMPLETE; | 2933 return GL_FRAMEBUFFER_COMPLETE; |
2761 } | 2934 } |
2762 return glCheckFramebufferStatusEXT(target); | 2935 return glCheckFramebufferStatusEXT(target); |
2763 } | 2936 } |
2764 | 2937 |
2765 void GLES2DecoderImpl::DoFramebufferTexture2D( | 2938 void GLES2DecoderImpl::DoFramebufferTexture2D( |
2766 GLenum target, GLenum attachment, GLenum textarget, | 2939 GLenum target, GLenum attachment, GLenum textarget, |
2767 GLuint client_texture_id, GLint level) { | 2940 GLuint client_texture_id, GLint level) { |
2768 if (!bound_framebuffer_) { | 2941 if (!bound_framebuffer_) { |
2769 SetGLError(GL_INVALID_OPERATION, | 2942 SetGLError(GL_INVALID_OPERATION, |
2770 "glFramebufferTexture2D: no framebuffer bound."); | 2943 "glFramebufferTexture2D: no framebuffer bound."); |
2771 return; | 2944 return; |
2772 } | 2945 } |
2773 GLuint service_id = 0; | 2946 GLuint service_id = 0; |
| 2947 TextureManager::TextureInfo* info = NULL; |
2774 if (client_texture_id) { | 2948 if (client_texture_id) { |
2775 TextureManager::TextureInfo* info = GetTextureInfo(client_texture_id); | 2949 info = GetTextureInfo(client_texture_id); |
2776 if (!info) { | 2950 if (!info) { |
2777 SetGLError(GL_INVALID_OPERATION, | 2951 SetGLError(GL_INVALID_OPERATION, |
2778 "glFramebufferTexture2D: unknown texture"); | 2952 "glFramebufferTexture2D: unknown texture"); |
2779 return; | 2953 return; |
2780 } | 2954 } |
2781 service_id = info->service_id(); | 2955 service_id = info->service_id(); |
2782 } | 2956 } |
2783 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); | 2957 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); |
| 2958 if (service_id != 0 && |
| 2959 glCheckFramebufferStatusEXT(target) == GL_FRAMEBUFFER_COMPLETE) { |
| 2960 ClearUnclearedRenderbuffers(bound_framebuffer_); |
| 2961 } |
2784 } | 2962 } |
2785 | 2963 |
2786 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( | 2964 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( |
2787 GLenum target, GLenum attachment, GLenum pname, GLint* params) { | 2965 GLenum target, GLenum attachment, GLenum pname, GLint* params) { |
2788 if (!bound_framebuffer_) { | 2966 if (!bound_framebuffer_) { |
2789 SetGLError(GL_INVALID_OPERATION, | 2967 SetGLError(GL_INVALID_OPERATION, |
2790 "glFramebufferAttachmentParameteriv: no framebuffer bound"); | 2968 "glFramebufferAttachmentParameteriv: no framebuffer bound"); |
2791 return; | 2969 return; |
2792 } | 2970 } |
2793 glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params); | 2971 glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params); |
(...skipping 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4996 return error::kNoError; | 5174 return error::kNoError; |
4997 } | 5175 } |
4998 | 5176 |
4999 // Include the auto-generated part of this file. We split this because it means | 5177 // Include the auto-generated part of this file. We split this because it means |
5000 // we can easily edit the non-auto generated parts right here in this file | 5178 // we can easily edit the non-auto generated parts right here in this file |
5001 // instead of having to edit some template or the code generator. | 5179 // instead of having to edit some template or the code generator. |
5002 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 5180 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
5003 | 5181 |
5004 } // namespace gles2 | 5182 } // namespace gles2 |
5005 } // namespace gpu | 5183 } // namespace gpu |
OLD | NEW |