Пример #1
0
        private PixelData RenderToTexture(int width, int height, Action <Canvas> renderMethod)
        {
            PixelData pixelData;

            using (Texture texture = new Texture(width, height, TextureSizeMode.NonPowerOfTwo, TextureMagFilter.Nearest, TextureMinFilter.Nearest))
                using (RenderTarget renderTarget = new RenderTarget(AAQuality.Off, texture))
                    using (DrawDevice device = new DrawDevice())
                    {
                        device.Perspective    = PerspectiveMode.Flat;
                        device.VisibilityMask = VisibilityFlag.AllGroups | VisibilityFlag.ScreenOverlay;
                        device.RenderMode     = RenderMatrix.OrthoScreen;
                        device.Target         = renderTarget;
                        device.ViewportRect   = new Rect(renderTarget.Width, renderTarget.Height);

                        device.PrepareForDrawcalls();
                        {
                            Canvas canvas = new Canvas(device);
                            renderMethod(canvas);
                        }
                        device.Render(ClearFlag.All, ColorRgba.TransparentBlack, 1.0f);

                        pixelData = texture.GetPixelData();
                    }

            return(pixelData);
        }
Пример #2
0
        /// <inheritdoc />
        protected override void OnRenderState()
        {
            // We're not calling the base implementation, because the default is to
            // render the scene from the view of an editing camera. The Game View, however,
            // is in the special position to render the actual game and completely ignore
            // any editing camera.
            //
            // base.OnRenderState();

            Point2 clientSize = new Point2(this.RenderableControl.ClientSize.Width, this.RenderableControl.ClientSize.Height);
            Point2 targetSize = this.TargetRenderSize;
            Rect   windowRect = this.LocalGameWindowRect;

            Vector2 imageSize;
            Rect    viewportRect;

            DualityApp.CalculateGameViewport(targetSize, out viewportRect, out imageSize);

            // Render the game view background using a background color matching editor UI,
            // so users can discern between an area that isn't rendered to and a rendered
            // area of the game that happens to be black or outside the game viewport.
            DrawDevice.RenderVoid(new Rect(clientSize), new ColorRgba(64, 64, 64));

            if (this.UseOffscreenBuffer)
            {
                // Render the scene to an offscreen buffer of matching size first
                this.SetupOutputRenderTarget();
                DualityApp.Render(this.outputTarget, viewportRect, imageSize);

                // Blit the offscreen buffer to the window area
                this.SetupBlitDevice();
                this.blitDevice.TargetSize   = clientSize;
                this.blitDevice.ViewportRect = new Rect(clientSize);

                BatchInfo blitMaterial = this.blitDevice.RentMaterial();
                blitMaterial.Technique   = DrawTechnique.Solid;
                blitMaterial.MainTexture = this.outputTexture;

                TargetResize blitResize = this.TargetSizeFitsClientArea ?
                                          TargetResize.None :
                                          TargetResize.Fit;

                this.blitDevice.PrepareForDrawcalls();
                this.blitDevice.AddFullscreenQuad(blitMaterial, blitResize);
                this.blitDevice.Render();
            }
            else
            {
                Rect windowViewportRect = new Rect(
                    windowRect.X + viewportRect.X,
                    windowRect.Y + viewportRect.Y,
                    viewportRect.W,
                    viewportRect.H);

                // Render the scene centered into the designated viewport area
                this.CleanupRenderTarget();
                DrawDevice.RenderVoid(windowRect);
                DualityApp.Render(null, windowViewportRect, imageSize);
            }
        }
Пример #3
0
        private PixelData RenderToTexture(int width, int height, Action <Canvas> renderMethod)
        {
            PixelData pixelData;

            using (Texture texture = new Texture(width, height, TextureSizeMode.NonPowerOfTwo, TextureMagFilter.Nearest, TextureMinFilter.Nearest))
                using (RenderTarget renderTarget = new RenderTarget(AAQuality.Off, true, texture))
                    using (DrawDevice device = new DrawDevice())
                    {
                        device.Projection     = ProjectionMode.Screen;
                        device.VisibilityMask = VisibilityFlag.AllGroups | VisibilityFlag.ScreenOverlay;
                        device.Target         = renderTarget;
                        device.TargetSize     = renderTarget.Size;
                        device.ViewportRect   = new Rect(renderTarget.Size);

                        device.PrepareForDrawcalls();
                        {
                            Canvas canvas = new Canvas();
                            canvas.Begin(device);
                            renderMethod(canvas);
                            canvas.End();
                        }
                        device.Render();

                        pixelData = texture.GetPixelData();
                    }

            return(pixelData);
        }
Пример #4
0
        protected override void OnRenderPointOfView(Scene scene, DrawDevice drawDevice, Rect viewportRect, Vector2 imageSize)
        {
            // Check if resolution changed
            if (lastImageSize != imageSize)
            {
                lastImageSize = imageSize;

                const float defaultRatio = (float)defaultWidth / defaultHeight;
                float       currentRatio = imageSize.X / imageSize.Y;

                int width, height;
                if (currentRatio > defaultRatio)
                {
                    width  = MathF.Min(defaultWidth, (int)imageSize.X);
                    height = (int)(width / currentRatio);
                }
                else if (currentRatio < defaultRatio)
                {
                    height = MathF.Min(defaultHeight, (int)imageSize.Y);
                    width  = (int)(height * currentRatio);
                }
                else
                {
                    width  = MathF.Min(defaultWidth, (int)imageSize.X);
                    height = MathF.Min(defaultHeight, (int)imageSize.Y);
                }

                TargetSize = new Point2(width, height);

                ResizeRenderTarget(finalTarget, TargetSize);
            }

            base.OnRenderPointOfView(scene, drawDevice, viewportRect, imageSize);
        }
Пример #5
0
        /// <summary>
        /// Called in order to let the specified <see cref="DrawDevice"/> collect all drawcalls from
        /// a set of renderers that was previously determined to be potentially visible.
        /// </summary>
        /// <param name="drawDevice"></param>
        /// <param name="visibleRenderers"></param>
        /// <param name="renderersSortedByType"></param>
        protected virtual void OnCollectRendererDrawcalls(DrawDevice drawDevice, RawList <ICmpRenderer> visibleRenderers, bool renderersSortedByType)
        {
            Type lastRendererType = null;
            Type rendererType     = null;

            //TimeCounter activeProfiler = null;
            ICmpRenderer[] data = visibleRenderers.Data;
            for (int i = 0; i < data.Length; i++)
            {
                if (i >= visibleRenderers.Count)
                {
                    break;
                }

                // Manage profilers per Component type
                if (renderersSortedByType)
                {
                    rendererType = data[i].GetType();
                    if (rendererType != lastRendererType)
                    {
                        //if (activeProfiler != null)
                        //	activeProfiler.EndMeasure();
                        //activeProfiler = Profile.RequestCounter<TimeCounter>(Profile.TimeCollectDrawcalls.FullName + @"\" + rendererType.Name);
                        //activeProfiler.BeginMeasure();
                        lastRendererType = rendererType;
                    }
                }

                // Collect Drawcalls from this Component
                data[i].Draw(drawDevice);
            }

            //if (activeProfiler != null)
            //	activeProfiler.EndMeasure();
        }
Пример #6
0
        private Pixmap.Layer RenderToTexture(int width, int height, Action <Canvas> renderMethod)
        {
            Pixmap.Layer pixelData;

            using (Texture texture = new Texture(width, height, Texture.SizeMode.NonPowerOfTwo))
                using (RenderTarget renderTarget = new RenderTarget(AAQuality.Off, texture))
                    using (DrawDevice device = new DrawDevice())
                    {
                        device.Perspective    = PerspectiveMode.Flat;
                        device.VisibilityMask = VisibilityFlag.AllGroups | VisibilityFlag.ScreenOverlay;
                        device.RenderMode     = RenderMatrix.OrthoScreen;
                        device.Target         = renderTarget;
                        device.ViewportRect   = new Rect(renderTarget.Width, renderTarget.Height);

                        device.BeginRendering(ClearFlag.All, ColorRgba.TransparentBlack, 1.0f);
                        {
                            Canvas canvas = new Canvas(device);
                            renderMethod(canvas);
                        }
                        device.EndRendering();

                        RenderTarget.Bind(RenderTarget.None);

                        pixelData = texture.RetrievePixelData();
                    }

            return(pixelData);
        }
Пример #7
0
        [Test] public void IsSphereInViewOrthographic()
        {
            Vector2 viewportSize = new Vector2(800, 600);

            using (DrawDevice device = new DrawDevice())
            {
                device.TargetSize   = viewportSize;
                device.ViewportRect = new Rect(viewportSize);
                device.ViewerPos    = new Vector3(0, 0, 0);
                device.FocusDist    = 500;
                device.NearZ        = 100;
                device.FarZ         = 10000;
                device.Projection   = ProjectionMode.Orthographic;

                // Viewport center
                Assert.IsTrue(device.IsSphereInView(new Vector3(0, 0, device.FocusDist), 150));

                // Just inside each of the viewports sides
                Assert.IsTrue(device.IsSphereInView(new Vector3(-viewportSize.X * 0.5f - 100, 0, device.FocusDist), 150));
                Assert.IsTrue(device.IsSphereInView(new Vector3(0, -viewportSize.Y * 0.5f - 100, device.FocusDist), 150));
                Assert.IsTrue(device.IsSphereInView(new Vector3(viewportSize.X * 0.5f + 100, 0, device.FocusDist), 150));
                Assert.IsTrue(device.IsSphereInView(new Vector3(0, viewportSize.Y * 0.5f + 100, device.FocusDist), 150));
                Assert.IsTrue(device.IsSphereInView(new Vector3(0, 0, device.FarZ - 50), 150));
                Assert.IsTrue(device.IsSphereInView(new Vector3(0, 0, device.NearZ + 50), 150));

                // Just outside each of the viewports sides
                Assert.IsFalse(device.IsSphereInView(new Vector3(-viewportSize.X * 0.5f - 200, 0, device.FocusDist), 150));
                Assert.IsFalse(device.IsSphereInView(new Vector3(0, -viewportSize.Y * 0.5f - 200, device.FocusDist), 150));
                Assert.IsFalse(device.IsSphereInView(new Vector3(viewportSize.X * 0.5f + 200, 0, device.FocusDist), 150));
                Assert.IsFalse(device.IsSphereInView(new Vector3(0, viewportSize.Y * 0.5f + 200, device.FocusDist), 150));
                Assert.IsFalse(device.IsSphereInView(new Vector3(0, 0, device.FarZ + 50), 150));
                Assert.IsFalse(device.IsSphereInView(new Vector3(0, 0, device.NearZ - 50), 150));
            }
        }
Пример #8
0
 public void Render(DrawDevice drawDevice)
 {
     foreach (var system in RenderingSystems)
     {
         system.Update(drawDevice);
     }
 }
Пример #9
0
        [Test] public void GetWorldPos()
        {
            using (DrawDevice device = new DrawDevice())
            {
                Vector2 targetSize     = new Vector2(800, 600);
                Vector2 viewportCenter = targetSize * 0.5f;

                // We'll check twice the focus distance to make sure orthographic
                // scaling is working as expected.
                device.FocusDist    = DrawDevice.DefaultFocusDist * 2.0f;
                device.NearZ        = 100;
                device.FarZ         = 10000;
                device.TargetSize   = targetSize;
                device.ViewportRect = new Rect(targetSize);
                device.ViewerPos    = new Vector3(0, 0, -device.FocusDist);

                // Screen space rendering
                device.Projection = ProjectionMode.Screen;

                // 1:1 world coordinate output in all cases
                AssertRoughlyEqual(new Vector3(0.0f, 0.0f, 0.0f), device.GetWorldPos(new Vector3(0.0f, 0.0f, 0.0f)));
                AssertRoughlyEqual(new Vector3(400.0f, 300.0f, 0.0f), device.GetWorldPos(new Vector3(400.0f, 300.0f, 0.0f)));
                AssertRoughlyEqual(new Vector3(800.0f, 600.0f, 0.0f), device.GetWorldPos(new Vector3(800.0f, 600.0f, 0.0f)));
                AssertRoughlyEqual(new Vector3(0.0f, 0.0f, 1000.0f), device.GetWorldPos(new Vector3(0.0f, 0.0f, 1000.0f)));
                AssertRoughlyEqual(new Vector3(400.0f, 0.0f, 1000.0f), device.GetWorldPos(new Vector3(400.0f, 0.0f, 1000.0f)));
                AssertRoughlyEqual(new Vector3(800.0f, 0.0f, 1000.0f), device.GetWorldPos(new Vector3(800.0f, 0.0f, 1000.0f)));
                AssertRoughlyEqual(new Vector3(0.0f, 300.0f, 1000.0f), device.GetWorldPos(new Vector3(0.0f, 300.0f, 1000.0f)));
                AssertRoughlyEqual(new Vector3(0.0f, 600.0f, 1000.0f), device.GetWorldPos(new Vector3(0.0f, 600.0f, 1000.0f)));

                // World space rendering with orthographic projection
                device.Projection = ProjectionMode.Orthographic;

                // Scaled up 2:1 due to focus distance scaling factor
                AssertRoughlyEqual(new Vector3(0.0f, 0.0f, 0.0f), device.GetWorldPos(new Vector3(viewportCenter, 0.0f)));
                AssertRoughlyEqual(new Vector3(-200.0f, -150.0f, 0.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(-400.0f, -300.0f), 0.0f)));
                AssertRoughlyEqual(new Vector3(200.0f, 150.0f, 0.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(400.0f, 300.0f), 0.0f)));

                // No scale changes at other distances
                AssertRoughlyEqual(new Vector3(0.0f, 0.0f, 1000.0f), device.GetWorldPos(new Vector3(viewportCenter, 1000.0f)));
                AssertRoughlyEqual(new Vector3(-200.0f, 0.0f, 1000.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(-400.0f, 0.0f), 1000.0f)));
                AssertRoughlyEqual(new Vector3(200.0f, 0.0f, 1000.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(400.0f, 0.0f), 1000.0f)));
                AssertRoughlyEqual(new Vector3(0.0f, -150.0f, 1000.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(0.0f, -300.0f), 1000.0f)));
                AssertRoughlyEqual(new Vector3(0.0f, 150.0f, 1000.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(0.0f, 300.0f), 1000.0f)));

                // World space rendering with perspective projection
                device.Projection = ProjectionMode.Perspective;

                // 1:1 scaling at focus distance
                AssertRoughlyEqual(new Vector3(0.0f, 0.0f, 0.0f), device.GetWorldPos(new Vector3(viewportCenter, 0.0f)));
                AssertRoughlyEqual(new Vector3(-400.0f, -300.0f, 0.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(-400.0f, -300.0f), 0.0f)));
                AssertRoughlyEqual(new Vector3(400.0f, 300.0f, 0.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(400.0f, 300.0f), 0.0f)));

                // Scaled down 1:2 at double the focus distance
                AssertRoughlyEqual(new Vector3(0.0f, 0.0f, 1000.0f), device.GetWorldPos(new Vector3(viewportCenter, 1000.0f)));
                AssertRoughlyEqual(new Vector3(-400.0f, 0.0f, 1000.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(-200.0f, 0.0f), 1000.0f)));
                AssertRoughlyEqual(new Vector3(400.0f, 0.0f, 1000.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(200.0f, 0.0f), 1000.0f)));
                AssertRoughlyEqual(new Vector3(0.0f, -600.0f, 1000.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(0.0f, -300.0f), 1000.0f)));
                AssertRoughlyEqual(new Vector3(0.0f, 600.0f, 1000.0f), device.GetWorldPos(new Vector3(viewportCenter + new Vector2(0.0f, 300.0f), 1000.0f)));
            }
        }
Пример #10
0
        IBuffer getTextCBuffer()
        {
            if (null != m_staticCBufferForText)
            {
                return(m_staticCBufferForText);
            }

            ConstantsBufferText data = new ConstantsBufferText();

            data.pixelSizeAndDpiScaling = pixelSizeAndDpiScaling;

            DrawDevice dev       = (DrawDevice)context.drawDevice;
            CSize      atlasSize = dev.fontTextures.grayscale.layerSize;

            data.textureAtlasSize.X = atlasSize.cx;
            data.textureAtlasSize.Y = atlasSize.cy;

            atlasSize = dev.fontTextures.cleartype.layerSize;
            data.textureAtlasSize.Z = atlasSize.cx;
            data.textureAtlasSize.W = atlasSize.cy;

            IBuffer ib;

            using (var device = context.renderContext.device)
                ib = device.CreateImmutableUniformBuffer(ref data, "Text cbuffer");
            m_staticCBufferForText = ib;
            return(ib);
        }
Пример #11
0
 public WindowsFonts(DrawDevice drawDevice) :
     base(drawDevice)
 {
     addDefaults(defaultFonts, eDefaultFont.Mono, "consola.ttf", "consolab.ttf", "consolai.ttf", "consolaz.ttf");
     addDefaults(defaultFonts, eDefaultFont.Sans, "calibri.ttf", "calibrib.ttf", "calibrii.ttf", "calibriz.ttf");
     addDefaults(defaultFonts, eDefaultFont.Serif, "cambria.ttc", "cambriab.ttf", "cambriai.ttf", "cambriaz.ttf");
     addDefaults(defaultFonts, eDefaultFont.ComicSans, "comic.ttf", "comicbd.ttf", "comici.ttf", "comicz.ttf");
 }
Пример #12
0
 private void SetupDevice()
 {
     if (this.drawDevice != null && !this.drawDevice.Disposed)
     {
         return;
     }
     this.drawDevice = new DrawDevice();
 }
Пример #13
0
        private void ProcessBloomStep(RenderStep step, DrawDevice drawDevice)
        {
            ContentRef <RenderTarget> outputTarget = drawDevice.Target;
            Vector2 imageSize    = drawDevice.TargetSize;
            Rect    viewportRect = drawDevice.ViewportRect;

            this.SetupTargets((Point2)drawDevice.TargetSize);

            // Extract bright spots from the rendered image
            {
                BatchInfo material = drawDevice.RentMaterial();
                material.Technique   = this.techFilterBrightness;
                material.MainTexture = step.Input.MainTexture;
                material.SetValue("minBrightness", this.minBrightness);
                material.SetValue("bloomStrength", this.bloomStrength);
                this.Blit(drawDevice, material, this.targetPingPongA[0]);
            }

            // Downsample to lowest target
            for (int i = 1; i < this.targetPingPongA.Length; i++)
            {
                BatchInfo material = drawDevice.RentMaterial();
                material.Technique   = this.techDownsample;
                material.MainTexture = this.targetPingPongA[i - 1].Targets[0];
                this.Blit(drawDevice, material, this.targetPingPongA[i]);
            }

            // Blur all targets, separating horizontal and vertical blur
            for (int i = 0; i < this.targetPingPongA.Length; i++)
            {
                BatchInfo material;
                material           = drawDevice.RentMaterial();
                material.Technique = this.techBlur;

                material.MainTexture = this.targetPingPongA[i].Targets[0];
                material.SetValue("blurDirection", new Vector2(1.0f, 0.0f));
                this.Blit(drawDevice, material, this.targetPingPongB[i]);

                material           = drawDevice.RentMaterial();
                material.Technique = this.techBlur;

                material.MainTexture = this.targetPingPongB[i].Targets[0];
                material.SetValue("blurDirection", new Vector2(0.0f, 1.0f));
                this.Blit(drawDevice, material, this.targetPingPongA[i]);
            }

            // Combine all targets into the final image using the draw device's original target
            {
                BatchInfo material = drawDevice.RentMaterial();
                material.Technique   = this.techCombineFinal;
                material.MainTexture = step.Input.MainTexture;
                material.SetTexture("blurFullTex", this.targetPingPongA[0].Targets[0]);
                material.SetTexture("blurHalfTex", this.targetPingPongA[1].Targets[0]);
                material.SetTexture("blurQuarterTex", this.targetPingPongA[2].Targets[0]);
                material.SetTexture("blurEighthTex", this.targetPingPongA[3].Targets[0]);
                this.Blit(drawDevice, material, outputTarget.Res, imageSize, viewportRect);
            }
        }
Пример #14
0
 /// <summary>
 /// Sets up a <see cref="DrawDevice"/> to be used for blitting an internal
 /// offscreen rendering target to the actual window surface.
 /// </summary>
 private void SetupBlitDevice()
 {
     if (this.blitDevice == null)
     {
         this.blitDevice            = new DrawDevice();
         this.blitDevice.ClearFlags = ClearFlag.Depth;
         this.blitDevice.Projection = ProjectionMode.Screen;
     }
 }
Пример #15
0
 private void ReleaseTransformDevice()
 {
     if (this.transformDevice == null)
     {
         return;
     }
     this.transformDevice.Dispose();
     this.transformDevice = null;
 }
Пример #16
0
 private void ReleaseDrawDevice()
 {
     if (this.drawDevice == null)
     {
         return;
     }
     this.drawDevice.Dispose();
     this.drawDevice = null;
 }
Пример #17
0
        private void ProcessResizeStep(DrawDevice drawDevice)
        {
            BatchInfo material = drawDevice.RentMaterial();

            material.Technique   = resizeShader;
            material.MainTexture = finalTexture;
            material.SetValue("mainTexSize", new Vector2(finalTexture.ContentWidth, finalTexture.ContentHeight));
            this.Blit(drawDevice, material, drawDevice.ViewportRect);
        }
Пример #18
0
 protected override void OnCollectRendererDrawcalls(DrawDevice drawDevice, RawList <ICmpRenderer> visibleRenderers, bool renderersSortedByType)
 {
     this.pickingMap.AddRange(visibleRenderers);
     foreach (ICmpRenderer r in visibleRenderers)
     {
         r.Draw(drawDevice);
         drawDevice.PickingIndex++;
     }
 }
Пример #19
0
        /// <summary>
        /// Uses the specified <see cref="DrawDevice"/> to collect renderer drawcalls in the specified <see cref="Scene"/>.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="drawDevice"></param>
        /// <param name="pickingMap"></param>
        protected void CollectRendererDrawcalls(Scene scene, DrawDevice drawDevice)
        {
            //Profile.TimeCollectDrawcalls.BeginMeasure();
            try
            {
                // If no visibility groups are met, don't bother looking for renderers.
                // This is important to allow efficient drawcall injection with additional
                // "dummy" renderpasses. CamViewStates render their overlays by temporarily
                // adding 3 - 4 of these passes. Iterating over all objects again would be
                // devastating for performance and at the same time pointless.
                if ((drawDevice.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None)
                {
                    return;
                }

                // Query renderers
                IRendererVisibilityStrategy visibilityStrategy = scene.VisibilityStrategy;
                if (visibilityStrategy == null)
                {
                    return;
                }

                //Profile.TimeQueryVisibleRenderers.BeginMeasure();

                if (this.collectRendererBuffer == null)
                {
                    this.collectRendererBuffer = new RawList <ICmpRenderer>();
                }
                this.collectRendererBuffer.Clear();

                visibilityStrategy.QueryVisibleRenderers(drawDevice, this.collectRendererBuffer);
                if (this.rendererFilter.Count > 0)
                {
                    this.collectRendererBuffer.RemoveAll(r =>
                    {
                        for (int i = 0; i < this.rendererFilter.Count; i++)
                        {
                            if (!this.rendererFilter[i](r))
                            {
                                return(true);
                            }
                        }
                        return(false);
                    });
                }

                //Profile.TimeQueryVisibleRenderers.EndMeasure();

                this.OnCollectRendererDrawcalls(drawDevice, this.collectRendererBuffer, visibilityStrategy.IsRendererQuerySorted);
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error while {0} was collecting renderer drawcalls: {1}", this, /*LogFormat.Exception(*/ e /*)*/);
            }
            //Profile.TimeCollectDrawcalls.EndMeasure();
        }
Пример #20
0
        public static void Blit(this RenderSetup renderSetup, DrawDevice device, BatchInfo source, Rect screenRect)
        {
            device.Target       = null;
            device.TargetSize   = screenRect.Size;
            device.ViewportRect = screenRect;

            device.PrepareForDrawcalls();
            device.AddFullscreenQuad(source, TargetResize.Stretch);
            device.Render();
        }
Пример #21
0
        private void Blit(DrawDevice device, BatchInfo source, RenderTarget target, Vector2 targetSize, Rect viewportRect)
        {
            device.Target       = target;
            device.TargetSize   = targetSize;
            device.ViewportRect = viewportRect;

            device.PrepareForDrawcalls();
            device.AddFullscreenQuad(source, TargetResize.Stretch);
            device.Render();
        }
Пример #22
0
 protected override void OnRenderSingleStep(RenderStep step, Scene scene, DrawDevice drawDevice)
 {
     if (step.Id == "Resize")
     {
         ProcessResizeStep(drawDevice);
     }
     else
     {
         base.OnRenderSingleStep(step, scene, drawDevice);
     }
 }
Пример #23
0
        public void initTextCBuffer()
        {
            DrawDevice dev      = (DrawDevice)context.drawDevice;
            Action     actClear = () =>
            {
                GpuResources res = this;
                ComUtils.clear(ref res.m_staticCBufferForText);
            };

            dev.fontTextures.subscriveResized(this, actClear);
        }
Пример #24
0
        /// <summary>
        /// Called to render a scene from the perspective of a single, pre-configured drawing device.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="drawDevice"></param>
        /// <param name="viewportRect"></param>
        /// <param name="imageSize"></param>
        /// <param name="outputTargetRect"></param>
        protected virtual void OnRenderPointOfView(Scene scene, DrawDevice drawDevice, Rect viewportRect, Vector2 imageSize)
        {
            // Resize all render targets to the viewport size we're dealing with
            this.ApplyOutputAutoResize((Point2)viewportRect.Size);

            // Execute all steps in the rendering setup, as well as those that were added in this camera
            foreach (RenderStep step in this.steps)
            {
                this.RenderSingleStep(step, scene, drawDevice, viewportRect, imageSize);
            }
        }
Пример #25
0
 protected override void OnRenderSingleStep(RenderStep step, Scene scene, DrawDevice drawDevice)
 {
     if (step.Id == "Bloom")
     {
         this.ProcessBloomStep(step, drawDevice);
     }
     else
     {
         base.OnRenderSingleStep(step, scene, drawDevice);
     }
 }
Пример #26
0
 protected override void OnRenderState()
 {
     // Render game pov
     if (!Scene.Current.Cameras.Any())
     {
         DrawDevice.RenderVoid();
     }
     else
     {
         DualityApp.Render();
     }
 }
Пример #27
0
        private void SetupDrawDevice()
        {
            if (this.drawDevice != null && !this.drawDevice.Disposed)
            {
                return;
            }

            // The draw device can just use default settings, because all rendering
            // will overwrite the relevant values, such as render mode and target size.
            // It will never be used by the Cameras transform methods.
            this.drawDevice = new DrawDevice();
        }
Пример #28
0
        private void SetupTransformDevice()
        {
            if (this.transformDevice != null && !this.transformDevice.Disposed)
            {
                return;
            }

            // The transform device used only for calculating transform results in
            // the camera methods. It is never used for rendering.
            this.transformDevice            = new DrawDevice();
            this.transformDevice.TargetSize = DualityApp.TargetViewSize;
        }
Пример #29
0
        private void SetupDevice()
        {
            if (this.drawDevice != null && !this.drawDevice.Disposed)
            {
                return;
            }

            this.drawDevice = new DrawDevice();

            // Default to world space render mode, so coordinate conversions
            // work as expected regardless of rendering state.
            this.drawDevice.RenderMode = RenderMatrix.WorldSpace;
        }
Пример #30
0
 /// <summary>
 /// Called to process the specified <see cref="RenderStep"/>.
 /// </summary>
 /// <param name="step"></param>
 /// <param name="drawDevice"></param>
 protected virtual void OnRenderSingleStep(RenderStep step, Scene scene, DrawDevice drawDevice)
 {
     drawDevice.PrepareForDrawcalls();
     if (step.Input == null)
     {
         this.CollectDrawcalls(step, scene, drawDevice);
     }
     else
     {
         drawDevice.AddFullscreenQuad(step.Input, step.InputResize);
     }
     drawDevice.Render();
 }
Пример #31
0
		private void ReleaseDevice()
		{
			if (this.drawDevice == null) return;
			this.drawDevice.Dispose();
			this.drawDevice = null;
		}
Пример #32
0
		private void SetupDevice()
		{
			if (this.drawDevice != null && !this.drawDevice.Disposed) return;
			this.drawDevice = new DrawDevice();
		}
Пример #33
0
		private Pixmap.Layer RenderToTexture(int width, int height, Action<Canvas> renderMethod)
		{
			Pixmap.Layer pixelData;

			using (Texture texture = new Texture(width, height, Texture.SizeMode.NonPowerOfTwo))
			using (RenderTarget renderTarget = new RenderTarget(AAQuality.Off, texture))
			using (DrawDevice device = new DrawDevice())
			{
				device.Perspective = PerspectiveMode.Flat;
				device.VisibilityMask = VisibilityFlag.AllGroups | VisibilityFlag.ScreenOverlay;
				device.RenderMode = RenderMatrix.OrthoScreen;
				device.Target = renderTarget;
				device.ViewportRect = new Rect(renderTarget.Width, renderTarget.Height);

				device.BeginRendering(ClearFlag.All, ColorRgba.TransparentBlack, 1.0f);
				{
					Canvas canvas = new Canvas(device);
					renderMethod(canvas);
				}
				device.EndRendering();
				
				RenderTarget.Bind(RenderTarget.None);

				pixelData = texture.RetrievePixelData();
			}

			return pixelData;
		}