Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from tannergooding/graphics
Update the graphics stack to support rendering a clear screen.
- Loading branch information
Showing
23 changed files
with
2,312 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using TerraFX.ApplicationModel; | ||
using TerraFX.Graphics; | ||
using TerraFX.UI; | ||
using TerraFX.Utilities; | ||
|
||
namespace TerraFX.Samples.Graphics | ||
{ | ||
public sealed class HelloWindow : Sample | ||
{ | ||
private IGraphicsContext? _graphicsContext; | ||
private IWindow? _window; | ||
private TimeSpan _elapsedTime; | ||
|
||
public HelloWindow(string name, params Assembly[] compositionAssemblies) | ||
: base(name, compositionAssemblies) | ||
{ | ||
} | ||
|
||
public override void OnIdle(object? sender, ApplicationIdleEventArgs eventArgs) | ||
{ | ||
ExceptionUtilities.ThrowIfNull(sender, nameof(sender)); | ||
|
||
var application = (Application)sender; | ||
|
||
if (_window is null) | ||
{ | ||
var windowProvider = application.GetService<IWindowProvider>(); | ||
_window = windowProvider.CreateWindow(); | ||
|
||
_window.Show(); | ||
} | ||
else if (_window.IsVisible) | ||
{ | ||
if (_graphicsContext is null) | ||
{ | ||
var graphicsProvider = application.GetService<IGraphicsProvider>(); | ||
var graphicsAdapter = graphicsProvider.GraphicsAdapters.First(); | ||
|
||
var graphicsSurface = _window.CreateGraphicsSurface(bufferCount: 2); | ||
_graphicsContext = graphicsAdapter.CreateGraphicsContext(graphicsSurface); | ||
} | ||
else | ||
{ | ||
_elapsedTime += eventArgs.Delta; | ||
|
||
if (_elapsedTime.TotalSeconds >= 2.5) | ||
{ | ||
application.RequestExit(); | ||
} | ||
|
||
var backgroundColor = new ColorRgba(red: 100.0f / 255.0f, green: 149.0f / 255.0f, blue: 237.0f / 255.0f, alpha: 1.0f); | ||
_graphicsContext.BeginFrame(backgroundColor); | ||
|
||
_graphicsContext.EndFrame(); | ||
_graphicsContext.PresentFrame(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"profiles": { | ||
"TerraFX.Samples.DirectX": { | ||
"TerraFX.Samples": { | ||
"commandName": "Project", | ||
"commandLineArgs": "all" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. | ||
|
||
namespace TerraFX.Graphics | ||
{ | ||
/// <summary>Defines a graphics surface kind.</summary> | ||
public enum GraphicsSurfaceKind | ||
{ | ||
/// <summary>Defines an unknown graphics surface kind that may require specialized handling.</summary> | ||
Unknown, | ||
|
||
/// <summary>Defines an Android based graphics surface.</summary> | ||
Android, | ||
|
||
/// <summary>Defines a Wayland based graphics surface.</summary> | ||
Wayland, | ||
|
||
/// <summary>Defines a Win32 based graphics surface.</summary> | ||
Win32, | ||
|
||
/// <summary>Defines an XCB based graphics surface.</summary> | ||
Xcb, | ||
|
||
/// <summary>Defines an Xlib based graphics surface.</summary> | ||
Xlib, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. | ||
|
||
namespace TerraFX.Graphics | ||
{ | ||
/// <summary>Represents a graphics context, which can be used for rendering images.</summary> | ||
public interface IGraphicsContext | ||
{ | ||
/// <summary>Gets the <see cref="IGraphicsAdapter" /> for the instance.</summary> | ||
IGraphicsAdapter GraphicsAdapter { get; } | ||
|
||
/// <summary>Gets the <see cref="IGraphicsSurface" /> for the instance.</summary> | ||
IGraphicsSurface GraphicsSurface { get; } | ||
|
||
/// <summary>Begins a new frame for rendering.</summary> | ||
/// <param name="backgroundColor">A color to which the background should be cleared.</param> | ||
void BeginFrame(ColorRgba backgroundColor); | ||
|
||
/// <summary>Ends the frame currently be rendered.</summary> | ||
void EndFrame(); | ||
|
||
/// <summary>Presents the last frame rendered.</summary> | ||
void PresentFrame(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. | ||
|
||
using System; | ||
using TerraFX.Numerics; | ||
|
||
namespace TerraFX.Graphics | ||
{ | ||
/// <summary>Represents a graphics surface.</summary> | ||
public interface IGraphicsSurface | ||
{ | ||
/// <summary>Gets the number of buffers for the instance.</summary> | ||
int BufferCount { get; } | ||
|
||
/// <summary>Gets the height of the instance.</summary> | ||
float Height => Size.Y; | ||
|
||
/// <summary>Gets the kind of surface represented by the instance.</summary> | ||
GraphicsSurfaceKind Kind { get; } | ||
|
||
/// <summary>Gets the size of the instance.</summary> | ||
Vector2 Size { get; } | ||
|
||
/// <summary>Gets the width of the instance.</summary> | ||
float Width => Size.X; | ||
|
||
/// <summary>Gets the window provider handle for the instance.</summary> | ||
IntPtr WindowProviderHandle { get; } | ||
|
||
/// <summary>Gets the window handle for the instance.</summary> | ||
IntPtr WindowHandle { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.