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.
19 #include "model-skybox.h"
22 #include <dali/devel-api/adaptor-framework/file-loader.h>
27 #include "obj-loader.h"
28 #include "generated/skybox-vert.h"
29 #include "generated/skybox-frag.h"
31 ModelSkybox::ModelSkybox()
35 ModelSkybox::~ModelSkybox()
39 void ModelSkybox::Init(const Vector3& size)
41 Geometry geometry = CreateGeometry();
42 Shader shader = Shader::New(SHADER_SKYBOX_VERT, SHADER_SKYBOX_FRAG);
44 Renderer renderer = Renderer::New(geometry, shader);
48 renderer.SetTextures(mTextureSet);
51 // Face culling is enabled to hide the backwards facing sides of the model
52 // This is sufficient to render a single object; for more complex scenes depth-testing might be required
53 renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON);
54 renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::ON);
55 renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
56 renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK);
58 mActor = Actor::New();
59 mActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
60 mActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
61 mActor.SetProperty(Actor::Property::SIZE, size);
62 mActor.AddRenderer(renderer);
66 * Set texture and sampler
68 void ModelSkybox::InitTexture(Texture texSkybox)
70 mTextureSet = TextureSet::New();
71 mTextureSet.SetTexture(0u, texSkybox);
73 Sampler sampler = Sampler::New();
74 sampler.SetWrapMode(WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE);
75 sampler.SetFilterMode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR);
76 mTextureSet.SetSampler(0, sampler);
79 Actor& ModelSkybox::GetActor()
85 * @brief CreateGeometry
86 * This function creates a cube geometry including texture coordinates.
88 Geometry ModelSkybox::CreateGeometry()
97 Vertex skyboxVertices[] = {
99 {Vector3(-1.0f, 1.0f, -1.0f)},
100 {Vector3(-1.0f, -1.0f, -1.0f)},
101 {Vector3(1.0f, -1.0f, -1.0f)},
102 {Vector3(1.0f, -1.0f, -1.0f)},
103 {Vector3(1.0f, 1.0f, -1.0f)},
104 {Vector3(-1.0f, 1.0f, -1.0f)},
107 {Vector3(-1.0f, -1.0f, 1.0f)},
108 {Vector3(-1.0f, -1.0f, -1.0f)},
109 {Vector3(-1.0f, 1.0f, -1.0f)},
110 {Vector3(-1.0f, 1.0f, -1.0f)},
111 {Vector3(-1.0f, 1.0f, 1.0f)},
112 {Vector3(-1.0f, -1.0f, 1.0f)},
115 {Vector3(1.0f, -1.0f, -1.0f)},
116 {Vector3(1.0f, -1.0f, 1.0f)},
117 {Vector3(1.0f, 1.0f, 1.0f)},
118 {Vector3(1.0f, 1.0f, 1.0f)},
119 {Vector3(1.0f, 1.0f, -1.0f)},
120 {Vector3(1.0f, -1.0f, -1.0f)},
123 {Vector3(-1.0f, -1.0f, 1.0f)},
124 {Vector3(-1.0f, 1.0f, 1.0f)},
125 {Vector3(1.0f, 1.0f, 1.0f)},
126 {Vector3(1.0f, 1.0f, 1.0f)},
127 {Vector3(1.0f, -1.0f, 1.0f)},
128 {Vector3(-1.0f, -1.0f, 1.0f)},
131 {Vector3(-1.0f, 1.0f, -1.0f)},
132 {Vector3(1.0f, 1.0f, -1.0f)},
133 {Vector3(1.0f, 1.0f, 1.0f)},
134 {Vector3(1.0f, 1.0f, 1.0f)},
135 {Vector3(-1.0f, 1.0f, 1.0f)},
136 {Vector3(-1.0f, 1.0f, -1.0f)},
139 {Vector3(-1.0f, -1.0f, -1.0f)},
140 {Vector3(-1.0f, -1.0f, 1.0f)},
141 {Vector3(1.0f, -1.0f, -1.0f)},
142 {Vector3(1.0f, -1.0f, -1.0f)},
143 {Vector3(-1.0f, -1.0f, 1.0f)},
144 {Vector3(1.0f, -1.0f, 1.0f)}};
146 VertexBuffer vertexBuffer = VertexBuffer::New(Property::Map()
147 .Add("aPosition", Property::VECTOR3));
148 vertexBuffer.SetData(skyboxVertices, sizeof(skyboxVertices) / sizeof(Vertex));
150 geometry = Geometry::New();
151 geometry.AddVertexBuffer(vertexBuffer);
152 geometry.SetType(Geometry::TRIANGLES);