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/devel-api/actors/mesh-actor.h>
23 #include <dali-test-suite-utils.h>
27 #include "mesh-builder.h"
32 // Size of the VertexAttributeArray enables
33 // GLES specification states that there's minimum of
34 const unsigned int TEST_MAX_ATTRIBUTE_CACHE_SIZE = 8;
48 // Create bitmap image
49 static BufferImage CreateBufferImage()
51 BufferImage image = BufferImage::New(4,4,Pixel::RGBA8888);
56 static MeshActor CreateMeshActor()
59 MeshData::VertexContainer vertices;
60 MeshData::FaceIndices faces;
62 ConstructVertices(vertices, 60);
63 ConstructFaces(vertices, faces);
64 Material customMaterial = ConstructMaterial();
65 meshData.SetData(vertices, faces, bones, customMaterial);
66 meshData.SetHasNormals(true);
67 meshData.SetHasTextureCoords(true);
69 Mesh mesh = Mesh::New(meshData);
70 MeshActor actor = MeshActor::New(mesh);
72 actor.SetName("Test MeshActor");
78 static ImageActor CreateImageActor()
80 BufferImage image = CreateBufferImage();
81 ImageActor actor = ImageActor::New( image );
82 actor.SetSize( 100.0f, 100.0f );
83 actor.SetName("Test ImageActor");
87 } // anonymous namespace
90 // Positive test case for a method
91 int UtcDaliContextVertexAttribStartup(void)
93 tet_infoline("Testing vertex attrib initial state in context");
95 TestApplication application;
98 application.SendNotification();
100 application.Render();
102 // context class should initially set the vertex attrib locations to disable
103 // Make sure it has been modified
104 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
106 // check the locations
107 for (unsigned int i = 0; i < TEST_MAX_ATTRIBUTE_CACHE_SIZE; i++)
109 DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(i) == false);
112 tet_result(TET_PASS);
116 // Tests to make the attribs only get set once when continually rendering an image actor
117 int UtcDaliContextVertexAttribImageRendering(void)
119 tet_infoline("Testing vertex attrib rendering state in context with images");
121 TestApplication application;
124 application.SendNotification();
125 application.Render();
126 application.Render();
128 // the vertex attribs get modified on startup to set them to disabled
129 // clear the flag to say they've changed
130 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
133 // create a test image actor
134 ImageActor imageActor(CreateImageActor());
135 Stage::GetCurrent().Add(imageActor);
138 application.SendNotification();
139 application.Render();
140 application.Render();
142 // check to make sure the state has changed (the image renderer will enable some
144 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
146 // Now check to make sure the state is cached, and isn't being set each frame.
147 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
149 application.Render();
150 application.Render();
151 application.Render();
153 // if it has changed then the caching has failed
154 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged() == false);
157 tet_result(TET_PASS);
161 // test to make sure the attribs change when rendering both image and mode actors
162 int UtcDaliContextVertexAttribImageAndModelRendering(void)
164 tet_infoline("Testing vertex attrib rendering state in context with images and models");
166 TestApplication application;
169 application.SendNotification();
170 application.Render();
171 application.Render();
173 // the vertex attribs get modified on startup to set them to disabled
174 // clear the flag to say they've changed
175 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
177 // create a test image and mesh actor.
179 MeshActor meshActor(CreateMeshActor());
180 Stage::GetCurrent().Add(meshActor);
182 ImageActor imageActor(CreateImageActor());
183 Stage::GetCurrent().Add(imageActor);
186 application.SendNotification();
187 application.Render();
188 application.Render();
190 // check to make sure the state changes during the rendering of a frame
191 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
193 // Now check to make sure the state is changing each frame.
194 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
196 application.Render();
197 application.Render();
198 application.Render();
200 // make sure the state has changed
201 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
203 // depending on the order of drawing, one of the attrib locations should be disabled
204 // Image uses locations 0 & 2 (position, texture)
205 // Model uses locations 0 & 1 (position, normals) -no textures
206 // so either location 1 or location 2 should be disabled after drawing.
208 // see if mesh was last to draw
209 if (application.GetGlAbstraction().GetVertexAttribArrayState(ATTRIB_NORMAL))
211 // texture should be disabled
212 DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(ATTRIB_TEXCOORD) == false)
216 // image was to draw so, normals should be disabled
217 DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(ATTRIB_NORMAL) == false)
220 tet_result(TET_PASS);