OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "gpu/command_buffer/client/vertex_array_object_manager.h" |
| 6 |
| 7 #include <GLES2/gl2ext.h> |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace gpu { |
| 11 namespace gles2 { |
| 12 |
| 13 class VertexArrayObjectManagerTest : public testing::Test { |
| 14 protected: |
| 15 static const GLuint kMaxAttribs = 4; |
| 16 static const GLuint kClientSideArrayBuffer = 0x1234; |
| 17 static const GLuint kClientSideElementArrayBuffer = 0x1235; |
| 18 |
| 19 virtual void SetUp() { |
| 20 manager_.reset(new VertexArrayObjectManager( |
| 21 kMaxAttribs, |
| 22 kClientSideArrayBuffer, |
| 23 kClientSideElementArrayBuffer)); |
| 24 } |
| 25 virtual void TearDown() { |
| 26 } |
| 27 |
| 28 scoped_ptr<VertexArrayObjectManager> manager_; |
| 29 }; |
| 30 |
| 31 // GCC requires these declarations, but MSVC requires they not be present |
| 32 #ifndef _MSC_VER |
| 33 const GLuint VertexArrayObjectManagerTest::kMaxAttribs; |
| 34 const GLuint VertexArrayObjectManagerTest::kClientSideArrayBuffer; |
| 35 const GLuint VertexArrayObjectManagerTest::kClientSideElementArrayBuffer; |
| 36 #endif |
| 37 |
| 38 TEST_F(VertexArrayObjectManagerTest, Basic) { |
| 39 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
| 40 // Check out of bounds access. |
| 41 uint32 param; |
| 42 void* ptr; |
| 43 EXPECT_FALSE(manager_->GetVertexAttrib( |
| 44 kMaxAttribs, GL_VERTEX_ATTRIB_ARRAY_ENABLED, ¶m)); |
| 45 EXPECT_FALSE(manager_->GetAttribPointer( |
| 46 kMaxAttribs, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); |
| 47 // Check defaults. |
| 48 for (GLuint ii = 0; ii < kMaxAttribs; ++ii) { |
| 49 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 50 ii, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); |
| 51 EXPECT_EQ(0u, param); |
| 52 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 53 ii, GL_VERTEX_ATTRIB_ARRAY_ENABLED, ¶m)); |
| 54 EXPECT_EQ(0u, param); |
| 55 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 56 ii, GL_VERTEX_ATTRIB_ARRAY_SIZE, ¶m)); |
| 57 EXPECT_EQ(4u, param); |
| 58 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 59 ii, GL_VERTEX_ATTRIB_ARRAY_TYPE, ¶m)); |
| 60 EXPECT_EQ(static_cast<uint32>(GL_FLOAT), param); |
| 61 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 62 ii, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, ¶m)); |
| 63 EXPECT_EQ(0u, param); |
| 64 EXPECT_TRUE(manager_->GetAttribPointer( |
| 65 ii, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); |
| 66 EXPECT_TRUE(NULL == ptr); |
| 67 } |
| 68 } |
| 69 |
| 70 TEST_F(VertexArrayObjectManagerTest, UnbindBuffer) { |
| 71 const GLuint kBufferToUnbind = 123; |
| 72 const GLuint kBufferToRemain = 456; |
| 73 bool changed = false; |
| 74 GLuint ids[2] = { 1, 3, }; |
| 75 manager_->GenVertexArrays(2, ids); |
| 76 // Bind buffers to attribs on 2 vaos. |
| 77 for (size_t ii = 0; ii < arraysize(ids); ++ii) { |
| 78 EXPECT_TRUE(manager_->BindVertexArray(ids[ii], &changed)); |
| 79 EXPECT_TRUE(manager_->SetAttribPointer( |
| 80 kBufferToUnbind, 0, 4, GL_FLOAT, false, 0, 0)); |
| 81 EXPECT_TRUE(manager_->SetAttribPointer( |
| 82 kBufferToRemain, 1, 4, GL_FLOAT, false, 0, 0)); |
| 83 EXPECT_TRUE(manager_->SetAttribPointer( |
| 84 kBufferToUnbind, 2, 4, GL_FLOAT, false, 0, 0)); |
| 85 EXPECT_TRUE(manager_->SetAttribPointer( |
| 86 kBufferToRemain, 3, 4, GL_FLOAT, false, 0, 0)); |
| 87 for (size_t jj = 0; jj < 4u; ++jj) { |
| 88 manager_->SetAttribEnable(jj, true); |
| 89 } |
| 90 } |
| 91 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
| 92 EXPECT_TRUE(manager_->BindVertexArray(ids[0], &changed)); |
| 93 // Unbind the buffer. |
| 94 manager_->UnbindBuffer(kBufferToUnbind); |
| 95 // The attribs are still enabled but their buffer is 0. |
| 96 EXPECT_TRUE(manager_->HaveEnabledClientSideBuffers()); |
| 97 // Check the status of the bindings. |
| 98 uint32 expected[][4] = { |
| 99 { 0, kBufferToRemain, 0, kBufferToRemain, }, |
| 100 { kBufferToUnbind, kBufferToRemain, kBufferToUnbind, kBufferToRemain, }, |
| 101 }; |
| 102 for (size_t ii = 0; ii < arraysize(ids); ++ii) { |
| 103 EXPECT_TRUE(manager_->BindVertexArray(ids[ii], &changed)); |
| 104 for (size_t jj = 0; jj < 4; ++jj) { |
| 105 uint32 param = 1; |
| 106 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 107 jj, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); |
| 108 EXPECT_EQ(expected[ii][jj], param) |
| 109 << "id: " << ids[ii] << ", attrib: " << jj; |
| 110 } |
| 111 } |
| 112 // The vao that was not bound still has all service side bufferws. |
| 113 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
| 114 } |
| 115 |
| 116 TEST_F(VertexArrayObjectManagerTest, GetSet) { |
| 117 const char* dummy = "dummy"; |
| 118 const void* p = reinterpret_cast<const void*>(dummy); |
| 119 manager_->SetAttribEnable(1, true); |
| 120 manager_->SetAttribPointer(123, 1, 3, GL_BYTE, true, 3, p); |
| 121 uint32 param; |
| 122 void* ptr; |
| 123 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 124 1, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, ¶m)); |
| 125 EXPECT_EQ(123u, param); |
| 126 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 127 1, GL_VERTEX_ATTRIB_ARRAY_ENABLED, ¶m)); |
| 128 EXPECT_NE(0u, param); |
| 129 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 130 1, GL_VERTEX_ATTRIB_ARRAY_SIZE, ¶m)); |
| 131 EXPECT_EQ(3u, param); |
| 132 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 133 1, GL_VERTEX_ATTRIB_ARRAY_TYPE, ¶m)); |
| 134 EXPECT_EQ(static_cast<uint32>(GL_BYTE), param); |
| 135 EXPECT_TRUE(manager_->GetVertexAttrib( |
| 136 1, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, ¶m)); |
| 137 EXPECT_NE(0u, param); |
| 138 EXPECT_TRUE(manager_->GetAttribPointer( |
| 139 1, GL_VERTEX_ATTRIB_ARRAY_POINTER, &ptr)); |
| 140 EXPECT_EQ(p, ptr); |
| 141 |
| 142 // Check that getting the divisor is passed to the service. |
| 143 // This is because the divisor is an optional feature which |
| 144 // only the service can validate. |
| 145 EXPECT_FALSE(manager_->GetVertexAttrib( |
| 146 0, GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, ¶m)); |
| 147 } |
| 148 |
| 149 TEST_F(VertexArrayObjectManagerTest, HaveEnabledClientSideArrays) { |
| 150 // Check turning on an array. |
| 151 manager_->SetAttribEnable(1, true); |
| 152 EXPECT_TRUE(manager_->HaveEnabledClientSideBuffers()); |
| 153 // Check turning off an array. |
| 154 manager_->SetAttribEnable(1, false); |
| 155 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
| 156 // Check turning on an array and assigning a buffer. |
| 157 manager_->SetAttribEnable(1, true); |
| 158 manager_->SetAttribPointer(123, 1, 3, GL_BYTE, true, 3, NULL); |
| 159 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
| 160 // Check unassigning a buffer. |
| 161 manager_->SetAttribPointer(0, 1, 3, GL_BYTE, true, 3, NULL); |
| 162 EXPECT_TRUE(manager_->HaveEnabledClientSideBuffers()); |
| 163 // Check disabling the array. |
| 164 manager_->SetAttribEnable(1, false); |
| 165 EXPECT_FALSE(manager_->HaveEnabledClientSideBuffers()); |
| 166 } |
| 167 |
| 168 TEST_F(VertexArrayObjectManagerTest, BindElementArray) { |
| 169 bool changed = false; |
| 170 GLuint ids[2] = { 1, 3, }; |
| 171 manager_->GenVertexArrays(2, ids); |
| 172 |
| 173 // Check the default element array is 0. |
| 174 EXPECT_EQ(0u, manager_->bound_element_array_buffer()); |
| 175 // Check binding the same array does not need a service call. |
| 176 EXPECT_FALSE(manager_->BindElementArray(0u)); |
| 177 // Check binding a new element array requires a service call. |
| 178 EXPECT_TRUE(manager_->BindElementArray(55u)); |
| 179 // Check the element array was bound. |
| 180 EXPECT_EQ(55u, manager_->bound_element_array_buffer()); |
| 181 // Check binding the same array does not need a service call. |
| 182 EXPECT_FALSE(manager_->BindElementArray(55u)); |
| 183 |
| 184 // Check with a new vao. |
| 185 EXPECT_TRUE(manager_->BindVertexArray(1, &changed)); |
| 186 // Check the default element array is 0. |
| 187 EXPECT_EQ(0u, manager_->bound_element_array_buffer()); |
| 188 // Check binding a new element array requires a service call. |
| 189 EXPECT_TRUE(manager_->BindElementArray(11u)); |
| 190 // Check the element array was bound. |
| 191 EXPECT_EQ(11u, manager_->bound_element_array_buffer()); |
| 192 // Check binding the same array does not need a service call. |
| 193 EXPECT_FALSE(manager_->BindElementArray(11u)); |
| 194 |
| 195 // check switching vao bindings returns the correct element array. |
| 196 EXPECT_TRUE(manager_->BindVertexArray(3, &changed)); |
| 197 EXPECT_EQ(0u, manager_->bound_element_array_buffer()); |
| 198 EXPECT_TRUE(manager_->BindVertexArray(0, &changed)); |
| 199 EXPECT_EQ(55u, manager_->bound_element_array_buffer()); |
| 200 EXPECT_TRUE(manager_->BindVertexArray(1, &changed)); |
| 201 EXPECT_EQ(11u, manager_->bound_element_array_buffer()); |
| 202 } |
| 203 |
| 204 TEST_F(VertexArrayObjectManagerTest, GenBindDelete) { |
| 205 // Check unknown array fails. |
| 206 bool changed = false; |
| 207 EXPECT_FALSE(manager_->BindVertexArray(123, &changed)); |
| 208 EXPECT_FALSE(changed); |
| 209 |
| 210 GLuint ids[2] = { 1, 3, }; |
| 211 manager_->GenVertexArrays(2, ids); |
| 212 // Check Genned arrays succeed. |
| 213 EXPECT_TRUE(manager_->BindVertexArray(1, &changed)); |
| 214 EXPECT_TRUE(changed); |
| 215 EXPECT_TRUE(manager_->BindVertexArray(3, &changed)); |
| 216 EXPECT_TRUE(changed); |
| 217 |
| 218 // Check binding the same array returns changed as false. |
| 219 EXPECT_TRUE(manager_->BindVertexArray(3, &changed)); |
| 220 EXPECT_FALSE(changed); |
| 221 |
| 222 // Check deleted ararys fail to bind |
| 223 manager_->DeleteVertexArrays(2, ids); |
| 224 EXPECT_FALSE(manager_->BindVertexArray(1, &changed)); |
| 225 EXPECT_FALSE(changed); |
| 226 EXPECT_FALSE(manager_->BindVertexArray(3, &changed)); |
| 227 EXPECT_FALSE(changed); |
| 228 |
| 229 // Check binding 0 returns changed as false since it's |
| 230 // already bound. |
| 231 EXPECT_TRUE(manager_->BindVertexArray(0, &changed)); |
| 232 EXPECT_FALSE(changed); |
| 233 } |
| 234 |
| 235 TEST_F(VertexArrayObjectManagerTest, IsReservedId) { |
| 236 EXPECT_TRUE(manager_->IsReservedId(kClientSideArrayBuffer)); |
| 237 EXPECT_TRUE(manager_->IsReservedId(kClientSideElementArrayBuffer)); |
| 238 EXPECT_FALSE(manager_->IsReservedId(0)); |
| 239 EXPECT_FALSE(manager_->IsReservedId(1)); |
| 240 EXPECT_FALSE(manager_->IsReservedId(2)); |
| 241 } |
| 242 |
| 243 } // namespace gles2 |
| 244 } // namespace gpu |
| 245 |
OLD | NEW |