예제 #1
0
파일: SkiaView.cs 프로젝트: j123123/Perspex
 public void SurfaceCreated(ISurfaceHolder holder)
 {
     Log.Info("PERSPEX", "Surface Created");
     _renderTarget =
         PerspexLocator.Current.GetService<IPlatformRenderInterface>()
             .CreateRenderer(new PlatformHandle(holder.Surface.Handle, "Surface"));
     Draw();
 }
예제 #2
0
        public override void Apply(IRenderTarget renderTarget)
        {
            GL.Viewport(Position.X, Position.Y, Size.Width, Size.Height);

            #if DEBUG
            Video.checkForError();
            #endif
        }
예제 #3
0
 public RenderTargetDecorator(IRenderTarget target, ITopLevelImpl window)
 {
     _target = target;
     var dec = window as WindowDecorator;
     if (dec != null)
         window = dec.TopLevel;
     _window = window;
 }
예제 #4
0
 public MainView()
 {
     AutoresizingMask = UIViewAutoresizing.All;
     SkiaPlatform.Initialize();
     _target = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>()
         .CreateRenderer(AvaloniaPlatformHandle);
     UpdateText(0);
 }
예제 #5
0
 public RenderTargetCollection(XnaScrapId id, IRenderTarget[] targets)
 {
     m_id = id;
     for (int i = 0; i < 4; ++i)
     {
         if (i < targets.Length)
             Targets[i] = targets[i];
     }
 }
 /// <summary>
 /// Adds a render target to the control
 /// </summary>
 private void AddRenderTarget( IRenderTarget renderTarget )
 {
     ListViewItem item = new ListViewItem( renderTarget.Name );
     item.SubItems.Add( renderTarget.Width.ToString( ) );
     item.SubItems.Add( renderTarget.Height.ToString( ) );
     item.SubItems.Add( renderTarget.Texture == null ? "None" : renderTarget.Texture.Format.ToString( ) );
     item.Tag = renderTarget;
     renderTargetListView.Items.Add( item );
 }
        /// <summary>
        /// Setup constructor
        /// </summary>
        /// <param name="sceneObjects">Scene objects</param>
        public ReflectionScene( params IRenderable[] sceneObjects )
        {
            Arguments.CheckNotNullAndContainsNoNulls( sceneObjects, "sceneObjects" );
            m_SceneObjects = sceneObjects;
            m_Reflections = Graphics.Factory.CreateRenderTarget( );
            m_Reflections.Create( "Reflections", 512, 512, TextureFormat.R8G8B8A8, 24, 0, false );

            m_ReflectionMatrixDataSource = Graphics.EffectDataSources.CreateValueDataSourceForNamedParameter<InvariantMatrix44>( "ReflectionProjectionMatrix" );
        }
예제 #8
0
파일: DustSystem.cs 프로젝트: andi2/ld32-1
        public override void UpdateAndDraw(Particle particle, float deltaTime, IRenderTarget target)
        {
            particle.Speed += new Vector2(0f, 300f) * deltaTime;
            particle.Color = initialColor.Transition(endColor, particle.Age / particle.Life);
            var backColor = new Color(0, 0, 0, 255).Transition(new Color(0, 0, 0, 0), particle.Age / particle.Life);
            particle.Coordinate += particle.Speed * deltaTime;

            target.DrawTexture(Texture, particle.Coordinate - new Vector2(2f, 2f), backColor, particle.Scale + new Vector2(4f, 4f), Origin, particle.Rotation.Degree, new Rectangle(Vector2.Zero, Texture.Size));
            target.DrawTexture(Texture, particle.Coordinate, particle.Color, particle.Scale, Origin, particle.Rotation.Degree, new Rectangle(Vector2.Zero, Texture.Size));
        }
예제 #9
0
 public SealControl()
 {
     InitializeComponent();
     SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.UserPaint, true);
     engine = new Engine();
     target = engine.CreateRenderTarget(this, this.Width, this.Height);
     var gm = engine.CreateGeometryManager();
     p = new PathGeometry(gm.CreatePath("M 10,10 C 300,200 50,5 60,40 C 10,10 200,160 100,110"));
     brush = target.CreateSolidColorBrush(Seal.Colors.DarkGoldenrod);
 }
 /// <summary>
 /// Removes a render target from the control
 /// </summary>
 private void RemoveRenderTarget( IRenderTarget renderTarget )
 {
     foreach ( ListViewItem item in renderTargetListView.Items )
     {
         if ( item.Tag == renderTarget )
         {
             renderTargetListView.Items.Remove( item );
             return;
         }
     }
 }
 /// <summary>
 /// Removes a created render target from the created render target list
 /// </summary>
 /// <param name="renderTarget"></param>
 public static void RemoveCreatedRenderTarget( IRenderTarget renderTarget )
 {
     Arguments.CheckNotNull( renderTarget, "renderTarget" );
     lock ( s_RenderTargets )
     {
         s_RenderTargets.Remove( renderTarget );
     }
     if ( RenderTargetRemoved != null )
     {
         RenderTargetRemoved( renderTarget );
     }
 }
예제 #12
0
 public MacWindowInfo(IRenderTarget target)
     : base(typeof (MacCefWindowInfo))
 {
     Handle = Marshal.AllocHGlobal(NativeSize);
     MarshalToNative(new MacCefWindowInfo {
         ParentView = target.Handle,
         X = 0,
         Y = 0,
         Width = target.Size.Width,
         Height = target.Size.Height
     });
     _isOwned = true;
 }
예제 #13
0
파일: MenuElement.cs 프로젝트: andi2/ld32-1
        public override void OnDraw(IRenderTarget target, Vector2 drawPosition)
        {
            drawPosition.X += Size.X / 2f;
            for (int i=0; i<Options.Count; i++)
            {
                if (new Rectangle(drawPosition - new Vector2(Sizes[i].X / 2f, 0f), Sizes[i]).Contains(Mouse.Location))
                    Font.DrawString(target, "<" + Options[i] + ">", Font.RenderSize, Program.Background * Opacity, drawPosition, HAlign.Center, VAlign.Top);
                else
                    Font.DrawString(target, Options[i], Font.RenderSize, Program.Background * Opacity, drawPosition, HAlign.Center, VAlign.Top);
                drawPosition.Y += Font.RenderLineHeight * 1.5f;
            }

            base.OnDraw(target, drawPosition);
        }
