Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude GLAD_WGL/GLAD_EGL #8

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 3
NamespaceIndentation: All
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
Expand Down
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,14 @@ oprofile_data/
CMakeSettings.json
/ci-artifacts/
/out/

bin/*
build*/
*.cflags
*.config
*.creator
*.creator.user.*
*.cxxflags
*.files
*.includes
*.autosave
2 changes: 2 additions & 0 deletions 3rdparty/glad/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_library(glad
src/glad.c
)

if(NOT LIBRETRO)
if(WIN32)
target_sources(glad PRIVATE
src/glad_wgl.c
Expand All @@ -11,6 +12,7 @@ elseif(X11_API OR WAYLAND_API)
src/glad_egl.c
)
endif()
endif()

target_include_directories(glad PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_include_directories(glad INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ include(Pcsx2Utils)
check_no_parenthesis_in_path()
detectOperatingSystem()
check_compiler_version("7.0" "7.0")
if(NOT MSVC)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_FOUND})
endif()
endif()

#-------------------------------------------------------------------------------
# Include specific module
Expand Down Expand Up @@ -60,6 +67,10 @@ if (QT_BUILD)
endif()
endif()

if(LIBRETRO)
add_subdirectory(libretro)
endif()

# tests
if(ACTUALLY_ENABLE_TESTS)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
Expand Down
16 changes: 16 additions & 0 deletions cmake/BuildParameters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,29 @@ set(PCSX2_DEFS "")
#-------------------------------------------------------------------------------
option(DISABLE_BUILD_DATE "Disable including the binary compile date")
option(ENABLE_TESTS "Enables building the unit tests" ON)
option(LIBRETRO "Enables building the libretro core" OFF)
set(USE_SYSTEM_LIBS "AUTO" CACHE STRING "Use system libraries instead of bundled libraries. ON - Always use system and fail if unavailable, OFF - Always use bundled, AUTO - Use system if available, otherwise use bundled. Default is AUTO")
if(LIBRETRO)
set(ENABLE_TESTS OFF)
set(CMAKE_BUILD_PO FALSE)
set(BUILD_REPLAY_LOADERS FALSE)
set(CUBEB_API FALSE)
set(DISABLE_SETCAP TRUE)
set(USE_VULKAN FALSE)
set(USE_DISCORD_PRESENCE FALSE)
set(USE_ACHIEVEMENTS OFF)
set(QT_BUILD OFF)
set(USE_SYSTEM_LIBS OFF)
add_definitions(-D__LIBRETRO__)
endif()
optional_system_library(fmt)
optional_system_library(ryml)
optional_system_library(zstd)
optional_system_library(libzip)
optional_system_library(SDL2)
option(LTO_PCSX2_CORE "Enable LTO/IPO/LTCG on the subset of pcsx2 that benefits most from it but not anything else")


option(USE_VTUNE "Plug VTUNE to profile GS JIT.")
option(USE_ACHIEVEMENTS "Build with RetroAchievements support" ON)
option(USE_DISCORD_PRESENCE "Enable support for Discord Rich Presence" ON)
Expand Down
4 changes: 2 additions & 2 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ if(APPLE)
target_link_options(common PRIVATE -fobjc-link-runtime)
endif()

if(USE_OPENGL)
if(USE_OPENGL AND NOT LIBRETRO)
if(WIN32)
target_sources(common PRIVATE
GL/ContextWGL.cpp
Expand Down Expand Up @@ -310,6 +310,6 @@ target_include_directories(common PUBLIC ../3rdparty/include ../)
target_compile_definitions(common PUBLIC "${PCSX2_DEFS}")
target_compile_options(common PRIVATE "${PCSX2_WARNINGS}")

if(COMMAND target_precompile_headers)
if(COMMAND target_precompile_headers AND NOT CCACHE_FOUND)
target_precompile_headers(common PRIVATE PrecompiledHeader.h)
endif()
5 changes: 5 additions & 0 deletions common/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ static void MSW_OutputDebugString(const char* text)
static bool hasDebugger = IsDebuggerPresent();
if (hasDebugger)
OutputDebugStringA(text);
else
{
printf(text);
fflush(stdout);
}
#else
fputs(text, stdout_fp);
fflush(stdout_fp);
Expand Down
8 changes: 7 additions & 1 deletion common/GL/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include <malloc.h>
#endif

#if defined(_WIN32) && !defined(_M_ARM64)
#if defined(__LIBRETRO__)
#include "common/GL/ContextRetroGL.h"
#elif defined(_WIN32) && !defined(_M_ARM64)
#include "common/GL/ContextWGL.h"
#elif defined(__APPLE__)
#include "common/GL/ContextAGL.h"
Expand Down Expand Up @@ -100,6 +102,9 @@ namespace GL
}

