Index: ddraw/ShaderGen2D.cpp |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | Bit 25: Depth fill (DDBLT_DEPTHFILL)
|
52 | 52 | Bit 26: ROP index bit 6
|
53 | 53 | Bit 27: ROP index bit 7
|
54 | | -Bit 28: reserved for DXGL usage
|
| 54 | +Bit 28: (DXGL) Use Clipper
|
55 | 55 | Bit 29: reserved for DXGL usage
|
56 | 56 | Bit 30: reserved for DXGL usage
|
57 | 57 | Bit 31: reserved for DXGL usage
|
Index: ddraw/ShaderGen3D.cpp |
— | — | @@ -125,8 +125,8 @@ |
126 | 126 | if(genshaders[i].shader.prog) ext->glDeleteProgram(genshaders[i].shader.prog);
|
127 | 127 | if(genshaders[i].shader.fs) ext->glDeleteShader(genshaders[i].shader.fs);
|
128 | 128 | if(genshaders[i].shader.vs) ext->glDeleteShader(genshaders[i].shader.vs);
|
129 | | - if(genshaders[i].shader.fsrc) delete genshaders[i].shader.fsrc;
|
130 | | - if(genshaders[i].shader.vsrc) delete genshaders[i].shader.vsrc;
|
| 129 | + if(genshaders[i].shader.fsrc.ptr) String_Free(&genshaders[i].shader.fsrc);
|
| 130 | + if(genshaders[i].shader.vsrc.ptr) String_Free(&genshaders[i].shader.vsrc);
|
131 | 131 | }
|
132 | 132 | if(genshaders) free(genshaders);
|
133 | 133 | genshaders = NULL;
|
— | — | @@ -231,8 +231,8 @@ |
232 | 232 | ext->glDeleteProgram(genshaders[genindex].shader.prog);
|
233 | 233 | ext->glDeleteShader(genshaders[genindex].shader.vs);
|
234 | 234 | ext->glDeleteShader(genshaders[genindex].shader.fs);
|
235 | | - delete genshaders[genindex].shader.vsrc;
|
236 | | - delete genshaders[genindex].shader.fsrc;
|
| 235 | + String_Free(&genshaders[genindex].shader.vsrc);
|
| 236 | + String_Free(&genshaders[genindex].shader.fsrc);
|
237 | 237 | ZeroMemory(&genshaders[genindex],sizeof(GenShader));
|
238 | 238 | }
|
239 | 239 | CreateShader(genindex,id,texstate,texcoords);
|
— | — | @@ -457,31 +457,31 @@ |
458 | 458 | char idstring[22];
|
459 | 459 | _snprintf(idstring,21,"%0.16I64X\n",id);
|
460 | 460 | idstring[21] = 0;
|
461 | | - genshaders[index].shader.vsrc = new string;
|
462 | | - genshaders[index].shader.fsrc = new string;
|
| 461 | + genshaders[index].shader.vsrc.ptr = NULL;
|
| 462 | + genshaders[index].shader.fsrc.ptr = NULL;
|
463 | 463 | // Create vertex shader
|
464 | 464 | //Header
|
465 | | - string *vsrc = genshaders[index].shader.vsrc;
|
466 | | - vsrc->append(header);
|
467 | | - vsrc->append(vertexshader);
|
468 | | - vsrc->append(idheader);
|
469 | | - vsrc->append(idstring);
|
| 465 | + STRING *vsrc = &genshaders[index].shader.vsrc;
|
| 466 | + String_Append(vsrc, header);
|
| 467 | + String_Append(vsrc, vertexshader);
|
| 468 | + String_Append(vsrc, idheader);
|
| 469 | + String_Append(vsrc, idstring);
|
470 | 470 | // Attributes
|
471 | | - vsrc->append(attr_xyz);
|
472 | | - if((id>>50)&1) vsrc->append(attr_rhw);
|
| 471 | + String_Append(vsrc, attr_xyz);
|
| 472 | + if((id>>50)&1) String_Append(vsrc, attr_rhw);
|
473 | 473 | tmp = attr_rgba;
|
474 | 474 | if((id>>35)&1)
|
475 | 475 | {
|
476 | 476 | tmp.replace(19,1,"0");
|
477 | | - vsrc->append(tmp);
|
| 477 | + String_Append(vsrc, tmp.c_str());
|
478 | 478 | }
|
479 | 479 | if((id>>36)&1)
|
480 | 480 | {
|
481 | 481 | tmp.replace(19,1,"1");
|
482 | | - vsrc->append(tmp);
|
| 482 | + String_Append(vsrc, tmp.c_str());
|
483 | 483 | }
|
484 | | - if((id>>37)&1) vsrc->append(attr_nxyz);
|
485 | | - else vsrc->append(const_nxyz);
|
| 484 | + if((id>>37)&1) String_Append(vsrc, attr_nxyz);
|
| 485 | + else String_Append(vsrc, const_nxyz);
|
486 | 486 | count = (id>>46)&7;
|
487 | 487 | if(count)
|
488 | 488 | {
|
— | — | @@ -489,7 +489,7 @@ |
490 | 490 | for(i = 0; i < count; i++)
|
491 | 491 | {
|
492 | 492 | tmp.replace(21,1,_itoa(i,idstring,10));
|
493 | | - vsrc->append(tmp);
|
| 493 | + String_Append(vsrc, tmp.c_str());
|
494 | 494 | }
|
495 | 495 | }
|
496 | 496 | for(i = 0; i < 8; i++)
|
— | — | @@ -515,31 +515,31 @@ |
516 | 516 | tmp.replace(19,1,_itoa(i,idstring,10));
|
517 | 517 | break;
|
518 | 518 | }
|
519 | | - vsrc->append(tmp);
|
| 519 | + String_Append(vsrc, tmp.c_str());
|
520 | 520 | }
|
521 | 521 |
|
522 | 522 | // Uniforms
|
523 | | - vsrc->append(unif_ambient);
|
524 | | - if((id>>50)&1) vsrc->append(unif_viewport);
|
| 523 | + String_Append(vsrc, unif_ambient);
|
| 524 | + if((id>>50)&1) String_Append(vsrc, unif_viewport);
|
525 | 525 | if((id>>59)&1) numlights = (id>>18)&7;
|
526 | 526 | else numlights = 0;
|
527 | 527 | if((id>>50)&1) numlights = 0;
|
528 | 528 | if(numlights) // Lighting
|
529 | 529 | {
|
530 | | - vsrc->append(lightstruct);
|
531 | | - vsrc->append(unif_world);
|
| 530 | + String_Append(vsrc, lightstruct);
|
| 531 | + String_Append(vsrc, unif_world);
|
532 | 532 | tmp = unif_light;
|
533 | 533 | for(i = 0; i < numlights; i++)
|
534 | 534 | {
|
535 | 535 | tmp.replace(19,1,_itoa(i,idstring,10));
|
536 | | - vsrc->append(tmp);
|
| 536 | + String_Append(vsrc, tmp.c_str());
|
537 | 537 | }
|
538 | 538 | }
|
539 | 539 |
|
540 | 540 | // Variables
|
541 | | - vsrc->append(var_common);
|
542 | | - if(!((id>>50)&1)) vsrc->append(var_xyzw);
|
543 | | - if(vertexfog && !pixelfog) vsrc->append(var_fogfactorvertex);
|
| 541 | + String_Append(vsrc, var_common);
|
| 542 | + if(!((id>>50)&1)) String_Append(vsrc, var_xyzw);
|
| 543 | + if(vertexfog && !pixelfog) String_Append(vsrc, var_fogfactorvertex);
|
544 | 544 |
|
545 | 545 | // Functions
|
546 | 546 | if(numlights)
|
— | — | @@ -555,20 +555,20 @@ |
556 | 556 | }
|
557 | 557 | }
|
558 | 558 | bool hasspecular = (id >> 11) & 1;
|
559 | | - if(hasspot) vsrc->append(func_spotlight);
|
560 | | - if(haspoint) vsrc->append(func_pointlight);
|
561 | | - if(hasdir) vsrc->append(func_dirlight);
|
| 559 | + if(hasspot) String_Append(vsrc, func_spotlight);
|
| 560 | + if(haspoint) String_Append(vsrc, func_pointlight);
|
| 561 | + if(hasdir) String_Append(vsrc, func_dirlight);
|
562 | 562 | //Main
|
563 | | - vsrc->append(mainstart);
|
564 | | - if((id>>50)&1) vsrc->append(op_tlvertex);
|
565 | | - else vsrc->append(op_transform);
|
566 | | - if((id>>49)&1) vsrc->append(op_normalize);
|
567 | | - else vsrc->append(op_normalpassthru);
|
| 563 | + String_Append(vsrc, mainstart);
|
| 564 | + if((id>>50)&1) String_Append(vsrc, op_tlvertex);
|
| 565 | + else String_Append(vsrc, op_transform);
|
| 566 | + if((id>>49)&1) String_Append(vsrc, op_normalize);
|
| 567 | + else String_Append(vsrc, op_normalpassthru);
|
568 | 568 | const string colorargs[] = {"gl_FrontMaterial.diffuse","gl_FrontMaterial.ambient","gl_FrontMaterial.specular",
|
569 | 569 | "gl_FrontMaterial.emission","rgba0.bgra","rgba1.bgra"};
|
570 | 570 | if(numlights)
|
571 | 571 | {
|
572 | | - vsrc->append(op_resetcolor);
|
| 572 | + String_Append(vsrc, op_resetcolor);
|
573 | 573 | for(i = 0; i < numlights; i++)
|
574 | 574 | {
|
575 | 575 | if(id>>(38+i)&1)
|
— | — | @@ -577,13 +577,13 @@ |
578 | 578 | {
|
579 | 579 | tmp = op_spotlight;
|
580 | 580 | tmp.replace(15,1,_itoa(i,idstring,10));
|
581 | | - vsrc->append(tmp);
|
| 581 | + String_Append(vsrc, tmp.c_str());
|
582 | 582 | }
|
583 | 583 | else
|
584 | 584 | {
|
585 | 585 | tmp = op_pointlight;
|
586 | 586 | tmp.replace(16,1,_itoa(i,idstring,10));
|
587 | | - vsrc->append(tmp);
|
| 587 | + String_Append(vsrc, tmp.c_str());
|
588 | 588 | }
|
589 | 589 | }
|
590 | 590 | else
|
— | — | @@ -590,7 +590,7 @@ |
591 | 591 | {
|
592 | 592 | tmp = op_dirlight;
|
593 | 593 | tmp.replace(14,1,_itoa(i,idstring,10));
|
594 | | - vsrc->append(tmp);
|
| 594 | + String_Append(vsrc, tmp.c_str());
|
595 | 595 | }
|
596 | 596 | }
|
597 | 597 | if((id>>60)&1)
|
— | — | @@ -600,35 +600,35 @@ |
601 | 601 | bool hascolor2 = false;
|
602 | 602 | if((id>>36)&1) hascolor2 = true;
|
603 | 603 | int matcolor;
|
604 | | - vsrc->append("gl_FrontColor = (");
|
| 604 | + String_Append(vsrc, "gl_FrontColor = (");
|
605 | 605 | matcolor = ((id>>23)&3);
|
606 | | - if((matcolor == D3DMCS_COLOR1) && hascolor1) vsrc->append(colorargs[4]);
|
607 | | - else if((matcolor == D3DMCS_COLOR2) && hascolor2) vsrc->append(colorargs[5]);
|
608 | | - else vsrc->append(colorargs[0]);
|
609 | | - vsrc->append(" * diffuse) + (");
|
| 606 | + if((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4].c_str());
|
| 607 | + else if((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5].c_str());
|
| 608 | + else String_Append(vsrc, colorargs[0].c_str());
|
| 609 | + String_Append(vsrc, " * diffuse) + (");
|
610 | 610 | matcolor = ((id>>27)&3);
|
611 | | - if((matcolor == D3DMCS_COLOR1) && hascolor1) vsrc->append(colorargs[4]);
|
612 | | - else if((matcolor == D3DMCS_COLOR2) && hascolor2) vsrc->append(colorargs[5]);
|
613 | | - else vsrc->append(colorargs[1]);
|
614 | | - vsrc->append(" * ambient)\n+ (");
|
| 611 | + if((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4].c_str());
|
| 612 | + else if((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5].c_str());
|
| 613 | + else String_Append(vsrc, colorargs[1].c_str());
|
| 614 | + String_Append(vsrc, " * ambient)\n+ (");
|
615 | 615 | matcolor = ((id>>25)&3);
|
616 | | - if((matcolor == D3DMCS_COLOR1) && hascolor1) vsrc->append(colorargs[4]);
|
617 | | - else if((matcolor == D3DMCS_COLOR2) && hascolor2) vsrc->append(colorargs[5]);
|
618 | | - else vsrc->append(colorargs[2]);
|
619 | | - vsrc->append(" * specular) + ");
|
| 616 | + if((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4].c_str());
|
| 617 | + else if((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5].c_str());
|
| 618 | + else String_Append(vsrc, colorargs[2].c_str());
|
| 619 | + String_Append(vsrc, " * specular) + ");
|
620 | 620 | matcolor = ((id>>29)&3);
|
621 | | - if((matcolor == D3DMCS_COLOR1) && hascolor1) vsrc->append(colorargs[4]);
|
622 | | - else if((matcolor == D3DMCS_COLOR2) && hascolor2) vsrc->append(colorargs[5]);
|
623 | | - else vsrc->append(colorargs[3]);
|
624 | | - vsrc->append(";\n");
|
| 621 | + if ((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4].c_str());
|
| 622 | + else if ((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5].c_str());
|
| 623 | + else String_Append(vsrc, colorargs[3].c_str());
|
| 624 | + String_Append(vsrc, ";\n");
|
625 | 625 | }
|
626 | | - else vsrc->append(op_colorout);
|
| 626 | + else String_Append(vsrc, op_colorout);
|
627 | 627 | }
|
628 | 628 | else
|
629 | 629 | {
|
630 | | - if((id>>35)&1) vsrc->append(op_colorvert);
|
631 | | - else vsrc->append(op_colorwhite);
|
632 | | - if((id>>36)&1) vsrc->append(op_color2vert);
|
| 630 | + if((id>>35)&1) String_Append(vsrc, op_colorvert);
|
| 631 | + else String_Append(vsrc, op_colorwhite);
|
| 632 | + if((id>>36)&1) String_Append(vsrc, op_color2vert);
|
633 | 633 | }
|
634 | 634 | int texindex;
|
635 | 635 | for(i = 0; i < 8; i++)
|
— | — | @@ -641,33 +641,33 @@ |
642 | 642 | {
|
643 | 643 | tmp = op_texpassthru1;
|
644 | 644 | tmp.replace(12,1,_itoa(i,idstring,10));
|
645 | | - vsrc->append(tmp);
|
| 645 | + String_Append(vsrc, tmp.c_str());
|
646 | 646 | texindex = (texstate[i].shaderid>>54)&3;
|
647 | 647 | switch(texcoords[texindex])
|
648 | 648 | {
|
649 | 649 | case -1: // No texcoords
|
650 | | - vsrc->append(op_texpassthru2null);
|
| 650 | + String_Append(vsrc, op_texpassthru2null);
|
651 | 651 | break;
|
652 | 652 | case 0: // st
|
653 | 653 | tmp = op_texpassthru2st;
|
654 | 654 | tmp.replace(7,1,_itoa(texindex,idstring,10));
|
655 | | - vsrc->append(tmp);
|
| 655 | + String_Append(vsrc, tmp.c_str());
|
656 | 656 | default:
|
657 | 657 | break;
|
658 | 658 | case 1: // str
|
659 | 659 | tmp = op_texpassthru2str;
|
660 | 660 | tmp.replace(8,1,_itoa(texindex,idstring,10));
|
661 | | - vsrc->append(tmp);
|
| 661 | + String_Append(vsrc, tmp.c_str());
|
662 | 662 | break;
|
663 | 663 | case 2: // strq
|
664 | 664 | tmp = op_texpassthru2strq;
|
665 | 665 | tmp.replace(4,1,_itoa(texindex,idstring,10));
|
666 | | - vsrc->append(tmp);
|
| 666 | + String_Append(vsrc, tmp.c_str());
|
667 | 667 | break;
|
668 | 668 | case 3: // s
|
669 | 669 | tmp = op_texpassthru2s;
|
670 | 670 | tmp.replace(6,1,_itoa(texindex,idstring,10));
|
671 | | - vsrc->append(tmp);
|
| 671 | + String_Append(vsrc, tmp.c_str());
|
672 | 672 | break;
|
673 | 673 | }
|
674 | 674 | }
|
— | — | @@ -674,30 +674,30 @@ |
675 | 675 | }
|
676 | 676 | if(vertexfog && !pixelfog)
|
677 | 677 | {
|
678 | | - if((id>>10)&1) vsrc->append(op_fogcoordrange);
|
679 | | - else vsrc->append(op_fogcoordstandard);
|
| 678 | + if((id>>10)&1) String_Append(vsrc, op_fogcoordrange);
|
| 679 | + else String_Append(vsrc, op_fogcoordstandard);
|
680 | 680 | switch(vertexfog)
|
681 | 681 | {
|
682 | 682 | case D3DFOG_LINEAR:
|
683 | | - vsrc->append(op_foglinear);
|
| 683 | + String_Append(vsrc, op_foglinear);
|
684 | 684 | break;
|
685 | 685 | case D3DFOG_EXP:
|
686 | | - vsrc->append(op_fogexp);
|
| 686 | + String_Append(vsrc, op_fogexp);
|
687 | 687 | break;
|
688 | 688 | case D3DFOG_EXP2:
|
689 | | - vsrc->append(op_fogexp2);
|
| 689 | + String_Append(vsrc, op_fogexp2);
|
690 | 690 | break;
|
691 | 691 | }
|
692 | | - vsrc->append(op_fogclamp);
|
| 692 | + String_Append(vsrc, op_fogclamp);
|
693 | 693 | }
|
694 | | - vsrc->append(mainend);
|
| 694 | + String_Append(vsrc, mainend);
|
695 | 695 | #ifdef _DEBUG
|
696 | 696 | OutputDebugStringA("Vertex shader:\n");
|
697 | | - OutputDebugStringA(vsrc->c_str());
|
| 697 | + OutputDebugStringA(vsrc->ptr);
|
698 | 698 | OutputDebugStringA("\nCompiling vertex shader:\n");
|
699 | 699 | #endif
|
700 | 700 | genshaders[index].shader.vs = ext->glCreateShader(GL_VERTEX_SHADER);
|
701 | | - const char *src = vsrc->c_str();
|
| 701 | + const char *src = vsrc->ptr;
|
702 | 702 | GLint srclen = strlen(src);
|
703 | 703 | ext->glShaderSource(genshaders[index].shader.vs,1,&src,&srclen);
|
704 | 704 | ext->glCompileShader(genshaders[index].shader.vs);
|
— | — | @@ -717,13 +717,13 @@ |
718 | 718 | }
|
719 | 719 | #endif
|
720 | 720 | // Create fragment shader
|
721 | | - string *fsrc = genshaders[index].shader.fsrc;
|
722 | | - fsrc->append(header);
|
723 | | - fsrc->append(fragshader);
|
| 721 | + STRING *fsrc = &genshaders[index].shader.fsrc;
|
| 722 | + String_Append(fsrc, header);
|
| 723 | + String_Append(fsrc, fragshader);
|
724 | 724 | _snprintf(idstring,21,"%0.16I64X\n",id);
|
725 | 725 | idstring[21] = 0;
|
726 | | - fsrc->append(idheader);
|
727 | | - fsrc->append(idstring);
|
| 726 | + String_Append(fsrc, idheader);
|
| 727 | + String_Append(fsrc, idstring);
|
728 | 728 | // Uniforms
|
729 | 729 | for(i = 0; i < 8; i++)
|
730 | 730 | {
|
— | — | @@ -730,7 +730,7 @@ |
731 | 731 | if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
|
732 | 732 | tmp = unif_tex;
|
733 | 733 | tmp.replace(21,1,_itoa(i,idstring,10));
|
734 | | - fsrc->append(tmp);
|
| 734 | + String_Append(fsrc, tmp.c_str());
|
735 | 735 | }
|
736 | 736 | if((id>>13)&1)
|
737 | 737 | {
|
— | — | @@ -740,19 +740,19 @@ |
741 | 741 | {
|
742 | 742 | tmp = unif_key;
|
743 | 743 | tmp.replace(17,1,_itoa(i,idstring,10));
|
744 | | - fsrc->append(tmp);
|
| 744 | + String_Append(fsrc, tmp.c_str());
|
745 | 745 | }
|
746 | 746 | }
|
747 | 747 | }
|
748 | | - if((id>>2)&1) fsrc->append(unif_alpharef);
|
| 748 | + if((id>>2)&1) String_Append(fsrc, unif_alpharef);
|
749 | 749 | // Variables
|
750 | | - fsrc->append(var_color);
|
751 | | - if(vertexfog && !pixelfog) fsrc->append(var_fogfactorvertex);
|
752 | | - if(pixelfog) fsrc->append(var_fogfactorpixel);
|
| 750 | + String_Append(fsrc, var_color);
|
| 751 | + if(vertexfog && !pixelfog) String_Append(fsrc, var_fogfactorvertex);
|
| 752 | + if(pixelfog) String_Append(fsrc, var_fogfactorpixel);
|
753 | 753 | // Functions
|
754 | 754 | // Main
|
755 | | - fsrc->append(mainstart);
|
756 | | - fsrc->append(op_colorfragin);
|
| 755 | + String_Append(fsrc, mainstart);
|
| 756 | + String_Append(fsrc, op_colorfragin);
|
757 | 757 | string arg1,arg2;
|
758 | 758 | string texarg;
|
759 | 759 | int args[4];
|
— | — | @@ -778,7 +778,7 @@ |
779 | 779 | arg1.replace(26,1,_itoa(i,idstring,10));
|
780 | 780 | arg1.replace(40,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
|
781 | 781 | arg1.replace(57,1,_itoa(i,idstring,10));
|
782 | | - fsrc->append(arg1);
|
| 782 | + String_Append(fsrc, arg1.c_str());
|
783 | 783 | }
|
784 | 784 | }
|
785 | 785 | // Color stage
|
— | — | @@ -847,56 +847,121 @@ |
848 | 848 | default:
|
849 | 849 | break;
|
850 | 850 | case D3DTOP_SELECTARG1:
|
851 | | - fsrc->append("color.rgb = " + arg1 + ";\n");
|
| 851 | + String_Append(fsrc, "color.rgb = ");
|
| 852 | + String_Append(fsrc, arg1.c_str());
|
| 853 | + String_Append(fsrc, ";\n");
|
852 | 854 | break;
|
853 | 855 | case D3DTOP_SELECTARG2:
|
854 | | - fsrc->append("color.rgb = " + arg2 + ";\n");
|
| 856 | + String_Append(fsrc, "color.rgb = ");
|
| 857 | + String_Append(fsrc, arg2.c_str());
|
| 858 | + String_Append(fsrc, ";\n");
|
855 | 859 | break;
|
856 | 860 | case D3DTOP_MODULATE:
|
857 | | - fsrc->append("color.rgb = " + arg1 + " * " + arg2 + ";\n");
|
| 861 | + String_Append(fsrc, "color.rgb = ");
|
| 862 | + String_Append(fsrc, arg1.c_str());
|
| 863 | + String_Append(fsrc, " * ");
|
| 864 | + String_Append(fsrc, arg2.c_str());
|
| 865 | + String_Append(fsrc, ";\n");
|
858 | 866 | break;
|
859 | 867 | case D3DTOP_MODULATE2X:
|
860 | | - fsrc->append("color.rgb = (" + arg1 + " * " + arg2 + ") * 2.0;\n");
|
| 868 | + String_Append(fsrc, "color.rgb = (");
|
| 869 | + String_Append(fsrc, arg1.c_str());
|
| 870 | + String_Append(fsrc, " * ");
|
| 871 | + String_Append(fsrc, arg2.c_str());
|
| 872 | + String_Append(fsrc, ") * 2.0;\n");
|
861 | 873 | break;
|
862 | 874 | case D3DTOP_MODULATE4X:
|
863 | | - fsrc->append("color.rgb = (" + arg1 + " * " + arg2 + ") * 4.0;\n");
|
| 875 | + String_Append(fsrc, "color.rgb = (");
|
| 876 | + String_Append(fsrc, arg1.c_str());
|
| 877 | + String_Append(fsrc, " * ");
|
| 878 | + String_Append(fsrc, arg2.c_str());
|
| 879 | + String_Append(fsrc, ") * 4.0;\n");
|
864 | 880 | break;
|
865 | 881 | case D3DTOP_ADD:
|
866 | | - fsrc->append("color.rgb = " + arg1 + " + " + arg2 + ";\n");
|
| 882 | + String_Append(fsrc, "color.rgb = ");
|
| 883 | + String_Append(fsrc, arg1.c_str());
|
| 884 | + String_Append(fsrc, " + ");
|
| 885 | + String_Append(fsrc, arg2.c_str());
|
| 886 | + String_Append(fsrc, ";\n");
|
867 | 887 | break;
|
868 | 888 | case D3DTOP_ADDSIGNED:
|
869 | | - fsrc->append("color.rgb = " + arg1 + " + " + arg2 + " - .5;\n");
|
| 889 | + String_Append(fsrc, "color.rgb = ");
|
| 890 | + String_Append(fsrc, arg1.c_str());
|
| 891 | + String_Append(fsrc, " + ");
|
| 892 | + String_Append(fsrc, arg2.c_str());
|
| 893 | + String_Append(fsrc, " - .5;\n");
|
870 | 894 | break;
|
871 | 895 | case D3DTOP_ADDSIGNED2X:
|
872 | | - fsrc->append("color.rgb = (" + arg1 + " + " + arg2 + " - .5) * 2.0;\n");
|
| 896 | + String_Append(fsrc, "color.rgb = (");
|
| 897 | + String_Append(fsrc, arg1.c_str());
|
| 898 | + String_Append(fsrc, " + ");
|
| 899 | + String_Append(fsrc, arg2.c_str());
|
| 900 | + String_Append(fsrc, " - .5) * 2.0;\n");
|
873 | 901 | break;
|
874 | 902 | case D3DTOP_SUBTRACT:
|
875 | | - fsrc->append("color.rgb = " + arg1 + " - " + arg2 + ";\n");
|
| 903 | + String_Append(fsrc, "color.rgb = ");
|
| 904 | + String_Append(fsrc, arg1.c_str());
|
| 905 | + String_Append(fsrc, " - ");
|
| 906 | + String_Append(fsrc, arg2.c_str());
|
| 907 | + String_Append(fsrc, ";\n");
|
876 | 908 | break;
|
877 | 909 | case D3DTOP_ADDSMOOTH:
|
878 | | - fsrc->append("color.rgb = " + arg1 + " + " + arg2 + " - " + arg1 + " * " + arg2 + ";\n");
|
| 910 | + String_Append(fsrc, "color.rgb = ");
|
| 911 | + String_Append(fsrc, arg1.c_str());
|
| 912 | + String_Append(fsrc, " + ");
|
| 913 | + String_Append(fsrc, arg2.c_str());
|
| 914 | + String_Append(fsrc, " - ");
|
| 915 | + String_Append(fsrc, arg1.c_str());
|
| 916 | + String_Append(fsrc, " * ");
|
| 917 | + String_Append(fsrc, arg2.c_str());
|
| 918 | + String_Append(fsrc, ";\n");
|
879 | 919 | break;
|
880 | 920 | case D3DTOP_BLENDDIFFUSEALPHA:
|
881 | | - fsrc->append("color.rgb = " + arg1 + " * gl_Color.a + " + arg2 + " * (1.0-gl_Color.a);\n");
|
| 921 | + String_Append(fsrc, "color.rgb = ");
|
| 922 | + String_Append(fsrc, arg1.c_str());
|
| 923 | + String_Append(fsrc, " * gl_Color.a + ");
|
| 924 | + String_Append(fsrc, arg2.c_str());
|
| 925 | + String_Append(fsrc, " * (1.0-gl_Color.a);\n");
|
882 | 926 | break;
|
883 | 927 | case D3DTOP_BLENDTEXTUREALPHA:
|
884 | 928 | texarg = blendargs[2];
|
885 | 929 | texarg.replace(17,1,_itoa(i,idstring,10));
|
886 | 930 | texarg.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
|
887 | | - fsrc->append("color.rgb = " + arg1 + " * " + texarg + ".a + " + arg2 + " * (1.0-"
|
888 | | - + texarg + ".a);\n");
|
| 931 | + String_Append(fsrc, "color.rgb = ");
|
| 932 | + String_Append(fsrc, arg1.c_str());
|
| 933 | + String_Append(fsrc, " * ");
|
| 934 | + String_Append(fsrc, texarg.c_str());
|
| 935 | + String_Append(fsrc, ".a + ");
|
| 936 | + String_Append(fsrc, arg2.c_str());
|
| 937 | + String_Append(fsrc, " * (1.0-");
|
| 938 | + String_Append(fsrc, texarg.c_str());
|
| 939 | + String_Append(fsrc, ".a);\n");
|
889 | 940 | break;
|
890 | 941 | case D3DTOP_BLENDFACTORALPHA:
|
891 | | - fsrc->append("color.rgb = " + arg1 + " * texfactor.a + " + arg2 + " * (1.0-texfactor.a);\n");
|
| 942 | + String_Append(fsrc, "color.rgb = ");
|
| 943 | + String_Append(fsrc, arg1.c_str());
|
| 944 | + String_Append(fsrc, " * texfactor.a + ");
|
| 945 | + String_Append(fsrc, arg2.c_str());
|
| 946 | + String_Append(fsrc, " * (1.0-texfactor.a);\n");
|
892 | 947 | break;
|
893 | 948 | case D3DTOP_BLENDTEXTUREALPHAPM:
|
894 | 949 | texarg = blendargs[2];
|
895 | 950 | texarg.replace(17,1,_itoa(i,idstring,10));
|
896 | 951 | texarg.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
|
897 | | - fsrc->append("color.rgb = " + arg1 + " + " + arg2 + " * (1.0-" + texarg + ".a);\n");
|
| 952 | + String_Append(fsrc, "color.rgb = ");
|
| 953 | + String_Append(fsrc, arg1.c_str());
|
| 954 | + String_Append(fsrc, " + ");
|
| 955 | + String_Append(fsrc, arg2.c_str());
|
| 956 | + String_Append(fsrc, " * (1.0-");
|
| 957 | + String_Append(fsrc, texarg.c_str());
|
| 958 | + String_Append(fsrc, ".a);\n");
|
898 | 959 | break;
|
899 | 960 | case D3DTOP_BLENDCURRENTALPHA:
|
900 | | - fsrc->append("color.rgb = " + arg1 + " * color.a + " + arg2 + " * (1.0-color.a);\n");
|
| 961 | + String_Append(fsrc, "color.rgb = ");
|
| 962 | + String_Append(fsrc, arg1.c_str());
|
| 963 | + String_Append(fsrc, " * color.a + ");
|
| 964 | + String_Append(fsrc, arg2.c_str());
|
| 965 | + String_Append(fsrc, " * (1.0-color.a);\n");
|
901 | 966 | break;
|
902 | 967 | }
|
903 | 968 | if(((texstate[i].shaderid>>17) & 31) == D3DTOP_DISABLE)alphadisabled = true;
|
— | — | @@ -965,56 +1030,121 @@ |
966 | 1031 | default:
|
967 | 1032 | break;
|
968 | 1033 | case D3DTOP_SELECTARG1:
|
969 | | - fsrc->append("color.a = " + arg1 + ";\n");
|
| 1034 | + String_Append(fsrc, "color.a = ");
|
| 1035 | + String_Append(fsrc, arg1.c_str());
|
| 1036 | + String_Append(fsrc, ";\n");
|
970 | 1037 | break;
|
971 | 1038 | case D3DTOP_SELECTARG2:
|
972 | | - fsrc->append("color.a = " + arg2 + ";\n");
|
| 1039 | + String_Append(fsrc, "color.a = ");
|
| 1040 | + String_Append(fsrc, arg2.c_str());
|
| 1041 | + String_Append(fsrc, ";\n");
|
973 | 1042 | break;
|
974 | 1043 | case D3DTOP_MODULATE:
|
975 | | - fsrc->append("color.a = " + arg1 + " * " + arg2 + ";\n");
|
| 1044 | + String_Append(fsrc, "color.a = ");
|
| 1045 | + String_Append(fsrc, arg1.c_str());
|
| 1046 | + String_Append(fsrc, " * ");
|
| 1047 | + String_Append(fsrc, arg2.c_str());
|
| 1048 | + String_Append(fsrc, ";\n");
|
976 | 1049 | break;
|
977 | 1050 | case D3DTOP_MODULATE2X:
|
978 | | - fsrc->append("color.a = (" + arg1 + " * " + arg2 + ") * 2.0;\n");
|
| 1051 | + String_Append(fsrc, "color.a = (");
|
| 1052 | + String_Append(fsrc, arg1.c_str());
|
| 1053 | + String_Append(fsrc, " * ");
|
| 1054 | + String_Append(fsrc, arg2.c_str());
|
| 1055 | + String_Append(fsrc, ") * 2.0;\n");
|
979 | 1056 | break;
|
980 | 1057 | case D3DTOP_MODULATE4X:
|
981 | | - fsrc->append("color.a = (" + arg1 + " * " + arg2 + ") * 4.0;\n");
|
| 1058 | + String_Append(fsrc, "color.a = (");
|
| 1059 | + String_Append(fsrc, arg1.c_str());
|
| 1060 | + String_Append(fsrc, " * ");
|
| 1061 | + String_Append(fsrc, arg2.c_str());
|
| 1062 | + String_Append(fsrc, ") * 4.0;\n");
|
982 | 1063 | break;
|
983 | 1064 | case D3DTOP_ADD:
|
984 | | - fsrc->append("color.a = " + arg1 + " + " + arg2 + ";\n");
|
| 1065 | + String_Append(fsrc, "color.a = ");
|
| 1066 | + String_Append(fsrc, arg1.c_str());
|
| 1067 | + String_Append(fsrc, " + ");
|
| 1068 | + String_Append(fsrc, arg2.c_str());
|
| 1069 | + String_Append(fsrc, ";\n");
|
985 | 1070 | break;
|
986 | 1071 | case D3DTOP_ADDSIGNED:
|
987 | | - fsrc->append("color.a = " + arg1 + " + " + arg2 + " - .5;\n");
|
| 1072 | + String_Append(fsrc, "color.a = ");
|
| 1073 | + String_Append(fsrc, arg1.c_str());
|
| 1074 | + String_Append(fsrc, " + ");
|
| 1075 | + String_Append(fsrc, arg2.c_str());
|
| 1076 | + String_Append(fsrc, " - .5;\n");
|
988 | 1077 | break;
|
989 | 1078 | case D3DTOP_ADDSIGNED2X:
|
990 | | - fsrc->append("color.a = (" + arg1 + " + " + arg2 + " - .5) * 2.0;\n");
|
| 1079 | + String_Append(fsrc, "color.a = (");
|
| 1080 | + String_Append(fsrc, arg1.c_str());
|
| 1081 | + String_Append(fsrc, " + ");
|
| 1082 | + String_Append(fsrc, arg2.c_str());
|
| 1083 | + String_Append(fsrc, " - .5) * 2.0;\n");
|
991 | 1084 | break;
|
992 | 1085 | case D3DTOP_SUBTRACT:
|
993 | | - fsrc->append("color.a = " + arg1 + " - " + arg2 + ";\n");
|
| 1086 | + String_Append(fsrc, "color.a = ");
|
| 1087 | + String_Append(fsrc, arg1.c_str());
|
| 1088 | + String_Append(fsrc, " - ");
|
| 1089 | + String_Append(fsrc, arg2.c_str());
|
| 1090 | + String_Append(fsrc, ";\n");
|
994 | 1091 | break;
|
995 | 1092 | case D3DTOP_ADDSMOOTH:
|
996 | | - fsrc->append("color.a = " + arg1 + " + " + arg2 + " - " + arg1 + " * " + arg2 + ";\n");
|
| 1093 | + String_Append(fsrc, "color.a = ");
|
| 1094 | + String_Append(fsrc, arg1.c_str());
|
| 1095 | + String_Append(fsrc, " + ");
|
| 1096 | + String_Append(fsrc, arg2.c_str());
|
| 1097 | + String_Append(fsrc, " - ");
|
| 1098 | + String_Append(fsrc, arg1.c_str());
|
| 1099 | + String_Append(fsrc, " * ");
|
| 1100 | + String_Append(fsrc, arg2.c_str());
|
| 1101 | + String_Append(fsrc, ";\n");
|
997 | 1102 | break;
|
998 | 1103 | case D3DTOP_BLENDDIFFUSEALPHA:
|
999 | | - fsrc->append("color.a = " + arg1 + " * gl_Color.a + " + arg2 + " * (1.0-gl_Color.a);\n");
|
| 1104 | + String_Append(fsrc, "color.a = ");
|
| 1105 | + String_Append(fsrc, arg1.c_str());
|
| 1106 | + String_Append(fsrc, " * gl_Color.a + ");
|
| 1107 | + String_Append(fsrc, arg2.c_str());
|
| 1108 | + String_Append(fsrc, " * (1.0-gl_Color.a);\n");
|
1000 | 1109 | break;
|
1001 | 1110 | case D3DTOP_BLENDTEXTUREALPHA:
|
1002 | 1111 | texarg = blendargs[2];
|
1003 | 1112 | texarg.replace(17,1,_itoa(i,idstring,10));
|
1004 | 1113 | texarg.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
|
1005 | | - fsrc->append("color.a = " + arg1 + " * " + texarg + ".a + " + arg2 + " * (1.0-"
|
1006 | | - + texarg + ".a);\n");
|
| 1114 | + String_Append(fsrc, "color.a = ");
|
| 1115 | + String_Append(fsrc, arg1.c_str());
|
| 1116 | + String_Append(fsrc, " * ");
|
| 1117 | + String_Append(fsrc, texarg.c_str());
|
| 1118 | + String_Append(fsrc, ".a + ");
|
| 1119 | + String_Append(fsrc, arg2.c_str());
|
| 1120 | + String_Append(fsrc, " * (1.0-");
|
| 1121 | + String_Append(fsrc, texarg.c_str());
|
| 1122 | + String_Append(fsrc, ".a);\n");
|
1007 | 1123 | break;
|
1008 | 1124 | case D3DTOP_BLENDFACTORALPHA:
|
1009 | | - fsrc->append("color.a = " + arg1 + " * texfactor.a + " + arg2 + " * (1.0-texfactor.a);\n");
|
| 1125 | + String_Append(fsrc, "color.a = ");
|
| 1126 | + String_Append(fsrc, arg1.c_str());
|
| 1127 | + String_Append(fsrc, " * texfactor.a + ");
|
| 1128 | + String_Append(fsrc, arg2.c_str());
|
| 1129 | + String_Append(fsrc, " * (1.0-texfactor.a);\n");
|
1010 | 1130 | break;
|
1011 | 1131 | case D3DTOP_BLENDTEXTUREALPHAPM:
|
1012 | 1132 | texarg = blendargs[2];
|
1013 | 1133 | texarg.replace(17,1,_itoa(i,idstring,10));
|
1014 | 1134 | texarg.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
|
1015 | | - fsrc->append("color.a = " + arg1 + " + " + arg2 + " * (1.0-" + texarg + ".a);\n");
|
| 1135 | + String_Append(fsrc, "color.a = ");
|
| 1136 | + String_Append(fsrc, arg1.c_str());
|
| 1137 | + String_Append(fsrc, " + ");
|
| 1138 | + String_Append(fsrc, arg2.c_str());
|
| 1139 | + String_Append(fsrc, " * (1.0-");
|
| 1140 | + String_Append(fsrc, texarg.c_str());
|
| 1141 | + String_Append(fsrc, ".a);\n");
|
1016 | 1142 | break;
|
1017 | 1143 | case D3DTOP_BLENDCURRENTALPHA:
|
1018 | | - fsrc->append("color.a = " + arg1 + " * color.a + " + arg2 + " * (1.0-color.a);\n");
|
| 1144 | + String_Append(fsrc, "color.a = ");
|
| 1145 | + String_Append(fsrc, arg1.c_str());
|
| 1146 | + String_Append(fsrc, " * color.a + ");
|
| 1147 | + String_Append(fsrc, arg2.c_str());
|
| 1148 | + String_Append(fsrc, " * (1.0-color.a);\n");
|
1019 | 1149 | break;
|
1020 | 1150 | }
|
1021 | 1151 | }
|
— | — | @@ -1023,25 +1153,25 @@ |
1024 | 1154 | switch((id>>3)&7)
|
1025 | 1155 | {
|
1026 | 1156 | case 0:
|
1027 | | - fsrc->append("discard;\n");
|
| 1157 | + String_Append(fsrc, "discard;\n");
|
1028 | 1158 | break;
|
1029 | 1159 | case 1:
|
1030 | | - fsrc->append("if(int(color.a * 255.5) >= alpharef) discard;");
|
| 1160 | + String_Append(fsrc, "if(int(color.a * 255.5) >= alpharef) discard;");
|
1031 | 1161 | break;
|
1032 | 1162 | case 2:
|
1033 | | - fsrc->append("if(int(color.a * 255.5) != alpharef) discard;");
|
| 1163 | + String_Append(fsrc, "if(int(color.a * 255.5) != alpharef) discard;");
|
1034 | 1164 | break;
|
1035 | 1165 | case 3:
|
1036 | | - fsrc->append("if(int(color.a * 255.5) > alpharef) discard;");
|
| 1166 | + String_Append(fsrc, "if(int(color.a * 255.5) > alpharef) discard;");
|
1037 | 1167 | break;
|
1038 | 1168 | case 4:
|
1039 | | - fsrc->append("if(int(color.a * 255.5) <= alpharef) discard;");
|
| 1169 | + String_Append(fsrc, "if(int(color.a * 255.5) <= alpharef) discard;");
|
1040 | 1170 | break;
|
1041 | 1171 | case 5:
|
1042 | | - fsrc->append("if(int(color.a * 255.5) == alpharef) discard;");
|
| 1172 | + String_Append(fsrc, "if(int(color.a * 255.5) == alpharef) discard;");
|
1043 | 1173 | break;
|
1044 | 1174 | case 6:
|
1045 | | - fsrc->append("if(int(color.a * 255.5) < alpharef) discard;");
|
| 1175 | + String_Append(fsrc, "if(int(color.a * 255.5) < alpharef) discard;");
|
1046 | 1176 | break;
|
1047 | 1177 | case 7:
|
1048 | 1178 | default:
|
— | — | @@ -1048,35 +1178,35 @@ |
1049 | 1179 | break;
|
1050 | 1180 | }
|
1051 | 1181 | }
|
1052 | | - if(vertexfog && !pixelfog) fsrc->append(op_fogblend);
|
| 1182 | + if(vertexfog && !pixelfog) String_Append(fsrc, op_fogblend);
|
1053 | 1183 | if(pixelfog)
|
1054 | 1184 | {
|
1055 | | - fsrc->append(op_fogcoordstandardpixel);
|
| 1185 | + String_Append(fsrc, op_fogcoordstandardpixel);
|
1056 | 1186 | switch(pixelfog)
|
1057 | 1187 | {
|
1058 | 1188 | case D3DFOG_LINEAR:
|
1059 | | - fsrc->append(op_foglinearpixel);
|
| 1189 | + String_Append(fsrc, op_foglinearpixel);
|
1060 | 1190 | break;
|
1061 | 1191 | case D3DFOG_EXP:
|
1062 | | - fsrc->append(op_fogexppixel);
|
| 1192 | + String_Append(fsrc, op_fogexppixel);
|
1063 | 1193 | break;
|
1064 | 1194 | case D3DFOG_EXP2:
|
1065 | | - fsrc->append(op_fogexp2pixel);
|
| 1195 | + String_Append(fsrc, op_fogexp2pixel);
|
1066 | 1196 | break;
|
1067 | 1197 | }
|
1068 | | - fsrc->append(op_fogclamp);
|
1069 | | - fsrc->append(op_fogblend);
|
| 1198 | + String_Append(fsrc, op_fogclamp);
|
| 1199 | + String_Append(fsrc, op_fogblend);
|
1070 | 1200 | }
|
1071 | | - if(((id>>61)&1) && !vertexfog && !pixelfog) fsrc->append(op_fogassign);
|
1072 | | - fsrc->append(op_colorfragout);
|
1073 | | - fsrc->append(mainend);
|
| 1201 | + if(((id>>61)&1) && !vertexfog && !pixelfog) String_Append(fsrc, op_fogassign);
|
| 1202 | + String_Append(fsrc, op_colorfragout);
|
| 1203 | + String_Append(fsrc, mainend);
|
1074 | 1204 | #ifdef _DEBUG
|
1075 | 1205 | OutputDebugStringA("Fragment shader:\n");
|
1076 | | - OutputDebugStringA(fsrc->c_str());
|
| 1206 | + OutputDebugStringA(fsrc->ptr);
|
1077 | 1207 | OutputDebugStringA("\nCompiling fragment shader:\n");
|
1078 | 1208 | #endif
|
1079 | 1209 | genshaders[index].shader.fs = ext->glCreateShader(GL_FRAGMENT_SHADER);
|
1080 | | - src = fsrc->c_str();
|
| 1210 | + src = fsrc->ptr;
|
1081 | 1211 | srclen = strlen(src);
|
1082 | 1212 | ext->glShaderSource(genshaders[index].shader.fs,1,&src,&srclen);
|
1083 | 1213 | ext->glCompileShader(genshaders[index].shader.fs);
|
Index: ddraw/ShaderGen3D.h |
— | — | @@ -22,8 +22,8 @@ |
23 | 23 | {
|
24 | 24 | GLint vs;
|
25 | 25 | GLint fs;
|
26 | | - string *vsrc;
|
27 | | - string *fsrc;
|
| 26 | + STRING vsrc;
|
| 27 | + STRING fsrc;
|
28 | 28 | GLint prog;
|
29 | 29 | GLint attribs[42];
|
30 | 30 | GLint uniforms[256];
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -28,8 +28,6 @@ |
29 | 29 | #include "glDirect3DLight.h"
|
30 | 30 | #include "ddraw.h"
|
31 | 31 | #include "scalers.h"
|
32 | | -#include <string>
|
33 | | -using namespace std;
|
34 | 32 | #include "ShaderGen3D.h"
|
35 | 33 | #include "matrix.h"
|
36 | 34 |
|