예제 #14
0
        private bool RenderToRenderTarget(IRenderTarget target, IList<IRenderable> renderables, IList<ISprite> sprites, bool doPresent, Camera camera, Light light)
        {
            this.device.SetRenderTarget(target);

            if (target.ClearBackGround)
                this.device.RawDevice.Clear(target.ClearOptions, target.ClearColor.ToArgb(), 1.0f, 0);

            Result result = this.device.RawDevice.BeginScene();
            if (result.IsFailure)
            {
                Log.Msg(TraceLevel.Error, this, "BeginScene failed, " + result.ToString());
                return false;
            }

            try
            {
                if (renderables != null && renderables.Count > 0)
                {
                    foreach (var renderable in renderables)
                    {
                        renderable.Render(camera, light);
                    }
                }

                if (sprites != null && sprites.Count > 0)
                {
                    this.spriteRenderer.RawSprite.Begin(SpriteFlags.AlphaBlend);
                    foreach (var sprite in sprites)
                    {
                        sprite.Render(this.spriteRenderer);
                    }
                    this.spriteRenderer.RawSprite.End();
                }
            }
            finally
            {
                this.device.RawDevice.EndScene();
            }

            if (doPresent)
                this.device.RawDevice.Present();

            target.OnRender();

            return true;
        }
예제 #15
0
 public WindowsWindowInfo(IRenderTarget target)
     : base(typeof (WindowsCefWindowInfo))
 {
     Handle = Marshal.AllocHGlobal(NativeSize);
     MarshalToNative(new WindowsCefWindowInfo {
         ParentWindow = target.Handle,
         Style = (uint) (WindowStyles.ChildWindow
                         | WindowStyles.ClipChildren
                         | WindowStyles.ClipSiblings
                         | WindowStyles.TabStop
                         | WindowStyles.Visible),
         X = 0,
         Y = 0,
         Width = target.Size.Width,
         Height = target.Size.Height
     });
     _isOwned = true;
 }
예제 #16
0
        public void Render(Rect rect)
        {
            if (_renderTarget == null)
            {
                _renderTarget = _root.CreateRenderTarget();
            }

            try
            {
                _renderTarget.Render(_root);
            }
            catch (RenderTargetCorruptedException ex)
            {
                Logging.Logger.Information("Renderer", this, "Render target was corrupted. Exception: {0}", ex);
                _renderTarget.Dispose();
                _renderTarget = null;
            }
            finally
            {
                _dirty = false;
            }
        }
예제 #17
0
        public bool Render(IRenderTarget renderTarget, IList<IRenderable> renderables, IList<ISprite> sprites, Camera camera, Light light, bool present)
        {
            if (camera == null || light == null)
                throw new ArgumentNullException("Argument camera or light is null");

            bool renderSuccess = false;
            try
            {
                // Save primary
                PrimaryRenderTarget.TargetSurface = this.device.RawDevice.GetRenderTarget(0);
                PrimaryRenderTarget.DepthStencilSurface = this.device.RawDevice.DepthStencilSurface;

                // Render this render target
                renderSuccess = RenderToRenderTarget(renderTarget, renderables, sprites, present, camera, light);
            }
            finally
            {
                // Restore primary
                this.device.SetRenderTarget(PrimaryRenderTarget);
            }

            return renderSuccess;
        }
예제 #18
0
        public Form1()
        {
            InitializeComponent();

            _render = new PlatformRenderInterface();
            PerspexLocator.CurrentMutable.Bind<IPlatformRenderInterface>().ToConstant(_render);
            _geometry =  new StreamGeometry();
            _rbitmap = new RenderTargetBitmap(50, 50);
            _renderTarget = _render.CreateRenderer(new PlatformHandle(Handle, "HWND"), ClientSize.Width,
                ClientSize.Height);
            var timer = new Timer() {Interval = 20};
            timer.Tick += delegate { Invalidate(); };
            timer.Start();
            components.Add(timer);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            using (var ctx = _geometry.Open())
            {
                ctx.BeginFigure(new Point(10,10), true);
                ctx.LineTo(new Point(40,25));
                ctx.BezierTo(new Point(50, 45), new Point(43, 48), new Point(20, 90));
                ctx.LineTo(new Point(10, 60));
                ctx.EndFigure(true);
            }

            _text =
                new FormattedText(
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
                    "Arial", 25, FontStyle.Normal, TextAlignment.Left, FontWeight.Normal);

            _text.Constraint = new Size(400, double.PositiveInfinity);

            using (var ctx = _rbitmap.CreateDrawingContext())
                ctx.DrawRectangle(new Pen(new SolidColorBrush(Colors.Aqua)), new Rect(10, 10, 30, 30), 5);

            _bitmap = new Bitmap(@"C:\Users\keks\Desktop\phoenix.png");
        }
예제 #19
0
파일: Viewport.cs 프로젝트: kaagati/spectre
        public Viewport(IRenderTarget target, BrowserDelegate browserDelegate)
        {
            _target = target;
            _target.TargetClosing += OnTargetClosing;
            _target.TargetClosed += OnTargetClosed;
            _target.TargetSizeChanged += OnTargetSizeChanged;

            _handler = new ClientHandler(browserDelegate);

            _settings = new BrowserSettings {
                IsFileAccessfromUrlsAllowed = false,
                IsWebSecurityDisabled = false,
                IsUniversalAccessFromFileUrlsAllowed = false,
                IsUserStyleSheetEnabled = false
            };

            if (Platform.IsLinux) {
                _resizer = new LinuxWindowResizer();
            }

            if (Platform.IsWindows) {
                _resizer = new WindowsWindowResizer();
            }
        }
