mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
UWP: 3D rendering works sort of
This commit is contained in:
parent
705106e324
commit
c26fb7b162
@ -1,5 +1,6 @@
|
|||||||
#include "../../src/Core.h"
|
#include "../../src/Core.h"
|
||||||
|
|
||||||
|
#include <winrt/Windows.ApplicationModel.DataTransfer.h>
|
||||||
#include <winrt/Windows.ApplicationModel.h>
|
#include <winrt/Windows.ApplicationModel.h>
|
||||||
#include <winrt/Windows.ApplicationModel.Core.h>
|
#include <winrt/Windows.ApplicationModel.Core.h>
|
||||||
#include <winrt/Windows.ApplicationModel.Activation.h>
|
#include <winrt/Windows.ApplicationModel.Activation.h>
|
||||||
@ -13,6 +14,7 @@
|
|||||||
using namespace winrt;
|
using namespace winrt;
|
||||||
using namespace Windows::ApplicationModel;
|
using namespace Windows::ApplicationModel;
|
||||||
using namespace Windows::ApplicationModel::Core;
|
using namespace Windows::ApplicationModel::Core;
|
||||||
|
using namespace Windows::ApplicationModel::DataTransfer;
|
||||||
using namespace Windows::ApplicationModel::Activation;
|
using namespace Windows::ApplicationModel::Activation;
|
||||||
using namespace Windows::Devices::Input;
|
using namespace Windows::Devices::Input;
|
||||||
using namespace Windows::Graphics::Display;
|
using namespace Windows::Graphics::Display;
|
||||||
@ -27,6 +29,7 @@ using namespace Windows::UI::Input;
|
|||||||
#include "../../src/Bitmap.h"
|
#include "../../src/Bitmap.h"
|
||||||
#include "../../src/Options.h"
|
#include "../../src/Options.h"
|
||||||
#include "../../src/Errors.h"
|
#include "../../src/Errors.h"
|
||||||
|
#define UWP_STRING(str) ((wchar_t*)(str)->uni)
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
@ -37,6 +40,7 @@ void Window_PreInit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Window_Init(void) {
|
void Window_Init(void) {
|
||||||
|
CoreWindow& window = CoreWindow::GetForCurrentThread();
|
||||||
Input.Sources = INPUT_SOURCE_NORMAL;
|
Input.Sources = INPUT_SOURCE_NORMAL;
|
||||||
|
|
||||||
DisplayInfo.Width = 640;
|
DisplayInfo.Width = 640;
|
||||||
@ -44,6 +48,13 @@ void Window_Init(void) {
|
|||||||
DisplayInfo.Depth = 32;
|
DisplayInfo.Depth = 32;
|
||||||
DisplayInfo.ScaleX = 1.0f;
|
DisplayInfo.ScaleX = 1.0f;
|
||||||
DisplayInfo.ScaleY = 1.0f;
|
DisplayInfo.ScaleY = 1.0f;
|
||||||
|
|
||||||
|
Rect bounds = window.Bounds();
|
||||||
|
|
||||||
|
WindowInfo.UIScaleX = DEFAULT_UI_SCALE_X;
|
||||||
|
WindowInfo.UIScaleY = DEFAULT_UI_SCALE_Y;
|
||||||
|
WindowInfo.Width = bounds.Width;
|
||||||
|
WindowInfo.Height = bounds.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window_Free(void) { }
|
void Window_Free(void) { }
|
||||||
@ -58,9 +69,18 @@ void Window_SetTitle(const cc_string* title) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Clipboard_GetText(cc_string* value) {
|
void Clipboard_GetText(cc_string* value) {
|
||||||
|
DataPackageView content = Clipboard::GetContent();
|
||||||
|
hstring str = content.GetTextAsync().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clipboard_SetText(const cc_string* value) {
|
void Clipboard_SetText(const cc_string* value) {
|
||||||
|
cc_winstring raw;
|
||||||
|
Platform_EncodeString(&raw, value);
|
||||||
|
auto str = hstring(UWP_STRING(&raw));
|
||||||
|
|
||||||
|
DataPackage package = DataPackage();
|
||||||
|
package.SetText(str);
|
||||||
|
Clipboard::SetContent(package);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Window_GetWindowState(void) {
|
int Window_GetWindowState(void) {
|
||||||
@ -88,6 +108,10 @@ void Window_RequestClose(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Window_ProcessEvents(float delta) {
|
void Window_ProcessEvents(float delta) {
|
||||||
|
CoreWindow& window = CoreWindow::GetForCurrentThread();
|
||||||
|
|
||||||
|
CoreDispatcher& dispatcher = window.Dispatcher();
|
||||||
|
dispatcher.ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gamepads_Init(void) {
|
void Gamepads_Init(void) {
|
||||||
@ -97,11 +121,18 @@ void Gamepads_Init(void) {
|
|||||||
void Gamepads_Process(float delta) { }
|
void Gamepads_Process(float delta) { }
|
||||||
|
|
||||||
static void Cursor_GetRawPos(int* x, int* y) {
|
static void Cursor_GetRawPos(int* x, int* y) {
|
||||||
*x = 0;
|
CoreWindow& window = CoreWindow::GetForCurrentThread();
|
||||||
*y = 0;
|
|
||||||
|
Point point = window.PointerPosition();
|
||||||
|
*x = point.X;
|
||||||
|
*y = point.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cursor_SetPosition(int x, int y) {
|
void Cursor_SetPosition(int x, int y) {
|
||||||
|
CoreWindow& window = CoreWindow::GetForCurrentThread();
|
||||||
|
|
||||||
|
Point point = Point(x, y);
|
||||||
|
window.PointerPosition(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Cursor_DoSetVisible(cc_bool visible) {
|
static void Cursor_DoSetVisible(cc_bool visible) {
|
||||||
@ -209,8 +240,15 @@ void OpenFileDialog(void) {
|
|||||||
//Windows::Storage::StorageFile file = picker->PickSingleFileAsync();
|
//Windows::Storage::StorageFile file = picker->PickSingleFileAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CCApp : implements<CCApp, IFrameworkView>
|
struct CCApp : implements<CCApp, IFrameworkViewSource, IFrameworkView>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// IFrameworkViewSource interface
|
||||||
|
IFrameworkView CreateView()
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// IFrameworkView interface
|
// IFrameworkView interface
|
||||||
void Initialize(CoreApplicationView const& view)
|
void Initialize(CoreApplicationView const& view)
|
||||||
{
|
{
|
||||||
@ -227,10 +265,11 @@ struct CCApp : implements<CCApp, IFrameworkView>
|
|||||||
void Run()
|
void Run()
|
||||||
{
|
{
|
||||||
CoreWindow& window = CoreWindow::GetForCurrentThread();
|
CoreWindow& window = CoreWindow::GetForCurrentThread();
|
||||||
window.Activate();
|
window.Activate();
|
||||||
|
Window_Main.Handle.ptr = get_abi(window);
|
||||||
|
|
||||||
CoreDispatcher& dispatcher = window.Dispatcher();
|
extern int main(int argc, char** argv);
|
||||||
dispatcher.ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
|
main(0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetWindow(CoreWindow const& win)
|
void SetWindow(CoreWindow const& win)
|
||||||
@ -238,15 +277,8 @@ struct CCApp : implements<CCApp, IFrameworkView>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CCAppSource : implements<CCAppSource, IFrameworkViewSource>
|
|
||||||
{
|
|
||||||
IFrameworkView CreateView() {
|
|
||||||
return make<CCApp>();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int __stdcall wWinMain(void*, void*, wchar_t** argv, int argc)
|
int __stdcall wWinMain(void*, void*, wchar_t** argv, int argc)
|
||||||
{
|
{
|
||||||
auto app = make<CCAppSource>();
|
auto app = make<CCApp>();
|
||||||
CoreApplication::Run(app);
|
CoreApplication::Run(app);
|
||||||
}
|
}
|
@ -190,7 +190,7 @@ typedef cc_uint8 cc_bool;
|
|||||||
#define CC_BUILD_NOMUSIC
|
#define CC_BUILD_NOMUSIC
|
||||||
#define CC_BUILD_NOSOUNDS
|
#define CC_BUILD_NOSOUNDS
|
||||||
#define DEFAULT_NET_BACKEND CC_NET_BACKEND_BUILTIN
|
#define DEFAULT_NET_BACKEND CC_NET_BACKEND_BUILTIN
|
||||||
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_SOFTGPU
|
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_D3D11
|
||||||
#elif defined _WIN32
|
#elif defined _WIN32
|
||||||
#define CC_BUILD_WIN
|
#define CC_BUILD_WIN
|
||||||
#define DEFAULT_NET_BACKEND CC_NET_BACKEND_BUILTIN
|
#define DEFAULT_NET_BACKEND CC_NET_BACKEND_BUILTIN
|
||||||
|
@ -12,8 +12,16 @@
|
|||||||
#define NOIME
|
#define NOIME
|
||||||
#define COBJMACROS
|
#define COBJMACROS
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
|
|
||||||
static const GUID guid_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
|
static const GUID guid_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
|
||||||
static const GUID guid_IXDGIDevice = { 0x54ec77fa, 0x1377, 0x44e6, { 0x8c, 0x32, 0x88, 0xfd, 0x5f, 0x44, 0xc8, 0x4c } };
|
static const GUID guid_IXDGIDevice = { 0x54ec77fa, 0x1377, 0x44e6, { 0x8c, 0x32, 0x88, 0xfd, 0x5f, 0x44, 0xc8, 0x4c } };
|
||||||
|
static const GUID guid_IDXGIFactory = { 0x7b7166ec, 0x21c7, 0x44ae, { 0xb2, 0x1a, 0xc9, 0xae, 0x32, 0x1a, 0xe3, 0x69 } };
|
||||||
|
static const GUID guid_IDXGIDevice = { 0x54ec77fa, 0x1377, 0x44e6, { 0x8c, 0x32, 0x88, 0xfd, 0x5f, 0x44, 0xc8, 0x4c } };
|
||||||
|
static const GUID guid_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
|
||||||
|
#ifdef CC_BUILD_UWP
|
||||||
|
#include <dxgi1_2.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// some generally useful debugging links
|
// some generally useful debugging links
|
||||||
// https://docs.microsoft.com/en-us/visualstudio/debugger/graphics/visual-studio-graphics-diagnostics
|
// https://docs.microsoft.com/en-us/visualstudio/debugger/graphics/visual-studio-graphics-diagnostics
|
||||||
@ -46,6 +54,51 @@ static void PS_UpdateShader(void);
|
|||||||
static void InitPipeline(void);
|
static void InitPipeline(void);
|
||||||
static void FreePipeline(void);
|
static void FreePipeline(void);
|
||||||
|
|
||||||
|
#ifdef CC_BUILD_UWP
|
||||||
|
static void LoadD3D11Library(void) { }
|
||||||
|
|
||||||
|
static void CreateDeviceAndSwapChain(void) {
|
||||||
|
// https://docs.microsoft.com/en-us/windows/uwp/gaming/simple-port-from-direct3d-9-to-11-1-part-1--initializing-direct3d
|
||||||
|
DWORD createFlags = 0;
|
||||||
|
D3D_FEATURE_LEVEL fl;
|
||||||
|
HRESULT hr;
|
||||||
|
#ifdef _DEBUG
|
||||||
|
createFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL,
|
||||||
|
createFlags, NULL, 0, D3D11_SDK_VERSION,
|
||||||
|
&device, &fl, &context);
|
||||||
|
if (hr) Logger_Abort2(hr, "Failed to create D3D11 device");
|
||||||
|
|
||||||
|
Gfx.MaxTexWidth = fl < D3D_FEATURE_LEVEL_11_0 ? 8192 : 16384;
|
||||||
|
Gfx.MaxTexHeight = fl < D3D_FEATURE_LEVEL_11_0 ? 8192 : 16384;
|
||||||
|
|
||||||
|
DXGI_SWAP_CHAIN_DESC1 desc = { 0 };
|
||||||
|
desc.BufferCount = 2; // TODO 1??
|
||||||
|
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||||
|
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||||
|
desc.SampleDesc.Count = 1;
|
||||||
|
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
||||||
|
desc.Scaling = DXGI_SCALING_NONE;
|
||||||
|
|
||||||
|
IDXGIDevice* dxgi_device = NULL;
|
||||||
|
hr = ID3D11Device_QueryInterface(device, &guid_IDXGIDevice, &dxgi_device);
|
||||||
|
if (FAILED(hr)) Logger_Abort2(hr, "Querying DXGI device");
|
||||||
|
|
||||||
|
IDXGIAdapter* dxgi_adapter = NULL;
|
||||||
|
hr = IDXGIDevice_GetAdapter(dxgi_device , &dxgi_adapter);
|
||||||
|
if (FAILED(hr)) Logger_Abort2(hr, "Querying DXGI adapter");
|
||||||
|
|
||||||
|
IDXGIFactory2* dxgi_factory2 = NULL;
|
||||||
|
hr = IDXGIAdapter_GetParent(dxgi_adapter, &guid_IDXGIFactory2, &dxgi_factory2);
|
||||||
|
if (FAILED(hr)) Logger_Abort2(hr, "Querying DXGI factory");
|
||||||
|
|
||||||
|
void* window = Window_Main.Handle.ptr;
|
||||||
|
hr = IDXGIFactory2_CreateSwapChainForCoreWindow(dxgi_factory2, device, window, &desc, NULL, &swapchain);
|
||||||
|
if (FAILED(hr)) Logger_Abort2(hr, "Creating swap chain");
|
||||||
|
}
|
||||||
|
#else
|
||||||
static PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN _D3D11CreateDeviceAndSwapChain;
|
static PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN _D3D11CreateDeviceAndSwapChain;
|
||||||
|
|
||||||
static void LoadD3D11Library(void) {
|
static void LoadD3D11Library(void) {
|
||||||
@ -99,6 +152,7 @@ static void CreateDeviceAndSwapChain(void) {
|
|||||||
Gfx.MaxTexWidth = fl < D3D_FEATURE_LEVEL_11_0 ? 8192 : 16384;
|
Gfx.MaxTexWidth = fl < D3D_FEATURE_LEVEL_11_0 ? 8192 : 16384;
|
||||||
Gfx.MaxTexHeight = fl < D3D_FEATURE_LEVEL_11_0 ? 8192 : 16384;
|
Gfx.MaxTexHeight = fl < D3D_FEATURE_LEVEL_11_0 ? 8192 : 16384;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void Gfx_Create(void) {
|
void Gfx_Create(void) {
|
||||||
LoadD3D11Library();
|
LoadD3D11Library();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user