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/service/vertex_attrib_manager.h" | 5 #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "gpu/command_buffer/service/buffer_manager.h" | 8 #include "gpu/command_buffer/service/buffer_manager.h" |
9 #include "gpu/command_buffer/service/error_state_mock.h" | 9 #include "gpu/command_buffer/service/error_state_mock.h" |
10 #include "gpu/command_buffer/service/feature_info.h" | 10 #include "gpu/command_buffer/service/feature_info.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 98 } |
99 | 99 |
100 TEST_F(VertexAttribManagerTest, SetAttribInfo) { | 100 TEST_F(VertexAttribManagerTest, SetAttribInfo) { |
101 BufferManager buffer_manager(NULL, NULL); | 101 BufferManager buffer_manager(NULL, NULL); |
102 buffer_manager.CreateBuffer(1, 2); | 102 buffer_manager.CreateBuffer(1, 2); |
103 Buffer* buffer = buffer_manager.GetBuffer(1); | 103 Buffer* buffer = buffer_manager.GetBuffer(1); |
104 ASSERT_TRUE(buffer != NULL); | 104 ASSERT_TRUE(buffer != NULL); |
105 | 105 |
106 VertexAttrib* attrib = manager_->GetVertexAttrib(1); | 106 VertexAttrib* attrib = manager_->GetVertexAttrib(1); |
107 | 107 |
108 manager_->SetAttribInfo(1, buffer, 3, GL_SHORT, GL_TRUE, 32, 32, 4); | 108 manager_->SetAttribInfo(1, buffer, 3, GL_SHORT, GL_TRUE, 32, 32, 4, GL_TRUE); |
109 | 109 |
110 EXPECT_EQ(buffer, attrib->buffer()); | 110 EXPECT_EQ(buffer, attrib->buffer()); |
111 EXPECT_EQ(4, attrib->offset()); | 111 EXPECT_EQ(4, attrib->offset()); |
112 EXPECT_EQ(3, attrib->size()); | 112 EXPECT_EQ(3, attrib->size()); |
113 EXPECT_EQ(static_cast<GLenum>(GL_SHORT), attrib->type()); | 113 EXPECT_EQ(static_cast<GLenum>(GL_SHORT), attrib->type()); |
114 EXPECT_EQ(GL_TRUE, attrib->normalized()); | 114 EXPECT_EQ(GL_TRUE, attrib->normalized()); |
115 EXPECT_EQ(32, attrib->gl_stride()); | 115 EXPECT_EQ(32, attrib->gl_stride()); |
| 116 EXPECT_EQ(GL_TRUE, attrib->integer()); |
116 | 117 |
117 // The VertexAttribManager must be destroyed before the BufferManager | 118 // The VertexAttribManager must be destroyed before the BufferManager |
118 // so it releases its buffers. | 119 // so it releases its buffers. |
119 manager_ = NULL; | 120 manager_ = NULL; |
120 buffer_manager.Destroy(false); | 121 buffer_manager.Destroy(false); |
121 } | 122 } |
122 | 123 |
123 TEST_F(VertexAttribManagerTest, HaveFixedAttribs) { | 124 TEST_F(VertexAttribManagerTest, HaveFixedAttribs) { |
124 EXPECT_FALSE(manager_->HaveFixedAttribs()); | 125 EXPECT_FALSE(manager_->HaveFixedAttribs()); |
125 manager_->SetAttribInfo(1, NULL, 4, GL_FIXED, GL_FALSE, 0, 16, 0); | 126 manager_->SetAttribInfo(1, NULL, 4, GL_FIXED, GL_FALSE, 0, 16, 0, GL_FALSE); |
126 EXPECT_TRUE(manager_->HaveFixedAttribs()); | 127 EXPECT_TRUE(manager_->HaveFixedAttribs()); |
127 manager_->SetAttribInfo(3, NULL, 4, GL_FIXED, GL_FALSE, 0, 16, 0); | 128 manager_->SetAttribInfo(3, NULL, 4, GL_FIXED, GL_FALSE, 0, 16, 0, GL_FALSE); |
128 EXPECT_TRUE(manager_->HaveFixedAttribs()); | 129 EXPECT_TRUE(manager_->HaveFixedAttribs()); |
129 manager_->SetAttribInfo(1, NULL, 4, GL_FLOAT, GL_FALSE, 0, 16, 0); | 130 manager_->SetAttribInfo(1, NULL, 4, GL_FLOAT, GL_FALSE, 0, 16, 0, GL_FALSE); |
130 EXPECT_TRUE(manager_->HaveFixedAttribs()); | 131 EXPECT_TRUE(manager_->HaveFixedAttribs()); |
131 manager_->SetAttribInfo(3, NULL, 4, GL_FLOAT, GL_FALSE, 0, 16, 0); | 132 manager_->SetAttribInfo(3, NULL, 4, GL_FLOAT, GL_FALSE, 0, 16, 0, GL_FALSE); |
132 EXPECT_FALSE(manager_->HaveFixedAttribs()); | 133 EXPECT_FALSE(manager_->HaveFixedAttribs()); |
133 } | 134 } |
134 | 135 |
135 TEST_F(VertexAttribManagerTest, CanAccess) { | 136 TEST_F(VertexAttribManagerTest, CanAccess) { |
136 MockErrorState error_state; | 137 MockErrorState error_state; |
137 BufferManager buffer_manager(NULL, NULL); | 138 BufferManager buffer_manager(NULL, NULL); |
138 buffer_manager.CreateBuffer(1, 2); | 139 buffer_manager.CreateBuffer(1, 2); |
139 Buffer* buffer = buffer_manager.GetBuffer(1); | 140 Buffer* buffer = buffer_manager.GetBuffer(1); |
140 ASSERT_TRUE(buffer != NULL); | 141 ASSERT_TRUE(buffer != NULL); |
141 | 142 |
142 VertexAttrib* attrib = manager_->GetVertexAttrib(1); | 143 VertexAttrib* attrib = manager_->GetVertexAttrib(1); |
143 | 144 |
144 EXPECT_TRUE(attrib->CanAccess(0)); | 145 EXPECT_TRUE(attrib->CanAccess(0)); |
145 manager_->Enable(1, true); | 146 manager_->Enable(1, true); |
146 EXPECT_FALSE(attrib->CanAccess(0)); | 147 EXPECT_FALSE(attrib->CanAccess(0)); |
147 | 148 |
148 manager_->SetAttribInfo(1, buffer, 4, GL_FLOAT, GL_FALSE, 0, 16, 0); | 149 manager_->SetAttribInfo(1, buffer, 4, GL_FLOAT, GL_FALSE, 0, 16, 0, GL_FALSE); |
149 EXPECT_FALSE(attrib->CanAccess(0)); | 150 EXPECT_FALSE(attrib->CanAccess(0)); |
150 | 151 |
151 EXPECT_TRUE(buffer_manager.SetTarget(buffer, GL_ARRAY_BUFFER)); | 152 EXPECT_TRUE(buffer_manager.SetTarget(buffer, GL_ARRAY_BUFFER)); |
152 TestHelper::DoBufferData( | 153 TestHelper::DoBufferData( |
153 gl_.get(), &error_state, &buffer_manager, buffer, 15, GL_STATIC_DRAW, | 154 gl_.get(), &error_state, &buffer_manager, buffer, 15, GL_STATIC_DRAW, |
154 NULL, GL_NO_ERROR); | 155 NULL, GL_NO_ERROR); |
155 | 156 |
156 EXPECT_FALSE(attrib->CanAccess(0)); | 157 EXPECT_FALSE(attrib->CanAccess(0)); |
157 TestHelper::DoBufferData( | 158 TestHelper::DoBufferData( |
158 gl_.get(), &error_state, &buffer_manager, buffer, 16, GL_STATIC_DRAW, | 159 gl_.get(), &error_state, &buffer_manager, buffer, 16, GL_STATIC_DRAW, |
159 NULL, GL_NO_ERROR); | 160 NULL, GL_NO_ERROR); |
160 EXPECT_TRUE(attrib->CanAccess(0)); | 161 EXPECT_TRUE(attrib->CanAccess(0)); |
161 EXPECT_FALSE(attrib->CanAccess(1)); | 162 EXPECT_FALSE(attrib->CanAccess(1)); |
162 | 163 |
163 manager_->SetAttribInfo(1, buffer, 4, GL_FLOAT, GL_FALSE, 0, 16, 1); | 164 manager_->SetAttribInfo(1, buffer, 4, GL_FLOAT, GL_FALSE, 0, 16, 1, GL_FALSE); |
164 EXPECT_FALSE(attrib->CanAccess(0)); | 165 EXPECT_FALSE(attrib->CanAccess(0)); |
165 | 166 |
166 TestHelper::DoBufferData( | 167 TestHelper::DoBufferData( |
167 gl_.get(), &error_state, &buffer_manager, buffer, 32, GL_STATIC_DRAW, | 168 gl_.get(), &error_state, &buffer_manager, buffer, 32, GL_STATIC_DRAW, |
168 NULL, GL_NO_ERROR); | 169 NULL, GL_NO_ERROR); |
169 EXPECT_TRUE(attrib->CanAccess(0)); | 170 EXPECT_TRUE(attrib->CanAccess(0)); |
170 EXPECT_FALSE(attrib->CanAccess(1)); | 171 EXPECT_FALSE(attrib->CanAccess(1)); |
171 manager_->SetAttribInfo(1, buffer, 4, GL_FLOAT, GL_FALSE, 0, 16, 0); | 172 manager_->SetAttribInfo(1, buffer, 4, GL_FLOAT, GL_FALSE, 0, 16, 0, GL_FALSE); |
172 EXPECT_TRUE(attrib->CanAccess(1)); | 173 EXPECT_TRUE(attrib->CanAccess(1)); |
173 manager_->SetAttribInfo(1, buffer, 4, GL_FLOAT, GL_FALSE, 0, 20, 0); | 174 manager_->SetAttribInfo(1, buffer, 4, GL_FLOAT, GL_FALSE, 0, 20, 0, GL_FALSE); |
174 EXPECT_TRUE(attrib->CanAccess(0)); | 175 EXPECT_TRUE(attrib->CanAccess(0)); |
175 EXPECT_FALSE(attrib->CanAccess(1)); | 176 EXPECT_FALSE(attrib->CanAccess(1)); |
176 | 177 |
177 // The VertexAttribManager must be destroyed before the BufferManager | 178 // The VertexAttribManager must be destroyed before the BufferManager |
178 // so it releases its buffers. | 179 // so it releases its buffers. |
179 manager_ = NULL; | 180 manager_ = NULL; |
180 buffer_manager.Destroy(false); | 181 buffer_manager.Destroy(false); |
181 } | 182 } |
182 | 183 |
183 TEST_F(VertexAttribManagerTest, Unbind) { | 184 TEST_F(VertexAttribManagerTest, Unbind) { |
184 BufferManager buffer_manager(NULL, NULL); | 185 BufferManager buffer_manager(NULL, NULL); |
185 buffer_manager.CreateBuffer(1, 2); | 186 buffer_manager.CreateBuffer(1, 2); |
186 buffer_manager.CreateBuffer(3, 4); | 187 buffer_manager.CreateBuffer(3, 4); |
187 Buffer* buffer1 = buffer_manager.GetBuffer(1); | 188 Buffer* buffer1 = buffer_manager.GetBuffer(1); |
188 Buffer* buffer2 = buffer_manager.GetBuffer(3); | 189 Buffer* buffer2 = buffer_manager.GetBuffer(3); |
189 ASSERT_TRUE(buffer1 != NULL); | 190 ASSERT_TRUE(buffer1 != NULL); |
190 ASSERT_TRUE(buffer2 != NULL); | 191 ASSERT_TRUE(buffer2 != NULL); |
191 | 192 |
192 VertexAttrib* attrib1 = manager_->GetVertexAttrib(1); | 193 VertexAttrib* attrib1 = manager_->GetVertexAttrib(1); |
193 VertexAttrib* attrib3 = manager_->GetVertexAttrib(3); | 194 VertexAttrib* attrib3 = manager_->GetVertexAttrib(3); |
194 | 195 |
195 // Attach to 2 buffers. | 196 // Attach to 2 buffers. |
196 manager_->SetAttribInfo(1, buffer1, 3, GL_SHORT, GL_TRUE, 32, 32, 4); | 197 manager_->SetAttribInfo( |
197 manager_->SetAttribInfo(3, buffer1, 3, GL_SHORT, GL_TRUE, 32, 32, 4); | 198 1, buffer1, 3, GL_SHORT, GL_TRUE, 32, 32, 4, GL_FALSE); |
| 199 manager_->SetAttribInfo( |
| 200 3, buffer1, 3, GL_SHORT, GL_TRUE, 32, 32, 4, GL_FALSE); |
198 // Check they were attached. | 201 // Check they were attached. |
199 EXPECT_EQ(buffer1, attrib1->buffer()); | 202 EXPECT_EQ(buffer1, attrib1->buffer()); |
200 EXPECT_EQ(buffer1, attrib3->buffer()); | 203 EXPECT_EQ(buffer1, attrib3->buffer()); |
201 // Unbind unattached buffer. | 204 // Unbind unattached buffer. |
202 manager_->Unbind(buffer2); | 205 manager_->Unbind(buffer2); |
203 // Should be no-op. | 206 // Should be no-op. |
204 EXPECT_EQ(buffer1, attrib1->buffer()); | 207 EXPECT_EQ(buffer1, attrib1->buffer()); |
205 EXPECT_EQ(buffer1, attrib3->buffer()); | 208 EXPECT_EQ(buffer1, attrib3->buffer()); |
206 // Unbind buffer. | 209 // Unbind buffer. |
207 manager_->Unbind(buffer1); | 210 manager_->Unbind(buffer1); |
208 // Check they were detached | 211 // Check they were detached |
209 EXPECT_TRUE(NULL == attrib1->buffer()); | 212 EXPECT_TRUE(NULL == attrib1->buffer()); |
210 EXPECT_TRUE(NULL == attrib3->buffer()); | 213 EXPECT_TRUE(NULL == attrib3->buffer()); |
211 | 214 |
212 // The VertexAttribManager must be destroyed before the BufferManager | 215 // The VertexAttribManager must be destroyed before the BufferManager |
213 // so it releases its buffers. | 216 // so it releases its buffers. |
214 manager_ = NULL; | 217 manager_ = NULL; |
215 buffer_manager.Destroy(false); | 218 buffer_manager.Destroy(false); |
216 } | 219 } |
217 | 220 |
218 // TODO(gman): Test ValidateBindings | 221 // TODO(gman): Test ValidateBindings |
219 // TODO(gman): Test ValidateBindings with client side arrays. | 222 // TODO(gman): Test ValidateBindings with client side arrays. |
220 | 223 |
221 } // namespace gles2 | 224 } // namespace gles2 |
222 } // namespace gpu | 225 } // namespace gpu |
223 | 226 |
224 | 227 |
OLD | NEW |