예제 #20
0
        public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
        {
            // Checking for redundant SetRenderTargets...
            if (renderTargets == null && RenderTargetCount == 0)
            {
                return;
            }
            else if (renderTargets != null && renderTargets.Length == RenderTargetCount)
            {
                bool isRedundant = true;
                for (int i = 0; i < renderTargets.Length; i += 1)
                {
                    if (renderTargets[i].RenderTarget != renderTargetBindings[i].RenderTarget ||
                        renderTargets[i].CubeMapFace != renderTargetBindings[i].CubeMapFace)
                    {
                        isRedundant = false;
                    }
                }
                if (isRedundant)
                {
                    return;
                }
            }

            if (renderTargets == null || renderTargets.Length == 0)
            {
                GLDevice.SetRenderTargets(null, null, 0, DepthFormat.None);

                // Set the viewport to the size of the backbuffer.
                Viewport = new Viewport(0, 0, PresentationParameters.BackBufferWidth, PresentationParameters.BackBufferHeight);

                // Set the scissor rectangle to the size of the backbuffer.
                ScissorRectangle = new Rectangle(0, 0, PresentationParameters.BackBufferWidth, PresentationParameters.BackBufferHeight);

                if (PresentationParameters.RenderTargetUsage == RenderTargetUsage.DiscardContents)
                {
                    Clear(DiscardColor);
                }

                // Generate mipmaps for previous targets, if needed
                for (int i = 0; i < RenderTargetCount; i += 1)
                {
                    if (renderTargetBindings[i].RenderTarget.LevelCount > 1)
                    {
                        GLDevice.GenerateTargetMipmaps(
                            renderTargetBindings[i].RenderTarget.texture
                            );
                    }
                }
                Array.Clear(renderTargetBindings, 0, renderTargetBindings.Length);
                RenderTargetCount = 0;
            }
            else
            {
                uint[] glTarget = new uint[renderTargets.Length];
                OpenGLDevice.GLenum[] glTargetFace = new OpenGLDevice.GLenum[renderTargets.Length];
                for (int i = 0; i < renderTargets.Length; i += 1)
                {
                    glTarget[i] = renderTargets[i].RenderTarget.texture.Handle;
                    if (renderTargets[i].RenderTarget is RenderTarget2D)
                    {
                        glTargetFace[i] = OpenGLDevice.GLenum.GL_TEXTURE_2D;
                    }
                    else
                    {
                        glTargetFace[i] = OpenGLDevice.GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int)renderTargets[i].CubeMapFace;
                    }
                }
                IRenderTarget target = renderTargets[0].RenderTarget as IRenderTarget;
                GLDevice.SetRenderTargets(
                    glTarget,
                    glTargetFace,
                    target.DepthStencilBuffer,
                    target.DepthStencilFormat
                    );

                // Generate mipmaps for previous targets, if needed
                for (int i = 0; i < RenderTargetCount; i += 1)
                {
                    if (renderTargetBindings[i].RenderTarget.LevelCount > 1)
                    {
                        // We only need to gen mipmaps if the target is no longer bound.
                        bool stillBound = false;
                        for (int j = 0; j < renderTargets.Length; j += 1)
                        {
                            if (renderTargetBindings[i].RenderTarget == renderTargets[j].RenderTarget)
                            {
                                stillBound = true;
                                break;
                            }
                        }
                        if (!stillBound)
                        {
                            GLDevice.GenerateTargetMipmaps(
                                renderTargetBindings[i].RenderTarget.texture
                                );
                        }
                    }
                }
                Array.Clear(renderTargetBindings, 0, renderTargetBindings.Length);
                Array.Copy(renderTargets, renderTargetBindings, renderTargets.Length);
                RenderTargetCount = renderTargets.Length;

                // Set the viewport to the size of the first render target.
                Viewport = new Viewport(0, 0, target.Width, target.Height);

                // Set the scissor rectangle to the size of the first render target.
                ScissorRectangle = new Rectangle(0, 0, target.Width, target.Height);

                if (target.RenderTargetUsage == RenderTargetUsage.DiscardContents)
                {
                    Clear(DiscardColor);
                }
            }
        }
예제 #21
0
 public DefaultResourceSet(IRenderTarget renderTarget)
 {
     RenderTarget = renderTarget;
 }
예제 #22
0
        internal void PlatformCreateRenderTarget(IRenderTarget renderTarget, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
        {
            var color   = 0;
            var depth   = 0;
            var stencil = 0;

            if (preferredMultiSampleCount > 0 && this.framebufferHelper.SupportsBlitFramebuffer)
            {
                this.framebufferHelper.GenRenderbuffer(out color);
                this.framebufferHelper.BindRenderbuffer(color);
#if GLES
                this.framebufferHelper.RenderbufferStorageMultisample(preferredMultiSampleCount, (int)RenderbufferStorage.Rgba8Oes, width, height);
#else
                this.framebufferHelper.RenderbufferStorageMultisample(preferredMultiSampleCount, (int)RenderbufferStorage.Rgba8, width, height);
#endif
            }

            if (preferredDepthFormat != DepthFormat.None)
            {
                var depthInternalFormat   = RenderbufferStorage.DepthComponent16;
                var stencilInternalFormat = (RenderbufferStorage)0;
                switch (preferredDepthFormat)
                {
                case DepthFormat.Depth16:
                    depthInternalFormat = RenderbufferStorage.DepthComponent16; break;

#if GLES
                case DepthFormat.Depth24:
                    if (GraphicsCapabilities.SupportsDepth24)
                    {
                        depthInternalFormat = RenderbufferStorage.DepthComponent24Oes;
                    }
                    else if (GraphicsCapabilities.SupportsDepthNonLinear)
                    {
                        depthInternalFormat = (RenderbufferStorage)0x8E2C;
                    }
                    else
                    {
                        depthInternalFormat = RenderbufferStorage.DepthComponent16;
                    }
                    break;

                case DepthFormat.Depth24Stencil8:
                    if (GraphicsCapabilities.SupportsPackedDepthStencil)
                    {
                        depthInternalFormat = RenderbufferStorage.Depth24Stencil8Oes;
                    }
                    else
                    {
                        if (GraphicsCapabilities.SupportsDepth24)
                        {
                            depthInternalFormat = RenderbufferStorage.DepthComponent24Oes;
                        }
                        else if (GraphicsCapabilities.SupportsDepthNonLinear)
                        {
                            depthInternalFormat = (RenderbufferStorage)0x8E2C;
                        }
                        else
                        {
                            depthInternalFormat = RenderbufferStorage.DepthComponent16;
                        }
                        stencilInternalFormat = RenderbufferStorage.StencilIndex8;
                        break;
                    }
                    break;
#else
                case DepthFormat.Depth24: depthInternalFormat = RenderbufferStorage.DepthComponent24; break;

                case DepthFormat.Depth24Stencil8: depthInternalFormat = RenderbufferStorage.Depth24Stencil8; break;
#endif
                }

                if (depthInternalFormat != 0)
                {
                    this.framebufferHelper.GenRenderbuffer(out depth);
                    this.framebufferHelper.BindRenderbuffer(depth);
                    this.framebufferHelper.RenderbufferStorageMultisample(preferredMultiSampleCount, (int)depthInternalFormat, width, height);
                    if (preferredDepthFormat == DepthFormat.Depth24Stencil8)
                    {
                        stencil = depth;
                        if (stencilInternalFormat != 0)
                        {
                            this.framebufferHelper.GenRenderbuffer(out stencil);
                            this.framebufferHelper.BindRenderbuffer(stencil);
                            this.framebufferHelper.RenderbufferStorageMultisample(preferredMultiSampleCount, (int)stencilInternalFormat, width, height);
                        }
                    }
                }
            }

            if (color != 0)
            {
                renderTarget.GLColorBuffer = color;
            }
            else
            {
                renderTarget.GLColorBuffer = renderTarget.GLTexture;
            }
            renderTarget.GLDepthBuffer   = depth;
            renderTarget.GLStencilBuffer = stencil;
        }
예제 #23
0
파일: TextBox.cs 프로젝트: pzaps/CrossGFX
        public override void DrawOver(IRenderTarget renderTarget)
        {
            if (this.HasFocus && this.caretVisible) {
                Point pA = GetCharacterPosition(cursorPos);

                Rectangle caretRectangle = new Rectangle(pA.X + base.textPosition.X, base.textPosition.Y - 2, 1, this.Value.TextSize + 4);
                renderTarget.Fill(caretRectangle,
                    ((selectionEnd - selectionStart > 0) ? this.Value.Color.Invert() : this.Value.Color));
            }
        }
예제 #24
0
 public BrowserWrapper(string address = "", BrowserSettings browserSettings = null,
                       RequestContext requestContext = null, bool automaticallyCreateBrowser = true, IRenderTarget target = null) :
     base(address, browserSettings, requestContext, automaticallyCreateBrowser)
 {
     this.target = target;
 }
예제 #25
0
 public static void Render([NotNull] this Document @this, [CanBeNull] IRenderTarget target = null, Rect?renderRect = null) =>
 ConsoleRenderer.RenderDocument(@this, target, renderRect);
예제 #26
0
 public static void setAdditionalRenderTarget(int index, IRenderTarget _target)
 {
     renderTargetArray[index] = _target;
 }
 public static IRenderTarget CreateRef(this IRenderTarget objectRef) =>
 ((IRenderTarget)objectRef.CreateRef(typeof(IRenderTarget)));
예제 #28
0
 GraphicsDevice IGraphicsDriver.CreateGraphicsDevice(SurfaceSettings settings, IRenderTarget renderTarget) => throw this;
예제 #29
0
 protected override void OnDraw(IRenderTarget target, in RenderStates states)
예제 #30
0
 public unsafe static IBitmap CreateBitmap(this IRenderTarget renderTarget, Size size, in BitmapProperties properties)
예제 #31
0
 public void Draw(IRenderTarget target, RenderStates states)
 {
     SFMLShape.Draw(target.SFMLTarget, states.SFMLRenderStates);
 }
예제 #32
0
        /// <summary>
        /// Рисует залитый треугольник горизонтальными линиями.
        /// </summary>
        private void DrawTriangle(
            IRenderTarget renderTarget,
            int ax, int ay, int az,
            int bx, int by, int bz,
            int cx, int cy, int cz,
            Color color)
        {
            if (ay > cy)
            {
                Utils.Exchange(ref ay, ref cy);
                Utils.Exchange(ref ax, ref cx);
                Utils.Exchange(ref az, ref cz);
            }

            if (ay > by)
            {
                Utils.Exchange(ref ay, ref by);
                Utils.Exchange(ref ax, ref bx);
                Utils.Exchange(ref az, ref bz);
            }

            if (cy < by)
            {
                Utils.Exchange(ref cy, ref by);
                Utils.Exchange(ref cx, ref bx);
                Utils.Exchange(ref cz, ref bz);
            }

            Func <float, float, float> plan = CreatePlan(
                ax, ay, az,
                bx, by, bz,
                cx, cy, cz);

            float cxaxcyay = (cx - ax) / (float)(cy - ay);
            float bxaxbyay = (bx - ax) / (float)(by - ay);
            float cxbxcyby = (cx - bx) / (float)(cy - by);

            for (int y = ay; y < cy; ++y)
            {
                var x1 = (int)(ax + (y - ay) * cxaxcyay);
                int x2;

                if (y < by)
                {
                    x2 = (int)(ax + (y - ay) * bxaxbyay);
                }
                else
                {
                    if (cy == by)
                    {
                        x2 = bx;
                    }
                    else
                    {
                        x2 = (int)(bx + (y - by) * cxbxcyby);
                    }
                }

                if (x1 > x2)
                {
                    Utils.Exchange(ref x1, ref x2);
                }

                DrawHorizontalLine(renderTarget, y, x1, x2, color, plan);
            }
        }
예제 #33
0
 public void setRenderTarget(IRenderTarget target)
 {
     if (target is RenderTarget2D)
         GraphicsDevice.SetRenderTarget(target as RenderTarget2D);
     else if (target is RenderTargetCollection)
         setRenderTargets(target as RenderTargetCollection);
     else if (target == null)
         GraphicsDevice.SetRenderTarget(null);
 }
예제 #34
0
 /// <summary>
 /// resets the Current Render Target back to the screen
 /// </summary>
 public static void ResetRenderTarget()
 {
     CurrentRenderTarget = null; //sets it back to the screen
 }
예제 #35
0
 public abstract void UpdateAndDraw(Particle particle, float deltaTime, IRenderTarget target);
예제 #36
0
 /// <summary>
 ///		Resets the rendering state of the DX9Device to default 2D.
 /// </summary>
 private void ResetState(IRenderTarget target)
 {
 }
예제 #37
0
        private void GL_popState()
        {
            // End the effect, restoring the previous shader state
            FNA3D.FNA3D_EndPassRestore(
                currentDevice.GLDevice,
                shaderProgram.glEffect
                );

            // Restore GL state
            currentDevice.BlendState        = prevBlend;
            currentDevice.DepthStencilState = prevDepthStencil;
            currentDevice.RasterizerState   = prevRasterizer;
            prevBlend        = null;
            prevDepthStencil = null;
            prevRasterizer   = null;

            /* Restore targets using GLDevice directly.
             * This prevents accidental clearing of previously bound targets.
             */
            if (oldTargets == null || oldTargets.Length == 0)
            {
                FNA3D.FNA3D_SetRenderTargets(
                    currentDevice.GLDevice,
                    IntPtr.Zero,
                    0,
                    IntPtr.Zero,
                    DepthFormat.None,
                    0
                    );
            }
            else
            {
                IRenderTarget oldTarget = oldTargets[0].RenderTarget as IRenderTarget;

                unsafe
                {
                    fixed(FNA3D.FNA3D_RenderTargetBinding *rt = &nativeOldTargets[0])
                    {
                        GraphicsDevice.PrepareRenderTargetBindings(
                            rt,
                            oldTargets
                            );
                        FNA3D.FNA3D_SetRenderTargets(
                            currentDevice.GLDevice,
                            rt,
                            oldTargets.Length,
                            oldTarget.DepthStencilBuffer,
                            oldTarget.DepthStencilFormat,
                            (byte)(oldTarget.RenderTargetUsage != RenderTargetUsage.DiscardContents ? 1 : 0)                              /* lol c# */
                            );
                    }
                }
            }
            oldTargets = null;

            // Set viewport AFTER setting targets!
            FNA3D.FNA3D_SetViewport(
                currentDevice.GLDevice,
                ref prevViewport.viewport
                );

            // Restore buffers
            currentDevice.SetVertexBuffers(oldBuffers);
            oldBuffers = null;

            // Restore samplers
            for (int i = 0; i < 3; i += 1)
            {
                /* The application may have set a texture ages
                 * ago, only to not unset after disposing. We
                 * have to avoid an ObjectDisposedException!
                 */
                if (oldTextures[i] == null || !oldTextures[i].IsDisposed)
                {
                    currentDevice.Textures[i] = oldTextures[i];
                }
                currentDevice.SamplerStates[i] = oldSamplers[i];
                oldTextures[i] = null;
                oldSamplers[i] = null;
            }
        }
예제 #38
0
파일: Gws.cs 프로젝트: MnMInfoTech/GWS
 protected override IBaseView newView(IRenderTarget window, bool isMultiWindow = false) =>
 new View(window, isMultiWindow);
예제 #39
0
 public override void Apply(IRenderTarget renderTarget)
 {
     com.Apply(Position.X, renderTarget.Size.Height - Size.Height - Position.Y, Size.Width, Size.Height);
 }
        /// <summary>
        ///		Attachs the given render target to this driver and detachs the old one.
        /// </summary>
        /// <param name="target">Render target to attach.</param>
        public void SetRenderTarget(IRenderTarget target)
        {
            if (target == _renderTarget || target == null) return;
            if (_renderTarget != null) _renderTarget.Detach();

            ResetState(target);
            _renderTarget = target;
            if (target.Attach() != true)
                throw new Exception("An error occured while attempting to attach the graphics driver to a render target.");
        }
예제 #41
0
 public void DrawOver(IRenderTarget target, in RenderStates states)
 /// <summary>
 /// Setup constructor
 /// </summary>
 /// <param name="innerContext">Inner rendering context</param>
 /// <param name="reflectionsRenderTarget">Render target that the reflected scene is rendered to</param>
 public ReflectionsRenderContext( IRenderContext innerContext, IRenderTarget reflectionsRenderTarget )
     : base(innerContext)
 {
     Arguments.CheckNotNull( reflectionsRenderTarget, "reflectionsRenderTarget" );
     m_ReflectionsRenderTarget = reflectionsRenderTarget;
 }
예제 #43
0
 public static RenderTexture ToSFML(this IRenderTarget self)
 {
     return(((CrystalCanvas)self).RenderTexture);
 }
예제 #44
0
 public SkiaRenderView(Activity context) : base(context)
 {
     _renderTarget =
         PerspexLocator.Current.GetService<IPlatformRenderInterface>()
             .CreateRenderer(this);
 }
        /// <summary>
        ///		Resets the rendering state of the DX9Device to default 2D.
        /// </summary>
        private void ResetState(IRenderTarget target)
        {
            if (_renderMode == RenderMode.Dimensions3)
            {
                // Setup default rendering state.
                _dx9Device.RenderState.AlphaTestEnable = true;
                _dx9Device.RenderState.ReferenceAlpha = 0;
                _dx9Device.RenderState.AlphaFunction = Compare.Greater;
                _dx9Device.RenderState.CullMode = Cull.Clockwise;
                _dx9Device.RenderState.ShadeMode = ShadeMode.Gouraud;
                _dx9Device.RenderState.Lighting = false;
                _dx9Device.RenderState.ScissorTestEnable = true;
                _dx9Device.RenderState.ZBufferEnable = true;
                _dx9Device.RenderState.ZBufferFunction = Compare.LessEqual;
                _zBufferEnabled = true;

                // Setup default tecture stages
                _dx9Device.SetTextureStageState(0, TextureStageStates.AlphaOperation, (int)TextureOperation.Modulate);
                _dx9Device.SetTextureStageState(0, TextureStageStates.AlphaArgument1, (int)TextureArgument.TextureColor);
                _dx9Device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate);
                _dx9Device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                _dx9Device.SetTextureStageState(0, TextureStageStates.ColorArgument2, (int)TextureArgument.Diffuse);
                _dx9Device.SamplerState[0].MinFilter = TextureFilter.Point;
                _dx9Device.SamplerState[0].MagFilter = TextureFilter.Point;
                _dx9Device.SamplerState[0].MipFilter = TextureFilter.Point;

                // Setup vertexs and key colors.
                _dx9Device.VertexFormat = CustomVertex.PositionColoredTextured.Format;

                // Setup projection and view matrix's
                _dx9Device.Transform.Projection = Matrix.PerspectiveLH(target.Width, target.Height, -1000.0f, 1000.0f);
                _dx9Device.Transform.World = Matrix.Identity;
                _dx9Device.Transform.View = Matrix.Identity;

                ((IGraphicsDriver)this).BlendMode = BlendMode.Alpha;
            }
            else
            {
                // Setup default rendering state.
                _dx9Device.RenderState.AlphaTestEnable = true;
                _dx9Device.RenderState.ReferenceAlpha = 0;
                _dx9Device.RenderState.AlphaFunction = Compare.Greater;
                _dx9Device.RenderState.CullMode = Cull.None;
                _dx9Device.RenderState.ShadeMode = ShadeMode.Flat;
                _dx9Device.RenderState.Lighting = false;
                _dx9Device.RenderState.ScissorTestEnable = true;
                _dx9Device.RenderState.ZBufferEnable = true;
                _dx9Device.RenderState.ZBufferFunction = Compare.LessEqual;
                _zBufferEnabled = true;

                // Setup default tecture stages
                _dx9Device.SetTextureStageState(0, TextureStageStates.AlphaOperation, (int)TextureOperation.Modulate);
                _dx9Device.SetTextureStageState(0, TextureStageStates.AlphaArgument1, (int)TextureArgument.TextureColor);
                _dx9Device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate);
                _dx9Device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);
                _dx9Device.SetTextureStageState(0, TextureStageStates.ColorArgument2, (int)TextureArgument.Diffuse);
                _dx9Device.SamplerState[0].MinFilter = TextureFilter.Point;
                _dx9Device.SamplerState[0].MagFilter = TextureFilter.Point;
                _dx9Device.SamplerState[0].MipFilter = TextureFilter.Point;

                // Setup vertexs and key colors.
                _dx9Device.VertexFormat = CustomVertex.PositionColoredTextured.Format;

                // Setup projection and view matrix's
                float width = target.Width;
                float height = target.Height;
                float zFar = 10000.0f;
                float zNear = -10000.0f;

                Matrix projectionMatrix = new Matrix();
                projectionMatrix.M11 = 2.0f / width;
                projectionMatrix.M12 = 0.0f;
                projectionMatrix.M13 = 0.0f;
                projectionMatrix.M14 = 0.0f;

                projectionMatrix.M21 = 0.0f;
                projectionMatrix.M22 = -2.0f / height;
                projectionMatrix.M23 = 0.0f;
                projectionMatrix.M24 = 0.0f;

                projectionMatrix.M31 = 0.0f;
                projectionMatrix.M32 = 0.0f;
                projectionMatrix.M33 = 1.0f / (zFar - zNear);
                projectionMatrix.M34 = 0.0f;

                projectionMatrix.M41 = -1 - (1.0f / width);
                projectionMatrix.M42 = 1 + (1.0f / height);
                projectionMatrix.M43 = -zNear / (zFar - zNear);
                projectionMatrix.M44 = 1.0f;

                _dx9Device.Transform.Projection = projectionMatrix;
                _dx9Device.Transform.World = Matrix.Identity;
                _dx9Device.Transform.View = Matrix.Identity;

                ((IGraphicsDriver)this).BlendMode = BlendMode.Alpha;
            }
        }
