mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
WIP on deleting some managed textures when context is lost but managed textures is not actually supported by graphics api
This commit is contained in:
parent
b8794585e4
commit
f476eee0c1
@ -769,6 +769,12 @@ static void OnContextLost(void* obj) {
|
|||||||
DeleteVbs();
|
DeleteVbs();
|
||||||
Gfx_DeleteTexture(&sides_tex);
|
Gfx_DeleteTexture(&sides_tex);
|
||||||
Gfx_DeleteTexture(&edges_tex);
|
Gfx_DeleteTexture(&edges_tex);
|
||||||
|
|
||||||
|
if (Gfx.ManagedTextures) return;
|
||||||
|
Gfx_DeleteTexture(&clouds_tex);
|
||||||
|
Gfx_DeleteTexture(&skybox_tex);
|
||||||
|
Gfx_DeleteTexture(&rain_tex);
|
||||||
|
Gfx_DeleteTexture(&snow_tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UpdateAll(void) {
|
static void UpdateAll(void) {
|
||||||
@ -894,11 +900,6 @@ static void EnvRenderer_Free(void) {
|
|||||||
OnContextLost(NULL);
|
OnContextLost(NULL);
|
||||||
Mem_Free(Weather_Heightmap);
|
Mem_Free(Weather_Heightmap);
|
||||||
Weather_Heightmap = NULL;
|
Weather_Heightmap = NULL;
|
||||||
|
|
||||||
Gfx_DeleteTexture(&clouds_tex);
|
|
||||||
Gfx_DeleteTexture(&skybox_tex);
|
|
||||||
Gfx_DeleteTexture(&rain_tex);
|
|
||||||
Gfx_DeleteTexture(&snow_tex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnvRenderer_Reset(void) {
|
static void EnvRenderer_Reset(void) {
|
||||||
|
@ -602,6 +602,7 @@ static void Game_RenderFrame(double delta) {
|
|||||||
void Game_Free(void* obj) {
|
void Game_Free(void* obj) {
|
||||||
struct IGameComponent* comp;
|
struct IGameComponent* comp;
|
||||||
Atlas_Free();
|
Atlas_Free();
|
||||||
|
Gfx.ManagedTextures = false;
|
||||||
|
|
||||||
Event_UnregisterVoid(&WorldEvents.NewMap, NULL, HandleOnNewMap);
|
Event_UnregisterVoid(&WorldEvents.NewMap, NULL, HandleOnNewMap);
|
||||||
Event_UnregisterVoid(&WorldEvents.MapLoaded, NULL, HandleOnNewMapLoaded);
|
Event_UnregisterVoid(&WorldEvents.MapLoaded, NULL, HandleOnNewMapLoaded);
|
||||||
|
@ -406,6 +406,7 @@ void Gfx_Init(void) {
|
|||||||
|
|
||||||
Gfx.MinZNear = 0.05f;
|
Gfx.MinZNear = 0.05f;
|
||||||
customMipmapsLevels = true;
|
customMipmapsLevels = true;
|
||||||
|
Gfx.ManagedTextures = true;
|
||||||
CommonInit();
|
CommonInit();
|
||||||
TryCreateDevice();
|
TryCreateDevice();
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ CC_VAR extern struct _GfxData {
|
|||||||
/* Whether some textures are created with mipmaps. */
|
/* Whether some textures are created with mipmaps. */
|
||||||
cc_bool Mipmaps;
|
cc_bool Mipmaps;
|
||||||
/* Whether managed textures are actually supported. */
|
/* Whether managed textures are actually supported. */
|
||||||
|
/* If not, you must free/create them just like normal textures */
|
||||||
cc_bool ManagedTextures;
|
cc_bool ManagedTextures;
|
||||||
/* Whether Gfx_Init has been called to initialise state. */
|
/* Whether Gfx_Init has been called to initialise state. */
|
||||||
cc_bool Initialised;
|
cc_bool Initialised;
|
||||||
|
17
src/Gui.c
17
src/Gui.c
@ -129,7 +129,7 @@ static void Gui_LoadOptions(void) {
|
|||||||
Gui_RawChatScale = Options_GetFloat(OPT_CHAT_SCALE, 0.35f, 5.0f, 1.0f);
|
Gui_RawChatScale = Options_GetFloat(OPT_CHAT_SCALE, 0.35f, 5.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnContextLost(void* obj) {
|
static void LoseAllScreens(void) {
|
||||||
struct Screen* s;
|
struct Screen* s;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ static void OnContextRecreated(void* obj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Gui_RefreshAll(void) {
|
void Gui_RefreshAll(void) {
|
||||||
OnContextLost(NULL);
|
LoseAllScreens();
|
||||||
OnContextRecreated(NULL);
|
OnContextRecreated(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,6 +393,15 @@ static void OnTextChanged(void* obj, const String* str) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void OnContextLost(void* obj) {
|
||||||
|
LoseAllScreens();
|
||||||
|
if (Gfx.ManagedTextures) return;
|
||||||
|
|
||||||
|
Gfx_DeleteTexture(&Gui_GuiTex);
|
||||||
|
Gfx_DeleteTexture(&Gui_GuiClassicTex);
|
||||||
|
Gfx_DeleteTexture(&Gui_IconsTex);
|
||||||
|
}
|
||||||
|
|
||||||
static void Gui_Init(void) {
|
static void Gui_Init(void) {
|
||||||
Event_RegisterVoid(&ChatEvents.FontChanged, NULL, OnFontChanged);
|
Event_RegisterVoid(&ChatEvents.FontChanged, NULL, OnFontChanged);
|
||||||
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
Event_RegisterEntry(&TextureEvents.FileChanged, NULL, OnFileChanged);
|
||||||
@ -422,9 +431,7 @@ static void Gui_Free(void) {
|
|||||||
|
|
||||||
while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]);
|
while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]);
|
||||||
|
|
||||||
Gfx_DeleteTexture(&Gui_GuiTex);
|
OnContextLost(NULL);
|
||||||
Gfx_DeleteTexture(&Gui_GuiClassicTex);
|
|
||||||
Gfx_DeleteTexture(&Gui_IconsTex);
|
|
||||||
Gui_Reset();
|
Gui_Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
src/Model.c
14
src/Model.c
@ -419,7 +419,13 @@ static struct ModelTex* textures_tail;
|
|||||||
#define Model_RetAABB(x1,y1,z1, x2,y2,z2) static struct AABB BB = { (x1)/16.0f,(y1)/16.0f,(z1)/16.0f, (x2)/16.0f,(y2)/16.0f,(z2)/16.0f }; e->ModelAABB = BB;
|
#define Model_RetAABB(x1,y1,z1, x2,y2,z2) static struct AABB BB = { (x1)/16.0f,(y1)/16.0f,(z1)/16.0f, (x2)/16.0f,(y2)/16.0f,(z2)/16.0f }; e->ModelAABB = BB;
|
||||||
|
|
||||||
static void Models_ContextLost(void* obj) {
|
static void Models_ContextLost(void* obj) {
|
||||||
|
struct ModelTex* tex;
|
||||||
Gfx_DeleteDynamicVb(&Models.Vb);
|
Gfx_DeleteDynamicVb(&Models.Vb);
|
||||||
|
if (Gfx.ManagedTextures) return;
|
||||||
|
|
||||||
|
for (tex = textures_head; tex; tex = tex->next) {
|
||||||
|
Gfx_DeleteTexture(&tex->texID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Models_ContextRecreated(void* obj) {
|
static void Models_ContextRecreated(void* obj) {
|
||||||
@ -2024,18 +2030,12 @@ static void Models_Init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Models_Free(void) {
|
static void Models_Free(void) {
|
||||||
struct ModelTex* tex;
|
|
||||||
|
|
||||||
for (tex = textures_head; tex; tex = tex->next) {
|
|
||||||
Gfx_DeleteTexture(&tex->texID);
|
|
||||||
}
|
|
||||||
Models_ContextLost(NULL);
|
Models_ContextLost(NULL);
|
||||||
|
CustomModel_FreeAll();
|
||||||
|
|
||||||
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Models_TextureChanged);
|
Event_UnregisterEntry(&TextureEvents.FileChanged, NULL, Models_TextureChanged);
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Models_ContextLost);
|
Event_UnregisterVoid(&GfxEvents.ContextLost, NULL, Models_ContextLost);
|
||||||
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated);
|
Event_UnregisterVoid(&GfxEvents.ContextRecreated, NULL, Models_ContextRecreated);
|
||||||
|
|
||||||
CustomModel_FreeAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Models_Reset(void) { CustomModel_FreeAll(); }
|
static void Models_Reset(void) { CustomModel_FreeAll(); }
|
||||||
|
@ -573,6 +573,9 @@ void Particles_CustomEffect(int effectID, float x, float y, float z, float origi
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static void OnContextLost(void* obj) {
|
static void OnContextLost(void* obj) {
|
||||||
Gfx_DeleteDynamicVb(&Particles_VB);
|
Gfx_DeleteDynamicVb(&Particles_VB);
|
||||||
|
|
||||||
|
if (Gfx.ManagedTextures) return;
|
||||||
|
Gfx_DeleteTexture(&Particles_TexId);
|
||||||
}
|
}
|
||||||
static void OnContextRecreated(void* obj) {
|
static void OnContextRecreated(void* obj) {
|
||||||
Particles_VB = Gfx_CreateDynamicVb(VERTEX_FORMAT_TEXTURED, PARTICLES_MAX * 4);
|
Particles_VB = Gfx_CreateDynamicVb(VERTEX_FORMAT_TEXTURED, PARTICLES_MAX * 4);
|
||||||
@ -599,7 +602,6 @@ static void Particles_Init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Particles_Free(void) {
|
static void Particles_Free(void) {
|
||||||
Gfx_DeleteTexture(&Particles_TexId);
|
|
||||||
OnContextLost(NULL);
|
OnContextLost(NULL);
|
||||||
|
|
||||||
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, OnBreakBlockEffect_Handler);
|
Event_UnregisterBlock(&UserEvents.BlockChanged, NULL, OnBreakBlockEffect_Handler);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user