isle-portable/CONFIG/qt/detectdx5.cpp
olebeck 47736862a7
Add PSVita port (#541)
* add psvita to cmake

* no PIE for vita

* add modules to vpk

* use custom pvr apphint

* select correct renderer for sdl renderer

* patch sdl3 shaders, got something on screen!

* use proper cmake patch for sdl

* add missing module

* remove test window which causes a bug in the vita sdl port to show up

* add gxm renderer (not working with display yet)

* avoid sdl renderer for vita, seems broken

* make gxm renderer work with new d3drm

* fix rendering somewhat, some geometry shows up

* support paletted textures directly to avoid copying the texture twice

* fix Draw2DImage

* make 3d work, broken lights

* clean up a bit

* fix normals matrix

* remove some unneeded changes

* forgot env var

* wrong env dest

* run clang format

* correct texture address mode, use tlsf instead of sceClibMspace

* double buffered uniforms seem to work now

* missed a line

* update GXMRenderer_EnumDevice

* hopefully actually fix uniform buffers

* run clang-format

* remove a change thats not needed

* improve fragment shader performance

* add vita to dist folder

* add base for vita config app

* add config self to vpk

* transform touch events to virtual size

* add livearea graphics

* Update cmake file to include livearea assets

* put manual in the right place

* add sample rco

* add messagebox on vita

* triple buffer textures because fences arent a thing on vita and making draw&cpu sync would be too slow

* make config app not crash on launch

* change defaults

* update gxm renderer with interface changes

* split 2d and 3d shaders completely

* update gxm renderer

* fix transition on gxm

* clang format

* move config cmake

* move CONFIG_vita

* always clear before drawing 2d image

* hopefully fix windows build

* clang-format fix broken includes

* order again

* undo moving qt cmake to its own list

* move uic search path

* use ifdefs for all d3drm backends, cpack to generate vpk

* cmake wrong escape

* small cleanups in gxm renderer

* defer texture delete to avoid overwriting the texture during a frame

* clang-format

* more of the layout for config

* remove top buttons

* use SceAppSettings instead of custom ui

* use select for back to info center on vita, to make screenshots possible again

* remove accidentally left in add_subdirectory

* adjust diskpath to be like other ports

* use vita_create_vpk and not cpack

* gxm: msaa support, fix wrong file path

* gxm: add mipmaps (disabled)

* clang-format

* fix open isle.ini with fopen

* add missing strings

* use iniparser_set not dictionary_set

* add default save path to config

* load config app after initializing ini on vita

* fix config build

* change the default disk & cd path, update the paf library

* update paf library headers

* include orders for clang-format

* clean up

* make shader compiler not required

* move asm language

* warn instead of error when shader source is changed when no compiler is found

---------

Co-authored-by: Li <li@silica.codes>
Co-authored-by: Christian Semmler <mail@csemmler.com>
2025-10-31 23:23:12 +00:00

159 lines
4.2 KiB
C++

#include "detectdx5.h"
#ifdef MINIWIN
#include "miniwin/ddraw.h"
#include "miniwin/dinput.h"
#include "qlibrary.h"
#include "qoperatingsystemversion.h"
#else
#include <ddraw.h>
#include <dinput.h>
#endif
typedef struct IUnknown* LPUNKNOWN;
typedef HRESULT WINAPI DirectDrawCreate_fn(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnknown FAR* pUnkOuter);
typedef HRESULT WINAPI
DirectInputCreateA_fn(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA* ppDI, LPUNKNOWN punkOuter);
// FUNCTION: CONFIG 0x004048f0
bool DetectDirectX5()
{
unsigned int version;
bool found;
DetectDirectX(&version, &found);
return version >= 0x500;
}
// FUNCTION: CONFIG 0x00404920
void DetectDirectX(unsigned int* p_version, bool* p_found)
{
#ifdef MINIWIN
QOperatingSystemVersion os_version = QOperatingSystemVersion::current();
*p_found = true;
*p_version = 0x500;
#else
OSVERSIONINFOA os_version;
os_version.dwOSVersionInfoSize = sizeof(os_version);
if (!GetVersionEx(&os_version)) {
*p_version = 0;
*p_found = 0;
return;
}
if (os_version.dwPlatformId == 2) {
*p_found = 2;
if (os_version.dwMajorVersion < 4) {
*p_found = 0;
return;
}
if (os_version.dwMajorVersion != 4) {
*p_version = MAKEWORD(5, 1);
return;
}
*p_version = 0x200;
HMODULE dinput_module = LoadLibrary("DINPUT.DLL");
if (!dinput_module) {
OutputDebugString("Couldn't LoadLibrary DInput\r\n");
return;
}
DirectInputCreateA_fn* func_DirectInputCreateA =
(DirectInputCreateA_fn*) GetProcAddress(dinput_module, "DirectInputCreateA");
FreeLibrary(dinput_module);
if (!func_DirectInputCreateA) {
OutputDebugString("Couldn't GetProcAddress DInputCreate\r\n");
return;
}
*p_version = MAKEWORD(3, 0);
return;
}
*p_found = true;
if (LOWORD(os_version.dwBuildNumber) >= 0x550) {
*p_version = MAKEWORD(5, 1);
return;
}
HMODULE ddraw_module = LoadLibrary("DDRAW.DLL");
if (!ddraw_module) {
*p_version = 0;
*p_found = false;
FreeLibrary(ddraw_module);
return;
}
DirectDrawCreate_fn* func_DirectDrawCreate =
(DirectDrawCreate_fn*) GetProcAddress(ddraw_module, "DirectDrawCreate");
if (!func_DirectDrawCreate) {
*p_version = 0;
*p_found = false;
FreeLibrary(ddraw_module);
OutputDebugString("Couldn't LoadLibrary DDraw\r\n");
return;
}
LPDIRECTDRAW ddraw;
if (FAILED(func_DirectDrawCreate(NULL, &ddraw, NULL))) {
*p_version = 0;
*p_found = false;
FreeLibrary(ddraw_module);
OutputDebugString("Couldn't create DDraw\r\n");
return;
}
*p_version = MAKEWORD(1, 0);
LPDIRECTDRAW2 ddraw2;
if (FAILED(ddraw->QueryInterface(IID_IDirectDraw2, (LPVOID*) &ddraw2))) {
ddraw->Release();
FreeLibrary(ddraw_module);
OutputDebugString("Couldn't QI DDraw2\r\n");
return;
}
ddraw->Release();
*p_version = MAKEWORD(2, 0);
HMODULE dinput_module = LoadLibrary("DINPUT.DLL");
if (!dinput_module) {
OutputDebugString("Couldn't LoadLibrary DInput\r\n");
ddraw2->Release();
FreeLibrary(ddraw_module);
return;
}
DirectInputCreateA_fn* func_DirectInputCreateA =
(DirectInputCreateA_fn*) GetProcAddress(dinput_module, "DirectInputCreateA");
FreeLibrary(dinput_module);
if (!func_DirectInputCreateA) {
FreeLibrary(ddraw_module);
ddraw2->Release();
OutputDebugString("Couldn't GetProcAddress DInputCreate\r\n");
return;
}
*p_version = MAKEWORD(3, 0);
DDSURFACEDESC surface_desc;
memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS;
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
if (FAILED(ddraw2->SetCooperativeLevel(NULL, DDSCL_NORMAL))) {
ddraw2->Release();
FreeLibrary(ddraw_module);
*p_version = 0;
OutputDebugString("Couldn't Set coop level\r\n");
return;
}
LPDIRECTDRAWSURFACE surface;
if (FAILED(ddraw2->CreateSurface(&surface_desc, &surface, NULL))) {
ddraw2->Release();
FreeLibrary(ddraw_module);
*p_version = 0;
OutputDebugString("Couldn't CreateSurface\r\n");
return;
}
LPDIRECTDRAWSURFACE3 surface3;
if (FAILED(surface->QueryInterface(IID_IDirectDrawSurface3, (LPVOID*) &surface3))) {
ddraw2->Release();
FreeLibrary(ddraw_module);
return;
}
*p_version = MAKEWORD(5, 0);
surface3->Release();
ddraw2->Release();
FreeLibrary(ddraw_module);
#endif
}