예제 #46
0
 public void CopyFromRenderTarget(PointInt32?destPoint, IRenderTarget renderTarget, RectInt32?srcRect)
 {
     base.innerRefT.CopyFromRenderTarget(destPoint, renderTarget, srcRect);
 }
예제 #47
0
 public void PushRenderTarget(IRenderTarget renderTarget)
 {
     m_currentRenderTarget.Push(renderTarget);
     m_renderManager.setRenderTarget(renderTarget);
 }
예제 #48
0
 public RenderTargetEventArgs(IRenderTarget renderTarget)
 {
     RenderTarget = renderTarget;
 }
 /// <summary>
 ///		Resets the rendering state of the DX9Device to default 2D.
 /// </summary>
 private void ResetState(IRenderTarget target)
 {
 }
예제 #50
0
        public static Bitmap RenderString(string str, StringRenderStyle style)
        {
            // Return null for bad strings
            if (string.IsNullOrWhiteSpace(str))
            {
                return(null);
            }

            string path; int charHeight, spaceWidth;

            switch (style)
            {
            case StringRenderStyle.BattleName: path = "BattleName"; charHeight = 11; spaceWidth = 2; break;

            case StringRenderStyle.BattleLevel: path = "BattleLevel"; charHeight = 10; spaceWidth = 7; break;

            case StringRenderStyle.BattleHP: path = "BattleHP"; charHeight = 8; spaceWidth = 0; break;

            default: path = "Default"; charHeight = 15; spaceWidth = 4; break;
            }

            int index;

            string GetCharKey()
            {
                string key = $"FONT_{path}_";

                if (index + 6 <= str.Length && str.Substring(index, 6) == "[PKMN]")
                {
                    key   += "PKMN";
                    index += 6;
                }
                else if (index + 4 <= str.Length && str.Substring(index, 4) == "[LV]")
                {
                    key   += "LV";
                    index += 4;
                }
                else
                {
                    key += ((int)str[index]).ToString("X");
                    index++;
                }
                const string questionMark = "FONT_Default_3F";

                return(DoesResourceExist($"Kermalis.PokemonBattleEngineClient.FONT.{path}.{key}.png") ? key : questionMark);
            }

            // Measure how large the string will end up
            int stringWidth = 0, stringHeight = charHeight, curLineWidth = 0;

            index = 0;
            while (index < str.Length)
            {
                if (str[index] == ' ')
                {
                    index++;
                    curLineWidth += spaceWidth;
                }
                else if (str[index] == '\r')
                {
                    index++;
                    continue;
                }
                else if (str[index] == '\n')
                {
                    index++;
                    stringHeight += charHeight + 1;
                    if (curLineWidth > stringWidth)
                    {
                        stringWidth = curLineWidth;
                    }
                    curLineWidth = 0;
                }
                else
                {
                    string key = GetCharKey();
                    if (!loadedBitmaps.ContainsKey(key))
                    {
                        loadedBitmaps.TryAdd(key, UriToBitmap(new Uri($"resm:Kermalis.PokemonBattleEngineClient.FONT.{path}.{key}.png?assembly=PokemonBattleEngineClient")));
                    }
                    curLineWidth += loadedBitmaps[key].PixelSize.Width;
                }
            }
            if (curLineWidth > stringWidth)
            {
                stringWidth = curLineWidth;
            }

            // Draw the string
            var wb = new WriteableBitmap(new PixelSize(stringWidth, stringHeight), new Vector(96, 96), PixelFormat.Bgra8888);

            using (IRenderTarget rtb = AvaloniaLocator.Current.GetService <IPlatformRenderInterface>().CreateRenderTarget(new[] { new WriteableBitmapSurface(wb) }))
                using (IDrawingContextImpl ctx = rtb.CreateDrawingContext(null))
                {
                    double x = 0, y = 0;
                    index = 0;
                    while (index < str.Length)
                    {
                        if (str[index] == ' ')
                        {
                            index++;
                            x += spaceWidth;
                        }
                        else if (str[index] == '\r')
                        {
                            index++;
                            continue;
                        }
                        else if (str[index] == '\n')
                        {
                            index++;
                            y += charHeight + 1;
                            x  = 0;
                        }
                        else
                        {
                            Bitmap bmp = loadedBitmaps[GetCharKey()];
                            ctx.DrawImage(bmp.PlatformImpl, 1.0, new Rect(0, 0, bmp.PixelSize.Width, charHeight), new Rect(x, y, bmp.PixelSize.Width, charHeight));
                            x += bmp.PixelSize.Width;
                        }
                    }
                }
            // Edit colors
            using (ILockedFramebuffer l = wb.Lock())
            {
                uint primary = 0xFFFFFFFF, secondary = 0xFF000000, tertiary = 0xFF808080;
                switch (style)
                {
                case StringRenderStyle.MenuBlack: primary = 0xFF5A5252; secondary = 0xFFA5A5AD; break;

                case StringRenderStyle.BattleWhite:     //secondary = 0xF0FFFFFF; break; // Looks horrible because of Avalonia's current issues
                case StringRenderStyle.MenuWhite: secondary = 0xFF848484; break;

                case StringRenderStyle.BattleName:
                case StringRenderStyle.BattleLevel: primary = 0xFFF7F7F7; secondary = 0xFF181818; break;

                case StringRenderStyle.BattleHP: primary = 0xFFF7F7F7; secondary = 0xFF101010; tertiary = 0xFF9C9CA5; break;
                }
                for (int x = 0; x < stringWidth; x++)
                {
                    for (int y = 0; y < stringHeight; y++)
                    {
                        var  address = new IntPtr(l.Address.ToInt64() + (x * sizeof(uint)) + (y * l.RowBytes));
                        uint pixel   = (uint)Marshal.ReadInt32(address);
                        if (pixel == 0xFFFFFFFF)
                        {
                            Marshal.WriteInt32(address, (int)primary);
                        }
                        else if (pixel == 0xFF000000)
                        {
                            Marshal.WriteInt32(address, (int)secondary);
                        }
                        else if (pixel == 0xFF808080)
                        {
                            Marshal.WriteInt32(address, (int)tertiary);
                        }
                    }
                }
            }
            return(wb);
        }
예제 #51
0
 public GUIContextRenderTargetEventArgs(GUIContext context, IRenderTarget target)
     : base(context)
 {
     renderTarget = target;
 }
예제 #52
0
 public override void Rendering(IRenderQueue q, IRenderTarget windowRenderTarget)
 {
     // throw new NotImplementedException();
 }
예제 #53
0
 /// <summary>
 ///		Sets up a new instance of this class with the given values.
 /// </summary>	
 /// <param name="renderControl">Control to render to.</param>
 /// <param name="flags">Flags to setup this control with.</param>
 public GraphicsCanvas(Control renderControl, GraphicsFlags flags, CanvasRenderHandler handler)
 {
     _renderControl = renderControl;
     _graphicsCanvas = GraphicsManager.Driver.CreateCanvas(renderControl, flags);
     if (handler != null) _renderDelegate += handler; // Fix this so its removed when canvas is destroyed!.
     _driver = GraphicsManager.Driver;
     GraphicsManager.RenderTarget = this;
 }
예제 #54
0
 //TODO DOCU
 public void UpdateRenderTargetData(IRenderTarget activeRenderTarget)
 {
     d_lastRenderTarget = activeRenderTarget;
     d_lastRenderTargetActivationCount = activeRenderTarget.GetActivationCounter();
 }
예제 #55
0
        public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
        {
            // Checking for redundant SetRenderTargets...
            if (renderTargets == null && RenderTargetCount == 0)
            {
                return;
            }
            else if (renderTargets != null && renderTargets.Length == RenderTargetCount)
            {
                bool isRedundant = true;
                for (int i = 0; i < renderTargets.Length; i += 1)
                {
                    if (renderTargets[i].RenderTarget != renderTargetBindings[i].RenderTarget ||
                        renderTargets[i].CubeMapFace != renderTargetBindings[i].CubeMapFace)
                    {
                        isRedundant = false;
                    }
                }
                if (isRedundant)
                {
                    return;
                }
            }

            int newWidth;
            int newHeight;
            RenderTargetUsage clearTarget;

            if (renderTargets == null || renderTargets.Length == 0)
            {
                GLDevice.SetRenderTargets(null, null, DepthFormat.None);

                // Set the viewport/scissor to the size of the backbuffer.
                newWidth    = PresentationParameters.BackBufferWidth;
                newHeight   = PresentationParameters.BackBufferHeight;
                clearTarget = PresentationParameters.RenderTargetUsage;

                // Generate mipmaps for previous targets, if needed
                for (int i = 0; i < RenderTargetCount; i += 1)
                {
                    if (renderTargetBindings[i].RenderTarget.LevelCount > 1)
                    {
                        GLDevice.GenerateTargetMipmaps(
                            renderTargetBindings[i].RenderTarget.texture
                            );
                    }
                }
                Array.Clear(renderTargetBindings, 0, renderTargetBindings.Length);
                RenderTargetCount = 0;
            }
            else
            {
                IRenderTarget target = renderTargets[0].RenderTarget as IRenderTarget;
                GLDevice.SetRenderTargets(
                    renderTargets,
                    target.DepthStencilBuffer,
                    target.DepthStencilFormat
                    );

                // Set the viewport/scissor to the size of the first render target.
                newWidth    = target.Width;
                newHeight   = target.Height;
                clearTarget = target.RenderTargetUsage;

                // Generate mipmaps for previous targets, if needed
                for (int i = 0; i < RenderTargetCount; i += 1)
                {
                    if (renderTargetBindings[i].RenderTarget.LevelCount > 1)
                    {
                        // We only need to gen mipmaps if the target is no longer bound.
                        bool stillBound = false;
                        for (int j = 0; j < renderTargets.Length; j += 1)
                        {
                            if (renderTargetBindings[i].RenderTarget == renderTargets[j].RenderTarget)
                            {
                                stillBound = true;
                                break;
                            }
                        }
                        if (!stillBound)
                        {
                            GLDevice.GenerateTargetMipmaps(
                                renderTargetBindings[i].RenderTarget.texture
                                );
                        }
                    }
                }
                Array.Clear(renderTargetBindings, 0, renderTargetBindings.Length);
                Array.Copy(renderTargets, renderTargetBindings, renderTargets.Length);
                RenderTargetCount = renderTargets.Length;
            }

            // Apply new GL state, clear target if requested
            Viewport         = new Viewport(0, 0, newWidth, newHeight);
            ScissorRectangle = new Rectangle(0, 0, newWidth, newHeight);
            if (clearTarget == RenderTargetUsage.DiscardContents)
            {
                Clear(
                    ClearOptions.Target | ClearOptions.DepthBuffer | ClearOptions.Stencil,
                    DiscardColor,
                    Viewport.MaxDepth,
                    0
                    );
            }
        }
