2 * Copyright (c) 2020 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-renderer.h"
19 #include "game-model.h"
20 #include "game-texture.h"
22 #include <dali/dali.h>
28 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
29 attribute highp vec3 aPosition;\n
30 attribute highp vec3 aNormal;\n
31 attribute highp vec2 aTexCoord;\n
32 uniform highp mat4 uMvpMatrix;\n
33 varying highp vec2 vTexCoord;\n
36 gl_Position = uMvpMatrix * vec4(aPosition, 1.0 );\n
37 vTexCoord = aTexCoord;\n
38 vTexCoord.y = 1.0 - vTexCoord.y;\n
42 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
43 uniform sampler2D sTexture;\n
44 varying highp vec2 vTexCoord;\n
47 gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4(1.2, 1.2, 1.2, 1.0);\n
54 GameRenderer::GameRenderer()
60 GameRenderer::~GameRenderer()
64 void GameRenderer::SetModel(GameModel* model)
70 void GameRenderer::SetMainTexture(GameTexture* texture)
76 void GameRenderer::Setup()
78 if(!mRenderer && mModel)
80 Dali::Shader shader = Dali::Shader::New(VERTEX_SHADER, FRAGMENT_SHADER);
81 mRenderer = Dali::Renderer::New(mModel->GetGeometry(), shader);
82 mRenderer.SetProperty(Dali::Renderer::Property::DEPTH_WRITE_MODE, Dali::DepthWriteMode::ON);
83 mRenderer.SetProperty(Dali::Renderer::Property::DEPTH_FUNCTION, Dali::DepthFunction::LESS_EQUAL);
84 mRenderer.SetProperty(Dali::Renderer::Property::DEPTH_TEST_MODE, Dali::DepthTestMode::ON);
87 Dali::TextureSet textureSet;
88 Dali::Geometry geometry;
92 geometry = mModel->GetGeometry();
95 if(mTexture && mTexture->GetTextureSet())
97 textureSet = mTexture->GetTextureSet();
100 if(textureSet && geometry)
102 mRenderer.SetGeometry(geometry);
103 mRenderer.SetTextures(textureSet);
107 Dali::Renderer& GameRenderer::GetRenderer()