source: trunk/BUTE/Ogre/OgreEffectWrapper.cpp @ 124

Revision 124, 12.7 KB checked in by barsi, 19 years ago (diff)

Added a folder remotely

Line 
1#include "Ogre.h"
2#include "OgreEffectWrapper.h"
3
4
5EffectWrapper::EffectWrapper(){
6        numberOfCurrentTechnique=-1;
7        numberOfCurrentPass=-1;
8        fragmentProgramParams=false;
9        vertexProgramParams=false;
10        shadowCasterParams=false;
11        shadowReceiverParams=false;
12        canSetNewTechnique=true;
13        this->material.setNull();
14}
15
16EffectWrapper::EffectWrapper(Material* material){
17        numberOfCurrentTechnique=-1;
18        numberOfCurrentPass=-1;
19        fragmentProgramParams=false;
20        vertexProgramParams=false;
21        shadowCasterParams=false;
22        shadowReceiverParams=false;
23        canSetNewTechnique=true;
24        this->material.bind(material);
25}
26
27
28
29EffectWrapper::~EffectWrapper(){
30
31}
32
33//D3D Effect framework style.
34
35bool EffectWrapper::SetFloat(const String& name, float value){
36        if(validateSet()){
37                return false;
38        }
39        if(vertexProgramParams){
40                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value);
41        }
42        if(fragmentProgramParams){
43                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value);
44        }
45        if(shadowCasterParams){
46                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value);
47        }
48        if(shadowReceiverParams){
49                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value);
50        }
51        return true;
52}
53
54bool EffectWrapper::SetFloatArray(const String& name,const float* value, size_t count){
55        if(validateSet()){
56                return false;
57        }
58        if(vertexProgramParams){
59                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value,count);
60        }
61        if(fragmentProgramParams){
62                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value,count);
63        }
64        if(shadowCasterParams){
65                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value,count);
66        }
67        if(shadowReceiverParams){
68                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value,count);
69        }
70        return true;
71}
72
73bool EffectWrapper::SetInt(const String& name, int value){
74        if(validateSet()){
75                return false;
76        }
77        if(vertexProgramParams){
78                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value);
79        }
80        if(fragmentProgramParams){
81                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value);
82        }
83        if(shadowCasterParams){
84                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value);
85        }
86        if(shadowReceiverParams){
87                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value);
88        }
89        return true;
90}
91
92bool EffectWrapper::SetIntArray(const String& name,const int* value, size_t count){
93        if(validateSet()){
94                return false;
95        }
96        if(vertexProgramParams){
97                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value,count);
98        }
99        if(fragmentProgramParams){
100                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value,count);
101        }
102        if(shadowCasterParams){
103                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value,count);
104        }
105        if(shadowReceiverParams){
106                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value,count);
107        }
108        return true;
109}
110
111bool EffectWrapper::SetDoubleArray(const String& name, double* value, size_t count){
112        if(validateSet()){
113                return false;
114        }
115        if(vertexProgramParams){
116                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value,count);
117        }
118        if(fragmentProgramParams){
119                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value,count);
120        }
121        if(shadowCasterParams){
122                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value,count);
123        }
124        if(shadowReceiverParams){
125                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value,count);
126        }
127        return true;
128}
129
130bool EffectWrapper::SetMatrix(const String& name, Matrix4& value){
131        if(validateSet()){
132                return false;
133        }
134        if(vertexProgramParams){
135                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value);
136        }
137        if(fragmentProgramParams){
138                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value);
139        }
140        if(shadowCasterParams){
141                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value);
142        }
143        if(shadowReceiverParams){
144                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value);
145        }
146        return true;
147}
148
149bool EffectWrapper::SetMatrixArray(const String& name, Matrix4* value, size_t numEntries){
150        if(validateSet()){
151                return false;
152        }
153        if(vertexProgramParams){
154                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value,numEntries);
155        }
156        if(fragmentProgramParams){
157                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value,numEntries);
158        }
159        if(shadowCasterParams){
160                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value,numEntries);
161        }
162        if(shadowReceiverParams){
163                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value,numEntries);
164        }
165        return true;
166}
167
168bool EffectWrapper::SetMatrixTranspose(const String& name, Matrix4& value){
169        if(validateSet()){
170                return false;
171        }
172        Matrix4 transposeValue=value;
173        transposeValue.transpose();
174        if(vertexProgramParams){
175                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,transposeValue);
176        }
177        if(fragmentProgramParams){
178                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,transposeValue);
179        }
180        if(shadowCasterParams){
181                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,transposeValue);
182        }
183        if(shadowReceiverParams){
184                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,transposeValue);
185        }
186        return true;
187}
188
189bool EffectWrapper::SetMatrixTransposeArray(const String& name, Matrix4* value, size_t numEntries){
190        if(validateSet()){
191                return false;
192        }
193        Matrix4* transposeValues=new Matrix4[numEntries];
194        for(unsigned int i=0;i<numEntries;i++){
195                transposeValues[i]=value[i];
196                transposeValues[i].transpose();
197        }
198        if(vertexProgramParams){
199                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,transposeValues,numEntries);
200        }
201        if(fragmentProgramParams){
202                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,transposeValues,numEntries);
203        }
204        if(shadowCasterParams){
205                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,transposeValues,numEntries);
206        }
207        if(shadowReceiverParams){
208                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,transposeValues,numEntries);
209        }
210        delete[] transposeValues;
211        return true;
212}
213
214bool EffectWrapper::SetTexture(int textureUnit,const String& textureName){
215        material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->createTextureUnitState()->setTextureName(textureName);
216        return(true);
217}
218
219//Ogre style.
220
221bool EffectWrapper::SetVector4(const String& name,const Vector4 &vec){
222        if(validateSet()){
223                return false;
224        }
225        if(vertexProgramParams){
226                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,vec);
227        }
228        if(fragmentProgramParams){
229                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,vec);
230        }
231        if(shadowCasterParams){
232                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,vec);
233        }
234        if(shadowReceiverParams){
235                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,vec);
236        }
237        return true;
238}
239
240bool EffectWrapper::SetVector3(const String& name,const Vector3 &vec){
241        if(validateSet()){
242                return false;
243        }
244        if(vertexProgramParams){
245                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,vec);
246        }
247        if(fragmentProgramParams){
248                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,vec);
249        }
250        if(shadowCasterParams){
251                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,vec);
252        }
253        if(shadowReceiverParams){
254                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,vec);
255        }
256        return(true);
257}
258
259bool EffectWrapper::SetReal(const String& name, Real value){
260        if(validateSet()){
261                return false;
262        }
263        if(vertexProgramParams){
264                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,value);
265        }
266        if(fragmentProgramParams){
267                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,value);
268        }
269        if(shadowCasterParams){
270                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,value);
271        }
272        if(shadowReceiverParams){
273                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,value);
274        }
275        return(true);
276}
277
278bool EffectWrapper::SetColourValue(const String& name, const ColourValue &colour){
279        if(validateSet()){
280                return false;
281        }
282        if(vertexProgramParams){
283                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getVertexProgramParameters()->setNamedConstant(name,colour);
284        }
285        if(fragmentProgramParams){
286                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getFragmentProgramParameters()->setNamedConstant(name,colour);
287        }
288        if(shadowCasterParams){
289                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowCasterVertexProgramParameters()->setNamedConstant(name,colour);
290        }
291        if(shadowReceiverParams){
292                material->getTechnique(numberOfCurrentTechnique)->getPass(numberOfCurrentPass)->getShadowReceiverVertexProgramParameters()->setNamedConstant(name,colour);
293        }
294        return(true);
295}
296
297bool EffectWrapper::SetTechniqueToUse(int numberOfTechnique){
298        if(canSetNewTechnique){
299                if(GetNumTechniques()>numberOfTechnique){
300                        this->numberOfCurrentTechnique=numberOfTechnique;
301                        return true;
302                }
303                else{
304                        return false;
305                }
306        }
307        return false;
308}
309
310MaterialPtr& EffectWrapper::getMaterial(){
311        return material;
312}
Note: See TracBrowser for help on using the repository browser.