Пример #1
0
 public Canvas3D(MainWindow window)
 {
     this.owner         = window;
     this.RenderFactory = window.RenderFactory;
     this.XwtRender     = window.XwtRender;
     this.Xwt           = window.Xwt;
 }
Пример #2
0
        public opentkdoc(IRendererFactory factory, IXwtRender xwtrender, IXwt xwt)
        {
            this.xwtrender = xwtrender;
            this.xwt       = xwt;
            this.factory   = factory;

            base.BackgroundColor = Colors.Black;
            base.MinWidth        = base.MinHeight = 100;
        }
Пример #3
0
            public Canvas3D(MainWindow window)
            {
                this.RenderFactory = window.Renderfactory;
                this.XwtRender     = window.XwtRender;
                this.Xwt           = window.Xwt;

                base.BackgroundColor = global::Xwt.Drawing.Colors.DarkGreen;
                base.MinWidth        = base.MinHeight = 100;
            }
Пример #4
0
 public GTK(out IRendererFactory render, bool initialize)
 {
     if (System.Environment.OSVersion.Platform == PlatformID.Unix ||
         System.Environment.OSVersion.Platform == PlatformID.MacOSX)
     {
         impl = new X11(out render);
     }
     else
     {
         impl = new Windows(out render);
     }
 }
Пример #5
0
        /* IRenderer IRendererFactory.Open(object ctl, Xwt.Size videosize)
         * {
         *   throw new NotImplementedException();
         * }*/
        IRenderer IRendererFactory.Open(IXwtRender xwt, Canvas w, IRenderOwner renderer, FPS fps, size videosize)
        {
            lock (this)
            {
                var window   = w.ParentWindow;
                var wFrame   = global::Xwt.Toolkit.CurrentEngine.GetSafeBackend(window);// as global::Xwt.WPFBackend.WindowFrameBackend;
                var wBackend = global::Xwt.Toolkit.CurrentEngine.GetSafeBackend(w);
                var e        = (System.Windows.FrameworkElement)wBackend.GetType().GetPropertyValue(wBackend, "Widget");

                return(new DirectX9Renderer(this, xwt, w, e, (System.Windows.Window)wFrame.GetType().GetPropertyValue(wFrame, "Window"), renderer, fps, videosize));
            }
        }
Пример #6
0
        public MainWindow(IRendererFactory renderfactory, IXwtRender xwtrender, IXwt xwt)
        {
            this.Renderfactory = renderfactory;
            this.XwtRender     = xwtrender;
            this.Xwt           = xwt;

            this.Content = new Canvas3D(this)
            {
                MinWidth            = 100,
                MinHeight           = 100,
                HorizontalPlacement = WidgetPlacement.Fill,
                VerticalPlacement   = WidgetPlacement.Fill,
                ExpandHorizontal    = true,
                ExpandVertical      = true
            };
        }
Пример #7
0
        /*  IRenderer IRendererFactory.Open(object ctl, System.Drawing.Size videosize)
         * {
         *    throw new NotImplementedException();
         * }*/
        IRenderer IRendererFactory.Open(IXwtRender xwt, Canvas widget, OpenTK.IRenderOwner renderer, FPS fps, size videosize)
        {
            lock (this)
            {
                IRenderer result;
                //    if (this.renderer == null)
                {
                    result = /*this.renderer = */ new OpenTKRenderer(this, xwt, widget, renderer, videosize);
                }
                //   else
                {
                    //        r = (this.renderer as OpenTKRenderer).Open(window, videosize);
                }

                renderers.Add(result);
                return(result);
            }
        }
