Example #1
0
        public static uint Draw(IFrameBuffer frameBuffer, uint tileSize)
        {
            uint positionX = (frameBuffer.Width / 2) - ((_width * tileSize) / 2);
            uint positionY = (frameBuffer.Height / 2) - ((_height * tileSize) / 2);

            //Can't store these as a static fields, they seem to break something
            uint[] logo   = new uint[] { 0x39E391, 0x44145B, 0x7CE455, 0x450451, 0x450451, 0x451451, 0x44E391 };
            uint[] colors = new uint[] { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00FFFF00 }; //Colors for each pixel

            for (int ty = 0; ty < _height; ty++)
            {
                uint data = logo[ty];

                for (int tx = 0; tx < _width; tx++)
                {
                    int mask = 1 << tx;

                    if ((data & mask) == mask)
                    {
                        frameBuffer.FillRectangle(colors[tx / 6], (uint)(positionX + (tileSize * tx)), (uint)(positionY + (tileSize * ty)), tileSize, tileSize); //Each pixel is aprox 5 tiles in width
                    }
                }
            }

            return(positionY);
        }
		public bool RenderTransition(IFrameBuffer from, IFrameBuffer to)
		{
			if (_tween.Task.IsCompleted)
			{
				return false;
			}
			_visitTween();
			var oldShader = AGSGame.Shader;
			_screenVectors.Render(to.Texture);
			var shader = GLShader.FromText(VERTEX_SHADER, FRAGMENT_SHADER, _graphics).Compile();
			if (shader == null)
			{
				return false;
			}
			shader.Bind();
			if (!shader.SetVariable("time", _time))
			{
				shader.Unbind();
				return false;
			}
			_screenVectors.Render(from.Texture);

			if (oldShader != null) oldShader.Bind();
			else shader.Unbind();

			return true;
		}
Example #3
0
        public void RenderBorderFront(AGSBoundingBox square)
        {
            if (_settings.WindowSize.Equals(_lastWindowSize) && _lastSquare.SameSize(square) &&
                _glUtils.DrawQuad(_frameBuffer, square, _quad))
            {
                return;
            }

            _frameBuffer?.Dispose();
            _lastSquare     = square;
            _lastWindowSize = _settings.WindowSize;

            float width  = _glUtils.CurrentResolution.Width - _padding;
            float height = _glUtils.CurrentResolution.Height - _padding;

            _frameBuffer = _glUtils.BeginFrameBuffer(square, _settings);
            if (_frameBuffer == null)
            {
                return;
            }
            _glUtils.DrawLine(_padding, _padding, width, height, _lineWidth, _color.R, _color.G, _color.B, _color.A);
            _glUtils.DrawLine(_padding, height, width, _padding, _lineWidth, _color.R, _color.G, _color.B, _color.A);

            _frameBuffer.End();

            _glUtils.DrawQuad(_frameBuffer, square, _quad);
        }
Example #4
0
        public bool RenderTransition(IFrameBuffer from, IFrameBuffer to)
        {
            if (_tween.Task.IsCompleted)
            {
                return(false);
            }
            _visitTween();
            var oldShader = AGSGame.Shader;

            _screenVectors.Render(to.Texture);
            var shader = _game.Factory.Shaders.FromText(null, FRAGMENT_SHADER).Compile();

            if (shader == null)
            {
                return(false);
            }
            shader.Bind();
            if (!shader.SetVariable("time", _time))
            {
                shader.Unbind();
                return(false);
            }
            _screenVectors.Render(from.Texture);

            if (oldShader != null)
            {
                oldShader.Bind();
            }
            else
            {
                shader.Unbind();
            }

            return(true);
        }
Example #5
0
        public static bool InitVBE(BaseHardwareAbstraction hal)
        {
            if (!VBE.IsVBEAvailable)
            {
                return(false);
            }

            uint memorySize = (uint)(VBE.ScreenWidth * VBE.ScreenHeight * (VBE.BitsPerPixel / 8));

            _lfb = hal.GetPhysicalMemory((uint)VBE.MemoryPhysicalLocation.ToInt32(), memorySize);

            switch (VBE.BitsPerPixel)
            {
            case 8: Framebuffer = new FrameBuffer8bpp(_lfb, VBE.ScreenWidth, VBE.ScreenHeight, 0, VBE.Pitch); break;

            case 16: Framebuffer = new FrameBuffer16bpp(_lfb, VBE.ScreenWidth, VBE.ScreenHeight, 0, VBE.Pitch); break;

            case 24: Framebuffer = new FrameBuffer24bpp(_lfb, VBE.ScreenWidth, VBE.ScreenHeight, 0, VBE.Pitch); break;

            case 32: Framebuffer = new FrameBuffer32bpp(_lfb, VBE.ScreenWidth, VBE.ScreenHeight, 0, VBE.Pitch); break;

            default:
                return(false);
            }

            return(true);
        }
Example #6
0
        /// <summary>
        /// Sets the mode.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <returns></returns>
        public bool SetMode(ushort width, ushort height)
        {
            this.width  = width;
            this.height = height;

            SendCommand(Register.Width, width);
            SendCommand(Register.Height, height);
            SendCommand(Register.Enable, 1);

            offset = GetValue(Register.FrameBufferOffset);

            SendCommand(Register.GuestID, 0x5010);             // ??
            bytesPerLine = GetValue(Register.BytesPerLine);

            switch (bitsPerPixel)
            {
            case 8: frameBuffer = new FrameBuffer8bpp(memory, width, height, offset, bytesPerLine); break;

            case 16: frameBuffer = new FrameBuffer16bpp(memory, width, height, offset, bytesPerLine); break;

            case 24: frameBuffer = new FrameBuffer24bpp(memory, width, height, offset, bytesPerLine); break;

            case 32: frameBuffer = new FrameBuffer32bpp(memory, width, height, offset, bytesPerLine); break;

            default: return(false);
            }

            return(true);
        }
Example #7
0
        public void EndFrame()
        {
            if (doRender.Count == 0)
            {
                return;
            }

            Sheet        currentSheet = null;
            IFrameBuffer fbo          = null;

            foreach (var v in doRender)
            {
                // Change sheet
                if (v.First != currentSheet)
                {
                    if (fbo != null)
                    {
                        DisableFrameBuffer(fbo);
                    }

                    currentSheet = v.First;
                    fbo          = EnableFrameBuffer(currentSheet);
                }

                v.Second();
            }

            if (fbo != null)
            {
                DisableFrameBuffer(fbo);
            }
        }
Example #8
0
        /// <summary>
        /// Sets the mode.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <returns></returns>
        public bool SetMode(ushort width, ushort height)
        {
            this.width  = width;
            this.height = height;

            // set height  & width
            SendCommand(Register.Height, height);
            SendCommand(Register.Width, width);
            SendCommand(Register.BitsPerPixel, 32);
            SendCommand(Register.Enable, 1);

            // use the host's bits per pixel
            bitsPerPixel = 32;             // ReadRegister(Register.BitsPerPixel);

            // get the frame buffer offset
            offset = ReadRegister(Register.FrameBufferOffset);

            // get the bytes per line (pitch)
            bytesPerLine = ReadRegister(Register.BytesPerLine);

            switch (bitsPerPixel)
            {
            case 8: frameBuffer = new FrameBuffer8bpp(memory, width, height, offset, 1); break;

            case 16: frameBuffer = new FrameBuffer16bpp(memory, width, height, offset, 2); break;

            case 24: frameBuffer = new FrameBuffer24bpp(memory, width, height, offset, 3); break;

            case 32: frameBuffer = new FrameBuffer32bpp(memory, width, height, offset, 4); break;

            default: return(false);
            }

            return(true);
        }
Example #9
0
        public void RenderBorderBack(ISquare square)
        {
            if (_glUtils.DrawQuad(_frameBuffer, square, _quad))
            {
                return;
            }

            float    width      = _settings.VirtualResolution.Width;
            float    height     = _settings.VirtualResolution.Height;
            IGLColor color      = IsSelected ? _selectedColor : _color;
            IGLColor foldColor  = IsSelected ? _selectedFoldColor : _foldColor;
            float    foldHeight = height * (1f / 5f);
            PointF   foldBottom = new PointF(width / 2f, foldHeight);

            _frameBuffer = _glUtils.BeginFrameBuffer(square, _settings);
            _glUtils.DrawQuad(0, new Vector3(0, height, 0), new Vector3(width, height, 0),
                              new Vector3(), new Vector3(width, 0, 0),
                              color, color, color, color);

            _glUtils.DrawTriangle(0, new GLVertex[] { new GLVertex(new Vector2(), _emptyVector, foldColor),
                                                      new GLVertex(foldBottom.ToVector2(), _emptyVector, foldColor), new GLVertex(new Vector2(width, 0), _emptyVector, foldColor) });
            _frameBuffer.End();

            _glUtils.DrawQuad(_frameBuffer, square, _quad);
        }
Example #10
0
        public void RenderBorderBack(ISquare square)
        {
            if (_glUtils.DrawQuad(_frameBuffer, square, _quad))
            {
                return;
            }

            float    width      = _settings.VirtualResolution.Width;
            float    height     = _settings.VirtualResolution.Height;
            float    foldWidth  = (width) * (1f / 5f);
            float    foldHeight = (height) * (1f / 5f);
            IGLColor color      = IsSelected ? _selectedColor : _color;
            IGLColor foldColor  = IsSelected ? _selectedFoldColor : _foldColor;

            Vector3 foldBottomLeft = new Vector3(width - foldWidth, foldHeight, 0);
            Vector3 foldTopLeft    = new Vector3(width - foldWidth, 0, 0);
            Vector3 foldTopRight   = new Vector3(width, foldHeight, 0);

            _frameBuffer = _glUtils.BeginFrameBuffer(square, _settings);
            _glUtils.DrawQuad(0, new Vector3(0f, height, 0), new Vector3(width - foldWidth, height, 0),
                              new Vector3(), foldTopLeft,
                              color, color, color, color);

            _glUtils.DrawQuad(0, new Vector3(width - foldWidth, height, 0), new Vector3(width, height, 0),
                              foldBottomLeft, foldTopRight,
                              color, color, color, color);

            _glUtils.DrawTriangle(0, new GLVertex[] { new GLVertex(foldBottomLeft.Xy, _emptyVector, foldColor),
                                                      new GLVertex(foldTopLeft.Xy, _emptyVector, foldColor), new GLVertex(foldTopRight.Xy, _emptyVector, foldColor) });
            _frameBuffer.End();

            _glUtils.DrawQuad(_frameBuffer, square, _quad);
        }
Example #11
0
        public static void Main()
        {
            ApplicationRuntime.Init();
            MessageManager.OnDispatchError   = OnDispatchError;
            MessageManager.OnMessageReceived = MessageReceived;

            fb = CreateFrameBuffer();
            if (fb == null)
            {
                Console.WriteLine("No Framebuffer found");
                ApplicationRuntime.Exit(0);
            }
            sur = new FramebufferSurface(fb);
            gfx = new GraphicsAdapter(sur);
            gfx.SetSource(0x00115F9F);
            gfx.Rectangle(0, 0, sur.Width, sur.Height);
            gfx.Fill();

            SysCalls.RegisterService(SysCallTarget.Tmp_DisplayServer_CreateWindow);
            SysCalls.RegisterService(SysCallTarget.Tmp_DisplayServer_FlushWindow);
            SysCalls.SetServiceStatus(ServiceStatus.Ready);

            Console.WriteLine("DisplayServer ready");

            while (true)
            {
                SysCalls.ThreadSleep(0);
            }
        }
Example #12
0
        public void BeginFrame(int2 scroll, float zoom)
        {
            Context.Clear();

            var surfaceSize       = Window.SurfaceSize;
            var surfaceBufferSize = surfaceSize.NextPowerOf2();

            if (screenSprite == null || screenSprite.Sheet.Size != surfaceBufferSize)
            {
                if (screenBuffer != null)
                {
                    screenBuffer.Dispose();
                }

                // Render the screen into a frame buffer to simplify reading back screenshots
                screenBuffer = Context.CreateFrameBuffer(surfaceBufferSize, Color.FromArgb(0xFF, 0, 0, 0));
            }

            if (screenSprite == null || surfaceSize.Width != screenSprite.Bounds.Width || -surfaceSize.Height != screenSprite.Bounds.Height)
            {
                var screenSheet = new Sheet(SheetType.BGRA, screenBuffer.Texture);

                // Flip sprite in Y to match OpenGL's bottom-left origin
                var screenBounds = Rectangle.FromLTRB(0, surfaceSize.Height, surfaceSize.Width, 0);
                screenSprite = new Sprite(screenSheet, screenBounds, TextureChannel.RGBA);
            }

            screenBuffer.Bind();
            SetViewportParams(scroll, zoom);
        }
Example #13
0
        public static bool InitVBE(BaseHardwareAbstraction hal)
        {
            if (!Multiboot.IsMultibootEnabled)
            {
                return(false);
            }

            if (!Multiboot.VBEPresent)
            {
                return(false);
            }

            VBEMode vbeInfo = Multiboot.VBEModeInfoStructure;

            uint memorySize = (uint)(vbeInfo.ScreenWidth * vbeInfo.ScreenHeight * (vbeInfo.BitsPerPixel / 8));

            _lfb = hal.RequestPhysicalMemory(vbeInfo.MemoryPhysicalLocation, memorySize);

            switch (vbeInfo.BitsPerPixel)
            {
            case 8: Framebuffer = new FrameBuffer8bpp(_lfb, vbeInfo.ScreenWidth, vbeInfo.ScreenHeight, 0, vbeInfo.Pitch); break;

            case 16: Framebuffer = new FrameBuffer16bpp(_lfb, vbeInfo.ScreenWidth, vbeInfo.ScreenHeight, 0, vbeInfo.Pitch); break;

            case 24: Framebuffer = new FrameBuffer24bpp(_lfb, vbeInfo.ScreenWidth, vbeInfo.ScreenHeight, 0, vbeInfo.Pitch); break;

            case 32: Framebuffer = new FrameBuffer32bpp(_lfb, vbeInfo.ScreenWidth, vbeInfo.ScreenHeight, 0, vbeInfo.Pitch); break;

            default:
                return(false);
            }

            return(true);
        }
        public bool RenderTransition(IFrameBuffer from, IFrameBuffer to)
        {
            if (_tweenX.Task.IsCompleted && _tweenY.Task.IsCompleted)
            {
                return(false);
            }
            if (!_tweenX.Task.IsCompleted)
            {
                _visitTweenX();
            }
            if (!_tweenY.Task.IsCompleted)
            {
                _visitTweenY();
            }

            var quad = new QuadVectors(_x, _y, _width, _height, _glUtils);

            if (_slideIn)
            {
                _screenVectors.Render(from.Texture);
                quad.Render(to.Texture);
            }
            else
            {
                _screenVectors.Render(to.Texture);
                quad.Render(from.Texture);
            }
            return(true);
        }
 public ThreadedFrameBuffer(ThreadedGraphicsContext device, IFrameBuffer frameBuffer)
 {
     this.device = device;
     getTexture  = () => frameBuffer.Texture;
     bind        = frameBuffer.Bind;
     unbind      = frameBuffer.Unbind;
     dispose     = frameBuffer.Dispose;
 }
Example #16
0
 public FramebufferSurface(IFrameBuffer dev)
 {
     Dev     = dev;
     _addr   = dev.Addr;
     _Width  = dev.Width;
     _Height = dev.Height;
     _Depth  = dev.Depth;
     _Pitch  = dev.Pitch;
 }
Example #17
0
        /// <summary>
        /// Creates a new GraphicContext from <seealso cref="IFrameBuffer"/>
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        public static GraphicContext FromBuffer(IFrameBuffer buffer)
        {
            var c = new GraphicContext();

            c._buffer = buffer;
            c.OffSet  = new Point(0, 0);
            c.Size    = new Size(buffer.Width, buffer.Height);

            return(c);
        }
Example #18
0
        private IFrameBuffer renderToBuffer(IRoom room)
        {
            TypedParameter sizeParam   = new TypedParameter(typeof(Size), _game.Settings.WindowSize);
            IFrameBuffer   frameBuffer = _resolver.Container.Resolve <IFrameBuffer>(sizeParam);

            frameBuffer.Begin();
            renderRoom(room);
            frameBuffer.End();
            return(frameBuffer);
        }
Example #19
0
 public bool RenderTransition(IFrameBuffer from, IFrameBuffer to)
 {
     if (_tween.Task.IsCompleted)
     {
         return(false);
     }
     _visitTween();
     _screenVectors.Render(to.Texture);
     _screenVectors.Render(from.Texture, a: _alpha);
     return(true);
 }
		public bool RenderTransition(IFrameBuffer from, IFrameBuffer to)
		{
			if (_tween.Task.IsCompleted)
			{
				return false;
			}
			_visitTween();
			_screenVectors.Render(to.Texture);
			_screenVectors.Render(from.Texture, a: _alpha);
			return true;
		}
Example #21
0
        public ThreadedFrameBuffer(ThreadedGraphicsContext device, IFrameBuffer frameBuffer)
        {
            this.device = device;
            getTexture  = () => frameBuffer.Texture;
            bind        = frameBuffer.Bind;
            unbind      = frameBuffer.Unbind;
            dispose     = frameBuffer.Dispose;

            enableScissor  = rect => frameBuffer.EnableScissor((Rectangle)rect);
            disableScissor = frameBuffer.DisableScissor;
        }
        private IFrameBuffer renderToBuffer()
        {
            TypedParameter sizeParam = new TypedParameter(typeof(Size), new Size(
                                                              (int)_window.AppWindowWidth, (int)_window.AppWindowHeight));
            IFrameBuffer frameBuffer = _resolver.Container.Resolve <IFrameBuffer>(sizeParam);

            frameBuffer.Begin();
            _rendererLoop.Tick();
            frameBuffer.End();
            return(frameBuffer);
        }
Example #23
0
        public void RenderBorderBack(ISquare square)
        {
            if (_glUtils.DrawQuad(_frameBuffer, square, _quad))
            {
                return;
            }

            float width           = _settings.VirtualResolution.Width;
            float height          = _settings.VirtualResolution.Height;
            float arrowWidth      = width * (1f / 2f);
            float arrowHeight     = height * (1f / 2f);
            float remainingWidth  = width - arrowWidth;
            float remainingHeight = height - arrowHeight;

            PointF point1, point2, point3;

            switch (Direction)
            {
            case ArrowDirection.Right:
                point1 = new PointF(remainingWidth / 2f, remainingHeight / 2f);          // square.TopLeft + new PointF(remainingWidth / 2f, -remainingHeight / 2f);
                point2 = new PointF(remainingWidth / 2f, height - remainingHeight / 2f); //square.BottomLeft + new PointF(remainingWidth / 2f, remainingHeight / 2f);
                point3 = new PointF(width - remainingWidth / 2f, height / 2f);           //square.BottomRight + new PointF(-remainingWidth / 2f, height / 2f);
                break;

            case ArrowDirection.Down:
                point1 = new PointF(remainingWidth / 2f, remainingHeight / 2f);
                point2 = new PointF(width / 2f, height - remainingHeight / 2f);
                point3 = new PointF(width - remainingWidth / 2f, remainingHeight / 2f);
                break;

            case ArrowDirection.Left:
                point1 = new PointF(width - remainingWidth / 2f, height - remainingHeight / 2f);
                point2 = new PointF(width - remainingWidth / 2f, remainingHeight / 2f);
                point3 = new PointF(remainingWidth / 2f, height / 2f);
                break;

            case ArrowDirection.Up:
                point1 = new PointF(remainingWidth / 2f, height - remainingHeight / 2f);
                point2 = new PointF(width / 2f, remainingHeight / 2f);
                point3 = new PointF(width - remainingWidth / 2f, height - remainingHeight / 2f);
                break;

            default: throw new NotSupportedException(Direction.ToString());
            }

            _frameBuffer = _glUtils.BeginFrameBuffer(square, _settings);
            _glUtils.DrawTriangle(0, new GLVertex[] { new GLVertex((point1).ToVector2(), _emptyVector, ArrowColor),
                                                      new GLVertex((point2).ToVector2(), _emptyVector, ArrowColor), new GLVertex((point3).ToVector2(), _emptyVector, ArrowColor) });
            _frameBuffer.End();

            _glUtils.DrawQuad(_frameBuffer, square, _quad);
        }
        public override void DoStart()
        {
            snapshotFrameInterval = 1;
            if (_constStateService.IsVideoMode)
            {
                snapshotFrameInterval = _constStateService.SnapshotFrameInterval;
            }

            _cmdBuffer  = new FrameBuffer(this, _networkService, 2000, snapshotFrameInterval, MaxPredictFrameCount);
            _world      = new World();
            _dumpHelper = new DumpHelper(_serviceContainer, _world);
            _hashHelper = new HashHelper(_serviceContainer, _world, _networkService, _cmdBuffer);
        }
Example #25
0
 public bool DrawQuad(IFrameBuffer frameBuffer, AGSBoundingBox square, GLVertex[] vertices)
 {
     if (frameBuffer == null)
     {
         return(false);
     }
     vertices[0] = new GLVertex(square.BottomLeft.Xy, _bottomLeft, Colors.White);
     vertices[1] = new GLVertex(square.BottomRight.Xy, _bottomRight, Colors.White);
     vertices[2] = new GLVertex(square.TopRight.Xy, _topRight, Colors.White);
     vertices[3] = new GLVertex(square.TopLeft.Xy, _topLeft, Colors.White);
     DrawQuad(frameBuffer.Texture.ID, vertices);
     return(true);
 }
Example #26
0
        /// <summary>
        /// Get a Image from IFrameBuffer with specific Bounds example from Display
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="rec"></param>
        /// <returns></returns>
        public static Image FromBuffer(IFrameBuffer buffer, Rectangle rec)
        {
            var img = new Image(rec.Size.Width, rec.Size.Height);

            for (uint x = rec.Location.X; x < rec.Size.Width; x++)
            {
                for (uint y = rec.Location.Y; y < rec.Size.Height; y++)
                {
                    img.SetPixel(x, y, buffer.GetPixel(x, y));
                }
            }

            return(img);
        }
Example #27
0
        /// <summary>Draws the string.</summary>
        public void DrawString(IFrameBuffer frameBuffer, uint color, uint x, uint y, string text)
        {
            int size8 = size / 8;

            string[] lines = text.Split('\n');

            for (int l = 0; l < lines.Length; l++)
            {
                int usedX = 0;
                for (int i = 0; i < lines[l].Length; i++)
                {
                    char c     = lines[l][i];
                    int  index = charset.IndexOf(c);

                    if (index < 0)
                    {
                        usedX += size / 2;
                        continue;
                    }

                    int maxX = 0, sizePerFont = size * size8 * index, X = usedX + (int)x, Y = (int)y + size * l;

                    for (int h = 0; h < size; h++)
                    {
                        for (int aw = 0; aw < size8; aw++)
                        {
                            for (int ww = 0; ww < 8; ww++)
                            {
                                if ((buffer[sizePerFont + (h * size8) + aw] & (0x80 >> ww)) != 0)
                                {
                                    int max = (aw * 8) + ww;

                                    int xx = X + max;
                                    int yy = Y + h;

                                    frameBuffer.SetPixel(color, (uint)xx, (uint)yy);

                                    if (max > maxX)
                                    {
                                        maxX = max;
                                    }
                                }
                            }
                        }
                    }

                    usedX += maxX + 2;
                }
            }
        }
		public bool RenderTransition(IFrameBuffer from, IFrameBuffer to)
		{
			if (_tween.Task.IsCompleted)
			{
				if (_isFadeIn)
				{
					_isFadeIn = false;
					return false;
				}
				_isFadeIn = true;
				_tween = Tween.RunWithExternalVisit(0f, 1f, b => _black = b, _timeInSeconds, _easingFadeIn, out _visitTween);
			}
			_visitTween();
			_screenVectors.Render(_isFadeIn ? to.Texture : from.Texture, _black, _black, _black);
			return true;
		}
Example #29
0
 public bool RenderTransition(IFrameBuffer from, IFrameBuffer to)
 {
     if (_tween.Task.IsCompleted)
     {
         if (_isFadeIn)
         {
             _isFadeIn = false;
             return(false);
         }
         _isFadeIn = true;
         _tween    = Tween.RunWithExternalVisit(0f, 1f, b => _black = b, _timeInSeconds, _easingFadeIn, out _visitTween);
     }
     _visitTween();
     _screenVectors.Render(_isFadeIn ? to.Texture : from.Texture, _black, _black, _black);
     return(true);
 }
Example #30
0
        public override void DoStart()
        {
            this.snapshotFrameInterval = 1;
            bool isVideoMode = this._globalStateService.IsVideoMode;

            if (isVideoMode)
            {
                this.snapshotFrameInterval = this._globalStateService.SnapshotFrameInterval;
            }
            this._cmdBuffer = new FrameBuffer(this, this._networkService, 2000, this.snapshotFrameInterval, 30);
            object contexts        = this._globalStateService.Contexts;
            object logicFeatureObj = this._ecsFactoryService.CreateSystems(contexts, this._serviceContainer);

            this._world      = (this.FuncCreateWorld(this._serviceContainer, contexts, logicFeatureObj) as World);
            this._hashHelper = new HashHelper(this._serviceContainer, this._world, this._networkService, this._cmdBuffer);
            this._dumpHelper = new DumpHelper(this._serviceContainer, this._world, this._hashHelper);
        }
Example #31
0
        public void BeginWorld(Rectangle worldViewport)
        {
            if (renderType != RenderType.None)
            {
                throw new InvalidOperationException("BeginWorld called with renderType = {0}, expected RenderType.None.".F(renderType));
            }

            BeginFrame();

            var worldBufferSize = worldViewport.Size.NextPowerOf2();

            if (worldSprite == null || worldSprite.Sheet.Size != worldBufferSize)
            {
                if (worldBuffer != null)
                {
                    worldBuffer.Dispose();
                }

                // Render the world into a framebuffer at 1:1 scaling to allow the depth buffer to match the artwork at all zoom levels
                worldBuffer = Context.CreateFrameBuffer(worldBufferSize);

                // Pixel art scaling mode is a customized bilinear sampling
                worldBuffer.Texture.ScaleFilter = TextureScaleFilter.Linear;
            }

            if (worldSprite == null || worldViewport.Size != worldSprite.Bounds.Size)
            {
                var worldSheet = new Sheet(SheetType.BGRA, worldBuffer.Texture);
                worldSprite = new Sprite(worldSheet, new Rectangle(int2.Zero, worldViewport.Size), TextureChannel.RGBA);
            }

            worldBuffer.Bind();

            if (worldBufferSize != lastWorldBufferSize || lastWorldViewport != worldViewport)
            {
                var depthScale = worldBufferSize.Height / (worldBufferSize.Height + depthMargin);
                WorldSpriteRenderer.SetViewportParams(worldBufferSize, depthScale, depthScale / 2, worldViewport.Location);
                WorldModelRenderer.SetViewportParams(worldBufferSize, worldViewport.Location);

                lastWorldViewport   = worldViewport;
                lastWorldBufferSize = worldBufferSize;
            }

            renderType = RenderType.World;
        }
Example #32
0
        /// <summary>Sets the mode.</summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitsPerPixel">
        /// If bitsPerPixel=0, then HostBitsPerPixel is used automatically.
        /// If bitsPerPixel!=0, then the requested bitsPerPixel is used.
        /// </param>
        public bool SVGASetMode(ushort width, ushort height, byte bitsPerPixel = 0)
        {
            this.width  = width;
            this.height = height;

            if (bitsPerPixel == 0)
            {
                // use the host's bits per pixel
                this.bitsPerPixel = SVGAGetRegister(SVGA_REGISTERS.HostBitsPerPixel);
            }
            else
            {
                // use the requested bits per pixel
                this.bitsPerPixel = bitsPerPixel;
            }

            // set height  & width
            SVGASetRegister(SVGA_REGISTERS.Width, this.width);
            SVGASetRegister(SVGA_REGISTERS.Height, this.height);
            SVGASetRegister(SVGA_REGISTERS.BitsPerPixel, this.bitsPerPixel);
            SVGASetRegister(SVGA_REGISTERS.Enable, 1);
            SVGASetRegister(SVGA_REGISTERS.ConfigDone, 1);

            // get the frame buffer offset
            offset = SVGAGetRegister(SVGA_REGISTERS.FrameBufferOffset);

            // get the bytes per line (pitch)
            bytesPerLine = SVGAGetRegister(SVGA_REGISTERS.BytesPerLine);

            switch (this.bitsPerPixel)
            {
            case 8: frameBuffer = new FrameBuffer8bpp(memory, width, height, offset, bytesPerLine, false); break;

            case 16: frameBuffer = new FrameBuffer16bpp(memory, width, height, offset, bytesPerLine, false); break;

            case 24: frameBuffer = new FrameBuffer24bpp(memory, width, height, offset, bytesPerLine, false); break;

            case 32: frameBuffer = new FrameBuffer32bpp(memory, width, height, offset, bytesPerLine, false); break;

            default: return(false);
            }

            return(true);
        }
        public void EndFrame()
        {
            if (!isInFrame)
            {
                throw new InvalidOperationException("BeginFrame has not been called. There is no frame to end.");
            }

            isInFrame            = false;
            sheetBuilderForFrame = null;

            if (doRender.Count == 0)
            {
                return;
            }

            Sheet        currentSheet = null;
            IFrameBuffer fbo          = null;

            foreach (var v in doRender)
            {
                // Change sheet
                if (v.First != currentSheet)
                {
                    if (fbo != null)
                    {
                        DisableFrameBuffer(fbo);
                    }

                    currentSheet = v.First;
                    fbo          = EnableFrameBuffer(currentSheet);
                }

                v.Second();
            }

            if (fbo != null)
            {
                DisableFrameBuffer(fbo);
            }

            doRender.Clear();
        }
		public bool RenderTransition(IFrameBuffer from, IFrameBuffer to)
		{
			if (_tweenX.Task.IsCompleted && _tweenY.Task.IsCompleted)
			{
				return false;
			}
			if (!_tweenX.Task.IsCompleted) _visitTweenX();
			if (!_tweenY.Task.IsCompleted) _visitTweenY();

			var quad = new QuadVectors (_x, _y, _width, _height, _glUtils);
			if (_slideIn)
			{
				_screenVectors.Render(from.Texture);
				quad.Render(to.Texture);
			}
			else
			{
				_screenVectors.Render(to.Texture);
				quad.Render(from.Texture);
			}
			return true;
		}
		public bool RenderTransition(IFrameBuffer from, IFrameBuffer to)
		{
			if (_tweenWidth.Task.IsCompleted)
			{
				if (_isBoxIn)
				{
					_isBoxIn = false;
					return false;
				}
				_isBoxIn = true;
				_tweenWidth = Tween.RunWithExternalVisit(0f, _screenWidth, f => _boxWidth = f, _timeInSeconds, _easingBoxIn, out _visitTweenWidth);
				Tween.RunWithExternalVisit(0f, _screenHeight, f => _boxHeight = f, _timeInSeconds, _easingBoxIn, out _visitTweenHeight);
			}

			_visitTweenWidth();
			_visitTweenHeight();

			if (_isBoxIn)
			{
				_screenVectors.Render(to.Texture);

				float x = _screenHalfWidth - _boxWidth / 2;
				float y = _screenHalfHeight - _boxHeight / 2;
                QuadVectors left = new QuadVectors (0f, 0f, x, _screenHeight, _glUtils);
                QuadVectors right = new QuadVectors (_screenWidth - x, 0f, x, _screenHeight, _glUtils);
                QuadVectors top = new QuadVectors (0f, 0f, _screenWidth, y, _glUtils);
                QuadVectors bottom = new QuadVectors (0f, _screenHeight - y, _screenWidth, y, _glUtils);
				renderBlackQuads(left, right, top, bottom);
			}
			else
			{
				_screenVectors.Render(from.Texture);
				QuadVectors quad = new QuadVectors (_screenHalfWidth - _boxWidth / 2, _screenHalfHeight - _boxHeight / 2, 
                                                    _boxWidth, _boxHeight, _glUtils);
				renderBlackQuads(quad);
			}
			return true;
		}
Example #36
0
		public bool Tick ()
		{
            if (_gameState.Room == null) return false;
			IRoom room = _gameState.Room;

			switch (_roomTransitions.State)
			{
				case RoomTransitionState.NotInTransition:
					activateShader();
					renderRoom(room);
					break;
				case RoomTransitionState.BeforeLeavingRoom:
                    if (_roomTransitions.Transition == null)
                    {
                        _roomTransitions.State = RoomTransitionState.NotInTransition;
                        return false;
                    }
                    else if (_gameState.Cutscene.IsSkipping)
                    {
                        _roomTransitions.State = RoomTransitionState.PreparingTransition;
                        return false;
                    }
					else if (!_roomTransitions.Transition.RenderBeforeLeavingRoom(getDisplayList(room), obj => renderObject(room, obj)))
					{
						if (_fromTransitionBuffer == null) _fromTransitionBuffer = renderToBuffer(room);
						_roomTransitions.State = RoomTransitionState.PreparingTransition;
						return false;
					}
					break;
				case RoomTransitionState.PreparingTransition:
					return false;
				case RoomTransitionState.InTransition:
                    if (_gameState.Cutscene.IsSkipping)
                    { 
                        _fromTransitionBuffer = null;
                        _toTransitionBuffer = null;
                        _roomTransitions.State = RoomTransitionState.AfterEnteringRoom;
                        return false;
                    }
					if (_toTransitionBuffer == null) _toTransitionBuffer = renderToBuffer(room);
					if (!_roomTransitions.Transition.RenderTransition(_fromTransitionBuffer, _toTransitionBuffer))
					{
						_fromTransitionBuffer = null;
						_toTransitionBuffer = null;
						_roomTransitions.State = RoomTransitionState.AfterEnteringRoom;
						return false;
					}
					break;
				case RoomTransitionState.AfterEnteringRoom:
                    if (_gameState.Cutscene.IsSkipping || !_roomTransitions.Transition.RenderAfterEnteringRoom(getDisplayList(room), obj => renderObject(room, obj)))
					{
						_roomTransitions.SetOneTimeNextTransition(null);
						_roomTransitions.State = RoomTransitionState.NotInTransition;
						return false;
					}
					break;
				default:
					throw new NotSupportedException (_roomTransitions.State.ToString());
			}
			return true;
		}
		public bool RenderTransition(IFrameBuffer from, IFrameBuffer to)
		{
			return false;
		}
Example #38
0
 public abstract bool IsFramebuffer(IFrameBuffer frameBuffer);
Example #39
0
 /* -----------------------------------------Frame Buffer-----------------------------------------------------------*/
 public abstract void BindFramebuffer(int target, IFrameBuffer frameBuffer);
Example #40
0
 public abstract void DeleteFramebuffer(IFrameBuffer frameBuffer);
Example #41
0
        /// <summary>
        /// Sets the mode.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <returns></returns>
        public bool SetMode(ushort width, ushort height)
        {
            this.width = width;
            this.height = height;

            // set heigth  & width
            SendCommand(Register.Height, height);
            SendCommand(Register.Width, width);
            SendCommand(Register.BitsPerPixel, 32);
            SendCommand(Register.Enable, 1);

            // use the host's bits per pixel
            bitsPerPixel = 32; // ReadRegister(Register.BitsPerPixel);

            // get the frame buffer offset
            offset = ReadRegister(Register.FrameBufferOffset);

            // get the bytes per line (pitch)
            bytesPerLine = ReadRegister(Register.BytesPerLine);

            switch (bitsPerPixel)
            {
                case 8: frameBuffer = new FrameBuffer8bpp(memory, width, height, offset, 1); break;
                case 16: frameBuffer = new FrameBuffer16bpp(memory, width, height, offset, 2); break;
                case 24: frameBuffer = new FrameBuffer24bpp(memory, width, height, offset, 3); break;
                case 32: frameBuffer = new FrameBuffer32bpp(memory, width, height, offset, 4); break;
                default: return false;
            }

            return true;
        }
Example #42
0
        /// <summary>
        /// Sets the mode.
        /// </summary>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <returns></returns>
        public bool SetMode(ushort width, ushort height)
        {
            this.width = width;
            this.height = height;

            SendCommand(Register.Width, width);
            SendCommand(Register.Height, height);
            SendCommand(Register.Enable, 1);

            offset = GetValue(Register.FrameBufferOffset);

            SendCommand(Register.GuestID, 0x5010); // ??
            bytesPerLine = GetValue(Register.BytesPerLine);

            switch (bitsPerPixel) {
                case 8: frameBuffer = new FrameBuffer8bpp(memory, width, height, offset, bytesPerLine); break;
                case 16: frameBuffer = new FrameBuffer16bpp(memory, width, height, offset, bytesPerLine); break;
                case 24: frameBuffer = new FrameBuffer24bpp(memory, width, height, offset, bytesPerLine); break;
                case 32: frameBuffer = new FrameBuffer32bpp(memory, width, height, offset, bytesPerLine); break;
                default: return false;
            }

            return true;
        }
Example #43
0
 void DisableFrameBuffer(IFrameBuffer fbo)
 {
     Game.Renderer.Flush();
     Game.Renderer.Device.DisableDepthBuffer();
     fbo.Unbind();
 }