Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we destroy the SDL_TTF texture, otherwise we leak #64

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ endif()
option(DAEDALUS_PSP_USE_ME "Use the Media Engine" ON)
option(DAEDALUS_PSP_USE_VFPU "Enable VFPU Instructions" ON)
option(DAEDALUS_SIM_DOUBLES "Simulate Doubles" ON)
option(DAEDALUS_SDL "Enable SDL" ON)
option(DAEDALUS_SDL "Enable SDL" OFF)
elseif(UNIX)
option(DAEDALUS_SDL "SDL Build" ON)
option(DAEDALUS_ENABLE_DYNAREC "Enable Dynamic Recompilation, Disable if system not supported" OFF)
Expand Down
1 change: 1 addition & 0 deletions Source/SysGL/Graphics/DrawTextSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ u32 CDrawText::Render(EFont font_type, s32 x, s32 y, float scale, const char *p_
SDL_RenderCopy(gSdlRenderer, Message, NULL, &Message_rect);

SDL_FreeSurface(surface);
SDL_DestroyTexture(Message);

return Message_rect.w;
}
Expand Down
186 changes: 79 additions & 107 deletions Source/SysGL/HLEGraphics/RendererGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,139 +866,111 @@ inline u32 MakeMirror(u32 mirror, u32 m)
{
return (mirror && m) ? (1<<m) : 0;
}
void RendererGL::PrepareRenderState(const float (&mat_project)[16], bool disable_zbuffer) {
DAEDALUS_PROFILE("RendererGL::PrepareRenderState");

if (disable_zbuffer) {
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
} else {
if (gRDPOtherMode.zmode == 3) {
glPolygonOffset(-1.0, -1.0);
} else {
glPolygonOffset(0.0, 0.0);
}

if ((mTnL.Flags.Zbuffer & gRDPOtherMode.z_cmp) | gRDPOtherMode.z_upd) {
glEnable(GL_DEPTH_TEST);
} else {
glDisable(GL_DEPTH_TEST);
}

glDepthMask(gRDPOtherMode.z_upd ? GL_TRUE : GL_FALSE);
}

void RendererGL::PrepareRenderState(const float (&mat_project)[16], bool disable_zbuffer)
{
DAEDALUS_PROFILE( "RendererGL::PrepareRenderState" );

if ( disable_zbuffer )
{
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
}
else
{
// Decal mode
if( gRDPOtherMode.zmode == 3 )
{
glPolygonOffset(-1.0, -1.0);
}
else
{
glPolygonOffset(0.0, 0.0);
}

// Enable or Disable ZBuffer test
if ( (mTnL.Flags.Zbuffer & gRDPOtherMode.z_cmp) | gRDPOtherMode.z_upd )
{
glEnable(GL_DEPTH_TEST);
}
else
{
glDisable(GL_DEPTH_TEST);
}

glDepthMask(gRDPOtherMode.z_upd ? GL_TRUE : GL_FALSE);
}


u32 cycle_mode = gRDPOtherMode.cycle_type;

// Initiate Blender
if(cycle_mode < CYCLE_COPY && gRDPOtherMode.force_bl)
{
InitBlenderMode();
}
else
{
glDisable(GL_BLEND);
}
u32 cycle_mode = gRDPOtherMode.cycle_type;

ShaderConfiguration config;
MakeShaderConfigFromCurrentState(&config);
if (cycle_mode < CYCLE_COPY && gRDPOtherMode.force_bl) {
InitBlenderMode();
} else {
glDisable(GL_BLEND);
}

const ShaderProgram * program = GetShaderForConfig(config);
if (program == NULL)
{
// There must have been some failure to compile the shader. Abort!
DBGConsole_Msg(0, "Couldn't generate a shader for mux %llx, cycle %d, alpha %d\n", config.Mux, config.CycleType, config.AlphaThreshold);
return;
}
ShaderConfiguration config;
MakeShaderConfigFromCurrentState(&config);

glUseProgram(program->program);
const ShaderProgram* program = GetShaderForConfig(config);
if (program == nullptr) {
DBGConsole_Msg(0, "Couldn't generate a shader for mux %llx, cycle %d, alpha %d\n", config.Mux, config.CycleType, config.AlphaThreshold);
return;
}

glUniformMatrix4fv(program->uloc_project, 1, GL_FALSE, mat_project);
glUseProgram(program->program);

glUniform4f(program->uloc_primcol, mPrimitiveColour.GetRf(), mPrimitiveColour.GetGf(), mPrimitiveColour.GetBf(), mPrimitiveColour.GetAf());
glUniform4f(program->uloc_envcol, mEnvColour.GetRf(), mEnvColour.GetGf(), mEnvColour.GetBf(), mEnvColour.GetAf());
glUniform1f(program->uloc_primlodfrac, mPrimLODFraction);
glUniformMatrix4fv(program->uloc_project, 1, GL_FALSE, mat_project);

// Second texture is sampled in 2 cycle mode if text_lod is clear (when set,
// gRDPOtherMode.text_lod enables mipmapping, but we just set lod_frac to 0.
bool use_t1 = cycle_mode == CYCLE_2CYCLE;
glUniform4f(program->uloc_primcol, mPrimitiveColour.GetRf(), mPrimitiveColour.GetGf(), mPrimitiveColour.GetBf(), mPrimitiveColour.GetAf());
glUniform4f(program->uloc_envcol, mEnvColour.GetRf(), mEnvColour.GetGf(), mEnvColour.GetBf(), mEnvColour.GetAf());
glUniform1f(program->uloc_primlodfrac, mPrimLODFraction);

bool install_textures[] = { true, use_t1 };
bool use_t1 = cycle_mode == CYCLE_2CYCLE;
bool install_textures[] = { true, use_t1 };

extern u32 gRDPFrame;
glUniform1i(program->uloc_foo, gRDPFrame);
extern u32 gRDPFrame;
glUniform1i(program->uloc_foo, gRDPFrame);

for (u32 i = 0; i < kNumTextures; ++i)
{
if (!install_textures[i])
continue;
for (u32 i = 0; i < kNumTextures; ++i) {
if (!install_textures[i])
continue;

std::shared_ptr<CNativeTexture> texture = mBoundTexture[i];
std::shared_ptr<CNativeTexture> texture = mBoundTexture[i];

if (texture != NULL)
{
glActiveTexture(GL_TEXTURE0 + i);
if (texture != nullptr) {
glActiveTexture(GL_TEXTURE0 + i);

texture->InstallTexture();
texture->InstallTexture();

u8 tile_idx = mActiveTile[i];
const RDP_Tile & rdp_tile = gRDPStateManager.GetTile( tile_idx );
const RDP_TileSize & tile_size = gRDPStateManager.GetTileSize( tile_idx );
u8 tile_idx = mActiveTile[i];
const RDP_Tile& rdp_tile = gRDPStateManager.GetTile(tile_idx);
const RDP_TileSize& tile_size = gRDPStateManager.GetTileSize(tile_idx);

// NB: think this can be done just once per program.
glUniform1i(program->uloc_texture[i], i);
glUniform1i(program->uloc_texture[i], i);

bool clamp_s = rdp_tile.clamp_s || (rdp_tile.mask_s == 0);
bool clamp_t = rdp_tile.clamp_t || (rdp_tile.mask_t == 0);
bool clamp_s = rdp_tile.clamp_s || (rdp_tile.mask_s == 0);
bool clamp_t = rdp_tile.clamp_t || (rdp_tile.mask_t == 0);

u32 mirror_bits_s = MakeMirror(rdp_tile.mirror_s, rdp_tile.mask_s);
u32 mirror_bits_t = MakeMirror(rdp_tile.mirror_t, rdp_tile.mask_t);
u32 mirror_bits_s = MakeMirror(rdp_tile.mirror_s, rdp_tile.mask_s);
u32 mirror_bits_t = MakeMirror(rdp_tile.mirror_t, rdp_tile.mask_t);

u32 mask_bits_s = MakeMask(rdp_tile.mask_s);
u32 mask_bits_t = MakeMask(rdp_tile.mask_t);
u32 mask_bits_s = MakeMask(rdp_tile.mask_s);
u32 mask_bits_t = MakeMask(rdp_tile.mask_t);

glUniform2i(program->uloc_tileclamp[i], clamp_s, clamp_t);
glUniform2i(program->uloc_tileclamp[i], clamp_s, clamp_t);

glUniform2f(program->uloc_tileshift[i], kShiftScales[rdp_tile.shift_s], kShiftScales[rdp_tile.shift_t]);
glUniform2i(program->uloc_tilemask[i], mask_bits_s, mask_bits_t);
glUniform2i(program->uloc_tilemirror[i], mirror_bits_s, mirror_bits_t);
glUniform2f(program->uloc_tileshift[i], kShiftScales[rdp_tile.shift_s], kShiftScales[rdp_tile.shift_t]);
glUniform2i(program->uloc_tilemask[i], mask_bits_s, mask_bits_t);
glUniform2i(program->uloc_tilemirror[i], mirror_bits_s, mirror_bits_t);

glUniform2i(program->uloc_tiletl[i], mTileTopLeft[i].s, mTileTopLeft[i].t);
glUniform2i(program->uloc_tilebr[i], tile_size.right, tile_size.bottom);
glUniform2i(program->uloc_tiletl[i], mTileTopLeft[i].s, mTileTopLeft[i].t);
glUniform2i(program->uloc_tilebr[i], tile_size.right, tile_size.bottom);

glUniform2f(program->uloc_texscale[i], 1.f / texture->GetCorrectedWidth(), 1.f / texture->GetCorrectedHeight());
glUniform2f(program->uloc_texscale[i], 1.f / texture->GetCorrectedWidth(), 1.f / texture->GetCorrectedHeight());

if( (gRDPOtherMode.text_filt != G_TF_POINT) | (gGlobalPreferences.ForceLinearFilter) )
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
if ((gRDPOtherMode.text_filt != G_TF_POINT) | (gGlobalPreferences.ForceLinearFilter)) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mTexWrap[i].u);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mTexWrap[i].v);
}
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mTexWrap[i].u);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mTexWrap[i].v);
}
}
}


