public void SetViewportParams(int2 scroll, float zoom) { // In HiDPI windows we follow Apple's convention of defining window coordinates as for standard resolution windows // but to have a higher resolution backing surface with more than 1 texture pixel per viewport pixel. // We must convert the surface buffer size to a viewport size - in general this is NOT just the window size // rounded to the next power of two, as the NextPowerOf2 calculation is done in the surface pixel coordinates var scale = Window.WindowScale; var surfaceBufferSize = Window.SurfaceSize.NextPowerOf2(); var bufferSize = new Size((int)(surfaceBufferSize.Width / scale), (int)(surfaceBufferSize.Height / scale)); // PERF: Calling SetViewportParams on each renderer is slow. Only call it when things change. // If zoom evaluates as different due to floating point weirdness that's OK, it will be going away soon if (lastBufferSize != bufferSize || lastScroll != scroll || lastZoom != zoom) { if (lastBufferSize != bufferSize) { SpriteRenderer.SetViewportParams(bufferSize, 0f, 0f, 1f, int2.Zero); } WorldSpriteRenderer.SetViewportParams(bufferSize, depthScale, depthOffset, zoom, scroll); WorldModelRenderer.SetViewportParams(bufferSize, zoom, scroll); lastBufferSize = bufferSize; lastScroll = scroll; lastZoom = zoom; } }
public void BeginFrame(int2 scroll, float zoom) { device.Clear(); 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); } }
public void BeginFrame(float2 scroll, float zoom) { device.Clear(); WorldSpriteRenderer.SetViewportParams(Resolution, zoom, scroll); SpriteRenderer.SetViewportParams(Resolution, 1f, float2.Zero); RgbaSpriteRenderer.SetViewportParams(Resolution, 1f, float2.Zero); WorldLineRenderer.SetViewportParams(Resolution, zoom, scroll); WorldQuadRenderer.SetViewportParams(Resolution, zoom, scroll); LineRenderer.SetViewportParams(Resolution, 1f, float2.Zero); }
public void ResetSproc() { sproc.SetTexture("Palette", currentPaletteTexture); sproc.SetViewportParams(lastResolution, 0f, 0f, 1f, int2.Zero); SpriteRenderer.shader.SetTexture("Palette", currentPaletteTexture); SpriteRenderer.SetViewportParams(lastResolution, 0f, 0f, 1f, int2.Zero); WorldSpriteRenderer.shader.SetTexture("Palette", currentPaletteTexture); WorldSpriteRenderer.SetViewportParams(lastResolution, depthScale, depthOffset, lastZoom, lastScroll); FontSpriteRenderer.SetViewportParams(lastResolution, 0f, 0f, 1f, int2.Zero); }
public void SetPalette(HardwarePalette palette) { if (palette.Texture == currentPaletteTexture) { return; } Flush(); currentPaletteTexture = palette.Texture; SpriteRenderer.SetPalette(currentPaletteTexture); WorldSpriteRenderer.SetPalette(currentPaletteTexture); WorldModelRenderer.SetPalette(currentPaletteTexture); }
public void SetPalette(HardwarePalette palette) { // Note: palette.Texture and palette.ColorShifts are updated at the same time // so we only need to check one of the two to know whether we must update the textures if (palette.Texture == currentPaletteTexture) { return; } Flush(); currentPaletteTexture = palette.Texture; SpriteRenderer.SetPalette(currentPaletteTexture, palette.ColorShifts); WorldSpriteRenderer.SetPalette(currentPaletteTexture, palette.ColorShifts); WorldModelRenderer.SetPalette(currentPaletteTexture); }
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; }
public void BeginWorld(Rectangle worldViewport) { if (renderType != RenderType.None) { throw new InvalidOperationException($"BeginWorld called with renderType = {renderType}, expected RenderType.None."); } BeginFrame(); if (worldSheet == null) { throw new InvalidOperationException($"BeginWorld called before SetMaximumViewportSize has been set."); } if (worldSprite == null || worldViewport.Size != lastWorldViewportSize) { // Downscale world rendering if needed to fit within the framebuffer var vw = worldViewport.Size.Width; var vh = worldViewport.Size.Height; var bw = worldSheet.Size.Width; var bh = worldSheet.Size.Height; worldDownscaleFactor = 1; while (vw / worldDownscaleFactor > bw || vh / worldDownscaleFactor > bh) { worldDownscaleFactor++; } var s = new Size(vw / worldDownscaleFactor, vh / worldDownscaleFactor); worldSprite = new Sprite(worldSheet, new Rectangle(int2.Zero, s), TextureChannel.RGBA); lastWorldViewportSize = worldViewport.Size; } worldBuffer.Bind(); if (lastWorldViewport != worldViewport) { WorldSpriteRenderer.SetViewportParams(worldSheet.Size, worldDownscaleFactor, depthMargin, worldViewport.Location); WorldModelRenderer.SetViewportParams(worldSheet.Size, worldViewport.Location); lastWorldViewport = worldViewport; } renderType = RenderType.World; }
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; SpriteRenderer.SetViewportParams(lastResolution, 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; WorldSpriteRenderer.SetViewportParams(lastResolution, depthScale, depthOffset, zoom, scroll); WorldModelRenderer.SetViewportParams(lastResolution, zoom, scroll); } }