3eac9ab5c96d3ab761037ca5befff0470af49099
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-FrameBuffer.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
20
21 using namespace Dali;
22
23 #include <mesh-builder.h>
24
25 void framebuffer_set_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void framebuffer_set_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35 int UtcDaliFrameBufferNew01(void)
36 {
37   TestApplication application;
38
39   unsigned int width(64);
40   unsigned int height(64);
41   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
42
43   DALI_TEST_CHECK( frameBuffer );
44
45   application.SendNotification();
46   application.Render();
47
48   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
49   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
50   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
51
52   END_TEST;
53 }
54
55 int UtcDaliFrameBufferNew02(void)
56 {
57   TestApplication application;
58
59   unsigned int width(64);
60   unsigned int height(64);
61   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_DEPTH );
62
63   DALI_TEST_CHECK( frameBuffer );
64
65   application.SendNotification();
66   application.Render();
67
68   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
69   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
70   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
71
72   END_TEST;
73 }
74
75 int UtcDaliFrameBufferNew03(void)
76 {
77   TestApplication application;
78
79   unsigned int width(64);
80   unsigned int height(64);
81   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_STENCIL );
82
83   DALI_TEST_CHECK( frameBuffer );
84
85   application.SendNotification();
86   application.Render();
87
88   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
89   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
90   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
91
92   END_TEST;
93 }
94
95 int UtcDaliFrameBufferNew04(void)
96 {
97   TestApplication application;
98
99   unsigned int width(64);
100   unsigned int height(64);
101   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_DEPTH_STENCIL );
102
103   DALI_TEST_CHECK( frameBuffer );
104
105   application.SendNotification();
106   application.Render();
107
108   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
109   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
110   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
111
112   END_TEST;
113 }
114
115 int UtcDaliFrameBufferNew05(void)
116 {
117   TestApplication application;
118   FrameBuffer frameBuffer;
119   DALI_TEST_CHECK( !frameBuffer );
120   END_TEST;
121 }
122
123 int UtcDaliFrameBufferCopyConstructor(void)
124 {
125   TestApplication application;
126
127   unsigned int width(64);
128   unsigned int height(64);
129   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
130
131   FrameBuffer frameBufferCopy( frameBuffer );
132
133   DALI_TEST_CHECK( frameBufferCopy );
134
135   END_TEST;
136 }
137
138 int UtcDaliFrameBufferAssignmentOperator(void)
139 {
140   TestApplication application;
141
142   unsigned int width(64);
143   unsigned int height(64);
144   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
145
146   FrameBuffer frameBuffer2;
147   DALI_TEST_CHECK( !frameBuffer2 );
148
149   frameBuffer2 = frameBuffer;
150   DALI_TEST_CHECK( frameBuffer2 );
151
152   END_TEST;
153 }
154
155 int UtcDaliFrameBufferDownCast01(void)
156 {
157   TestApplication application;
158   unsigned int width(64);
159   unsigned int height(64);
160   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
161
162   BaseHandle handle(frameBuffer);
163   FrameBuffer frameBuffer2 = FrameBuffer::DownCast(handle);
164   DALI_TEST_CHECK( frameBuffer2 );
165
166   END_TEST;
167 }
168
169 int UtcDaliFrameBufferDownCast02(void)
170 {
171   TestApplication application;
172
173   Handle handle = Handle::New(); // Create a custom object
174   FrameBuffer frameBuffer = FrameBuffer::DownCast(handle);
175   DALI_TEST_CHECK( !frameBuffer );
176   END_TEST;
177 }
178
179 int UtcDaliFrameBufferAttachColorTexture01(void)
180 {
181   TestApplication application;
182
183   unsigned int width(64);
184   unsigned int height(64);
185   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR_DEPTH_STENCIL );
186   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
187   frameBuffer.AttachColorTexture( texture );
188
189   application.SendNotification();
190   application.Render();
191
192   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
193   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
194   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
195
196   END_TEST;
197 }
198
199 int UtcDaliFrameBufferAttachColorTexture02(void)
200 {
201   TestApplication application;
202
203   unsigned int width(64);
204   unsigned int height(64);
205   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
206   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
207   texture.GenerateMipmaps();
208
209   //Attach mipmap 1
210   frameBuffer.AttachColorTexture( texture, 0u, 1u );
211
212   application.SendNotification();
213   application.Render();
214
215   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
216   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
217   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
218
219   END_TEST;
220 }
221
222 int UtcDaliFrameBufferAttachColorTexture03(void)
223 {
224   TestApplication application;
225
226   unsigned int width(64);
227   unsigned int height(64);
228   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
229   Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
230   texture.GenerateMipmaps();
231
232   //Attach NEGATIVE_Y face of the cubemap
233   frameBuffer.AttachColorTexture( texture, 0u, CubeMapLayer::NEGATIVE_Y );
234
235   application.SendNotification();
236   application.Render();
237
238   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
239   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
240   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
241
242   END_TEST;
243 }
244
245 int UtcDaliFrameBufferGetColorTexture01(void)
246 {
247   TestApplication application;
248
249   unsigned int width(64);
250   unsigned int height(64);
251   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
252   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
253   frameBuffer.AttachColorTexture( texture );
254
255   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
256
257   END_TEST;
258 }
259
260 int UtcDaliFrameBufferGetColorTexture02(void)
261 {
262   TestApplication application;
263
264   unsigned int width(64);
265   unsigned int height(64);
266   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::COLOR );
267   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
268   frameBuffer.AttachColorTexture( texture, 0u, 1u );
269
270   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
271
272   END_TEST;
273 }
274