working on opengl resources reinitialization

This commit is contained in:
Emil Kabirov 2018-10-15 17:29:14 +05:00
parent ce905daa85
commit 55b042a979
4 changed files with 100 additions and 77 deletions

View File

@ -918,6 +918,9 @@ void TGameLevel::InnerDraw(int screenWidth, int screenHeight, int matrixWidth, i
} }
// ::::::::::: // :::::::::::
*SE::Console << BkgTexture;
*SE::Console << std::to_string(ResourceManager->TexList[BkgTexture]);
glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[BkgTexture]); glBindTexture(GL_TEXTURE_2D,ResourceManager->TexList[BkgTexture]);
//Renderer->DrawRect(Vector2f(xlOffset, ylOffset), Vector2f(xlOffset+tSW, ylOffset+tSH),Vector2f(0.f, 0.f), Vector2f(1.f, 1.f)); //Renderer->DrawRect(Vector2f(xlOffset, ylOffset), Vector2f(xlOffset+tSW, ylOffset+tSH),Vector2f(0.f, 0.f), Vector2f(1.f, 1.f));
Renderer->DrawRect(Vector2f(bkgSWO, bkgSHO), Vector2f(bkgSWO + bkgSW, bkgSHO + bkgSH), Vector2f(0.f, 0.f), Vector2f(1.f, 1.f)); Renderer->DrawRect(Vector2f(bkgSWO, bkgSHO), Vector2f(bkgSWO + bkgSW, bkgSHO + bkgSH), Vector2f(0.f, 0.f), Vector2f(1.f, 1.f));

View File

