public static void uploadKeySymMap(this iGraphicsEngine engine) { lock ( syncRoot ) { if (uploaded) { return; } uploaded = true; // Deserialize into an array Assembly ass = Assembly.GetExecutingAssembly(); using (var x11 = ComLightCast.cast <iLinuxEngine>(engine)) using (var stm = ass.GetManifestResourceStream(resourceName)) using (var unzip = new GZipStream(stm, CompressionMode.Decompress)) using (var reader = new BinaryReader(unzip)) { int count = reader.ReadInt32(); sKeySymMap[] map = new sKeySymMap[count]; for (int i = 0; i < count; i++) { map[i].read(reader); } // Upload the data to native memory. // X11 window class uses the data to resolve key symbols // https://www.oreilly.com/library/view/xlib-reference-manual/9780937175262/16_appendix-h.html // into characters, to be passed to iKeyboardHandler.keyEvent method. x11.uploadKeySymMap(map, count); } } }
void switchToTrueFullScreen(iDiligentWindow window) { if (window.windowState == eShowWindow.TrueFullscreen) { // Already in true full screen mode. Switch to maximized borderless. window.moveWindow(eShowWindow.Fullscreen); return; } iGraphicsEngine graphicsEngine = Render.graphicsEngine; using (var gpuEnum = graphicsEngine.createGpuEnumerator()) using (var gpu = gpuEnum.openDefaultAdapter()) using (var connector = gpu.openDefaultConnector()) { var format = context.swapChainFormats.color; if (format == Diligent.Graphics.TextureFormat.Unknown) { throw new ApplicationException("The swap chain was not created"); } connector.setSurfaceFormat(format); // Debug code below // Console.WriteLine( "Following is available:\n{0}", string.Join( "\n", connector.getAllModes() ) ); // connector.enumModes(); CSize trueFullScreenRez = new CSize(1920, 1080); if (!connector.findVideoMode(out var mode, ref trueFullScreenRez)) { throw new ApplicationException("The default monitor doesn't support FullHD"); } window.fullScreen(connector, ref mode); } }
/// <summary>Before creating any windows, please call this. Will only do something on Linux.</summary> public static void loadKeySyms(this iGraphicsEngine engine) { if (RuntimeEnvironment.operatingSystem != eOperatingSystem.Linux) { return; } engine.uploadKeySymMap(); }
static void runFullScreen(iGraphicsEngine engine, SampleBase sample) { iVideoSetup videoSetup = new Utils.VideoSetup(idealDrmFormat); var dispatcher = engine.dispatcher(); ThreadPool.QueueUserWorkItem(obj => { Console.ReadKey(); dispatcher.postQuitMessage(0); }); engine.renderFullScreen(sample.context, fullscreenResolution, videoSetup); }
public static void print(iGraphicsEngine engine) { using (var dispatcher = engine.dispatcher()) using (var gpuEnum = engine.createGpuEnumerator()) using (var gpu = gpuEnum.openFirstAdapter()) { int count = gpu.getInfo().numConnectors; for (int i = 0; i < count; i++) { using (var c = gpu.openConnector(i)) Console.WriteLine(c.getInfo().ToString()); } } }
/// <summary>Create a window on desktop, and run the application rendering into that window.</summary> /// <remarks>This works on both Windows and Linux. On Linux you need a desktop manager for this, "Raspbian Buster Lite" distro doesn’t have it.</remarks> public static void renderWindowed(this iGraphicsEngine engine, Context content, string windowTitle = null, iWindowSetup windowSetup = null) { if (null == currentEngine) { currentEngine = new WeakReference <iGraphicsEngine>(engine); } var deviceType = RuntimeEnvironment.defaultDevice; engine.loadKeySyms(); using (var dispatcher = engine.dispatcher()) using (var window = dispatcher.nativeDispatcher.createWindow(content, windowSetup, deviceType)) { content.initialize(window, null); // Wire up the input setupWindowedInput(window, content); // Set the title window.windowTitle = windowTitle ?? $"{ content.ToString() } ( { deviceType } )"; // Run the main loop dispatcher.run(content); } content.flushShadersCache(); }
/// <summary>Uninitialize logging; any log messages produced after this call will go straight to /dev/null</summary> public static void clearLoggerSink(this iGraphicsEngine engine) { engine.setLoggerSink(null, eLogLevel.Error); }
/// <summary>Create a .NET dispatcher for the current thread.</summary> /// <remarks>If the current thread already has one created, return the old one instead.</remarks> public static Dispatcher dispatcher(this iGraphicsEngine engine) { return(Dispatcher.currentDispatcher ?? new Dispatcher(engine.createDispatcher())); }
/// <summary>Get capability flags implemented by the currently loaded native library.</summary> public static eCapabilityFlags getCapabilityFlags(this iGraphicsEngine engine) { return(engine.getLibraryInfo().capabilityFlags); }
static extern void createEngine([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Marshaler <iGraphicsEngine>))] out iGraphicsEngine engine);
static void runWindowed(iGraphicsEngine engine, SampleBase sample) { iWindowSetup setup = new Utils.WindowSetup(); engine.renderWindowed(sample.context, null, setup); }
/// <summary>Wire up logging of Diligent native library into colored console</summary> public static void setConsoleLoggerSink(this iGraphicsEngine native, eLogLevel maxLevel = eLogLevel.Info) { logLevel = maxLevel; native.setLoggerSink(pfnLog, maxLevel); GraphicsUtils.engineCreated(native); }