From 2a852170a8314c84c10600aa5c3d4098d92dd7ae Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 16 Sep 2020 22:14:35 +0200 Subject: [PATCH] (Windows) Fixed some build issues and got the OpenGL shaders to work. Also some additional code cleanup. --- CMakeLists.txt | 11 +-- INSTALL.md | 83 +++++++++++++++-------- es-app/CMakeLists.txt | 7 +- es-app/src/VolumeControl.cpp | 33 ++++----- es-app/src/VolumeControl.h | 6 +- es-app/src/main.cpp | 1 + es-core/src/Platform.cpp | 32 ++++----- es-core/src/Platform.h | 6 +- es-core/src/components/ImageComponent.cpp | 15 ++-- es-core/src/components/ImageComponent.h | 3 +- es-core/src/components/VideoComponent.cpp | 7 +- es-core/src/renderers/Renderer.cpp | 52 +++++++------- es-core/src/renderers/Renderer.h | 3 +- es-core/src/renderers/Renderer_GL21.cpp | 26 ++++--- es-core/src/renderers/Shader_GL21.cpp | 10 ++- es-core/src/renderers/Shader_GL21.h | 6 ++ 16 files changed, 177 insertions(+), 124 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49d5dc2b5..c9dfab320 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -241,16 +241,17 @@ if(NOT WIN32) nanosvg) elseif(WIN32) set(COMMON_LIBRARIES - "${PROJECT_SOURCE_DIR}/libpugixml.dll" "${PROJECT_SOURCE_DIR}/FreeImage.dll" + "${PROJECT_SOURCE_DIR}/glew32.dll" "${PROJECT_SOURCE_DIR}/libcurl-x64.dll" - "${PROJECT_SOURCE_DIR}/libvlc.dll" "${PROJECT_SOURCE_DIR}/libfreetype.dll" - "Winmm.dll" - "mingw32" + "${PROJECT_SOURCE_DIR}/libpugixml.dll" "${PROJECT_SOURCE_DIR}/libSDL2main.a" + "${PROJECT_SOURCE_DIR}/libvlc.dll" "${PROJECT_SOURCE_DIR}/SDL2.dll" - "nanosvg") + "mingw32" + "nanosvg" + "Winmm.dll") endif() if(APPLE) diff --git a/INSTALL.md b/INSTALL.md index 4d635a460..10c85dda2 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -10,9 +10,9 @@ Table of contents: EmulationStation-DE is developed and compiled using both Clang/LLVM and GCC on Unix, Clang/LLVM on macOS and GCC (MinGW) on Windows. I'm intending to get Clang/LLVM working on Windows as well. -There are much more details regarding compilers later in this document, so read on! +There are more details regarding compilers later in this document. -Any code editor can be used of course, but I recommend [VSCodium](https://vscodium.com) or [VSCode](https://code.visualstudio.com). +Any code editor can be used of course, but I recommend [VSCode](https://code.visualstudio.com). ## Building on Unix @@ -20,13 +20,13 @@ Any code editor can be used of course, but I recommend [VSCodium](https://vscodi The code has a few dependencies. For building, you'll need CMake and development packages for cURL, FreeImage, FreeType, libVLC, pugixml, SDL2 and RapidJSON. **On Debian/Ubuntu:** -All of the required packages can be easily installed with `apt-get`: +All of the required packages can be easily installed with apt-get: ``` sudo apt-get install build-essential cmake libsdl2-dev libfreeimage-dev libfreetype6-dev libcurl4-openssl-dev libpugixml-dev rapidjson-dev libasound2-dev libvlc-dev libgl1-mesa-dev ``` **On Fedora:** -For this operating system, use `dnf` (with rpmfusion activated) : +For this operating system, use dnf (with rpmfusion activated) : ``` sudo dnf install cmake SDL2-devel freeimage-devel freetype-devel curl-devel rapidjson-devel alsa-lib-devel vlc-devel mesa-libGL-devel ``` @@ -109,7 +109,7 @@ Advantage with GCC (vs Clang): *Release build: Optimizations enabled, debug info disabled, binary stripped.* \ *Debug build: Optimizations disabled, debug info enabled, binary not stripped.* -This Clang debug build is LLVM "native", i.e. intended to be debugged using the LLVM project debugger LLDB. The problem is that this is still not well integrated with VSCodium that I use for development so I need to keep using GDB. But this is problematic as the libstd++ data required by GDB is missing in the binary, making it impossible to see the values of for instance `std::string` variables. +This Clang debug build is LLVM "native", i.e. intended to be debugged using the LLVM project debugger LLDB. The problem is that this is still not well integrated with VSCode that I use for development so I need to keep using GDB. But this is problematic as the libstd++ data required by GDB is missing in the binary, making it impossible to see the values of for instance `std::string` variables. It's possible to activate the additional debug info needed by GDB by using the flag `-D_GLIBCXX_DEBUG`. I've added this to CMakeLists.txt when using Clang, but this bloats the binary and makes the code much slower. Actually, instead of a 4% faster application startup, it's now 36% slower! The same goes for the binary size, instead of 17% smaller it's now 17% larger. @@ -211,7 +211,9 @@ sudo apt-get install rpm ## Building on macOS -EmulationStation for macOS is built using Clang/LLVM which is the default compiler for this operating system. It's pretty straightforward to build software on this OS. Although it's a bizarre Unix variant, it is still a proper system with good tools. The main deficiency (apart from a very strange window manager) is that there is no package manager and you need to register an account to install software from the App Store. There are several third party package managers though, and the use of one of them, `Homebrew`, is detailed below. +EmulationStation for macOS is built using Clang/LLVM which is the default compiler for this operating system. It's pretty straightforward to build software on this OS. Although it's a bizarre Unix variant with a very strange window manager, it is still a proper system with good tools. The main deficiency is that there is no native package manager, but as there are several third party package managers available, this can be partly compensated for. The use of one of them, `Homebrew`, is detailed below. + +As for code editing, I use [VSCode](https://code.visualstudio.com). I suppose Xcode could be used instead but I have no experience with this tool and no interest in it as I want to use the same tools for all the operating systems that I develop on. **Setting up the build tools:** @@ -428,25 +430,27 @@ This is a strange legacy operating system. However it's still popular, so we nee I did a brief evaluation of the Microsoft Visual C++ compiler (MSVC) but as far as I'm concerned it's an abomination so I won't cover it here and it won't be supported. +The OpenGL library shipped with Windows is unfortunately garbage, so the OpenGL Extension Wrangler (GLEW) library needs to be used as well to provide shader support. Its installation is explained below. + At the moment I have only built the software using GCC on Windows, but I aim to get Clang/LLVM working at a later date. Anyway, here's a (not so) brief summary of how to get a build environment up and running on Windows. **Install Git, CMake, MinGW and your code editor:** -[Git](https://gitforwindows.org) +[https://gitforwindows.org](https://gitforwindows.org) -[CMake](https://cmake.org/download) +[https://cmake.org/download](https://cmake.org/download) -[MinGW](https://gnutoolchains.com/mingw64) +[https://gnutoolchains.com/mingw64](https://gnutoolchains.com/mingw64) Make a copy of `mingw64/bin/mingw32-make` to `make` just for convenience and make sure that the necessary paths are defined for the PATH environmental variable. I won't get into the details on how to configure Git, but there are many resources available online to support with this. The `Git Bash` shell is very useful though as it's somewhat reproducing a Unix environment using MinGW/MSYS. -Install your editor of choice. As for VSCodium it's unfortunately broken or crippled under Windows, making some important extensions impossible to install. VSCode can however be used instead. +Install your editor of choice, I use [VSCode](https://code.visualstudio.com). -It's strongly recommended to set line breaks to Unix-style (linefeed only) directly in the editor, although it can also be configured in Git for conversion during commit. The source code for EmulationStation-DE only uses Unix-style line breaks. +It's strongly recommended to set line breaks to Unix-style (line feed only) directly in the editor, although it can also be configured in Git for conversion during commit. The source code for EmulationStation-DE only uses Unix-style line breaks. **Enable pretty printing for GDB:** @@ -455,7 +459,7 @@ This is useful for displaying `std::string` values for example. Adjust your paths accordingly, the below are just examples of course. Save a file to -C:/Programming/mingw64/bin/pp.gdb with the following contents: +C:\Programming\mingw64\bin\pp.gdb with the following contents: ``` python @@ -472,21 +476,39 @@ If using VSCode, add the following line to launch.json: An equivalent setup should be possible on other code editors as well. -Note that most GDB builds for Windows have broken Python support so that pretty printing won't work. The MinGW installation recommended in the previous step works fine though. +Note that most GDB builds for Windows have broken Python support so that pretty printing won't work. The MinGW installation recommended in the previous step should work fine though. **Download the dependency packages:** -[FreeImage](https://sourceforge.net/projects/freeimage) +FreeImage\ +[https://sourceforge.net/projects/freeimage](https://sourceforge.net/projects/freeimage) -[cURL](https://curl.haxx.se/download.html) +cURL\ +[https://curl.haxx.se/download.html](https://curl.haxx.se/download.html) -[SDL2](https://www.libsdl.org/download-2.0.php) +SDL2\ +[https://www.libsdl.org/download-2.0.php](https://www.libsdl.org/download-2.0.php) -[libVLC](https://ftp.lysator.liu.se/pub/videolan/vlc) +libVLC\ +[https://ftp.lysator.liu.se/pub/videolan/vlc](https://ftp.lysator.liu.se/pub/videolan/vlc) -Uncompress the files to a suitable directory, for example C:/Programming/Dependencies/ +Uncompress the files for the above packages to a suitable directory, for example C:\Programming\Dependencies\ -The following packages are not readily available for Windows, so clone the repos and build them yourself: +GLEW\ +[http://glew.sourceforge.net](http://glew.sourceforge.net) + +This library needs to be compiled from source as the pre-built libraries don't seem to work with GCC. The GitHub repo seems to be somewhat broken as well, therefore the manual download is required. It's recommended to get the source in zip format and uncompress it to the same directory as the other libraries listed above. + +Now simply build the required glew32.dll library: + +``` +unzip glew-2.1.0.zip +cd glew-2.1.0 +make +``` +You will probably see a huge amount of compile warnings, and the glewinfo.exe tool may fail to build, but we don't need it so it's not an issue. + +The following packages are not readily available for Windows either, so clone the repos and build them yourself: [FreeType](https://www.freetype.org) ``` @@ -518,7 +540,7 @@ git checkout v1.1.0 **Clone the EmulationStation-DE repository:** -This works the same as in Unix, just run the following: +This works the same as in Unix or macOS, just run the following: ``` git clone https://gitlab.com/leonstyhre/emulationstation-de @@ -526,11 +548,11 @@ git clone https://gitlab.com/leonstyhre/emulationstation-de **Setup the include directories:** -As there is no standardized include directory structure in Windows and no package manager, you need to provide the include files manually. +As there is no standardized include directory structure in Windows, you need to provide the include files manually. -Make a directory in your build environment tree, for instance under `C:/Programming/include`. +Make a directory in your build environment tree, for instance under C:\Programming\include\ -Copy the include files from cURL, FreeImage, FreeType, pugixml, RapidJSON, SDL2 and VLC to this directory. +Copy the include files from cURL, FreeImage, FreeType, GLEW, pugixml, RapidJSON, SDL2 and VLC to this directory. It should then look something like this: ``` @@ -539,6 +561,7 @@ curl/ FreeImage.h freetype/ ft2build.h +GL/ pugiconfig.hpp pugixml.hpp rapidjson/ @@ -554,18 +577,19 @@ Copy the following files to the `emulationstation-de` build directory. Most of t ``` FreeImage.dll +glew32.dll libcrypto-1_1-x64.dll (from the OpenSSL package, located in Git MinGW/MSYS under /mingw/bin/) libcurl-x64.dll libfreetype.dll libgcc_s_seh-1.dll (located in Git MinGW/MSYS under /mingw/bin/) libpugixml.dll +libSDL2main.a libssl-1_1-x64.dll (from the OpenSSL package, located in Git MinGW under /mingw/bin/) libstdc++-6.dll libvlc.dll libvlccore.dll libwinpthread-1.dll (located in Git MinGW under /mingw/bin/) SDL2.dll -libSDL2main.a ``` The files from the MinGW installation must correspond to the version used to compile the binary. @@ -608,21 +632,22 @@ Or for a debug build: cmake -G "MinGW Makefiles" -DWIN32_INCLUDE_DIR=../include -DCMAKE_BUILD_TYPE=Debug . ``` -For some reason defining the '../include' path doesn't work when running CMake from PowerShell (and no, changing to backslash doesn't help). Instead use Bash, by running from a `Git Bash` shell. +For some reason defining the '../include' path doesn't work when running CMake from PowerShell (and no, changing to backslash doesn't help). Instead use Bash, by running from a Git Bash shell. -The make command works fine directly in PowerShell though so it can be run from the VSCode terminal. Unfortunately I haven't been able to find a way to use a civilized shell from inside VSCode so we're stuck with PowerShell. +The make command works fine directly in PowerShell though so it can be run from the VSCode terminal. Running `make -j6` (or whatever number of parallel jobs you prefer) should now build the binary. -Note that compilation time is much longer than on Unix, and linking time is excessive for a debug build (around 10 times longer on my computer). The debug binary is also much larger than on Unix. +Note that compilation time is much longer than on Unix or macOS, and linking time is excessive for a debug build (around 10 times longer on my computer). The debug binary is also much larger than on Unix. **Creating an NSIS installer:** To create an NSIS installer (Nullsoft Scriptable Install System) you need to first install the NSIS creation tool: -[NSIS](https://nsis.sourceforge.io/Download) +NSIS\ +[https://nsis.sourceforge.io/Download](https://nsis.sourceforge.io/Download) -Simply install the application using it's installer. +Simply install the application using its installer. After the installation has been completed, go to the emulationstation-de directory and run cpack to generate the NSIS installer: diff --git a/es-app/CMakeLists.txt b/es-app/CMakeLists.txt index 39a5beca3..2bf974962 100644 --- a/es-app/CMakeLists.txt +++ b/es-app/CMakeLists.txt @@ -119,9 +119,10 @@ endif() # Setup for installation and package generation. if(WIN32) install(TARGETS EmulationStation RUNTIME DESTINATION .) - install(FILES ../FreeImage.dll ../libcrypto-1_1-x64.dll ../libcurl-x64.dll ../libfreetype.dll - ../libgcc_s_seh-1.dll ../libpugixml.dll ../libssl-1_1-x64.dll ../libstdc++-6.dll - ../libvlc.dll ../libvlccore.dll ../libwinpthread-1.dll ../SDL2.dll DESTINATION .) + install(FILES ../FreeImage.dll ../glew32.dll ../libcrypto-1_1-x64.dll ../libcurl-x64.dll + ../libfreetype.dll ../libgcc_s_seh-1.dll ../libpugixml.dll ../libssl-1_1-x64.dll + ../libstdc++-6.dll ../libvlc.dll ../libvlccore.dll ../libwinpthread-1.dll + ../SDL2.dll DESTINATION .) install(DIRECTORY ${CMAKE_SOURCE_DIR}/plugins DESTINATION .) install(FILES ../LICENSE DESTINATION .) install(DIRECTORY ${CMAKE_SOURCE_DIR}/licenses DESTINATION .) diff --git a/es-app/src/VolumeControl.cpp b/es-app/src/VolumeControl.cpp index 2320fd5de..cdd595fd3 100644 --- a/es-app/src/VolumeControl.cpp +++ b/es-app/src/VolumeControl.cpp @@ -1,4 +1,6 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // VolumeControl.cpp // // Controls system audio volume. @@ -13,10 +15,6 @@ #include "Settings.h" #endif -#if defined(_WIN64) -#include -#endif - // The ALSA Audio Card and Audio Device selection code is disabled at the moment. // As PulseAudio controls the sound devices for the desktop environment, it doesn't // make much sense to be able to select ALSA devices directly. Normally (always?) @@ -173,14 +171,15 @@ void VolumeControl::init() } #elif defined(_WIN64) // Get windows version information. - OSVERSIONINFOEXA osVer = {sizeof(OSVERSIONINFO)}; + OSVERSIONINFOEXA osVer = { sizeof(OSVERSIONINFO) }; ::GetVersionExA(reinterpret_cast(&osVer)); // Check windows version. if (osVer.dwMajorVersion < 6) { // Windows older than Vista. use mixer API. open default mixer. if (mixerHandle == nullptr) { #if defined(_WIN64) - if (mixerOpen(&mixerHandle, 0, (DWORD_PTR)nullptr, 0, 0) == MMSYSERR_NOERROR) { + if (mixerOpen(&mixerHandle, 0, reinterpret_cast(nullptr), 0, 0) == + MMSYSERR_NOERROR) { #else if (mixerOpen(&mixerHandle, 0, nullptr, 0, 0) == MMSYSERR_NOERROR) { #endif @@ -191,12 +190,13 @@ void VolumeControl::init() mixerLineControls.cControls = 1; // Id of "Speaker Out" line's volume slider. //mixerLineControls.dwControlID = 0x00000000; - //Get volume control. + // Get volume control. mixerLineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME; mixerLineControls.pamxctrl = &mixerControl; mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL); - if (mixerGetLineControls((HMIXEROBJ)mixerHandle, &mixerLineControls, - MIXER_GETLINECONTROLSF_ONEBYTYPE) != MMSYSERR_NOERROR) { + if (mixerGetLineControls(reinterpret_cast(mixerHandle), + &mixerLineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE) != + MMSYSERR_NOERROR) { LOG(LogError) << "VolumeControl::getVolume() - Failed to get mixer volume control!"; mixerClose(mixerHandle); @@ -214,7 +214,7 @@ void VolumeControl::init() CoInitialize(nullptr); IMMDeviceEnumerator * deviceEnumerator = nullptr; CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_INPROC_SERVER, - __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator); + __uuidof(IMMDeviceEnumerator), reinterpret_cast(&deviceEnumerator)); if (deviceEnumerator != nullptr) { // Get default endpoint. IMMDevice * defaultDevice = nullptr; @@ -222,7 +222,8 @@ void VolumeControl::init() if (defaultDevice != nullptr) { // Retrieve endpoint volume. defaultDevice->Activate(__uuidof(IAudioEndpointVolume), - CLSCTX_INPROC_SERVER, nullptr, (LPVOID *)&endpointVolume); + CLSCTX_INPROC_SERVER, nullptr, + reinterpret_cast(&endpointVolume)); if (endpointVolume == nullptr) LOG(LogError) << "VolumeControl::init() - " "Failed to get default audio endpoint volume!"; @@ -315,9 +316,9 @@ int VolumeControl::getVolume() const mixerControlDetails.cMultipleItems = 0; mixerControlDetails.paDetails = &value; mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED); - if (mixerGetControlDetails((HMIXEROBJ)mixerHandle, &mixerControlDetails, + if (mixerGetControlDetails(reinterpret_cast(mixerHandle), &mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE) == MMSYSERR_NOERROR) - volume = (int)Math::round((value.dwValue * 100) / 65535.0f); + volume = static_cast(Math::round((value.dwValue * 100) / 65535.0f)); else LOG(LogError) << "VolumeControl::getVolume() - Failed to get mixer volume!"; } @@ -325,7 +326,7 @@ int VolumeControl::getVolume() const // Windows Vista or above. use EndpointVolume API. float floatVolume = 0.0f; // 0-1 if (endpointVolume->GetMasterVolumeLevelScalar(&floatVolume) == S_OK) { - volume = (int)Math::round(floatVolume * 100.0f); + volume = static_cast(Math::round(floatVolume * 100.0f)); LOG(LogInfo) << "System audio volume is " << volume; } else { @@ -387,7 +388,7 @@ void VolumeControl::setVolume(int volume) mixerControlDetails.cMultipleItems = 0; mixerControlDetails.paDetails = &value; mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED); - if (mixerSetControlDetails((HMIXEROBJ)mixerHandle, &mixerControlDetails, + if (mixerSetControlDetails(reinterpret_cast(mixerHandle), &mixerControlDetails, MIXER_SETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR) LOG(LogError) << "VolumeControl::setVolume() - Failed to set mixer volume!"; } @@ -395,7 +396,7 @@ void VolumeControl::setVolume(int volume) // Windows Vista or above. use EndpointVolume API. float floatVolume = 0.0f; // 0-1 if (volume > 0) - floatVolume = (float)volume / 100.0f; + floatVolume = static_cast(volume) / 100.0f; if (endpointVolume->SetMasterVolumeLevelScalar(floatVolume, nullptr) != S_OK) LOG(LogError) << "VolumeControl::setVolume() - Failed to set master volume!"; } diff --git a/es-app/src/VolumeControl.h b/es-app/src/VolumeControl.h index e22de4753..449a1d0d1 100644 --- a/es-app/src/VolumeControl.h +++ b/es-app/src/VolumeControl.h @@ -1,10 +1,11 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // VolumeControl.h // // Controls system audio volume. // -#pragma once #ifndef ES_APP_VOLUME_CONTROL_H #define ES_APP_VOLUME_CONTROL_H @@ -19,7 +20,8 @@ #elif defined(_WIN64) #include #include -//#include +#include +#include #endif // Singleton pattern. Call getInstance() to get an object. diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 716b63f39..5626406de 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -9,6 +9,7 @@ // Desktop Edition fork by Leon Styhre. // // The line length limit is 100 characters and the indentations are 4 spaces. +// Line breaks are Unix-style (line feed only). // // main.cpp // diff --git a/es-core/src/Platform.cpp b/es-core/src/Platform.cpp index dccec8fbf..7deb1ad02 100644 --- a/es-core/src/Platform.cpp +++ b/es-core/src/Platform.cpp @@ -1,4 +1,6 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // Platform.cpp // // Platform-specific functions. @@ -19,13 +21,7 @@ #include #endif -#if defined(_WIN64) -#include -#include -#include -#else #include -#endif #include int runRebootCommand() @@ -133,16 +129,16 @@ int launchEmulatorWindows(const std::wstring& cmd_utf16) DWORD errorCode = 0; processReturnValue = CreateProcessW( - nullptr, // No application name (use command line). - (wchar_t*) cmd_utf16.c_str(), // Command line. - nullptr, // Process attributes. - nullptr, // Thread attributes. - FALSE, // Handles inheritance. - 0, // Creation flags. - nullptr, // Use parent's environment block. - nullptr, // Use parent's starting directory. - &si, // Pointer to the STARTUPINFOW structure. - &pi); // Pointer to the PROCESS_INFORMATION structure. + nullptr, // No application name (use command line). + const_cast(cmd_utf16.c_str()), // Command line. + nullptr, // Process attributes. + nullptr, // Thread attributes. + FALSE, // Handles inheritance. + 0, // Creation flags. + nullptr, // Use parent's environment block. + nullptr, // Use parent's starting directory. + &si, // Pointer to the STARTUPINFOW structure. + &pi); // Pointer to the PROCESS_INFORMATION structure. // Unfortunately suspending ES and resuming when the emulator process has exited // doesn't work reliably on Windows, so we may need to keep ES running in the @@ -161,7 +157,7 @@ int launchEmulatorWindows(const std::wstring& cmd_utf16) FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPWSTR)&pBuffer, 0, nullptr); + reinterpret_cast(&pBuffer), 0, nullptr); errorCode = GetLastError(); @@ -196,7 +192,7 @@ unsigned int getTaskbarState() #if defined(_WIN64) APPBARDATA barData; barData.cbSize = sizeof(APPBARDATA); - return (UINT) SHAppBarMessage(ABM_GETSTATE, &barData); + return static_cast(SHAppBarMessage(ABM_GETSTATE, &barData)); #else return 0; #endif diff --git a/es-core/src/Platform.h b/es-core/src/Platform.h index 6734c2c47..9cb862f3c 100644 --- a/es-core/src/Platform.h +++ b/es-core/src/Platform.h @@ -1,18 +1,18 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // Platform.h // // Platform-specific functions. // -#pragma once #ifndef ES_CORE_PLATFORM_H #define ES_CORE_PLATFORM_H #include -// Why the hell this naming inconsistency exists is well beyond me. #if defined(_WIN64) - #define sleep Sleep +#include #endif enum QuitMode { diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index 7d5fa6583..13eb6af85 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -1,4 +1,6 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // ImageComponent.cpp // // Handles images: loading, resizing, cropping, color shifting etc. @@ -337,9 +339,9 @@ void ImageComponent::updateColors() { const float opacity = (mOpacity * (mFading ? mFadeOpacity / 255.0 : 1.0)) / 255.0; const unsigned int color = Renderer::convertColor((mColorShift & 0xFFFFFF00) | - (unsigned char)((mColorShift & 0xFF) * opacity)); + static_cast((mColorShift & 0xFF) * opacity)); const unsigned int colorEnd = Renderer::convertColor((mColorShiftEnd & 0xFFFFFF00) | - (unsigned char)((mColorShiftEnd & 0xFF) * opacity)); + static_cast((mColorShiftEnd & 0xFF) * opacity)); mVertices[0].col = color; mVertices[1].col = mColorGradientHorizontal ? colorEnd : color; @@ -408,7 +410,7 @@ void ImageComponent::fadeIn(bool textureLoaded) mFading = false; } else { - mFadeOpacity = (unsigned char)opacity; + mFadeOpacity = static_cast(opacity); } updateColors(); } @@ -425,15 +427,16 @@ void ImageComponent::applyTheme(const std::shared_ptr& theme, const s { using namespace ThemeFlags; - GuiComponent::applyTheme(theme, view, element, (properties ^ SIZE) | - ((properties & (SIZE | POSITION)) ? ORIGIN : 0)); + GuiComponent::applyTheme(theme, view, element, (properties ^ ThemeFlags::SIZE) | + ((properties & (ThemeFlags::SIZE | POSITION)) ? ORIGIN : 0)); const ThemeData::ThemeElement* elem = theme->getElement(view, element, "image"); if (!elem) return; Vector2f scale = getParent() ? getParent()->getSize() : - Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); + Vector2f(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); if (properties & ThemeFlags::SIZE) { if (elem->has("size")) diff --git a/es-core/src/components/ImageComponent.h b/es-core/src/components/ImageComponent.h index 1d3b7d65c..3c52f495e 100644 --- a/es-core/src/components/ImageComponent.h +++ b/es-core/src/components/ImageComponent.h @@ -1,10 +1,11 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // ImageComponent.h // // Handles images: loading, resizing, cropping, color shifting etc. // -#pragma once #ifndef ES_CORE_COMPONENTS_IMAGE_COMPONENT_H #define ES_CORE_COMPONENTS_IMAGE_COMPONENT_H diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index 97fc743b8..c39c79b97 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -33,7 +33,8 @@ std::string getTitleFolder() { void writeSubtitle(const char* gameName, const char* systemName, bool always) { FILE* file = fopen(getTitlePath().c_str(), "w"); - int end = (int)(Settings::getInstance()->getInt("ScreenSaverSwapVideoTimeout") / (1000)); + int end = static_cast((Settings::getInstance()-> + getInt("ScreenSaverSwapVideoTimeout") / (1000))); if (always) fprintf(file, "1\n00:00:01,000 --> 00:00:%d,000\n", end); @@ -198,8 +199,8 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, const s { using namespace ThemeFlags; - GuiComponent::applyTheme(theme, view, element, (properties ^ SIZE) | - ((properties & (SIZE | POSITION)) ? ORIGIN : 0)); + GuiComponent::applyTheme(theme, view, element, (properties ^ ThemeFlags::SIZE) | + ((properties & (ThemeFlags::SIZE | POSITION)) ? ORIGIN : 0)); const ThemeData::ThemeElement* elem = theme->getElement(view, element, "video"); diff --git a/es-core/src/renderers/Renderer.cpp b/es-core/src/renderers/Renderer.cpp index 2df832bd5..d4e56b836 100644 --- a/es-core/src/renderers/Renderer.cpp +++ b/es-core/src/renderers/Renderer.cpp @@ -1,4 +1,6 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // Renderer.cpp // // General rendering functions. @@ -8,11 +10,11 @@ #include "math/Transform4x4f.h" #include "math/Vector2i.h" -#include "Shader_GL21.h" #include "resources/ResourceManager.h" #include "ImageIO.h" #include "Log.h" #include "Settings.h" +#include "Shader_GL21.h" #include #include @@ -55,8 +57,10 @@ namespace Renderer #endif // Try creating SDL surface from logo data. - SDL_Surface* logoSurface = SDL_CreateRGBSurfaceFrom((void*)rawData.data(), - (int)width, (int)height, 32, (int)(width * 4), rmask, gmask, bmask, amask); + SDL_Surface* logoSurface = SDL_CreateRGBSurfaceFrom( + static_cast(rawData.data()), + static_cast(width), static_cast(height), 32, + static_cast((width * 4)), rmask, gmask, bmask, amask); if (logoSurface != nullptr) { SDL_SetWindowIcon(sdlWindow, logoSurface); @@ -76,22 +80,22 @@ namespace Renderer initialCursorState = (SDL_ShowCursor(0) != 0); - SDL_DisplayMode dispMode; - SDL_GetDesktopDisplayMode(0, &dispMode); + SDL_DisplayMode displayMode; + SDL_GetDesktopDisplayMode(0, &displayMode); windowWidth = Settings::getInstance()->getInt("WindowWidth") ? - Settings::getInstance()->getInt("WindowWidth") : dispMode.w; + Settings::getInstance()->getInt("WindowWidth") : displayMode.w; windowHeight = Settings::getInstance()->getInt("WindowHeight") ? - Settings::getInstance()->getInt("WindowHeight") : dispMode.h; + Settings::getInstance()->getInt("WindowHeight") : displayMode.h; screenWidth = Settings::getInstance()->getInt("ScreenWidth") ? - Settings::getInstance()->getInt("ScreenWidth") : windowWidth; + Settings::getInstance()->getInt("ScreenWidth") : windowWidth; screenHeight = Settings::getInstance()->getInt("ScreenHeight") ? - Settings::getInstance()->getInt("ScreenHeight") : windowHeight; + Settings::getInstance()->getInt("ScreenHeight") : windowHeight; screenOffsetX = Settings::getInstance()->getInt("ScreenOffsetX") ? Settings::getInstance()->getInt("ScreenOffsetX") : 0; screenOffsetY = Settings::getInstance()->getInt("ScreenOffsetY") ? Settings::getInstance()->getInt("ScreenOffsetY") : 0; screenRotate = Settings::getInstance()->getInt("ScreenRotate") ? - Settings::getInstance()->getInt("ScreenRotate") : 0; + Settings::getInstance()->getInt("ScreenRotate") : 0; // Prevent ES window from minimizing when switching windows (when launching // games or when manually switching windows using task switcher). @@ -100,7 +104,7 @@ namespace Renderer #if defined(__APPLE__) || defined(__unix__) bool userResolution = false; // Check if the user has changed the resolution from the command line. - if (windowWidth != dispMode.w || windowHeight != dispMode.h) + if (windowWidth != displayMode.w || windowHeight != displayMode.h) userResolution = true; // Not sure if this could be a useful setting for some users. // SDL_SetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, "0"); @@ -234,7 +238,7 @@ namespace Renderer viewport.w = screenHeight; viewport.h = screenWidth; projection.orthoProjection(0, screenHeight, screenWidth, 0, -1.0, 1.0); - projection.rotate((float)ES_DEG_TO_RAD(90), {0, 0, 1}); + projection.rotate(static_cast(ES_DEG_TO_RAD(90)), {0, 0, 1}); projection.translate({0, screenHeight * -1.0f, 0}); } break; @@ -244,7 +248,7 @@ namespace Renderer viewport.w = screenWidth; viewport.h = screenHeight; projection.orthoProjection(0, screenWidth, screenHeight, 0, -1.0, 1.0); - projection.rotate((float)ES_DEG_TO_RAD(180), {0, 0, 1}); + projection.rotate(static_cast(ES_DEG_TO_RAD(180)), {0, 0, 1}); projection.translate({screenWidth * -1.0f, screenHeight * -1.0f, 0}); } break; @@ -254,7 +258,7 @@ namespace Renderer viewport.w = screenHeight; viewport.h = screenWidth; projection.orthoProjection(0, screenHeight, screenWidth, 0, -1.0, 1.0); - projection.rotate((float)ES_DEG_TO_RAD(270), {0, 0, 1}); + projection.rotate(static_cast(ES_DEG_TO_RAD(270)), {0, 0, 1}); projection.translate({screenWidth * -1.0f, 0, 0}); } break; @@ -284,24 +288,20 @@ namespace Renderer box.h = screenHeight - box.y; switch (screenRotate) { - case 0: { + case 0: box = Rect(screenOffsetX + box.x, screenOffsetY + box.y, box.w, box.h); - } break; - case 1: { - box = Rect(windowWidth - screenOffsetY - box.y - box.h, screenOffsetX + - box.x, box.h, box.w); - } + case 1: + box = Rect(windowWidth - screenOffsetY - box.y - box.h, + screenOffsetX + box.x, box.h, box.w); break; - case 2: { + case 2: box = Rect(windowWidth - screenOffsetX - box.x - box.w, windowHeight - screenOffsetY - box.y - box.h, box.w, box.h); - } break; - case 3: { - box = Rect(screenOffsetY + box.y, windowHeight - screenOffsetX - box.x - - box.w, box.h, box.w); - } + case 3: + box = Rect(screenOffsetY + box.y, windowHeight - + screenOffsetX - box.x - box.w, box.h, box.w); break; } diff --git a/es-core/src/renderers/Renderer.h b/es-core/src/renderers/Renderer.h index 39925574e..692e44317 100644 --- a/es-core/src/renderers/Renderer.h +++ b/es-core/src/renderers/Renderer.h @@ -1,10 +1,11 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // Renderer.h // // General rendering functions. // -#pragma once #ifndef ES_CORE_RENDERER_RENDERER_H #define ES_CORE_RENDERER_RENDERER_H diff --git a/es-core/src/renderers/Renderer_GL21.cpp b/es-core/src/renderers/Renderer_GL21.cpp index 3e0318cbb..2adeca94f 100644 --- a/es-core/src/renderers/Renderer_GL21.cpp +++ b/es-core/src/renderers/Renderer_GL21.cpp @@ -1,4 +1,6 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // Renderer_GL21.cpp // // OpenGL 2.1 rendering functions. @@ -88,24 +90,32 @@ namespace Renderer return false; } + #if defined(_WIN64) + glewInit(); + #endif + SDL_GL_MakeCurrent(getSDLWindow(), sdlContext); std::string vendor = glGetString(GL_VENDOR) ? - (const char*)glGetString(GL_VENDOR) : ""; + reinterpret_cast(glGetString(GL_VENDOR)) : ""; std::string renderer = glGetString(GL_RENDERER) ? - (const char*)glGetString(GL_RENDERER) : ""; + reinterpret_cast(glGetString(GL_RENDERER)) : ""; std::string version = glGetString(GL_VERSION) ? - (const char*)glGetString(GL_VERSION) : ""; + reinterpret_cast(glGetString(GL_VERSION)) : ""; std::string extensions = glGetString(GL_EXTENSIONS) ? - (const char*)glGetString(GL_EXTENSIONS) : ""; + reinterpret_cast(glGetString(GL_EXTENSIONS)) : ""; LOG(LogInfo) << "GL vendor: " << vendor; LOG(LogInfo) << "GL renderer: " << renderer; LOG(LogInfo) << "GL version: " << version; + #if defined(_WIN64) + LOG(LogInfo) << "EmulationStation renderer: OpenGL 2.1 with GLEW"; + #else LOG(LogInfo) << "EmulationStation renderer: OpenGL 2.1"; + #endif LOG(LogInfo) << "Checking available OpenGL extensions..."; std::string glExts = glGetString(GL_EXTENSIONS) ? - (const char*)glGetString(GL_EXTENSIONS) : ""; + reinterpret_cast(glGetString(GL_EXTENSIONS)) : ""; if (extensions.find("GL_ARB_texture_non_power_of_two") == std::string::npos) { LOG(LogError) << "GL_ARB_texture_non_power_of_two: MISSING"; missingExtension = true; @@ -327,7 +337,7 @@ namespace Renderer float shaderWidth = width * 1.2; // Workaround to get the scanlines to render somehow proportional to the // resolution. A better solution is for sure needed. - float shaderHeight = height + height / ((int)height >> 7) * 2.0; + float shaderHeight = height + height / (static_cast(height) >> 7) * 2.0; if (runShader) { runShader->activateShaders(); runShader->setModelViewProjectionMatrix(getProjectionMatrix() * _trans); @@ -343,7 +353,7 @@ namespace Renderer void setProjection(const Transform4x4f& _projection) { GL_CHECK_ERROR(glMatrixMode(GL_PROJECTION)); - GL_CHECK_ERROR(glLoadMatrixf((GLfloat*)&_projection)); + GL_CHECK_ERROR(glLoadMatrixf(reinterpret_cast(&_projection))); } void setMatrix(const Transform4x4f& _matrix) @@ -352,7 +362,7 @@ namespace Renderer matrix.round(); GL_CHECK_ERROR(glMatrixMode(GL_MODELVIEW)); - GL_CHECK_ERROR(glLoadMatrixf((GLfloat*)&matrix)); + GL_CHECK_ERROR(glLoadMatrixf(reinterpret_cast(&matrix))); } void setViewport(const Rect& _viewport) diff --git a/es-core/src/renderers/Shader_GL21.cpp b/es-core/src/renderers/Shader_GL21.cpp index b0f256d48..44b467de6 100644 --- a/es-core/src/renderers/Shader_GL21.cpp +++ b/es-core/src/renderers/Shader_GL21.cpp @@ -1,4 +1,6 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // Shader_GL21.cpp // // OpenGL 2.1 GLSL shader functions. @@ -38,7 +40,7 @@ namespace Renderer // This will load the entire GLSL source code into the string variable. const ResourceData& shaderData = ResourceManager::getInstance()->getFileData(path); - shaderCode.assign((const char*)shaderData.ptr.get(), shaderData.length); + shaderCode.assign(reinterpret_cast(shaderData.ptr.get()), shaderData.length); // Define the GLSL version (version 120 = OpenGL 2.1). preprocessorDefines = "#version 120\n"; @@ -65,7 +67,8 @@ namespace Renderer GLuint currentShader = glCreateShader(std::get<2>(*it)); GLchar const* shaderCodePtr = std::get<1>(*it).c_str(); - glShaderSource(currentShader, 1, (const GLchar**)&shaderCodePtr, nullptr); + glShaderSource(currentShader, 1, + reinterpret_cast(&shaderCodePtr), nullptr); glCompileShader(currentShader); GLint shaderCompiled; @@ -114,7 +117,8 @@ namespace Renderer void Renderer::Shader::setModelViewProjectionMatrix(Transform4x4f mvpMatrix) { if (shaderMVPMatrix != -1) - GL_CHECK_ERROR(glUniformMatrix4fv(shaderMVPMatrix, 1, GL_FALSE, (GLfloat*)&mvpMatrix)); + GL_CHECK_ERROR(glUniformMatrix4fv(shaderMVPMatrix, 1, GL_FALSE, + reinterpret_cast(&mvpMatrix))); } void Renderer::Shader::setTextureSize(std::array shaderVec2) diff --git a/es-core/src/renderers/Shader_GL21.h b/es-core/src/renderers/Shader_GL21.h index b9e199ab1..f92e6e28b 100644 --- a/es-core/src/renderers/Shader_GL21.h +++ b/es-core/src/renderers/Shader_GL21.h @@ -1,4 +1,6 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // Shader_GL21.h // // OpenGL 2.1 GLSL shader functions. @@ -11,6 +13,10 @@ #include "math/Transform4x4f.h" +#if defined(_WIN64) +#include +#endif + #include #include #include