SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLAssetManager Class Reference

Toplevel holder of the assets meshes, materials, textures and shaders. More...

#include <SLAssetManager.h>

Public Member Functions

 ~SLAssetManager ()
 
void generateStaticFonts (SLstring fontPath)
 
void clear ()
 for all assets, clear gpu data More...
 
void deleteDataGpu ()
 for all assets, clear gpu data More...
 
bool removeMesh (SLMesh *mesh)
 Removes the specified mesh from the meshes resource vector. More...
 
bool removeProgram (SLGLProgram *program)
 Removes the specified mesh from the meshes resource vector. More...
 
SLGLProgramgetProgramByName (const string &programName)
 Returns the pointer to shader program if found by name. More...
 
void merge (SLAssetManager &other)
 merge other asset manager into this More...
 
SLVMeshmeshes ()
 
SLVMaterialmaterials ()
 
SLVGLTexturetextures ()
 
SLVGLProgramprograms ()
 

Static Public Member Functions

static void generateFonts (SLstring fontPath, SLGLProgram &fontTexProgram)
 Generates all static fonts. More...
 
static void deleteFonts ()
 Deletes all static fonts. More...
 
static SLTexFontgetFont (SLfloat heightMM, SLint dpi)
 returns nearest font for a given height in mm More...
 

Static Public Attributes

static SLTexFontfont07 = nullptr
 7 pixel high fixed size font More...
 
static SLTexFontfont08 = nullptr
 8 pixel high fixed size font More...
 
static SLTexFontfont09 = nullptr
 9 pixel high fixed size font More...
 
static SLTexFontfont10 = nullptr
 10 pixel high fixed size font More...
 
static SLTexFontfont12 = nullptr
 12 pixel high fixed size font More...
 
static SLTexFontfont14 = nullptr
 14 pixel high fixed size font More...
 
static SLTexFontfont16 = nullptr
 16 pixel high fixed size font More...
 
static SLTexFontfont18 = nullptr
 18 pixel high fixed size font More...
 
static SLTexFontfont20 = nullptr
 20 pixel high fixed size font More...
 
static SLTexFontfont22 = nullptr
 22 pixel high fixed size font More...
 
static SLTexFontfont24 = nullptr
 24 pixel high fixed size font More...
 

Protected Attributes

SLVMesh _meshes
 Vector of all meshes. More...
 
SLVMaterial _materials
 Vector of all materials pointers. More...
 
SLVGLTexture _textures
 Vector of all texture pointers. More...
 
SLVGLProgram _programs
 Vector of all shader program pointers. More...
 

Detailed Description

Toplevel holder of the assets meshes, materials, textures and shaders.

All these assets can be shared among instances of SLScene, SLNode and SLMaterial. Shared assets are meshes (SLMesh), materials (SLMaterial), textures (SLGLTexture) and shader programs (SLGLProgram). One instance of SLAssetManager must be owned and destroyed by the app (see e.g. AppCommon.h).

Definition at line 32 of file SLAssetManager.h.

Constructor & Destructor Documentation

◆ ~SLAssetManager()

SLAssetManager::~SLAssetManager ( )

Definition at line 31 of file SLAssetManager.cpp.

32 {
33  clear();
34 }
void clear()
for all assets, clear gpu data

Member Function Documentation

◆ clear()

void SLAssetManager::clear ( )

for all assets, clear gpu data

Definition at line 44 of file SLAssetManager.cpp.

45 {
46  // delete materials
47  for (auto m : _materials)
48  delete m;
49  _materials.clear();
50 
51  // delete textures
52  for (auto t : _textures)
53  delete t;
54  _textures.clear();
55 
56  // delete meshes
57  for (auto m : _meshes)
58  delete m;
59  _meshes.clear();
60 
61  // delete shader programs
62  for (auto p : _programs)
63  delete p;
64  _programs.clear();
65 }
SLVGLTexture _textures
Vector of all texture pointers.
SLVMaterial _materials
Vector of all materials pointers.
SLVGLProgram _programs
Vector of all shader program pointers.
SLVMesh _meshes
Vector of all meshes.

◆ deleteDataGpu()

void SLAssetManager::deleteDataGpu ( )

for all assets, clear gpu data

Definition at line 68 of file SLAssetManager.cpp.

69 {
70  /*
71  SLGLState* stateGL = SLGLState::instance();
72 
73  // check if current
74  for (auto m : _materials)
75  {
76  if (stateGL->currentMaterial() == m)
77  stateGL->currentMaterial(nullptr);
78  }
79  */
80 
81  // delete textures
82  for (auto t : _textures)
83  t->deleteDataGpu();
84 
85  // delete meshes
86  for (auto m : _meshes)
87  m->deleteDataGpu();
88 
89  // delete shader programs
90  for (auto p : _programs)
91  ; // p->deleteDataGpu();
92 }

◆ deleteFonts()

void SLAssetManager::deleteFonts ( )
static

