SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppDemoSceneTextureCompression.cpp
Go to the documentation of this file.
1 /**
2  * \file AppDemoSceneTextureCompression.cpp
3  * \brief Implementation for an SLScene inherited class
4  * \details For more info about App framework and the scene assembly see:
5  * https://cpvrlab.github.io/SLProject4/app-framework.html
6  * \date May 2024
7  * \authors Marino von Wattenwyl
8  * \copyright http://opensource.org/licenses/GPL-3.0
9  * \remarks Please use clangformat to format the code. See more code style on
10  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
11 */
12 
14 #include <SLAssetLoader.h>
15 #include <SLLightSpot.h>
16 #include <SLRectangle.h>
17 #include <AppCommon.h>
18 
19 //-----------------------------------------------------------------------------
21 {
22  info("Texture Compression Test Scene");
23 }
24 //-----------------------------------------------------------------------------
25 //! All assets the should be loaded in parallel must be registered in here.
27 {
28  SLint min = GL_LINEAR_MIPMAP_LINEAR;
29  SLint mag = GL_LINEAR;
30 
33  "earth2048_C.png",
34  min,
35  mag);
38  "earth2048_C_Q90.jpg",
39  min,
40  mag);
43  "earth2048_C_Q40.jpg",
44  min,
45  mag);
46 
47  /* Console commands to generate the following KTX files
48  ./../../../externals/prebuilt/mac64_ktx_v4.0.0-beta7-cpvr/release/toktx --automipmap --linear --lower_left_maps_to_s0t0 --bcmp --clevel 4 --qlevel 255 earth2048_C_bcmp_Q255.ktx2 earth2048_C.png
49  ./../../../externals/prebuilt/mac64_ktx_v4.0.0-beta7-cpvr/release/toktx --automipmap --linear --lower_left_maps_to_s0t0 --bcmp --clevel 4 --qlevel 128 earth2048_C_bcmp_Q128.ktx2 earth2048_C.png
50  ./../../../externals/prebuilt/mac64_ktx_v4.0.0-beta7-cpvr/release/toktx --automipmap --linear --lower_left_maps_to_s0t0 --bcmp --clevel 4 --qlevel 1 earth2048_C_bcmp_Q001.ktx2 earth2048_C.png
51  ./../../../externals/prebuilt/mac64_ktx_v4.0.0-beta7-cpvr/release/toktx --automipmap --linear --lower_left_maps_to_s0t0 --uastc 4 --zcmp 19 earth2048_C_uastc4.ktx2 earth2048_C.png
52  ./../../../externals/prebuilt/mac64_ktx_v4.0.0-beta7-cpvr/release/toktx --automipmap --linear --lower_left_maps_to_s0t0 --uastc 2 --zcmp 19 earth2048_C_uastc2.ktx2 earth2048_C.png
53  ./../../../externals/prebuilt/mac64_ktx_v4.0.0-beta7-cpvr/release/toktx --automipmap --linear --lower_left_maps_to_s0t0 --uastc 0 --zcmp 19 earth2048_C_uastc0.ktx2 earth2048_C.png
54  */
55 
58  "earth2048_C_bcmp_Q255.ktx2",
59  min,
60  mag);
63  "earth2048_C_bcmp_Q128.ktx2",
64  min,
65  mag);
68  "earth2048_C_bcmp_Q001.ktx2",
69  min,
70  mag);
73  "earth2048_C_uastc4.ktx2",
74  min,
75  mag);
78  "earth2048_C_uastc2.ktx2",
79  min,
80  mag);
83  "earth2048_C_uastc0.ktx2",
84  min,
85  mag);
86 }
87 //-----------------------------------------------------------------------------
88 //! After parallel loading of the assets the scene gets assembled in here.
90 {
91  // Create a scene group node
92  SLNode* scene = new SLNode("scene node");
93  this->root3D(scene);
94 
95  // Create a light source node
96  SLLightSpot* light1 = new SLLightSpot(am, this, 0.1f);
97  light1->translation(5, 5, 5);
98  light1->name("light node");
99  scene->addChild(light1);
100 
101  SLCamera* cam1 = new SLCamera("Camera 1");
102  cam1->clipNear(0.1f);
103  cam1->clipFar(100);
104  cam1->translation(0, 0, 4.2f);
105  cam1->lookAt(0, 0, 0);
106  cam1->focalDist(4.2f);
107  cam1->background().colors(SLCol4f(0.7f, 0.7f, 0.7f),
108  SLCol4f(0.2f, 0.2f, 0.2f));
109  cam1->setInitialState();
110  scene->addChild(cam1);
111 
112  // Position for rectangle and uv out of earth texture
113  SLVec2f pMin(-.5f, -.5f), pMax(.5f, .5f);
114  SLVec2f tMin(.47f, .69f), tMax(.56f, .81f);
115 
116  //.........................................................................
117  SLMaterial* matPng = new SLMaterial(am,
118  "matPng",
119  _texPng);
120  SLMesh* rectMeshPng = new SLRectangle(am,
121  pMin,
122  pMax,
123  tMin,
124  tMax,
125  1,
126  1,
127  "rectMeshPng",
128  matPng);
129  SLNode* rectNodePng = new SLNode(rectMeshPng,
130  "rectNodePng");
131  rectNodePng->translate(-1.05f, 1.05f, 0);
132  scene->addChild(rectNodePng);
133  //.........................................................................
134  SLMaterial* matJpgQ90 = new SLMaterial(am,
135  "matJpgQ90",
136  _texJpgQ90);
137  SLMesh* rectMeshJpgQ90 = new SLRectangle(am,
138  pMin,
139  pMax,
140  tMin,
141  tMax,
142  1,
143  1,
144  "rectMeshJpgQ90",
145  matJpgQ90);
146  SLNode* rectNodeJpgQ90 = new SLNode(rectMeshJpgQ90,
147  "rectNodeJpgQ90");
148  rectNodeJpgQ90->translate(0, 1.05f, 0);
149  scene->addChild(rectNodeJpgQ90);
150  //.........................................................................
151  SLMaterial* matJpgQ40 = new SLMaterial(am,
152  "matJpgQ40",
153  _texJpgQ40);
154  SLMesh* rectMeshJpgQ40 = new SLRectangle(am,
155  pMin,
156  pMax,
157  tMin,
158  tMax,
159  1,
160  1,
161  "rectMeshJpgQ40",
162  matJpgQ40);
163  SLNode* rectNodeJpgQ40 = new SLNode(rectMeshJpgQ40,
164  "rectNodeJpgQ40");
165  rectNodeJpgQ40->translate(1.05f, 1.05f, 0);
166  scene->addChild(rectNodeJpgQ40);
167  //.........................................................................
168  SLMaterial* matKtxBcmp255 = new SLMaterial(am,
169  "matKtxBcmp255",
171  SLMesh* rectMeshKtxBcmp255 = new SLRectangle(am,
172  pMin,
173  pMax,
174  tMin,
175  tMax,
176  1,
177  1,
178  "rectMeshKtxBcmp255",
179  matKtxBcmp255);
180  SLNode* rectNodeKtxBcmp255 = new SLNode(rectMeshKtxBcmp255,
181  "rectNodeKtxBcmp255");
182  rectNodeKtxBcmp255->translate(-1.05f, 0, 0);
183  scene->addChild(rectNodeKtxBcmp255);
184  //.........................................................................
185  SLMaterial* matKtxBcmp128 = new SLMaterial(am,
186  "matKtxBcmp128",
188  SLMesh* rectMeshKtxBcmp128 = new SLRectangle(am,
189  pMin,
190  pMax,
191  tMin,
192  tMax,
193  1,
194  1,
195  "rectMeshKtxBcmp128",
196  matKtxBcmp128);
197  SLNode* rectNodeKtxBcmp128 = new SLNode(rectMeshKtxBcmp128,
198  "rectNodeKtxBcmp128");
199  rectNodeKtxBcmp128->translate(0, 0, 0);
200  scene->addChild(rectNodeKtxBcmp128);
201  //.........................................................................
202  SLMaterial* matKtxBcmp001 = new SLMaterial(am,
203  "matKtxBcmp001",
205  SLMesh* rectMeshKtxBcmp001 = new SLRectangle(am,
206  pMin,
207  pMax,
208  tMin,
209  tMax,
210  1,
211  1,
212  "rectMeshKtxBcmp001",
213  matKtxBcmp001);
214  SLNode* rectNodeKtxBcmp001 = new SLNode(rectMeshKtxBcmp001,
215  "rectNodeKtxBcmp001");
216  rectNodeKtxBcmp001->translate(1.05f, 0, 0);
217  scene->addChild(rectNodeKtxBcmp001);
218  //.........................................................................
219  SLMaterial* matKtxUastc4 = new SLMaterial(am,
220  "matKtxUastc4",
221  _texKtxUastc4);
222  SLMesh* rectMeshKtxUastc4 = new SLRectangle(am,
223  pMin,
224  pMax,
225  tMin,
226  tMax,
227  1,
228  1,
229  "rectMeshKtxUastc4",
230  matKtxUastc4);
231  SLNode* rectNodeKtxUastc4 = new SLNode(rectMeshKtxUastc4,
232  "rectNodeKtxUastc4");
233  rectNodeKtxUastc4->translate(1.05f, -1.05f, 0);
234  scene->addChild(rectNodeKtxUastc4);
235  //.........................................................................
236  SLMaterial* matKtxUastc2 = new SLMaterial(am,
237  "matKtxUastc2",
238  _texKtxUastc2);
239  SLMesh* rectMeshKtxUastc2 = new SLRectangle(am,
240  pMin,
241  pMax,
242  tMin,
243  tMax,
244  1,
245  1,
246  "rectMeshKtxUastc2",
247  matKtxUastc2);
248  SLNode* rectNodeKtxUastc2 = new SLNode(rectMeshKtxUastc2,
249  "rectNodeKtxUastc2");
250  rectNodeKtxUastc2->translate(0, -1.05f, 0);
251  scene->addChild(rectNodeKtxUastc2);
252  //.........................................................................
253  SLMaterial* matKtxUastc0 = new SLMaterial(am,
254  "matKtxUastc0",
255  _texKtxUastc0);
256  SLMesh* rectMeshKtxUastc0 = new SLRectangle(am,
257  pMin,
258  pMax,
259  tMin,
260  tMax,
261  1,
262  1,
263  "rectMeshKtxUastc0",
264  matKtxUastc0);
265  SLNode* rectNodeKtxUastc0 = new SLNode(rectMeshKtxUastc0,
266  "rectNodeKtxUastc0");
267  rectNodeKtxUastc0->translate(-1.05f, -1.05f, 0);
268  scene->addChild(rectNodeKtxUastc0);
269  //.........................................................................
270  // Add active camera
271  sv->camera(cam1);
272 
273  // Save energy
274  sv->doWaitOnIdle(true);
275 }
276 //-----------------------------------------------------------------------------
The AppCommon class holds the top-level instances of the app-demo.
Class declaration for an SLScene inherited class.
int SLint
Definition: SL.h:170
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
void registerAssetsToLoad(SLAssetLoader &al) override
All scene specific assets have to be registered for async loading in here.
void assemble(SLAssetManager *am, SLSceneView *sv) override
After parallel loading of the assets the scene gets assembled in here.
void addTextureToLoad(SLGLTexture *&texture, const SLstring &path, SLint min_filter=GL_LINEAR_MIPMAP_LINEAR, SLint mag_filter=GL_LINEAR, SLTextureType type=TT_unknown, SLint wrapS=GL_REPEAT, SLint wrapT=GL_REPEAT)
Add 2D textures with internal image allocation.
Toplevel holder of the assets meshes, materials, textures and shaders.
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
void clipFar(const SLfloat cFar)
Definition: SLCamera.h:109
void clipNear(const SLfloat cNear)
Definition: SLCamera.h:108
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLBackground & background()
Definition: SLCamera.h:165
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
An SLMesh object is a triangulated mesh, drawn with one draw call.
Definition: SLMesh.h:134
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void addChild(SLNode *child)
Definition: SLNode.cpp:207
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
void setInitialState()
Definition: SLNode.cpp:1084
void lookAt(SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
Definition: SLNode.h:652
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
void name(const SLstring &Name)
Definition: SLObject.h:34
SLRectangle creates a rectangular mesh with a certain resolution.
Definition: SLRectangle.h:29
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SLNode * root3D()
Definition: SLScene.h:99
friend class SLNode
Definition: SLScene.h:48
SLstring & info()
Definition: SLScene.h:102
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
void doWaitOnIdle(SLbool doWI)
Definition: SLSceneView.h:149