Browse Source

Got X11 working on MacOS using the XQuartz compatibility tool.

David Piuva 9 months ago
parent
commit
b6a82f149a

+ 6 - 0
Source/DFPSR/DFPSR.DsrHead

@@ -38,6 +38,12 @@ if Graphics
 		Link "X11"
 		Link "X11"
 		WindowManager = "../windowManagers/X11Window.cpp"
 		WindowManager = "../windowManagers/X11Window.cpp"
 	end if
 	end if
+	if MacOS
+		# TODO: Replace with a native backend.
+		Message "  Using X11\n"
+		Link "X11"
+		WindowManager = "../windowManagers/X11Window.cpp"
+	end if
 	if Windows
 	if Windows
 		Message "  Using Win32\n"
 		Message "  Using Win32\n"
 		Link "gdi32"
 		Link "gdi32"

+ 8 - 0
Source/SDK/terrain/build_macos.sh

@@ -0,0 +1,8 @@
+# Hack to use X11 on MacOS
+export CPATH=/opt/homebrew/include:$CPATH
+export LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH
+
+# Launch the build system with Terrain.DsrProj and MacOS selected as the platform.
+echo "Running build_linux.sh $@"
+chmod +x ../../tools/builder/buildProject.sh;
+../../tools/builder/buildProject.sh Terrain.DsrProj MacOS $@;

+ 29 - 5
Source/windowManagers/X11Window.cpp

@@ -193,11 +193,9 @@ dsr::PackOrderIndex X11Window::getColorFormat_locked() {
 		visualRequest.depth = 32;
 		visualRequest.depth = 32;
 		visualRequest.c_class = TrueColor;
 		visualRequest.c_class = TrueColor;
 		int visualCount;
 		int visualCount;
+		dsr::PackOrderIndex result = dsr::PackOrderIndex::RGBA;
 		XVisualInfo *formatList = XGetVisualInfo(this->display, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualRequest, &visualCount);
 		XVisualInfo *formatList = XGetVisualInfo(this->display, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualRequest, &visualCount);
-		dsr::PackOrderIndex result = dsr::PackOrderIndex::RGBA;
-		if (formatList == nullptr) {
-			dsr::throwError(U"Error! The display does not support truecolor formats.\n");
-		} else {
+		if (formatList != nullptr) {
 			for (int i = 0; i < visualCount; i++) {
 			for (int i = 0; i < visualCount; i++) {
 				if (formatList[i].bits_per_rgb == 8) {
 				if (formatList[i].bits_per_rgb == 8) {
 					const uint32_t red = formatList[i].red_mask;
 					const uint32_t red = formatList[i].red_mask;
@@ -216,12 +214,38 @@ dsr::PackOrderIndex X11Window::getColorFormat_locked() {
 					} else if (blue == second && green == third && red == fourth) {
 					} else if (blue == second && green == third && red == fourth) {
 						result = dsr::PackOrderIndex::ABGR;
 						result = dsr::PackOrderIndex::ABGR;
 					} else {
 					} else {
-						dsr::throwError(U"Error! Unhandled color format. Only RGBA, ARGB, BGRA and ABGR are currently supported.\n");
+						dsr::throwError(U"Error! Unhandled 32-bit color format. Only RGBA, ARGB, BGRA and ABGR are currently supported.\n");
 					}
 					}
 					break;
 					break;
 				}
 				}
 			}
 			}
 			XFree(formatList);
 			XFree(formatList);
+		} else {
+			visualRequest.depth = 24;
+			XVisualInfo *formatList = XGetVisualInfo(this->display, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualRequest, &visualCount);
+			if (formatList != nullptr) {
+				for (int i = 0; i < visualCount; i++) {
+					if (formatList[i].bits_per_rgb == 8) {
+						const uint32_t red = formatList[i].red_mask;
+						const uint32_t green = formatList[i].green_mask;
+						const uint32_t blue = formatList[i].blue_mask;
+						const uint32_t first = 255u;
+						const uint32_t second = 255u << 8u;
+						const uint32_t third = 255u << 16u;
+						if (red == first && green == second && blue == third) {
+							result = dsr::PackOrderIndex::RGBA; // RGB
+						} else if (blue == first && green == second && red == third) {
+							result = dsr::PackOrderIndex::BGRA; // BGR
+						} else {
+							dsr::throwError(U"Error! Unhandled 24-bit color format. Only RGB and BGR are currently supported.\n");
+						}
+						break;
+					}
+				}
+				XFree(formatList);
+			} else {
+				dsr::throwError(U"Error! The display does not support any known 24 truecolor formats.\n");
+			}
 		}
 		}
 	unlockWindow();
 	unlockWindow();
 	return result;
 	return result;