Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Context.cpp
1 /*
2  * Copyright (c) 2014 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 <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23
24 using namespace Dali;
25
26
27 namespace
28 {
29 // Size of the VertexAttributeArray enables
30 // GLES specification states that there's a minimum of 8
31 const unsigned int TEST_MAX_ATTRIBUTE_CACHE_SIZE = 8;
32
33 enum TestAttribType
34 {
35   ATTRIB_UNKNOWN = -1,
36   ATTRIB_POSITION,
37   ATTRIB_NORMAL,
38   ATTRIB_TEXCOORD,
39   ATTRIB_COLOR,
40   ATTRIB_BONE_WEIGHTS,
41   ATTRIB_BONE_INDICES,
42   ATTRIB_TYPE_LAST
43 };
44
45 // Create bitmap actor
46 static Actor CreateBitmapActor()
47 {
48   Actor actor = CreateRenderableActor();
49   actor.SetProperty( Actor::Property::SIZE, Vector2( 100.0f, 100.0f ) );
50   actor.SetProperty( Actor::Property::NAME,"Test Image Rendering Actor");
51   return actor;
52 }
53
54 } // anonymous namespace
55
56
57 // Positive test case for a method
58 int UtcDaliContextVertexAttribStartup(void)
59 {
60   tet_infoline("Testing vertex attrib initial state in context");
61
62   TestApplication application;
63
64   // start up
65   application.SendNotification();
66   application.Render();
67   application.Render();
68
69   // check the locations
70   for (unsigned int i = 0; i < TEST_MAX_ATTRIBUTE_CACHE_SIZE; i++)
71   {
72     DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(i) == false);
73   }
74
75   tet_result(TET_PASS);
76   END_TEST;
77 }
78
79 // Tests to make the attribs only get set once when continually rendering an image actor
80 int UtcDaliContextVertexAttribImageRendering(void)
81 {
82   tet_infoline("Testing vertex attrib rendering state in context with images");
83
84   TestApplication application;
85
86   // start up
87   application.SendNotification();
88   application.Render();
89   application.Render();
90
91   // the vertex attribs get modified on startup to set them to disabled
92   // clear the flag to say they've changed
93   application.GetGlAbstraction().ClearVertexAttribArrayChanged();
94
95
96   // create a test bitmap actor
97   Actor actor(CreateBitmapActor());
98   application.GetScene().Add(actor);
99
100
101   application.SendNotification();
102   application.Render();
103   application.Render();
104
105   // check to make sure the state has changed (the image renderer will enable some
106   // locations).
107   DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
108
109   // Now check to make sure the state is cached, and isn't being set each frame.
110   application.GetGlAbstraction().ClearVertexAttribArrayChanged();
111
112   application.Render();
113   application.Render();
114   application.Render();
115
116   // if it has changed then the caching has failed
117   DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged() == false);
118
119
120   tet_result(TET_PASS);
121   END_TEST;
122 }