Deletes all static fonts.

Definition at line 180 of file SLAssetManager.cpp.

181 {
182  delete font07;
183  font07 = nullptr;
184  delete font08;
185  font08 = nullptr;
186  delete font09;
187  font09 = nullptr;
188  delete font10;
189  font10 = nullptr;
190  delete font12;
191  font12 = nullptr;
192  delete font14;
193  font14 = nullptr;
194  delete font16;
195  font16 = nullptr;
196  delete font18;
197  font18 = nullptr;
198  delete font20;
199  font20 = nullptr;
200  delete font22;
201  font22 = nullptr;
202  delete font24;
203  font24 = nullptr;
204 }
static SLTexFont * font24
24 pixel high fixed size font
static SLTexFont * font10
10 pixel high fixed size font
static SLTexFont * font20
20 pixel high fixed size font
static SLTexFont * font09
9 pixel high fixed size font
static SLTexFont * font22
22 pixel high fixed size font
static SLTexFont * font14
14 pixel high fixed size font
static SLTexFont * font07
7 pixel high fixed size font
static SLTexFont * font08
8 pixel high fixed size font
static SLTexFont * font18
18 pixel high fixed size font
static SLTexFont * font12
12 pixel high fixed size font
static SLTexFont * font16
16 pixel high fixed size font

◆ generateFonts()

void SLAssetManager::generateFonts ( SLstring  fontPath,
SLGLProgram fontTexProgram 
)
static

Generates all static fonts.

Definition at line 153 of file SLAssetManager.cpp.

154 {
155  font07 = new SLTexFont(fontPath + "Font07.png", &fontTexProgram);
156  assert(font07);
157  font08 = new SLTexFont(fontPath + "Font08.png", &fontTexProgram);
158  assert(font08);
159  font09 = new SLTexFont(fontPath + "Font09.png", &fontTexProgram);
160  assert(font09);
161  font10 = new SLTexFont(fontPath + "Font10.png", &fontTexProgram);
162  assert(font10);
163  font12 = new SLTexFont(fontPath + "Font12.png", &fontTexProgram);
164  assert(font12);
165  font14 = new SLTexFont(fontPath + "Font14.png", &fontTexProgram);
166  assert(font14);
167  font16 = new SLTexFont(fontPath + "Font16.png", &fontTexProgram);
168  assert(font16);
169  font18 = new SLTexFont(fontPath + "Font18.png", &fontTexProgram);
170  assert(font18);
171  font20 = new SLTexFont(fontPath + "Font20.png", &fontTexProgram);
172  assert(font20);
173  font22 = new SLTexFont(fontPath + "Font22.png", &fontTexProgram);
174  assert(font22);
175  font24 = new SLTexFont(fontPath + "Font24.png", &fontTexProgram);
176  assert(font24);
177 }
Texture Font class inherits SLGLTexture for alpha blended font rendering.
Definition: SLTexFont.h:40

◆ generateStaticFonts()

void SLAssetManager::generateStaticFonts ( SLstring  fontPath)

Definition at line 36 of file SLAssetManager.cpp.

37 {
38  // font and video texture are not added to the _textures vector
41 }
@ SP_fontTex
static void generateFonts(SLstring fontPath, SLGLProgram &fontTexProgram)
Generates all static fonts.
static SLGLProgramGeneric * get(SLStdShaderProg id)
Get program reference for given id.

◆ getFont()

SLTexFont * SLAssetManager::getFont ( SLfloat  heightMM,
SLint  dpi 
)
static

returns nearest font for a given height in mm

Definition at line 207 of file SLAssetManager.cpp.

208 {
209  SLfloat dpmm = (SLfloat)dpi / 25.4f;
210  SLfloat targetH_PX = dpmm * heightMM;
211 
212  if (targetH_PX < 7) return font07;
213  if (targetH_PX < 8) return font08;
214  if (targetH_PX < 9) return font09;
215  if (targetH_PX < 10) return font10;
216  if (targetH_PX < 12) return font12;
217  if (targetH_PX < 14) return font14;
218  if (targetH_PX < 16) return font16;
219  if (targetH_PX < 18) return font18;
220  if (targetH_PX < 20) return font20;
221  if (targetH_PX < 24) return font22;
222  return font24;
223 }
static SLint dpi
Dot per inch resolution of screen.
Definition: AppGLFW.cpp:41
float SLfloat
Definition: SL.h:173

◆ getProgramByName()

SLGLProgram * SLAssetManager::getProgramByName ( const string &  programName)

Returns the pointer to shader program if found by name.

Definition at line 125 of file SLAssetManager.cpp.

126 {
127  for (auto sp : _programs)
128  if (sp->name() == programName)
129  return sp;
130  return nullptr;
131 }

◆ materials()

SLVMaterial& SLAssetManager::materials ( )
inline

Definition at line 58 of file SLAssetManager.h.

58 { return _materials; }

◆ merge()

void SLAssetManager::merge ( SLAssetManager other)

