OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/framebuffer_manager.h" | 5 #include "gpu/command_buffer/service/framebuffer_manager.h" |
6 #include "gpu/command_buffer/service/feature_info.h" | 6 #include "gpu/command_buffer/service/feature_info.h" |
7 | 7 |
8 #include "gpu/command_buffer/common/gl_mock.h" | 8 #include "gpu/command_buffer/common/gl_mock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace gpu { | 11 namespace gpu { |
12 namespace gles2 { | 12 namespace gles2 { |
13 | 13 |
14 class FramebufferManagerTest : public testing::Test { | 14 class FramebufferManagerTest : public testing::Test { |
| 15 static const GLint kMaxTextureSize = 64; |
| 16 static const GLint kMaxCubemapSize = 64; |
| 17 static const GLint kMaxRenderbufferSize = 64; |
| 18 static const GLint kMaxSamples = 4; |
| 19 |
15 public: | 20 public: |
16 FramebufferManagerTest() { | 21 FramebufferManagerTest() |
| 22 : texture_manager_(kMaxTextureSize, kMaxCubemapSize), |
| 23 renderbuffer_manager_(kMaxRenderbufferSize, kMaxSamples) { |
| 24 |
17 } | 25 } |
18 ~FramebufferManagerTest() { | 26 ~FramebufferManagerTest() { |
19 manager_.Destroy(false); | 27 manager_.Destroy(false); |
| 28 texture_manager_.Destroy(false); |
| 29 renderbuffer_manager_.Destroy(false); |
20 } | 30 } |
21 | 31 |
22 protected: | 32 protected: |
23 virtual void SetUp() { | 33 virtual void SetUp() { |
24 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 34 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
25 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 35 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
26 } | 36 } |
27 | 37 |
28 virtual void TearDown() { | 38 virtual void TearDown() { |
29 ::gfx::GLInterface::SetGLInterface(NULL); | 39 ::gfx::GLInterface::SetGLInterface(NULL); |
30 gl_.reset(); | 40 gl_.reset(); |
31 } | 41 } |
32 | 42 |
33 // Use StrictMock to make 100% sure we know how GL will be called. | 43 // Use StrictMock to make 100% sure we know how GL will be called. |
34 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 44 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
35 FramebufferManager manager_; | 45 FramebufferManager manager_; |
| 46 TextureManager texture_manager_; |
| 47 RenderbufferManager renderbuffer_manager_; |
36 }; | 48 }; |
37 | 49 |
| 50 // GCC requires these declarations, but MSVC requires they not be present |
| 51 #ifndef COMPILER_MSVC |
| 52 const GLint FramebufferManagerTest::kMaxTextureSize; |
| 53 const GLint FramebufferManagerTest::kMaxCubemapSize; |
| 54 const GLint FramebufferManagerTest::kMaxRenderbufferSize; |
| 55 #endif |
| 56 |
38 TEST_F(FramebufferManagerTest, Basic) { | 57 TEST_F(FramebufferManagerTest, Basic) { |
39 const GLuint kClient1Id = 1; | 58 const GLuint kClient1Id = 1; |
40 const GLuint kService1Id = 11; | 59 const GLuint kService1Id = 11; |
41 const GLuint kClient2Id = 2; | 60 const GLuint kClient2Id = 2; |
42 // Check we can create framebuffer. | 61 // Check we can create framebuffer. |
43 manager_.CreateFramebufferInfo(kClient1Id, kService1Id); | 62 manager_.CreateFramebufferInfo(kClient1Id, kService1Id); |
44 // Check framebuffer got created. | 63 // Check framebuffer got created. |
45 FramebufferManager::FramebufferInfo* info1 = | 64 FramebufferManager::FramebufferInfo* info1 = |
46 manager_.GetFramebufferInfo(kClient1Id); | 65 manager_.GetFramebufferInfo(kClient1Id); |
47 ASSERT_TRUE(info1 != NULL); | 66 ASSERT_TRUE(info1 != NULL); |
(...skipping 27 matching lines...) Expand all Loading... |
75 // Check the resources were released. | 94 // Check the resources were released. |
76 info1 = manager_.GetFramebufferInfo(kClient1Id); | 95 info1 = manager_.GetFramebufferInfo(kClient1Id); |
77 ASSERT_TRUE(info1 == NULL); | 96 ASSERT_TRUE(info1 == NULL); |
78 } | 97 } |
79 | 98 |
80 class FramebufferInfoTest : public testing::Test { | 99 class FramebufferInfoTest : public testing::Test { |
81 public: | 100 public: |
82 static const GLuint kClient1Id = 1; | 101 static const GLuint kClient1Id = 1; |
83 static const GLuint kService1Id = 11; | 102 static const GLuint kService1Id = 11; |
84 | 103 |
| 104 static const GLint kMaxTextureSize = 64; |
| 105 static const GLint kMaxCubemapSize = 64; |
| 106 static const GLint kMaxRenderbufferSize = 64; |
| 107 static const GLint kMaxSamples = 4; |
| 108 |
85 FramebufferInfoTest() | 109 FramebufferInfoTest() |
86 : manager_() { | 110 : manager_(), |
| 111 texture_manager_(kMaxTextureSize, kMaxCubemapSize), |
| 112 renderbuffer_manager_(kMaxRenderbufferSize, kMaxSamples) { |
87 } | 113 } |
88 ~FramebufferInfoTest() { | 114 ~FramebufferInfoTest() { |
89 manager_.Destroy(false); | 115 manager_.Destroy(false); |
| 116 texture_manager_.Destroy(false); |
| 117 renderbuffer_manager_.Destroy(false); |
90 } | 118 } |
91 | 119 |
92 protected: | 120 protected: |
93 virtual void SetUp() { | 121 virtual void SetUp() { |
94 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 122 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
95 ::gfx::GLInterface::SetGLInterface(gl_.get()); | 123 ::gfx::GLInterface::SetGLInterface(gl_.get()); |
96 manager_.CreateFramebufferInfo(kClient1Id, kService1Id); | 124 manager_.CreateFramebufferInfo(kClient1Id, kService1Id); |
97 info_ = manager_.GetFramebufferInfo(kClient1Id); | 125 info_ = manager_.GetFramebufferInfo(kClient1Id); |
98 ASSERT_TRUE(info_ != NULL); | 126 ASSERT_TRUE(info_ != NULL); |
99 } | 127 } |
100 | 128 |
101 virtual void TearDown() { | 129 virtual void TearDown() { |
102 ::gfx::GLInterface::SetGLInterface(NULL); | 130 ::gfx::GLInterface::SetGLInterface(NULL); |
103 gl_.reset(); | 131 gl_.reset(); |
104 } | 132 } |
105 | 133 |
106 // Use StrictMock to make 100% sure we know how GL will be called. | 134 // Use StrictMock to make 100% sure we know how GL will be called. |
107 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | 135 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
108 FramebufferManager manager_; | 136 FramebufferManager manager_; |
109 FramebufferManager::FramebufferInfo* info_; | 137 FramebufferManager::FramebufferInfo* info_; |
| 138 TextureManager texture_manager_; |
| 139 RenderbufferManager renderbuffer_manager_; |
110 }; | 140 }; |
111 | 141 |
112 // GCC requires these declarations, but MSVC requires they not be present | 142 // GCC requires these declarations, but MSVC requires they not be present |
113 #ifndef COMPILER_MSVC | 143 #ifndef COMPILER_MSVC |
114 const GLuint FramebufferInfoTest::kClient1Id; | 144 const GLuint FramebufferInfoTest::kClient1Id; |
115 const GLuint FramebufferInfoTest::kService1Id; | 145 const GLuint FramebufferInfoTest::kService1Id; |
| 146 const GLint FramebufferInfoTest::kMaxTextureSize; |
| 147 const GLint FramebufferInfoTest::kMaxCubemapSize; |
| 148 const GLint FramebufferInfoTest::kMaxRenderbufferSize; |
116 #endif | 149 #endif |
117 | 150 |
118 TEST_F(FramebufferInfoTest, Basic) { | 151 TEST_F(FramebufferInfoTest, Basic) { |
119 EXPECT_EQ(kService1Id, info_->service_id()); | 152 EXPECT_EQ(kService1Id, info_->service_id()); |
120 EXPECT_FALSE(info_->IsDeleted()); | 153 EXPECT_FALSE(info_->IsDeleted()); |
121 EXPECT_TRUE(NULL == info_->GetAttachment(GL_COLOR_ATTACHMENT0)); | 154 EXPECT_TRUE(NULL == info_->GetAttachment(GL_COLOR_ATTACHMENT0)); |
122 EXPECT_TRUE(NULL == info_->GetAttachment(GL_DEPTH_ATTACHMENT)); | 155 EXPECT_TRUE(NULL == info_->GetAttachment(GL_DEPTH_ATTACHMENT)); |
123 EXPECT_TRUE(NULL == info_->GetAttachment(GL_STENCIL_ATTACHMENT)); | 156 EXPECT_TRUE(NULL == info_->GetAttachment(GL_STENCIL_ATTACHMENT)); |
124 EXPECT_TRUE(NULL == info_->GetAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); | 157 EXPECT_TRUE(NULL == info_->GetAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); |
125 EXPECT_FALSE(info_->HasDepthAttachment()); | 158 EXPECT_FALSE(info_->HasDepthAttachment()); |
126 EXPECT_FALSE(info_->HasStencilAttachment()); | 159 EXPECT_FALSE(info_->HasStencilAttachment()); |
| 160 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT), |
| 161 info_->IsPossiblyComplete()); |
| 162 EXPECT_TRUE(info_->IsCleared()); |
127 EXPECT_EQ(static_cast<GLenum>(0), info_->GetColorAttachmentFormat()); | 163 EXPECT_EQ(static_cast<GLenum>(0), info_->GetColorAttachmentFormat()); |
128 } | 164 } |
129 | 165 |
130 TEST_F(FramebufferInfoTest, AttachRenderbuffer) { | 166 TEST_F(FramebufferInfoTest, AttachRenderbuffer) { |
131 const GLuint kRenderbufferClient1Id = 33; | 167 const GLuint kRenderbufferClient1Id = 33; |
132 const GLuint kRenderbufferService1Id = 333; | 168 const GLuint kRenderbufferService1Id = 333; |
133 const GLuint kRenderbufferClient2Id = 34; | 169 const GLuint kRenderbufferClient2Id = 34; |
134 const GLuint kRenderbufferService2Id = 334; | 170 const GLuint kRenderbufferService2Id = 334; |
135 const GLint kMaxRenderbufferSize = 128; | 171 const GLuint kRenderbufferClient3Id = 35; |
136 const GLint kMaxSamples = 4; | 172 const GLuint kRenderbufferService3Id = 335; |
| 173 const GLuint kRenderbufferClient4Id = 36; |
| 174 const GLuint kRenderbufferService4Id = 336; |
137 const GLsizei kWidth1 = 16; | 175 const GLsizei kWidth1 = 16; |
138 const GLsizei kHeight1 = 32; | 176 const GLsizei kHeight1 = 32; |
139 const GLenum kFormat1 = GL_STENCIL_INDEX8; | 177 const GLenum kFormat1 = GL_RGBA4; |
140 const GLsizei kSamples1 = 0; | 178 const GLsizei kSamples1 = 0; |
141 const GLsizei kWidth2 = 64; | 179 const GLsizei kWidth2 = 16; |
142 const GLsizei kHeight2 = 128; | 180 const GLsizei kHeight2 = 32; |
143 const GLenum kFormat2 = GL_STENCIL_INDEX; | 181 const GLenum kFormat2 = GL_DEPTH_COMPONENT16; |
144 const GLsizei kSamples2 = 0; | 182 const GLsizei kSamples2 = 0; |
145 const GLsizei kWidth3 = 75; | 183 const GLsizei kWidth3 = 16; |
146 const GLsizei kHeight3 = 123; | 184 const GLsizei kHeight3 = 32; |
147 const GLenum kFormat3 = GL_STENCIL_INDEX8; | 185 const GLenum kFormat3 = GL_STENCIL_INDEX8; |
148 const GLsizei kSamples3 = 0; | 186 const GLsizei kSamples3 = 0; |
| 187 const GLsizei kWidth4 = 16; |
| 188 const GLsizei kHeight4 = 32; |
| 189 const GLenum kFormat4 = GL_STENCIL_INDEX8; |
| 190 const GLsizei kSamples4 = 0; |
149 | 191 |
150 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); | 192 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
151 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); | 193 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
152 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 194 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
153 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); | 195 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); |
154 EXPECT_FALSE(info_->IsNotComplete()); | |
155 | 196 |
156 RenderbufferManager rb_manager(kMaxRenderbufferSize, kMaxSamples); | 197 renderbuffer_manager_.CreateRenderbufferInfo( |
157 rb_manager.CreateRenderbufferInfo( | |
158 kRenderbufferClient1Id, kRenderbufferService1Id); | 198 kRenderbufferClient1Id, kRenderbufferService1Id); |
159 RenderbufferManager::RenderbufferInfo* rb_info1 = | 199 RenderbufferManager::RenderbufferInfo* rb_info1 = |
160 rb_manager.GetRenderbufferInfo(kRenderbufferClient1Id); | 200 renderbuffer_manager_.GetRenderbufferInfo(kRenderbufferClient1Id); |
161 ASSERT_TRUE(rb_info1 != NULL); | 201 ASSERT_TRUE(rb_info1 != NULL); |
162 | 202 |
163 // check adding one attachment | 203 // check adding one attachment |
164 info_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, rb_info1); | 204 info_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, rb_info1); |
165 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); | 205 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
166 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); | 206 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
167 EXPECT_TRUE(info_->IsNotComplete()); | |
168 EXPECT_EQ(static_cast<GLenum>(GL_RGBA4), info_->GetColorAttachmentFormat()); | 207 EXPECT_EQ(static_cast<GLenum>(GL_RGBA4), info_->GetColorAttachmentFormat()); |
169 EXPECT_FALSE(info_->HasDepthAttachment()); | 208 EXPECT_FALSE(info_->HasDepthAttachment()); |
170 EXPECT_FALSE(info_->HasStencilAttachment()); | 209 EXPECT_FALSE(info_->HasStencilAttachment()); |
| 210 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT), |
| 211 info_->IsPossiblyComplete()); |
| 212 EXPECT_TRUE(info_->IsCleared()); |
171 | 213 |
172 rb_info1->SetInfo(1, GL_RGB, 0, 0); | 214 renderbuffer_manager_.SetInfo( |
173 EXPECT_EQ(static_cast<GLenum>(GL_RGB), info_->GetColorAttachmentFormat()); | 215 rb_info1, kSamples1, kFormat1, kWidth1, kHeight1); |
| 216 EXPECT_EQ(static_cast<GLenum>(kFormat1), info_->GetColorAttachmentFormat()); |
174 EXPECT_FALSE(info_->HasDepthAttachment()); | 217 EXPECT_FALSE(info_->HasDepthAttachment()); |
175 EXPECT_FALSE(info_->HasStencilAttachment()); | 218 EXPECT_FALSE(info_->HasStencilAttachment()); |
| 219 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 220 info_->IsPossiblyComplete()); |
| 221 EXPECT_FALSE(info_->IsCleared()); |
176 | 222 |
177 // check adding another | 223 // check adding another |
178 info_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, rb_info1); | 224 renderbuffer_manager_.CreateRenderbufferInfo( |
| 225 kRenderbufferClient2Id, kRenderbufferService2Id); |
| 226 RenderbufferManager::RenderbufferInfo* rb_info2 = |
| 227 renderbuffer_manager_.GetRenderbufferInfo(kRenderbufferClient2Id); |
| 228 ASSERT_TRUE(rb_info2 != NULL); |
| 229 info_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, rb_info2); |
179 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); | 230 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
180 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); | 231 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
181 EXPECT_TRUE(info_->IsNotComplete()); | 232 EXPECT_EQ(static_cast<GLenum>(kFormat1), info_->GetColorAttachmentFormat()); |
182 EXPECT_EQ(static_cast<GLenum>(GL_RGB), info_->GetColorAttachmentFormat()); | |
183 EXPECT_TRUE(info_->HasDepthAttachment()); | 233 EXPECT_TRUE(info_->HasDepthAttachment()); |
184 EXPECT_FALSE(info_->HasStencilAttachment()); | 234 EXPECT_FALSE(info_->HasStencilAttachment()); |
| 235 // The attachment has a size of 0,0 so depending on the order of the map |
| 236 // of attachments it could either get INCOMPLETE_ATTACHMENT because it's 0,0 |
| 237 // or INCOMPLETE_DIMENSIONS because it's not the same size as the other |
| 238 // attachment. |
| 239 GLenum status = info_->IsPossiblyComplete(); |
| 240 EXPECT_TRUE( |
| 241 status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT || |
| 242 status == GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT); |
| 243 EXPECT_FALSE(info_->IsCleared()); |
| 244 |
| 245 renderbuffer_manager_.SetInfo( |
| 246 rb_info2, kSamples2, kFormat2, kWidth2, kHeight2); |
| 247 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 248 info_->IsPossiblyComplete()); |
| 249 EXPECT_FALSE(info_->IsCleared()); |
| 250 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
185 | 251 |
186 // check marking them as cleared. | 252 // check marking them as cleared. |
187 info_->MarkAttachedRenderbuffersAsCleared(); | 253 info_->MarkAttachmentsAsCleared(&renderbuffer_manager_, &texture_manager_); |
188 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); | 254 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
189 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); | 255 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
190 EXPECT_TRUE(info_->IsNotComplete()); | 256 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 257 info_->IsPossiblyComplete()); |
| 258 EXPECT_TRUE(info_->IsCleared()); |
191 | 259 |
192 // Check adding one that is already cleared. | 260 // Check adding one that is already cleared. |
| 261 renderbuffer_manager_.CreateRenderbufferInfo( |
| 262 kRenderbufferClient3Id, kRenderbufferService3Id); |
| 263 RenderbufferManager::RenderbufferInfo* rb_info3 = |
| 264 renderbuffer_manager_.GetRenderbufferInfo(kRenderbufferClient3Id); |
| 265 ASSERT_TRUE(rb_info3 != NULL); |
| 266 renderbuffer_manager_.SetInfo( |
| 267 rb_info3, kSamples3, kFormat3, kWidth3, kHeight3); |
| 268 renderbuffer_manager_.SetCleared(rb_info3); |
| 269 |
193 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, rb_info1); | 270 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, rb_info1); |
194 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 271 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
195 EXPECT_EQ(static_cast<GLenum>(GL_RGB), info_->GetColorAttachmentFormat()); | |
196 EXPECT_TRUE(info_->HasDepthAttachment()); | |
197 EXPECT_TRUE(info_->HasStencilAttachment()); | |
198 | |
199 // Check marking the renderbuffer as unclared. | |
200 rb_info1->SetInfo(kSamples1, kFormat1, kWidth1, kHeight1); | |
201 EXPECT_FALSE(info_->IsNotComplete()); | |
202 EXPECT_EQ(static_cast<GLenum>(kFormat1), info_->GetColorAttachmentFormat()); | 272 EXPECT_EQ(static_cast<GLenum>(kFormat1), info_->GetColorAttachmentFormat()); |
203 EXPECT_TRUE(info_->HasDepthAttachment()); | 273 EXPECT_TRUE(info_->HasDepthAttachment()); |
204 EXPECT_TRUE(info_->HasStencilAttachment()); | 274 EXPECT_TRUE(info_->HasStencilAttachment()); |
| 275 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 276 info_->IsPossiblyComplete()); |
| 277 EXPECT_TRUE(info_->IsCleared()); |
| 278 |
| 279 // Check marking the renderbuffer as unclared. |
| 280 renderbuffer_manager_.SetInfo( |
| 281 rb_info1, kSamples1, kFormat1, kWidth1, kHeight1); |
| 282 EXPECT_EQ(static_cast<GLenum>(kFormat1), info_->GetColorAttachmentFormat()); |
| 283 EXPECT_TRUE(info_->HasDepthAttachment()); |
| 284 EXPECT_TRUE(info_->HasStencilAttachment()); |
| 285 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 286 info_->IsPossiblyComplete()); |
| 287 EXPECT_FALSE(info_->IsCleared()); |
205 | 288 |
206 const FramebufferManager::FramebufferInfo::Attachment* attachment = | 289 const FramebufferManager::FramebufferInfo::Attachment* attachment = |
207 info_->GetAttachment(GL_COLOR_ATTACHMENT0); | 290 info_->GetAttachment(GL_COLOR_ATTACHMENT0); |
208 ASSERT_TRUE(attachment != NULL); | 291 ASSERT_TRUE(attachment != NULL); |
209 EXPECT_EQ(kWidth1, attachment->width()); | 292 EXPECT_EQ(kWidth1, attachment->width()); |
210 EXPECT_EQ(kHeight1, attachment->height()); | 293 EXPECT_EQ(kHeight1, attachment->height()); |
211 EXPECT_EQ(kSamples1, attachment->samples()); | 294 EXPECT_EQ(kSamples1, attachment->samples()); |
212 EXPECT_EQ(kFormat1, attachment->internal_format()); | 295 EXPECT_EQ(kFormat1, attachment->internal_format()); |
213 EXPECT_FALSE(attachment->cleared()); | 296 EXPECT_FALSE(attachment->cleared()); |
214 | 297 |
215 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 298 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
216 | 299 |
217 // Clear it. | 300 // Clear it. |
218 info_->MarkAttachedRenderbuffersAsCleared(); | 301 info_->MarkAttachmentsAsCleared(&renderbuffer_manager_, &texture_manager_); |
219 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 302 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 303 EXPECT_TRUE(info_->IsCleared()); |
220 | 304 |
221 // Check replacing an attachment | 305 // Check replacing an attachment |
222 rb_manager.CreateRenderbufferInfo( | 306 renderbuffer_manager_.CreateRenderbufferInfo( |
223 kRenderbufferClient2Id, kRenderbufferService2Id); | 307 kRenderbufferClient4Id, kRenderbufferService4Id); |
224 RenderbufferManager::RenderbufferInfo* rb_info2 = | 308 RenderbufferManager::RenderbufferInfo* rb_info4 = |
225 rb_manager.GetRenderbufferInfo(kRenderbufferClient2Id); | 309 renderbuffer_manager_.GetRenderbufferInfo(kRenderbufferClient4Id); |
226 ASSERT_TRUE(rb_info2 != NULL); | 310 ASSERT_TRUE(rb_info4 != NULL); |
227 rb_info2->SetInfo(kSamples2, kFormat2, kWidth2, kHeight2); | 311 renderbuffer_manager_.SetInfo( |
| 312 rb_info4, kSamples4, kFormat4, kWidth4, kHeight4); |
228 | 313 |
229 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, rb_info2); | 314 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, rb_info4); |
230 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 315 EXPECT_TRUE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
| 316 EXPECT_FALSE(info_->IsCleared()); |
231 | 317 |
232 attachment = info_->GetAttachment(GL_STENCIL_ATTACHMENT); | 318 attachment = info_->GetAttachment(GL_STENCIL_ATTACHMENT); |
233 ASSERT_TRUE(attachment != NULL); | 319 ASSERT_TRUE(attachment != NULL); |
234 EXPECT_EQ(kWidth2, attachment->width()); | 320 EXPECT_EQ(kWidth4, attachment->width()); |
235 EXPECT_EQ(kHeight2, attachment->height()); | 321 EXPECT_EQ(kHeight4, attachment->height()); |
236 EXPECT_EQ(kSamples2, attachment->samples()); | 322 EXPECT_EQ(kSamples4, attachment->samples()); |
237 EXPECT_EQ(kFormat2, attachment->internal_format()); | 323 EXPECT_EQ(kFormat4, attachment->internal_format()); |
238 EXPECT_FALSE(attachment->cleared()); | 324 EXPECT_FALSE(attachment->cleared()); |
| 325 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 326 info_->IsPossiblyComplete()); |
239 | 327 |
240 // Check changing an attachment. | 328 // Check changing an attachment. |
241 rb_info2->SetInfo(kSamples3, kFormat3, kWidth3, kHeight3); | 329 renderbuffer_manager_.SetInfo( |
| 330 rb_info4, kSamples4, kFormat4, kWidth4 + 1, kHeight4); |
242 | 331 |
243 attachment = info_->GetAttachment(GL_STENCIL_ATTACHMENT); | 332 attachment = info_->GetAttachment(GL_STENCIL_ATTACHMENT); |
244 ASSERT_TRUE(attachment != NULL); | 333 ASSERT_TRUE(attachment != NULL); |
245 EXPECT_EQ(kWidth3, attachment->width()); | 334 EXPECT_EQ(kWidth4 + 1, attachment->width()); |
246 EXPECT_EQ(kHeight3, attachment->height()); | 335 EXPECT_EQ(kHeight4, attachment->height()); |
247 EXPECT_EQ(kSamples3, attachment->samples()); | 336 EXPECT_EQ(kSamples4, attachment->samples()); |
248 EXPECT_EQ(kFormat3, attachment->internal_format()); | 337 EXPECT_EQ(kFormat4, attachment->internal_format()); |
249 EXPECT_FALSE(attachment->cleared()); | 338 EXPECT_FALSE(attachment->cleared()); |
| 339 EXPECT_FALSE(info_->IsCleared()); |
| 340 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT), |
| 341 info_->IsPossiblyComplete()); |
250 | 342 |
251 // Check removing it. | 343 // Check removing it. |
252 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, NULL); | 344 info_->AttachRenderbuffer(GL_STENCIL_ATTACHMENT, NULL); |
253 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 345 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
254 EXPECT_EQ(static_cast<GLenum>(kFormat1), info_->GetColorAttachmentFormat()); | 346 EXPECT_EQ(static_cast<GLenum>(kFormat1), info_->GetColorAttachmentFormat()); |
255 EXPECT_TRUE(info_->HasDepthAttachment()); | 347 EXPECT_TRUE(info_->HasDepthAttachment()); |
256 EXPECT_FALSE(info_->HasStencilAttachment()); | 348 EXPECT_FALSE(info_->HasStencilAttachment()); |
257 | 349 |
258 rb_manager.Destroy(false); | 350 EXPECT_TRUE(info_->IsCleared()); |
| 351 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 352 info_->IsPossiblyComplete()); |
| 353 |
| 354 // Remove depth, Set color to 0 size. |
| 355 info_->AttachRenderbuffer(GL_DEPTH_ATTACHMENT, NULL); |
| 356 renderbuffer_manager_.SetInfo(rb_info1, kSamples1, kFormat1, 0, 0); |
| 357 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT), |
| 358 info_->IsPossiblyComplete()); |
| 359 |
| 360 // Remove color. |
| 361 info_->AttachRenderbuffer(GL_COLOR_ATTACHMENT0, NULL); |
| 362 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT), |
| 363 info_->IsPossiblyComplete()); |
259 } | 364 } |
260 | 365 |
261 TEST_F(FramebufferInfoTest, AttachTexture) { | 366 TEST_F(FramebufferInfoTest, AttachTexture) { |
262 const GLuint kTextureClient1Id = 33; | 367 const GLuint kTextureClient1Id = 33; |
263 const GLuint kTextureService1Id = 333; | 368 const GLuint kTextureService1Id = 333; |
264 const GLuint kTextureClient2Id = 34; | 369 const GLuint kTextureClient2Id = 34; |
265 const GLuint kTextureService2Id = 334; | 370 const GLuint kTextureService2Id = 334; |
266 const GLint kMaxTextureSize = 128; | |
267 const GLint kDepth = 1; | 371 const GLint kDepth = 1; |
268 const GLint kBorder = 0; | 372 const GLint kBorder = 0; |
269 const GLenum kType = GL_UNSIGNED_BYTE; | 373 const GLenum kType = GL_UNSIGNED_BYTE; |
270 const GLsizei kWidth1 = 16; | 374 const GLsizei kWidth1 = 16; |
271 const GLsizei kHeight1 = 32; | 375 const GLsizei kHeight1 = 32; |
272 const GLint kLevel1 = 0; | 376 const GLint kLevel1 = 0; |
273 const GLenum kFormat1 = GL_RGBA; | 377 const GLenum kFormat1 = GL_RGBA; |
274 const GLenum kTarget1 = GL_TEXTURE_2D; | 378 const GLenum kTarget1 = GL_TEXTURE_2D; |
275 const GLsizei kSamples1 = 0; | 379 const GLsizei kSamples1 = 0; |
276 const GLsizei kWidth2 = 64; | 380 const GLsizei kWidth2 = 16; |
277 const GLsizei kHeight2 = 128; | 381 const GLsizei kHeight2 = 32; |
278 const GLint kLevel2 = 0; | 382 const GLint kLevel2 = 0; |
279 const GLenum kFormat2 = GL_RGB; | 383 const GLenum kFormat2 = GL_RGB; |
280 const GLenum kTarget2 = GL_TEXTURE_2D; | 384 const GLenum kTarget2 = GL_TEXTURE_2D; |
281 const GLsizei kSamples2 = 0; | 385 const GLsizei kSamples2 = 0; |
282 const GLsizei kWidth3 = 75; | 386 const GLsizei kWidth3 = 75; |
283 const GLsizei kHeight3 = 123; | 387 const GLsizei kHeight3 = 123; |
284 const GLint kLevel3 = 0; | 388 const GLint kLevel3 = 0; |
285 const GLenum kFormat3 = GL_RGB565; | 389 const GLenum kFormat3 = GL_RGB565; |
286 const GLsizei kSamples3 = 0; | 390 const GLsizei kSamples3 = 0; |
287 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); | 391 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
288 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); | 392 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT)); |
289 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); | 393 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT)); |
290 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); | 394 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)); |
291 EXPECT_FALSE(info_->IsNotComplete()); | 395 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT), |
| 396 info_->IsPossiblyComplete()); |
292 | 397 |
293 FeatureInfo feature_info; | 398 FeatureInfo feature_info; |
294 TextureManager tex_manager(kMaxTextureSize, kMaxTextureSize); | 399 texture_manager_.CreateTextureInfo( |
295 tex_manager.CreateTextureInfo( | |
296 &feature_info, kTextureClient1Id, kTextureService1Id); | 400 &feature_info, kTextureClient1Id, kTextureService1Id); |
297 TextureManager::TextureInfo* tex_info1 = | 401 TextureManager::TextureInfo* tex_info1 = |
298 tex_manager.GetTextureInfo(kTextureClient1Id); | 402 texture_manager_.GetTextureInfo(kTextureClient1Id); |
299 ASSERT_TRUE(tex_info1 != NULL); | 403 ASSERT_TRUE(tex_info1 != NULL); |
300 | 404 |
301 // check adding one attachment | 405 // check adding one attachment |
302 info_->AttachTexture(GL_COLOR_ATTACHMENT0, tex_info1, kTarget1, kLevel1); | 406 info_->AttachTexture(GL_COLOR_ATTACHMENT0, tex_info1, kTarget1, kLevel1); |
303 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); | 407 EXPECT_FALSE(info_->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)); |
304 EXPECT_TRUE(info_->IsNotComplete()); | 408 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT), |
| 409 info_->IsPossiblyComplete()); |
| 410 EXPECT_TRUE(info_->IsCleared()); |
305 EXPECT_EQ(static_cast<GLenum>(0), info_->GetColorAttachmentFormat()); | 411 EXPECT_EQ(static_cast<GLenum>(0), info_->GetColorAttachmentFormat()); |
306 | 412 |
307 tex_manager.SetInfoTarget(&feature_info, tex_info1, GL_TEXTURE_2D); | 413 texture_manager_.SetInfoTarget(&feature_info, tex_info1, GL_TEXTURE_2D); |
308 tex_manager.SetLevelInfo( | 414 texture_manager_.SetLevelInfo( |
309 &feature_info, tex_info1, GL_TEXTURE_2D, kLevel1, | 415 &feature_info, tex_info1, GL_TEXTURE_2D, kLevel1, |
310 kFormat1, kWidth1, kHeight1, kDepth, kBorder, kFormat1, kType); | 416 kFormat1, kWidth1, kHeight1, kDepth, kBorder, kFormat1, kType, false); |
311 EXPECT_FALSE(info_->IsNotComplete()); | 417 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 418 info_->IsPossiblyComplete()); |
| 419 EXPECT_FALSE(info_->IsCleared()); |
| 420 texture_manager_.SetLevelInfo( |
| 421 &feature_info, tex_info1, GL_TEXTURE_2D, kLevel1, |
| 422 kFormat1, kWidth1, kHeight1, kDepth, kBorder, kFormat1, kType, true); |
| 423 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 424 info_->IsPossiblyComplete()); |
| 425 EXPECT_TRUE(info_->IsCleared()); |
312 EXPECT_EQ(static_cast<GLenum>(kFormat1), info_->GetColorAttachmentFormat()); | 426 EXPECT_EQ(static_cast<GLenum>(kFormat1), info_->GetColorAttachmentFormat()); |
313 | 427 |
314 const FramebufferManager::FramebufferInfo::Attachment* attachment = | 428 const FramebufferManager::FramebufferInfo::Attachment* attachment = |
315 info_->GetAttachment(GL_COLOR_ATTACHMENT0); | 429 info_->GetAttachment(GL_COLOR_ATTACHMENT0); |
316 ASSERT_TRUE(attachment != NULL); | 430 ASSERT_TRUE(attachment != NULL); |
317 EXPECT_EQ(kWidth1, attachment->width()); | 431 EXPECT_EQ(kWidth1, attachment->width()); |
318 EXPECT_EQ(kHeight1, attachment->height()); | 432 EXPECT_EQ(kHeight1, attachment->height()); |
319 EXPECT_EQ(kSamples1, attachment->samples()); | 433 EXPECT_EQ(kSamples1, attachment->samples()); |
320 EXPECT_EQ(kFormat1, attachment->internal_format()); | 434 EXPECT_EQ(kFormat1, attachment->internal_format()); |
321 EXPECT_TRUE(attachment->cleared()); | 435 EXPECT_TRUE(attachment->cleared()); |
322 | 436 |
323 // Check replacing an attachment | 437 // Check replacing an attachment |
324 tex_manager.CreateTextureInfo( | 438 texture_manager_.CreateTextureInfo( |
325 &feature_info, kTextureClient2Id, kTextureService2Id); | 439 &feature_info, kTextureClient2Id, kTextureService2Id); |
326 TextureManager::TextureInfo* tex_info2 = | 440 TextureManager::TextureInfo* tex_info2 = |
327 tex_manager.GetTextureInfo(kTextureClient2Id); | 441 texture_manager_.GetTextureInfo(kTextureClient2Id); |
328 ASSERT_TRUE(tex_info2 != NULL); | 442 ASSERT_TRUE(tex_info2 != NULL); |
329 tex_manager.SetInfoTarget(&feature_info, tex_info2, GL_TEXTURE_2D); | 443 texture_manager_.SetInfoTarget(&feature_info, tex_info2, GL_TEXTURE_2D); |
330 tex_manager.SetLevelInfo( | 444 texture_manager_.SetLevelInfo( |
331 &feature_info, tex_info2, GL_TEXTURE_2D, kLevel2, | 445 &feature_info, tex_info2, GL_TEXTURE_2D, kLevel2, |
332 kFormat2, kWidth2, kHeight2, kDepth, kBorder, kFormat2, kType); | 446 kFormat2, kWidth2, kHeight2, kDepth, kBorder, kFormat2, kType, true); |
333 | 447 |
334 info_->AttachTexture(GL_COLOR_ATTACHMENT0, tex_info2, kTarget2, kLevel2); | 448 info_->AttachTexture(GL_COLOR_ATTACHMENT0, tex_info2, kTarget2, kLevel2); |
335 EXPECT_EQ(static_cast<GLenum>(kFormat2), info_->GetColorAttachmentFormat()); | 449 EXPECT_EQ(static_cast<GLenum>(kFormat2), info_->GetColorAttachmentFormat()); |
| 450 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 451 info_->IsPossiblyComplete()); |
| 452 EXPECT_TRUE(info_->IsCleared()); |
336 | 453 |
337 attachment = info_->GetAttachment(GL_COLOR_ATTACHMENT0); | 454 attachment = info_->GetAttachment(GL_COLOR_ATTACHMENT0); |
338 ASSERT_TRUE(attachment != NULL); | 455 ASSERT_TRUE(attachment != NULL); |
339 EXPECT_EQ(kWidth2, attachment->width()); | 456 EXPECT_EQ(kWidth2, attachment->width()); |
340 EXPECT_EQ(kHeight2, attachment->height()); | 457 EXPECT_EQ(kHeight2, attachment->height()); |
341 EXPECT_EQ(kSamples2, attachment->samples()); | 458 EXPECT_EQ(kSamples2, attachment->samples()); |
342 EXPECT_EQ(kFormat2, attachment->internal_format()); | 459 EXPECT_EQ(kFormat2, attachment->internal_format()); |
343 EXPECT_TRUE(attachment->cleared()); | 460 EXPECT_TRUE(attachment->cleared()); |
344 | 461 |
345 // Check changing attachment | 462 // Check changing attachment |
346 tex_manager.SetLevelInfo( | 463 texture_manager_.SetLevelInfo( |
347 &feature_info, tex_info2, GL_TEXTURE_2D, kLevel3, | 464 &feature_info, tex_info2, GL_TEXTURE_2D, kLevel3, |
348 kFormat3, kWidth3, kHeight3, kDepth, kBorder, kFormat3, kType); | 465 kFormat3, kWidth3, kHeight3, kDepth, kBorder, kFormat3, kType, false); |
349 attachment = info_->GetAttachment(GL_COLOR_ATTACHMENT0); | 466 attachment = info_->GetAttachment(GL_COLOR_ATTACHMENT0); |
350 ASSERT_TRUE(attachment != NULL); | 467 ASSERT_TRUE(attachment != NULL); |
351 EXPECT_EQ(kWidth3, attachment->width()); | 468 EXPECT_EQ(kWidth3, attachment->width()); |
352 EXPECT_EQ(kHeight3, attachment->height()); | 469 EXPECT_EQ(kHeight3, attachment->height()); |
353 EXPECT_EQ(kSamples3, attachment->samples()); | 470 EXPECT_EQ(kSamples3, attachment->samples()); |
354 EXPECT_EQ(kFormat3, attachment->internal_format()); | 471 EXPECT_EQ(kFormat3, attachment->internal_format()); |
355 EXPECT_TRUE(attachment->cleared()); | 472 EXPECT_FALSE(attachment->cleared()); |
356 EXPECT_EQ(static_cast<GLenum>(kFormat3), info_->GetColorAttachmentFormat()); | 473 EXPECT_EQ(static_cast<GLenum>(kFormat3), info_->GetColorAttachmentFormat()); |
| 474 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), |
| 475 info_->IsPossiblyComplete()); |
| 476 EXPECT_FALSE(info_->IsCleared()); |
| 477 |
| 478 // Set to size 0 |
| 479 texture_manager_.SetLevelInfo( |
| 480 &feature_info, tex_info2, GL_TEXTURE_2D, kLevel3, |
| 481 kFormat3, 0, 0, kDepth, kBorder, kFormat3, kType, false); |
| 482 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT), |
| 483 info_->IsPossiblyComplete()); |
357 | 484 |
358 // Check removing it. | 485 // Check removing it. |
359 info_->AttachTexture(GL_COLOR_ATTACHMENT0, NULL, 0, 0); | 486 info_->AttachTexture(GL_COLOR_ATTACHMENT0, NULL, 0, 0); |
360 EXPECT_TRUE(info_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL); | 487 EXPECT_TRUE(info_->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL); |
361 EXPECT_EQ(static_cast<GLenum>(0), info_->GetColorAttachmentFormat()); | 488 EXPECT_EQ(static_cast<GLenum>(0), info_->GetColorAttachmentFormat()); |
362 | 489 |
363 tex_manager.Destroy(false); | 490 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT), |
| 491 info_->IsPossiblyComplete()); |
| 492 EXPECT_TRUE(info_->IsCleared()); |
364 } | 493 } |
365 | 494 |
366 } // namespace gles2 | 495 } // namespace gles2 |
367 } // namespace gpu | 496 } // namespace gpu |
368 | 497 |
369 | 498 |
OLD | NEW |