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/client/vertex_array_object_manager.h" | 5 #include "gpu/command_buffer/client/vertex_array_object_manager.h" |
6 | 6 |
7 #include <GLES2/gl2ext.h> | 7 #include <GLES2/gl2ext.h> |
8 #include <GLES3/gl3.h> | 8 #include <GLES3/gl3.h> |
| 9 #include <stddef.h> |
| 10 #include <stdint.h> |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 | 12 |
11 namespace gpu { | 13 namespace gpu { |
12 namespace gles2 { | 14 namespace gles2 { |
13 | 15 |
14 class VertexArrayObjectManagerTest : public testing::Test { | 16 class VertexArrayObjectManagerTest : public testing::Test { |
15 protected: | 17 protected: |
16 static const GLuint kMaxAttribs = 4; | 18 static const GLuint kMaxAttribs = 4; |
17 static const GLuint kClientSideArrayBuffer = 0x1234; | 19 static const GLuint kClientSideArrayBuffer = 0x1234; |
18 static const GLuint kClientSideElementArrayBuffer = 0x1235; | 20 static const GLuint kClientSideElementArrayBuffer = 0x1235; |
(...skipping 14 matching lines...) Expand all Loading... |
33 // GCC requires these declarations, but MSVC requires they not be present | 35 // GCC requires these declarations, but MSVC requires they not be present |
34 #ifndef _MSC_VER | 36 #ifndef _MSC_VER |
35 const GLuint VertexArrayObjectManagerTest::kMaxAttribs; | 37 const GLuint VertexArrayObjectManagerTest::kMaxAttribs; |
36 const GLuint VertexArrayObjectManagerTest::kClientSideArrayBuffer; | 38 const GLuint VertexArrayObjectManagerTest::kClientSideArrayBuffer; |
37 const GLuint VertexArrayObjectManagerTest::kClientSideElementArrayBuffer; | 39 const GLuint VertexArrayObjectManagerTest::kClientSideElementArrayBuffer; |
38 #endif | 40 #endif |
39 | 41 |
40 TEST_F(VertexArrayObjectManagerTest, Basic) { | 42 TEST_F(VertexArrayObjectManagerTest, Basic) { |
41 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); | 43 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
42 // Check out of bounds access. | 44 // Check out of bounds access. |
43 uint32 param; | 45 uint32_t param; |
44 void* ptr; | 46 void* ptr; |
45 EXPECT_FALSE(manager_->GetVertexAttrib( | 47 EXPECT_FALSE(manager_->GetVertexAttrib( |
46 kMaxAttribs, GL_VERTEX_ATTRIB_ARRAY_ENABLED, ¶m)); | 48 kMaxAttribs, GL_VERTEX_ATTRIB_ARRAY_ENABLED, ¶m)); |
47 EXPECT_FALSE(manager_->GetAttribPointer( | 49 EXPECT_FALSE(manager_->GetAttribPointer( |
48 kMaxAttribs, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); | 50 kMaxAttribs, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); |
49 // Check defaults. | 51 // Check defaults. |
50 for (GLuint ii = 0; ii < kMaxAttribs; ++ii) { | 52 for (GLuint ii = 0; ii < kMaxAttribs; ++ii) { |
51 EXPECT_TRUE(manager_->GetVertexAttrib( | 53 EXPECT_TRUE(manager_->GetVertexAttrib( |
52 ii, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); | 54 ii, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); |
53 EXPECT_EQ(0u, param); | 55 EXPECT_EQ(0u, param); |
54 EXPECT_TRUE(manager_->GetVertexAttrib( | 56 EXPECT_TRUE(manager_->GetVertexAttrib( |
55 ii, GL_VERTEX_ATTRIB_ARRAY_ENABLED, ¶m)); | 57 ii, GL_VERTEX_ATTRIB_ARRAY_ENABLED, ¶m)); |
56 EXPECT_EQ(0u, param); | 58 EXPECT_EQ(0u, param); |
57 EXPECT_TRUE(manager_->GetVertexAttrib( | 59 EXPECT_TRUE(manager_->GetVertexAttrib( |
58 ii, GL_VERTEX_ATTRIB_ARRAY_SIZE, ¶m)); | 60 ii, GL_VERTEX_ATTRIB_ARRAY_SIZE, ¶m)); |
59 EXPECT_EQ(4u, param); | 61 EXPECT_EQ(4u, param); |
60 EXPECT_TRUE(manager_->GetVertexAttrib( | 62 EXPECT_TRUE(manager_->GetVertexAttrib( |
61 ii, GL_VERTEX_ATTRIB_ARRAY_TYPE, ¶m)); | 63 ii, GL_VERTEX_ATTRIB_ARRAY_TYPE, ¶m)); |
62 EXPECT_EQ(static_cast<uint32>(GL_FLOAT), param); | 64 EXPECT_EQ(static_cast<uint32_t>(GL_FLOAT), param); |
63 EXPECT_TRUE(manager_->GetVertexAttrib( | 65 EXPECT_TRUE(manager_->GetVertexAttrib( |
64 ii, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, ¶m)); | 66 ii, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, ¶m)); |
65 EXPECT_EQ(0u, param); | 67 EXPECT_EQ(0u, param); |
66 EXPECT_TRUE(manager_->GetAttribPointer( | 68 EXPECT_TRUE(manager_->GetAttribPointer( |
67 ii, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); | 69 ii, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); |
68 EXPECT_TRUE(NULL == ptr); | 70 EXPECT_TRUE(NULL == ptr); |
69 } | 71 } |
70 } | 72 } |
71 | 73 |
72 TEST_F(VertexArrayObjectManagerTest, UnbindBuffer) { | 74 TEST_F(VertexArrayObjectManagerTest, UnbindBuffer) { |
(...skipping 20 matching lines...) Expand all Loading... |
93 manager_->BindElementArray(kElementArray); | 95 manager_->BindElementArray(kElementArray); |
94 } | 96 } |
95 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); | 97 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
96 EXPECT_TRUE(manager_->BindVertexArray(ids[0], &changed)); | 98 EXPECT_TRUE(manager_->BindVertexArray(ids[0], &changed)); |
97 // Unbind the buffer. | 99 // Unbind the buffer. |
98 manager_->UnbindBuffer(kBufferToUnbind); | 100 manager_->UnbindBuffer(kBufferToUnbind); |
99 manager_->UnbindBuffer(kElementArray); | 101 manager_->UnbindBuffer(kElementArray); |
100 // The attribs are still enabled but their buffer is 0. | 102 // The attribs are still enabled but their buffer is 0. |
101 EXPECT_TRUE(manager_->HaveEnabledClientSideBuffers()); | 103 EXPECT_TRUE(manager_->HaveEnabledClientSideBuffers()); |
102 // Check the status of the bindings. | 104 // Check the status of the bindings. |
103 static const uint32 expected[][4] = { | 105 static const uint32_t expected[][4] = { |
104 { 0, kBufferToRemain, 0, kBufferToRemain, }, | 106 { |
105 { kBufferToUnbind, kBufferToRemain, kBufferToUnbind, kBufferToRemain, }, | 107 0, kBufferToRemain, 0, kBufferToRemain, |
| 108 }, |
| 109 { |
| 110 kBufferToUnbind, kBufferToRemain, kBufferToUnbind, kBufferToRemain, |
| 111 }, |
106 }; | 112 }; |
107 static const GLuint expected_element_array[] = { | 113 static const GLuint expected_element_array[] = { |
108 0, kElementArray, | 114 0, kElementArray, |
109 }; | 115 }; |
110 for (size_t ii = 0; ii < arraysize(ids); ++ii) { | 116 for (size_t ii = 0; ii < arraysize(ids); ++ii) { |
111 EXPECT_TRUE(manager_->BindVertexArray(ids[ii], &changed)); | 117 EXPECT_TRUE(manager_->BindVertexArray(ids[ii], &changed)); |
112 for (size_t jj = 0; jj < 4; ++jj) { | 118 for (size_t jj = 0; jj < 4; ++jj) { |
113 uint32 param = 1; | 119 uint32_t param = 1; |
114 EXPECT_TRUE(manager_->GetVertexAttrib( | 120 EXPECT_TRUE(manager_->GetVertexAttrib( |
115 jj, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); | 121 jj, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); |
116 EXPECT_EQ(expected[ii][jj], param) | 122 EXPECT_EQ(expected[ii][jj], param) |
117 << "id: " << ids[ii] << ", attrib: " << jj; | 123 << "id: " << ids[ii] << ", attrib: " << jj; |
118 } | 124 } |
119 EXPECT_EQ(expected_element_array[ii], | 125 EXPECT_EQ(expected_element_array[ii], |
120 manager_->bound_element_array_buffer()); | 126 manager_->bound_element_array_buffer()); |
121 } | 127 } |
122 | 128 |
123 // The vao that was not bound still has all service side bufferws. | 129 // The vao that was not bound still has all service side bufferws. |
124 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); | 130 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
125 | 131 |
126 // Make sure unbinding 0 does not effect count incorrectly. | 132 // Make sure unbinding 0 does not effect count incorrectly. |
127 EXPECT_TRUE(manager_->BindVertexArray(0, &changed)); | 133 EXPECT_TRUE(manager_->BindVertexArray(0, &changed)); |
128 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); | 134 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
129 manager_->SetAttribEnable(2, true); | 135 manager_->SetAttribEnable(2, true); |
130 manager_->UnbindBuffer(0); | 136 manager_->UnbindBuffer(0); |
131 manager_->SetAttribEnable(2, false); | 137 manager_->SetAttribEnable(2, false); |
132 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); | 138 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
133 } | 139 } |
134 | 140 |
135 TEST_F(VertexArrayObjectManagerTest, GetSet) { | 141 TEST_F(VertexArrayObjectManagerTest, GetSet) { |
136 const char* dummy = "dummy"; | 142 const char* dummy = "dummy"; |
137 const void* p = reinterpret_cast<const void*>(dummy); | 143 const void* p = reinterpret_cast<const void*>(dummy); |
138 manager_->SetAttribEnable(1, true); | 144 manager_->SetAttribEnable(1, true); |
139 manager_->SetAttribPointer(123, 1, 3, GL_BYTE, true, 3, p, GL_TRUE); | 145 manager_->SetAttribPointer(123, 1, 3, GL_BYTE, true, 3, p, GL_TRUE); |
140 uint32 param; | 146 uint32_t param; |
141 void* ptr; | 147 void* ptr; |
142 EXPECT_TRUE(manager_->GetVertexAttrib( | 148 EXPECT_TRUE(manager_->GetVertexAttrib( |
143 1, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); | 149 1, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); |
144 EXPECT_EQ(123u, param); | 150 EXPECT_EQ(123u, param); |
145 EXPECT_TRUE(manager_->GetVertexAttrib( | 151 EXPECT_TRUE(manager_->GetVertexAttrib( |
146 1, GL_VERTEX_ATTRIB_ARRAY_ENABLED, ¶m)); | 152 1, GL_VERTEX_ATTRIB_ARRAY_ENABLED, ¶m)); |
147 EXPECT_NE(0u, param); | 153 EXPECT_NE(0u, param); |
148 EXPECT_TRUE(manager_->GetVertexAttrib( | 154 EXPECT_TRUE(manager_->GetVertexAttrib( |
149 1, GL_VERTEX_ATTRIB_ARRAY_SIZE, ¶m)); | 155 1, GL_VERTEX_ATTRIB_ARRAY_SIZE, ¶m)); |
150 EXPECT_EQ(3u, param); | 156 EXPECT_EQ(3u, param); |
151 EXPECT_TRUE(manager_->GetVertexAttrib( | 157 EXPECT_TRUE(manager_->GetVertexAttrib( |
152 1, GL_VERTEX_ATTRIB_ARRAY_TYPE, ¶m)); | 158 1, GL_VERTEX_ATTRIB_ARRAY_TYPE, ¶m)); |
153 EXPECT_EQ(static_cast<uint32>(GL_BYTE), param); | 159 EXPECT_EQ(static_cast<uint32_t>(GL_BYTE), param); |
154 EXPECT_TRUE(manager_->GetVertexAttrib( | 160 EXPECT_TRUE(manager_->GetVertexAttrib( |
155 1, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, ¶m)); | 161 1, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, ¶m)); |
156 EXPECT_NE(0u, param); | 162 EXPECT_NE(0u, param); |
157 EXPECT_TRUE(manager_->GetVertexAttrib( | 163 EXPECT_TRUE(manager_->GetVertexAttrib( |
158 1, GL_VERTEX_ATTRIB_ARRAY_INTEGER, ¶m)); | 164 1, GL_VERTEX_ATTRIB_ARRAY_INTEGER, ¶m)); |
159 EXPECT_EQ(1u, param); | 165 EXPECT_EQ(1u, param); |
160 EXPECT_TRUE(manager_->GetAttribPointer( | 166 EXPECT_TRUE(manager_->GetAttribPointer( |
161 1, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); | 167 1, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); |
162 EXPECT_EQ(p, ptr); | 168 EXPECT_EQ(p, ptr); |
163 | 169 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 EXPECT_TRUE(manager_->IsReservedId(kClientSideArrayBuffer)); | 264 EXPECT_TRUE(manager_->IsReservedId(kClientSideArrayBuffer)); |
259 EXPECT_TRUE(manager_->IsReservedId(kClientSideElementArrayBuffer)); | 265 EXPECT_TRUE(manager_->IsReservedId(kClientSideElementArrayBuffer)); |
260 EXPECT_FALSE(manager_->IsReservedId(0)); | 266 EXPECT_FALSE(manager_->IsReservedId(0)); |
261 EXPECT_FALSE(manager_->IsReservedId(1)); | 267 EXPECT_FALSE(manager_->IsReservedId(1)); |
262 EXPECT_FALSE(manager_->IsReservedId(2)); | 268 EXPECT_FALSE(manager_->IsReservedId(2)); |
263 } | 269 } |
264 | 270 |
265 } // namespace gles2 | 271 } // namespace gles2 |
266 } // namespace gpu | 272 } // namespace gpu |
267 | 273 |
OLD | NEW |