From 72ae497350d03c8a52824f226d0e9883ae3e4ed0 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 6 Sep 2015 12:23:14 +0200 Subject: [PATCH] Remove glstate usage except in the GPU implementation. Prepare for moving it into PPSSPP. --- Core/HLE/sceDisplay.cpp | 4 +--- GPU/Directx9/FramebufferDX9.cpp | 6 +++--- GPU/Directx9/GPU_DX9.cpp | 5 +++++ GPU/Directx9/GPU_DX9.h | 1 + GPU/GLES/GLES_GPU.cpp | 5 +++++ GPU/GLES/GLES_GPU.h | 1 + GPU/GPUCommon.cpp | 1 - GPU/GPUCommon.h | 2 +- GPU/Software/SoftGpu.cpp | 12 +++++------ UI/DevScreens.cpp | 1 - UI/EmuScreen.cpp | 3 +-- UI/MiscScreens.cpp | 1 - UI/NativeApp.cpp | 35 +------------------------------- Windows/OpenGLBase.cpp | 4 +--- android/jni/TestRunner.cpp | 7 ++----- headless/WindowsHeadlessHost.cpp | 8 ++------ native | 2 +- 17 files changed, 31 insertions(+), 67 deletions(-) diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index 7d3b595c8b..a834376165 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -33,9 +33,7 @@ #include "base/timeutil.h" #include "profiler/profiler.h" -#ifndef _XBOX -#include "gfx_es2/gl_state.h" -#endif +#include "gfx_es2/gpu_features.h" #include "Common/ChunkFile.h" #include "Core/CoreTiming.h" diff --git a/GPU/Directx9/FramebufferDX9.cpp b/GPU/Directx9/FramebufferDX9.cpp index 452a5fe584..8d1349f74f 100644 --- a/GPU/Directx9/FramebufferDX9.cpp +++ b/GPU/Directx9/FramebufferDX9.cpp @@ -775,7 +775,7 @@ namespace DX9 { fbo_bind_as_render_target(extraFBOs_[0]); int fbo_w, fbo_h; fbo_get_dimensions(extraFBOs_[0], &fbo_w, &fbo_h); - glstate.viewport.set(0, 0, fbo_w, fbo_h); + dxstate.viewport.set(0, 0, fbo_w, fbo_h); DrawActiveTexture(colorTexture, 0, 0, fbo_w, fbo_h, fbo_w, fbo_h, true, 1.0f, 1.0f, postShaderProgram_); fbo_unbind(); @@ -787,12 +787,12 @@ namespace DX9 { return; } colorTexture = fbo_get_color_texture(extraFBOs_[0]); - glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight); + dxstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight); // These are in the output display coordinates DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height); } else { // Use post-shader, but run shader at output resolution. - glstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight); + dxstate.viewport.set(0, 0, PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight); // These are in the output display coordinates DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, true, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height, postShaderProgram_); } diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 12ff6c44d6..0e7fa8eba5 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -509,6 +509,11 @@ void DIRECTX9_GPU::BeginFrame() { ScheduleEvent(GPU_EVENT_BEGIN_FRAME); } +void DIRECTX9_GPU::ReapplyGfxStateInternal() { + DX9::dxstate.Restore(); + GPUCommon::ReapplyGfxStateInternal(); +} + void DIRECTX9_GPU::BeginFrameInternal() { if (resized_) { UpdateCmdInfo(); diff --git a/GPU/Directx9/GPU_DX9.h b/GPU/Directx9/GPU_DX9.h index 6673212adf..0fc3fb929f 100644 --- a/GPU/Directx9/GPU_DX9.h +++ b/GPU/Directx9/GPU_DX9.h @@ -41,6 +41,7 @@ public: void PreExecuteOp(u32 op, u32 diff) override; void ExecuteOp(u32 op, u32 diff) override; + void ReapplyGfxStateInternal() override; void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) override; void CopyDisplayToOutput() override; void BeginFrame() override; diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index 52686ef8e1..07e899506d 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -678,6 +678,11 @@ void GLES_GPU::UpdateCmdInfo() { } } +void GLES_GPU::ReapplyGfxStateInternal() { + glstate.Restore(); + GPUCommon::ReapplyGfxStateInternal(); +} + void GLES_GPU::BeginFrameInternal() { if (resized_) { CheckGPUFeatures(); diff --git a/GPU/GLES/GLES_GPU.h b/GPU/GLES/GLES_GPU.h index b2a97684e1..a40090e85e 100644 --- a/GPU/GLES/GLES_GPU.h +++ b/GPU/GLES/GLES_GPU.h @@ -46,6 +46,7 @@ public: void Execute_Generic(u32 op, u32 diff); void ExecuteOp(u32 op, u32 diff) override; + void ReapplyGfxStateInternal() override; void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format) override; void CopyDisplayToOutput() override; void BeginFrame() override; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index cb97da1071..786952e256 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -620,7 +620,6 @@ void GPUCommon::ReapplyGfxState() { } void GPUCommon::ReapplyGfxStateInternal() { - // ShaderManager_DirtyShader(); // The commands are embedded in the command memory so we can just reexecute the words. Convenient. // To be safe we pass 0xFFFFFFFF as the diff. diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index fa1288fd41..87d4d8d84d 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -133,7 +133,7 @@ protected: void CheckDrawSync(); int GetNextListIndex(); void ProcessDLQueueInternal(); - void ReapplyGfxStateInternal(); + virtual void ReapplyGfxStateInternal(); virtual void FastLoadBoneMatrix(u32 target); virtual void ProcessEvent(GPUEvent ev); virtual bool ShouldExitEventLoop() { diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 39cfd7e4b3..79dd804036 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -29,7 +29,7 @@ #include "Core/MIPS/MIPS.h" #include "Core/Reporting.h" #include "gfx/gl_common.h" -#include "gfx_es2/gl_state.h" +// #include "gfx_es2/gl_state.h" #include "profiler/profiler.h" #include "GPU/Software/SoftGpu.h" @@ -187,9 +187,9 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) float dstwidth = (float)PSP_CoreParameter().pixelWidth; float dstheight = (float)PSP_CoreParameter().pixelHeight; - glstate.blend.disable(); - glstate.viewport.set(0, 0, dstwidth, dstheight); - glstate.scissorTest.disable(); + glDisable(GL_BLEND); + glViewport(0, 0, dstwidth, dstheight); + glDisable(GL_SCISSOR_TEST); glBindTexture(GL_TEXTURE_2D, temp_texture); @@ -275,8 +275,8 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight) {texvert_u, 1} }; - glstate.arrayBuffer.unbind(); - glstate.elementArrayBuffer.unbind(); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glVertexAttribPointer(attr_pos, 2, GL_FLOAT, GL_FALSE, 0, verts); glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, texverts); glEnableVertexAttribArray(attr_pos); diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 514e729751..037307ae99 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -18,7 +18,6 @@ #include #include "base/compat.h" -#include "gfx_es2/gl_state.h" #include "gfx_es2/gpu_features.h" #include "i18n/i18n.h" #include "ui/ui_context.h" diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index f218ae5d43..213a210367 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -23,8 +23,7 @@ #include "base/timeutil.h" #include "profiler/profiler.h" -#include "gfx_es2/glsl_program.h" -#include "gfx_es2/gl_state.h" +#include "gfx_es2/gpu_features.h" #include "gfx_es2/draw_text.h" #include "gfx_es2/fbo.h" diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index 22ab4e9541..c2827cc7b5 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -51,7 +51,6 @@ #include "base/timeutil.h" #include "base/colorutil.h" #include "gfx_es2/draw_buffer.h" -#include "gfx_es2/gl_state.h" #include "util/random/rng.h" #include "UI/ui_atlas.h" diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 4a7584e679..f7f59c40a0 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -48,8 +48,8 @@ #include "file/zip_read.h" #include "thread/thread.h" #include "net/http_client.h" -#include "gfx_es2/gl_state.h" // TODO: Get rid of this from here #include "gfx_es2/draw_text.h" +#include "gfx_es2/gpu_features.h" #include "gfx/gl_lost_manager.h" #include "gfx/texture.h" #include "i18n/i18n.h" @@ -85,9 +85,6 @@ #include "EmuScreen.h" #include "GameInfoCache.h" #include "HostTypes.h" -#ifdef _WIN32 -#include "GPU/Directx9/helper/dx_state.h" -#endif #include "UI/OnScreenDisplay.h" #include "UI/MiscScreens.h" #include "UI/TiltEventProcessor.h" @@ -571,11 +568,6 @@ void NativeInitGraphics() { screenManager->setUIContext(uiContext); screenManager->setThin3DContext(thin3d); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - #ifdef _WIN32 winAudioBackend = CreateAudioBackend((AudioBackendType)g_Config.iAudioBackend); winAudioBackend->Init(MainWindow::GetHWND(), &Win32Mix, 44100); @@ -684,19 +676,6 @@ void NativeRender() { viewport.MaxDepth = 1.0; viewport.MinDepth = 0.0; thin3d->SetViewports(1, &viewport); - - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { - glstate.depthWrite.set(GL_TRUE); - glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glstate.Restore(); - } else { -#ifdef _WIN32 - DX9::dxstate.depthWrite.set(true); - DX9::dxstate.colorMask.set(true, true, true, true); - DX9::dxstate.Restore(); -#endif - } - thin3d->SetTargetSize(pixel_xres, pixel_yres); float xres = dp_xres; @@ -727,17 +706,6 @@ void NativeRender() { TakeScreenshot(); } - thin3d->SetScissorEnabled(false); - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { - glstate.depthWrite.set(GL_TRUE); - glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - } else { -#ifdef _WIN32 - DX9::dxstate.depthWrite.set(true); - DX9::dxstate.colorMask.set(true, true, true, true); -#endif - } - if (resized) { resized = false; if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) { @@ -780,7 +748,6 @@ void NativeDeviceLost() { if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { gl_lost(); - glstate.Restore(); } // Should dirty EVERYTHING } diff --git a/Windows/OpenGLBase.cpp b/Windows/OpenGLBase.cpp index a2e0075273..572fb95ed9 100644 --- a/Windows/OpenGLBase.cpp +++ b/Windows/OpenGLBase.cpp @@ -1,6 +1,6 @@ #include "Common/CommonWindows.h" -#include "native/gfx_es2/gl_state.h" #include "native/gfx/gl_common.h" +#include "native/gfx_es2/gpu_features.h" #include "GL/gl.h" #include "GL/wglew.h" #include "Core/Config.h" @@ -237,7 +237,6 @@ bool GL_Init(HWND window, std::string *error_message) { return false; } - if (!m_hrc) { *error_message = "No m_hrc"; return false; @@ -245,7 +244,6 @@ bool GL_Init(HWND window, std::string *error_message) { hRC = m_hrc; - glstate.Initialize(); if (wglSwapIntervalEXT) wglSwapIntervalEXT(0); if (enableGLDebug && glewIsSupported("GL_ARB_debug_output")) { diff --git a/android/jni/TestRunner.cpp b/android/jni/TestRunner.cpp index ab96ef612f..80f0266f28 100644 --- a/android/jni/TestRunner.cpp +++ b/android/jni/TestRunner.cpp @@ -15,7 +15,6 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - // TO USE: // Simply copy pspautotests to the root of the USB memory / SD card of your android device. // Then go to Settings / Developer Menu / Run CPU tests. @@ -29,7 +28,7 @@ #include "base/basictypes.h" #include "base/display.h" #include "base/logging.h" -#include "gfx_es2/gl_state.h" +#include "gfx/gl_common.h" #include "Core/Core.h" #include "Core/System.h" @@ -38,7 +37,6 @@ #include "Core/MIPS/MIPS.h" #include "TestRunner.h" - static const char * const testsToRun[] = { "cpu/cpu_alu/cpu_alu", "cpu/fpu/fpu", @@ -153,8 +151,7 @@ void RunTests() } PSP_Shutdown(); } - glstate.Restore(); - glstate.viewport.set(0,0,pixel_xres,pixel_yres); + glViewport(0,0,pixel_xres,pixel_yres); PSP_CoreParameter().pixelWidth = pixel_xres; PSP_CoreParameter().pixelHeight = pixel_yres; PSP_CoreParameter().headLess = false; diff --git a/headless/WindowsHeadlessHost.cpp b/headless/WindowsHeadlessHost.cpp index 9fddc19d8a..a2977d5cab 100644 --- a/headless/WindowsHeadlessHost.cpp +++ b/headless/WindowsHeadlessHost.cpp @@ -28,7 +28,6 @@ #include "GPU/GPUState.h" #include "base/logging.h" -#include "gfx_es2/gl_state.h" #include "gfx/gl_common.h" #include "file/vfs.h" #include "file/zip_read.h" @@ -40,8 +39,7 @@ const int WINDOW_HEIGHT = 272; typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int value); PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = NULL; -HWND CreateHiddenWindow() -{ +HWND CreateHiddenWindow() { static WNDCLASSEX wndClass = { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW | CS_OWNDC, @@ -187,7 +185,6 @@ bool WindowsHeadlessHost::InitGraphics(std::string *error_message) SetVSync(0); glewInit(); - glstate.Initialize(); LoadNativeAssets(); @@ -218,8 +215,7 @@ bool WindowsHeadlessHost::ResizeGL() RECT rc; GetWindowRect(hWnd, &rc); - glstate.viewport.set(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); - glstate.viewport.restore(); + glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, WINDOW_WIDTH, WINDOW_HEIGHT, 0.0f, -1.0f, 1.0f); diff --git a/native b/native index e875f0a0c3..3f05c8d990 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit e875f0a0c3932fb7b80846e78c318fa36b2b5c6f +Subproject commit 3f05c8d99031931149a072c64cae51eb5635202b