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

Comparing libgender/shader.h (file contents):
Revision 1.18 by root, Fri Oct 29 17:21:54 2004 UTC vs.
Revision 1.19 by root, Fri Oct 29 22:32:49 2004 UTC

413 }; 413 };
414 414
415 template<int dimension, const char *strtype> 415 template<int dimension, const char *strtype>
416 struct varying_f_i : varying_i<dimension, GL_FLOAT, strtype> 416 struct varying_f_i : varying_i<dimension, GL_FLOAT, strtype>
417 { 417 {
418 void set (const gl::vertex_buffer_object &vb, GLint offset) 418 void set (const gl::vertex_buffer &vb, GLint offset)
419 { 419 {
420 varying_i<dimension, GL_FLOAT, strtype>::set (gl::format_stride (vb.format), (GLvoid *)(long)offset); 420 varying_i<dimension, GL_FLOAT, strtype>::set (gl::format_stride (vb.format), (GLvoid *)(long)offset);
421 } 421 }
422 }; 422 };
423 423
425 { 425 {
426 }; 426 };
427 427
428 struct varying_2f_i : varying_f_i<2, str_vec2> 428 struct varying_2f_i : varying_f_i<2, str_vec2>
429 { 429 {
430 void set_t (const gl::vertex_buffer_object &vb) 430 void set_t (const gl::vertex_buffer &vb)
431 { 431 {
432 set (vb, gl::format_offset_t (vb.format)); 432 set (vb, gl::format_offset_t (vb.format));
433 } 433 }
434 }; 434 };
435 435
436 struct varying_3f_i : varying_f_i<3, str_vec3> 436 struct varying_3f_i : varying_f_i<3, str_vec3>
437 { 437 {
438 void set_p (const gl::vertex_buffer_object &vb) 438 void set_p (const gl::vertex_buffer &vb)
439 { 439 {
440 set (vb, gl::format_offset_p (vb.format)); 440 set (vb, gl::format_offset_p (vb.format));
441 } 441 }
442 442
443 void set_n (const gl::vertex_buffer_object &vb) 443 void set_n (const gl::vertex_buffer &vb)
444 { 444 {
445 set (vb, gl::format_offset_n (vb.format)); 445 set (vb, gl::format_offset_n (vb.format));
446 } 446 }
447 }; 447 };
448 448
491 typedef temp_ref<str_mat3> temp_matrix_3f; 491 typedef temp_ref<str_mat3> temp_matrix_3f;
492 typedef temp_ref<str_mat4> temp_matrix_4f; 492 typedef temp_ref<str_mat4> temp_matrix_4f;
493 493
494 struct texture_units 494 struct texture_units
495 { 495 {
496 static GLenum units[8]; 496 static int units[8];
497 static int unit_count; 497 static int unit_count;
498 498
499 static GLenum get_texture_unit () 499 static GLenum get_texture_unit ()
500 { 500 {
501 assert (unit_count); 501 assert (unit_count);
510 }; 510 };
511 511
512 template<GLenum gltype, const char *strtype> 512 template<GLenum gltype, const char *strtype>
513 struct sampler_i : uniform_i, texture_units 513 struct sampler_i : uniform_i, texture_units
514 { 514 {
515 GLenum unit; 515 int unit;
516 GLuint name; 516 GLuint name;
517 517
518 void update () 518 void update ()
519 { 519 {
520 if (dirty) 520 if (dirty)
525 } 525 }
526 526
527 void enable () 527 void enable ()
528 { 528 {
529#if DEBUG 529#if DEBUG
530 assert (unit < GL_TEXTURE0); 530 assert (unit < 0);
531#endif 531#endif
532 GLint loc = location ();
532 533
534 if (loc >= 0)
535 {
533 unit = get_texture_unit (); 536 unit = get_texture_unit ();
534 glActiveTexture (unit); 537 glActiveTexture (GL_TEXTURE0 + unit);
535 glBindTexture (gltype, name); 538 glBindTexture (gltype, name);
539 glUniform1iARB (loc, unit);
540 }
536 } 541 }
537 542
538 void disable () 543 void disable ()
539 { 544 {
545 if (unit >= 0)
546 {
540 put_texture_unit (unit); 547 put_texture_unit (unit);
541#if DEBUG 548 unit = -1;
542 assert (unit >= GL_TEXTURE0); 549 }
543 unit = GL_ZERO;
544#endif
545 } 550 }
546 551
547 template<class bufferclass, class vectype> 552 template<class bufferclass, class vectype>
548 void set (const gl::vertex_buffer_object &vb, const vectype bufferclass::*vp) 553 void set (const gl::vertex_buffer &vb, const vectype bufferclass::*vp)
549 { 554 {
550 glTexCoordPointer ( 555 glTexCoordPointer (
551 vector_traits<vectype>::dimension (), 556 vector_traits<vectype>::dimension (),
552 gltype_traits<typename vector_traits<vectype>::basetype>::gltype, 557 gltype_traits<typename vector_traits<vectype>::basetype>::gltype,
553 sizeof (bufferclass), 558 sizeof (bufferclass),
557 562
558 sampler_i (GLuint texture) 563 sampler_i (GLuint texture)
559 : uniform_i (strtype) 564 : uniform_i (strtype)
560 , name (texture) 565 , name (texture)
561#if DEBUG 566#if DEBUG
562 , unit (GL_ZERO) 567 , unit (-1)
563#endif 568#endif
564 { 569 {
565 } 570 }
566 }; 571 };
567 572

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines