Yuxiao Mao пре 4 месеци
родитељ
комит
6f2fb0c8f6
4 измењених фајлова са 60 додато и 60 уклоњено
  1. 2 2
      libs/directx/directx.cpp
  2. 3 3
      libs/directx/dx12.cpp
  3. 6 6
      libs/directx/gamecontroller.c
  4. 49 49
      libs/directx/window.c

+ 2 - 2
libs/directx/directx.cpp

@@ -358,7 +358,7 @@ HL_PRIM dx_pointer *HL_NAME(create_input_layout)( varray *arr, vbyte *bytecode,
 
 HL_PRIM dx_pointer *HL_NAME(create_depth_stencil_view)( dx_resource *tex, int format, bool readOnly ) {
 	ID3D11DepthStencilView *view;
-	D3D11_DEPTH_STENCIL_VIEW_DESC  desc;
+	D3D11_DEPTH_STENCIL_VIEW_DESC desc;
 	ZeroMemory(&desc, sizeof(desc));
 	desc.Format = (DXGI_FORMAT)format;
 	desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
@@ -373,7 +373,7 @@ HL_PRIM dx_pointer *HL_NAME(create_depth_stencil_state)( dx_struct<D3D11_DEPTH_S
 	return state;
 }
 
-HL_PRIM void HL_NAME(om_set_depth_stencil_state)( dx_pointer *s, int ref )  {
+HL_PRIM void HL_NAME(om_set_depth_stencil_state)( dx_pointer *s, int ref ) {
 	driver->context->OMSetDepthStencilState((ID3D11DepthStencilState*)s,ref);
 }
 

+ 3 - 3
libs/directx/dx12.cpp

@@ -502,12 +502,12 @@ inline UINT64 UpdateSubresources(
 	auto MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
 	if (MemToAlloc > SIZE_MAX)
 	{
-	   return 0;
+		return 0;
 	}
 	void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));
 	if (pMem == nullptr)
 	{
-	   return 0;
+		return 0;
 	}
 	auto pLayouts = static_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
 	auto pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
@@ -923,7 +923,7 @@ HL_PRIM void HL_NAME(command_list_set_graphics_root_unordered_access_view)( ID3D
 	l->SetGraphicsRootUnorderedAccessView(index,handle);
 }
 
-HL_PRIM void HL_NAME(command_list_execute_indirect)( ID3D12GraphicsCommandList *l, ID3D12CommandSignature *sign, int maxCommandCount, ID3D12Resource *args, int64 argsOffset, ID3D12Resource *count, int64 countOffset  ) {
+HL_PRIM void HL_NAME(command_list_execute_indirect)( ID3D12GraphicsCommandList *l, ID3D12CommandSignature *sign, int maxCommandCount, ID3D12Resource *args, int64 argsOffset, ID3D12Resource *count, int64 countOffset ) {
 	l->ExecuteIndirect(sign, maxCommandCount, args, argsOffset, count, countOffset);
 }
 

+ 6 - 6
libs/directx/gamecontroller.c

@@ -185,7 +185,7 @@ static BOOL CALLBACK gctrl_dinput_deviceCb(const DIDEVICEINSTANCE *instance, voi
 
 	result = IDirectInput8_CreateDevice(gctrl_dinput, &instance->guidInstance, &di_device, NULL);
 	if( FAILED(result) ) return DIENUM_CONTINUE;
-	
+
 	device = (dx_gctrl_device*)malloc(sizeof(dx_gctrl_device));
 	ZeroMemory(device, sizeof(dx_gctrl_device));
 
@@ -256,7 +256,7 @@ static void gctrl_dinput_update(dx_gctrl_data *data) {
 	}
 	if( result != DI_OK )
 		return;
-	
+
 	data->buttons = 0;
 	for( int i = 0; i < mapping->button->size; i++ ) {
 		dinput_mapping_btn *bmap = hl_aptr(mapping->button, dinput_mapping_btn*)[i];
@@ -272,9 +272,9 @@ static void gctrl_dinput_update(dx_gctrl_data *data) {
 		}
 
 		switch (i) {
-			case 0: 
+			case 0:
 			case 2:
-				((double*)data->axes)[i] = (double)(val / 65535.) * 2 - 1.; 
+				((double*)data->axes)[i] = (double)(val / 65535.) * 2 - 1.;
 				break;
 			case 1:
 			case 3:
@@ -284,14 +284,14 @@ static void gctrl_dinput_update(dx_gctrl_data *data) {
 			case 5:
 				((double*)data->axes)[i] = bmap->axis < 0 ? (val > 0 ? 1 : 0) : (double)(val / 65535.);
 				break;
-			default: 
+			default:
 				data->buttons |= (val > 0 ? 1 : 0) << (i - 6);
 				break;
 		}
 	}
 }
 
-// 
+//
 
 void gctrl_detect_thread(void *p) {
 	while (true) {

+ 49 - 49
libs/directx/window.c

@@ -138,14 +138,14 @@ static bool setRelativeMode( HWND wnd, bool enabled ) {
 	RAWINPUTDEVICE mouse = { 0x01, 0x02, 0, NULL }; /* Mouse: UsagePage = 1, Usage = 2 */
 
 	if ( relative_mouse == enabled ) return true;
-	
+
 	if ( !enabled ) {
 		mouse.dwFlags |= RIDEV_REMOVE;
 		if ( show_cursor ) SetCursor(cur_cursor);
 	} else {
 		SetCursor(NULL);
 	}
-	
+
 	relative_mouse = enabled;
 	updateClipCursor(wnd);
 
@@ -203,8 +203,8 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar
 	case WM_SYSCOMMAND:
 		if( wparam == SC_KEYMENU && (lparam>>16) <= 0 )
 			return 0;
-		break;	
-	case WM_MOUSEMOVE: 
+		break;
+	case WM_MOUSEMOVE:
 		{
 			dx_events *evt = get_events(wnd);
 			if( !evt->is_over ) {
@@ -229,11 +229,11 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar
 				RAWINPUT inp;
 				UINT size = sizeof(inp);
 				GetRawInputData(hRawInput, RID_INPUT, &inp, &size, sizeof(RAWINPUTHEADER));
-				
+
 				// Ignore pseudo-movement from touch events.
 				if ( inp.header.dwType == RIM_TYPEMOUSE ) {
 					RAWMOUSE* mouse = &inp.data.mouse;
-					
+
 					if ( (mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE ) {
 						if ( mouse->lLastX != 0 || mouse->lLastY != 0 ) {
 							e = addEvent(wnd, MouseMove);
@@ -243,12 +243,12 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar
 							e->mouseXRel = mouse->lLastX;
 							e->mouseYRel = mouse->lLastY;
 						}
-						
+
 					} else if ( mouse->lLastX || mouse->lLastY ) {
 						// Absolute movement - simulate relative movement
-						
+
 						static POINT lastMousePos;
-						
+
 						bool virtual_desktop = mouse->usFlags & MOUSE_VIRTUAL_DESKTOP;
 						int w = GetSystemMetrics(virtual_desktop ? SM_CXVIRTUALSCREEN : SM_CXSCREEN);
 						int h = GetSystemMetrics(virtual_desktop ? SM_CYVIRTUALSCREEN : SM_CYSCREEN);
@@ -268,7 +268,7 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar
 							lastMousePos.x = x;
 							lastMousePos.y = y;
 						}
-						
+
 					}
 				}
 			}
@@ -291,7 +291,7 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar
 			}
 		}
 		bool repeat = (umsg == WM_KEYDOWN || umsg == WM_SYSKEYDOWN) && (lparam & 0x40000000) != 0;
-		// see 
+		// see
 		e = addEvent(wnd,(umsg == WM_KEYUP || umsg == WM_SYSKEYUP) ? KeyUp : KeyDown);
 		e->keyCode = (int)wparam;
 		e->scanCode = (lparam >> 16) & 0xFF;
@@ -318,7 +318,7 @@ static LRESULT CALLBACK WndProc( HWND wnd, UINT umsg, WPARAM wparam, LPARAM lpar
 			shift_downs[0] = false;
 			e = addEvent(wnd,KeyUp);
 			e->keyCode = VK_SHIFT | 256;
-		}			
+		}
 		if( shift_downs[1] && GetKeyState(VK_RSHIFT) >= 0 ) {
 			//printf("RSHIFT RELEASED\n");
 			shift_downs[1] = false;
@@ -523,7 +523,7 @@ HL_PRIM dx_window *HL_NAME(win_create_ex)( int x, int y, int width, int height,
 		wc.cbClsExtra    = 0;
 		wc.cbWndExtra    = 0;
 		wc.hInstance     = hinst;
-		wc.hIcon		 = ExtractIcon(hinst, fileName, 0);
+		wc.hIcon         = ExtractIcon(hinst, fileName, 0);
 		wc.hIconSm       = wc.hIcon;
 		wc.hCursor       = NULL;
 		wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
@@ -702,7 +702,7 @@ HL_PRIM void HL_NAME(win_resize)(dx_window *win, int mode) {
 HL_PRIM void HL_NAME(win_set_fullscreen)(dx_window *win, bool fs) {
 	if( fs ) {
 		MONITORINFO mi = { sizeof(mi) };
-        GetMonitorInfo(MonitorFromWindow(win,MONITOR_DEFAULTTOPRIMARY), &mi);
+		GetMonitorInfo(MonitorFromWindow(win,MONITOR_DEFAULTTOPRIMARY), &mi);
 		SetWindowLong(win,GWL_STYLE,WS_POPUP | WS_VISIBLE);
 		SetWindowPos(win,NULL,mi.rcMonitor.left,mi.rcMonitor.top,mi.rcMonitor.right - mi.rcMonitor.left,mi.rcMonitor.bottom - mi.rcMonitor.top,SWP_NOOWNERZORDER|SWP_FRAMECHANGED|SWP_SHOWWINDOW);
 	} else {
@@ -951,46 +951,46 @@ HL_PRIM dx_cursor HL_NAME(load_cursor)( int res ) {
 
 HL_PRIM dx_cursor HL_NAME(create_cursor)( int width, int height, vbyte *data, int hotX, int hotY ) {
 	int pad = sizeof(void*) << 3;
-    HICON hicon;
-    HDC hdc = GetDC(NULL);
-    BITMAPV4HEADER bmh;
-    void *pixels;
-    void *maskbits;
-    int maskbitslen;
-    ICONINFO ii;
-
-    ZeroMemory(&bmh,sizeof(bmh));
-    bmh.bV4Size = sizeof(bmh);
-    bmh.bV4Width = width;
-    bmh.bV4Height = -height;
-    bmh.bV4Planes = 1;
-    bmh.bV4BitCount = 32;
-    bmh.bV4V4Compression = BI_BITFIELDS;
-    bmh.bV4AlphaMask = 0xFF000000;
-    bmh.bV4RedMask   = 0x00FF0000;
-    bmh.bV4GreenMask = 0x0000FF00;
-    bmh.bV4BlueMask  = 0x000000FF;
-
-    maskbitslen = ((width + (-width)%pad) >> 3) * height;
-    maskbits = malloc(maskbitslen);
+	HICON hicon;
+	HDC hdc = GetDC(NULL);
+	BITMAPV4HEADER bmh;
+	void *pixels;
+	void *maskbits;
+	int maskbitslen;
+	ICONINFO ii;
+
+	ZeroMemory(&bmh,sizeof(bmh));
+	bmh.bV4Size = sizeof(bmh);
+	bmh.bV4Width = width;
+	bmh.bV4Height = -height;
+	bmh.bV4Planes = 1;
+	bmh.bV4BitCount = 32;
+	bmh.bV4V4Compression = BI_BITFIELDS;
+	bmh.bV4AlphaMask = 0xFF000000;
+	bmh.bV4RedMask   = 0x00FF0000;
+	bmh.bV4GreenMask = 0x0000FF00;
+	bmh.bV4BlueMask  = 0x000000FF;
+
+	maskbitslen = ((width + (-width)%pad) >> 3) * height;
+	maskbits = malloc(maskbitslen);
 	if( maskbits == NULL )
 		return NULL;
 	memset(maskbits,0xFF,maskbitslen);
 
 	memset(&ii,0,sizeof(ii));
-    ii.fIcon = FALSE;
-    ii.xHotspot = (DWORD)hotX;
-    ii.yHotspot = (DWORD)hotY;
-    ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, DIB_RGB_COLORS, &pixels, NULL, 0);
-    ii.hbmMask = CreateBitmap(width, height, 1, 1, maskbits);
-    ReleaseDC(NULL, hdc);
-    free(maskbits);
-
-    memcpy(pixels, data, height * width * 4);
-    hicon = CreateIconIndirect(&ii);
-
-    DeleteObject(ii.hbmColor);
-    DeleteObject(ii.hbmMask);
+	ii.fIcon = FALSE;
+	ii.xHotspot = (DWORD)hotX;
+	ii.yHotspot = (DWORD)hotY;
+	ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, DIB_RGB_COLORS, &pixels, NULL, 0);
+	ii.hbmMask = CreateBitmap(width, height, 1, 1, maskbits);
+	ReleaseDC(NULL, hdc);
+	free(maskbits);
+
+	memcpy(pixels, data, height * width * 4);
+	hicon = CreateIconIndirect(&ii);
+
+	DeleteObject(ii.hbmColor);
+	DeleteObject(ii.hbmMask);
 	return hicon;
 }