diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index ca64acae56..6fe38db384 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -118,8 +118,10 @@ GPU_GLES::GPU_GLES(GraphicsContext *gfxCtx, Draw::DrawContext *draw) } GPU_GLES::~GPU_GLES() { - GLRenderManager *render = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); - render->Wipe(); + if (draw_) { + GLRenderManager *render = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); + render->Wipe(); + } // If we're here during app shutdown (exiting the Windows app in-game, for example) // everything should already be cleared since DeviceLost has been run. @@ -135,9 +137,6 @@ GPU_GLES::~GPU_GLES() { shaderManagerGL_ = nullptr; delete framebufferManagerGL_; delete textureCacheGL_; -#ifdef _WIN32 - gfxCtx_->SwapInterval(0); -#endif } static constexpr int MakeIntelSimpleVer(int v1, int v2, int v3) { @@ -332,11 +331,13 @@ void GPU_GLES::DeviceLost() { // TransformDraw has registered as a GfxResourceHolder. drawEngine_.ClearInputLayoutMap(); shaderManagerGL_->ClearCache(false); - textureCacheGL_->Clear(false); + textureCacheGL_->DeviceLost(); fragmentTestCache_.Clear(false); depalShaderCache_.Clear(); drawEngine_.DeviceLost(); framebufferManagerGL_->DeviceLost(); + // Don't even try to access the lost device. + draw_ = nullptr; } void GPU_GLES::DeviceRestore() { diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index e1b45f40c4..ed802319a8 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -53,6 +53,7 @@ TextureCacheGLES::TextureCacheGLES(Draw::DrawContext *draw) SetupTextureDecoder(); nextTexture_ = nullptr; + std::vector entries; entries.push_back({ 0, 3, GL_FLOAT, GL_FALSE, 20, 0 }); entries.push_back({ 1, 2, GL_FLOAT, GL_FALSE, 20, 12 }); @@ -60,7 +61,9 @@ TextureCacheGLES::TextureCacheGLES(Draw::DrawContext *draw) } TextureCacheGLES::~TextureCacheGLES() { - render_->DeleteInputLayout(shadeInputLayout_); + if (shadeInputLayout_) { + render_->DeleteInputLayout(shadeInputLayout_); + } Clear(true); } @@ -839,6 +842,22 @@ bool TextureCacheGLES::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) #endif } +void TextureCacheGLES::DeviceLost() { + if (shadeInputLayout_) { + render_->DeleteInputLayout(shadeInputLayout_); + shadeInputLayout_ = nullptr; + } + Clear(false); + draw_ = nullptr; + render_ = nullptr; +} + void TextureCacheGLES::DeviceRestore(Draw::DrawContext *draw) { draw_ = draw; + if (!shadeInputLayout_) { + std::vector entries; + entries.push_back({ 0, 3, GL_FLOAT, GL_FALSE, 20, 0 }); + entries.push_back({ 1, 2, GL_FLOAT, GL_FALSE, 20, 12 }); + shadeInputLayout_ = render_->CreateInputLayout(entries); + } } diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index 36f7e600e0..a88eb8d7ec 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -66,6 +66,7 @@ public: void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight); bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) override; + void DeviceLost(); void DeviceRestore(Draw::DrawContext *draw); protected: @@ -95,7 +96,7 @@ private: ShaderManagerGLES *shaderManager_; DrawEngineGLES *drawEngine_; - GLRInputLayout *shadeInputLayout_; + GLRInputLayout *shadeInputLayout_ = nullptr; enum { INVALID_TEX = -1 }; };