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 "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace gpu { | 10 namespace gpu { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 EXPECT_EQ(0u, param); | 63 EXPECT_EQ(0u, param); |
64 EXPECT_TRUE(manager_->GetAttribPointer( | 64 EXPECT_TRUE(manager_->GetAttribPointer( |
65 ii, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); | 65 ii, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); |
66 EXPECT_TRUE(NULL == ptr); | 66 EXPECT_TRUE(NULL == ptr); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 TEST_F(VertexArrayObjectManagerTest, UnbindBuffer) { | 70 TEST_F(VertexArrayObjectManagerTest, UnbindBuffer) { |
71 const GLuint kBufferToUnbind = 123; | 71 const GLuint kBufferToUnbind = 123; |
72 const GLuint kBufferToRemain = 456; | 72 const GLuint kBufferToRemain = 456; |
| 73 const GLuint kElementArray = 789; |
73 bool changed = false; | 74 bool changed = false; |
74 GLuint ids[2] = { 1, 3, }; | 75 GLuint ids[2] = { 1, 3, }; |
75 manager_->GenVertexArrays(2, ids); | 76 manager_->GenVertexArrays(arraysize(ids), ids); |
76 // Bind buffers to attribs on 2 vaos. | 77 // Bind buffers to attribs on 2 vaos. |
77 for (size_t ii = 0; ii < arraysize(ids); ++ii) { | 78 for (size_t ii = 0; ii < arraysize(ids); ++ii) { |
78 EXPECT_TRUE(manager_->BindVertexArray(ids[ii], &changed)); | 79 EXPECT_TRUE(manager_->BindVertexArray(ids[ii], &changed)); |
79 EXPECT_TRUE(manager_->SetAttribPointer( | 80 EXPECT_TRUE(manager_->SetAttribPointer( |
80 kBufferToUnbind, 0, 4, GL_FLOAT, false, 0, 0)); | 81 kBufferToUnbind, 0, 4, GL_FLOAT, false, 0, 0)); |
81 EXPECT_TRUE(manager_->SetAttribPointer( | 82 EXPECT_TRUE(manager_->SetAttribPointer( |
82 kBufferToRemain, 1, 4, GL_FLOAT, false, 0, 0)); | 83 kBufferToRemain, 1, 4, GL_FLOAT, false, 0, 0)); |
83 EXPECT_TRUE(manager_->SetAttribPointer( | 84 EXPECT_TRUE(manager_->SetAttribPointer( |
84 kBufferToUnbind, 2, 4, GL_FLOAT, false, 0, 0)); | 85 kBufferToUnbind, 2, 4, GL_FLOAT, false, 0, 0)); |
85 EXPECT_TRUE(manager_->SetAttribPointer( | 86 EXPECT_TRUE(manager_->SetAttribPointer( |
86 kBufferToRemain, 3, 4, GL_FLOAT, false, 0, 0)); | 87 kBufferToRemain, 3, 4, GL_FLOAT, false, 0, 0)); |
87 for (size_t jj = 0; jj < 4u; ++jj) { | 88 for (size_t jj = 0; jj < 4u; ++jj) { |
88 manager_->SetAttribEnable(jj, true); | 89 manager_->SetAttribEnable(jj, true); |
89 } | 90 } |
| 91 manager_->BindElementArray(kElementArray); |
90 } | 92 } |
91 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); | 93 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
92 EXPECT_TRUE(manager_->BindVertexArray(ids[0], &changed)); | 94 EXPECT_TRUE(manager_->BindVertexArray(ids[0], &changed)); |
93 // Unbind the buffer. | 95 // Unbind the buffer. |
94 manager_->UnbindBuffer(kBufferToUnbind); | 96 manager_->UnbindBuffer(kBufferToUnbind); |
| 97 manager_->UnbindBuffer(kElementArray); |
95 // The attribs are still enabled but their buffer is 0. | 98 // The attribs are still enabled but their buffer is 0. |
96 EXPECT_TRUE(manager_->HaveEnabledClientSideBuffers()); | 99 EXPECT_TRUE(manager_->HaveEnabledClientSideBuffers()); |
97 // Check the status of the bindings. | 100 // Check the status of the bindings. |
98 uint32 expected[][4] = { | 101 static const uint32 expected[][4] = { |
99 { 0, kBufferToRemain, 0, kBufferToRemain, }, | 102 { 0, kBufferToRemain, 0, kBufferToRemain, }, |
100 { kBufferToUnbind, kBufferToRemain, kBufferToUnbind, kBufferToRemain, }, | 103 { kBufferToUnbind, kBufferToRemain, kBufferToUnbind, kBufferToRemain, }, |
101 }; | 104 }; |
| 105 static const GLuint expected_element_array[] = { |
| 106 0, kElementArray, |
| 107 }; |
102 for (size_t ii = 0; ii < arraysize(ids); ++ii) { | 108 for (size_t ii = 0; ii < arraysize(ids); ++ii) { |
103 EXPECT_TRUE(manager_->BindVertexArray(ids[ii], &changed)); | 109 EXPECT_TRUE(manager_->BindVertexArray(ids[ii], &changed)); |
104 for (size_t jj = 0; jj < 4; ++jj) { | 110 for (size_t jj = 0; jj < 4; ++jj) { |
105 uint32 param = 1; | 111 uint32 param = 1; |
106 EXPECT_TRUE(manager_->GetVertexAttrib( | 112 EXPECT_TRUE(manager_->GetVertexAttrib( |
107 jj, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); | 113 jj, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); |
108 EXPECT_EQ(expected[ii][jj], param) | 114 EXPECT_EQ(expected[ii][jj], param) |
109 << "id: " << ids[ii] << ", attrib: " << jj; | 115 << "id: " << ids[ii] << ", attrib: " << jj; |
110 } | 116 } |
| 117 EXPECT_EQ(expected_element_array[ii], |
| 118 manager_->bound_element_array_buffer()); |
111 } | 119 } |
| 120 |
112 // The vao that was not bound still has all service side bufferws. | 121 // The vao that was not bound still has all service side bufferws. |
113 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); | 122 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
114 } | 123 } |
115 | 124 |
116 TEST_F(VertexArrayObjectManagerTest, GetSet) { | 125 TEST_F(VertexArrayObjectManagerTest, GetSet) { |
117 const char* dummy = "dummy"; | 126 const char* dummy = "dummy"; |
118 const void* p = reinterpret_cast<const void*>(dummy); | 127 const void* p = reinterpret_cast<const void*>(dummy); |
119 manager_->SetAttribEnable(1, true); | 128 manager_->SetAttribEnable(1, true); |
120 manager_->SetAttribPointer(123, 1, 3, GL_BYTE, true, 3, p); | 129 manager_->SetAttribPointer(123, 1, 3, GL_BYTE, true, 3, p); |
121 uint32 param; | 130 uint32 param; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 manager_->SetAttribPointer(0, 1, 3, GL_BYTE, true, 3, NULL); | 170 manager_->SetAttribPointer(0, 1, 3, GL_BYTE, true, 3, NULL); |
162 EXPECT_TRUE(manager_->HaveEnabledClientSideBuffers()); | 171 EXPECT_TRUE(manager_->HaveEnabledClientSideBuffers()); |
163 // Check disabling the array. | 172 // Check disabling the array. |
164 manager_->SetAttribEnable(1, false); | 173 manager_->SetAttribEnable(1, false); |
165 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); | 174 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
166 } | 175 } |
167 | 176 |
168 TEST_F(VertexArrayObjectManagerTest, BindElementArray) { | 177 TEST_F(VertexArrayObjectManagerTest, BindElementArray) { |
169 bool changed = false; | 178 bool changed = false; |
170 GLuint ids[2] = { 1, 3, }; | 179 GLuint ids[2] = { 1, 3, }; |
171 manager_->GenVertexArrays(2, ids); | 180 manager_->GenVertexArrays(arraysize(ids), ids); |
172 | 181 |
173 // Check the default element array is 0. | 182 // Check the default element array is 0. |
174 EXPECT_EQ(0u, manager_->bound_element_array_buffer()); | 183 EXPECT_EQ(0u, manager_->bound_element_array_buffer()); |
175 // Check binding the same array does not need a service call. | 184 // Check binding the same array does not need a service call. |
176 EXPECT_FALSE(manager_->BindElementArray(0u)); | 185 EXPECT_FALSE(manager_->BindElementArray(0u)); |
177 // Check binding a new element array requires a service call. | 186 // Check binding a new element array requires a service call. |
178 EXPECT_TRUE(manager_->BindElementArray(55u)); | 187 EXPECT_TRUE(manager_->BindElementArray(55u)); |
179 // Check the element array was bound. | 188 // Check the element array was bound. |
180 EXPECT_EQ(55u, manager_->bound_element_array_buffer()); | 189 EXPECT_EQ(55u, manager_->bound_element_array_buffer()); |
181 // Check binding the same array does not need a service call. | 190 // Check binding the same array does not need a service call. |
(...skipping 19 matching lines...) Expand all Loading... |
201 EXPECT_EQ(11u, manager_->bound_element_array_buffer()); | 210 EXPECT_EQ(11u, manager_->bound_element_array_buffer()); |
202 } | 211 } |
203 | 212 |
204 TEST_F(VertexArrayObjectManagerTest, GenBindDelete) { | 213 TEST_F(VertexArrayObjectManagerTest, GenBindDelete) { |
205 // Check unknown array fails. | 214 // Check unknown array fails. |
206 bool changed = false; | 215 bool changed = false; |
207 EXPECT_FALSE(manager_->BindVertexArray(123, &changed)); | 216 EXPECT_FALSE(manager_->BindVertexArray(123, &changed)); |
208 EXPECT_FALSE(changed); | 217 EXPECT_FALSE(changed); |
209 | 218 |
210 GLuint ids[2] = { 1, 3, }; | 219 GLuint ids[2] = { 1, 3, }; |
211 manager_->GenVertexArrays(2, ids); | 220 manager_->GenVertexArrays(arraysize(ids), ids); |
212 // Check Genned arrays succeed. | 221 // Check Genned arrays succeed. |
213 EXPECT_TRUE(manager_->BindVertexArray(1, &changed)); | 222 EXPECT_TRUE(manager_->BindVertexArray(1, &changed)); |
214 EXPECT_TRUE(changed); | 223 EXPECT_TRUE(changed); |
215 EXPECT_TRUE(manager_->BindVertexArray(3, &changed)); | 224 EXPECT_TRUE(manager_->BindVertexArray(3, &changed)); |
216 EXPECT_TRUE(changed); | 225 EXPECT_TRUE(changed); |
217 | 226 |
218 // Check binding the same array returns changed as false. | 227 // Check binding the same array returns changed as false. |
219 EXPECT_TRUE(manager_->BindVertexArray(3, &changed)); | 228 EXPECT_TRUE(manager_->BindVertexArray(3, &changed)); |
220 EXPECT_FALSE(changed); | 229 EXPECT_FALSE(changed); |
221 | 230 |
(...skipping 14 matching lines...) Expand all Loading... |
236 EXPECT_TRUE(manager_->IsReservedId(kClientSideArrayBuffer)); | 245 EXPECT_TRUE(manager_->IsReservedId(kClientSideArrayBuffer)); |
237 EXPECT_TRUE(manager_->IsReservedId(kClientSideElementArrayBuffer)); | 246 EXPECT_TRUE(manager_->IsReservedId(kClientSideElementArrayBuffer)); |
238 EXPECT_FALSE(manager_->IsReservedId(0)); | 247 EXPECT_FALSE(manager_->IsReservedId(0)); |
239 EXPECT_FALSE(manager_->IsReservedId(1)); | 248 EXPECT_FALSE(manager_->IsReservedId(1)); |
240 EXPECT_FALSE(manager_->IsReservedId(2)); | 249 EXPECT_FALSE(manager_->IsReservedId(2)); |
241 } | 250 } |
242 | 251 |
243 } // namespace gles2 | 252 } // namespace gles2 |
244 } // namespace gpu | 253 } // namespace gpu |
245 | 254 |
OLD | NEW |