static void setupWindowedInput(iDiligentWindow window, Context content) { iKeyboardInput keyboardInput = content.scene as iKeyboardInput; iMouseInput mouseInput = content.scene as iMouseInput; if (null == keyboardInput && null == mouseInput) { return; } if (null != keyboardInput) { var handler = keyboardInput.keyboardHandler; if (handler is iInputEventTime eventTime) { eventTime.sourceInitialized(window.timeSource()); } window.input.keyboardInputHandler(handler); } if (null != mouseInput) { var handler = mouseInput.mouseHandler; if (handler is iInputEventTime eventTime) { eventTime.sourceInitialized(window.timeSource()); } window.input.mouseInputHandler(handler); } }
bool handleWindowedModeHotkey(iDiligentWindow window, eKey key, eKeyboardState ks) { // if( key == eKey.Esc && content.windowState == eShowWindow.Fullscreen ) if (key == eKey.Esc) { window.moveWindow(eShowWindow.Normal); return(true); } if (key == eKey.Up && ks.HasFlag(eKeyboardState.ControlDown)) { window.moveWindow(eShowWindow.Maximized); return(true); } if (key == eKey.Down && ks.HasFlag(eKeyboardState.ControlDown)) { window.moveWindow(eShowWindow.Minimized); return(true); } if (key == eKey.Enter && ks.HasFlag(eKeyboardState.AltDown)) { if (ks.HasFlag(eKeyboardState.ControlDown)) { switchToTrueFullScreen(window); } else { window.moveWindow(eShowWindow.Fullscreen); } return(true); } return(false); }
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); } }
void iContent.swapChainRecreated(iDiligentWindow window) { try { swapChain = window.swapChain; context = window.context; timersHardPause?.Dispose(); timersHardPause = null; var scDesc = swapChain.GetDesc(); swapChainSize = new CSize(scDesc.Width, scDesc.Height); byte samples = swapChainFormats.sampleCount; swapChainFormats = new SwapChainFormats(scDesc.ColorBufferFormat, scDesc.DepthBufferFormat, samples); swapChainBuffersCount = scDesc.BufferCount; } catch (Exception ex) { NativeContext.cacheException(ex); throw; } }
async Task iSceneAsyncInit.createResourcesAsync(Context context) { iDiligentWindow wnd = context.renderContext as iDiligentWindow; wnd?.setTitle("Vrmac graphics video player sample"); mediaEngine.autoPlay = true; // string dir = RuntimeEnvironment.runningWindows ? windowsDirectory : linuxDirectory; // await mediaEngine.loadMedia( Path.Combine( dir, fileName ) ); await mediaEngine.loadMedia(mediaFilePath); var streams = mediaEngine.mediaStreams; if (!streams.HasFlag(eMediaStreams.Video)) { throw new ApplicationException("There's no video in that media file"); } using (var dev = context.device) renderState = mediaEngine.createRenderer(context, dev, videoBorderColor); context.swapChainResized.add(this, onResized); ConsoleLogger.logInfo("VideoPlayerSample started playing the media"); mouseHandler.subscribe(controller); controller.initialize(animation, mediaEngine); if (null != wnd) { string fileName = Path.GetFileName(mediaFilePath); wnd.windowTitle = "Vrmac graphics video player sample: " + fileName; } // Debug code below: wait 2 seconds, and seek // await Task.Delay( 2000 ); // mediaEngine.setCurrentTime( TimeSpan.FromSeconds( 2278 ) ); }
/// <summary>Switch window state without moving the window</summary> public static void moveWindow(this iDiligentWindow wnd, eShowWindow newState) { CRect rect = CRect.empty; wnd.moveWindow(newState, ref rect); }
/// <summary>Get a time source interface, to get timestamps of input events</summary> public static iInputEventTimeSource timeSource(this iDiligentWindow wnd) { return(timeSources.GetValue(wnd, callback)); }
static iInputEventTimeSource createTimeSource(iDiligentWindow window) { return(new InputEventTime(window.input)); }