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 BufferImage CreateBufferImage()
50 BufferImage image = BufferImage::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);
71 actor.SetName("Test MeshActor");
77 static ImageActor CreateImageActor()
79 BufferImage image = CreateBufferImage();
80 ImageActor actor = ImageActor::New( image );
81 actor.SetSize( 100.0f, 100.0f );
82 actor.SetName("Test ImageActor");
86 } // anonymous namespace
89 // Positive test case for a method
90 int UtcDaliContextVertexAttribStartup(void)
92 tet_infoline("Testing vertex attrib initial state in context");
94 TestApplication application;
97 application.SendNotification();
101 // context class should initially set the vertex attrib locations to disable
102 // Make sure it has been modified
103 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
105 // check the locations
106 for (unsigned int i = 0; i < TEST_MAX_ATTRIBUTE_CACHE_SIZE; i++)
108 DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(i) == false);
111 tet_result(TET_PASS);
115 // Tests to make the attribs only get set once when continually rendering an image actor
116 int UtcDaliContextVertexAttribImageRendering(void)
118 tet_infoline("Testing vertex attrib rendering state in context with images");
120 TestApplication application;
123 application.SendNotification();
124 application.Render();
125 application.Render();
127 // the vertex attribs get modified on startup to set them to disabled
128 // clear the flag to say they've changed
129 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
132 // create a test image actor
133 ImageActor imageActor(CreateImageActor());
134 Stage::GetCurrent().Add(imageActor);
137 application.SendNotification();
138 application.Render();
139 application.Render();
141 // check to make sure the state has changed (the image renderer will enable some
143 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
145 // Now check to make sure the state is cached, and isn't being set each frame.
146 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
148 application.Render();
149 application.Render();
150 application.Render();
152 // if it has changed then the caching has failed
153 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged() == false);
156 tet_result(TET_PASS);
160 // test to make sure the attribs change when rendering both image and mode actors
161 int UtcDaliContextVertexAttribImageAndModelRendering(void)
163 tet_infoline("Testing vertex attrib rendering state in context with images and models");
165 TestApplication application;
168 application.SendNotification();
169 application.Render();
170 application.Render();
172 // the vertex attribs get modified on startup to set them to disabled
173 // clear the flag to say they've changed
174 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
176 // create a test image and mesh actor.
178 MeshActor meshActor(CreateMeshActor());
179 Stage::GetCurrent().Add(meshActor);
181 ImageActor imageActor(CreateImageActor());
182 Stage::GetCurrent().Add(imageActor);
185 application.SendNotification();
186 application.Render();
187 application.Render();
189 // check to make sure the state changes during the rendering of a frame
190 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
192 // Now check to make sure the state is changing each frame.
193 application.GetGlAbstraction().ClearVertexAttribArrayChanged();
195 application.Render();
196 application.Render();
197 application.Render();
199 // make sure the state has changed
200 DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
202 // depending on the order of drawing, one of the attrib locations should be disabled
203 // Image uses locations 0 & 2 (position, texture)
204 // Model uses locations 0 & 1 (position, normals) -no textures
205 // so either location 1 or location 2 should be disabled after drawing.
207 // see if mesh was last to draw
208 if (application.GetGlAbstraction().GetVertexAttribArrayState(ATTRIB_NORMAL))
210 // texture should be disabled
211 DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(ATTRIB_TEXCOORD) == false)
215 // image was to draw so, normals should be disabled
216 DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(ATTRIB_NORMAL) == false)
219 tet_result(TET_PASS);