From 808f05da8978fc2fa2ea046c43a7a1be433f98d4 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 17 Aug 2014 12:19:04 +0200 Subject: [PATCH] (Partially) slip thin3d underneath DrawBuffer. --- Common/KeyMap.cpp | 2 +- Core/Dialog/SavedataParam.cpp | 1 + Core/MIPS/JitCommon/JitBlockCache.cpp | 2 +- UI/ControlMappingScreen.cpp | 1 - UI/CwCheatScreen.cpp | 1 - UI/EmuScreen.cpp | 10 +-- UI/MiscScreens.cpp | 11 +-- UI/NativeApp.cpp | 25 ++++-- UI/UI.vcxproj | 4 +- UI/UI.vcxproj.filters | 2 - UI/UIShader.cpp | 113 -------------------------- UI/UIShader.h | 31 ------- Windows/OpenGLBase.cpp | 3 +- native | 2 +- 14 files changed, 31 insertions(+), 177 deletions(-) delete mode 100644 UI/UIShader.cpp delete mode 100644 UI/UIShader.h diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 6b3bfc5bad..bf7314a9fd 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -747,7 +747,7 @@ bool KeyFromPspButton(int btn, std::vector *keys) { bool AxisToPspButton(int deviceId, int axisId, int direction, std::vector *pspKeys) { int key = TranslateKeyCodeFromAxis(axisId, direction); - return KeyToPspButton(deviceId, key, pspKeys); + return KeyToPspButton(deviceId, key, pspKeys); } bool AxisFromPspButton(int btn, int *deviceId, int *axisId, int *direction) { diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 0abff6aefc..760fa3dd83 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -185,6 +185,7 @@ void SaveFileInfo::DoState(PointerWrap &p) p.Do(hasTexture); if (hasTexture) { if (p.mode == p.MODE_READ) { + delete texture; texture = new PPGeImage(""); } texture->DoState(p); diff --git a/Core/MIPS/JitCommon/JitBlockCache.cpp b/Core/MIPS/JitCommon/JitBlockCache.cpp index e0e42cbbc4..54fa8016ab 100644 --- a/Core/MIPS/JitCommon/JitBlockCache.cpp +++ b/Core/MIPS/JitCommon/JitBlockCache.cpp @@ -316,7 +316,7 @@ MIPSOpcode JitBlockCache::GetEmuHackOpForBlock(int blockNum) const { } int JitBlockCache::GetBlockNumberFromStartAddress(u32 addr, bool realBlocksOnly) { - if (!blocks_) + if (!blocks_ || !Memory::IsValidAddress(addr)) return -1; MIPSOpcode inst = MIPSOpcode(Memory::Read_U32(addr)); diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 9db228d193..ab5bb942c2 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -30,7 +30,6 @@ #include "Core/Config.h" #include "UI/ui_atlas.h" #include "UI/ControlMappingScreen.h" -#include "UI/UIShader.h" #include "UI/GameSettingsScreen.h" class ControlMapper : public UI::LinearLayout { diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index 498ed41aa0..b5dc4bd732 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -28,7 +28,6 @@ #include "UI/OnScreenDisplay.h" #include "UI/ui_atlas.h" #include "UI/GamepadEmu.h" -#include "UI/UIShader.h" #include "UI/MainScreen.h" #include "UI/EmuScreen.h" diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index d01cae3a31..0e10380169 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -50,7 +50,6 @@ #include "UI/ui_atlas.h" #include "UI/OnScreenDisplay.h" #include "UI/GamepadEmu.h" -#include "UI/UIShader.h" #include "UI/MainScreen.h" #include "UI/EmuScreen.h" #include "UI/DevScreens.h" @@ -705,14 +704,14 @@ void EmuScreen::render() { if (useBufferedRendering) fbo_unbind(); - UIShader_Prepare(); - - uiTexture->Bind(0); + screenManager()->getUIContext()->RebindTexture(); + Thin3DContext *thin3d = screenManager()->getThin3DContext(); glstate.viewport.set(0, 0, pixel_xres, pixel_yres); glstate.viewport.restore(); - ui_draw2d.Begin(UIShader_Get(), DBMODE_NORMAL); + thin3d->SetBlendState(thin3d->GetBlendStatePreset(BS_STANDARD_ALPHA)); + ui_draw2d.Begin(thin3d->GetShaderSetPreset(SS_TEXTURE_COLOR_2D), DBMODE_NORMAL); if (root_) { UI::LayoutViewHierarchy(*screenManager()->getUIContext(), root_); @@ -757,7 +756,6 @@ void EmuScreen::render() { ui_draw2d.SetFontScale(1.0f, 1.0f); } - glsl_bind(UIShader_Get()); ui_draw2d.End(); ui_draw2d.Flush(); diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index e91c6ea952..24e3903e26 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -18,7 +18,6 @@ #include "base/colorutil.h" #include "base/timeutil.h" #include "gfx_es2/draw_buffer.h" -#include "gfx_es2/gl_state.h" #include "file/vfs.h" #include "math/curves.h" #include "i18n/i18n.h" @@ -85,11 +84,8 @@ void DrawBackground(UIContext &dc, float alpha = 1.0f) { last_xres = xres; last_yres = yres; } - - glstate.depthWrite.set(GL_TRUE); - glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glClearColor(0.1f, 0.2f, 0.43f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + + dc.GetThin3DContext()->Clear(T3DClear::COLOR | T3DClear::DEPTH | T3DClear::STENCIL, 0xff224477, 0.0, 0); int img = I_BG; #ifdef GOLD img = I_BG_GOLD; @@ -396,15 +392,16 @@ bool LogoScreen::key(const KeyInput &key) { void LogoScreen::render() { UIScreen::render(); - UIContext &dc = *screenManager()->getUIContext(); + int error = glGetError(); const Bounds &bounds = dc.GetBounds(); float xres = dc.GetBounds().w; float yres = dc.GetBounds().h; dc.Begin(); + error = glGetError(); float t = (float)frames_ / 60.0f; float alpha = t; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 45cc19124b..45e42612e3 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -58,6 +58,7 @@ #include "math/fast/fast_math.h" #include "math/math_util.h" #include "math/lin/matrix4x4.h" +#include "thin3d/thin3d.h" #include "ui/ui.h" #include "ui/screen.h" #include "ui/ui_context.h" @@ -80,7 +81,6 @@ #include "ui_atlas.h" #include "EmuScreen.h" #include "GameInfoCache.h" -#include "UIShader.h" #include "HostTypes.h" #include "UI/OnScreenDisplay.h" @@ -132,6 +132,7 @@ struct PendingMessage { static recursive_mutex pendingMutex; static std::vector pendingMessages; +static Thin3DContext *thin3d; static UIContext *uiContext; std::thread *graphicsLoadThread; @@ -463,12 +464,13 @@ void NativeInit(int argc, const char *argv[], void NativeInitGraphics() { FPU_SetFastMode(); + thin3d = T3DCreateGLContext(); + CheckGLExtensions(); + ui_draw2d.SetAtlas(&ui_atlas); ui_draw2d_front.SetAtlas(&ui_atlas); - UIShader_Init(); - // memset(&ui_theme, 0, sizeof(ui_theme)); // New style theme #ifdef _WIN32 @@ -526,8 +528,8 @@ void NativeInitGraphics() { ui_theme.popupTitle.fgColor = 0xFF59BEE3; #endif - ui_draw2d.Init(); - ui_draw2d_front.Init(); + ui_draw2d.Init(thin3d); + ui_draw2d_front.Init(thin3d); uiTexture = new Texture(); #ifdef USING_QT_UI @@ -542,11 +544,13 @@ void NativeInitGraphics() { uiContext = new UIContext(); uiContext->theme = &ui_theme; - uiContext->Init(UIShader_Get(), UIShader_GetPlain(), uiTexture, &ui_draw2d, &ui_draw2d_front); + + uiContext->Init(thin3d, thin3d->GetShaderSetPreset(SS_TEXTURE_COLOR_2D), thin3d->GetShaderSetPreset(SS_COLOR_2D), uiTexture, &ui_draw2d, &ui_draw2d_front); if (uiContext->Text()) uiContext->Text()->SetFont("Tahoma", 20, 0); 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); @@ -576,7 +580,7 @@ void NativeShutdownGraphics() { ui_draw2d.Shutdown(); ui_draw2d_front.Shutdown(); - UIShader_Shutdown(); + thin3d->Release(); } void TakeScreenshot() { @@ -688,8 +692,11 @@ void NativeRender() { Matrix4x4 ortho; ortho.setOrtho(0.0f, xres, yres, 0.0f, -1.0f, 1.0f); - glsl_bind(UIShader_Get()); - glUniformMatrix4fv(UIShader_Get()->u_worldviewproj, 1, GL_FALSE, ortho.getReadPtr()); + ui_draw2d.SetDrawMatrix(ortho); + ui_draw2d_front.SetDrawMatrix(ortho); + + + // glsl_bind(UIShader_Get()); screenManager->render(); if (screenManager->getUIContext()->Text()) { diff --git a/UI/UI.vcxproj b/UI/UI.vcxproj index 938c45c27b..9202890720 100644 --- a/UI/UI.vcxproj +++ b/UI/UI.vcxproj @@ -38,7 +38,6 @@ - @@ -60,7 +59,6 @@ - @@ -192,4 +190,4 @@ - + \ No newline at end of file diff --git a/UI/UI.vcxproj.filters b/UI/UI.vcxproj.filters index 5cdfefd726..8a3740e483 100644 --- a/UI/UI.vcxproj.filters +++ b/UI/UI.vcxproj.filters @@ -5,7 +5,6 @@ - Screens @@ -53,7 +52,6 @@ - Screens diff --git a/UI/UIShader.cpp b/UI/UIShader.cpp deleted file mode 100644 index c982d983b9..0000000000 --- a/UI/UIShader.cpp +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) 2012- PPSSPP Project. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 2.0 or later versions. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#include "gfx_es2/glsl_program.h" -#include "gfx_es2/gl_state.h" -#include "UIShader.h" - -static GLSLProgram *glslModulate; -static GLSLProgram *glslPlain; - -static const char modulate_fs[] = - "#ifdef GL_ES\n" - "precision lowp float;\n" - "#endif\n" - "uniform sampler2D sampler0;\n" - "varying vec2 v_texcoord0;\n" - "varying vec4 v_color;\n" - "void main() {\n" - " gl_FragColor = texture2D(sampler0, v_texcoord0) * v_color;\n" - "}\n"; - -static const char modulate_vs[] = - "attribute vec4 a_position;\n" - "attribute vec4 a_color;\n" - "attribute vec2 a_texcoord0;\n" - "uniform mat4 u_worldviewproj;\n" - "varying vec2 v_texcoord0;\n" - "varying vec4 v_color;\n" - "void main() {\n" - " v_texcoord0 = a_texcoord0;\n" - " v_color = a_color;\n" - " gl_Position = u_worldviewproj * a_position;\n" - "}\n"; - -static const char plain_fs[] = - "#ifdef GL_ES\n" - "precision lowp float;\n" - "#endif\n" - "varying vec4 v_color;\n" - "void main() {\n" - " gl_FragColor = v_color;\n" - "}\n"; - -static const char plain_vs[] = - "attribute vec4 a_position;\n" - "attribute vec4 a_color;\n" - "uniform mat4 u_worldviewproj;\n" - "varying vec4 v_color;\n" - "void main() {\n" - " v_color = a_color;\n" - " gl_Position = u_worldviewproj * a_position;\n" - "}\n"; - -void UIShader_Init() { - // Compile UI shaders - glslModulate = glsl_create_source(modulate_vs, modulate_fs); - glslPlain = glsl_create_source(plain_vs, plain_fs); -} - -GLSLProgram *UIShader_Get() -{ - return glslModulate; -} - - -GLSLProgram *UIShader_GetPlain() -{ - return glslPlain; -} - -void UIShader_Shutdown() -{ - glsl_destroy(glslModulate); - glsl_destroy(glslPlain); -} - -void UIShader_Prepare() -{ - // Draw 2D overlay stuff - glstate.cullFace.disable(); - glstate.depthTest.disable(); - glstate.scissorTest.disable(); - glstate.stencilTest.disable(); - glstate.stencilMask.set(0xFF); -#if !defined(USING_GLES2) - glstate.colorLogicOp.disable(); -#endif - glstate.dither.enable(); - - glstate.blend.enable(); - glstate.blendFuncSeparate.set(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glstate.blendEquationSeparate.set(GL_FUNC_ADD, GL_FUNC_ADD); - - glstate.depthWrite.set(GL_TRUE); - glstate.colorMask.set(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glstate.Restore(); - - uiTexture->Bind(0); -} diff --git a/UI/UIShader.h b/UI/UIShader.h deleted file mode 100644 index 6edb962c3d..0000000000 --- a/UI/UIShader.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2012- PPSSPP Project. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 2.0 or later versions. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#pragma once - -#include "gfx_es2/glsl_program.h" -#include "gfx/texture.h" - -void UIShader_Init(); -GLSLProgram *UIShader_Get(); -GLSLProgram *UIShader_GetPlain(); // Just color -void UIShader_Shutdown(); - -void UIShader_Prepare(); - -// TODO: Remove -extern Texture *uiTexture; \ No newline at end of file diff --git a/Windows/OpenGLBase.cpp b/Windows/OpenGLBase.cpp index a6b5bd66a0..437bac92f3 100644 --- a/Windows/OpenGLBase.cpp +++ b/Windows/OpenGLBase.cpp @@ -19,7 +19,7 @@ static HWND hWnd; // Holds Our Window Handle static int xres, yres; // TODO: Make config? -static bool enableGLDebug = false; +static bool enableGLDebug = true; void GL_SwapBuffers() { SwapBuffers(hDC); @@ -71,6 +71,7 @@ void DebugCallbackARB(GLenum source, GLenum type, GLuint id, GLenum severity, FILE *outFile = (FILE*)userParam; char finalMessage[256]; FormatDebugOutputARB(finalMessage, 256, source, type, id, severity, message); + OutputDebugStringA(finalMessage); ERROR_LOG(G3D, "GL: %s", finalMessage); } diff --git a/native b/native index 2ba8e36b2b..ff5df25135 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 2ba8e36b2bde65021c9a5c0f937a0e3892c2ad62 +Subproject commit ff5df25135423a06357d5e455be19acfec81663f