mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
108 lines
2.8 KiB
C++
108 lines
2.8 KiB
C++
|
#include <windows.h>
|
||
|
#include "d3d9helper.hpp"
|
||
|
#include "d3d9.hpp"
|
||
|
#include "d3dobject.hpp"
|
||
|
#include <iostream>
|
||
|
#include <winbase.h>
|
||
|
#include <drm/drm.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <unistd.h>
|
||
|
#include <sys/ioctl.h>
|
||
|
#include <linux/kd.h>
|
||
|
|
||
|
|
||
|
IDirect3D9::IDirect3D9 (UINT SDKVersion) {
|
||
|
//Create connection with DRM
|
||
|
int fd = open("/dev/dri/card0", O_RDWR, 0); //DirectX automatically selects the first GPU
|
||
|
|
||
|
if (fd < 0) {
|
||
|
std::cerr << "\033[1;31m" //RED BOLD
|
||
|
<< "ODX ERROR: Failed to open /dev/dri/card0. Please check if you have the proper permissions to access the device." << std::endl
|
||
|
<< "Direct3DCreate9 fails and returns NULL.\033[0;0m" << std::endl
|
||
|
<< std::endl;
|
||
|
close(fd);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
//check if the device is Hardware or Software (Does DirectX have this check?)
|
||
|
unsigned int gpuType;
|
||
|
|
||
|
int ioctlResult = ioctl(fd, DRM_IOCTL_GET_CAP, &gpuType);
|
||
|
if (ioctlResult != 0) {
|
||
|
std::cerr << "\033[1;31m"
|
||
|
<< "ODX ERROR: Failed to get device info" << std::endl
|
||
|
<< "Direct3DCreate9 fails and returns NULL.\033[0;0m" << std::endl
|
||
|
<< std::endl;
|
||
|
close(fd);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
std::cout << "\033[1;32m" //GREEN BOLD
|
||
|
<< "ODX INFO: Device is " << (gpuType == DRM_CAP_DUMB_BUFFER ? "Software" : "Hardware") << std::endl
|
||
|
<< "\033[0;0m" << std::endl;
|
||
|
|
||
|
IDirect3DDevice9* device;
|
||
|
this->CreateDevice(
|
||
|
D3DADAPTER_DEFAULT,
|
||
|
D3DDEVTYPE::D3DDEVTYPE_SW, // TODO
|
||
|
NULL, // TODO
|
||
|
NULL, // TODO
|
||
|
NULL, // TODO
|
||
|
&device
|
||
|
);
|
||
|
}
|
||
|
|
||
|
|
||
|
ULONG IDirect3D9::AddRef() {
|
||
|
DXGASSERT(((ULONG_PTR)(&m_cRef) & 3) == 0);
|
||
|
|
||
|
InterlockedIncrement((LONG *)&m_cRef);
|
||
|
return m_cRef;
|
||
|
}
|
||
|
|
||
|
|
||
|
HRESULT IDirect3D9::CreateDevice(
|
||
|
UINT Adapter,
|
||
|
D3DDEVTYPE DeviceType,
|
||
|
HWND hFocusWindow,
|
||
|
DWORD BehaviorFlags,
|
||
|
D3DPRESENT_PARAMETERS *pPresentationParameters,
|
||
|
IDirect3DDevice9 **ppReturnedDeviceInterface
|
||
|
) {
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
ULONG IDirect3D9::Release() {
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
HRESULT IDirect3D9::QueryInterface ( REFIID riid, void ** ppvObj ) {
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
IDirect3D9* Direct3DCreate9(UINT SDKVersion) {
|
||
|
HINSTANCE instance = NULL;
|
||
|
constexpr const UINT supported_sdk = 0x0900;
|
||
|
|
||
|
if (SDKVersion != supported_sdk) {
|
||
|
std::cout << "\033[1;31m" //RED BOLD
|
||
|
<< std::endl
|
||
|
<< "D3D ERROR: This application compiled against improper D3D headers." << std::endl
|
||
|
<< "The application is compiled with SDK version (" << SDKVersion << ") but the currently installed" << std::endl
|
||
|
<< "runtime supports versions from (" << supported_sdk << ")." << std::endl
|
||
|
<< "Please recompile with an up-to-date SDK.\033[0;0m" << std::endl
|
||
|
<< std::endl;
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
IDirect3D9* r = new IDirect3D9(SDKVersion);
|
||
|
|
||
|
if (r == NULL)
|
||
|
std::cout << "\033[0;31m"
|
||
|
<< "Creating D3D enumeration object failed; out of memory. Direct3DCreate fails and returns NULL.\033[0;0m" << std::endl;
|
||
|
|
||
|
return r;
|
||
|
}
|