// FIXME(strmnnrmn): for fill/copy modes this does more work than needed.
// It ends up copying colour/uv coords when not needed, and can use a shader uniform for the fill colour.
void RendererGL::RenderTriangles( DaedalusVtx * p_vertices, u32 num_vertices, bool disable_zbuffer )
Expand Down
6 changes: 5 additions & 1 deletion Source/SysPSP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/../EBOOT.PBP DESTINATION DaedalusX64)
list(APPEND daed_libs)
set(daed_libs ${daed_libs} PARENT_SCOPE)

list(APPEND sys_libraries intrafont pspkubridge pspfpu pspdebug)
if(DAEDALUS_SDL)
list(APPEND sys_libraries intrafont pspkubridge pspfpu pspdebug )
else()
list(APPEND sys_libraries intrafont pspkubridge pspfpu pspdebug pspgu pspge pspaudio pspaudiolib psppower pspctrl pspdisplay)
endif()
set(sys_libraries ${sys_libraries} PARENT_SCOPE)

set(plat_main SysPSP/main.cpp PARENT_SCOPE)
9 changes: 5 additions & 4 deletions Source/SysPSP/HLEAudio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
add_library(HLEAudio_PSP OBJECT
# ${PROJECT_SOURCE_DIR}/Source/SysPosix/HLEAudio/AudioPluginSDL.cpp
AudioPluginPSP_SDL.cpp
)
if(DAEDALUS_SDL)
add_library(HLEAudio_PSP OBJECT {PROJECT_SOURCE_DIR}/Source/SysPosix/HLEAudio/AudioPluginSDL.cpp)
else()
add_library(HLEAudio_PSP OBJECT AudioPluginPSP.cpp)
endif()