@ -152,8 +152,6 @@ void TMyApplication::InnerInit()
ST::PathToResources = ""; ST::PathToResources = "";
#endif #endif
LoadUserProgress();
if (Console != NULL) if (Console != NULL)
{ {
*Console<<"APP INIT\n"; *Console<<"APP INIT\n";
@ -162,59 +160,62 @@ void TMyApplication::InnerInit()
GameState = CONST_GAMESTATE_PRELOADING; GameState = CONST_GAMESTATE_PRELOADING;
StateTimer = 0.f; StateTimer = 0.f;
/*
ResourceManager->ShaderManager.AddShader("DefaultShader", "shader1vertex", "shader1fragment.txt");
ResourceManager->ShaderManager.AddShader("FrameShader", "frameshader_vertex.txt", "frameshader_fragment.txt");
ResourceManager->ShaderManager.AddShader("BrickShader", "brickshader_vertex.txt", "brickshader_fragment.txt");
Renderer->PushShader("DefaultShader");
*/
//ResourceManager->ShaderManager.AddShader("DefaultShader", "shaders/texture-shader.vertex", "shaders/texture-shader.fragment");
ResourceManager->ShaderManager.AddShader("DefaultShader", "shaders/gui_transparent.vertex", "shaders/gui_transparent.fragment"); ResourceManager->ShaderManager.AddShader("DefaultShader", "shaders/gui_transparent.vertex", "shaders/gui_transparent.fragment");
ResourceManager->ShaderManager.AddShader("HoverableButtonShader", "shaders/gui_transparent.vertex", "shaders/hoverable-button.fragment"); Renderer->PushShader("DefaultShader");
ResourceManager->ShaderManager.AddShader("BlackAndWhiteShader", "shaders/gui_transparent_blackandwhite.vertex", "shaders/gui_transparent_blackandwhite.fragment");
ResourceManager->ShaderManager.AddShader("ColorShader", "shaders/color-shader.vertex", "shaders/color-shader.fragment");
ResourceManager->ShaderManager.AddShader("FrameShader", "shaders/frameshader_vertex.txt", "shaders/frameshader_fragment.txt");
ResourceManager->ShaderManager.AddShader("BrickShader", "shaders/brickshader_vertex.txt", "shaders/brickshader_fragment.txt");
ResourceManager->ShaderManager.AddShader(ParticleEffect::PARTICLE_SHADER, "shaders/particle-shader.vertex", "shaders/particle-shader.fragment");
Renderer->PushShader("DefaultShader");
//ResourceManager->TexList.AddTexture(CONST_LOADING_BACKGROUND_BLACK + ".png", CONST_LOADING_BACKGROUND_BLACK); ResourceManager->TexList.AddTexture("console_bkg.bmp");
//ResourceManager->TexList.AddTexture(CONST_LOADING_TEXTURE + ".png", CONST_LOADING_TEXTURE); ResourceManager->TexList.AddTexture("white.bmp");
//ResourceManager->TexList.AddTexture(CONST_LOGO_SMALL_TEXTURE + ".png", CONST_LOGO_SMALL_TEXTURE);
ResourceManager->TexList.AddTexture("console_bkg.bmp"); ResourceManager->FontManager.AddFont("arial32", "arial32.png", "arial32.txt");
ResourceManager->TexList.AddTexture("white.bmp"); ResourceManager->FontManager.AddFont("lucon12", "lucon12.png", "lucon12.txt");
ResourceManager->FontManager.PushFont("lucon12");
Renderer->SetOrthoProjection();
ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 256, 256); Renderer->SetFullScreenViewport();
//OnDrawSignal.connect(boost::bind(&TGameLoading::Draw, boost::ref(GameLoading)));
Inited = true;
Renderer->SetOrthoProjection(); ResourceManager->newGuiManager.LoadFromConfig("gui_loading.json");
Renderer->SetFullScreenViewport(); skipUpdateToUpdateScreen = true;
Application->SetGameLevelScreenScale(); StateTimer = 0.f;
//GameLevel.SetLevelScale(); }
EffectsInit();
// ------- UI -------
ResourceManager->FontManager.AddFont("arial32", "arial32.png", "arial32.txt");
ResourceManager->FontManager.AddFont("lucon12", "lucon12.png", "lucon12.txt");
ResourceManager->FontManager.PushFont("lucon12");
//ResourceManager->newGuiManager.LoadFromConfig("gui_main_menu.json");
ResourceManager->newGuiManager.LoadFromConfig("gui_loading.json");
// ------- UI ------- void TMyApplication::InnerReinitGLResources()
{
RenderLevelSnapshots();
// TESTS of menu lsparkler.reinitGlResources();
if (Menu.GalaxMenu.InitGalaxyMenu("levels/galaxy_ptree.json")) { rsparkler.reinitGlResources();
std::cout << "ok" << std::endl; tsparkler.reinitGlResources();
} bsparkler.reinitGlResources();
else { lvlFirework.reinitGlResources();
std::cout << "menu error" << std::endl; }
}
void TMyApplication::RenderLevelSnapshots()
{
Renderer->SwitchToFrameBuffer("LevelBuffer");
Renderer->SetProjectionMatrix(768, 480);
Renderer->LoadIdentity();
for (auto &star : Menu.GalaxMenu.galaxies[0].Stars)
{
for (auto level : star.selectionMenu.gameLevels)
{
level->DrawSnapshot("LevelBuffer", false);
Renderer->PushShader("BlackAndWhiteShader");
level->DrawSnapshot("LevelBuffer", true);
Renderer->PopShader();
}
}
Renderer->SwitchToScreen();
Renderer->SetOrthoProjection();
} }
void TMyApplication::InnerDeinit() void TMyApplication::InnerDeinit()
@ -494,10 +495,48 @@ void TMyApplication::InnerUpdate(size_t dt)
StateTimer += dt/1000.f; StateTimer += dt/1000.f;
if (StateTimer >= 1.f) if (StateTimer >= 1.f)
{ {
LoadResources(); StateTimer -= 1.f;
GameState = CONST_GAMESTATE_LOADING; skipUpdateToUpdateScreen = false;
StateTimer = 0.f;
} }
if (skipUpdateToUpdateScreen)
{
return;
}
LoadUserProgress();
ResourceManager->ShaderManager.AddShader("HoverableButtonShader", "shaders/gui_transparent.vertex", "shaders/hoverable-button.fragment");
ResourceManager->ShaderManager.AddShader("BlackAndWhiteShader", "shaders/gui_transparent_blackandwhite.vertex", "shaders/gui_transparent_blackandwhite.fragment");
ResourceManager->ShaderManager.AddShader("ColorShader", "shaders/color-shader.vertex", "shaders/color-shader.fragment");
ResourceManager->ShaderManager.AddShader("FrameShader", "shaders/frameshader_vertex.txt", "shaders/frameshader_fragment.txt");
ResourceManager->ShaderManager.AddShader("BrickShader", "shaders/brickshader_vertex.txt", "shaders/brickshader_fragment.txt");
ResourceManager->ShaderManager.AddShader(ParticleEffect::PARTICLE_SHADER, "shaders/particle-shader.vertex", "shaders/particle-shader.fragment");
ResourceManager->FrameManager.AddFrameRenderBuffer("LevelBuffer", 256, 256);
//OnDrawSignal.connect(boost::bind(&TGameLoading::Draw, boost::ref(GameLoading)));
Inited = true;
Application->SetGameLevelScreenScale();
//GameLevel.SetLevelScale();
EffectsInit();
// ------- UI -------
// TESTS of menu
if (Menu.GalaxMenu.InitGalaxyMenu("levels/galaxy_ptree.json")) {
std::cout << "ok" << std::endl;
}
else {
std::cout << "menu error" << std::endl;
}
RenderLevelSnapshots();
LoadResources();
GameState = CONST_GAMESTATE_LOADING;
} }
else if (GameState == CONST_GAMESTATE_LOADING) else if (GameState == CONST_GAMESTATE_LOADING)
{ {
@ -516,31 +555,6 @@ void TMyApplication::InnerUpdate(size_t dt)
} }
else else
{ {
Renderer->SwitchToFrameBuffer("LevelBuffer");
Renderer->SetProjectionMatrix(768, 480);
Renderer->LoadIdentity();
for (auto &star : Menu.GalaxMenu.galaxies[0].Stars)
{
for (auto level : star.selectionMenu.gameLevels)
{
level->DrawSnapshot("LevelBuffer", false);
Renderer->PushShader("BlackAndWhiteShader");
level->DrawSnapshot("LevelBuffer", true);
Renderer->PopShader();
}
}
Renderer->SwitchToScreen();
Renderer->SetOrthoProjection();
GameState = CONST_GAMESTATE_MENU; GameState = CONST_GAMESTATE_MENU;
ApplySignalsToMenu(); ApplySignalsToMenu();

View File

@ -89,6 +89,8 @@ const int CONST_GAMESTATE_PRELOADING = 7;
class TMyApplication : public TApplication class TMyApplication : public TApplication
{ {
protected: protected:
bool skipUpdateToUpdateScreen;
int levelScreenWidth; int levelScreenWidth;
int levelScreenHeight; int levelScreenHeight;
float levelScreenRatio = 1.6; float levelScreenRatio = 1.6;
@ -137,12 +139,16 @@ public:
bool Loaded; bool Loaded;
TMyApplication() : TApplication(), Loaded(false), Inited(false) { } TMyApplication() : TApplication(), Loaded(false), Inited(false) { }
void LoadUserProgress(); void LoadUserProgress();
void SaveUserProgress(int levelStar, int levelIndex); void SaveUserProgress(int levelStar, int levelIndex);
virtual void InnerInit(); virtual void InnerInit();
virtual void RenderLevelSnapshots();
virtual void InnerReinitGLResources();
virtual void InnerDeinit(); virtual void InnerDeinit();
virtual void InnerDraw(); virtual void InnerDraw();

View File

@ -65,7 +65,7 @@ public class GL2JNIActivity extends Activity
@Override @Override
protected void onPause() protected void onPause()
{ {
EngineWrapper.CallDestroy(); //EngineWrapper.CallDestroy();
super.onPause(); super.onPause();
mView.onPause(); mView.onPause();
} }