public void DrawBox(float x, float y, float w, float h, float px, Color4 Color)
        {
            if (px <= 0)
            {
                return;
            }

            x             += shiftX;
            y             += shiftY;
            line.GLLines   = true;
            line.Antialias = true;
            line.Width     = px;

            line.Begin();
            line.Draw(new Vector2[2] {
                new Vector2(x, y), new Vector2(x + w, y)
            }, Color);
            line.Draw(new Vector2[2] {
                new Vector2(x + w, y), new Vector2(x + w, y + h)
            }, Color);
            line.Draw(new Vector2[2] {
                new Vector2(x + w, y + h), new Vector2(x, y + h)
            }, Color);
            line.Draw(new Vector2[2] {
                new Vector2(x, y + h), new Vector2(x, y)
            }, Color);
            line.End();
        }
Exemplo n.º 2
0
        public int CompositeImage(IntPtr pD3DDevice, IntPtr pddsRenderTarget, AMMediaType pmtRenderTarget, long rtStart, long rtEnd, int dwClrBkGnd, VMR9VideoStreamInfo[] pVideoStreamInfo, int cStreams)
        {
            try
            {
                // Just in case the filter call CompositeImage before InitCompositionDevice (this sometime occure)
                if (unmanagedDevice != pD3DDevice)
                {
                    SetManagedDevice(pD3DDevice);
                }

                // Create a managed Direct3D surface (the Render Target) from the unmanaged pointer.
                // The constructor don't call IUnknown.AddRef but the "destructor" seem to call IUnknown.Release
                // Direct3D seem to be happier with that according to the DirectX log
                Marshal.AddRef(pddsRenderTarget);
                Surface            renderTarget     = Surface.FromPointer(pddsRenderTarget);
                SurfaceDescription renderTargetDesc = renderTarget.Description;
                Rectangle          renderTargetRect = new Rectangle(0, 0, renderTargetDesc.Width, renderTargetDesc.Height);

                // Same thing for the first video surface
                // WARNING : This Compositor sample only use the video provided to the first pin.
                Marshal.AddRef(pVideoStreamInfo[0].pddsVideoSurface);
                Surface            surface     = Surface.FromPointer(pVideoStreamInfo[0].pddsVideoSurface);
                SurfaceDescription surfaceDesc = surface.Description;
                Rectangle          surfaceRect = new Rectangle(0, 0, surfaceDesc.Width, surfaceDesc.Height);


                // Set the device's render target (this doesn't seem to be needed)
                device.SetRenderTarget(0, renderTarget);

                // Copy the whole video surface into the render target
                // it's a de facto surface cleaning...
                device.StretchRectangle(surface, surfaceRect, renderTarget, renderTargetRect, TextureFilter.None);

                // sprite's methods need to be called between device.BeginScene and device.EndScene
                device.BeginScene();

                // Init the sprite engine for AlphaBlending operations
                sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.DoNotSaveState);

                //mouse
                if (_mouseTrack != null)
                {
                    if (_mouseTrack.Count > 1)
                    {
                        if (_mouseTrackDraw)
                        {
                            _d3dMouseTrackLine.Width = _mouseTrackLineWidth;
                            _d3dMouseTrackLine.Begin();
                            _d3dMouseTrackLine.Draw(_mouseTrack.ToArray(), _mouseTrackColor);
                            _d3dMouseTrackLine.End();
                        }
                    }
                    if (_mouseTrack.Count > 0)
                    {
                        if (_mouseCursorCircleDraw)
                        {
                            _d3dMouseCursorCircleLine.Width = _mouseCursorCircleLineWidth;
                            _d3dMouseCursorCircleLine.Begin();
                            _d3dMouseCursorCircleLine.Draw(InitCircle(100, _mouseTrack[_mouseTrack.Count - 1], 50), _mouseCursorCircleColor);
                            _d3dMouseCursorCircleLine.End();
                        }

                        if (_mouseCursorDraw)
                        {
                            Vector3 cursorPos = new Vector3(_mouseTrack[_mouseTrack.Count - 1], 0.5f);
                            sprite.Draw(_mouseCursorTex, Vector3.Zero, cursorPos, Color.White);
                        }
                    }
                }
                if (_mouseFixationDraw && _mouseFixation != null)
                {
                    if (_mouseFixation.Count > 0)
                    {
                        List <Vector2> scanpath = new List <Vector2>();
                        for (int i = 0; i < _mouseFixation.Count; i++)
                        {
                            //Fixation
                            _d3dMouseFixationLine.Width = _mouseFixationLineWidth;
                            _d3dMouseFixationLine.Begin();
                            _d3dMouseFixationLine.Draw(InitCircle(100, _mouseFixation[i].fixation, _mouseFixation[i].fsize), _mouseFixationColor);
                            _d3dMouseFixationLine.End();

                            //ScanPath
                            scanpath.Add(_mouseFixation[i].fixation);
                            if (i >= 1 && _mouseScanpathDraw)
                            {
                                _d3dMouseScanpathLine.Width = _mouseScanpathLineWidth;
                                _d3dMouseScanpathLine.Begin();
                                _d3dMouseScanpathLine.Draw(scanpath.ToArray(), _mouseScanpathColor);
                                _d3dMouseScanpathLine.End();
                            }

                            //Fixation ID
                            if (_mouseFixationIDDraw)
                            {
                                _d3dMouseFixtionFont.DrawString(sprite, (i + 1).ToString(), new Rectangle(new Point((int)_mouseFixation[i].fixation.X, (int)_mouseFixation[i].fixation.Y), new Size(50, 50)), 0, _mouseFixationIDColor);
                            }
                        }
                    }
                }
                //gaze
                if (_gazeTrack != null)
                {
                    if (_gazeTrack.Count > 1)
                    {
                        if (_gazeTrackDraw)
                        {
                            _d3dGazeTrackLine.Width = _gazeTrackLineWidth;
                            _d3dGazeTrackLine.Begin();
                            _d3dGazeTrackLine.Draw(_gazeTrack.ToArray(), _gazeTrackColor);
                            _d3dGazeTrackLine.End();
                        }
                    }
                    if (_gazeTrack.Count > 0)
                    {
                        if (_gazeCursorCircleDraw)
                        {
                            _d3dGazeCursorCircleLine.Width = _gazeCursorCircleLineWidth;
                            _d3dGazeCursorCircleLine.Begin();
                            _d3dGazeCursorCircleLine.Draw(InitCircle(100, _gazeTrack[_gazeTrack.Count - 1], 50), _gazeCursorCircleColor);
                            _d3dGazeCursorCircleLine.End();
                        }

                        if (_gazeCursorDraw)
                        {
                            Vector3 cursorPos = new Vector3(_gazeTrack[_gazeTrack.Count - 1], 0.5f);
                            sprite.Draw(_gazeCursorTex, Vector3.Zero, cursorPos, Color.White);
                        }
                    }
                }
                if (_gazeFixationDraw && _gazeFixation != null)
                {
                    if (_gazeFixation.Count > 0)
                    {
                        List <Vector2> scanpath = new List <Vector2>();
                        for (int i = 0; i < _gazeFixation.Count; i++)
                        {
                            //Fixation
                            _d3dGazeFixationLine.Width = _gazeFixationLineWidth;
                            _d3dGazeFixationLine.Begin();
                            _d3dGazeFixationLine.Draw(InitCircle(100, _gazeFixation[i].fixation, _gazeFixation[i].fsize), _gazeFixationColor);
                            _d3dGazeFixationLine.End();

                            //ScanPath
                            scanpath.Add(_gazeFixation[i].fixation);
                            if (i >= 1 && _gazeScanpathDraw)
                            {
                                _d3dGazeScanpathLine.Width = _gazeScanpathLineWidth;
                                _d3dGazeScanpathLine.Begin();
                                _d3dGazeScanpathLine.Draw(scanpath.ToArray(), _gazeScanpathColor);
                                _d3dGazeScanpathLine.End();
                            }
                            //Fixation ID
                            if (_gazeFixationIDDraw)
                            {
                                _d3dGazeFixtionFont.DrawString(sprite, (i + 1).ToString(), new Rectangle(new Point((int)_gazeFixation[i].fixation.X, (int)_gazeFixation[i].fixation.Y), new Size(50, 50)), 0, _gazeFixationIDColor);
                            }
                        }
                    }
                }


                // End the spite engine (drawings take place here)
                sprite.Flush();
                sprite.End();


                // End the sceen.
                device.EndScene();

                // No Present requiered because the rendering is on a render target...
                // device.Present();

                // Dispose the managed surface
                surface.Dispose();
                surface = null;

                // and the managed render target
                renderTarget.Dispose();
                renderTarget = null;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }

            // return a success to the filter
            return(0);
        }
Exemplo n.º 3
0
        void Render(GameTime RenderTime)
        {
            lock (queue)
            {
                if (queue.Count > 0)
                {
                    render = queue.Dequeue();
                }
            }

            spriteRenderer.Begin(SpriteFlags.SortTexture | SpriteFlags.SortDepthFrontToBack | SpriteFlags.AlphaBlend);

            //if (engine.UseTextureFilter)
            //{
            //    device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Anisotropic);
            //    device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Anisotropic);
            //    device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Anisotropic);
            //}
            //else
            {
                device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Point);
                device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Point);
                device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Point);
            }

            // TODO engine scale
            spriteRenderer.Transform = SlimDX.Matrix.Scaling(new SlimDX.Vector3(renderScale, renderScale, 1));

            SlimDX.Matrix lineMatrix = SlimDX.Matrix.AffineTransformation2D(1, new SlimDX.Vector2(), 0, new SlimDX.Vector2());
            // TODO engine scale
            //lineMatrix = SlimDX.Matrix.Transformation2D(new SlimDX.Vector2(), 0, new SlimDX.Vector2(engine.Scale.x, engine.Scale.y), new SlimDX.Vector2(), 0, new SlimDX.Vector2());
            lineMatrix = SlimDX.Matrix.Transformation2D(new SlimDX.Vector2(), 0, new SlimDX.Vector2(renderScale, renderScale), new SlimDX.Vector2(), 0, new SlimDX.Vector2());
            lineMatrix = spriteRenderer.Transform;
            lineRenderer.Begin();

            // application render
            engine.MainTarget.elapsed = RenderTime.Elapsed;

            float currentFactor = 1;

            if (render != null)
            {
                foreach (RenderEntity entity in render)
                {
                    if (entity is SpriteEntity)
                    {
                        SpriteEntity sprite = entity as SpriteEntity;
                        // diposed texture links may remain in queue after direct3d reset, just skip them
                        if (sprite.Texture.Disposed)
                        {
                            continue;
                        }

                        // if sprite resolution changed, then update transform matrix
                        if (currentFactor != sprite.Factor)
                        {
                            currentFactor = sprite.Factor;
                            // TODO engine scale
                            //spriteRenderer.Transform = SlimDX.Matrix.Scaling(new SlimDX.Vector3(engine.Scale.x * sprite.Factor, engine.Scale.y * sprite.Factor, 1));
                            spriteRenderer.Transform = SlimDX.Matrix.Scaling(new SlimDX.Vector3(renderScale * sprite.Factor, renderScale * sprite.Factor, 1));
                        }

                        // recompute position for not 1:1 sprite resolutions
                        SlimDX.Vector3 pos = sprite.Position;
                        if (currentFactor != 1)
                        {
                            pos.X /= currentFactor;
                            pos.Y /= currentFactor;
                        }

                        spriteRenderer.Draw(sprite.Texture, sprite.Rectangle, new SlimDX.Vector3(0, 0, 0), pos, sprite.Color);
                    }
                    else if (entity is LineEntity)
                    {
                        LineEntity       line = entity as LineEntity;
                        SlimDX.Vector3[] vec  = new SlimDX.Vector3[] { line.Start, line.End };
                        SlimDX.Vector4[] v    = SlimDX.Vector3.Transform(vec, ref lineMatrix);

                        SlimDX.Vector2[] vec2 = new SlimDX.Vector2[] { new SlimDX.Vector2(v[0].X, v[0].Y), new SlimDX.Vector2(v[1].X, v[1].Y) };
                        lineRenderer.Draw(vec2, line.Color);
                    }
                }
            }

            lineRenderer.End();

            blendOverlay.BlockFadeOut = engine.IsLoading || blockBlend;
            blendOverlay.Render(RenderTime, spriteRenderer);
            if (engine.MusicBlend)
            {
                engine.Music.Volume = 1 - BlendState;
            }
            else
            {
                engine.Music.Volume = 1;
            }

            spriteRenderer.End();

            errorOverlay.Render(RenderTime, spriteRenderer);

            loadingOverlay.Render(RenderTime, spriteRenderer);
        }