ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/material.h
(Generate patch)

Comparing libgender/material.h (file contents):
Revision 1.7 by root, Thu Oct 21 21:30:34 2004 UTC vs.
Revision 1.8 by root, Thu Oct 21 22:28:42 2004 UTC

29 template<class type> 29 template<class type>
30 struct ref 30 struct ref
31 { 31 {
32 type *p; 32 type *p;
33 33
34 ref ()
35 {
36 p = new type;
37 p->refcnt_inc ();
38 }
39
34 ref (type &d) 40 ref (type &d)
35 { 41 {
36 d.refcnt_inc (); 42 d.refcnt_inc ();
37 p = &d; 43 p = &d;
38 } 44 }
80 extern const char str_float2 []; 86 extern const char str_float2 [];
81 extern const char str_float3 []; 87 extern const char str_float3 [];
82 extern const char str_float4 []; 88 extern const char str_float4 [];
83 extern const char str_float4x4 []; 89 extern const char str_float4x4 [];
84 90
91 extern const char str_sampler1d [];
92 extern const char str_sampler2d [];
93 extern const char str_sampler3d [];
94 extern const char str_samplerCUBE [];
95 extern const char str_samplerRECT [];
96
85 typedef ref<struct var_i> var; 97 typedef ref<struct var_i> var;
86 typedef ref<struct uniform_i> uniform; 98 typedef ref<struct uniform_i> uniform;
87 99
88 struct shader_builder 100 struct shader_builder
89 { 101 {
90 struct shader_program *prog; 102 struct shader_program *prog;
91 vector<uniform> refs; // uniform parameters 103 vector<uniform> refs; // uniform parameters
92 vector<var> temps; // temporary variables 104 vector<var> temps; // temporary variables
93 vector<var> streams; // varying inputs & outputs 105 vector<var> streams; // varying inputs & outputs
94 vector<var> samplers; // textures
95 106
96 ostringstream source; 107 ostringstream source;
97 108
98 template<typename type> 109 template<typename type>
99 shader_builder &operator <<(const type &t) 110 shader_builder &operator <<(const type &t)
291 static varying_1f psize_1f; 302 static varying_1f psize_1f;
292 static varying_1f attr6_1f, attr7_1f; 303 static varying_1f attr6_1f, attr7_1f;
293 static varying_2f attr6_2f, attr7_2f; 304 static varying_2f attr6_2f, attr7_2f;
294 static varying_3f attr6_3f, attr7_3f; 305 static varying_3f attr6_3f, attr7_3f;
295 static varying_4f attr6_4f, attr7_4f; 306 static varying_4f attr6_4f, attr7_4f;
307 static varying_1f texcoord_1f[8];
296 static varying_2f texcoord0_2f; 308 static varying_2f texcoord_2f[8];
309 static varying_3f texcoord_3f[8];
297 static varying_4f texcoord0_4f; 310 static varying_4f texcoord_4f[8];
298 static varying_2f texcoord1_2f;
299 static varying_4f texcoord1_4f;
300 static varying_2f texcoord2_2f;
301 static varying_4f texcoord2_4f;
302 static varying_2f texcoord3_2f;
303 static varying_4f texcoord3_4f;
304 static varying_2f texcoord4_2f;
305 static varying_4f texcoord4_4f;
306 static varying_2f texcoord5_2f;
307 static varying_4f texcoord5_4f;
308 static varying_2f texcoord6_2f;
309 static varying_4f texcoord6_4f;
310 static varying_2f texcoord7_2f;
311 static varying_4f texcoord7_4f;
312 311
313 bool is (const var &r); 312 bool is (const var &r);
314 } vin; 313 } vin;
315 314
316 extern struct fin 315 extern struct fin
317 { 316 {
318 static varying_4f position_4f; 317 static varying_4f position_4f;
319 static varying_4f color0_4f; 318 static varying_4f color0_4f;
320 static varying_4f color1_4f; 319 static varying_4f color1_4f;
321 static varying_4f texcoord0_4f; 320 static varying_4f texcoord_4f[8];
322 static varying_4f texcoord1_4f;
323 static varying_4f texcoord2_4f;
324 static varying_4f texcoord3_4f;
325 static varying_4f texcoord4_4f;
326 static varying_4f texcoord5_4f;
327 static varying_4f texcoord6_4f;
328 static varying_4f texcoord7_4f;
329 321
330 bool is (const var &r); 322 bool is (const var &r);
331 } fin; 323 } fin;
332 324
333 extern struct fin &vout; 325 extern struct fin &vout;
342 334
343 bool is (const var &r); 335 bool is (const var &r);
344 } fout; 336 } fout;
345 337
346 // predefined globals 338 // predefined globals
347 extern uniform_matrix_f_i mvp, mv, proj; 339 extern uniform_matrix_f mvp, mv, proj;
348 340
349 struct temporary_i : var_i 341 struct temporary_i : var_i
350 { 342 {
351 void build (shader_builder &b); 343 void build (shader_builder &b);
352 344
366 typedef temp_ref<CG_FLOAT, str_float2 > temp_2f; 358 typedef temp_ref<CG_FLOAT, str_float2 > temp_2f;
367 typedef temp_ref<CG_FLOAT, str_float3 > temp_3f; 359 typedef temp_ref<CG_FLOAT, str_float3 > temp_3f;
368 typedef temp_ref<CG_FLOAT, str_float4 > temp_4f; 360 typedef temp_ref<CG_FLOAT, str_float4 > temp_4f;
369 typedef temp_ref<CG_FLOAT, str_float4x4> temp_matrix_f; 361 typedef temp_ref<CG_FLOAT, str_float4x4> temp_matrix_f;
370 362
371 template<CGtype cgtype> 363 template<CGtype cgtype, const char *strtype>
372 struct sampler_i : var_i 364 struct sampler_i : uniform_i
365 {
366 GLuint texture;
367
368 void update ()
373 { 369 {
374 sampler_i () : var_i (cgtype) { } 370 if (dirty)
371 {
372 cgGLSetTextureParameter (param, texture);
373 dirty = false;
374 }
375 }
376
377 void begin ()
378 {
379 cgGLEnableTextureParameter (texture);
380 }
381
382 sampler_i (GLuint texturename) : uniform_i (cgtype, strtype), texture (texturename) { }
375 }; 383 };
384
385 struct sampler1d_i : sampler_i<CG_SAMPLER1D, str_sampler1d>
386 {
387 sampler1d_i (GLuint texturename) : sampler_i<CG_SAMPLER1D, str_sampler1d> (texturename) { }
388 };
389
390 struct sampler2d_i : sampler_i<CG_SAMPLER2D, str_sampler2d>
391 {
392 sampler2d_i (GLuint texturename) : sampler_i<CG_SAMPLER2D, str_sampler2d> (texturename) { }
393 };
394
395 struct sampler3d_i : sampler_i<CG_SAMPLER3D, str_sampler3d>
396 {
397 sampler3d_i (GLuint texturename) : sampler_i<CG_SAMPLER3D, str_sampler3d> (texturename) { }
398 };
399
400 struct samplerCUBE_i : sampler_i<CG_SAMPLERCUBE, str_samplerCUBE>
401 {
402 samplerCUBE_i (GLuint texturename) : sampler_i<CG_SAMPLERCUBE, str_samplerCUBE> (texturename) { }
403 };
404
405 struct samplerRECT_i : sampler_i<CG_SAMPLERRECT, str_samplerRECT>
406 {
407 samplerRECT_i (GLuint texturename) : sampler_i<CG_SAMPLERRECT, str_samplerRECT> (texturename) { }
408 };
409
410 template<class sampler_i>
411 struct sampler_ref : ref<sampler_i>
412 {
413 sampler_ref (GLuint texturename)
414 : ref<sampler_i> (*new sampler_i (texturename))
415 {
416 }
417 };
418
419 typedef sampler_ref<sampler1d_i> sampler1d;
420 typedef sampler_ref<sampler2d_i> sampler2d;
421 typedef sampler_ref<sampler3d_i> sampler3d;
422 typedef sampler_ref<samplerCUBE_i> samplerCUBE;
423 typedef sampler_ref<samplerRECT_i> samplerRECT;
376 424
377 struct fragment_const_string_i : fragment_i 425 struct fragment_const_string_i : fragment_i
378 { 426 {
379 const char *str; 427 const char *str;
380 428

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines