public Renderer( PresentationParameters p_PresentationParameters ) { m_GraphicsAdapter = GraphicsAdapter.DefaultAdapter; m_PresentationParameters = p_PresentationParameters; #if XBOX360 m_PresentationParameters.BackBufferWidth = m_GraphicsAdapter.CurrentDisplayMode.Width; m_PresentationParameters.BackBufferHeight = m_GraphicsAdapter.CurrentDisplayMode.Height; m_PresentationParameters.IsFullScreen = true; #endif m_GraphicsDeviceService = GraphicsDeviceService.AddReference( m_PresentationParameters ); m_ServiceContainer.AddService< IGraphicsDeviceService >( m_GraphicsDeviceService ); m_ClearColour = new Color( 1.0f, 1.0f, 1.0f ); m_Width = m_PresentationParameters.BackBufferWidth; m_Height = m_PresentationParameters.BackBufferHeight; if( GamerServicesDispatcher.IsInitialized == false ) { GamerServicesDispatcher.WindowHandle = m_GraphicsDeviceService.GraphicsDevice. PresentationParameters.DeviceWindowHandle; GamerServicesDispatcher.Initialize( m_ServiceContainer ); GamerServicesDispatcher.Update( ); } }
protected override void Dispose(bool disposing) { if (graphicsDeviceService != null) { graphicsDeviceService.Release(disposing); graphicsDeviceService = null; } base.Dispose(disposing); }
/// <summary> /// Disposes the control. /// </summary> protected override void Dispose(Boolean disposing) { if (_graphicsDeviceService != null) { _graphicsDeviceService.Release(disposing); _graphicsDeviceService = null; } base.Dispose(disposing); }
protected override void Dispose( bool p_Disposing ) { if( m_GraphicsDeviceService != null ) { m_GraphicsDeviceService.Release( p_Disposing ); m_GraphicsDeviceService = null; } base.Dispose( p_Disposing ); }
public RendererImpl(IntPtr hwnd, int multiSampleCount, int minWidth, int minHeight) { Adapter = GraphicsAdapter.DefaultAdapter; PresentParams = new PresentationParameters() { DeviceWindowHandle = hwnd, BackBufferWidth = Math.Max(minWidth, GraphicsAdapter.Adapters.Max(a => a.CurrentDisplayMode.Width)), BackBufferHeight = Math.Max(minHeight, GraphicsAdapter.Adapters.Max(a => a.CurrentDisplayMode.Height)), BackBufferFormat = Adapter.CurrentDisplayMode.Format, DepthStencilFormat = DepthFormat.Depth24Stencil8, PresentationInterval = PresentInterval.Immediate, RenderTargetUsage = RenderTargetUsage.PreserveContents, MultiSampleCount = multiSampleCount, IsFullScreen = false, }; Device = new GraphicsDevice(Adapter, GraphicsProfile.HiDef, PresentParams); DeviceService = new GraphicsDeviceService(Device); Loader = new ContentManager(DeviceService, Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); SpriteBatch = new SpriteBatch(Device); DebugFont = Loader.Load<SpriteFont>("Content/Fonts/Debug"); WhiteTexel = new Texture2D(Device, 1, 1); WhiteTexel.SetData(new Color[] { Color.White }); if (Global.No) { CoordinateSystemTexture2D = Loader.Load<Texture2D>("Content/Textures/UV"); var ptw = 800; var pth = 600; var ptd = from y in Enumerable.Range(0, pth) from x in Enumerable.Range(0, ptw) let yb = y == 0 || y == (pth - 1) let xb = x == 0 || x == (ptw - 1) let bw = ((x / 8) % 2) == 0 ? Color.Black : Color.White select (xb || yb) ? Color.Black.Alpha(0.1f) : bw; HorizontalStripes = new Texture2D(Device, ptw, pth, false, SurfaceFormat.Color); HorizontalStripes.SetData(ptd.ToArray()); RenderTarget2D = new RenderTarget2D(Device, PresentParams.BackBufferWidth, PresentParams.BackBufferHeight, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); } PostOps = new List<Action>(); }
protected override void Dispose(bool disposing) { // Release our reference to the GraphicsDeviceService if we have one if (graphicsService != null) { graphicsService.Release(disposing); graphicsService = null; } // Unhook the Rendering event so we no longer attempt to draw CompositionTarget.Rendering -= CompositionTarget_Rendering; base.Dispose(disposing); }
//void XnaWindowHost_Loaded(object sender, RoutedEventArgs e) public void Start() { // If we don't yet have a GraphicsDeviceService reference, we must add one for this control if (graphicsService == null) { graphicsService = GraphicsDeviceService.AddRef(hWnd, (int)ActualWidth, (int)ActualHeight); // // Invoke the LoadContent event if (LoadContent != null) { LoadContent(this, new GraphicsServiceEventArgs(graphicsService)); } } }
private void OnUnloaded(object sender, RoutedEventArgs e) { if (_graphicsDeviceService != null) { RemoveBackBufferReference(); CompositionTarget.Rendering -= OnCompositionTargetRendering; _graphicsDeviceService.DeviceResetting -= OnGraphicsDeviceServiceDeviceResetting; _graphicsDeviceService = null; DeviceService.EndD3D(); } }
protected override void OnCreateControl ( ) { // construction logic graphicsDeviceService = GraphicsDeviceService.AddReference ( owner.Handle, vpRectangle ); // more construction logic // Give derived classes a chance to initialize themselves. Initialize ( ); }
protected override void Dispose(bool disposing) { if (_deviceService != null) { try { _deviceService.Release(); } catch { } _deviceService = null; } base.Dispose(disposing); }
public void initialize() { // Initialize graphics device service _graphicsDeviceService = GraphicsDeviceService.AddRef(view.Handle, view.Width, view.Height); // Initialize core resource controller ResourceManager.initialize(_graphicsDeviceService.GraphicsDevice); ResourceManager.rootDirectory = resourcesSourcePath + "\\"; // Create controllers _levelController = new LevelController(this, _editorView.levelView); _materialController = new MaterialController(this, _editorView.materialView); _blueprintController = new BlueprintController(this, _editorView.blueprintView); _circuitController = new CircuitController(this, _editorView.circuitsView); _backgroundController = new BackgroundController(this, _editorView.backgroundView); }
void DrawingSurface_Unloaded(object sender, RoutedEventArgs e) { if (GraphicsDeviceService != null) { // D3DImage will keep an reference to the backbuffer that causes the device reset below to fail. D3dImage.Lock(); D3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero); D3dImage.Unlock(); backbuffer = IntPtr.Zero; CompositionTarget.Rendering -= CompositionTarget_Rendering; GraphicsDeviceService.DeviceResetting -= GraphicsDeviceService_DeviceResetting; GraphicsDeviceService = null; } }
private void OnLoaded(object sender, RoutedEventArgs e) { if (_graphicsDeviceService == null) { // We use a render target, so the back buffer dimensions don't matter. _graphicsDeviceService = GraphicsDeviceService.AddRef(1, 1); _graphicsDeviceService.DeviceResetting += OnGraphicsDeviceServiceDeviceResetting; // Invoke the LoadContent event RaiseLoadContent(new GraphicsDeviceEventArgs(_graphicsDeviceService.GraphicsDevice)); EnsureRenderTarget(); CompositionTarget.Rendering += OnCompositionTargetRendering; _contentNeedsRefresh = true; } }
/// <summary> /// Initializes the control. /// </summary> protected override void OnCreateControl() { // Don't initialize the graphics device if we are running in the designer. if (!DesignMode) { graphicsDeviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height); // Register the service, so components like ContentManager can find it. services.AddService <IGraphicsDeviceService>(graphicsDeviceService); // Give derived classes a chance to initialize themselves. Initialize(); } base.OnCreateControl(); }
protected override void Dispose(bool disposing) { if (this.gDeviceService != null) { this.timer.Stop( ); this.timer = null; this.services.RemoveService(this.gDeviceService); this.gDeviceService.Dispose(disposing); this.gDeviceService = null; //GC.Collect( ); //GC.WaitForPendingFinalizers( ); GC.SuppressFinalize(this); } base.Dispose(disposing); }
protected override void OnCreateControl() { if (!DesignMode) { graphicsDeviceService = GraphicsDeviceService.AddRef(this.Handle, this.Width, this.Height); services.AddService(typeof(IGraphicsDeviceService), graphicsDeviceService); Initialize(); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.Update += new EventHandler(XNAControl_Update); this.FormDrawBefore += new EventHandler<PaintEventArgs>(XNAControl_FormDrawBefore); this.Draw += new EventHandler(XNAControl_Draw); this.FormDrawAfter += new EventHandler<PaintEventArgs>(XNAControl_FormDrawAfter); // TODO XNA输入绑定句柄管理 Microsoft.Xna.Framework.Input.Mouse.WindowHandle = this.Handle; } base.OnCreateControl(); }
void DrawingSurface_Loaded(object sender, RoutedEventArgs e) { if (GraphicsDeviceService == null) { GraphicsDeviceService = GraphicsDeviceService.AddRef(IntPtr.Zero, (int)ActualWidth, (int)ActualHeight, GraphicsProfile); GraphicsDeviceService.DeviceResetting += GraphicsDeviceService_DeviceResetting; D3dImage.Lock(); D3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, backbuffer = Interop.GetBackBuffer(GraphicsDeviceService.GraphicsDevice)); D3dImage.Unlock(); Marshal.Release(backbuffer); CompositionTarget.Rendering += CompositionTarget_Rendering; stopWatch = Stopwatch.StartNew(); lastDrawTimestamp = TimeSpan.Zero; contentNeedsRefresh = true; } }
protected override void OnCreateControl( ) { if (!this.DesignMode) { this.gDeviceService = GraphicsDeviceService.AddInstance(this.Handle, this.ClientSize.Width, this.ClientSize.Height, 8); // msaa this.services = new ServiceContainer( ); this.services.AddService <IGraphicsDeviceService>(this.gDeviceService); this.content = new ContentManager(this.services, @".\"); this.timer = Stopwatch.StartNew( ); this.Initialize( ); Application.Idle += delegate { this.Invalidate( ); }; } base.OnCreateControl( ); }
/// <summary> /// Constructs a new PForm. /// </summary> public PForm() { InitializeComponent(); // Don't initialize the graphics device if we are running in the designer. if (!DesignMode) { graphicsDeviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height); // Register the service, so components like ContentManager can find it. services.AddService <IGraphicsDeviceService>(graphicsDeviceService); InitializePiccolo(false, null); OpenDefaultProject(); RefreshProject(); } }
protected override void OnCreateControl( ) { if( !DesignMode ) { m_GraphicsDeviceService = GraphicsDeviceService.AddReference( Handle, ClientSize.Width, ClientSize.Height ); m_Services.AddService< IGraphicsDeviceService >( m_GraphicsDeviceService ); Initialise( ); m_Label.Text = this.Name; m_Label.AutoSize = true; this.Controls.Add( m_Label ); System.Diagnostics.Debug.WriteLine( "Handle: {0}", Handle ); } base.OnCreateControl( ); }
private void _tkControl_Load(object sender, EventArgs e) { if (!DesignMode) { _deviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height); _services.AddService <IGraphicsDeviceService>(_deviceService); if (ControlInitializing != null) { ControlInitializing(this, EventArgs.Empty); } Initialize(); if (ControlInitialized != null) { ControlInitialized(this, EventArgs.Empty); } } }
protected override void Dispose(bool disposing) { // Release our reference to the GraphicsDeviceService if we have one if (_graphicsService != null) { _graphicsService.Release(disposing); _graphicsService = null; } // Unhook all events. CompositionTarget.Rendering -= OnCompositionTargetRendering; if (Application.Current != null) { Application.Current.Activated -= OnApplicationActivated; Application.Current.Deactivated -= OnApplicationDeactivated; } SizeChanged -= OnXnaWindowHostSizeChanged; Loaded -= OnXnaWindowHostLoaded; base.Dispose(disposing); }
public Renderer(int bufferWidth, int bufferHeight, int msaa = 8) { this.control = new Control( ); ServiceContainer services = new ServiceContainer( ); this.gDeviceService = GraphicsDeviceService.AddInstance(this.control.Handle, bufferWidth, bufferHeight, msaa); services.AddService <IGraphicsDeviceService>(this.gDeviceService); this.gDevice = this.gDeviceService.GraphicsDevice; this.content = new ContentManager(services, @".\content"); this.renderTarget = new RenderTarget2D( this.gDevice, bufferWidth, bufferHeight, false, this.gDevice.PresentationParameters.BackBufferFormat, this.gDevice.PresentationParameters.DepthStencilFormat, msaa, RenderTargetUsage.DiscardContents); }
void UserControl_Loaded(object sender, RoutedEventArgs e) { // if we're not in design mode, initialize the graphics device if (DesignerProperties.GetIsInDesignMode(this) == false && graphicsService == null) { // add a reference to the graphics device graphicsService = GraphicsDeviceService.AddRef((PresentationSource.FromVisual(this) as HwndSource).Handle); // create the image source imageSource = new RenderTargetImageSource(GraphicsDevice, (int)ActualWidth, (int)ActualHeight); rootImage.Source = imageSource.WriteableBitmap; // hook the rendering event CompositionTarget.Rendering += CompositionTarget_Rendering; // Invoke the ControlLoaded event if (ControlLoaded != null) { ControlLoaded(this, new GraphicsDeviceEventArgs(graphicsService.GraphicsDevice)); } } }
#pragma warning disable 1591 protected override void OnCreateControl() { if (!designMode && ClientSize.Width > 0 && ClientSize.Height > 0) { _graphicsDeviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height, GraphicsProfile); Services.AddService <IGraphicsDeviceService>(_graphicsDeviceService); #if DX _chain = new SwapChainRenderTarget(_graphicsDeviceService.GraphicsDevice, Handle, ClientSize.Width, ClientSize.Height); Microsoft.Xna.Framework.Input.Mouse.WindowHandle = Handle; #elif GL _chain = new SwapChainRenderTarget_GL(_graphicsDeviceService.GraphicsDevice, ClientSize.Width, ClientSize.Height); _Intervall.Enabled = true; _Intervall.Start(); _Intervall.Tick += (sender, e) => { PresentDirty(); }; #endif AutomaticInvalidation = true; Initialize(); } base.OnCreateControl(); }
private void BootstrapSharpDX(System.Windows.Forms.Form form) { var registry = new GameServiceRegistry(); var graphicsDeviceService = new GraphicsDeviceService(form); registry.AddService(typeof(IGraphicsDeviceService), graphicsDeviceService); Engine.graphicsDeviceService = graphicsDeviceService; GraphicsContext graphicsContext = new GraphicsContext(graphicsDeviceService, graphicsDeviceService.Device, graphicsDeviceService.DeviceContext); Engine.graphicsContext = graphicsContext; ContentManager contentManager = new ContentManager(registry); Engine.contentManager = contentManager; InputContext inputContext = new InputContext(form); Engine.inputContext = inputContext; graphicsContext.GBuffer.Initialize(); }
public void instance(string[] args) { try { Form form = new Form(); GraphicsDeviceService gds = GraphicsDeviceService.AddRef(form.Handle, form.ClientSize.Width, form.ClientSize.Height); ServiceContainer services = new ServiceContainer(); services.AddService <IGraphicsDeviceService>(gds); var content = new ContentManager(services); foreach (string p in args) { Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " " + p); if (File.Exists(p)) { if (Path.GetExtension(p).Equals(".xnb")) { ConvertToPng(content, p); } } else { Console.WriteLine("Invalid file path or file"); } } foreach (string f in filesToDelete) { File.Delete(f); } content.Unload(); } catch (Exception e) { Console.WriteLine(e.Message); } }
protected override void OnCreateControl() { if (!DesignMode) { _deviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height); ServiceLocator.Add <IGraphicsDeviceService>(_deviceService); ServiceLocator.Add(_deviceService.GraphicsDevice); ServiceLocator.Add <IEntityService>(new EntityService()); ServiceLocator.Add <ICollisionService>(new CollisionService()); _camera = new Camera(_deviceService.GraphicsDevice.Viewport); if (!ServiceLocator.Has <Camera>()) { ServiceLocator.Add(_camera); } if (ControlInitializing != null) { ControlInitializing(this, EventArgs.Empty); } // Start the animation timer. _timer = Stopwatch.StartNew(); Initialize(); if (ControlInitialized != null) { ControlInitialized(this, EventArgs.Empty); } Application.Idle += (o, args) => Invalidate(true); } }
public void FixtureSetup() { _service = MockGraphicsDeviceService.AddRef(800, 600); }
private void _tkControl_Load(object sender, EventArgs e) { if (!DesignMode) { _deviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height); _services.AddService<IGraphicsDeviceService>(_deviceService); if (ControlInitializing != null) { ControlInitializing(this, EventArgs.Empty); } Initialize(); if (ControlInitialized != null) { ControlInitialized(this, EventArgs.Empty); } } }
public void Initialize() { ContentBuilder = new ContentBuilder(); Content = new ContentManager(GraphicsDeviceService.AddRef()); Content.RootDirectory = ContentBuilder.OutputDirectory; }
/// <summary> /// Initializes the control. /// </summary> protected override void OnCreateControl() { // Don't initialize the graphics device if we are running in the designer. if (!DesignMode) { graphicsDeviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height); // Register the service, so components like ContentManager can find it. services.AddService<IGraphicsDeviceService>(graphicsDeviceService); // Give derived classes a chance to initialize themselves. Initialize(); base.ResizeRedraw = true; } base.OnCreateControl(); }
public ServiceProvider() { graphicsDeviceService = new GraphicsDeviceService(); }
protected override void OnCreateControl() { if (!DesignMode) { _deviceService = GraphicsDeviceService.AddRef(Handle, ClientSize.Width, ClientSize.Height); _services.AddService<IGraphicsDeviceService>(_deviceService); if (ControlInitializing != null) { ControlInitializing(this, EventArgs.Empty); } Initialize(); if (ControlInitialized != null) { ControlInitialized(this, EventArgs.Empty); } } base.OnCreateControl(); }
public WriteableBitmap ToImage(bool opaqueAlpha) { if (this.textureType != 21) { using (var stream = new MemoryStream()) { stream.WriteU32(0x20534444); // 'DDS ' stream.WriteU32(0x7C); // header size stream.WriteU32(0xA1007); // flags: stream.WriteU32(height); stream.WriteU32(width); stream.WriteU32((uint)height * (uint)width); // size of top mipmap level... at least in DXT5 for >4x4 stream.WriteU32(0); stream.WriteU32(mipmapInfo / 0x100); for (int i = 0; i < 11; i++) { stream.WriteU32(0); } // pixel format stream.WriteU32(32); stream.WriteU32(4); // DDPF_FOURCC? stream.WriteU32(textureType); stream.WriteU32(32); stream.WriteU32(0xff0000); stream.WriteU32(0x00ff00); stream.WriteU32(0x0000ff); stream.WriteU32(0xff000000); stream.WriteU32(0); // 0x41008 for (int i = 0; i < 4; i++) { stream.WriteU32(0); } stream.Write(texData.blob, 0, texData.blob.Length); GraphicsDeviceService.AddRef(new WindowInteropHelper(Application.Current.MainWindow).Handle); Texture2D texture; try { DDSLib.DDSFromStream(stream, GraphicsDeviceService.Instance.GraphicsDevice, 0, true, out texture); return(new WriteableBitmap(DDSLib.Texture2Image(texture))); } catch { return(null); } } } else //In this case it's a regular bitmap saved as a texture { using (MemoryStream byteStream = new MemoryStream(this.texData.blob, 0, this.texData.blob.Length)) { for (int i = 0; i < this.mipmapInfo; i++) { // uint blockSize = byteStream.ReadU32().Swap(); WriteableBitmap bitmap = new WriteableBitmap((int)this.width, (int)this.height, 300, 300, PixelFormats.Pbgra32, BitmapPalettes.Halftone64); if (this.textureType == 21) { for (int j = 0; j < (byteStream.Length / 4); j++) { byte b = byteStream.ReadU8(); byte g = byteStream.ReadU8(); byte r = byteStream.ReadU8(); byte a = byteStream.ReadU8(); if (opaqueAlpha) { a = 255; } try { if ((j / this.width) < this.height) { bitmap.SetPixel((int)(j % this.width), (int)(j / this.width), a, r, g, b); } } catch { } } return(bitmap); } } } } return(null); }
public void Init(Dictionary<string, ISceneObject> scene, GraphicsDeviceService device, Camera camera) { m_camera = camera; m_device = device; m_sceneObjects = scene; }
/// <summary> /// Gets a reference to the singleton instance. /// </summary> public static GraphicsDeviceService AddRef(IntPtr windowHandle, int width, int height) { // Increment the "how many controls sharing the device" reference count. if (Interlocked.Increment(ref referenceCount) == 1) { // If this is the first control to start using the // device, we must create the singleton instance. singletonInstance = new GraphicsDeviceService(windowHandle, width, height); } return singletonInstance; }
protected override void OnCreateControl() { if(!DesignMode) { services = new ServiceContainer(); graphicsDeviceService = GraphicsDeviceService.AddRef(Handle, Width, Height); services.AddService<IGraphicsDeviceService>(graphicsDeviceService); // Register the service, so components like ContentManager can find it. spriteBatch = new SpriteBatch(GraphicsDevice); content = new ContentManager(services, "Content"); viewport = new Viewport(); surfaceRectangle = new XNARectangle(0, 0, Width, Height); canUpdate = true; Initialize(); } base.OnCreateControl(); }