コード例 #1
0
ファイル: OTKSwapBuffer.cs プロジェクト: windygu/noForms
        void RenderPass(Common.Region dc, Common.Size ReqSize)
        {
            renderTime.Start();
            // Resize the form and backbuffer to noForm.Size
            Resize(ReqSize);

            Win32Util.Size w32Size = new Win32Util.Size((int)ReqSize.width, (int)ReqSize.height);
            Win32Util.SetWindowSize(w32Size, w32.handle);

            // Allow noform size to change as requested..like a layout hook (truncating layout passes with the render passes for performance)
            RenderSizeChanged(ReqSize);

            // Do Drawing stuff

            // 1) render to fbo
            throw new NotImplementedException();


// Create Color Texture
            uint ColorTexture;
            int  FboWidth  = (int)ReqSize.width;
            int  FboHeight = (int)ReqSize.height;

            GL.GenTextures(1, out ColorTexture);
            GL.BindTexture(TextureTarget.Texture2D, ColorTexture);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, FboWidth, FboHeight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);

            // create fbo
            uint FboHandle;

            GL.Ext.GenFramebuffers(1, out FboHandle);
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, FboHandle);
            GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, ColorTexture, 0);

            // draw to fbo..?
            noForm.DrawBase(this, dc);
            // unbind fbo
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); // return to visible framebuffer
            GL.DrawBuffer(DrawBufferMode.Back);

            // 2) go through dirty rects and copy to the window context
            throw new NotImplementedException();
            foreach (var dr in dc.AsRectangles())
            {
                //dostuff
            }

            // 3) call swapbuffers on window context...
            throw new NotImplementedException();

            currentFps = 1f / (float)renderTime.Elapsed.TotalSeconds;
            renderTime.Reset();
        }
コード例 #2
0
        void RenderPass(Common.Region dc, Common.Size ReqSize)
        {
            renderTime.Start();
            // Resize the backbuffer to noForm.Size, and fire the noForms sizechanged
            Resize(ReqSize);

            // Allow noform size to change as requested..like a layout hook (truncating layout passes with the render passes for performance)
            RenderSizeChanged(ReqSize);

            foreach (var dr in dc.AsRectangles())
            {
                var sdr = SDGTr.trF(dr);
                graphics.FillRectangle(blackBack, sdr);
            }

            // Do Drawing stuff
            noForm.DrawBase(this, dc);

            //res
            winForm.Invoke(new System.Windows.Forms.MethodInvoker(() =>
            {
                winForm.ClientSize = new System.Drawing.Size((int)ReqSize.width, (int)ReqSize.height);
                winForm.Location   = SDGTr.trI(noForm.Location);
            }));

            // flush buffer to window
            var winGr = winForm.CreateGraphics();

            foreach (var dr in dc.AsRectangles())
            {
                var sdr = SDGTr.trF(dr);
                winGr.DrawImage(buffer, sdr, sdr, GraphicsUnit.Pixel);
            }
            winGr.Dispose();
            lastFrameRenderDuration = 1f / (float)renderTime.Elapsed.TotalSeconds;
            renderTime.Reset();
        }
コード例 #3
0
ファイル: D2DSwapChain.cs プロジェクト: windygu/noForms
        void RenderPass(Common.Region dc, Common.Size ReqSize)
        {
            renderTime.Start();
            // Resize the form and backbuffer to noForm.Size
            Resize(ReqSize);

            Win32Util.Size w32Size = new Win32Util.Size((int)ReqSize.width, (int)ReqSize.height);
            Win32Util.SetWindowSize(w32Size, winHandle); // FIXME blocks when closing->endrender event is locked...

            // Allow noform size to change as requested..like a layout hook (truncating layout passes with the render passes for performance)
            RenderSizeChanged(ReqSize);

            // Do Drawing stuff
            DrawingSize rtSize = new DrawingSize((int)d2dRenderTarget.Size.Width, (int)d2dRenderTarget.Size.Height);

            using (Texture2D t2d = new Texture2D(backBuffer.Device, backBuffer.Description))
            {
                using (Surface1 srf = t2d.QueryInterface <Surface1>())
                {
                    using (RenderTarget trt = new RenderTarget(d2dFactory, srf, new RenderTargetProperties(d2dRenderTarget.PixelFormat)))
                    {
                        _backRenderer.renderTarget = trt;
                        trt.BeginDraw();
                        noForm.DrawBase(this, dc);
                        trt.EndDraw();

                        foreach (var rc in dc.AsRectangles())
                        {
                            t2d.Device.CopySubresourceRegion(t2d, 0,
                                                             new ResourceRegion()
                            {
                                Left = (int)rc.left, Right = (int)rc.right, Top = (int)rc.top, Bottom = (int)rc.bottom, Back = 1, Front = 0
                            }, backBuffer, 0,
                                                             (int)rc.left, (int)rc.top, 0);
                        }
                    }
                }
            }
            swapchain.Present(0, PresentFlags.None);

            //System.Threading.Thread.Sleep(1000);
            lastFrameRenderDuration = 1f / (float)renderTime.Elapsed.TotalSeconds;
            renderTime.Reset();
        }
