50
50
#include " r_draw.h"
51
51
#include " r_image.h"
52
52
#include " r_modes.h"
53
+ #include " r_units.h"
53
54
#include " r_wipe.h"
54
55
#include " stb_sprintf.h"
55
56
#include " w_files.h"
@@ -572,25 +573,24 @@ static void CalcSizes()
572
573
(FNSZ / console_font->image_character_height_ ));
573
574
}
574
575
575
- static void SolidBox (int x, int y, int w, int h, RGBAColor col, float alpha)
576
+ static void SolidBox (float x, float y, float w, float h, RGBAColor col, float alpha)
576
577
{
577
- if (alpha < 0 . 99f )
578
- glEnable (GL_BLEND );
578
+ RendererVertex *glvert = BeginRenderUnit (GL_QUADS, 4 , GL_MODULATE, 0 , (GLuint) kTextureEnvironmentDisable , 0 ,
579
+ 0 , alpha < 0 . 99f ? kBlendingAlpha : kBlendingNone );
579
580
580
581
sg_color sgcol = sg_make_color_1i (col);
581
-
582
- glColor4f (sgcol.r , sgcol.g , sgcol.b , alpha);
583
-
584
- glBegin (GL_QUADS);
585
-
586
- glVertex2i (x, y);
587
- glVertex2i (x, y + h);
588
- glVertex2i (x + w, y + h);
589
- glVertex2i (x + w, y);
590
-
591
- glEnd ();
592
-
593
- glDisable (GL_BLEND);
582
+ sgcol.a = alpha;
583
+
584
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
585
+ glvert++->position = {{x, y, 0 }};
586
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
587
+ glvert++->position = {{x, y + h, 0 }};
588
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
589
+ glvert++->position = {{x + w, y + h, 0 }};
590
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
591
+ glvert->position = {{x + w, y, 0 }};
592
+
593
+ EndRenderUnit (4 );
594
594
}
595
595
596
596
static void HorizontalLine (int y, RGBAColor col)
@@ -600,15 +600,11 @@ static void HorizontalLine(int y, RGBAColor col)
600
600
SolidBox (0 , y, current_screen_width - 1 , 1 , col, alpha);
601
601
}
602
602
603
- static void DrawChar (int x, int y, char ch, RGBAColor col)
603
+ static void DrawChar (float x, float y, char ch, RendererVertex *glvert, sg_color * col)
604
604
{
605
605
if (x + FNSZ < 0 )
606
606
return ;
607
607
608
- sg_color sgcol = sg_make_color_1i (col);
609
-
610
- glColor4f (sgcol.r , sgcol.g , sgcol.b , 1 .0f );
611
-
612
608
if (console_font->definition_ ->type_ == kFontTypeTrueType )
613
609
{
614
610
float chwidth = console_font->CharWidth (ch);
@@ -618,16 +614,18 @@ static void DrawChar(int x, int y, char ch, RGBAColor col)
618
614
float y_adjust = console_font->truetype_glyph_map_ .at ((uint8_t )ch).y_shift [current_font_size] * FNSZ_ratio;
619
615
float height = console_font->truetype_glyph_map_ .at ((uint8_t )ch).height [current_font_size] * FNSZ_ratio;
620
616
stbtt_aligned_quad *q = console_font->truetype_glyph_map_ .at ((uint8_t )ch).character_quad [current_font_size];
621
- glBegin (GL_POLYGON);
622
- glTexCoord2f (q->s0 , q->t0 );
623
- glVertex2f (x + x_adjust, y - y_adjust);
624
- glTexCoord2f (q->s1 , q->t0 );
625
- glVertex2f (x + x_adjust + width, y - y_adjust);
626
- glTexCoord2f (q->s1 , q->t1 );
627
- glVertex2f (x + x_adjust + width, y - y_adjust - height);
628
- glTexCoord2f (q->s0 , q->t1 );
629
- glVertex2f (x + x_adjust, y - y_adjust - height);
630
- glEnd ();
617
+ memcpy (&glvert->rgba_color , col, 4 * sizeof (float ));
618
+ glvert->position = {{x + x_adjust, y - y_adjust, 0 }};
619
+ glvert++->texture_coordinates [0 ] = {{q->s0 , q->t0 }};
620
+ memcpy (&glvert->rgba_color , col, 4 * sizeof (float ));
621
+ glvert->position = {{x + x_adjust + width, y - y_adjust, 0 }};
622
+ glvert++->texture_coordinates [0 ] = {{q->s1 , q->t0 }};
623
+ memcpy (&glvert->rgba_color , col, 4 * sizeof (float ));
624
+ glvert->position = {{x + x_adjust + width, y - y_adjust - height, 0 }};
625
+ glvert++->texture_coordinates [0 ] = {{q->s1 , q->t1 }};
626
+ memcpy (&glvert->rgba_color , col, 4 * sizeof (float ));
627
+ glvert->position = {{x + x_adjust, y - y_adjust - height, 0 }};
628
+ glvert->texture_coordinates [0 ] = {{q->s0 , q->t1 }};
631
629
return ;
632
630
}
633
631
@@ -639,51 +637,45 @@ static void DrawChar(int x, int y, char ch, RGBAColor col)
639
637
float ty1 = (py)*console_font->font_image_ ->height_ratio_ ;
640
638
float ty2 = (py + 1 ) * console_font->font_image_ ->height_ratio_ ;
641
639
642
- glBegin (GL_POLYGON);
643
-
644
- glTexCoord2f (tx1, ty1);
645
- glVertex2i (x, y);
646
-
647
- glTexCoord2f (tx1, ty2);
648
- glVertex2i (x, y + FNSZ);
649
-
650
- glTexCoord2f (tx2, ty2);
651
- glVertex2i (x + FNSZ, y + FNSZ);
652
-
653
- glTexCoord2f (tx2, ty1);
654
- glVertex2i (x + FNSZ, y);
655
-
656
- glEnd ();
640
+ memcpy (&glvert->rgba_color , col, 4 * sizeof (float ));
641
+ glvert->position = {{x, y, 0 }};
642
+ glvert++->texture_coordinates [0 ] = {{tx1, ty1}};
643
+ memcpy (&glvert->rgba_color , col, 4 * sizeof (float ));
644
+ glvert->position = {{x, y + FNSZ, 0 }};
645
+ glvert++->texture_coordinates [0 ] = {{tx1, ty2}};
646
+ memcpy (&glvert->rgba_color , col, 4 * sizeof (float ));
647
+ glvert->position = {{x + FNSZ, y + FNSZ, 0 }};
648
+ glvert++->texture_coordinates [0 ] = {{tx2, ty2}};
649
+ memcpy (&glvert->rgba_color , col, 4 * sizeof (float ));
650
+ glvert->position = {{x + FNSZ, y, 0 }};
651
+ glvert->texture_coordinates [0 ] = {{tx2, ty1}};
657
652
}
658
653
659
- static void DrawEndoomChar (float x, float y, char ch, RGBAColor col, RGBAColor col2, bool blink, int enwidth)
654
+ static void DrawEndoomChar (float x, float y, char ch, RGBAColor col, RGBAColor col2, bool blink, int enwidth, GLuint tex_id )
660
655
{
661
656
if (x + FNSZ < 0 )
662
657
return ;
663
658
664
659
sg_color sgcol = sg_make_color_1i (col2);
660
+ sgcol.a = 1 .0f ;
665
661
666
- glDisable (GL_TEXTURE_2D);
667
-
668
- glColor4f (sgcol.r , sgcol.g , sgcol.b , 1 .0f );
669
-
670
- glBegin (GL_QUADS);
671
-
672
- glVertex2i (x - (enwidth / 2 ), y);
673
-
674
- glVertex2i (x - (enwidth / 2 ), y + FNSZ);
675
-
676
- glVertex2i (x + (enwidth / 2 ), y + FNSZ);
662
+ RendererVertex *glvert = BeginRenderUnit (GL_QUADS, 4 , GL_MODULATE, 0 , (GLuint)kTextureEnvironmentDisable , 0 ,
663
+ 0 , kBlendingNone );
677
664
678
- glVertex2i (x + (enwidth / 2 ), y);
665
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
666
+ glvert++->position = {{x - (enwidth / 2 ), y}};
667
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
668
+ glvert++->position = {{x - (enwidth / 2 ), y + FNSZ}};
669
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
670
+ glvert++->position = {{x + (enwidth / 2 ), y + FNSZ}};
671
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
672
+ glvert->position = {{x + (enwidth / 2 ), y}};
679
673
680
- glEnd ();
681
674
682
- glEnable (GL_TEXTURE_2D );
675
+ EndRenderUnit ( 4 );
683
676
684
677
sgcol = sg_make_color_1i (col);
685
-
686
- glColor4f (sgcol.r , sgcol.g , sgcol.b , 1 .0f );
678
+ sgcol.a = 1 .0f ;
687
679
688
680
if (blink && console_cursor >= 16 )
689
681
ch = 0x20 ;
@@ -697,49 +689,47 @@ static void DrawEndoomChar(float x, float y, char ch, RGBAColor col, RGBAColor c
697
689
float ty1 = (py)*endoom_font->font_image_ ->height_ratio_ ;
698
690
float ty2 = (py + 1 ) * endoom_font->font_image_ ->height_ratio_ ;
699
691
700
- glBegin (GL_POLYGON);
701
-
702
- glTexCoord2f (tx1, ty1);
703
- glVertex2i (x - enwidth, y);
704
-
705
- glTexCoord2f (tx1, ty2);
706
- glVertex2i (x - enwidth, y + FNSZ);
707
-
708
- glTexCoord2f (tx2, ty2);
709
- glVertex2i (x + enwidth, y + FNSZ);
710
-
711
- glTexCoord2f (tx2, ty1);
712
- glVertex2i (x + enwidth, y);
713
-
714
- glEnd ();
692
+ glvert = BeginRenderUnit (GL_POLYGON, 4 , GL_MODULATE, tex_id, (GLuint)kTextureEnvironmentDisable , 0 ,
693
+ 0 , kBlendingMasked );
694
+
695
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
696
+ glvert->texture_coordinates [0 ] = {{tx1, ty1}};
697
+ glvert++->position = {{x - enwidth, y}};
698
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
699
+ glvert->texture_coordinates [0 ] = {{tx1, ty2}};
700
+ glvert++->position = {{x - enwidth, y + FNSZ}};
701
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
702
+ glvert->texture_coordinates [0 ] = {{tx2, ty2}};
703
+ glvert++->position = {{x + enwidth, y + FNSZ}};
704
+ memcpy (&glvert->rgba_color , &sgcol, 4 * sizeof (float ));
705
+ glvert->texture_coordinates [0 ] = {{tx2, ty1}};
706
+ glvert->position = {{x + enwidth, y}};
707
+
708
+ EndRenderUnit (4 );
715
709
}
716
710
717
711
// writes the text on coords (x,y) of the console
718
- static void DrawText (int x, int y, const char *s, RGBAColor col)
712
+ static void DrawText (float x, float y, const char *s, RGBAColor col)
719
713
{
714
+ GLuint tex_id = 0 ;
715
+ BlendingMode blend = kBlendingNone ;
716
+
720
717
if (console_font->definition_ ->type_ == kFontTypeImage )
721
718
{
722
719
// Always whiten the font when used with console output
723
- GLuint tex_id = ImageCache (console_font->font_image_ , true , (const Colormap *)0 , true );
724
-
725
- glEnable (GL_TEXTURE_2D);
726
- glBindTexture (GL_TEXTURE_2D, tex_id);
727
-
728
- glEnable (GL_BLEND);
729
- glEnable (GL_ALPHA_TEST);
730
- glAlphaFunc (GL_GREATER, 0 );
720
+ tex_id = ImageCache (console_font->font_image_ , true , (const Colormap *)0 , true );
721
+ blend = kBlendingMasked ;
731
722
}
732
723
else if (console_font->definition_ ->type_ == kFontTypeTrueType )
733
724
{
734
- glEnable (GL_BLEND);
735
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
736
- glEnable (GL_TEXTURE_2D);
737
725
if ((image_smoothing &&
738
726
console_font->definition_ ->truetype_smoothing_ == FontDefinition::kTrueTypeSmoothOnDemand ) ||
739
727
console_font->definition_ ->truetype_smoothing_ == FontDefinition::kTrueTypeSmoothAlways )
740
- glBindTexture (GL_TEXTURE_2D, console_font->truetype_smoothed_texture_id_ [current_font_size]) ;
728
+ tex_id = console_font->truetype_smoothed_texture_id_ [current_font_size];
741
729
else
742
- glBindTexture (GL_TEXTURE_2D, console_font->truetype_texture_id_ [current_font_size]);
730
+ tex_id = console_font->truetype_texture_id_ [current_font_size];
731
+
732
+ blend = kBlendingAlpha ;
743
733
}
744
734
745
735
bool draw_cursor = false ;
@@ -750,10 +740,18 @@ static void DrawText(int x, int y, const char *s, RGBAColor col)
750
740
draw_cursor = true ;
751
741
}
752
742
743
+ sg_color sgcol = sg_make_color_1i (col);
744
+ RendererVertex *glvert = nullptr ;
745
+
753
746
int pos = 0 ;
754
747
for (; *s; s++, pos++)
755
748
{
756
- DrawChar (x, y, *s, col);
749
+ glvert = BeginRenderUnit (GL_POLYGON, 4 , GL_MODULATE, tex_id, (GLuint)kTextureEnvironmentDisable , 0 ,
750
+ 0 , blend);
751
+
752
+ DrawChar (x, y, *s, glvert, &sgcol);
753
+
754
+ EndRenderUnit (4 );
757
755
758
756
if (console_font->definition_ ->type_ == kFontTypeTrueType )
759
757
{
@@ -767,7 +765,13 @@ static void DrawText(int x, int y, const char *s, RGBAColor col)
767
765
768
766
if (pos == input_position && draw_cursor)
769
767
{
770
- DrawChar (x, y, 95 , col);
768
+ glvert = BeginRenderUnit (GL_POLYGON, 4 , GL_MODULATE, tex_id, (GLuint)kTextureEnvironmentDisable , 0 ,
769
+ 0 , blend);
770
+
771
+ DrawChar (x, y, 95 , glvert, &sgcol);
772
+
773
+ EndRenderUnit (4 );
774
+
771
775
draw_cursor = false ;
772
776
}
773
777
@@ -778,11 +782,14 @@ static void DrawText(int x, int y, const char *s, RGBAColor col)
778
782
}
779
783
780
784
if (draw_cursor)
781
- DrawChar (x, y, 95 , col);
785
+ {
786
+ glvert = BeginRenderUnit (GL_POLYGON, 4 , GL_MODULATE, tex_id, (GLuint)kTextureEnvironmentDisable , 0 ,
787
+ 0 , blend);
782
788
783
- glDisable (GL_TEXTURE_2D);
784
- glDisable (GL_ALPHA_TEST);
785
- glDisable (GL_BLEND);
789
+ DrawChar (x, y, 95 , glvert, &sgcol);
790
+
791
+ EndRenderUnit (4 );
792
+ }
786
793
}
787
794
788
795
static void EndoomDrawText (int x, int y, ConsoleLine *endoom_line)
@@ -793,29 +800,18 @@ static void EndoomDrawText(int x, int y, ConsoleLine *endoom_line)
793
800
int enwidth = RoundToInteger ((float )endoom_font->image_monospace_width_ *
794
801
((float )FNSZ / endoom_font->image_monospace_width_ ) / 2 );
795
802
796
- glEnable (GL_TEXTURE_2D);
797
- glBindTexture (GL_TEXTURE_2D, tex_id);
798
-
799
- glEnable (GL_BLEND);
800
- glEnable (GL_ALPHA_TEST);
801
- glAlphaFunc (GL_GREATER, 0 );
802
-
803
803
for (int i = 0 ; i < 80 ; i++)
804
804
{
805
805
uint8_t info = endoom_line->endoom_bytes_ .at (i);
806
806
807
807
DrawEndoomChar (x, y, endoom_line->line_ .at (i), endoom_colors[info & 15 ], endoom_colors[(info >> 4 ) & 7 ],
808
- info & 128 , enwidth);
808
+ info & 128 , enwidth, tex_id );
809
809
810
810
x += enwidth;
811
811
812
812
if (x >= current_screen_width)
813
813
break ;
814
814
}
815
-
816
- glDisable (GL_TEXTURE_2D);
817
- glDisable (GL_ALPHA_TEST);
818
- glDisable (GL_BLEND);
819
815
}
820
816
821
817
void ConsoleSetupFont (void )
@@ -860,6 +856,8 @@ void ConsoleDrawer(void)
860
856
861
857
// -- background --
862
858
859
+ StartUnitBatch (false );
860
+
863
861
int CON_GFX_HT = (current_screen_height * 3 / 5 );
864
862
865
863
int y = current_screen_height;
@@ -939,6 +937,8 @@ void ConsoleDrawer(void)
939
937
if (y >= current_screen_height)
940
938
break ;
941
939
}
940
+
941
+ FinishUnitBatch ();
942
942
}
943
943
944
944
static void GotoEndOfLine (void )
@@ -1624,6 +1624,8 @@ void ConsoleShowFPS(void)
1624
1624
if (debug_fps.d_ == 0 )
1625
1625
return ;
1626
1626
1627
+ StartUnitBatch (false );
1628
+
1627
1629
ConsoleSetupFont ();
1628
1630
1629
1631
// -AJA- 2022: reworked for better accuracy, ability to show WORST time
@@ -1723,13 +1725,17 @@ void ConsoleShowFPS(void)
1723
1725
stbsp_sprintf (textbuf, " %i texture" , ec_frame_stats.draw_texture_change );
1724
1726
DrawText (x, y, textbuf, SG_WEB_GRAY_RGBA32);
1725
1727
}
1728
+
1729
+ FinishUnitBatch ();
1726
1730
}
1727
1731
1728
1732
void ConsoleShowPosition (void )
1729
1733
{
1730
1734
if (debug_position.d_ <= 0 )
1731
1735
return ;
1732
1736
1737
+ StartUnitBatch (false );
1738
+
1733
1739
ConsoleSetupFont ();
1734
1740
1735
1741
Player *p = players[display_player];
@@ -1779,6 +1785,8 @@ void ConsoleShowPosition(void)
1779
1785
y -= FNSZ;
1780
1786
stbsp_sprintf (textbuf, " sub: %d" , (int )(p->map_object_ ->subsector_ - level_subsectors));
1781
1787
DrawText (x, y, textbuf, SG_WEB_GRAY_RGBA32);
1788
+
1789
+ FinishUnitBatch ();
1782
1790
}
1783
1791
1784
1792
void ConsolePrintEndoom ()
0 commit comments