2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
26 #include "mesh-builder.h"
31 // Size of the VertexAttributeArray enables
32 // GLES specification states that there's minimum of
33 const unsigned int TEST_MAX_ATTRIBUTE_CACHE_SIZE = 8;
47 // Create bitmap image
48 static BitmapImage CreateBitmapImage()
50 BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
55 static MeshActor CreateMeshActor()
58 MeshData::VertexContainer vertices;
59 MeshData::FaceIndices faces;
61 ConstructVertices(vertices, 60);
62 ConstructFaces(vertices, faces);
63 Material customMaterial = ConstructMaterial();
64 meshData.SetData(vertices, faces, bones, customMaterial);
65 meshData.SetHasNormals(true);
66 meshData.SetHasTextureCoords(true);
68 Mesh mesh = Mesh::New(meshData);
69 MeshActor actor = MeshActor::New(mesh);
70 actor.SetName("Test MeshActor");
75 static LightActor CreateLight()
77 Light light = Light::New("Light");
78 light.SetType( POINT );
79 light.SetAmbientColor( Vector3( 0.22f, 0.33f, 0.44f ) );
80 light.SetDiffuseColor( Vector3( 0.55f, 0.66f, 0.77f) );
81 light.SetSpecularColor( Vector3( 0.88f, 0.99f, 0.11f) );
82 LightActor lightActor = LightActor::New();
83 lightActor.SetParentOrigin( ParentOrigin::CENTER );
84 lightActor.SetPosition( 0.f, 0.f, 100.0f );
85 lightActor.SetLight( light );
86 lightActor.SetName( light.GetName() );
91 static ImageActor CreateImageActor()
93 BitmapImage image = CreateBitmapImage();
94 ImageActor actor = ImageActor::New( image );
95 actor.SetSize( 100.0f, 100.0f );
96 actor.SetName("Test ImageActor");
100 } // anonymous namespace
103 // Positive test case for a method
104 int UtcDaliContextVertexAttribStartup(void)
106 tet_infoline("Testing vertex attrib initial state in context");
108 TestApplication application;
111 application.SendNotification();
112 application.Render();
113 application.Render();
115 // context class should initially set the vertex attrib locations to disable
116 // Make sure it has been modified
117 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
119 // check the locations
120 for (unsigned int i = 0; i < TEST_MAX_ATTRIBUTE_CACHE_SIZE; i++)
122 DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(i) == false);
125 tet_result(TET_PASS);
129 // Tests to make the attribs only get set once when continually rendering an image actor
130 int UtcDaliContextVertexAttribImageRendering(void)
132 tet_infoline("Testing vertex attrib rendering state in context with images");
134 TestApplication application;
137 application.SendNotification();
138 application.Render();
139 application.Render();
141 // the vertex attribs get modified on startup to set them to disabled
142 // clear the flag to say they've changed
143 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
146 // create a test image actor
147 ImageActor imageActor(CreateImageActor());
148 Stage::GetCurrent().Add(imageActor);
151 application.SendNotification();
152 application.Render();
153 application.Render();
155 // check to make sure the state has changed (the image renderer will enable some
157 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
159 // Now check to make sure the state is cached, and isn't being set each frame.
160 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
162 application.Render();
163 application.Render();
164 application.Render();
166 // if it has changed then the caching has failed
167 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged() == false);
170 tet_result(TET_PASS);
174 // test to make sure the attribs change when rendering both image and mode actors
175 int UtcDaliContextVertexAttribImageAndModelRendering(void)
177 tet_infoline("Testing vertex attrib rendering state in context with images and models");
179 TestApplication application;
182 application.SendNotification();
183 application.Render();
184 application.Render();
186 // the vertex attribs get modified on startup to set them to disabled
187 // clear the flag to say they've changed
188 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
190 // create a test light, image and mesh actor. (meshes won't render without light)
192 LightActor lightActor(CreateLight());
193 Stage::GetCurrent().Add(lightActor);
194 lightActor.SetActive(true);
196 MeshActor meshActor(CreateMeshActor());
197 Stage::GetCurrent().Add(meshActor);
199 ImageActor imageActor(CreateImageActor());
200 Stage::GetCurrent().Add(imageActor);
203 application.SendNotification();
204 application.Render();
205 application.Render();
207 // check to make sure the state changes during the rendering of a frame
208 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
210 // Now check to make sure the state is changing each frame.
211 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
213 application.Render();
214 application.Render();
215 application.Render();
217 // make sure the state has changed
218 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
220 // depending on the order of drawing, one of the attrib locations should be disabled
221 // Image uses locations 0 & 2 (position, texture)
222 // Model uses locations 0 & 1 (position, normals) -no textures
223 // so either location 1 or location 2 should be disabled after drawing.
225 // see if mesh was last to draw
226 if (application.GetGlAbstraction().GetVertexAttribArrayState(ATTRIB_NORMAL))
228 // texture should be disabled
229 DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(ATTRIB_TEXCOORD) == false)
233 // image was to draw so, normals should be disabled
234 DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(ATTRIB_NORMAL) == false)
237 tet_result(TET_PASS);