예제 #56
0
 public SkiaRenderView(Activity context) : base(context)
 {
     _renderTarget =
         AvaloniaLocator.Current.GetService <IPlatformRenderInterface>()
         .CreateRenderTarget(this);
 }
예제 #57
0
파일: LogoElement.cs 프로젝트: andi2/ld32-1
 public override void OnDraw(IRenderTarget target, Vector2 drawPosition)
 {
     target.DrawTexture(Texture, drawPosition, Color * Opacity, Vector2.One, (Texture.Size / 2f).Floor, 0f, new Rectangle(Vector2.Zero, Texture.Size));
     base.OnDraw(target, drawPosition);
 }
예제 #58
0
        private void Render(bool forceComposite)
        {
            using (var l = _lock.TryLock())
            {
                if (l == null)
                {
                    return;
                }

                IDrawingContextImpl context = null;
                try
                {
                    try
                    {
                        IDrawingContextImpl GetContext()
                        {
                            if (context != null)
                            {
                                return(context);
                            }
                            if ((RenderTarget as IRenderTargetWithCorruptionInfo)?.IsCorrupted == true)
                            {
                                RenderTarget.Dispose();
                                RenderTarget = null;
                            }
                            if (RenderTarget == null)
                            {
                                RenderTarget = ((IRenderRoot)_root).CreateRenderTarget();
                            }
                            return(context = RenderTarget.CreateDrawingContext(this));
                        }

                        var(scene, updated) = UpdateRenderLayersAndConsumeSceneIfNeeded(GetContext);

                        using (scene)
                        {
                            if (scene?.Item != null)
                            {
                                var overlay = DrawDirtyRects || DrawFps;
                                if (DrawDirtyRects)
                                {
                                    _dirtyRectsDisplay.Tick();
                                }
                                if (overlay)
                                {
                                    RenderOverlay(scene.Item, GetContext());
                                }
                                if (updated || forceComposite || overlay)
                                {
                                    RenderComposite(scene.Item, GetContext());
                                }
                            }
                        }
                    }
                    finally
                    {
                        context?.Dispose();
                    }
                }
                catch (RenderTargetCorruptedException ex)
                {
                    Logging.Logger.Information("Renderer", this, "Render target was corrupted. Exception: {0}", ex);
                    RenderTarget?.Dispose();
                    RenderTarget = null;
                }
            }
        }
예제 #59
0
 public void Draw(IRenderTarget target, RenderStates renderStates)
 {
     Draw(target.SFMLTarget, renderStates.SFMLRenderStates);
 }
예제 #60
0
 public RenderTargetScriptObject(IRenderTarget target)
 {
     _nativeObject = target;
 }