Commit 2fd2ed7c authored by James's avatar James
Browse files

Sanitise + maintain internal OpenGL state when interacting with LibRetro

parent 87f43610
...@@ -305,8 +305,9 @@ void retro_run() { ...@@ -305,8 +305,9 @@ void retro_run() {
UpdateSettings(false); UpdateSettings(false);
// We can't assume that the frontend has been nice and preserved all OpenGL settings. Reset. // We can't assume that the frontend has been nice and preserved all OpenGL settings. Reset.
OpenGLState new_state {}; auto last_state = OpenGLState::GetCurState();
new_state.Apply(); ResetGLState();
last_state.Apply();
while (!emu_instance->emu_window->HasSubmittedFrame()) { while (!emu_instance->emu_window->HasSubmittedFrame()) {
auto result = Core::System::GetInstance().RunLoop(); auto result = Core::System::GetInstance().RunLoop();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <glad/glad.h> #include <glad/glad.h>
#include <video_core/renderer_opengl/gl_state.h>
#include "citra_libretro/citra_libretro.h" #include "citra_libretro/citra_libretro.h"
#include "citra_libretro/environment.h" #include "citra_libretro/environment.h"
...@@ -13,7 +14,11 @@ ...@@ -13,7 +14,11 @@
/// LibRetro expects a "default" GL state. /// LibRetro expects a "default" GL state.
void ResetGLState() { void ResetGLState() {
// Clean up state. // Reset internal state.
OpenGLState state {};
state.Apply();
// Clean up global state.
glLogicOp(GL_COPY); glLogicOp(GL_COPY);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
...@@ -48,25 +53,25 @@ EmuWindow_LibRetro::~EmuWindow_LibRetro() {} ...@@ -48,25 +53,25 @@ EmuWindow_LibRetro::~EmuWindow_LibRetro() {}
void EmuWindow_LibRetro::SwapBuffers() { void EmuWindow_LibRetro::SwapBuffers() {
submittedFrame = true; submittedFrame = true;
auto current_state = OpenGLState::GetCurState();
ResetGLState(); ResetGLState();
if (enableEmulatedPointer) { if (enableEmulatedPointer) {
// TODO: Port tracker to OpenGLState
tracker.Render(width, height); tracker.Render(width, height);
} }
LibRetro::UploadVideoFrame(RETRO_HW_FRAME_BUFFER_VALID, static_cast<unsigned>(width), LibRetro::UploadVideoFrame(RETRO_HW_FRAME_BUFFER_VALID, static_cast<unsigned>(width),
static_cast<unsigned>(height), 0); static_cast<unsigned>(height), 0);
glUseProgram(0);
ResetGLState(); ResetGLState();
glBindFramebuffer(GL_FRAMEBUFFER, 0); current_state.Apply();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
} }
void EmuWindow_LibRetro::SetupFramebuffer() { void EmuWindow_LibRetro::SetupFramebuffer() {
ResetGLState(); // TODO: Expose interface in renderer_opengl to configure this in it's internal state
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer);
// glClear can be a slow path - skip clearing if we don't need to. // glClear can be a slow path - skip clearing if we don't need to.
...@@ -117,6 +122,7 @@ void EmuWindow_LibRetro::OnMinimalClientAreaChangeRequest( ...@@ -117,6 +122,7 @@ void EmuWindow_LibRetro::OnMinimalClientAreaChangeRequest(
void EmuWindow_LibRetro::Prepare(bool hasOGL) { void EmuWindow_LibRetro::Prepare(bool hasOGL) {
// TODO: Handle custom layouts // TODO: Handle custom layouts
// TODO: Extract this ugly thing somewhere else
unsigned baseX; unsigned baseX;
unsigned baseY; unsigned baseY;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment