Пример #1
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);
            }
        }
Пример #2
0
            public void UpdateFromSource(IMouseInputSource source)
            {
                this.IsAvailable = source != null ? source.IsAvailable : false;
                if (source == null)
                {
                    return;
                }

                this.WindowPos = source.Pos;
                this.Wheel     = source.Wheel;
                for (int i = 0; i < this.ButtonPressed.Length; i++)
                {
                    this.ButtonPressed[i] = source[(MouseButton)i];
                }

                // Map window position to game view position
                Rect    viewportRect;
                Vector2 gameViewSize;

                DualityApp.CalculateGameViewport(DualityApp.WindowSize, out viewportRect, out gameViewSize);
                Vector2 relativePos = new Vector2(
                    MathF.Clamp((this.WindowPos.X - viewportRect.X) / viewportRect.W, 0.0f, 1.0f),
                    MathF.Clamp((this.WindowPos.Y - viewportRect.Y) / viewportRect.H, 0.0f, 1.0f));

                this.ViewPos = relativePos * gameViewSize;
            }
Пример #3
0
        private void OnRenderFrame(FrameEventArgs e)
        {
            if (DualityApp.ExecContext == DualityApp.ExecutionContext.Terminated)
            {
                return;
            }

            Vector2 imageSize;
            Rect    viewportRect;

            DualityApp.CalculateGameViewport(this.Size, out viewportRect, out imageSize);

            DualityApp.Render(null, viewportRect, imageSize);

            this.internalWindow.SwapBuffers();
        }
Пример #4
0
        private void OnUpdate(double milliseconds)
        {
            if (DualityApp.ExecContext == DualityApp.ExecutionContext.Terminated)
            {
                return;
            }

            DualityApp.Update();

            Vector2 imageSize;
            Rect    viewportRect;

            DualityApp.CalculateGameViewport(this.Size, out viewportRect, out imageSize);

            DualityApp.Render(null, viewportRect, imageSize);

            window.Invoke("requestAnimationFrame", updateDelegate);
        }