2 * Copyright (c) 2016 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.
18 #include "game-model.h"
19 #include "game-texture.h"
20 #include "game-renderer.h"
22 #include <dali/dali.h>
27 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
28 attribute highp vec3 aPosition;\n
29 attribute highp vec3 aNormal;\n
30 attribute highp vec2 aTexCoord;\n
31 uniform highp mat4 uMvpMatrix;\n
32 varying highp vec2 vTexCoord;\n
35 gl_Position = uMvpMatrix * vec4(aPosition, 1.0 );\n
36 vTexCoord = aTexCoord;\n
37 vTexCoord.y = 1.0 - vTexCoord.y;\n
41 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
42 uniform sampler2D sTexture;\n
43 varying highp vec2 vTexCoord;\n
46 gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4(1.2, 1.2, 1.2, 1.0);\n
52 GameRenderer::GameRenderer()
58 GameRenderer::~GameRenderer()
62 void GameRenderer::SetModel( GameModel* model )
68 void GameRenderer::SetMainTexture( GameTexture* texture )
74 void GameRenderer::Setup()
76 if( !mRenderer && mModel )
78 Dali::Shader shader = Dali::Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
79 mRenderer = Dali::Renderer::New( mModel->GetGeometry(), shader );
80 mRenderer.SetProperty( Dali::Renderer::Property::DEPTH_WRITE_MODE, Dali::DepthWriteMode::ON );
81 mRenderer.SetProperty( Dali::Renderer::Property::DEPTH_FUNCTION, Dali::DepthFunction::LESS_EQUAL );
82 mRenderer.SetProperty( Dali::Renderer::Property::DEPTH_TEST_MODE, Dali::DepthTestMode::ON );
85 Dali::TextureSet textureSet;
86 Dali::Geometry geometry;
90 geometry = mModel->GetGeometry();
93 if( mTexture && mTexture->GetTextureSet() )
95 textureSet = mTexture->GetTextureSet();
98 if( textureSet && geometry )
100 mRenderer.SetGeometry( geometry );
101 mRenderer.SetTextures( textureSet );
105 Dali::Renderer& GameRenderer::GetRenderer()