1
1
#include " FrameMan.h"
2
2
3
+ #include " SDL3/SDL_surface.h"
3
4
#include " WindowMan.h"
4
5
#include " PostProcessMan.h"
5
6
#include " PresetMan.h"
34
35
using namespace RTE ;
35
36
36
37
void BitmapDeleter::operator ()(BITMAP* bitmap) const { destroy_bitmap (bitmap); }
37
- void SurfaceDeleter::operator ()(SDL_Surface* surface) const { SDL_FreeSurface (surface); }
38
+ void SurfaceDeleter::operator ()(SDL_Surface* surface) const { SDL_DestroySurface (surface); }
38
39
39
40
const std::array<std::function<void (int r, int g, int b, int a)>, DrawBlendMode::BlendModeCount> FrameMan::c_BlenderSetterFunctions = {
40
41
nullptr , // NoBlend obviously has no blender, but we want to keep the indices matching with the enum.
@@ -157,17 +158,15 @@ int FrameMan::CreateBackBuffers() {
157
158
m_PlayerScreen = m_BackBuffer;
158
159
}
159
160
160
- m_ScreenDumpBuffer = std::unique_ptr<SDL_Surface, SurfaceDeleter>(
161
- SDL_CreateRGBSurfaceWithFormat (0 , m_BackBuffer8->w , m_BackBuffer8->h , 24 , SDL_PIXELFORMAT_RGB24)
162
- );
161
+ m_ScreenDumpBuffer = std::unique_ptr<SDL_Surface, SurfaceDeleter>(SDL_CreateSurface (m_BackBuffer8->w , m_BackBuffer8->h , SDL_PIXELFORMAT_RGB24));
163
162
164
163
return 0 ;
165
164
}
166
165
167
166
void FrameMan::CreatePresetColorTables () {
168
167
// Create RGB lookup table that supposedly speeds up calculation of other color tables.
169
- // create_rgb_table(&m_RGBTable, m_DefaultPalette, nullptr);
170
- // rgb_map = &m_RGBTable;
168
+ // create_rgb_table(&m_RGBTable, m_DefaultPalette, nullptr);
169
+ // rgb_map = &m_RGBTable;
171
170
172
171
// Create transparency color tables. Tables for other blend modes will be created on demand.
173
172
int transparencyPresetCount = BlendAmountLimits::MaxBlend / c_BlendAmountStep;
@@ -410,7 +409,7 @@ void FrameMan::SetBlendMode(DrawBlendMode blendMode) {
410
409
rlSetBlendMode (RL_BLEND_ALPHA);
411
410
const Shader* dissolve = dynamic_cast <const Shader*>(g_PresetMan.GetEntityPreset (" Shader" , " Dissolve" ));
412
411
dissolve->Begin ();
413
- GLint paletteLoc = dissolve->GetUniformLocation (" rtePalette" );
412
+ GLint paletteLoc = dissolve->GetUniformLocation (" rtePalette" );
414
413
rlSetUniformSampler (paletteLoc, g_PostProcessMan.GetPaletteTexture ());
415
414
break ;
416
415
}
@@ -491,11 +490,10 @@ bool FrameMan::LoadPalette(const std::string& palettePath) {
491
490
SDL_Palette* palette = SDL_GetSurfacePalette (paletteImage);
492
491
for (size_t i = 0 ; i < 256 ; i++) {
493
492
m_Palette[i] = {
494
- palette->colors [i].r ,
495
- palette->colors [i].g ,
496
- palette->colors [i].b ,
497
- 0
498
- };
493
+ palette->colors [i].r ,
494
+ palette->colors [i].g ,
495
+ palette->colors [i].b ,
496
+ 0 };
499
497
}
500
498
SDL_DestroySurface (paletteImage);
501
499
@@ -518,7 +516,7 @@ int FrameMan::SaveBitmap(SaveBitmapMode modeToSave, const std::string& nameBase,
518
516
set_palette (m_DefaultPalette);
519
517
520
518
// TODO: Remove this once GCC13 is released and switched to. std::format and std::chrono::time_zone are not part of latest libstdc++.
521
- #if defined(__GNUC__) && (__GNUC__ < 13 || defined(__APPLE__)) // FIXME: macOS for some reason builds with incorrect iconv in CI which breaks format, could not debug.
519
+ #if defined(__GNUC__) && (__GNUC__ < 13 || defined(__APPLE__)) // FIXME: macOS for some reason builds with incorrect iconv in CI which breaks format, could not debug.
522
520
std::chrono::time_point now = std::chrono::system_clock::now ();
523
521
time_t currentTime = std::chrono::system_clock::to_time_t (now);
524
522
tm* localCurrentTime = std::localtime (¤tTime);
@@ -548,15 +546,15 @@ int FrameMan::SaveBitmap(SaveBitmapMode modeToSave, const std::string& nameBase,
548
546
SaveScreenToBitmap ();
549
547
550
548
// Make a copy of the buffer because it may be overwritten mid thread and everything will be on fire.
551
- SDL_Surface* saveSurface = SDL_ConvertSurfaceFormat (m_ScreenDumpBuffer.get (), m_ScreenDumpBuffer->format -> format , 0 );
549
+ SDL_Surface* saveSurface = SDL_ConvertSurface (m_ScreenDumpBuffer.get (), m_ScreenDumpBuffer->format );
552
550
auto saveScreenDump = [fullFileName](SDL_Surface* bitmapToSaveCopy) {
553
551
// nullptr for the PALETTE parameter here because we're saving a 24bpp file and it's irrelevant.
554
552
if (IMG_SavePNG (bitmapToSaveCopy, fullFileName.c_str ()) == 0 ) {
555
553
g_ConsoleMan.PrintString (" SYSTEM: Screen was dumped to: " + fullFileName);
556
554
} else {
557
555
g_ConsoleMan.PrintString (" ERROR: Unable to save bitmap to: " + fullFileName);
558
556
}
559
- // SDL_FreeSurface(bitmapToSaveCopy);
557
+ // SDL_FreeSurface(bitmapToSaveCopy);
560
558
};
561
559
std::thread saveThread (saveScreenDump, saveSurface);
562
560
saveThread.detach ();
@@ -586,21 +584,19 @@ int FrameMan::SaveBitmap(SaveBitmapMode modeToSave, const std::string& nameBase,
586
584
587
585
BITMAP* depthConvertBitmap = create_bitmap_ex (24 , m_WorldDumpBuffer->w , m_WorldDumpBuffer->h );
588
586
blit (m_WorldDumpBuffer.get (), depthConvertBitmap, 0 , 0 , 0 , 0 , m_WorldDumpBuffer->w , m_WorldDumpBuffer->h );
589
- SDL_Surface* saveSurface = SDL_CreateRGBSurfaceWithFormatFrom (
590
- depthConvertBitmap->dat ,
591
- depthConvertBitmap->w ,
592
- depthConvertBitmap->h ,
593
- 24 ,
594
- 3 ,
595
- SDL_PIXELFORMAT_RGB24
596
- );
587
+ SDL_Surface* saveSurface = SDL_CreateSurfaceFrom (
588
+ depthConvertBitmap->w ,
589
+ depthConvertBitmap->h ,
590
+ SDL_PIXELFORMAT_RGB24,
591
+ depthConvertBitmap->dat ,
592
+ 3 );
597
593
598
594
if (IMG_SavePNG (saveSurface, fullFileName.c_str ()) == 0 ) {
599
595
g_ConsoleMan.PrintString (" SYSTEM: World was dumped to: " + fullFileName);
600
596
saveSuccess = true ;
601
597
}
602
598
destroy_bitmap (depthConvertBitmap);
603
- // SDL_FreeSurface (saveSurface);
599
+ SDL_DestroySurface (saveSurface);
604
600
}
605
601
break ;
606
602
default :
@@ -635,12 +631,16 @@ void FrameMan::SaveScreenToBitmap() {
635
631
636
632
int FrameMan::SaveIndexedPNG (const char * fileName, BITMAP* bitmapToSave) const {
637
633
set_palette (m_DefaultPalette);
638
- SDL_Surface* surface = SDL_CreateRGBSurfaceWithFormatFrom (bitmapToSave->dat , bitmapToSave->w , bitmapToSave->h , bitmap_color_depth (bitmapToSave), bitmap_color_depth (bitmapToSave)/8 , SDL_PIXELFORMAT_INDEX8);
634
+ SDL_Surface* surface = SDL_CreateSurfaceFrom (bitmapToSave->w ,
635
+ bitmapToSave->h ,
636
+ SDL_PIXELFORMAT_INDEX8,
637
+ bitmapToSave->dat ,
638
+ bitmap_color_depth (bitmapToSave) / 8 );
639
639
SDL_Palette* pal = ContentFile::DefaultPaletteToSDL ();
640
640
SDL_SetSurfacePalette (surface, pal);
641
641
int saveResult = IMG_SavePNG (surface, fileName);
642
- SDL_FreePalette (pal);
643
- SDL_FreeSurface (surface);
642
+ SDL_DestroyPalette (pal);
643
+ SDL_DestroySurface (surface);
644
644
645
645
return saveResult;
646
646
}
@@ -809,7 +809,7 @@ void FrameMan::Draw() {
809
809
ZoneScopedN (" Draw" );
810
810
TracyGpuZone (" FrameMan::Draw" );
811
811
812
- // rlSetShader(rlGetShaderIdDefault(), rlGetShaderLocsDefault());
812
+ // rlSetShader(rlGetShaderIdDefault(), rlGetShaderLocsDefault());
813
813
Shader backgroundShader;
814
814
g_PresetMan.GetEntityPreset (" Shader" , " Background" )->Clone (&backgroundShader);
815
815
glClearColor (0 .0f , 0 .0f , 0 .0f , 0 .0f );
@@ -841,7 +841,7 @@ void FrameMan::Draw() {
841
841
rlSetUniformSampler (backgroundShader.GetUniformLocation (" rtePalette" ), g_PostProcessMan.GetPaletteTexture ());
842
842
backgroundShader.SetInt (" drawMasked" , 1 );
843
843
844
- // rlSetUniformSampler(backgroundShader.GetUniformLocation("rtePalette"), g_PostProcessMan.GetPaletteTexture());
844
+ // rlSetUniformSampler(backgroundShader.GetUniformLocation("rtePalette"), g_PostProcessMan.GetPaletteTexture());
845
845
BITMAP* drawScreen = (screenCount == 1 ) ? m_BackBuffer8.get () : m_PlayerScreen8.get ();
846
846
BITMAP* drawScreenGUI = (screenCount == 1 ) ? m_BackBuffer8.get () : m_PlayerScreen8.get ();
847
847
// Need to clear the backbuffers because Scene background layers can be too small to fill the whole backbuffer or drawn masked resulting in artifacts from the previous frame.
@@ -868,7 +868,6 @@ void FrameMan::Draw() {
868
868
// Draw the scene
869
869
g_SceneMan.Draw (drawScreen, drawScreenGUI, targetPos);
870
870
871
-
872
871
g_PrimitiveMan.DrawPrimitives (playerScreen, drawScreenGUI, targetPos);
873
872
874
873
// Get only the scene-relative post effects that affect this player's screen
@@ -919,7 +918,7 @@ void FrameMan::Draw() {
919
918
}
920
919
921
920
rlEnableDepthTest ();
922
- rlZDepth (c_GuiDepth- 1 .0f );
921
+ rlZDepth (c_GuiDepth - 1 .0f );
923
922
g_GLResourceMan.UpdateDynamicBitmap (m_BackBuffer8.get (), true );
924
923
backgroundShader.Begin ();
925
924
backgroundShader.Enable ();
@@ -1001,14 +1000,14 @@ void FrameMan::DrawScreenFlash(int playerScreen, BITMAP* playerGUIBitmap) {
1001
1000
1002
1001
rlColor4ub (m_FlashScreenColor[playerScreen], 0 , 0 , 50 );
1003
1002
rlVertex2f (playerGUIBitmap->w * .25f , playerGUIBitmap->h * .25f );
1004
- rlVertex2f (playerGUIBitmap->w - playerGUIBitmap->w * .25f , playerGUIBitmap->h *0 .25f );
1003
+ rlVertex2f (playerGUIBitmap->w - playerGUIBitmap->w * .25f , playerGUIBitmap->h * 0 .25f );
1005
1004
rlColor4ub (m_FlashScreenColor[playerScreen], 0 , 0 , 255 );
1006
1005
rlVertex2f (playerGUIBitmap->w , 0 .0f );
1007
1006
rlVertex2f (0 .0f , 0 .0f );
1008
1007
1009
1008
rlColor4ub (m_FlashScreenColor[playerScreen], 0 , 0 , 50 );
1010
1009
rlVertex2f (playerGUIBitmap->w * .25f , playerGUIBitmap->h - playerGUIBitmap->h * .25f );
1011
- rlVertex2f (playerGUIBitmap->w * .25f , playerGUIBitmap->h *0 .25f );
1010
+ rlVertex2f (playerGUIBitmap->w * .25f , playerGUIBitmap->h * 0 .25f );
1012
1011
rlColor4ub (m_FlashScreenColor[playerScreen], 0 , 0 , 255 );
1013
1012
rlVertex2f (0 .0f , 0 .0f );
1014
1013
rlVertex2f (0 .0f , playerGUIBitmap->h );
0 commit comments