Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/graphics/importer/resource_texture.cc @ 9854

Last change on this file since 9854 was 9854, checked in by bensch, 18 years ago

more nice comments, and also updated the KeepLevel loading (if you want to load a Resource to a KeepLevel just append it at loadtime:
eg.:
Texture tex = ResourceTexture(orxonox.png, GL_TEXTURE_2D, GameEnd);
where GameEnd is the KeepLevel as defined in orxonox.cc→initResources()

File size: 1.6 KB
Line 
1
2#include "resource_texture.h"
3#include "substring.h"
4#include "multi_type.h"
5#include "debug.h"
6
7
8ResourceTexture::ResourceTexture(const std::string& imageName, GLenum target, const Resources::KeepLevel& keepLevel)
9    : Resource(&ResourceTexture::type)
10{
11  Resources::StorePointer* ptr = this->acquireResource(imageName + ',' + MultiType((int)target).getString());
12
13  if (ptr)
14  {
15    PRINTF(5)("FOUND TEXTURE: %s\n", imageName.c_str());
16    this->acquireData(static_cast<ResourceTexture::TextureResourcePointer*>(ptr)->ptr());
17  }
18  else
19  {
20    PRINTF(5)("NOT FOUND TEXTURE: %s\n", imageName.c_str());
21    std::string fileName = this->Resource::locateFile(imageName);
22    this->Texture::loadImage(fileName, target);
23    this->Resource::addResource(new ResourceTexture::TextureResourcePointer(imageName + ',' + MultiType((int)target).getString(), keepLevel, this->Texture::dataPointer()));
24  }
25}
26
27ResourceTexture ResourceTexture::createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel)
28{
29  SubString loadValues(loadString, ',');
30  std::string imageName;
31  GLenum target = GL_TEXTURE_2D;
32  if (loadValues.size() > 0)
33    imageName = loadValues[0];
34  if (loadValues.size() > 1)
35    target = (GLenum)MultiType(loadValues[2]).getInt();
36
37  return ResourceTexture(imageName, target, keepLevel);
38}
39
40
41
42Resources::tType<ResourceTexture> ResourceTexture::type("Texture");
43
44
45
46
47
48ResourceTexture::TextureResourcePointer::TextureResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const TextureData::Pointer& data)
49    : Resources::StorePointer(loadString, keepLevel) , pointer(data)
50{}
51
52
Note: See TracBrowser for help on using the repository browser.