aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CCgMaterialRenderer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CCgMaterialRenderer.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CCgMaterialRenderer.cpp722
1 files changed, 361 insertions, 361 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CCgMaterialRenderer.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CCgMaterialRenderer.cpp
index a5e4937..f307d57 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CCgMaterialRenderer.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CCgMaterialRenderer.cpp
@@ -1,361 +1,361 @@
1// Copyright (C) 2012 Patryk Nadrowski 1// Copyright (C) 2012 Patryk Nadrowski
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "IrrCompileConfig.h" 5#include "IrrCompileConfig.h"
6#ifdef _IRR_COMPILE_WITH_CG_ 6#ifdef _IRR_COMPILE_WITH_CG_
7 7
8#include "CCgMaterialRenderer.h" 8#include "CCgMaterialRenderer.h"
9 9
10namespace irr 10namespace irr
11{ 11{
12namespace video 12namespace video
13{ 13{
14 14
15CCgUniform::CCgUniform(const CGparameter& parameter, bool global) : Parameter(parameter), Type(CG_UNKNOWN_TYPE) 15CCgUniform::CCgUniform(const CGparameter& parameter, bool global) : Parameter(parameter), Type(CG_UNKNOWN_TYPE)
16{ 16{
17 Name = cgGetParameterName(Parameter); 17 Name = cgGetParameterName(Parameter);
18 18
19 if(global) 19 if(global)
20 Space = CG_GLOBAL; 20 Space = CG_GLOBAL;
21 else 21 else
22 Space = CG_PROGRAM; 22 Space = CG_PROGRAM;
23} 23}
24 24
25const core::stringc& CCgUniform::getName() const 25const core::stringc& CCgUniform::getName() const
26{ 26{
27 return Name; 27 return Name;
28} 28}
29 29
30const CGparameter& CCgUniform::getParameter() const 30const CGparameter& CCgUniform::getParameter() const
31{ 31{
32 return Parameter; 32 return Parameter;
33} 33}
34 34
35CGenum CCgUniform::getSpace() const 35CGenum CCgUniform::getSpace() const
36{ 36{
37 return Space; 37 return Space;
38} 38}
39 39
40CGtype CCgUniform::getType() const 40CGtype CCgUniform::getType() const
41{ 41{
42 return Type; 42 return Type;
43} 43}
44 44
45CCgUniform1f::CCgUniform1f(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) 45CCgUniform1f::CCgUniform1f(const CGparameter& parameter, bool global) : CCgUniform(parameter, global)
46{ 46{
47 Type = CG_FLOAT; 47 Type = CG_FLOAT;
48} 48}
49 49
50void CCgUniform1f::update(const void* data, const SMaterial& material) const 50void CCgUniform1f::update(const void* data, const SMaterial& material) const
51{ 51{
52 f32* Data = (f32*)data; 52 f32* Data = (f32*)data;
53 cgSetParameter1f(Parameter, *Data); 53 cgSetParameter1f(Parameter, *Data);
54} 54}
55 55
56CCgUniform2f::CCgUniform2f(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) 56CCgUniform2f::CCgUniform2f(const CGparameter& parameter, bool global) : CCgUniform(parameter, global)
57{ 57{
58 Type = CG_FLOAT2; 58 Type = CG_FLOAT2;
59} 59}
60 60
61void CCgUniform2f::update(const void* data, const SMaterial& material) const 61void CCgUniform2f::update(const void* data, const SMaterial& material) const
62{ 62{
63 f32* Data = (f32*)data; 63 f32* Data = (f32*)data;
64 cgSetParameter2f(Parameter, *Data, *(Data+1)); 64 cgSetParameter2f(Parameter, *Data, *(Data+1));
65} 65}
66 66
67CCgUniform3f::CCgUniform3f(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) 67CCgUniform3f::CCgUniform3f(const CGparameter& parameter, bool global) : CCgUniform(parameter, global)
68{ 68{
69 Type = CG_FLOAT3; 69 Type = CG_FLOAT3;
70} 70}
71 71
72void CCgUniform3f::update(const void* data, const SMaterial& material) const 72void CCgUniform3f::update(const void* data, const SMaterial& material) const
73{ 73{
74 f32* Data = (f32*)data; 74 f32* Data = (f32*)data;
75 cgSetParameter3f(Parameter, *Data, *(Data+1), *(Data+2)); 75 cgSetParameter3f(Parameter, *Data, *(Data+1), *(Data+2));
76} 76}
77 77
78CCgUniform4f::CCgUniform4f(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) 78CCgUniform4f::CCgUniform4f(const CGparameter& parameter, bool global) : CCgUniform(parameter, global)
79{ 79{
80 Type = CG_FLOAT4; 80 Type = CG_FLOAT4;
81} 81}
82 82
83void CCgUniform4f::update(const void* data, const SMaterial& material) const 83void CCgUniform4f::update(const void* data, const SMaterial& material) const
84{ 84{
85 f32* Data = (f32*)data; 85 f32* Data = (f32*)data;
86 cgSetParameter4f(Parameter, *Data, *(Data+1), *(Data+2), *(Data+3)); 86 cgSetParameter4f(Parameter, *Data, *(Data+1), *(Data+2), *(Data+3));
87} 87}
88 88
89CCgUniform1i::CCgUniform1i(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) 89CCgUniform1i::CCgUniform1i(const CGparameter& parameter, bool global) : CCgUniform(parameter, global)
90{ 90{
91 Type = CG_INT; 91 Type = CG_INT;
92} 92}
93 93
94void CCgUniform1i::update(const void* data, const SMaterial& material) const 94void CCgUniform1i::update(const void* data, const SMaterial& material) const
95{ 95{
96 s32* Data = (s32*)data; 96 s32* Data = (s32*)data;
97 cgSetParameter1i(Parameter, *Data); 97 cgSetParameter1i(Parameter, *Data);
98} 98}
99 99
100CCgUniform2i::CCgUniform2i(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) 100CCgUniform2i::CCgUniform2i(const CGparameter& parameter, bool global) : CCgUniform(parameter, global)
101{ 101{
102 Type = CG_INT2; 102 Type = CG_INT2;
103} 103}
104 104
105void CCgUniform2i::update(const void* data, const SMaterial& material) const 105void CCgUniform2i::update(const void* data, const SMaterial& material) const
106{ 106{
107 s32* Data = (s32*)data; 107 s32* Data = (s32*)data;
108 cgSetParameter2i(Parameter, *Data, *(Data+1)); 108 cgSetParameter2i(Parameter, *Data, *(Data+1));
109} 109}
110 110
111CCgUniform3i::CCgUniform3i(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) 111CCgUniform3i::CCgUniform3i(const CGparameter& parameter, bool global) : CCgUniform(parameter, global)
112{ 112{
113 Type = CG_INT3; 113 Type = CG_INT3;
114} 114}
115 115
116void CCgUniform3i::update(const void* data, const SMaterial& material) const 116void CCgUniform3i::update(const void* data, const SMaterial& material) const
117{ 117{
118 s32* Data = (s32*)data; 118 s32* Data = (s32*)data;
119 cgSetParameter3i(Parameter, *Data, *(Data+1), *(Data+2)); 119 cgSetParameter3i(Parameter, *Data, *(Data+1), *(Data+2));
120} 120}
121 121
122CCgUniform4i::CCgUniform4i(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) 122CCgUniform4i::CCgUniform4i(const CGparameter& parameter, bool global) : CCgUniform(parameter, global)
123{ 123{
124 Type = CG_INT4; 124 Type = CG_INT4;
125} 125}
126 126
127void CCgUniform4i::update(const void* data, const SMaterial& material) const 127void CCgUniform4i::update(const void* data, const SMaterial& material) const
128{ 128{
129 s32* Data = (s32*)data; 129 s32* Data = (s32*)data;
130 cgSetParameter4i(Parameter, *Data, *(Data+1), *(Data+2), *(Data+3)); 130 cgSetParameter4i(Parameter, *Data, *(Data+1), *(Data+2), *(Data+3));
131} 131}
132 132
133CCgUniform4x4f::CCgUniform4x4f(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) 133CCgUniform4x4f::CCgUniform4x4f(const CGparameter& parameter, bool global) : CCgUniform(parameter, global)
134{ 134{
135 Type = CG_FLOAT4x4; 135 Type = CG_FLOAT4x4;
136} 136}
137 137
138void CCgUniform4x4f::update(const void* data, const SMaterial& material) const 138void CCgUniform4x4f::update(const void* data, const SMaterial& material) const
139{ 139{
140 f32* Data = (f32*)data; 140 f32* Data = (f32*)data;
141 cgSetMatrixParameterfr(Parameter, Data); 141 cgSetMatrixParameterfr(Parameter, Data);
142} 142}
143 143
144CCgUniformSampler2D::CCgUniformSampler2D(const CGparameter& parameter, bool global) : CCgUniform(parameter, global) 144CCgUniformSampler2D::CCgUniformSampler2D(const CGparameter& parameter, bool global) : CCgUniform(parameter, global)
145{ 145{
146 Type = CG_SAMPLER2D; 146 Type = CG_SAMPLER2D;
147} 147}
148 148
149void CCgUniformSampler2D::update(const void* data, const SMaterial& material) const 149void CCgUniformSampler2D::update(const void* data, const SMaterial& material) const
150{ 150{
151} 151}
152 152
153CCgMaterialRenderer::CCgMaterialRenderer(IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData) : 153CCgMaterialRenderer::CCgMaterialRenderer(IShaderConstantSetCallBack* callback, IMaterialRenderer* baseMaterial, s32 userData) :
154 CallBack(callback), BaseMaterial(baseMaterial), UserData(userData), 154 CallBack(callback), BaseMaterial(baseMaterial), UserData(userData),
155 VertexProgram(0), FragmentProgram(0), GeometryProgram(0), VertexProfile(CG_PROFILE_UNKNOWN), FragmentProfile(CG_PROFILE_UNKNOWN), GeometryProfile(CG_PROFILE_UNKNOWN), 155 VertexProgram(0), FragmentProgram(0), GeometryProgram(0), VertexProfile(CG_PROFILE_UNKNOWN), FragmentProfile(CG_PROFILE_UNKNOWN), GeometryProfile(CG_PROFILE_UNKNOWN),
156 Material(IdentityMaterial), Error(CG_NO_ERROR) 156 Material(IdentityMaterial), Error(CG_NO_ERROR)
157{ 157{
158 #ifdef _DEBUG 158 #ifdef _DEBUG
159 setDebugName("CCgMaterialRenderer"); 159 setDebugName("CCgMaterialRenderer");
160 #endif 160 #endif
161 161
162 if(BaseMaterial) 162 if(BaseMaterial)
163 BaseMaterial->grab(); 163 BaseMaterial->grab();
164 164
165 if(CallBack) 165 if(CallBack)
166 CallBack->grab(); 166 CallBack->grab();
167} 167}
168 168
169CCgMaterialRenderer::~CCgMaterialRenderer() 169CCgMaterialRenderer::~CCgMaterialRenderer()
170{ 170{
171 if(CallBack) 171 if(CallBack)
172 CallBack->drop(); 172 CallBack->drop();
173 173
174 if(BaseMaterial) 174 if(BaseMaterial)
175 BaseMaterial->drop(); 175 BaseMaterial->drop();
176 176
177 for(unsigned int i = 0; i < UniformInfo.size(); ++i) 177 for(unsigned int i = 0; i < UniformInfo.size(); ++i)
178 delete UniformInfo[i]; 178 delete UniformInfo[i];
179 179
180 UniformInfo.clear(); 180 UniformInfo.clear();
181} 181}
182 182
183bool CCgMaterialRenderer::isTransparent() const 183bool CCgMaterialRenderer::isTransparent() const
184{ 184{
185 return BaseMaterial ? BaseMaterial->isTransparent() : false; 185 return BaseMaterial ? BaseMaterial->isTransparent() : false;
186} 186}
187 187
188void CCgMaterialRenderer::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) 188void CCgMaterialRenderer::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
189{ 189{
190 os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING); 190 os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING);
191} 191}
192 192
193bool CCgMaterialRenderer::setVertexShaderConstant(const c8* name, const f32* floats, int count) 193bool CCgMaterialRenderer::setVertexShaderConstant(const c8* name, const f32* floats, int count)
194{ 194{
195 return setPixelShaderConstant(name, floats, count); 195 return setPixelShaderConstant(name, floats, count);
196} 196}
197 197
198bool CCgMaterialRenderer::setVertexShaderConstant(const c8* name, const bool* bools, int count) 198bool CCgMaterialRenderer::setVertexShaderConstant(const c8* name, const bool* bools, int count)
199{ 199{
200 return setPixelShaderConstant(name, bools, count); 200 return setPixelShaderConstant(name, bools, count);
201} 201}
202 202
203bool CCgMaterialRenderer::setVertexShaderConstant(const c8* name, const s32* ints, int count) 203bool CCgMaterialRenderer::setVertexShaderConstant(const c8* name, const s32* ints, int count)
204{ 204{
205 return setPixelShaderConstant(name, ints, count); 205 return setPixelShaderConstant(name, ints, count);
206} 206}
207 207
208void CCgMaterialRenderer::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount) 208void CCgMaterialRenderer::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
209{ 209{
210 os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING); 210 os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING);
211} 211}
212 212
213bool CCgMaterialRenderer::setPixelShaderConstant(const c8* name, const f32* floats, int count) 213bool CCgMaterialRenderer::setPixelShaderConstant(const c8* name, const f32* floats, int count)
214{ 214{
215 bool Status = false; 215 bool Status = false;
216 216
217 for(unsigned int i = 0; i < UniformInfo.size(); ++i) 217 for(unsigned int i = 0; i < UniformInfo.size(); ++i)
218 { 218 {
219 if(UniformInfo[i]->getName() == name) 219 if(UniformInfo[i]->getName() == name)
220 { 220 {
221 UniformInfo[i]->update(floats, Material); 221 UniformInfo[i]->update(floats, Material);
222 222
223 Status = true; 223 Status = true;
224 } 224 }
225 } 225 }
226 226
227 return Status; 227 return Status;
228} 228}
229 229
230bool CCgMaterialRenderer::setPixelShaderConstant(const c8* name, const s32* ints, int count) 230bool CCgMaterialRenderer::setPixelShaderConstant(const c8* name, const s32* ints, int count)
231{ 231{
232 bool Status = false; 232 bool Status = false;
233 233
234 for(unsigned int i = 0; i < UniformInfo.size(); ++i) 234 for(unsigned int i = 0; i < UniformInfo.size(); ++i)
235 { 235 {
236 if(UniformInfo[i]->getName() == name) 236 if(UniformInfo[i]->getName() == name)
237 { 237 {
238 UniformInfo[i]->update(ints, Material); 238 UniformInfo[i]->update(ints, Material);
239 239
240 Status = true; 240 Status = true;
241 } 241 }
242 } 242 }
243 243
244 return Status; 244 return Status;
245} 245}
246 246
247bool CCgMaterialRenderer::setPixelShaderConstant(const c8* name, const bool* bools, int count) 247bool CCgMaterialRenderer::setPixelShaderConstant(const c8* name, const bool* bools, int count)
248{ 248{
249 bool Status = false; 249 bool Status = false;
250 250
251 for(unsigned int i = 0; i < UniformInfo.size(); ++i) 251 for(unsigned int i = 0; i < UniformInfo.size(); ++i)
252 { 252 {
253 if(UniformInfo[i]->getName() == name) 253 if(UniformInfo[i]->getName() == name)
254 { 254 {
255 UniformInfo[i]->update(bools, Material); 255 UniformInfo[i]->update(bools, Material);
256 256
257 Status = true; 257 Status = true;
258 } 258 }
259 } 259 }
260 260
261 return Status; 261 return Status;
262} 262}
263 263
264void CCgMaterialRenderer::getUniformList() 264void CCgMaterialRenderer::getUniformList()
265{ 265{
266 for(unsigned int i = 0; i < UniformInfo.size(); ++i) 266 for(unsigned int i = 0; i < UniformInfo.size(); ++i)
267 delete UniformInfo[i]; 267 delete UniformInfo[i];
268 268
269 UniformInfo.clear(); 269 UniformInfo.clear();
270 270
271 for(unsigned int i = 0; i < 2; ++i) 271 for(unsigned int i = 0; i < 2; ++i)
272 { 272 {
273 CGenum Space = CG_GLOBAL; 273 CGenum Space = CG_GLOBAL;
274 bool IsGlobal = 1; 274 bool IsGlobal = 1;
275 275
276 if(i == 1) 276 if(i == 1)
277 { 277 {
278 Space = CG_PROGRAM; 278 Space = CG_PROGRAM;
279 IsGlobal = 0; 279 IsGlobal = 0;
280 } 280 }
281 281
282 for(unsigned int j = 0; j < 3; ++j) 282 for(unsigned int j = 0; j < 3; ++j)
283 { 283 {
284 CGprogram* Program = 0; 284 CGprogram* Program = 0;
285 285
286 switch(j) 286 switch(j)
287 { 287 {
288 case 0: 288 case 0:
289 Program = &VertexProgram; 289 Program = &VertexProgram;
290 break; 290 break;
291 case 1: 291 case 1:
292 Program = &FragmentProgram; 292 Program = &FragmentProgram;
293 break; 293 break;
294 case 2: 294 case 2:
295 Program = &GeometryProgram; 295 Program = &GeometryProgram;
296 break; 296 break;
297 } 297 }
298 298
299 if(*Program) 299 if(*Program)
300 { 300 {
301 CGparameter Parameter = cgGetFirstParameter(*Program, Space); 301 CGparameter Parameter = cgGetFirstParameter(*Program, Space);
302 302
303 while(Parameter) 303 while(Parameter)
304 { 304 {
305 if(cgGetParameterVariability(Parameter) == CG_UNIFORM && cgGetParameterDirection(Parameter) == CG_IN) 305 if(cgGetParameterVariability(Parameter) == CG_UNIFORM && cgGetParameterDirection(Parameter) == CG_IN)
306 { 306 {
307 CCgUniform* Uniform = 0; 307 CCgUniform* Uniform = 0;
308 308
309 CGtype Type = cgGetParameterType(Parameter); 309 CGtype Type = cgGetParameterType(Parameter);
310 310
311 switch(Type) 311 switch(Type)
312 { 312 {
313 case CG_FLOAT: 313 case CG_FLOAT:
314 case CG_FLOAT1: 314 case CG_FLOAT1:
315 Uniform = new CCgUniform1f(Parameter, IsGlobal); 315 Uniform = new CCgUniform1f(Parameter, IsGlobal);
316 break; 316 break;
317 case CG_FLOAT2: 317 case CG_FLOAT2:
318 Uniform = new CCgUniform2f(Parameter, IsGlobal); 318 Uniform = new CCgUniform2f(Parameter, IsGlobal);
319 break; 319 break;
320 case CG_FLOAT3: 320 case CG_FLOAT3:
321 Uniform = new CCgUniform3f(Parameter, IsGlobal); 321 Uniform = new CCgUniform3f(Parameter, IsGlobal);
322 break; 322 break;
323 case CG_FLOAT4: 323 case CG_FLOAT4:
324 Uniform = new CCgUniform4f(Parameter, IsGlobal); 324 Uniform = new CCgUniform4f(Parameter, IsGlobal);
325 break; 325 break;
326 case CG_INT: 326 case CG_INT:
327 case CG_INT1: 327 case CG_INT1:
328 Uniform = new CCgUniform1i(Parameter, IsGlobal); 328 Uniform = new CCgUniform1i(Parameter, IsGlobal);
329 break; 329 break;
330 case CG_INT2: 330 case CG_INT2:
331 Uniform = new CCgUniform2i(Parameter, IsGlobal); 331 Uniform = new CCgUniform2i(Parameter, IsGlobal);
332 break; 332 break;
333 case CG_INT3: 333 case CG_INT3:
334 Uniform = new CCgUniform3i(Parameter, IsGlobal); 334 Uniform = new CCgUniform3i(Parameter, IsGlobal);
335 break; 335 break;
336 case CG_INT4: 336 case CG_INT4:
337 Uniform = new CCgUniform4i(Parameter, IsGlobal); 337 Uniform = new CCgUniform4i(Parameter, IsGlobal);
338 break; 338 break;
339 case CG_FLOAT4x4: 339 case CG_FLOAT4x4:
340 Uniform = new CCgUniform4x4f(Parameter, IsGlobal); 340 Uniform = new CCgUniform4x4f(Parameter, IsGlobal);
341 break; 341 break;
342 case CG_SAMPLER2D: 342 case CG_SAMPLER2D:
343 Uniform = new CCgUniformSampler2D(Parameter, IsGlobal); 343 Uniform = new CCgUniformSampler2D(Parameter, IsGlobal);
344 break; 344 break;
345 } 345 }
346 346
347 if(Uniform) 347 if(Uniform)
348 UniformInfo.push_back(Uniform); 348 UniformInfo.push_back(Uniform);
349 } 349 }
350 350
351 Parameter = cgGetNextParameter(Parameter); 351 Parameter = cgGetNextParameter(Parameter);
352 } 352 }
353 } 353 }
354 } 354 }
355 } 355 }
356} 356}
357 357
358} 358}
359} 359}
360 360
361#endif 361#endif