2 * Copyright (c) 2015 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.
20 #include "debug-visual.h"
23 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
24 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
25 #include <dali-toolkit/internal/visuals/visual-data-impl.h>
26 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
39 const char * const POSITION_ATTRIBUTE_NAME("aPosition");
40 const char * const INDEX_NAME("indices");
42 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
43 attribute mediump vec2 aPosition;\n
44 uniform mediump mat4 uMvpMatrix;\n
45 uniform mediump vec3 uSize;\n
49 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
50 vertexPosition.xyz *= uSize;\n
51 gl_Position = uMvpMatrix * vertexPosition;\n
55 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(\n
56 uniform lowp vec4 uColor;\n
60 gl_FragColor = uColor;\n
67 DebugVisual::DebugVisual( VisualFactoryCache& factoryCache )
68 : Visual( factoryCache )
72 DebugVisual::~DebugVisual()
75 void DebugVisual::DoSetOnStage( Actor& actor )
80 void DebugVisual::DoCreatePropertyMap( Property::Map& map ) const
83 map.Insert( RENDERER_TYPE, DEBUG_RENDERER );
86 void DebugVisual::InitializeRenderer()
88 mImpl->mRenderer = mFactoryCache.GetDebugRenderer();
89 if( !mImpl->mRenderer )
91 Geometry geometry = CreateQuadWireframeGeometry();
92 Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
94 mImpl->mRenderer = Renderer::New( geometry, shader);
95 mFactoryCache.CacheDebugRenderer( mImpl->mRenderer );
99 Geometry DebugVisual::CreateQuadWireframeGeometry()
101 const float halfWidth = 0.5f;
102 const float halfHeight = 0.5f;
103 struct QuadVertex { Vector2 position;};
104 QuadVertex quadVertexData[4] =
106 { Vector2(-halfWidth, -halfHeight) },
107 { Vector2( halfWidth, -halfHeight) },
108 { Vector2( halfWidth, halfHeight) },
109 { Vector2(-halfWidth, halfHeight) }
112 Property::Map quadVertexFormat;
113 quadVertexFormat[POSITION_ATTRIBUTE_NAME] = Property::VECTOR2;
114 PropertyBuffer quadVertices = PropertyBuffer::New( quadVertexFormat );
115 quadVertices.SetData( quadVertexData, 4 );
118 unsigned short indexData[10] = { 0, 1, 1, 2, 2, 3, 3, 0 };
120 // Create the geometry object
121 Geometry geometry = Geometry::New();
122 geometry.AddVertexBuffer( quadVertices );
123 geometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0]) );
124 geometry.SetGeometryType( Geometry::LINES );
129 } // namespace Internal
131 } // namespace Toolkit