list(APPEND daed_libs "HLEAudio_PSP")
set(daed_libs ${daed_libs} PARENT_SCOPE)
Expand Down
2 changes: 2 additions & 0 deletions Source/SysPSP/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ static bool Initialize()
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

#ifdef DAEDALUS_SDL
if( SDL_Init( SDL_INIT_AUDIO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
return false;
}
#endif

// Detect PSP greater than PSP 1000
if ( kuKernelGetModel() > 0 )
Expand Down
4 changes: 2 additions & 2 deletions Source/UI/AdvancedOptionsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ IAdvancedOptionsScreen::IAdvancedOptionsScreen( CUIContext * p_context, const Ro
mElements.Add( new CBoolSetting( &mRomPreferences.VideoRateMatch, "Video Rate Match", "Match video rate to the frame rate (makes some games less sluggish Rayman2/Donald Duck/Tom and Jerry/Earth Worm Jim)", "Yes", "No" ) );
mElements.Add( new CBoolSetting( &mRomPreferences.AudioRateMatch, "Audio Rate Match", "Match audio rate to the frame rate (less pops and clicks)", "Yes", "No" ) );
mElements.Add( new CBoolSetting( &mRomPreferences.FogEnabled, "Fog Emulation", "Enable or disable distance fog (works on many ROMs but the extra rendering pass uses more resources)", "Enabled", "Disabled" ) );
mElements.Add( new CUICommandImpl( new CMemberFunctor< IAdvancedOptionsScreen >( this, &IAdvancedOptionsScreen::OnConfirm ), "Save & Return", "Confirm changes to settings and return." ) );
mElements.Add( new CUICommandImpl( new CMemberFunctor< IAdvancedOptionsScreen >( this, &IAdvancedOptionsScreen::OnCancel ), "Cancel", "Cancel changes to settings and return." ) );
mElements.Add( new CUICommandImpl(std::bind(&IAdvancedOptionsScreen::OnConfirm, this ), "Save & Return", "Confirm changes to settings and return." ) );
mElements.Add( new CUICommandImpl(std::bind(&IAdvancedOptionsScreen::OnCancel, this ), "Cancel", "Cancel changes to settings and return." ) );

}

Expand Down
4 changes: 2 additions & 2 deletions Source/UI/CheatOptionsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ ICheatOptionsScreen::ICheatOptionsScreen( CUIContext * p_context, const RomID &
}


mElements.Add( new CUICommandImpl( new CMemberFunctor< ICheatOptionsScreen >( this, &ICheatOptionsScreen::OnConfirm ), "Save & Return", "Confirm changes to settings and return." ) );
mElements.Add( new CUICommandImpl( new CMemberFunctor< ICheatOptionsScreen >( this, &ICheatOptionsScreen::OnCancel ), "Cancel", "Cancel changes to settings and return." ) );
mElements.Add( new CUICommandImpl(std::bind(&ICheatOptionsScreen::OnConfirm, this ), "Save & Return", "Confirm changes to settings and return." ) );
mElements.Add( new CUICommandImpl(std::bind(&ICheatOptionsScreen::OnCancel, this ), "Cancel", "Cancel changes to settings and return." ) );

}

Expand Down
Loading
Loading