-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShaderDeployer.cpp
More file actions
160 lines (134 loc) · 4.36 KB
/
ShaderDeployer.cpp
File metadata and controls
160 lines (134 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "stdafx.h"
#include "ShaderDeployer.h"
classShaderDeployer * classShaderDeployer::pInstance = new classShaderDeployer();
std::map<std::string, vrShader *> classShaderDeployer::shaderList;
std::map<std::string, int> classShaderDeployer::representationList;
void classShaderDeployer::init()
{
loadAllShader();
}
void classShaderDeployer::loadAllShader(void)
{
loadShader("v_accsnow", VERTEX, "E:\\newstart\\Data_CG\\SnowVertexShader1.cg");
loadShader("f_accsnow", FRAGMENT, "E:\\newstart\\Data_CG\\SnowFragmentShader1.cg");
loadShader("v_sensor_terrain", VERTEX, "E:\\newstart\\Data_CG\\SensorVertexShader1.cg");
loadShader("f_sensor_terrain", FRAGMENT, "E:\\newstart\\Data_CG\\SensorFragmentShader1.cg");
loadShader("v_sensor_model", VERTEX, "E:\\newstart\\Data_CG\\SensorVertexShader3.cg");
loadShader("f_sensor_model", FRAGMENT, "E:\\newstart\\Data_CG\\SensorFragmentShader3.cg");
}
void classShaderDeployer::removeAllShader(void)
{
std::map<std::string, vrShader *>::iterator it = shaderList.begin();
for (;it != shaderList.end(); it++)
{
//cout << (*it).second->getRef() << endl;
(*it).second->unref();
shaderList.erase(it);
}
}
classShaderDeployer::classShaderDeployer(void)
{
}
classShaderDeployer::~classShaderDeployer(void)
{
}
classShaderDeployer* classShaderDeployer::instance(void)
{
return pInstance;
}
void classShaderDeployer::destory(void)
{
delete pInstance;
}
vrShader *classShaderDeployer::loadShader(std::string _name, ShaderType _type, const char *_path)
{
vrShader *__shader = NULL;
vrShaderFactory* __shaderFactory = new vrShaderFactory();
switch(_type)
{
case VERTEX:
__shader = __shaderFactory->read(_path, vrShader::TYPE_VERTEX);
__shader->ref(); //从shaderfactory中出来引用数为0,需要ref
__shader->setHardwareProfile(CG_PROFILE_GP4VP);
break;
case FRAGMENT:
__shader = __shaderFactory->read(_path, vrShader::TYPE_FRAGMENT);
__shader->ref(); //从shaderfactory中出来引用数为0,需要ref
__shader->setHardwareProfile(CG_PROFILE_GP4FP);
break;
default:
std::cout << "classShaderDeployer: addShader(): Unknown shader type!" << std::endl;
break;
}
__shaderFactory->unref();
//std::cout << __shader->getHardwareProfile() << std::endl;
std::map<std::string, vrShader *>::iterator it;
it = shaderList.find(_name);
if (it != shaderList.end())
{
it->second->unref();
shaderList.erase(it);
std::cout << "ShaderDeployer:" << _name << " already exists and will be replaced! " << std::endl;
}
shaderList[_name] = __shader;
return __shader;
}
void classShaderDeployer::removeShader(std::string _name)
{
std::map<std::string, vrShader *>::iterator it;
it = shaderList.find(_name);
if (it != shaderList.end())
{
it->second->unref();
shaderList.erase(it);
return;
}
std::cout << "ShaderDeployer:" << _name << " doesn't exist! Fail to delete it!" << std::endl;
}
vrShader *classShaderDeployer::getShader(std::string _name)
{
std::map<std::string, vrShader *>::iterator it;
it = shaderList.find(_name);
if (it != shaderList.end())
return it->second;
std::cout << "ShaderDeployer:" << _name << " doesn't exist! Fail to get it!" << std::endl;
return NULL;
}
void classShaderDeployer::addRepresentation(std::string _name)
{
std::map<std::string, int>::iterator it;
it = representationList.find(_name);
if (it != representationList.end())
{
std::cout << "ShaderDeployer:" << _name << " already exists! " << std::endl;
}
else
{
int __representation = 0;
if(vsChannel::registerRepresentation(_name.c_str()) == vsgu::FAILURE)
std::cout << "ShaderDeployer:" <<_name << ": registerRepresentation() failed! " << std::endl;
__representation = vsChannel::getRepresentationIndex(_name.c_str());
representationList[_name] = __representation;
}
}
void classShaderDeployer::removeRepresentation(std::string _name)
{
std::map<std::string, int>::iterator it;
it = representationList.find(_name);
if (it != representationList.end())
{
vsChannel::unregisterRepresentation(_name.c_str());
representationList.erase(it);
return;
}
std::cout << "ShaderDeployer:" << _name << " doesn't exist! Fail to delete it!" << std::endl;
}
int classShaderDeployer::getRepresentation(std::string _name)
{
std::map<std::string, int>::iterator it;
it = representationList.find(_name);
if (it != representationList.end())
return it->second;
std::cout << "ShaderDeployer:" << _name << " doesn't exist! Fail to get it!" << std::endl;
return 0;
}