Exemple #1
0
        void IRenderer.Present(IVideoFrame src, rectangle dstrec, IntPtr window) // painting on block or rpreview-something with alpha=255
        {
            dstrec = new rectangle(point.Zero, this.viewsize);

            if (islost || device.TestCooperativeLevel() == ResultCode.DeviceLost /*||
                                                                                  * this.lastsize.Width != r.Width || this.lastsize.Height != r.Height*/)
            {
                Reset();
                //      this.lastsize = r.Size;

                islost = false;
            }
            if (src != null)
            {
                this.frame.Set(0, src.Width, src.Height, 0);

                var dr = (this.frame as IDirectXFrame).Textures[0].LockRectangle(0, LockFlags.Discard);

                Debug.Assert(this.frame.Width == src.Width);
                Debug.Assert(this.frame.Height == src.Height);


                using (var lck = this.opentk.GetDrawLock())
                {
                    src.CopyTo(dr.DataPointer, dr.Pitch);
                    //       Marshal.Copy(fill, 0, dr.DataPointer, dr.Pitch * src.Height);
                }
                (this.frame as IDirectXFrame).Textures[0].UnlockRectangle(0);
            }
            else
            {
                this.frame.Set(0, this.renderframe.Width, this.renderframe.Height, 0);

                var dr = (this.frame as IDirectXFrame).Textures[0].LockRectangle(0, LockFlags.Discard);

                Debug.Assert(this.frame.Width == this.renderframe.Width);
                Debug.Assert(this.frame.Height == this.renderframe.Height);

                using (var lck = this.opentk.GetDrawLock())
                {
                    this.renderframe.CopyTo(dr.DataPointer, dr.Pitch);
                    //       Marshal.Copy(fill, 0, dr.DataPointer, dr.Pitch * renderframe.Height);
                }
                (this.frame as IDirectXFrame).Textures[0].UnlockRectangle(0);
            }
            //    IDirectXFrame framesrc = (IDirectXFrame)src;

            /*   device.Viewport = new SharpDX.Mathematics.Interop.RawViewport()
             * {
             *     X = 0,
             *     Y = 0,
             *     Width = this.viewsize.width,
             *     Height = viewsize.height,
             *     MinDepth=0,
             *     MaxDepth=1
             * };*/

            device.Clear(ClearFlags.Target, new SharpDX.Mathematics.Interop.RawColorBGRA(0, 0, 255, 255), 1.0f, 0);

            device.BeginScene();

            device.SetStreamSource(0, vertices2, 0, Utilities.SizeOf <vertex>());
            device.VertexDeclaration = vertexDecl2;

            var m = Matrix.Scaling(dstrec.width, -dstrec.height, 1) * Matrix.Translation(dstrec.x, dstrec.height, 0);

            //   Matrix proj = Matrix.Scaling(1, -1, 1);
            //   m= Matrix.Multiply(m, proj);
            var worldViewProj = m * CreateViewMatrix(this.viewsize.width, this.viewsize.height);

            presenteffect.SetValue("worldViewProj", worldViewProj);
            presenteffect.SetValue("alpha", 1.0f);
            presenteffect.SetTexture("texture0", (this.frame as IDirectXFrame).Textures[0]);

            //       effect.Technique = technique;
            presenteffect.Begin();
            presenteffect.BeginPass(0);

            device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);

            presenteffect.EndPass();
            presenteffect.End();

            device.EndScene();

            presenteffect.SetTexture("texture0", null);
        }