Пример #8
0
        internal OpenTKRenderer(FrameFactory owner, IXwtRender xwtrender, Xwt.Canvas window, IRenderOwner renderer, size videosize)
        {
            //    OpenTKRenderer.usecnt = 1;
            this.owner     = owner;
            this.Xwt       = xwtrender;
            this.videosize = videosize;
            this.window    = window;
            this.renderer  = renderer;

            this.viewsize         = window.Size;
            window.BoundsChanged += viewsizechanged;

            this.actionthread = new Thread(run)
            {
                Name = "opentk"
            };
            this.actionthread.Start();

            var _this = this;

            this.Xwt.CreateForWidgetContext(this, this.renderer, window);

            // Invoke(() =>
            //  {
            this.Lock(false);
            try
            {
                try
                {
                    //        GL.GetInternalformat(TextureTarget.Texture2D, SizedInternalFormat.Rgba8, InternalFormatParameter..TEXTUREIMAGEFORMAT, 1, &preferred_format).

                    this.vertices1 = new vertices(_vertices);
                    this.vertices2 = new vertices(_vertices2);

                    /*   GL.GenBuffers(1, out buf_vertices2); // Generate 1 buffer
                     * GL.BindBuffer(BufferTarget.ArrayBuffer, buf_vertices2);
                     * GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0);
                     * GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 2 * sizeof(float));
                     * GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * vertices2.Length, vertices2, BufferUsageHint.StaticDraw);
                     * GL.EnableVertexAttribArray(0);
                     * GL.EnableVertexAttribArray(1);
                     *
                     * GL.GenBuffers(1, out buf_vertices3); // Generate 1 buffer
                     * GL.BindBuffer(BufferTarget.ArrayBuffer, buf_vertices3);
                     * GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0);
                     * GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 4 * sizeof(float), 2 * sizeof(float));
                     * GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * vertices3.Length, vertices3, BufferUsageHint.StaticDraw);
                     * GL.EnableVertexAttribArray(0);
                     * GL.EnableVertexAttribArray(1);*/

                    //     GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

                    /*    this.presentshader = new shader(shadervertex, shaderfragment, vertices1);
                     *  GL.UseProgram(this.presentshader);
                     *  var pos = GL.GetUniformLocation(this.presentshader, "tex");
                     *  GL.Uniform1(pos, 0);
                     */
                    /*             this.combineshader = new shader(combineshadervertex, combineshaderfragment, vertices1);
                     *
                     *           GL.UseProgram(combineshader);
                     *           var pos = GL.GetUniformLocation(this.combineshader, "tex");
                     *           GL.Uniform1(pos, 0);
                     *           pos = GL.GetUniformLocation(this.combineshader, "vpHeight");
                     *           GL.Uniform1(pos, (float)videosize.height);
                     *
                     *           this.deinterlaceblendshader = new shader(combineshadervertex, blendshaderfragment, vertices1);
                     *           GL.UseProgram(deinterlaceblendshader);
                     *           pos = GL.GetUniformLocation(this.deinterlaceblendshader, "vpHeight");
                     *           GL.Uniform1(pos, (float)videosize.height);
                     *
                     *           this.deinterlacesplitshader = new shader(combineshadervertex, splitshaderfragment, vertices1);
                     *
                     *           GL.UseProgram(deinterlacesplitshader);
                     *           pos = GL.GetUniformLocation(this.deinterlacesplitshader, "vpHeight");
                     *           GL.Uniform1(pos, (float)videosize.height);*/
                }
                catch (Exception e)
                {
                    //         Log.LogException(e);
                    Dispose(true);
                    GC.SuppressFinalize(this);
                    throw;
                }
            }
            finally
            {
                Unlock(false);
            }
            //   });
        }
Пример #9
0
        public mainwindow(IXwtRender xwtrender)
        {
            this.xwtrender = xwtrender;

            this.Title   = $"Xwt Demo Application {Xwt.Toolkit.CurrentEngine.Type}";
            this.Width   = 150; this.Height = 150;
            this.Padding = 0;

            this.CloseRequested += (s, e) => { if (!closing)
                                               {
                                                   e.AllowClose = this.close();
                                               }
            };

            var menu = new Menu();
            var file = new MenuItem("_File");

            file.SubMenu = new Menu();
            file.SubMenu.Items.Add(UIHelpers.NewMenuItem("New window", new_mainwindow));
            file.SubMenu.Items.Add(UIHelpers.NewMenuItem("New testdoc", new_testdoc));
            file.SubMenu.Items.Add(UIHelpers.NewMenuItem("New toolbar", new_toolbar));
            file.SubMenu.Items.Add(UIHelpers.NewMenuItem("New google", new_webview));
            file.SubMenu.Items.Add(UIHelpers.NewMenuItem("New opentk", new_opentk));
            file.SubMenu.Items.Add(UIHelpers.NewMenuItem("New opentk2", new_opentk2));
            file.SubMenu.Items.Add(UIHelpers.NewMenuItem("New properties", new_properties));
            //   file.SubMenu.Items.Add(new MenuItem("_Open"));
            //    file.SubMenu.Items.Add(new MenuItem("_New"));
            var mi = new MenuItem("_Close");

            mi.Clicked += (s, e) => { if (this.close())
                                      {
                                          base.Close();
                                      }
                                      ; };
            file.SubMenu.Items.Add(mi);
            menu.Items.Add(file);


            var dockmenu = new MenuItem("Dock")
            {
                SubMenu = new Menu()
            };

            dockmenu.SubMenu.Items.Add(UIHelpers.NewMenuItem("save layout to disk", save_layout));
            dockmenu.SubMenu.Items.Add(UIHelpers.NewMenuItem("load layout from disk", load_layout));
            menu.Items.Add(dockmenu);

            this.MainMenu = menu;
            this.Content  = dock = new DockPanel(this, Program.Xwt);

            try
            {
                dock.LoadXml(settingsfile, true, Deserialize);
            }
            catch
            {
                dock.Dock(new testdockitem());
                dock.Dock(new testtoolitem(this), DockPosition.Top);
                dock.Dock(new IDockContent[] { new testtoolitem(this), new testtoolitem(this), new testtoolitem(this), new testtoolitem(this), new testtoolitem(this) }, DockPosition.Top);
            }
        }
Пример #10
0
 private static void TryLoad(ToolkitType type)
 {
     ToolkitType           = type;
     XwtRender             = BaseLib.Media.OpenTK.Platform.TryLoad(type, out IRendererFactory renderfactory);
     Program.RenderFactory = renderfactory;
 }
Пример #11
0
        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();
        }