std::unique_ptr<Context> context;
#if defined(__LIBRETRO__)
context = ContextRetroGL::Create(wi, versions_to_try);
#else
#if defined(_WIN32) && !defined(_M_ARM64)
context = ContextWGL::Create(wi, versions_to_try);
#elif defined(__APPLE__)
Expand All @@ -114,6 +119,7 @@ namespace GL
#if defined(WAYLAND_API)
if (wi.type == WindowInfo::Type::Wayland)
context = ContextEGLWayland::Create(wi, versions_to_try);
#endif
#endif

if (!context)
Expand Down
93 changes: 93 additions & 0 deletions common/GL/ContextRetroGL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2021 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/

#include "common/PrecompiledHeader.h"

#include "common/Console.h"
#include "ContextRetroGL.h"
#include <optional>
#include <vector>
#include "common/WindowInfo.h"
#include "GS/Renderers/Common/GSDevice.h"
#include "GS/GSVector.h"

#include <libretro.h>
extern retro_video_refresh_t video_cb;
extern retro_hw_render_callback hw_render;

namespace GL
{
ContextRetroGL::ContextRetroGL(const WindowInfo& wi)
: Context(wi)
{
}

ContextRetroGL::~ContextRetroGL()
{
}

std::unique_ptr<Context> ContextRetroGL::Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try)
{
std::unique_ptr<ContextRetroGL> context = std::make_unique<ContextRetroGL>(wi);
return context;
}

void* ContextRetroGL::GetProcAddress(const char* name)
{
return reinterpret_cast<void*>(hw_render.get_proc_address(name));
}

bool ContextRetroGL::ChangeSurface(const WindowInfo& new_wi)
{
return true;
}

void ContextRetroGL::ResizeSurface(u32 new_surface_width /*= 0*/, u32 new_surface_height /*= 0*/)
{
m_wi.surface_width = new_surface_width;
m_wi.surface_height = new_surface_height;
}

bool ContextRetroGL::SwapBuffers()
{
if(g_gs_device->GetCurrent())
video_cb(RETRO_HW_FRAME_BUFFER_VALID, g_gs_device->GetCurrent()->GetWidth(), g_gs_device->GetCurrent()->GetHeight(), 0);
else
video_cb(NULL, 0, 0, 0);
return true;
}

bool ContextRetroGL::MakeCurrent()
{
return true;
}

bool ContextRetroGL::DoneCurrent()
{
return true;
}

bool ContextRetroGL::SetSwapInterval(s32 interval)
{
return true;
}

std::unique_ptr<Context> ContextRetroGL::CreateSharedContext(const WindowInfo& wi)
{
std::unique_ptr<ContextRetroGL> context = std::make_unique<ContextRetroGL>(wi);
return context;
}

} // namespace GL
40 changes: 40 additions & 0 deletions common/GL/ContextRetroGL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2021 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "common/GL/Context.h"

