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 "gpu/command_buffer/common/gles2_cmd_format.h" | 7 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
9 #include "gpu/command_buffer/common/gl_mock.h" | 9 #include "gpu/command_buffer/common/gl_mock.h" |
10 #include "gpu/command_buffer/common/id_allocator.h" | 10 #include "gpu/command_buffer/common/id_allocator.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 227 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
228 | 228 |
229 // Try with size > 2 (ie, vec3 instead of vec2) | 229 // Try with size > 2 (ie, vec3 instead of vec2) |
230 DoVertexAttribPointer(1, 3, GL_FLOAT, 0, 0); | 230 DoVertexAttribPointer(1, 3, GL_FLOAT, 0, 0); |
231 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 231 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
232 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); | 232 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
233 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 233 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
234 | 234 |
235 // Try with stride > 8 (vec2 + vec2 byte) | 235 // Try with stride > 8 (vec2 + vec2 byte) |
236 GLfloat f; | 236 GLfloat f; |
237 DoVertexAttribPointer(1, 2, GL_FLOAT, sizeof(f) * 2 + 1, 0); | 237 DoVertexAttribPointer(1, 2, GL_FLOAT, sizeof(f) * 2 + sizeof(f), 0); |
238 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 238 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
239 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); | 239 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
240 EXPECT_EQ(GL_NO_ERROR, GetGLError()); | 240 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
241 } | 241 } |
242 | 242 |
243 TEST_F(GLES2DecoderWithShaderTest, DrawElementsNoAttributesSucceeds) { | 243 TEST_F(GLES2DecoderWithShaderTest, DrawElementsNoAttributesSucceeds) { |
244 SetupTexture(); | 244 SetupTexture(); |
245 SetupIndexBuffer(); | 245 SetupIndexBuffer(); |
246 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0); | 246 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0); |
247 EXPECT_CALL(*gl_, DrawElements(GL_TRIANGLES, kValidIndexRangeCount, | 247 EXPECT_CALL(*gl_, DrawElements(GL_TRIANGLES, kValidIndexRangeCount, |
(...skipping 2403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2651 -1, // stencil mask front, | 2651 -1, // stencil mask front, |
2652 0.5f, // depth | 2652 0.5f, // depth |
2653 1, // depth mask | 2653 1, // depth mask |
2654 false); // scissor test | 2654 false); // scissor test |
2655 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_cmd)); | 2655 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_cmd)); |
2656 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_cmd)); | 2656 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_cmd)); |
2657 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 2657 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
2658 } | 2658 } |
2659 #endif | 2659 #endif |
2660 | 2660 |
| 2661 TEST_F(GLES2DecoderWithShaderTest, VertexAttribPointer) { |
| 2662 SetupVertexBuffer(); |
| 2663 static const GLenum types[] = { |
| 2664 GL_BYTE, |
| 2665 GL_UNSIGNED_BYTE, |
| 2666 GL_SHORT, |
| 2667 GL_UNSIGNED_SHORT, |
| 2668 GL_FLOAT, |
| 2669 GL_FIXED, |
| 2670 GL_INT, |
| 2671 GL_UNSIGNED_INT, |
| 2672 }; |
| 2673 static const GLsizei sizes[] = { |
| 2674 1, |
| 2675 1, |
| 2676 2, |
| 2677 2, |
| 2678 4, |
| 2679 4, |
| 2680 4, |
| 2681 4, |
| 2682 }; |
| 2683 static const GLuint indices[] = { |
| 2684 0, |
| 2685 1, |
| 2686 kNumVertexAttribs - 1, |
| 2687 kNumVertexAttribs, |
| 2688 }; |
| 2689 static const GLsizei offset_mult[] = { |
| 2690 0, |
| 2691 0, |
| 2692 1, |
| 2693 1, |
| 2694 2, |
| 2695 1000, |
| 2696 }; |
| 2697 static const GLsizei offset_offset[] = { |
| 2698 0, |
| 2699 1, |
| 2700 0, |
| 2701 1, |
| 2702 0, |
| 2703 0, |
| 2704 }; |
| 2705 static const GLsizei stride_mult[] = { |
| 2706 -1, |
| 2707 0, |
| 2708 0, |
| 2709 1, |
| 2710 1, |
| 2711 2, |
| 2712 1000, |
| 2713 }; |
| 2714 static const GLsizei stride_offset[] = { |
| 2715 0, |
| 2716 0, |
| 2717 1, |
| 2718 0, |
| 2719 1, |
| 2720 0, |
| 2721 0, |
| 2722 }; |
| 2723 for (size_t tt = 0; tt < arraysize(types); ++tt) { |
| 2724 GLenum type = types[tt]; |
| 2725 GLsizei num_bytes = sizes[tt]; |
| 2726 for (size_t ii = 0; ii < arraysize(indices); ++ii) { |
| 2727 GLuint index = indices[ii]; |
| 2728 for (GLint size = 0; size < 5; ++size) { |
| 2729 for (size_t oo = 0; oo < arraysize(offset_mult); ++oo) { |
| 2730 GLuint offset = num_bytes * offset_mult[oo] + offset_offset[oo]; |
| 2731 for (size_t ss = 0; ss <= arraysize(stride_mult); ++ss) { |
| 2732 GLsizei stride = num_bytes * stride_mult[ss] + stride_offset[ss]; |
| 2733 for (int normalize = 0; normalize < 2; ++normalize) { |
| 2734 bool index_good = index < static_cast<GLuint>(kNumVertexAttribs); |
| 2735 bool size_good = (size > 0 && size < 5); |
| 2736 bool offset_good = (offset % num_bytes == 0); |
| 2737 bool stride_good = (stride % num_bytes == 0) && stride >= 0 && |
| 2738 stride <= 255; |
| 2739 bool type_good = (type != GL_INT && type != GL_UNSIGNED_INT && |
| 2740 type != GL_FIXED); |
| 2741 bool good = size_good && offset_good && stride_good && |
| 2742 type_good && index_good; |
| 2743 bool call = good && (type != GL_FIXED); |
| 2744 if (call) { |
| 2745 EXPECT_CALL(*gl_, VertexAttribPointer( |
| 2746 index, size, type, normalize, stride, |
| 2747 BufferOffset(offset))); |
| 2748 } |
| 2749 VertexAttribPointer cmd; |
| 2750 cmd.Init(index, size, type, normalize, stride, offset); |
| 2751 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
| 2752 if (good) { |
| 2753 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 2754 } else if (size_good && |
| 2755 offset_good && |
| 2756 stride_good && |
| 2757 type_good && |
| 2758 !index_good) { |
| 2759 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); |
| 2760 } else if (size_good && |
| 2761 offset_good && |
| 2762 stride_good && |
| 2763 !type_good && |
| 2764 index_good) { |
| 2765 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); |
| 2766 } else if (size_good && |
| 2767 offset_good && |
| 2768 !stride_good && |
| 2769 type_good && |
| 2770 index_good) { |
| 2771 if (stride < 0 || stride > 255) { |
| 2772 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); |
| 2773 } else { |
| 2774 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 2775 } |
| 2776 } else if (size_good && |
| 2777 !offset_good && |
| 2778 stride_good && |
| 2779 type_good && |
| 2780 index_good) { |
| 2781 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); |
| 2782 } else if (!size_good && |
| 2783 offset_good && |
| 2784 stride_good && |
| 2785 type_good && |
| 2786 index_good) { |
| 2787 EXPECT_EQ(GL_INVALID_VALUE, GetGLError()); |
| 2788 } else { |
| 2789 EXPECT_NE(GL_NO_ERROR, GetGLError()); |
| 2790 } |
| 2791 } |
| 2792 } |
| 2793 } |
| 2794 } |
| 2795 } |
| 2796 } |
| 2797 } |
| 2798 |
2661 // TODO(gman): BufferData | 2799 // TODO(gman): BufferData |
2662 | 2800 |
2663 // TODO(gman): BufferDataImmediate | 2801 // TODO(gman): BufferDataImmediate |
2664 | 2802 |
2665 // TODO(gman): BufferSubData | 2803 // TODO(gman): BufferSubData |
2666 | 2804 |
2667 // TODO(gman): BufferSubDataImmediate | 2805 // TODO(gman): BufferSubDataImmediate |
2668 | 2806 |
2669 // TODO(gman): CompressedTexImage2D | 2807 // TODO(gman): CompressedTexImage2D |
2670 | 2808 |
(...skipping 10 matching lines...) Expand all Loading... |
2681 // TODO(gman): TexImage2D | 2819 // TODO(gman): TexImage2D |
2682 | 2820 |
2683 // TODO(gman): TexImage2DImmediate | 2821 // TODO(gman): TexImage2DImmediate |
2684 | 2822 |
2685 // TODO(gman): TexSubImage2DImmediate | 2823 // TODO(gman): TexSubImage2DImmediate |
2686 | 2824 |
2687 // TODO(gman): UseProgram | 2825 // TODO(gman): UseProgram |
2688 | 2826 |
2689 // TODO(gman): SwapBuffers | 2827 // TODO(gman): SwapBuffers |
2690 | 2828 |
2691 // TODO(gman): VertexAttribPointer | |
2692 | |
2693 } // namespace gles2 | 2829 } // namespace gles2 |
2694 } // namespace gpu | 2830 } // namespace gpu |
OLD | NEW |