Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/resource_shader.cc @ 10041

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 1.8 KB
Line 
1
2#include "resource_shader.h"
3#include "debug.h"
4#include "substring.h"
5
6ResourceShader::ResourceShader(const std::string& vertexShaderName, const std::string& fragmentShaderName, const Resources::KeepLevel& keepLevel)
7    : Resource(&ResourceShader::type)
8{
9  Resources::StorePointer* ptr = this->acquireResource(vertexShaderName +','+fragmentShaderName);
10
11  if (ptr)
12  {
13    PRINTF(5)("FOUND SHADER: %s\n", vertexShaderName.c_str());
14    this->acquireData(static_cast<ResourceShader::ShaderResourcePointer*>(ptr)->ptr());
15  }
16  else
17  {
18    PRINTF(5)("NOT FOUND SHADER: %s\n", vertexShaderName.c_str());
19    std::string vertexFileName = this->Resource::locateFile(vertexShaderName);
20    std::string fragmentFileName;
21    if (!fragmentShaderName.empty())
22      fragmentFileName = this->Resource::locateFile(fragmentShaderName);
23
24    this->Shader::load(vertexFileName, fragmentFileName);
25    this->Resource::addResource(new ResourceShader::ShaderResourcePointer(vertexShaderName+','+fragmentShaderName, keepLevel, this->Shader::dataPointer()));
26  }
27}
28
29ResourceShader ResourceShader::createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel)
30{
31  std::string vertexShaderName;
32  std::string fragmentShaderName;
33
34  SubString shaderNames(loadString, ',');
35  if (shaderNames.size() > 0)
36    vertexShaderName = shaderNames[0];
37  if (shaderNames.size() > 1)
38    fragmentShaderName = shaderNames[1];
39
40  return ResourceShader(vertexShaderName, fragmentShaderName, keepLevel);
41}
42
43Resources::tType<ResourceShader> ResourceShader::type("Shader");
44
45ResourceShader::ShaderResourcePointer::ShaderResourcePointer(const std::string& loadString, const Resources::KeepLevel& keepLevel, const ShaderData::Pointer& data)
46    : Resources::StorePointer(loadString, keepLevel) , pointer(data)
47{}
Note: See TracBrowser for help on using the repository browser.