Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 8
0
 public void Render(DrawDevice drawDevice)
 {
     foreach (var system in RenderingSystems)
     {
         system.Update(drawDevice);
     }
 }
Ejemplo n.º 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)));
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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");
 }
Ejemplo n.º 12
0
 private void SetupDevice()
 {
     if (this.drawDevice != null && !this.drawDevice.Disposed)
     {
         return;
     }
     this.drawDevice = new DrawDevice();
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 15
0
 private void ReleaseTransformDevice()
 {
     if (this.transformDevice == null)
     {
         return;
     }
     this.transformDevice.Dispose();
     this.transformDevice = null;
 }
Ejemplo n.º 16
0
 private void ReleaseDrawDevice()
 {
     if (this.drawDevice == null)
     {
         return;
     }
     this.drawDevice.Dispose();
     this.drawDevice = null;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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++;
     }
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 22
0
 protected override void OnRenderSingleStep(RenderStep step, Scene scene, DrawDevice drawDevice)
 {
     if (step.Id == "Resize")
     {
         ProcessResizeStep(drawDevice);
     }
     else
     {
         base.OnRenderSingleStep(step, scene, drawDevice);
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 26
0
 protected override void OnRenderState()
 {
     // Render game pov
     if (!Scene.Current.Cameras.Any())
     {
         DrawDevice.RenderVoid();
     }
     else
     {
         DualityApp.Render();
     }
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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();
 }
Ejemplo n.º 31
0
		private void ReleaseDevice()
		{
			if (this.drawDevice == null) return;
			this.drawDevice.Dispose();
			this.drawDevice = null;
		}
Ejemplo n.º 32
0
		private void SetupDevice()
		{
			if (this.drawDevice != null && !this.drawDevice.Disposed) return;
			this.drawDevice = new DrawDevice();
		}
Ejemplo n.º 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;
		}