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 // A class to emulate GLES2 over command buffers. | 5 // A class to emulate GLES2 over command buffers. |
6 | 6 |
7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
8 | 8 |
9 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
10 #include <GLES2/gl2extchromium.h> | 10 #include <GLES2/gl2extchromium.h> |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
694 *params = bound_read_framebuffer_; | 694 *params = bound_read_framebuffer_; |
695 return true; | 695 return true; |
696 } | 696 } |
697 return false; | 697 return false; |
698 case GL_RENDERBUFFER_BINDING: | 698 case GL_RENDERBUFFER_BINDING: |
699 if (share_group_->bind_generates_resource()) { | 699 if (share_group_->bind_generates_resource()) { |
700 *params = bound_renderbuffer_; | 700 *params = bound_renderbuffer_; |
701 return true; | 701 return true; |
702 } | 702 } |
703 return false; | 703 return false; |
704 case GL_MAX_UNIFORM_BUFFER_BINDINGS: | |
705 *params = capabilities_.max_uniform_buffer_bindings; | |
706 return true; | |
707 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: | |
708 *params = capabilities_.max_transform_feedback_separate_attribs; | |
709 return true; | |
710 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: | |
711 *params = capabilities_.uniform_buffer_offset_alignment; | |
712 return true; | |
704 default: | 713 default: |
705 return false; | 714 return false; |
706 } | 715 } |
707 } | 716 } |
708 | 717 |
709 bool GLES2Implementation::GetBooleanvHelper(GLenum pname, GLboolean* params) { | 718 bool GLES2Implementation::GetBooleanvHelper(GLenum pname, GLboolean* params) { |
710 // TODO(gman): Make this handle pnames that return more than 1 value. | 719 // TODO(gman): Make this handle pnames that return more than 1 value. |
711 GLint value; | 720 GLint value; |
712 if (!GetHelper(pname, &value)) { | 721 if (!GetHelper(pname, &value)) { |
713 return false; | 722 return false; |
(...skipping 1929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2643 case GL_ELEMENT_ARRAY_BUFFER: | 2652 case GL_ELEMENT_ARRAY_BUFFER: |
2644 changed = vertex_array_object_manager_->BindElementArray(buffer_id); | 2653 changed = vertex_array_object_manager_->BindElementArray(buffer_id); |
2645 break; | 2654 break; |
2646 case GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM: | 2655 case GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM: |
2647 bound_pixel_pack_transfer_buffer_id_ = buffer_id; | 2656 bound_pixel_pack_transfer_buffer_id_ = buffer_id; |
2648 break; | 2657 break; |
2649 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: | 2658 case GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM: |
2650 bound_pixel_unpack_transfer_buffer_id_ = buffer_id; | 2659 bound_pixel_unpack_transfer_buffer_id_ = buffer_id; |
2651 break; | 2660 break; |
2652 default: | 2661 default: |
2653 changed = true; | 2662 SetGLErrorInvalidEnum("glBindBuffer", target, "target"); |
2654 break; | 2663 return; |
2655 } | 2664 } |
2656 // TODO(gman): There's a bug here. If the target is invalid the ID will not be | |
2657 // used even though it's marked it as used here. | |
2658 if (changed) { | 2665 if (changed) { |
2659 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind( | 2666 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind( |
2660 this, target, buffer_id, &GLES2Implementation::BindBufferStub); | 2667 this, target, buffer_id, &GLES2Implementation::BindBufferStub); |
2661 } | 2668 } |
2662 } | 2669 } |
2663 | 2670 |
2664 void GLES2Implementation::BindBufferStub(GLenum target, GLuint buffer) { | 2671 void GLES2Implementation::BindBufferStub(GLenum target, GLuint buffer) { |
2665 helper_->BindBuffer(target, buffer); | 2672 helper_->BindBuffer(target, buffer); |
2666 if (share_group_->bind_generates_resource()) | 2673 if (share_group_->bind_generates_resource()) |
2667 helper_->CommandBufferHelper::Flush(); | 2674 helper_->CommandBufferHelper::Flush(); |
2668 } | 2675 } |
2669 | 2676 |
2670 void GLES2Implementation::BindBufferBaseHelper( | 2677 void GLES2Implementation::BindBufferBaseHelper( |
2671 GLenum target, GLuint index, GLuint buffer_id) { | 2678 GLenum target, GLuint index, GLuint buffer_id) { |
2672 // TODO(zmo): See note #1 above. | 2679 // TODO(zmo): See note #1 above. |
2673 // TODO(zmo): There's a bug here. If the target or index is invalid the ID | 2680 switch (target) { |
2674 // will not be used even though it's marked it as used here. | 2681 case GL_TRANSFORM_FEEDBACK_BUFFER: |
2682 if (index >= static_cast<GLuint>( | |
2683 capabilities_.max_transform_feedback_separate_attribs)) { | |
2684 SetGLError(GL_INVALID_VALUE, "glBindBufferBase", | |
2685 "index larger than max limit"); | |
2686 return; | |
2687 } | |
2688 break; | |
2689 case GL_UNIFORM_BUFFER: | |
2690 if (index >= | |
2691 static_cast<GLuint>(capabilities_.max_uniform_buffer_bindings)) { | |
2692 SetGLError(GL_INVALID_VALUE, "glBindBufferBase", | |
2693 "index larger than max limit"); | |
2694 return; | |
2695 } | |
2696 break; | |
2697 default: | |
2698 SetGLErrorInvalidEnum("glBindBufferBase", target, "target"); | |
2699 return; | |
2700 } | |
2701 | |
2675 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind( | 2702 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind( |
2676 this, target, index, buffer_id, &GLES2Implementation::BindBufferBaseStub); | 2703 this, target, index, buffer_id, &GLES2Implementation::BindBufferBaseStub); |
2677 } | 2704 } |
2678 | 2705 |
2679 void GLES2Implementation::BindBufferBaseStub( | 2706 void GLES2Implementation::BindBufferBaseStub( |
2680 GLenum target, GLuint index, GLuint buffer) { | 2707 GLenum target, GLuint index, GLuint buffer) { |
2681 helper_->BindBufferBase(target, index, buffer); | 2708 helper_->BindBufferBase(target, index, buffer); |
2682 if (share_group_->bind_generates_resource()) | 2709 if (share_group_->bind_generates_resource()) |
2683 helper_->CommandBufferHelper::Flush(); | 2710 helper_->CommandBufferHelper::Flush(); |
2684 } | 2711 } |
2685 | 2712 |
2686 void GLES2Implementation::BindBufferRangeHelper( | 2713 void GLES2Implementation::BindBufferRangeHelper( |
2687 GLenum target, GLuint index, GLuint buffer_id, | 2714 GLenum target, GLuint index, GLuint buffer_id, |
2688 GLintptr offset, GLsizeiptr size) { | 2715 GLintptr offset, GLsizeiptr size) { |
2689 // TODO(zmo): See note #1 above. | 2716 // TODO(zmo): See note #1 above. |
2690 // TODO(zmo): There's a bug here. If an arguments is invalid the ID will not | 2717 switch (target) { |
2691 // be used even though it's marked it as used here. | 2718 case GL_TRANSFORM_FEEDBACK_BUFFER: |
2719 if (index >= static_cast<GLuint>( | |
2720 capabilities_.max_transform_feedback_separate_attribs)) { | |
2721 SetGLError(GL_INVALID_VALUE, "glBindBufferRange", | |
2722 "index larget than max limit"); | |
2723 return; | |
2724 } | |
2725 if (offset % 4 != 0 || size % 4 != 0) { | |
2726 SetGLError(GL_INVALID_VALUE, "glBindBufferRange", | |
2727 "offset and size must be multiples of 4"); | |
2728 return; | |
2729 } | |
2730 break; | |
2731 case GL_UNIFORM_BUFFER: | |
2732 if (index >= | |
2733 static_cast<GLuint>(capabilities_.max_uniform_buffer_bindings)) { | |
2734 SetGLError(GL_INVALID_VALUE, "glBindBufferRange", | |
2735 "index larger than max limit"); | |
2736 return; | |
2737 } | |
2738 if (capabilities_.uniform_buffer_offset_alignment != 0 && | |
2739 offset % capabilities_.uniform_buffer_offset_alignment != 0) { | |
2740 SetGLError(GL_INVALID_VALUE, "glBindBufferRange", | |
2741 "offset must be multiples of alignment"); | |
2742 return; | |
2743 } | |
2744 break; | |
2745 default: | |
2746 SetGLErrorInvalidEnum("glBindBufferRange", target, "target"); | |
2747 return; | |
2748 } | |
2749 if (buffer_id != 0 && size <= 0) { | |
2750 SetGLError(GL_INVALID_VALUE, "glBindBufferRange", | |
2751 "size must be larger than 0"); | |
2752 return; | |
2753 } | |
2754 | |
2692 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind( | 2755 GetIdHandler(id_namespaces::kBuffers)->MarkAsUsedForBind( |
2693 this, target, index, buffer_id, offset, size, | 2756 this, target, index, buffer_id, offset, size, |
2694 &GLES2Implementation::BindBufferRangeStub); | 2757 &GLES2Implementation::BindBufferRangeStub); |
2695 } | 2758 } |
2696 | 2759 |
2697 void GLES2Implementation::BindBufferRangeStub( | 2760 void GLES2Implementation::BindBufferRangeStub( |
2698 GLenum target, GLuint index, GLuint buffer, | 2761 GLenum target, GLuint index, GLuint buffer, |
2699 GLintptr offset, GLsizeiptr size) { | 2762 GLintptr offset, GLsizeiptr size) { |
2700 helper_->BindBufferRange(target, index, buffer, offset, size); | 2763 helper_->BindBufferRange(target, index, buffer, offset, size); |
2701 if (share_group_->bind_generates_resource()) | 2764 if (share_group_->bind_generates_resource()) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2758 // TODO(gman): See note #1 above. | 2821 // TODO(gman): See note #1 above. |
2759 bool changed = false; | 2822 bool changed = false; |
2760 switch (target) { | 2823 switch (target) { |
2761 case GL_RENDERBUFFER: | 2824 case GL_RENDERBUFFER: |
2762 if (bound_renderbuffer_ != renderbuffer) { | 2825 if (bound_renderbuffer_ != renderbuffer) { |
2763 bound_renderbuffer_ = renderbuffer; | 2826 bound_renderbuffer_ = renderbuffer; |
2764 changed = true; | 2827 changed = true; |
2765 } | 2828 } |
2766 break; | 2829 break; |
2767 default: | 2830 default: |
2768 changed = true; | 2831 SetGLErrorInvalidEnum("glBindRenderbuffer", target, "target"); |
2769 break; | 2832 return; |
2770 } | 2833 } |
2771 // TODO(gman): There's a bug here. If the target is invalid the ID will not be | |
2772 // used even though it's marked it as used here. | |
2773 if (changed) { | 2834 if (changed) { |
2774 GetIdHandler(id_namespaces::kRenderbuffers)->MarkAsUsedForBind( | 2835 GetIdHandler(id_namespaces::kRenderbuffers)->MarkAsUsedForBind( |
2775 this, target, renderbuffer, | 2836 this, target, renderbuffer, |
2776 &GLES2Implementation::BindRenderbufferStub); | 2837 &GLES2Implementation::BindRenderbufferStub); |
2777 } | 2838 } |
2778 } | 2839 } |
2779 | 2840 |
2780 void GLES2Implementation::BindRenderbufferStub(GLenum target, | 2841 void GLES2Implementation::BindRenderbufferStub(GLenum target, |
2781 GLuint renderbuffer) { | 2842 GLuint renderbuffer) { |
2782 helper_->BindRenderbuffer(target, renderbuffer); | 2843 helper_->BindRenderbuffer(target, renderbuffer); |
(...skipping 25 matching lines...) Expand all Loading... | |
2808 changed = true; | 2869 changed = true; |
2809 } | 2870 } |
2810 break; | 2871 break; |
2811 case GL_TEXTURE_EXTERNAL_OES: | 2872 case GL_TEXTURE_EXTERNAL_OES: |
2812 if (unit.bound_texture_external_oes != texture) { | 2873 if (unit.bound_texture_external_oes != texture) { |
2813 unit.bound_texture_external_oes = texture; | 2874 unit.bound_texture_external_oes = texture; |
2814 changed = true; | 2875 changed = true; |
2815 } | 2876 } |
2816 break; | 2877 break; |
2817 default: | 2878 default: |
2818 changed = true; | 2879 SetGLErrorInvalidEnum("glBindTexture", target, "target."); |
2819 break; | 2880 return; |
2820 } | 2881 } |
2821 // TODO(gman): There's a bug here. If the target is invalid the ID will not be | |
2822 // used. even though it's marked it as used here. | |
piman
2015/02/04 00:43:19
note: this is still true. For example, we don't kn
| |
2823 if (changed) { | 2882 if (changed) { |
2824 GetIdHandler(id_namespaces::kTextures)->MarkAsUsedForBind( | 2883 GetIdHandler(id_namespaces::kTextures)->MarkAsUsedForBind( |
2825 this, target, texture, &GLES2Implementation::BindTextureStub); | 2884 this, target, texture, &GLES2Implementation::BindTextureStub); |
2826 } | 2885 } |
2827 } | 2886 } |
2828 | 2887 |
2829 void GLES2Implementation::BindTextureStub(GLenum target, GLuint texture) { | 2888 void GLES2Implementation::BindTextureStub(GLenum target, GLuint texture) { |
2830 helper_->BindTexture(target, texture); | 2889 helper_->BindTexture(target, texture); |
2831 if (share_group_->bind_generates_resource()) | 2890 if (share_group_->bind_generates_resource()) |
2832 helper_->CommandBufferHelper::Flush(); | 2891 helper_->CommandBufferHelper::Flush(); |
2833 } | 2892 } |
2834 | 2893 |
2835 void GLES2Implementation::BindTransformFeedbackHelper( | 2894 void GLES2Implementation::BindTransformFeedbackHelper( |
2836 GLenum target, GLuint transformfeedback) { | 2895 GLenum target, GLuint transformfeedback) { |
2837 helper_->BindTransformFeedback(target, transformfeedback); | 2896 helper_->BindTransformFeedback(target, transformfeedback); |
2838 } | 2897 } |
2839 | 2898 |
2840 void GLES2Implementation::BindVertexArrayOESHelper(GLuint array) { | 2899 void GLES2Implementation::BindVertexArrayOESHelper(GLuint array) { |
2841 // TODO(gman): See note #1 above. | |
2842 bool changed = false; | 2900 bool changed = false; |
2843 if (vertex_array_object_manager_->BindVertexArray(array, &changed)) { | 2901 if (vertex_array_object_manager_->BindVertexArray(array, &changed)) { |
2844 if (changed) { | 2902 if (changed) { |
2845 // Unlike other BindXXXHelpers we don't call MarkAsUsedForBind | 2903 // Unlike other BindXXXHelpers we don't call MarkAsUsedForBind |
2846 // because unlike other resources VertexArrayObject ids must | 2904 // because unlike other resources VertexArrayObject ids must |
2847 // be generated by GenVertexArrays. A random id to Bind will not | 2905 // be generated by GenVertexArrays. A random id to Bind will not |
2848 // generate a new object. | 2906 // generate a new object. |
2849 helper_->BindVertexArrayOES(array); | 2907 helper_->BindVertexArrayOES(array); |
2850 } | 2908 } |
2851 } else { | 2909 } else { |
2852 SetGLError( | 2910 SetGLError( |
2853 GL_INVALID_OPERATION, "glBindVertexArrayOES", | 2911 GL_INVALID_OPERATION, "glBindVertexArrayOES", |
2854 "id was not generated with glGenVertexArrayOES"); | 2912 "id was not generated with glGenVertexArrayOES"); |
2855 } | 2913 } |
2856 } | 2914 } |
2857 | 2915 |
2858 void GLES2Implementation::BindValuebufferCHROMIUMHelper(GLenum target, | 2916 void GLES2Implementation::BindValuebufferCHROMIUMHelper(GLenum target, |
2859 GLuint valuebuffer) { | 2917 GLuint valuebuffer) { |
2860 bool changed = false; | 2918 bool changed = false; |
2861 switch (target) { | 2919 switch (target) { |
2862 case GL_SUBSCRIBED_VALUES_BUFFER_CHROMIUM: | 2920 case GL_SUBSCRIBED_VALUES_BUFFER_CHROMIUM: |
2863 if (bound_valuebuffer_ != valuebuffer) { | 2921 if (bound_valuebuffer_ != valuebuffer) { |
2864 bound_valuebuffer_ = valuebuffer; | 2922 bound_valuebuffer_ = valuebuffer; |
2865 changed = true; | 2923 changed = true; |
2866 } | 2924 } |
2867 break; | 2925 break; |
2868 default: | 2926 default: |
2869 changed = true; | 2927 SetGLErrorInvalidEnum("glBindValuebufferCHROMIUM", target, "target"); |
2870 break; | 2928 return; |
2871 } | 2929 } |
2872 // TODO(gman): There's a bug here. If the target is invalid the ID will not be | |
2873 // used even though it's marked it as used here. | |
2874 if (changed) { | 2930 if (changed) { |
2875 GetIdHandler(id_namespaces::kValuebuffers)->MarkAsUsedForBind( | 2931 GetIdHandler(id_namespaces::kValuebuffers)->MarkAsUsedForBind( |
2876 this, target, valuebuffer, | 2932 this, target, valuebuffer, |
2877 &GLES2Implementation::BindValuebufferCHROMIUMStub); | 2933 &GLES2Implementation::BindValuebufferCHROMIUMStub); |
2878 } | 2934 } |
2879 } | 2935 } |
2880 | 2936 |
2881 void GLES2Implementation::BindValuebufferCHROMIUMStub(GLenum target, | 2937 void GLES2Implementation::BindValuebufferCHROMIUMStub(GLenum target, |
2882 GLuint valuebuffer) { | 2938 GLuint valuebuffer) { |
2883 helper_->BindValuebufferCHROMIUM(target, valuebuffer); | 2939 helper_->BindValuebufferCHROMIUM(target, valuebuffer); |
(...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4373 return false; | 4429 return false; |
4374 } | 4430 } |
4375 | 4431 |
4376 // Include the auto-generated part of this file. We split this because it means | 4432 // Include the auto-generated part of this file. We split this because it means |
4377 // we can easily edit the non-auto generated parts right here in this file | 4433 // we can easily edit the non-auto generated parts right here in this file |
4378 // instead of having to edit some template or the code generator. | 4434 // instead of having to edit some template or the code generator. |
4379 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 4435 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
4380 | 4436 |
4381 } // namespace gles2 | 4437 } // namespace gles2 |
4382 } // namespace gpu | 4438 } // namespace gpu |
OLD | NEW |