public void ShaderBrokenLoad() { var shader = Engine.AssetLoader.Get <ShaderAsset>("Shaders/BrokenShader.xml"); ; Runner.ExecuteAsLoop(_ => { RenderComposer composer = Engine.Renderer.StartFrame(); // Set shader. composer.SetShader(shader.Shader); // Render a blank square. composer.RenderSprite(new Vector3(10, 10, 0), new Vector2(10, 10), Color.White); // Reset to default shader. composer.SetShader(); Engine.Renderer.EndFrame(); Runner.VerifyScreenshot(ResultDb.BrokenShader); }).WaitOne(); // Even though the shader is broken, and it doesn't specify a fallback, it should load the compat shader. Assert.True(shader.Shader != null); Assert.True(shader.IsFallback); Engine.AssetLoader.Destroy(shader.Name); }
protected override void RenderContent(RenderComposer composer) { ImGui.InputInt("Font Size", ref _size); if (ImGui.Button("Select Font")) { var explorer = new FileExplorer <FontAsset>(f => { _font = f; }); Parent.AddWindow(explorer); } if (_font == null) { return; } ImGui.Text($"Font: {_font.Font.FullName}"); ImGui.Text($"Asset Name: {_font.Name}"); if (ImGui.Checkbox("Emotion Renderer", ref _emotionRenderer)) { FontAsset.GlyphRasterizer = _emotionRenderer ? GlyphRasterizer.Emotion : GlyphRasterizer.StbTrueType; } ImGui.InputTextMultiline("Test Text", ref _testText, 200, new Vector2(200, 100)); composer.RenderString(new Vector3(0, 100, 0), Color.Black, _testText, _font.GetAtlas(_size)); }
public void ShaderFallback() { var shader = Engine.AssetLoader.Get <ShaderAsset>("Shaders/BrokenShaderWithFallback.xml"); ; Runner.ExecuteAsLoop(_ => { RenderComposer composer = Engine.Renderer.StartFrame(); // Set shader. composer.SetShader(shader.Shader); // Render a blank square. composer.RenderSprite(new Vector3(10, 10, 0), new Vector2(10, 10), Color.White); // Reset to default shader. composer.SetShader(); Engine.Renderer.EndFrame(); Runner.VerifyScreenshot(ResultDb.ShaderFallback); }).WaitOne(); // The shader should've loaded its fallback. Assert.True(shader.Shader != null); Assert.True(shader.IsFallback); Engine.AssetLoader.Destroy(shader.Name); }
public void TestDepthFromOtherFrameBuffer() { Runner.ExecuteAsLoop(_ => { FrameBuffer testBuffer = new FrameBuffer(Engine.Renderer.DrawBuffer.Size).WithColor().WithDepth(true); var shader = Engine.AssetLoader.Get <ShaderAsset>("Shaders/DepthTest.xml"); RenderComposer composer = Engine.Renderer.StartFrame(); composer.RenderTo(testBuffer); composer.ClearFrameBuffer(); composer.RenderSprite(new Vector3(0, 0, 10), new Vector2(100, 100), Color.Green); composer.RenderTo(null); composer.SetUseViewMatrix(false); composer.SetShader(shader.Shader); shader.Shader.SetUniformInt("depthTexture", 1); Texture.EnsureBound(testBuffer.DepthTexture.Pointer, 1); composer.RenderSprite(new Vector3(0, 0, 0), testBuffer.Texture.Size, Color.White, testBuffer.Texture); composer.SetShader(); composer.SetUseViewMatrix(true); composer.RenderSprite(new Vector3(20, 20, 15), new Vector2(100, 100), Color.Blue); composer.RenderSprite(new Vector3(10, 10, 0), new Vector2(100, 100), Color.Red); Engine.Renderer.EndFrame(); Runner.VerifyScreenshot(ResultDb.TestDepthFromOtherFrameBuffer); testBuffer.Dispose(); }).WaitOne(); }
public void Draw(RenderComposer composer) { Vector2 pen = Vector2.Zero; string[] assets = Engine.AssetLoader.AllAssets; for (int i = 0; i < assets.Length; i++) { if (!assets[i].Contains(".png")) { continue; } var texture = Engine.AssetLoader.Get <TextureAsset>(assets[i]); if (texture == null || texture.Texture == null) { continue; } composer.RenderSprite(pen.ToVec3(), texture.Texture.Size, Color.White, texture.Texture); pen.X += texture.Texture.Size.X; if (pen.X > 1000) { pen.Y += 500; pen.X = 0; } } }
protected override void RenderContent(RenderComposer composer) { List <Texture> textures = Texture.AllTextures; ImGui.BeginChild("Texture List", new Vector2(500, 600), true); ImGui.BeginListBox("", new Vector2(490, 580)); for (var i = 0; i < textures.Count; i++) { Texture texture = textures[i]; if (ImGui.Button($"{texture.Pointer} - {texture.CreationStack.Substring(0, Math.Min(100, texture.CreationStack.Length))}")) { _selectedTexture = texture; } } ImGui.EndListBox(); ImGui.EndChild(); ImGui.SameLine(); ImGui.BeginChild("Texture", new Vector2(600, 600), true, ImGuiWindowFlags.HorizontalScrollbar); if (_selectedTexture != null) { ImGui.Text(_selectedTexture.CreationStack); int byteSize = (int)(_selectedTexture.Size.X * _selectedTexture.Size.Y) * Gl.PixelTypeToByteCount(_selectedTexture.PixelType) * Gl.PixelFormatToComponentCount(_selectedTexture.PixelFormat); ImGui.Text( $"Dimensions: {_selectedTexture.Size}, Format: {_selectedTexture.PixelFormat}, Memory Usage: {Helpers.FormatByteAmountAsString(byteSize)}, Smooth: {_selectedTexture.Smooth}"); Tuple <Vector2, Vector2> uv = _selectedTexture.GetImGuiUV(); ImGui.Image(new IntPtr(_selectedTexture.Pointer), _selectedTexture.Size, uv.Item1, uv.Item2); } ImGui.EndChild(); }
public void DecodeBmp256() { string bmp256 = Path.Join("Assets", "Images", "256colorbmp.bmp"); byte[] bytes = File.ReadAllBytes(bmp256); Assert.True(BmpFormat.IsBmp(bytes)); byte[] decodedPixelData = BmpFormat.Decode(bytes, out BmpFileHeader fileHeader); Assert.True(decodedPixelData != null); Runner.ExecuteAsLoop(_ => { var r = new Texture( new Vector2(fileHeader.Width, fileHeader.Height), decodedPixelData, PixelFormat.Bgra ) { FlipY = true }; RenderComposer composer = Engine.Renderer.StartFrame(); composer.RenderSprite(Vector3.Zero, new Vector2(fileHeader.Width, fileHeader.Height), Color.White, r); Engine.Renderer.EndFrame(); Runner.VerifyScreenshot(ResultDb.Bmp256ColorDecode); r.Dispose(); }).WaitOne(); }
public override void Render(RenderComposer composer) { foreach (Collision.LineSegment seg in Segments) { composer.RenderLine(new Vector3(seg.PointA, 6), new Vector3(seg.PointB, 6), Color.Pink, 2); } }
public override void Render(RenderComposer composer) { if (InclineAngle != 0f) { composer.PushModelMatrix( Matrix4x4.CreateRotationZ(InclineAngle, new Vector3(Center, 0)) ); } composer.RenderSprite( Position, Size, !IsAffectedByGravityPush ? Color.White : Color.Pink, TextureAsset.Texture, null, IsFacingRight ); if (InclineAngle != 0f) { composer.PopModelMatrix(); } if (IsInteracting) { string text = Dialogues[0].DialogueLines[0]; composer.RenderString(Position + new Vector3(-30, -30, 0), Color.Black, text, Engine.AssetLoader.Get <FontAsset>("Fonts/Calibri 400.ttf").GetAtlas(16)); } //Rectangle futurePosition = new Rectangle(CollisionBox.X, CollisionBox.Y - (GravityTimer.Progress * StartingVelocityY), CollisionBox.Width, CollisionBox.Height); //composer.RenderOutline(futurePosition, Color.Green, 1); //composer.RenderOutline(CollisionBox.ToRectangle(), Color.Red, 2); }
public void FramebufferResizing() { Runner.ExecuteAsLoop(_ => { FrameBuffer testBuffer = new FrameBuffer(new Vector2(1000, 1000)).WithColor(); RenderComposer composer = Engine.Renderer.StartFrame(); composer.RenderToAndClear(testBuffer); composer.RenderSprite(new Vector3(0, 0, 0), new Vector2(1000, 1000), Color.Red); composer.RenderTo(null); composer.RenderSprite(new Vector3(0, 0, 0), new Vector2(100, 100), Color.White, testBuffer.Texture); testBuffer.Resize(new Vector2(500, 500), true); composer.RenderToAndClear(testBuffer); composer.RenderSprite(new Vector3(0, 0, 0), new Vector2(500, 500), Color.Green); composer.RenderTo(null); composer.RenderFrameBuffer(testBuffer, new Vector2(100, 100), new Vector3(100, 0, 0)); Engine.Renderer.EndFrame(); Runner.VerifyScreenshot(ResultDb.FramebufferResizing); testBuffer.Dispose(); }).WaitOne(); }
public void Render(RenderComposer composer) { for (var i = 0; i < _openWindows.Count; i++) { // Remove closed. if (!_openWindows[i].Open) { lock (_openWindows) { _openWindows[i].Dispose(); _openWindows.RemoveAt(i); i--; continue; } } // Overlap prevention on open. (kind of) var spawnOffset = new Vector2(10, 10); if (i != 0) { ImGuiWindow prev = _openWindows[i - 1]; spawnOffset = prev.Position.X + prev.Size.X * 2 > Engine.Renderer.DrawBuffer.Size.X ? new Vector2(prev.Position.X, prev.Position.Y + prev.Size.Y + 10) : new Vector2(_openWindows[i - 1].Position.X + _openWindows[i - 1].Size.X + 10, _openWindows[i - 1].Position.Y); } _openWindows[i].Render(spawnOffset, composer); } }
public void RenderComposerSpriteLimit() { Runner.ExecuteAsLoop(_ => { RenderComposer composer = Engine.Renderer.StartFrame(); const int count = ushort.MaxValue * 2; const int size = 1; var y = 0; var x = 0; var elements = 0; while (elements < count) { var c = new Color(elements, 255 - elements, elements < ushort.MaxValue ? 255 : 0); composer.RenderSprite(new Vector3(x * size, y * size, 0), new Vector2(size, size), c); x++; elements++; if (x * size < Engine.Renderer.CurrentTarget.Size.X) { continue; } y++; x = 0; } Engine.Renderer.EndFrame(); Runner.VerifyScreenshot(ResultDb.RenderComposerSpriteLimitTest); }).WaitOne(); }
public void Draw(RenderComposer composer) { // The vertices were taken from a font, and the polygon is huge. composer.PushModelMatrix(Matrix4x4.CreateScale(0.1f, 0.1f, 1f)); composer.SetStencilTest(true); composer.StencilWindingStart(); composer.ToggleRenderColor(false); // Draw all of them together. Winding will take care of the overlap. var accum = Rectangle.Empty; for (var i = 0; i < _testPolygon.Length; i++) { composer.RenderVertices(_testPolygon[i].Vertices, Color.White); accum = accum.Union(_testPolygon[i].Bounds2D); } composer.StencilWindingEnd(); composer.ToggleRenderColor(true); // You need one quad which covers the bounds of all the polygons. // In this case I added the bounding boxes, but you could just draw a screen sized quad. composer.RenderSprite(accum, Color.Red); composer.SetStencilTest(false); composer.PopModelMatrix(); }
public void Draw(RenderComposer composer) { composer.RenderToAndClear(_fbo); composer.SetUseViewMatrix(false); composer.RenderSprite(new Vector3(0, 0, 0), new Vector2(100, 100), new Color(_currentRedValue, (byte)50, (byte)50)); composer.RenderTo(null); composer.SetUseViewMatrix(true); composer.RenderSprite(new Vector3(10, -50, 0), new Vector2(100, 100), new Color(_currentRedValue, (byte)50, (byte)50)); if (_asyncSample) { if (_sampleReq == null || _sampleReq.Finished) { if (_sampleReq != null && _sampleReq.Finished) { _lastColorResult = new Color(_sampleReq.Data[0], _sampleReq.Data[1], _sampleReq.Data[2], _sampleReq.Data[3]); } _sampleReq = _fbo.SampleAsync(new Rectangle(0, 0, 1, 1), OpenGL.PixelFormat.Rgba); } } else { byte[] sampleReq = _fbo.Sample(new Rectangle(0, 0, 1, 1), OpenGL.PixelFormat.Rgba); _lastColorResult = new Color(sampleReq[0], sampleReq[1], sampleReq[2], sampleReq[3]); } composer.RenderSprite(new Vector3(-100, -50, 10), new Vector2(100, 100), _lastColorResult); }
public override void Draw(RenderComposer composer) { Color textCol = new Color(32, 32, 32); int size = 20; string text = "The quick brown fox jumped over the lazy dog."; composer.SetUseViewMatrix(false); composer.RenderSprite(new Vector3(0, 0, 0), Engine.Renderer.CurrentTarget.Size, new Color(240, 240, 240)); composer.PushModelMatrix(Matrix4x4.CreateScale(1, 1, 1) * Matrix4x4.CreateTranslation(100, 100, 0)); FontAsset.GlyphRasterizer = GlyphRasterizer.Emotion; composer.RenderLine(new Vector3(0, 0, 0), new Vector3(500, 0, 0), Color.Red); composer.RenderString(new Vector3(0, 0, 0), textCol, "Emotion Renderer:\n" + text, _font.GetAtlas(size)); FontAsset.GlyphRasterizer = GlyphRasterizer.EmotionSDFVer3; composer.RenderLine(new Vector3(0, 140, 0), new Vector3(500, 140, 0), Color.Red); composer.RenderString(new Vector3(0, 140, 0), textCol, "EmotionSDFVer3:\n" + text, _font.GetAtlas(size)); FontAsset.GlyphRasterizer = GlyphRasterizer.EmotionSDFVer4; composer.RenderLine(new Vector3(0, 300, 0), new Vector3(500, 300, 0), Color.Red); composer.RenderString(new Vector3(0, 300, 0), textCol, "EmotionSDFVer4:\n" + text, _font.GetAtlas(size)); FontAsset.GlyphRasterizer = GlyphRasterizer.StbTrueType; composer.RenderLine(new Vector3(0, 450, 0), new Vector3(500, 450, 0), Color.Red); composer.RenderString(new Vector3(0, 450, 0), textCol, "StbTrueType:\n" + text, _font.GetAtlas(size)); composer.PopModelMatrix(); composer.SetUseViewMatrix(true); }
public void Draw(RenderComposer composer) { RenderMap(composer); RenderMouseOverTiles(composer); RenderGui(composer); }
protected override void RenderContent(RenderComposer composer) { ImGui.Checkbox("FadeIn", ref _fadeIn); if (_fadeIn) { ImGui.SameLine(); ImGui.DragFloat("FadeIn Duration", ref _fadeInTimestamp, 0.5f, 0.0f, _asset.Duration); } ImGui.Checkbox("FadeOut", ref _fadeOut); if (_fadeOut) { ImGui.SameLine(); ImGui.DragFloat("FadeOut Duration", ref _fadeOutTimestamp, 0.5f, 0.0f, _asset.Duration); } ImGui.Checkbox("CrossFade", ref _crossFade); if (_crossFade) { ImGui.SameLine(); ImGui.DragFloat("CrossFade Duration", ref _crossFadeTimestamp, 0.5f, 0.0f, _asset.Duration); } if (ImGui.Button("Ok")) { _trackCallback(GetTrack()); Open = false; } }
protected override bool RenderInternal(RenderComposer c) { var open = true; ImGui.SetNextWindowPos(new Vector2(0, 20), ImGuiCond.Always); ImGui.SetNextWindowSize(new Vector2(c.CurrentTarget.Size.X, 20)); ImGui.Begin(Title, ref open, ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove); RenderImGui(); RenderLayerUI(c); ImGui.End(); Position = Vector3.Zero; Size = c.CurrentTarget.Size; if (!open) { Parent?.RemoveChild(this); return(false); } EditorHelpers.RenderToolGrid(c, Position, Size, new Color(32, 32, 32), 20); Vector2 posVec2 = Position.ToVec2(); c.RenderLine(posVec2 + new Vector2(Size.X / 2, 0), posVec2 + new Vector2(Size.X / 2, Size.Y), Color.White * 0.7f); c.RenderLine(posVec2 + new Vector2(0, Size.Y / 2), posVec2 + new Vector2(Size.X, Size.Y / 2), Color.White * 0.7f); c.SetUseViewMatrix(true); _map?.Render(c); c.SetUseViewMatrix(false); return(true); }
public override void Draw(RenderComposer composer) { composer.SetUseViewMatrix(false); composer.RenderSprite(new Vector3(0, 0, 0), Engine.Renderer.CurrentTarget.Size, Color.CornflowerBlue); composer.SetUseViewMatrix(true); foreach (RopeSimConnection2D p in _connections) { composer.RenderLine((p.Start.Position + new Vector2(_circleRadius)).ToVec3(), (p.End.Position + new Vector2(_circleRadius)).ToVec3(), Color.White); } if (_dragging != null) { Vector2 worldMouse = Engine.Renderer.Camera.ScreenToWorld(Engine.Host.MousePosition); composer.RenderLine((_dragging.Position + new Vector2(_circleRadius)).ToVec3(), worldMouse.ToVec3(), Color.Red); } if (_draggingCut != Vector2.Zero) { Vector2 worldMouse = Engine.Renderer.Camera.ScreenToWorld(Engine.Host.MousePosition); composer.RenderLine(_draggingCut.ToVec3(), worldMouse.ToVec3(), Color.Red); } foreach (var p in _points) { composer.RenderCircle(p.Position.ToVec3(), _circleRadius, p.Locked ? Color.Magenta : Color.Black); } }
protected override bool RenderInternal(RenderComposer composer) { if (TextureAsset == null) { return(false); } // Corners composer.RenderSprite(_topLeftDraw, _topLeftDrawSize, _calculatedColor, TextureAsset.Texture, _topLeftUV); composer.RenderSprite(_topRightDraw, _topRightDrawSize, _calculatedColor, TextureAsset.Texture, _topRightUV); composer.RenderSprite(_bottomLeftDraw, _bottomLeftDrawSize, _calculatedColor, TextureAsset.Texture, _bottomLeftUV); composer.RenderSprite(_bottomRightDraw, _bottomRightDrawSize, _calculatedColor, TextureAsset.Texture, _bottomRightUV); // Center composer.RenderSprite(_centerDraw, _centerDrawSize, _calculatedColor, TextureAsset.Texture, _centerUV); // Vertical bars DrawTileVertical(composer, _verticalBarLeftDraw, _verticalBarLeftDrawSize, _verticalBarLeftTileArea, _verticalBarLeftUV); DrawTileVertical(composer, _verticalBarRightDraw, _verticalBarRightDrawSize, _verticalBarRightTileArea, _verticalBarRightUV); // Horizontal bars DrawTileHorizontal(composer, _horizontalBarTopDraw, _horizontalBarTopDrawSize, _horizontalBarTopTileArea, _horizontalBarTopUV); DrawTileHorizontal(composer, _horizontalBarBottomDraw, _horizontalBarBottomDrawSize, _horizontalBarBottomTileArea, _horizontalBarBottomUV); return(true); }
public void DecodePngInterlaced() { string png = Path.Join("Assets", "Images", "spritesheetAnimation.png"); byte[] bytes = File.ReadAllBytes(png); Assert.True(PngFormat.IsPng(bytes)); byte[] decodedPixelData = PngFormat.Decode(bytes, out PngFileHeader fileHeader); Assert.True(decodedPixelData != null); Assert.True(fileHeader.InterlaceMethod == 1); Runner.ExecuteAsLoop(_ => { var r = new Texture( fileHeader.Size, decodedPixelData, fileHeader.PixelFormat); RenderComposer composer = Engine.Renderer.StartFrame(); composer.RenderSprite(Vector3.Zero, fileHeader.Size, Color.White, r); Engine.Renderer.EndFrame(); Runner.VerifyScreenshot(ResultDb.PngDecodeInterlaced); r.Dispose(); }).WaitOne(); }
protected override void RenderContent(RenderComposer composer) { if (ImGui.Button("Choose File")) { var explorer = new FileExplorer <TextAsset>(LoadFile); Parent.AddWindow(explorer); } ImGui.Text($"Current File: {_file?.Name ?? "None"}"); if (_file == null) { return; } if (ImGui.Button("Reload")) { LoadFile(FileExplorer <TextAsset> .ExplorerLoadAsset(_file.Name)); } ImGui.Text("Tile Layers"); for (var i = 0; i < _map.TiledMap.TileLayers.Count; i++) { TmxLayer curLayer = _map.TiledMap.TileLayers[i]; ImGui.Text($"{curLayer.Name} {curLayer.Width}x{curLayer.Height}" + (curLayer.Visible ? "" : " Hidden")); } composer.SetUseViewMatrix(true); composer.Render(_map); }
public void TestUVMapping() { var asset = Engine.AssetLoader.Get <TextureAsset>("Images/logoAsymmetric.png"); Runner.ExecuteAsLoop(_ => { RenderComposer composer = Engine.Renderer.StartFrame(); composer.RenderSprite(new Vector3(10, 10, 0), new Vector2(100, 100), Color.White, asset.Texture, null, true); composer.RenderSprite(new Vector3(100, 10, 0), new Vector2(100, 100), Color.White, asset.Texture, null, false, true); composer.RenderSprite(new Vector3(200, 10, 0), new Vector2(100, 100), Color.White, asset.Texture, null, true, true); composer.FlushRenderStream(); asset.Texture.Tile = false; composer.RenderSprite(new Vector3(10, 100, 0), new Vector2(100, 100), Color.White, asset.Texture, null, true); composer.RenderSprite(new Vector3(100, 100, 0), new Vector2(100, 100), Color.White, asset.Texture, null, false, true); composer.RenderSprite(new Vector3(200, 100, 0), new Vector2(100, 100), Color.White, asset.Texture, null, true, true); composer.RenderSprite(new Vector3(10, 200, 0), new Vector2(100, 100), Color.White, asset.Texture, new Rectangle(0, 0, 50, 50), true); composer.RenderSprite(new Vector3(100, 200, 0), new Vector2(100, 100), Color.White, asset.Texture, new Rectangle(0, 0, 50, 50), false, true); composer.RenderSprite(new Vector3(200, 200, 0), new Vector2(100, 100), Color.White, asset.Texture, new Rectangle(0, 0, 50, 50), true, true); composer.FlushRenderStream(); asset.Texture.Tile = true; Engine.Renderer.EndFrame(); Runner.VerifyScreenshot(ResultDb.TestUVMapping); }).WaitOne(); }
protected override bool RenderInternal(RenderComposer c) { c.SetUseViewMatrix(false); c.RenderSprite(Vector3.Zero, c.CurrentTarget.Size, Color.CornflowerBlue); base.RenderInternal(c); _ui.Render(c); return(true); }
protected override bool RenderInternal(RenderComposer c) { if (OutlineColor != null) { c.RenderSprite(Position - _scaledOutline.ToVec3(), Size + _scaledOutline * 2, OutlineColor.Value); } c.RenderSprite(Bounds, _calculatedColor); return(true); }
public override unsafe void Render(RenderComposer composer) { var data = new Span <VertexDataSprite>((void *)_memoryPtr, _mappedTo / 4); // Temp sort until https://github.com/dotnet/corefx/issues/15329 reaches us. QuickSort(data, 0, data.Length - 1); base.Render(composer); }
public override void Render(RenderComposer composer) { // Render composer.RenderOutline( Position, Size, Color.Pink, 2 ); }
private void RenderAnimation(RenderComposer composer) { var offset = new Vector2(100, 100); if (_animation.Anchors.Length > 0) { offset += _animation.Anchors[_animation.CurrentFrameIndex] * Scale; } composer.RenderSprite(new Vector3(offset, 1), _animation.CurrentFrame.Size * Scale, Color.White, _animation.Texture, _animation.CurrentFrame, _mirrored); }
protected override void RenderContent(RenderComposer composer) { ImGui.InputText("Text: ", ref _text, 100); if (!ImGui.Button("Done")) { return; } _callback(_text); Open = false; }
public override void Render(RenderComposer composer) { base.Render(composer); //composer.RenderLine( // CollisionLine.AwithZ(Position.Z), // CollisionLine.BwithZ(Position.Z), // Color.Yellow //); }