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-renderer.h"
23 #include <dali-toolkit/internal/controls/renderers/renderer-factory-impl.h>
24 #include <dali-toolkit/internal/controls/renderers/renderer-factory-cache.h>
25 #include <dali-toolkit/internal/controls/renderers/control-renderer-data-impl.h>
38 const char * const RENDERER_TYPE("rendererType");
39 const char * const RENDERER_TYPE_VALUE("debug");
41 const char * const POSITION_ATTRIBUTE_NAME("aPosition");
42 const char * const INDEX_NAME("indices");
44 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
45 attribute mediump vec2 aPosition;\n
46 uniform mediump mat4 uMvpMatrix;\n
47 uniform mediump vec3 uSize;\n
51 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
52 vertexPosition.xyz *= uSize;\n
53 gl_Position = uMvpMatrix * vertexPosition;\n
57 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(\n
58 uniform lowp vec4 uColor;\n
62 gl_FragColor = uColor;\n
69 DebugRenderer::DebugRenderer( RendererFactoryCache& factoryCache )
70 : ControlRenderer( factoryCache )
74 DebugRenderer::~DebugRenderer()
77 void DebugRenderer::DoSetOnStage( Actor& actor )
82 void DebugRenderer::DoCreatePropertyMap( Property::Map& map ) const
85 map.Insert( RENDERER_TYPE, RENDERER_TYPE_VALUE );
88 void DebugRenderer::InitializeRenderer()
90 mImpl->mRenderer = mFactoryCache.GetDebugRenderer();
91 if( !mImpl->mRenderer )
93 Geometry geometry = CreateQuadWireframeGeometry();
94 Shader shader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
95 Material material = Material::New( shader );
96 mImpl->mRenderer = Renderer::New( geometry,
98 mFactoryCache.CacheDebugRenderer( mImpl->mRenderer );
102 Geometry DebugRenderer::CreateQuadWireframeGeometry()
104 const float halfWidth = 0.5f;
105 const float halfHeight = 0.5f;
106 struct QuadVertex { Vector2 position;};
107 QuadVertex quadVertexData[4] =
109 { Vector2(-halfWidth, -halfHeight) },
110 { Vector2( halfWidth, -halfHeight) },
111 { Vector2( halfWidth, halfHeight) },
112 { Vector2(-halfWidth, halfHeight) }
115 Property::Map quadVertexFormat;
116 quadVertexFormat[POSITION_ATTRIBUTE_NAME] = Property::VECTOR2;
117 PropertyBuffer quadVertices = PropertyBuffer::New( quadVertexFormat, 4 );
118 quadVertices.SetData(quadVertexData);
121 unsigned int indexData[10] = { 0, 1, 1, 2, 2, 3, 3, 0 };
122 Property::Map indexFormat;
123 indexFormat[INDEX_NAME] = Property::INTEGER;
124 PropertyBuffer indices = PropertyBuffer::New( indexFormat, sizeof(indexData)/sizeof(indexData[0]) );
125 indices.SetData(indexData);
127 // Create the geometry object
128 Geometry geometry = Geometry::New();
129 geometry.AddVertexBuffer( quadVertices );
130 geometry.SetIndexBuffer( indices );
131 geometry.SetGeometryType( Geometry::LINES );
136 } // namespace Internal
138 } // namespace Toolkit