コード例 #4
0
        void RenderPass(Common.Region dc, Common.Size ReqSize)
        {
            renderTime.Start();
            // FIXME so much object spam and disposal in this very high frequency function (also inside Resize called belw).  My poor megabytes!

            // Resize the form and backbuffer to noForm.Size, and fire the noForms sizechanged
            Resize(ReqSize);

            // make size...
            Win32Util.Size w32Size = new Win32Util.Size((int)ReqSize.width, (int)ReqSize.height);
            Win32Util.SetWindowSize(w32Size, hWnd);

            // Allow noform size to change as requested..like a layout hook (truncating layout passes with the render passes for performance)
            RenderSizeChanged(ReqSize);

            lock (noForm)
            {
                // Do Drawing stuff
                DrawingSize rtSize = new DrawingSize((int)d2dRenderTarget.Size.Width, (int)d2dRenderTarget.Size.Height);
                using (Texture2D t2d = new Texture2D(backBuffer.Device, backBuffer.Description))
                {
                    using (Surface1 srf = t2d.QueryInterface <Surface1>())
                    {
                        using (RenderTarget trt = new RenderTarget(d2dFactory, srf, new RenderTargetProperties(d2dRenderTarget.PixelFormat)))
                        {
                            _backRenderer.renderTarget = trt;
                            trt.BeginDraw();
                            noForm.DrawBase(this, dc);
                            // Fill with transparency the edgeBuffer!
                            trt.FillRectangle(new RectangleF(0, noForm.Size.height, noForm.Size.width + edgeBufferSize, noForm.Size.height + edgeBufferSize), scbTrans);
                            trt.FillRectangle(new RectangleF(noForm.Size.width, 0, noForm.Size.width + edgeBufferSize, noForm.Size.height + edgeBufferSize), scbTrans);
                            trt.EndDraw();

                            foreach (var rc in dc.AsRectangles())
                            {
                                t2d.Device.CopySubresourceRegion(t2d, 0,
                                                                 new ResourceRegion()
                                {
                                    Left = (int)rc.left, Right = (int)rc.right, Top = (int)rc.top, Bottom = (int)rc.bottom, Back = 1, Front = 0
                                }, backBuffer, 0,
                                                                 (int)rc.left, (int)rc.top, 0);
                            }
                        }
                    }
                }

                // Present DC to windows (ugh layered windows sad times)
                IntPtr dxHdc = surface.GetDC(false);
                System.Drawing.Graphics dxdc     = System.Drawing.Graphics.FromHdc(dxHdc);
                Win32Util.Point         dstPoint = new Win32Util.Point((int)(noForm.Location.X), (int)(noForm.Location.Y));
                Win32Util.Point         srcPoint = new Win32Util.Point(0, 0);
                Win32Util.Size          pSize    = new Win32Util.Size(rtSize.Width, rtSize.Height);
                Win32Util.BLENDFUNCTION bf       = new Win32Util.BLENDFUNCTION()
                {
                    SourceConstantAlpha = 255, AlphaFormat = Win32Util.AC_SRC_ALPHA, BlendFlags = 0, BlendOp = 0
                };

                bool suc = Win32Util.UpdateLayeredWindow(hWnd, someDC, ref dstPoint, ref pSize, dxHdc, ref srcPoint, 1, ref bf, 2);

                surface.ReleaseDC();
                dxdc.Dispose();
            }
            lastFrameRenderDuration = 1f / (float)renderTime.Elapsed.TotalSeconds;
            renderTime.Reset();
        }