merge other asset manager into this

Definition at line 135 of file SLAssetManager.cpp.

136 {
137  // update the assetmanager pointer for automatic program assignment
138  for (SLMaterial* m : other.materials())
139  m->assetManager(this);
140  // transfer assets from other to this
141  _meshes.insert(_meshes.end(), other.meshes().begin(), other.meshes().end());
142  _materials.insert(_materials.end(), other.materials().begin(), other.materials().end());
143  _textures.insert(_textures.end(), other.textures().begin(), other.textures().end());
144  _programs.insert(_programs.end(), other.programs().begin(), other.programs().end());
145  // clear ownership of other
146  other.meshes().clear();
147  other.materials().clear();
148  other.textures().clear();
149  other.programs().clear();
150 }
SLVMesh & meshes()
SLVGLProgram & programs()
SLVMaterial & materials()
SLVGLTexture & textures()
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56

◆ meshes()

SLVMesh& SLAssetManager::meshes ( )
inline

Definition at line 57 of file SLAssetManager.h.

57 { return _meshes; }

◆ programs()

SLVGLProgram& SLAssetManager::programs ( )
inline

Definition at line 60 of file SLAssetManager.h.

60 { return _programs; }

◆ removeMesh()

bool SLAssetManager::removeMesh ( SLMesh mesh)

Removes the specified mesh from the meshes resource vector.

Definition at line 95 of file SLAssetManager.cpp.

96 {
97  assert(mesh);
98  for (SLulong i = 0; i < _meshes.size(); ++i)
99  {
100  if (_meshes[i] == mesh)
101  {
102  _meshes.erase(_meshes.begin() + i);
103  return true;
104  }
105  }
106  return false;
107 }
unsigned long SLulong
Definition: SL.h:165

◆ removeProgram()

bool SLAssetManager::removeProgram ( SLGLProgram program)

Removes the specified mesh from the meshes resource vector.

Removes the specified program from the meshes resource vector.

Definition at line 110 of file SLAssetManager.cpp.

111 {
112  assert(program);
113  for (SLulong i = 0; i < _programs.size(); ++i)
114  {
115  if (_programs[i] == program)
116  {
117  _programs.erase(_programs.begin() + i);
118  return true;
119  }
120  }
121  return false;
122 }

◆ textures()

SLVGLTexture& SLAssetManager::textures ( )
inline

Definition at line 59 of file SLAssetManager.h.

59 { return _textures; }

Member Data Documentation

◆ _materials

SLVMaterial SLAssetManager::_materials
protected

Vector of all materials pointers.

Definition at line 83 of file SLAssetManager.h.

◆ _meshes

SLVMesh SLAssetManager::_meshes
protected

Vector of all meshes.

Definition at line 82 of file SLAssetManager.h.

◆ _programs

SLVGLProgram SLAssetManager::_programs
protected

Vector of all shader program pointers.

Definition at line 85 of file SLAssetManager.h.

◆ _textures

SLVGLTexture SLAssetManager::_textures
protected

Vector of all texture pointers.

Definition at line 84 of file SLAssetManager.h.

◆ font07

SLTexFont * SLAssetManager::font07 = nullptr
static

7 pixel high fixed size font

Definition at line 69 of file SLAssetManager.h.

◆ font08

SLTexFont * SLAssetManager::font08 = nullptr
static

8 pixel high fixed size font

Definition at line 70 of file SLAssetManager.h.

◆ font09

SLTexFont * SLAssetManager::font09 = nullptr
static

9 pixel high fixed size font

Definition at line 71 of file SLAssetManager.h.

◆ font10

SLTexFont * SLAssetManager::font10 = nullptr
static

10 pixel high fixed size font

Definition at line 72 of file SLAssetManager.h.

◆ font12

SLTexFont * SLAssetManager::font12 = nullptr
static

12 pixel high fixed size font

Definition at line 73 of file SLAssetManager.h.

◆ font14

SLTexFont * SLAssetManager::font14 = nullptr
static

14 pixel high fixed size font

Definition at line 74 of file SLAssetManager.h.

◆ font16

SLTexFont * SLAssetManager::font16 = nullptr
static

16 pixel high fixed size font

Definition at line 75 of file SLAssetManager.h.

◆ font18

SLTexFont * SLAssetManager::font18 = nullptr
static

18 pixel high fixed size font

Definition at line 76 of file SLAssetManager.h.

◆ font20

SLTexFont * SLAssetManager::font20 = nullptr
static

20 pixel high fixed size font

Definition at line 77 of file SLAssetManager.h.

◆ font22

SLTexFont * SLAssetManager::font22 = nullptr
static

22 pixel high fixed size font

Definition at line 78 of file SLAssetManager.h.

◆ font24

SLTexFont * SLAssetManager::font24 = nullptr
static

24 pixel high fixed size font

Definition at line 79 of file SLAssetManager.h.


The documentation for this class was generated from the following files: