Example #1
0
        public void BeginUI()
        {
            if (renderType == RenderType.World)
            {
                // Complete world rendering
                Flush();
                worldBuffer.Unbind();

                // Render the world buffer into the UI buffer
                screenBuffer.Bind();

                var scale      = Window.EffectiveWindowScale;
                var bufferSize = new Size((int)(screenSprite.Bounds.Width / scale), (int)(-screenSprite.Bounds.Height / scale));

                SpriteRenderer.SetAntialiasingPixelsPerTexel(Window.SurfaceSize.Height * 1f / worldSprite.Bounds.Height);
                RgbaSpriteRenderer.DrawSprite(worldSprite, float3.Zero, new float2(bufferSize));
                Flush();
                SpriteRenderer.SetAntialiasingPixelsPerTexel(0);
            }
            else
            {
                // World rendering was skipped
                BeginFrame();
                screenBuffer.Bind();
            }

            renderType = RenderType.UI;
        }
Example #2
0
        public Renderer(DefaultPlatform platform, GraphicSettings graphicSettings)
        {
            this.platform = platform;
            var resolution = GetResolution(graphicSettings);

            Window  = platform.CreateWindow(new Size(resolution.Width, resolution.Height), graphicSettings.Mode, graphicSettings.BatchSize, Game.Settings.Graphics.DisableWindowsDPIScaling, Game.Settings.Game.LockMouseWindow, Game.Settings.Graphics.DisableWindowsRenderThread);
            Context = Window.Context;

            TempBufferSize = graphicSettings.BatchSize;
            SheetSize      = graphicSettings.SheetSize;

            WorldSpriteRenderer     = new SpriteRenderer("WorldSpriteRenderer", this, Context.CreateShader("combined"));         // каждый имеет vertex массив, VAO это tempbuffer.
            WorldRgbaSpriteRenderer = new RgbaSpriteRenderer(WorldSpriteRenderer);
            WorldRgbaColorRenderer  = new RgbaColorRenderer(WorldSpriteRenderer);
            WorldModelRenderer      = new ModelRenderer(this, Context.CreateShader("model"));                               // каждый имеет vertex массив, VAO это tempbuffer
            SpriteRenderer          = new SpriteRenderer("SpriteRenderer", this, Context.CreateShader("combined"));         // каждый имеет vertex массив, VAO это tempbuffer.
            RgbaSpriteRenderer      = new RgbaSpriteRenderer(SpriteRenderer);                                               // эти пишут в родительский VBO
            RgbaColorRenderer       = new RgbaColorRenderer(SpriteRenderer);                                                // эти пишут в родительский VBO
            FontSpriteRenderer      = new SpriteRenderer("FontSpriteRenderer", this, Context.CreateShader("text"));         // каждый имеет свой vertex массив, VAO это tempbuffer.
            ImguiSpriteRenderer     = new SpriteRenderer("ImguiSpriteRenderer", this, Context.CreateShader("combined"));    // для ImGui
            PixelDumpRenderer       = new PixelDumpRenderer("ImguiSpriteRenderer", this, Context.CreateShader("combined")); // для ImGui

            sproc = new ShaderIF_API();
            IntPtr context = ImGui.CreateContext();

            ImGui.SetCurrentContext(context);

            RendererVertexBuffer = Context.CreateVertexBuffer(TempBufferSize, "Renderer");
        }
Example #3
0
        public void EndFrame(IInputHandler inputHandler)
        {
            Flush();

            screenBuffer.Unbind();

            // Render the compositor buffer to the screen
            // HACK / PERF: Fudge the coordinates to cover the actual window while keeping the buffer viewport parameters
            // This saves us two redundant (and expensive) SetViewportParams each frame
            RgbaSpriteRenderer.DrawSprite(screenSprite, new float3(0, lastBufferSize.Height, 0), new float3(lastBufferSize.Width, -lastBufferSize.Height, 0));
            Flush();

            Window.PumpInput(inputHandler);
            Context.Present();
        }
Example #4
0
        public void SetPalette(HardwarePalette palette)
        {
            if (palette.Texture == currentPaletteTexture)
            {
                return;
            }

            Flush();
            currentPaletteTexture = palette.Texture;

            RgbaSpriteRenderer.SetPalette(currentPaletteTexture);
            SpriteRenderer.SetPalette(currentPaletteTexture);
            WorldSpriteRenderer.SetPalette(currentPaletteTexture);
            WorldRgbaSpriteRenderer.SetPalette(currentPaletteTexture);
            WorldVoxelRenderer.SetPalette(currentPaletteTexture);
        }
        public Renderer(IPlatform platform, GraphicSettings graphicSettings)
        {
            var resolution = GetResolution(graphicSettings);

            Window  = platform.CreateWindow(new Size(resolution.Width, resolution.Height), graphicSettings.Mode, graphicSettings.BatchSize);
            Context = Window.Context;

            TempBufferSize = graphicSettings.BatchSize;
            SheetSize      = graphicSettings.SheetSize;

            WorldSpriteRenderer     = new SpriteRenderer(this, Context.CreateShader("combined"));
            WorldRgbaSpriteRenderer = new RgbaSpriteRenderer(WorldSpriteRenderer);
            WorldRgbaColorRenderer  = new RgbaColorRenderer(WorldSpriteRenderer);
            WorldModelRenderer      = new ModelRenderer(this, Context.CreateShader("model"));
            SpriteRenderer          = new SpriteRenderer(this, Context.CreateShader("combined"));
            RgbaSpriteRenderer      = new RgbaSpriteRenderer(SpriteRenderer);
            RgbaColorRenderer       = new RgbaColorRenderer(SpriteRenderer);

            tempBuffer = Context.CreateVertexBuffer(TempBufferSize);
        }
Example #6
0
        public void EndFrame(IInputHandler inputHandler)
        {
            if (renderType != RenderType.UI)
            {
                throw new InvalidOperationException("EndFrame called with renderType = {0}, expected RenderType.UI.".F(renderType));
            }

            Flush();

            screenBuffer.Unbind();

            // Render the compositor buffers to the screen
            // HACK / PERF: Fudge the coordinates to cover the actual window while keeping the buffer viewport parameters
            // This saves us two redundant (and expensive) SetViewportParams each frame
            RgbaSpriteRenderer.DrawSprite(screenSprite, new float3(0, lastBufferSize.Height, 0), new float3(lastBufferSize.Width, -lastBufferSize.Height, 0));
            Flush();

            Window.PumpInput(inputHandler);
            Context.Present();

            renderType = RenderType.None;
        }
Example #7
0
        public void SetViewportParams(int2 scroll, float zoom)
        {
            // PERF: Calling SetViewportParams on each renderer is slow. Only call it when things change.
            var resolutionChanged = lastResolution != Resolution;

            if (resolutionChanged)
            {
                lastResolution = Resolution;
                RgbaSpriteRenderer.SetViewportParams(Resolution, 0f, 0f, 1f, int2.Zero);
                SpriteRenderer.SetViewportParams(Resolution, 0f, 0f, 1f, int2.Zero);
                RgbaColorRenderer.SetViewportParams(Resolution, 0f, 0f, 1f, int2.Zero);
            }

            // If zoom evaluates as different due to floating point weirdness that's OK, setting the parameters again is harmless.
            if (resolutionChanged || lastScroll != scroll || lastZoom != zoom)
            {
                lastScroll = scroll;
                lastZoom   = zoom;
                WorldRgbaSpriteRenderer.SetViewportParams(Resolution, depthScale, depthOffset, zoom, scroll);
                WorldSpriteRenderer.SetViewportParams(Resolution, depthScale, depthOffset, zoom, scroll);
                WorldVoxelRenderer.SetViewportParams(Resolution, zoom, scroll);
                WorldRgbaColorRenderer.SetViewportParams(Resolution, depthScale, depthOffset, zoom, scroll);
            }
        }
Example #8
0
        public void SetViewportParams(int2 scroll, float zoom)
        {
            var resolutionChanged = lastResolution != Resolution;

            if (resolutionChanged)
            {
                lastResolution = Resolution;
                RgbaSpriteRenderer.SetViewportParams(Resolution, 1f, int2.Zero);
                SpriteRenderer.SetViewportParams(Resolution, 1f, int2.Zero);
                LineRenderer.SetViewportParams(Resolution, 1f, int2.Zero);
            }

            // If zoom evaluates as different due to floating point weirdness that's OK, setting the parameters again is harmless.
            if (resolutionChanged || lastScroll != scroll || lastZoom != zoom)
            {
                lastScroll = scroll;
                lastZoom   = zoom;
                WorldRgbaSpriteRenderer.SetViewportParams(Resolution, zoom, scroll);
                WorldSpriteRenderer.SetViewportParams(Resolution, zoom, scroll);
                WorldVoxelRenderer.SetViewportParams(Resolution, zoom, scroll);
                WorldLineRenderer.SetViewportParams(Resolution, zoom, scroll);
                WorldQuadRenderer.SetViewportParams(Resolution, zoom, scroll);
            }
        }