namespace GL
{
class ContextRetroGL : public Context
{
public:
ContextRetroGL(const WindowInfo& wi);
~ContextRetroGL() override;

static std::unique_ptr<Context> Create(const WindowInfo& wi, gsl::span<const Version> versions_to_try);

void* GetProcAddress(const char* name) override;
virtual bool ChangeSurface(const WindowInfo& new_wi) override;
virtual void ResizeSurface(u32 new_surface_width = 0, u32 new_surface_height = 0) override;
bool SwapBuffers() override;
bool MakeCurrent() override;
bool DoneCurrent() override;
bool SetSwapInterval(s32 interval) override;
virtual std::unique_ptr<Context> CreateSharedContext(const WindowInfo& wi) override;
};

} // namespace GL
1 change: 1 addition & 0 deletions common/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/

#include <algorithm>
#include "General.h"
#include "Console.h"

Expand Down
1 change: 1 addition & 0 deletions common/Perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#pragma once

#include <cstdio>
#include <vector>
#include <cstdio>
#include "common/Pcsx2Types.h"
Expand Down
1 change: 1 addition & 0 deletions common/Vulkan/Builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/

#include <limits>
#include "common/Vulkan/Builders.h"
#include "common/Vulkan/Util.h"
#include "common/Assertions.h"
Expand Down
3 changes: 2 additions & 1 deletion common/WindowInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ struct WindowInfo
Win32,
X11,
Wayland,
MacOS
MacOS,
Libretro
};

/// The type of the surface. Surfaceless indicates it will not be displayed on screen at all.
Expand Down
69 changes: 69 additions & 0 deletions libretro/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

add_library(pcsx2_libretro SHARED)

#target_link_libraries(PCSX2 PRIVATE
# ${wxWidgets_LIBRARIES}
# ${AIO_LIBRARIES}
# ${GLIB_LIBRARIES}
# ${GLIB_GIO_LIBRARIES}
#)

#add_link_options(-fuse-ld=gold)
#add_link_options(-Wl,--gc-sections,--print-symbol-counts,sym.log)

target_sources(pcsx2_libretro PRIVATE
${CMAKE_SOURCE_DIR}/libretro/main.cpp
${CMAKE_SOURCE_DIR}/libretro/options.cpp
${CMAKE_SOURCE_DIR}/libretro/input.cpp
${CMAKE_SOURCE_DIR}/libretro/Console.cpp
${CMAKE_SOURCE_DIR}/libretro/SPU2.cpp
${CMAKE_SOURCE_DIR}/libretro/DEV9.cpp
${CMAKE_SOURCE_DIR}/libretro/USB.cpp
${CMAKE_SOURCE_DIR}/libretro/InputRecording.cpp

${CMAKE_SOURCE_DIR}/common/GL/ContextRetroGL.cpp
# ${CMAKE_SOURCE_DIR}/pcsx2/USB/USBNull.cpp
# ${pcsx2LTOSources}
# ${pcsx2GuiSources}
)

target_link_libraries(pcsx2_libretro PRIVATE
PCSX2_FLAGS
PCSX2
)

target_include_directories(PCSX2_FLAGS INTERFACE
"${CMAKE_SOURCE_DIR}/libretro"
)

target_include_directories(pcsx2_libretro PRIVATE
"${CMAKE_SOURCE_DIR}"
"${CMAKE_SOURCE_DIR}/libretro"
"${CMAKE_SOURCE_DIR}/common/include"
"${CMAKE_SOURCE_DIR}/3rdparty/include"
"${CMAKE_SOURCE_DIR}/pcsx2"
)

#include_directories(. ${CMAKE_SOURCE_DIR}/libretro ${CMAKE_SOURCE_DIR}/common)
set_target_properties(pcsx2_libretro PROPERTIES
LIBRARY_OUTPUT_NAME pcsx2_libretro
PREFIX ""
)

# set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}")

if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CLANG 1)
endif()

if(NOT MSVC AND NOT CLANG)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
endif()

if(PACKAGE_MODE)
install(TARGETS pcsx2_libretro DESTINATION ${BIN_DIR})
else(PACKAGE_MODE)
install(TARGETS pcsx2_libretro DESTINATION ${CMAKE_SOURCE_DIR}/bin)
endif(PACKAGE_MODE)

#setup_main_executable(pcsx2-libretro)
Loading