void IXwtRender.CreateForWidgetContext(IRenderer renderer, IRenderOwner rendererimpl, Canvas widget) { impl.CreateForWidgetContext(renderer, rendererimpl, widget); }
internal DirectX9Renderer(FrameFactory owner, IXwtRender xwt, Canvas widget, System.Windows.FrameworkElement window, System.Windows.Window main, IRenderOwner renderer, FPS fps, size videosize) { this.owner = owner; this.xwt = xwt; this.widget = widget; this.window = window as System.Windows.Controls.Panel; this.mainwindow = main; this.videosize = videosize; this.renderer = renderer; var w = System.Windows.Window.GetWindow(this.mainwindow); var h = new WindowInteropHelper(w); this.hwnd = h.Handle; /* mainwindow.Measure(new System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity)); * mainwindow.Arrange(new Rect(0, 0, mainwindow.Width, mainwindow.Height)); * * this.window.Arrange(ew Rect(0, 0, this.window.ActualWidth, this.window.ActualHeight));*/ //window..CompositionTarget // OpenTKRenderer.usecnt = 1; // this.ctlhandle = this.ctl.Handle; this.viewsize = new size(Convert.ToInt32(window.ActualWidth), Convert.ToInt32(window.ActualHeight)); this.window.SizeChanged += Ctl_SizeChanged; xwt.CreateForWidgetContext(this, renderer, widget); this.opentk = this.owner.opentk.Open(this.owner.opentkxwt, widget, renderer, fps, videosize); this.thread = new WorkerThread(); this.thread.Do(() => { // System.Drawing.Rectangle r = new System.Drawing.Rectangle(System.Drawing.Point.Empty, this.viewsize);// Win32Helper.GetClientRect(ctlhandle); // this.lastsize = new System.Drawing.Size(r.Width, r.Height); this.pp = new PresentParameters(this.videosize.width, this.videosize.height); pp.DeviceWindowHandle = this.hwnd; pp.EnableAutoDepthStencil = true; pp.SwapEffect = SwapEffect.Copy; pp.PresentationInterval = PresentInterval.Immediate; try { /* this.direct3D = new Direct3DEx(); * this.isex = true; * this.device = new DeviceEx(this.direct3D as Direct3DEx, 0, DeviceType.Hardware, this.hwnd, CreateFlags.Multithreaded | CreateFlags.HardwareVertexProcessing, pp);*/ } catch { if (this.direct3D != null) { throw; } } if (this.direct3D == null) { this.direct3D = new Direct3D(); this.device = new Device(this.direct3D, 0, DeviceType.Hardware, this.hwnd, CreateFlags.Multithreaded | CreateFlags.HardwareVertexProcessing, pp); } this.depthtexture = new Texture(this.device, 4096, 4096, 1, Usage.DepthStencil, Format.D24S8, Pool.Default); this.depthsurface = this.depthtexture.GetSurfaceLevel(0); this.olddepth = this.device.DepthStencilSurface; this.device.DepthStencilSurface = this.depthsurface; // this.lastsize = r.Size; // Compiles the effect this.presenteffect = _LoadEffect("render");// Effect.FromFile(device, "render.fx", ShaderFlags.None); this.technique = presenteffect.GetTechnique(0); this.effect2 = _LoadEffect("render2"); this.technique2 = effect2.GetTechnique(0); this.effect3 = _LoadEffect("render3"); // Get the technique // Prepare matrices // Creates and sets the Vertex Declaration this.vertexDecl2 = new VertexDeclaration(device, vertexElems2); // device.SetStreamSource(0, vertices2, 0, Utilities.SizeOf<vertex>()); // device.VertexDeclaration = vertexDecl2; this.vertices2 = new VertexBuffer(device, Utilities.SizeOf <vertex>() * 6, Usage.WriteOnly, VertexFormat.None, isex ? Pool.Default : Pool.Managed); vertices2.Lock(0, 0, LockFlags.None).WriteRange(this.initdata); vertices2.Unlock(); this.indices = new IndexBuffer(device, sizeof(int) * initdata2.Length, Usage.WriteOnly, isex ? Pool.Default : Pool.Managed, false); this.indices.Lock(0, 0, LockFlags.None).WriteRange(this.initdata2); this.indices.Unlock(); this.frame = new VideoFrame(this); this.frame.Set(opentk.AlphaFormat); }); this._layer = new layer(this); this._layer?.rec.Arrange(new Rect(0, 0, this.window.ActualWidth, this.window.ActualHeight)); this.window.Children.Add((FrameworkElement)_layer); //this.initdone.Set(); }