diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index f375661e0b..d5974ecca6 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -48,6 +48,11 @@ if(WIN32) set(SRCS ${SRCS} ExtendedTrace.cpp) endif(WIN32) +set(LIBS "${CMAKE_THREAD_LIBS_INIT}") +if((NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") AND (NOT ANDROID)) + set(LIBS ${LIBS} rt) +endif() + enable_precompiled_headers(stdafx.h stdafx.cpp SRCS) -add_dolphin_library(common "${SRCS}" "${CMAKE_THREAD_LIBS_INIT}") +add_dolphin_library(common "${SRCS}" "${LIBS}") diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 77f778c877..1bf53a0519 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -221,7 +221,18 @@ if(_M_ARM_32) ) endif() -set(LIBS bdisasm inputcommon videoogl videosoftware sfml-network) +set(LIBS + audiocommon + bdisasm + common + discio + inputcommon + ${LZO} + sfml-network + videoogl + videosoftware + z + ) if(LIBUSB_FOUND) # Using shared LibUSB @@ -236,6 +247,8 @@ if(WIN32) HW/WiimoteReal/IOWin.cpp) elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(SRCS ${SRCS} HW/BBA-TAP/TAP_Apple.cpp HW/WiimoteReal/IOdarwin.mm) + set(LIBS ${LIBS} + ${IOB_LIBRARY}) elseif(UNIX) set(SRCS ${SRCS} HW/BBA-TAP/TAP_Unix.cpp) if((${CMAKE_SYSTEM_NAME} MATCHES "Linux") AND BLUEZ_FOUND) diff --git a/Source/Core/Core/Host.h b/Source/Core/Core/Host.h index 202db8ab82..23796cc807 100644 --- a/Source/Core/Core/Host.h +++ b/Source/Core/Core/Host.h @@ -42,6 +42,8 @@ void Host_UpdateLogDisplay(); void Host_UpdateMainFrame(); void Host_UpdateStatusBar(const std::string& text, int Filed = 0); void Host_UpdateTitle(const std::string& title); +void Host_ShowVideoConfig(void* parent, const std::string& backend_name, + const std::string& config_name); // TODO (neobrain): Remove this from host! void* Host_GetRenderHandle(); diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index 685f2d30c4..ed20786896 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -4,41 +4,17 @@ endif() set(LIBS core ${LZO} - discio - bdisasm - inputcommon - common - audiocommon - z - sfml-network ${GTK2_LIBRARIES}) -if((NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") AND (NOT ANDROID)) - set(LIBS ${LIBS} rt) -endif() - if(NOT ANDROID) if(USE_X11) - set(LIBS ${LIBS} ${X11_LIBRARIES} - ${XINPUT2_LIBRARIES} - ${XRANDR_LIBRARIES}) + set(LIBS ${LIBS} ${XRANDR_LIBRARIES}) endif() if(USE_WAYLAND) - set(LIBS ${LIBS} ${WAYLAND_LIBRARIES} - ${XKBCOMMON_LIBRARIES}) + set(LIBS ${LIBS} ${WAYLAND_LIBRARIES} ${XKBCOMMON_LIBRARIES}) endif() link_directories(${CMAKE_PREFIX_PATH}/lib) - - if(SDL2_FOUND) - # Using shared SDL2 - set(LIBS ${LIBS} ${SDL2_LIBRARY}) - else(SDL2_FOUND) - if(SDL_FOUND) - # Using shared SDL - set(LIBS ${LIBS} ${SDL_LIBRARY}) - endif() - endif() else() set(LIBS ${LIBS} png iconv) endif() @@ -87,6 +63,7 @@ if(wxWidgets_FOUND) MemoryCards/WiiSaveCrypted.cpp NetWindow.cpp PatchAddEdit.cpp + SoftwareVideoConfigDialog.cpp TASInputDlg.cpp VideoConfigDiag.cpp WXInputBase.cpp @@ -123,6 +100,7 @@ else() endif() endif() +set(SRCS ${SRCS} GLInterface/GLInterface.cpp) if(WIN32) set(SRCS ${SRCS} stdafx.cpp) @@ -134,7 +112,6 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") ${COREAUDIO_LIBRARY} ${COREFUND_LIBRARY} ${CORESERV_LIBRARY} - ${IOB_LIBRARY} ${IOK_LIBRARY} ${FORCEFEEDBACK} ) diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj b/Source/Core/DolphinWX/DolphinWX.vcxproj index b56308c6a4..e62e2f2e43 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj @@ -74,6 +74,7 @@ + @@ -90,6 +91,7 @@ + Create @@ -125,7 +127,6 @@ - @@ -139,6 +140,7 @@ + diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj.filters b/Source/Core/DolphinWX/DolphinWX.vcxproj.filters index 19ddf71a1b..b9910845a8 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj.filters +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj.filters @@ -27,6 +27,7 @@ + @@ -153,9 +154,11 @@ GUI + + GUI\Video + - @@ -276,6 +279,9 @@ + + GUI\Video + diff --git a/Source/Core/DolphinWX/GLInterface/AGL.h b/Source/Core/DolphinWX/GLInterface/AGL.h index 8f75df51cd..490691338d 100644 --- a/Source/Core/DolphinWX/GLInterface/AGL.h +++ b/Source/Core/DolphinWX/GLInterface/AGL.h @@ -8,7 +8,7 @@ #import #endif -#include "DolphinWX/GLInterface/InterfaceBase.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" class cInterfaceAGL : public cInterfaceBase { diff --git a/Source/Core/DolphinWX/GLInterface/EGL.h b/Source/Core/DolphinWX/GLInterface/EGL.h index c525b4d7a7..e2994f3b96 100644 --- a/Source/Core/DolphinWX/GLInterface/EGL.h +++ b/Source/Core/DolphinWX/GLInterface/EGL.h @@ -8,7 +8,7 @@ #include #include "Core/ConfigManager.h" -#include "DolphinWX/GLInterface/InterfaceBase.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" class cPlatform diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.cpp b/Source/Core/DolphinWX/GLInterface/GLInterface.cpp new file mode 100644 index 0000000000..bb9ce669e2 --- /dev/null +++ b/Source/Core/DolphinWX/GLInterface/GLInterface.cpp @@ -0,0 +1,23 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "DolphinWX/GLInterface/GLInterface.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" + +GLWindow GLWin; + +cInterfaceBase* HostGL_CreateGLInterface() +{ + #if defined(USE_EGL) && USE_EGL + return new cInterfaceEGL; + #elif defined(__APPLE__) + return new cInterfaceAGL; + #elif defined(_WIN32) + return new cInterfaceWGL; + #elif defined(HAVE_X11) && HAVE_X11 + return new cInterfaceGLX; + #else + return nullptr; + #endif +} diff --git a/Source/Core/DolphinWX/GLInterface/GLInterface.h b/Source/Core/DolphinWX/GLInterface/GLInterface.h index edd7d93665..26c92f53d4 100644 --- a/Source/Core/DolphinWX/GLInterface/GLInterface.h +++ b/Source/Core/DolphinWX/GLInterface/GLInterface.h @@ -108,5 +108,4 @@ typedef struct { unsigned int width, height; } GLWindow; -extern cInterfaceBase *GLInterface; extern GLWindow GLWin; diff --git a/Source/Core/DolphinWX/GLInterface/GLX.h b/Source/Core/DolphinWX/GLInterface/GLX.h index ca64e62b48..1ded9ec331 100644 --- a/Source/Core/DolphinWX/GLInterface/GLX.h +++ b/Source/Core/DolphinWX/GLInterface/GLX.h @@ -6,8 +6,8 @@ #include -#include "DolphinWX/GLInterface/InterfaceBase.h" #include "DolphinWX/GLInterface/X11_Util.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" class cInterfaceGLX : public cInterfaceBase { diff --git a/Source/Core/DolphinWX/GLInterface/WGL.h b/Source/Core/DolphinWX/GLInterface/WGL.h index 7a0d3ff20d..529168b578 100644 --- a/Source/Core/DolphinWX/GLInterface/WGL.h +++ b/Source/Core/DolphinWX/GLInterface/WGL.h @@ -5,7 +5,7 @@ #pragma once #include -#include "DolphinWX/GLInterface/InterfaceBase.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" class cInterfaceWGL : public cInterfaceBase { diff --git a/Source/Core/DolphinWX/Main.cpp b/Source/Core/DolphinWX/Main.cpp index 0dfc76d01b..68aa986a8d 100644 --- a/Source/Core/DolphinWX/Main.cpp +++ b/Source/Core/DolphinWX/Main.cpp @@ -46,6 +46,8 @@ #include "DolphinWX/Frame.h" #include "DolphinWX/Globals.h" #include "DolphinWX/Main.h" +#include "DolphinWX/SoftwareVideoConfigDialog.h" +#include "DolphinWX/VideoConfigDiag.h" #include "DolphinWX/WxUtils.h" #include "DolphinWX/Debugger/CodeWindow.h" #include "DolphinWX/Debugger/JitWindow.h" @@ -686,3 +688,18 @@ void Host_ConnectWiimote(int wm_idx, bool connect) { CFrame::ConnectWiimote(wm_idx, connect); } + +void Host_ShowVideoConfig(void* parent, const std::string& backend_name, + const std::string& config_name) +{ + if (backend_name == "Direct3D" || backend_name == "OpenGL") + { + VideoConfigDiag diag((wxWindow*)parent, backend_name, config_name); + diag.ShowModal(); + } + else if (backend_name == "Software Renderer") + { + SoftwareVideoConfigDialog diag((wxWindow*)parent, backend_name, config_name); + diag.ShowModal(); + } +} diff --git a/Source/Core/DolphinWX/MainAndroid.cpp b/Source/Core/DolphinWX/MainAndroid.cpp index c7d706814c..b8f05b4684 100644 --- a/Source/Core/DolphinWX/MainAndroid.cpp +++ b/Source/Core/DolphinWX/MainAndroid.cpp @@ -125,6 +125,8 @@ void Host_SysMessage(const char *fmt, ...) void Host_SetWiiMoteConnectionState(int _State) {} +void Host_ShowVideoConfig(void*, const std::string&, const std::string&) {} + #define DVD_BANNER_WIDTH 96 #define DVD_BANNER_HEIGHT 32 std::vector m_volume_names; diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index eb9167599c..6deebab93b 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -17,6 +17,7 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/CoreParameter.h" +#include "Core/Host.h" #include "Core/HW/Wiimote.h" #include "Core/PowerPC/PowerPC.h" @@ -133,6 +134,8 @@ void Host_SysMessage(const char *fmt, ...) void Host_SetWiiMoteConnectionState(int _State) {} +void Host_ShowVideoConfig(void*, const std::string&, const std::string&) {} + #if HAVE_X11 void X11_MainLoop() { diff --git a/Source/Core/DolphinWX/SoftwareVideoConfigDialog.cpp b/Source/Core/DolphinWX/SoftwareVideoConfigDialog.cpp new file mode 100644 index 0000000000..ddd5f710ff --- /dev/null +++ b/Source/Core/DolphinWX/SoftwareVideoConfigDialog.cpp @@ -0,0 +1,144 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Common/FileUtil.h" +#include "Core/Core.h" +#include "DolphinWX/SoftwareVideoConfigDialog.h" +#include "DolphinWX/VideoConfigDiag.h" +#include "DolphinWX/WxUtils.h" + +template +IntegerSetting::IntegerSetting(wxWindow* parent, const wxString& label, T& setting, int minVal, int maxVal, long style) : + wxSpinCtrl(parent, -1, label, wxDefaultPosition, wxDefaultSize, style), + m_setting(setting) +{ + SetRange(minVal, maxVal); + SetValue(m_setting); + Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, &IntegerSetting::UpdateValue, this); +} + + +SoftwareVideoConfigDialog::SoftwareVideoConfigDialog(wxWindow* parent, const std::string& title, const std::string& _ininame) : + wxDialog(parent, -1, + wxString(wxString::Format(_("Dolphin %s Graphics Configuration"), title))), + vconfig(g_SWVideoConfig), + ininame(_ininame) +{ + vconfig.Load((File::GetUserPath(D_CONFIG_IDX) + ininame + ".ini").c_str()); + + wxNotebook* const notebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize); + + // -- GENERAL -- + { + wxPanel* const page_general= new wxPanel(notebook, -1, wxDefaultPosition); + notebook->AddPage(page_general, wxT("General")); + wxBoxSizer* const szr_general = new wxBoxSizer(wxVERTICAL); + + // - rendering + { + wxStaticBoxSizer* const group_rendering = new wxStaticBoxSizer(wxVERTICAL, page_general, wxT("Rendering")); + szr_general->Add(group_rendering, 0, wxEXPAND | wxALL, 5); + wxGridSizer* const szr_rendering = new wxGridSizer(2, 5, 5); + group_rendering->Add(szr_rendering, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); + + // backend + wxStaticText* const label_backend = new wxStaticText(page_general, wxID_ANY, _("Backend:")); + wxChoice* const choice_backend = new wxChoice(page_general, wxID_ANY, wxDefaultPosition); + + for (const VideoBackend* backend : g_available_video_backends) + { + choice_backend->AppendString(StrToWxStr(backend->GetDisplayName())); + } + + // TODO: How to get the translated plugin name? + choice_backend->SetStringSelection(StrToWxStr(g_video_backend->GetName())); + choice_backend->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &SoftwareVideoConfigDialog::Event_Backend, this); + + szr_rendering->Add(label_backend, 1, wxALIGN_CENTER_VERTICAL, 5); + szr_rendering->Add(choice_backend, 1, 0, 0); + + if (Core::GetState() != Core::CORE_UNINITIALIZED) + { + label_backend->Disable(); + choice_backend->Disable(); + } + + // rasterizer + szr_rendering->Add(new SettingCheckBox(page_general, wxT("Hardware rasterization"), wxT(""), vconfig.bHwRasterizer)); + + // xfb + szr_rendering->Add(new SettingCheckBox(page_general, wxT("Bypass XFB"), wxT(""), vconfig.bBypassXFB)); + } + + // - info + { + wxStaticBoxSizer* const group_info = new wxStaticBoxSizer(wxVERTICAL, page_general, wxT("Overlay Information")); + szr_general->Add(group_info, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); + wxGridSizer* const szr_info = new wxGridSizer(2, 5, 5); + group_info->Add(szr_info, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); + + szr_info->Add(new SettingCheckBox(page_general, wxT("Various Statistics"), wxT(""), vconfig.bShowStats)); + } + + // - utility + { + wxStaticBoxSizer* const group_utility = new wxStaticBoxSizer(wxVERTICAL, page_general, wxT("Utility")); + szr_general->Add(group_utility, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); + wxGridSizer* const szr_utility = new wxGridSizer(2, 5, 5); + group_utility->Add(szr_utility, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); + + szr_utility->Add(new SettingCheckBox(page_general, wxT("Dump Textures"), wxT(""), vconfig.bDumpTextures)); + szr_utility->Add(new SettingCheckBox(page_general, wxT("Dump Objects"), wxT(""), vconfig.bDumpObjects)); + szr_utility->Add(new SettingCheckBox(page_general, wxT("Dump Frames"), wxT(""), vconfig.bDumpFrames)); + + // - debug only + wxStaticBoxSizer* const group_debug_only_utility = new wxStaticBoxSizer(wxHORIZONTAL, page_general, wxT("Debug Only")); + group_utility->Add(group_debug_only_utility, 0, wxEXPAND | wxBOTTOM, 5); + wxGridSizer* const szr_debug_only_utility = new wxGridSizer(2, 5, 5); + group_debug_only_utility->Add(szr_debug_only_utility, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); + + szr_debug_only_utility->Add(new SettingCheckBox(page_general, wxT("Dump TEV Stages"), wxT(""), vconfig.bDumpTevStages)); + szr_debug_only_utility->Add(new SettingCheckBox(page_general, wxT("Dump Texture Fetches"), wxT(""), vconfig.bDumpTevTextureFetches)); + } + + // - misc + { + wxStaticBoxSizer* const group_misc = new wxStaticBoxSizer(wxVERTICAL, page_general, wxT("Drawn Object Range")); + szr_general->Add(group_misc, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); + wxFlexGridSizer* const szr_misc = new wxFlexGridSizer(2, 5, 5); + group_misc->Add(szr_misc, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5); + + szr_misc->Add(new U32Setting(page_general, wxT("Start"), vconfig.drawStart, 0, 100000)); + szr_misc->Add(new U32Setting(page_general, wxT("End"), vconfig.drawEnd, 0, 100000)); + } + + page_general->SetSizerAndFit(szr_general); + } + + wxBoxSizer* const szr_main = new wxBoxSizer(wxVERTICAL); + szr_main->Add(notebook, 1, wxEXPAND | wxALL, 5); + szr_main->Add(new wxButton(this, wxID_OK, wxT("Close"), wxDefaultPosition), + 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 5); + + SetSizerAndFit(szr_main); + Center(); + SetFocus(); +} + +SoftwareVideoConfigDialog::~SoftwareVideoConfigDialog() +{ + g_SWVideoConfig.Save((File::GetUserPath(D_CONFIG_IDX) + ininame + ".ini").c_str()); +} diff --git a/Source/Core/DolphinWX/SoftwareVideoConfigDialog.h b/Source/Core/DolphinWX/SoftwareVideoConfigDialog.h new file mode 100644 index 0000000000..5c394dfc16 --- /dev/null +++ b/Source/Core/DolphinWX/SoftwareVideoConfigDialog.h @@ -0,0 +1,51 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +// TODO: Merge this with the original VideoConfigDiag or something +// This is an awful way of managing a separate video backend. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Core/ConfigManager.h" +#include "VideoBackends/Software/SWVideoConfig.h" +#include "VideoCommon/VideoBackendBase.h" + +class SoftwareVideoConfigDialog : public wxDialog +{ +public: + SoftwareVideoConfigDialog(wxWindow* parent, const std::string &title, const std::string& ininame); + ~SoftwareVideoConfigDialog(); + + void Event_Backend(wxCommandEvent &ev) + { + VideoBackend* new_backend = g_available_video_backends[ev.GetInt()]; + + if (g_video_backend != new_backend) + { + Close(); + + g_video_backend = new_backend; + SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend = g_video_backend->GetName(); + + g_video_backend->ShowConfig(GetParent()); + } + ev.Skip(); + } + +protected: + SWVideoConfig& vconfig; + std::string ininame; +}; diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp index 37d7fb8bbd..997fc5a1c5 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp @@ -31,6 +31,7 @@ #include "DolphinWX/Main.h" #include "DolphinWX/VideoConfigDiag.h" #include "DolphinWX/WxUtils.h" +#include "VideoBackends/OGL/main.h" #include "VideoCommon/VideoBackendBase.h" #include "VideoCommon/VideoConfig.h" diff --git a/Source/Core/InputCommon/CMakeLists.txt b/Source/Core/InputCommon/CMakeLists.txt index 6b771c38e1..92fce634e3 100644 --- a/Source/Core/InputCommon/CMakeLists.txt +++ b/Source/Core/InputCommon/CMakeLists.txt @@ -4,6 +4,9 @@ set(SRCS ControllerEmu.cpp ControllerInterface/Device.cpp ControllerInterface/ExpressionParser.cpp) + +set(LIBS common) + if(WIN32) set(SRCS ${SRCS} ControllerInterface/DInput/DInput.cpp @@ -24,6 +27,7 @@ elseif(X11_FOUND) set(SRCS ${SRCS} ControllerInterface/Xlib/XInput2.cpp) endif() + set(LIBS ${LIBS} ${X11_LIBRARIES} ${XINPUT2_LIBRARIES}) elseif(ANDROID) set(SRCS ${SRCS} ControllerInterface/Android/Android.cpp) @@ -31,6 +35,11 @@ endif() if(SDL_FOUND OR SDL2_FOUND) set(SRCS ${SRCS} ControllerInterface/SDL/SDL.cpp) + if (SDL2_FOUND) + set(LIBS ${LIBS} ${SDL2_LIBRARY}) + elseif(SDL_FOUND) + set(LIBS ${LIBS} ${SDL_LIBRARY}) + endif() endif() -add_dolphin_library(inputcommon "${SRCS}" "") +add_dolphin_library(inputcommon "${SRCS}" "${LIBS}") diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index a2534b56a1..fc797ebdec 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -5,10 +5,6 @@ #include "Common/Thread.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" -#if USE_EGL -#include "DolphinWX/GLInterface/GLInterface.h" -#endif - #ifdef CIFACE_USE_XINPUT #include "InputCommon/ControllerInterface/XInput/XInput.h" #endif @@ -57,16 +53,10 @@ void ControllerInterface::Initialize() ciface::XInput::Init(m_devices); #endif #ifdef CIFACE_USE_XLIB -#if USE_EGL -if (GLWin.platform == EGL_PLATFORM_X11) { -#endif ciface::Xlib::Init(m_devices, m_hwnd); #ifdef CIFACE_USE_X11_XINPUT2 ciface::XInput2::Init(m_devices, m_hwnd); #endif -#if USE_EGL -} -#endif #endif #ifdef CIFACE_USE_OSX ciface::OSX::Init(m_devices, m_hwnd); diff --git a/Source/Core/VideoBackends/D3D/main.cpp b/Source/Core/VideoBackends/D3D/main.cpp index 1e78abfcb7..42c492b793 100644 --- a/Source/Core/VideoBackends/D3D/main.cpp +++ b/Source/Core/VideoBackends/D3D/main.cpp @@ -3,7 +3,6 @@ // Refer to the license.txt file included. #include -#include #include "Common/FileUtil.h" #include "Common/IniFile.h" @@ -14,9 +13,6 @@ #include "Core/Core.h" #include "Core/Host.h" -#include "DolphinWX/VideoConfigDiag.h" -#include "DolphinWX/Debugger/DebuggerPanel.h" - #include "VideoBackends/D3D/D3DBase.h" #include "VideoBackends/D3D/D3DUtil.h" #include "VideoBackends/D3D/Globals.h" @@ -139,13 +135,10 @@ void InitBackendInfo() DX11::D3D::UnloadD3D(); } -void VideoBackend::ShowConfig(void *_hParent) +void VideoBackend::ShowConfig(void *hParent) { -#if defined(HAVE_WX) && HAVE_WX InitBackendInfo(); - VideoConfigDiag diag((wxWindow*)_hParent, _trans("Direct3D"), "gfx_dx11"); - diag.ShowModal(); -#endif + Host_ShowVideoConfig(hParent, GetDisplayName(), "gfx_dx11"); } bool VideoBackend::Initialize(void *&window_handle) diff --git a/Source/Core/VideoBackends/OGL/GLExtensions/GLExtensions.cpp b/Source/Core/VideoBackends/OGL/GLExtensions/GLExtensions.cpp index 7b70871ccb..f81f277a36 100644 --- a/Source/Core/VideoBackends/OGL/GLExtensions/GLExtensions.cpp +++ b/Source/Core/VideoBackends/OGL/GLExtensions/GLExtensions.cpp @@ -6,6 +6,7 @@ #include #include "Common/Logging/Log.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/GLExtensions/GLExtensions.h" #if defined(__linux__) || defined(__APPLE__) diff --git a/Source/Core/VideoBackends/OGL/GLExtensions/GLExtensions.h b/Source/Core/VideoBackends/OGL/GLExtensions/GLExtensions.h index cb52c6ba53..b7cacd7650 100644 --- a/Source/Core/VideoBackends/OGL/GLExtensions/GLExtensions.h +++ b/Source/Core/VideoBackends/OGL/GLExtensions/GLExtensions.h @@ -4,8 +4,6 @@ #include -#include "DolphinWX/GLInterface/GLInterface.h" - #include "VideoBackends/OGL/GLExtensions/ARB_blend_func_extended.h" #include "VideoBackends/OGL/GLExtensions/ARB_buffer_storage.h" #include "VideoBackends/OGL/GLExtensions/ARB_debug_output.h" diff --git a/Source/Core/DolphinWX/GLInterface/InterfaceBase.h b/Source/Core/VideoBackends/OGL/GLInterfaceBase.h similarity index 83% rename from Source/Core/DolphinWX/GLInterface/InterfaceBase.h rename to Source/Core/VideoBackends/OGL/GLInterfaceBase.h index c709e52bf5..bfddeb0c70 100644 --- a/Source/Core/DolphinWX/GLInterface/InterfaceBase.h +++ b/Source/Core/VideoBackends/OGL/GLInterfaceBase.h @@ -41,3 +41,9 @@ public: virtual void Update() { } virtual bool PeekMessages() { return false; } }; + +extern cInterfaceBase *GLInterface; + +// This function has to be defined along the Host_ functions from Core/Host.h. +// Current canonical implementation: DolphinWX/GLInterface/GLInterface.cpp. +cInterfaceBase* HostGL_CreateGLInterface(); diff --git a/Source/Core/VideoBackends/OGL/GLUtil.cpp b/Source/Core/VideoBackends/OGL/GLUtil.cpp index 97d4378239..ac3894e42d 100644 --- a/Source/Core/VideoBackends/OGL/GLUtil.cpp +++ b/Source/Core/VideoBackends/OGL/GLUtil.cpp @@ -8,13 +8,13 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/GLUtil.h" #include "VideoBackends/OGL/Render.h" #include "VideoBackends/OGL/VideoBackend.h" #include "VideoCommon/VideoConfig.h" -GLWindow GLWin; cInterfaceBase *GLInterface; namespace OGL @@ -35,15 +35,7 @@ void VideoBackend::UpdateFPSDisplay(const std::string& text) } void InitInterface() { - #if defined(USE_EGL) && USE_EGL - GLInterface = new cInterfaceEGL; - #elif defined(__APPLE__) - GLInterface = new cInterfaceAGL; - #elif defined(_WIN32) - GLInterface = new cInterfaceWGL; - #elif defined(HAVE_X11) && HAVE_X11 - GLInterface = new cInterfaceGLX; - #endif + GLInterface = HostGL_CreateGLInterface(); } GLuint OpenGL_CompileProgram(const char* vertexShader, const char* fragmentShader) diff --git a/Source/Core/VideoBackends/OGL/GLUtil.h b/Source/Core/VideoBackends/OGL/GLUtil.h index a46e381586..16c91baa65 100644 --- a/Source/Core/VideoBackends/OGL/GLUtil.h +++ b/Source/Core/VideoBackends/OGL/GLUtil.h @@ -5,7 +5,6 @@ #pragma once #include "Common/MathUtil.h" -#include "DolphinWX/GLInterface/GLInterface.h" #include "VideoBackends/OGL/GLExtensions/GLExtensions.h" #include "VideoCommon/VideoConfig.h" diff --git a/Source/Core/VideoBackends/OGL/PerfQuery.cpp b/Source/Core/VideoBackends/OGL/PerfQuery.cpp index 8e2de6dd4e..178ef7108e 100644 --- a/Source/Core/VideoBackends/OGL/PerfQuery.cpp +++ b/Source/Core/VideoBackends/OGL/PerfQuery.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "DolphinWX/GLInterface/GLInterface.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/GLUtil.h" #include "VideoBackends/OGL/PerfQuery.h" #include "VideoCommon/RenderBase.h" diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index c9b373918b..a3bba96fd1 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -20,6 +20,7 @@ #include "Core/Movie.h" #include "VideoBackends/OGL/FramebufferManager.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/GLUtil.h" #include "VideoBackends/OGL/main.h" #include "VideoBackends/OGL/PostProcessing.h" @@ -1459,7 +1460,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl if (!bLastFrameDumped) { #ifdef _WIN32 - bAVIDumping = AVIDump::Start((HWND)((cInterfaceWGL*)GLInterface)->m_window_handle, w, h); + bAVIDumping = AVIDump::Start(nullptr, w, h); #else bAVIDumping = AVIDump::Start(w, h); #endif diff --git a/Source/Core/VideoBackends/OGL/SamplerCache.cpp b/Source/Core/VideoBackends/OGL/SamplerCache.cpp index c9bf699843..2b422e1f55 100644 --- a/Source/Core/VideoBackends/OGL/SamplerCache.cpp +++ b/Source/Core/VideoBackends/OGL/SamplerCache.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/SamplerCache.h" #include "VideoCommon/DriverDetails.h" diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index 145bc0086e..9837795ce6 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -19,6 +19,7 @@ #include "Core/HW/Memmap.h" #include "VideoBackends/OGL/FramebufferManager.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/ProgramShaderCache.h" #include "VideoBackends/OGL/Render.h" #include "VideoBackends/OGL/TextureCache.h" diff --git a/Source/Core/VideoBackends/OGL/main.cpp b/Source/Core/VideoBackends/OGL/main.cpp index 8ee6471019..44febec4a9 100644 --- a/Source/Core/VideoBackends/OGL/main.cpp +++ b/Source/Core/VideoBackends/OGL/main.cpp @@ -49,6 +49,7 @@ Make AA apply instantly during gameplay if possible #include "Core/Host.h" #include "VideoBackends/OGL/FramebufferManager.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/GLUtil.h" #include "VideoBackends/OGL/PerfQuery.h" #include "VideoBackends/OGL/PostProcessing.h" @@ -82,11 +83,6 @@ Make AA apply instantly during gameplay if possible #include "Common/IniFile.h" #endif -#if defined(HAVE_WX) && HAVE_WX -#include "DolphinWX/VideoConfigDiag.h" -#include "DolphinWX/Debugger/DebuggerPanel.h" -#endif // HAVE_WX - namespace OGL { @@ -160,11 +156,8 @@ static void InitBackendInfo() void VideoBackend::ShowConfig(void *_hParent) { -#if defined(HAVE_WX) && HAVE_WX InitBackendInfo(); - VideoConfigDiag diag((wxWindow*)_hParent, "OpenGL", "gfx_opengl"); - diag.ShowModal(); -#endif + Host_ShowVideoConfig(_hParent, GetDisplayName(), "gfx_opengl"); } bool VideoBackend::Initialize(void *&window_handle) diff --git a/Source/Core/VideoBackends/OGL/main.h b/Source/Core/VideoBackends/OGL/main.h index 0866e823a7..82edcab740 100644 --- a/Source/Core/VideoBackends/OGL/main.h +++ b/Source/Core/VideoBackends/OGL/main.h @@ -4,4 +4,6 @@ #pragma once +#include + #include "VideoCommon/MainBase.h" diff --git a/Source/Core/VideoBackends/Software/EfbCopy.cpp b/Source/Core/VideoBackends/Software/EfbCopy.cpp index 479cc35ddc..5c4e1e24c3 100644 --- a/Source/Core/VideoBackends/Software/EfbCopy.cpp +++ b/Source/Core/VideoBackends/Software/EfbCopy.cpp @@ -4,6 +4,7 @@ #include "Core/Core.h" #include "Core/HW/Memmap.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/Software/BPMemLoader.h" #include "VideoBackends/Software/DebugUtil.h" #include "VideoBackends/Software/EfbCopy.h" diff --git a/Source/Core/VideoBackends/Software/HwRasterizer.cpp b/Source/Core/VideoBackends/Software/HwRasterizer.cpp index 5645c26bf9..05460da312 100644 --- a/Source/Core/VideoBackends/Software/HwRasterizer.cpp +++ b/Source/Core/VideoBackends/Software/HwRasterizer.cpp @@ -5,6 +5,7 @@ #include "Common/Common.h" #include "Common/MemoryUtil.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/Software/BPMemLoader.h" #include "VideoBackends/Software/DebugUtil.h" #include "VideoBackends/Software/HwRasterizer.h" diff --git a/Source/Core/VideoBackends/Software/SWRenderer.cpp b/Source/Core/VideoBackends/Software/SWRenderer.cpp index f94fad595a..c94e19a31f 100644 --- a/Source/Core/VideoBackends/Software/SWRenderer.cpp +++ b/Source/Core/VideoBackends/Software/SWRenderer.cpp @@ -8,6 +8,7 @@ #include "Common/Common.h" #include "Common/StringUtil.h" #include "Core/Core.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/GLUtil.h" #include "VideoBackends/Software/RasterFont.h" #include "VideoBackends/Software/SWCommandProcessor.h" diff --git a/Source/Core/VideoBackends/Software/SWmain.cpp b/Source/Core/VideoBackends/Software/SWmain.cpp index c4a6d2f0c8..415fa0547b 100644 --- a/Source/Core/VideoBackends/Software/SWmain.cpp +++ b/Source/Core/VideoBackends/Software/SWmain.cpp @@ -12,9 +12,11 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" +#include "Core/Host.h" #include "Core/HW/Memmap.h" #include "Core/HW/VideoInterface.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" #include "VideoBackends/OGL/GLExtensions/GLExtensions.h" #include "VideoBackends/Software/BPMemLoader.h" #include "VideoBackends/Software/Clipper.h" @@ -31,10 +33,6 @@ #include "VideoBackends/Software/VideoBackend.h" #include "VideoBackends/Software/XFMemLoader.h" -#if defined(HAVE_WX) && HAVE_WX -#include "VideoBackends/Software/VideoConfigDialog.h" -#endif // HAVE_WX - #include "VideoCommon/Fifo.h" #include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/PixelEngine.h" @@ -60,15 +58,17 @@ static std::mutex m_csSWVidOccupied; std::string VideoSoftware::GetName() const { - return _trans("Software Renderer"); + return "Software Renderer"; } -void VideoSoftware::ShowConfig(void *_hParent) +std::string VideoSoftware::GetDisplayName() const { -#if defined(HAVE_WX) && HAVE_WX - VideoConfigDialog diag((wxWindow*)_hParent, "Software", "gfx_software"); - diag.ShowModal(); -#endif + return "Software Renderer"; +} + +void VideoSoftware::ShowConfig(void *hParent) +{ + Host_ShowVideoConfig(hParent, GetDisplayName(), "gfx_software"); } bool VideoSoftware::Initialize(void *&window_handle) diff --git a/Source/Core/VideoBackends/Software/Software.vcxproj b/Source/Core/VideoBackends/Software/Software.vcxproj index 2f1febddfe..39732cd845 100644 --- a/Source/Core/VideoBackends/Software/Software.vcxproj +++ b/Source/Core/VideoBackends/Software/Software.vcxproj @@ -59,7 +59,6 @@ - @@ -87,7 +86,6 @@ - diff --git a/Source/Core/VideoBackends/Software/VideoBackend.h b/Source/Core/VideoBackends/Software/VideoBackend.h index 4694945a5c..dbfe1c7cab 100644 --- a/Source/Core/VideoBackends/Software/VideoBackend.h +++ b/Source/Core/VideoBackends/Software/VideoBackend.h @@ -14,6 +14,7 @@ class VideoSoftware : public VideoBackend void Shutdown() override; std::string GetName() const override; + std::string GetDisplayName() const override; void EmuStateChange(EMUSTATE_CHANGE newState) override; diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index 9417b7e78f..136cc33795 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -12,16 +12,13 @@ #include "VideoCommon/BPMemory.h" #include "VideoCommon/DataReader.h" -#include "VideoCommon/IndexGenerator.h" #include "VideoCommon/LookUpTables.h" #include "VideoCommon/PixelEngine.h" -#include "VideoCommon/Statistics.h" #include "VideoCommon/VertexLoader.h" #include "VideoCommon/VertexLoader_Color.h" #include "VideoCommon/VertexLoader_Normal.h" #include "VideoCommon/VertexLoader_Position.h" #include "VideoCommon/VertexLoader_TextCoord.h" -#include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoConfig.h" @@ -866,13 +863,7 @@ void VertexLoader::RunVertices(const VAT& vat, int primitive, int const count) return; } SetupRunVertices(vat, primitive, count); - VertexManager::PrepareForAdditionalData(primitive, count, - m_native_vtx_decl.stride); ConvertVertices(count); - IndexGenerator::AddIndices(primitive, count); - - ADDSTAT(stats.thisFrame.numPrims, count); - INCSTAT(stats.thisFrame.numPrimitiveJoins); } void VertexLoader::SetVAT(const VAT& vat) diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index d5e74a0e11..d94af17360 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -9,6 +9,7 @@ #include "Core/HW/Memmap.h" +#include "VideoCommon/IndexGenerator.h" #include "VideoCommon/Statistics.h" #include "VideoCommon/VertexLoader.h" #include "VideoCommon/VertexLoaderManager.h" @@ -152,7 +153,15 @@ void RunVertices(int vtx_attr_group, int primitive, int count) VertexManager::Flush(); s_current_vtx_fmt = required_vtx_fmt; - RefreshLoader(vtx_attr_group)->RunVertices(g_VtxAttr[vtx_attr_group], primitive, count); + VertexManager::PrepareForAdditionalData(primitive, count, + loader->GetNativeVertexDeclaration().stride); + + loader->RunVertices(g_VtxAttr[vtx_attr_group], primitive, count); + + IndexGenerator::AddIndices(primitive, count); + + ADDSTAT(stats.thisFrame.numPrims, count); + INCSTAT(stats.thisFrame.numPrimitiveJoins); } int GetVertexSize(int vtx_attr_group) diff --git a/Source/UnitTests/CMakeLists.txt b/Source/UnitTests/CMakeLists.txt index f75c6199d7..104b1836ab 100644 --- a/Source/UnitTests/CMakeLists.txt +++ b/Source/UnitTests/CMakeLists.txt @@ -1,12 +1,20 @@ -macro(add_dolphin_test target srcs libs) - add_executable(Tests/${target} EXCLUDE_FROM_ALL ${srcs}) +macro(add_dolphin_test target srcs) + # Since this is a Core dependency, it can't be linked as a library and has + # to be linked as an object file. Otherwise CMake inserts the library after + # core, but before other core dependencies like videocommon which also use + # Host_ functions. + set(srcs2 ${srcs} ${CMAKE_SOURCE_DIR}/Source/UnitTests/TestUtils/StubHost.cpp) + add_executable(Tests/${target} EXCLUDE_FROM_ALL ${srcs2}) add_custom_command(TARGET Tests/${target} PRE_LINK COMMAND mkdir -p ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Tests) - target_link_libraries(Tests/${target} ${libs} gtest) + target_link_libraries(Tests/${target} core gtest) add_dependencies(unittests Tests/${target}) add_test(NAME ${target} COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Tests/${target}) endmacro(add_dolphin_test) +add_subdirectory(TestUtils) + add_subdirectory(Common) add_subdirectory(Core) +add_subdirectory(VideoCommon) diff --git a/Source/UnitTests/Common/CMakeLists.txt b/Source/UnitTests/Common/CMakeLists.txt index 42c0a8aaed..05337f4321 100644 --- a/Source/UnitTests/Common/CMakeLists.txt +++ b/Source/UnitTests/Common/CMakeLists.txt @@ -1,7 +1,7 @@ -add_dolphin_test(BitFieldTest BitFieldTest.cpp common) -add_dolphin_test(CommonFuncsTest CommonFuncsTest.cpp common) -add_dolphin_test(EventTest EventTest.cpp common) -add_dolphin_test(FifoQueueTest FifoQueueTest.cpp common) -add_dolphin_test(FixedSizeQueueTest FixedSizeQueueTest.cpp common) -add_dolphin_test(FlagTest FlagTest.cpp common) -add_dolphin_test(MathUtilTest MathUtilTest.cpp common) +add_dolphin_test(BitFieldTest BitFieldTest.cpp) +add_dolphin_test(CommonFuncsTest CommonFuncsTest.cpp) +add_dolphin_test(EventTest EventTest.cpp) +add_dolphin_test(FifoQueueTest FifoQueueTest.cpp) +add_dolphin_test(FixedSizeQueueTest FixedSizeQueueTest.cpp) +add_dolphin_test(FlagTest FlagTest.cpp) +add_dolphin_test(MathUtilTest MathUtilTest.cpp) diff --git a/Source/UnitTests/Core/CMakeLists.txt b/Source/UnitTests/Core/CMakeLists.txt index e52290e387..93f635a3ea 100644 --- a/Source/UnitTests/Core/CMakeLists.txt +++ b/Source/UnitTests/Core/CMakeLists.txt @@ -1 +1 @@ -add_dolphin_test(MMIOTest MMIOTest.cpp core) +add_dolphin_test(MMIOTest MMIOTest.cpp) diff --git a/Source/UnitTests/TestUtils/CMakeLists.txt b/Source/UnitTests/TestUtils/CMakeLists.txt new file mode 100644 index 0000000000..79424a42a6 --- /dev/null +++ b/Source/UnitTests/TestUtils/CMakeLists.txt @@ -0,0 +1,9 @@ +set(SRCS + # Do not add StubHost.cpp here - it is added manually via add_dolphin_test. + ) + +set(LIBS + ) + +# TODO: uncomment when there is actually something here. +#add_dolphin_library(testutils "${SRCS}" "${LIBS}") diff --git a/Source/UnitTests/TestUtils/StubHost.cpp b/Source/UnitTests/TestUtils/StubHost.cpp new file mode 100644 index 0000000000..7dc5871c8e --- /dev/null +++ b/Source/UnitTests/TestUtils/StubHost.cpp @@ -0,0 +1,34 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +// Stub implementation of the Host_* callbacks for tests. These implementations +// do nothing except return default values when required. + +#include + +#include "Core/Host.h" +#include "VideoBackends/OGL/GLInterfaceBase.h" + +void Host_NotifyMapLoaded() {} +void Host_RefreshDSPDebuggerWindow() {} +void Host_ShowJitResults(unsigned int) {} +void Host_Message(int) {} +void* Host_GetRenderHandle() { return nullptr; } +void* Host_GetInstance() { return nullptr; } +void Host_UpdateTitle(const std::string&) {} +void Host_UpdateLogDisplay() {} +void Host_UpdateDisasmDialog() {} +void Host_UpdateMainFrame() {} +void Host_UpdateBreakPointView() {} +void Host_GetRenderWindowSize(int&, int&, int&, int&) {} +void Host_RequestRenderWindowSize(int, int) {} +void Host_SetStartupDebuggingParameters() {} +bool Host_UIHasFocus() { return false; } +bool Host_RendererHasFocus() { return false; } +void Host_ConnectWiimote(int, bool) {} +void Host_UpdateStatusBar(const std::string&, int) {} +void Host_SysMessage(const char*, ...) {} +void Host_SetWiiMoteConnectionState(int) {} +void Host_ShowVideoConfig(void*, const std::string&, const std::string&) {} +cInterfaceBase* HostGL_CreateGLInterface() { return nullptr; } diff --git a/Source/UnitTests/VideoCommon/CMakeLists.txt b/Source/UnitTests/VideoCommon/CMakeLists.txt new file mode 100644 index 0000000000..b5198536ed --- /dev/null +++ b/Source/UnitTests/VideoCommon/CMakeLists.txt @@ -0,0 +1 @@ +add_dolphin_test(VertexLoaderTest VertexLoaderTest.cpp) diff --git a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp new file mode 100644 index 0000000000..1126cbd73a --- /dev/null +++ b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp @@ -0,0 +1,249 @@ +#include + +#include "Common/Common.h" +#include "VideoCommon/DataReader.h" +#include "VideoCommon/VertexLoader.h" + +// Needs to be included later because it defines a TEST macro that conflicts +// with a TEST method definition in x64Emitter.h. +#include // NOLINT + +TEST(VertexLoaderUID, UniqueEnough) +{ + std::set uids; + + TVtxDesc vtx_desc; + memset(&vtx_desc, 0, sizeof (vtx_desc)); + VAT vat; + memset(&vat, 0, sizeof (vat)); + uids.insert(VertexLoaderUID(vtx_desc, vat)); + + vtx_desc.Hex = 0xFEDCBA9876543210ull; + EXPECT_EQ(uids.end(), uids.find(VertexLoaderUID(vtx_desc, vat))); + uids.insert(VertexLoaderUID(vtx_desc, vat)); + + vat.g0.Hex = 0xFFFFFFFF; + vat.g1.Hex = 0xFFFFFFFF; + vat.g2.Hex = 0xFFFFFFFF; + EXPECT_EQ(uids.end(), uids.find(VertexLoaderUID(vtx_desc, vat))); + uids.insert(VertexLoaderUID(vtx_desc, vat)); +} + +static u8 input_memory[16 * 1024 * 1024]; +static u8 output_memory[16 * 1024 * 1024]; + +class VertexLoaderTest : public testing::Test +{ +protected: + + void SetUp() override + { + memset(&input_memory[0], 0, sizeof (input_memory)); + memset(&output_memory[0], 0, sizeof (input_memory)); + + memset(&m_vtx_desc, 0, sizeof (m_vtx_desc)); + memset(&m_vtx_attr, 0, sizeof (m_vtx_attr)); + + ResetPointers(); + } + + // Pushes a value to the input stream. + template + void Input(T val) + { + // Converts *to* big endian, not from. + *(T*)(&input_memory[m_input_pos]) = Common::FromBigEndian(val); + m_input_pos += sizeof (val); + } + + // Reads a value from the output stream. + template + T Output() + { + T out = *(T*)&output_memory[m_output_pos]; + m_output_pos += sizeof (out); + return out; + } + + // Combination of EXPECT_EQ and Output. + template + void ExpectOut(T val) + { + EXPECT_EQ(val, Output()); + } + + void ResetPointers() + { + g_pVideoData = &input_memory[0]; + VertexManager::s_pCurBufferPointer = &output_memory[0]; + m_input_pos = m_output_pos = 0; + } + + u32 m_input_pos, m_output_pos; + + TVtxDesc m_vtx_desc; + VAT m_vtx_attr; +}; + +TEST_F(VertexLoaderTest, PositionDirectFloatXYZ) +{ + m_vtx_desc.Position = 1; // Direct + m_vtx_attr.g0.PosElements = 1; // XYZ + m_vtx_attr.g0.PosFormat = 4; // Float + + VertexLoader loader(m_vtx_desc, m_vtx_attr); + + ASSERT_EQ(3 * sizeof (float), (u32)loader.GetNativeVertexDeclaration().stride); + ASSERT_EQ(3 * sizeof (float), (u32)loader.GetVertexSize()); + + // Write some vertices. + Input(0.0f); Input(0.0f); Input(0.0f); + Input(1.0f); Input(0.0f); Input(0.0f); + Input(0.0f); Input(1.0f); Input(0.0f); + Input(0.0f); Input(0.0f); Input(1.0f); + + // Convert 4 points. "7" -> primitive are points. + loader.RunVertices(m_vtx_attr, 7, 4); + + ExpectOut(0.0f); ExpectOut(0.0f); ExpectOut(0.0f); + ExpectOut(1.0f); ExpectOut(0.0f); ExpectOut(0.0f); + ExpectOut(0.0f); ExpectOut(1.0f); ExpectOut(0.0f); + ExpectOut(0.0f); ExpectOut(0.0f); ExpectOut(1.0f); + + // Test that scale does nothing for floating point inputs. + Input(1.0f); Input(2.0f); Input(4.0f); + m_vtx_attr.g0.PosFrac = 1; + loader.RunVertices(m_vtx_attr, 7, 1); + ExpectOut(1.0f); ExpectOut(2.0f); ExpectOut(4.0f); +} + +TEST_F(VertexLoaderTest, PositionDirectU16XY) +{ + m_vtx_desc.Position = 1; // Direct + m_vtx_attr.g0.PosElements = 0; // XY + m_vtx_attr.g0.PosFormat = 2; // U16 + + VertexLoader loader(m_vtx_desc, m_vtx_attr); + + ASSERT_EQ(3 * sizeof (float), (u32)loader.GetNativeVertexDeclaration().stride); + ASSERT_EQ(2 * sizeof (u16), (u32)loader.GetVertexSize()); + + // Write some vertices. + Input(0); Input(0); + Input(1); Input(2); + Input(256); Input(257); + Input(65535); Input(65534); + Input(12345); Input(54321); + + // Convert 5 points. "7" -> primitive are points. + loader.RunVertices(m_vtx_attr, 7, 5); + + ExpectOut(0.0f); ExpectOut(0.0f); ExpectOut(0.0f); + ExpectOut(1.0f); ExpectOut(2.0f); ExpectOut(0.0f); + ExpectOut(256.0f); ExpectOut(257.0f); ExpectOut(0.0f); + ExpectOut(65535.0f); ExpectOut(65534.0f); ExpectOut(0.0f); + ExpectOut(12345.0f); ExpectOut(54321.0f); ExpectOut(0.0f); + + // Test that scale works on U16 inputs. + Input(42); Input(24); + m_vtx_attr.g0.PosFrac = 1; + loader.RunVertices(m_vtx_attr, 7, 1); + ExpectOut(21.0f); ExpectOut(12.0f); ExpectOut(0.0f); +} + +TEST_F(VertexLoaderTest, PositionDirectFloatXYZSpeed) +{ + m_vtx_desc.Position = 1; // Direct + m_vtx_attr.g0.PosElements = 1; // XYZ + m_vtx_attr.g0.PosFormat = 4; // Float + + VertexLoader loader(m_vtx_desc, m_vtx_attr); + + ASSERT_EQ(3 * sizeof (float), (u32)loader.GetNativeVertexDeclaration().stride); + ASSERT_EQ(3 * sizeof (float), (u32)loader.GetVertexSize()); + + for (int i = 0; i < 1000; ++i) + { + ResetPointers(); + loader.RunVertices(m_vtx_attr, 7, 100000); + } +} + +TEST_F(VertexLoaderTest, PositionDirectU16XYSpeed) +{ + m_vtx_desc.Position = 1; // Direct + m_vtx_attr.g0.PosElements = 0; // XY + m_vtx_attr.g0.PosFormat = 2; // U16 + + VertexLoader loader(m_vtx_desc, m_vtx_attr); + + ASSERT_EQ(3 * sizeof (float), (u32)loader.GetNativeVertexDeclaration().stride); + ASSERT_EQ(2 * sizeof (u16), (u32)loader.GetVertexSize()); + + for (int i = 0; i < 1000; ++i) + { + ResetPointers(); + loader.RunVertices(m_vtx_attr, 7, 100000); + } +} + +TEST_F(VertexLoaderTest, LargeFloatVertexSpeed) +{ + // Enables most attributes in floating point direct mode to test speed. + m_vtx_desc.PosMatIdx = 1; + m_vtx_desc.Tex0MatIdx = 1; + m_vtx_desc.Tex1MatIdx = 1; + m_vtx_desc.Tex2MatIdx = 1; + m_vtx_desc.Tex3MatIdx = 1; + m_vtx_desc.Tex4MatIdx = 1; + m_vtx_desc.Tex5MatIdx = 1; + m_vtx_desc.Tex6MatIdx = 1; + m_vtx_desc.Tex7MatIdx = 1; + m_vtx_desc.Position = 1; + m_vtx_desc.Normal = 1; + m_vtx_desc.Color0 = 1; + m_vtx_desc.Color1 = 1; + m_vtx_desc.Tex0Coord = 1; + m_vtx_desc.Tex1Coord = 1; + m_vtx_desc.Tex2Coord = 1; + m_vtx_desc.Tex3Coord = 1; + m_vtx_desc.Tex4Coord = 1; + m_vtx_desc.Tex5Coord = 1; + m_vtx_desc.Tex6Coord = 1; + m_vtx_desc.Tex7Coord = 1; + + m_vtx_attr.g0.PosElements = 1; // XYZ + m_vtx_attr.g0.PosFormat = 4; // Float + m_vtx_attr.g0.NormalElements = 1; // NBT + m_vtx_attr.g0.NormalFormat = 4; // Float + m_vtx_attr.g0.Color0Elements = 1; // Has Alpha + m_vtx_attr.g0.Color0Comp = 5; // RGBA8888 + m_vtx_attr.g0.Color1Elements = 1; // Has Alpha + m_vtx_attr.g0.Color1Comp = 5; // RGBA8888 + m_vtx_attr.g0.Tex0CoordElements = 1; // ST + m_vtx_attr.g0.Tex0CoordFormat = 4; // Float + m_vtx_attr.g1.Tex1CoordElements = 1; // ST + m_vtx_attr.g1.Tex1CoordFormat = 4; // Float + m_vtx_attr.g1.Tex2CoordElements = 1; // ST + m_vtx_attr.g1.Tex2CoordFormat = 4; // Float + m_vtx_attr.g1.Tex3CoordElements = 1; // ST + m_vtx_attr.g1.Tex3CoordFormat = 4; // Float + m_vtx_attr.g1.Tex4CoordElements = 1; // ST + m_vtx_attr.g1.Tex4CoordFormat = 4; // Float + m_vtx_attr.g2.Tex5CoordElements = 1; // ST + m_vtx_attr.g2.Tex5CoordFormat = 4; // Float + m_vtx_attr.g2.Tex6CoordElements = 1; // ST + m_vtx_attr.g2.Tex6CoordFormat = 4; // Float + m_vtx_attr.g2.Tex7CoordElements = 1; // ST + m_vtx_attr.g2.Tex7CoordFormat = 4; // Float + + VertexLoader loader(m_vtx_desc, m_vtx_attr); + + // This test is only done 100x in a row since it's ~20x slower using the + // current vertex loader implementation. + for (int i = 0; i < 100; ++i) + { + ResetPointers(); + loader.RunVertices(m_vtx_attr, 7, 100000); + } +}