mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Content browser
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,272 @@
|
||||
using ImGui;
|
||||
using System;
|
||||
using System.IO;
|
||||
using GlitchyEngine.Collections;
|
||||
using System.Collections;
|
||||
using GlitchyEngine.Renderer;
|
||||
using GlitchyEngine.Math;
|
||||
|
||||
namespace GlitchyEditor.EditWindows
|
||||
{
|
||||
class ContentBrowserWindow : EditorWindow
|
||||
{
|
||||
// TODO: Get from project
|
||||
const String ContentDirectory = "./content";
|
||||
|
||||
FileSystemWatcher fsw ~ {
|
||||
_.StopRaisingEvents();
|
||||
delete _;
|
||||
};
|
||||
|
||||
private String _currentDirectory ~ delete _;
|
||||
|
||||
public static SubTexture2D s_FolderTexture;
|
||||
public static SubTexture2D s_FileTexture;
|
||||
|
||||
public this()
|
||||
{
|
||||
fsw = new FileSystemWatcher(ContentDirectory);
|
||||
fsw.IncludeSubdirectories = true;
|
||||
|
||||
fsw.OnChanged.Add(new (filename) => {
|
||||
_fileSystemDirty = true;
|
||||
_currentDirectoryDirty = true;
|
||||
});
|
||||
|
||||
fsw.OnCreated.Add(new (filename) => {
|
||||
_fileSystemDirty = true;
|
||||
_currentDirectoryDirty = true;
|
||||
});
|
||||
|
||||
fsw.OnDeleted.Add(new (filename) => {
|
||||
_fileSystemDirty = true;
|
||||
_currentDirectoryDirty = true;
|
||||
});
|
||||
|
||||
fsw.OnRenamed.Add(new (newName, oldName) => {
|
||||
_fileSystemDirty = true;
|
||||
_currentDirectoryDirty = true;
|
||||
});
|
||||
|
||||
fsw.StartRaisingEvents();
|
||||
|
||||
}
|
||||
|
||||
protected override void InternalShow()
|
||||
{
|
||||
if(!ImGui.Begin("Content Browser", &_open, .None))
|
||||
{
|
||||
ImGui.End();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_fileSystemDirty)
|
||||
{
|
||||
BuildDirectoryTree();
|
||||
|
||||
_fileSystemDirty = false;
|
||||
}
|
||||
|
||||
if (_currentDirectoryDirty)
|
||||
{
|
||||
BuildCurrentDirectory();
|
||||
}
|
||||
|
||||
ImGui.Columns(2);
|
||||
|
||||
DrawDirectorySideBar();
|
||||
|
||||
ImGui.NextColumn();
|
||||
|
||||
DrawCurrentDirectory();
|
||||
|
||||
ImGui.Columns(1);
|
||||
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
private bool _fileSystemDirty = true;
|
||||
private bool _currentDirectoryDirty = true;
|
||||
|
||||
class DirectoryNode
|
||||
{
|
||||
public String Name ~ delete _;
|
||||
public String Path ~ delete _;
|
||||
}
|
||||
|
||||
TreeNode<DirectoryNode> directoryNames = new TreeNode<DirectoryNode>() ~ DeleteTreeAndChildren!(_);
|
||||
|
||||
class Entry
|
||||
{
|
||||
public String Name ~ delete _;
|
||||
public bool IsDirectory;
|
||||
}
|
||||
|
||||
List<Entry> _currentDirContent = new .() ~ DeleteContainerAndItems!(_);
|
||||
|
||||
private void BuildDirectoryTree()
|
||||
{
|
||||
DeleteTreeAndChildren!(directoryNames);
|
||||
directoryNames = new TreeNode<DirectoryNode>();
|
||||
|
||||
String str = scope .(ContentDirectory);
|
||||
|
||||
void AddDirectoryToTree(String path, TreeNode<DirectoryNode> parentNode)
|
||||
{
|
||||
DirectoryNode node = new DirectoryNode();
|
||||
node.Path = new String(path);
|
||||
node.Name = new String();
|
||||
|
||||
Path.GetFileName(node.Path, node.Name);
|
||||
|
||||
var newNode = parentNode.AddChild(node);
|
||||
|
||||
String filter = scope $"{path}/*";
|
||||
|
||||
for (var directory in Directory.Enumerate(filter, .Directories))
|
||||
{
|
||||
directory.GetFilePath(str..Clear());
|
||||
|
||||
AddDirectoryToTree(str, newNode);
|
||||
}
|
||||
}
|
||||
|
||||
String filter = scope $"{ContentDirectory}/*";
|
||||
|
||||
for (var directory in Directory.Enumerate(filter, .Directories))
|
||||
{
|
||||
directory.GetFilePath(str..Clear());
|
||||
|
||||
AddDirectoryToTree(str, directoryNames);
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildCurrentDirectory()
|
||||
{
|
||||
ClearAndDeleteItems!(_currentDirContent);
|
||||
|
||||
String filter = scope $"{_currentDirectory}/*";
|
||||
|
||||
String buffer = scope String();
|
||||
|
||||
for (var entry in Directory.Enumerate(filter, .Directories | .Files))
|
||||
{
|
||||
entry.GetFilePath(buffer..Clear());
|
||||
|
||||
Entry e = new Entry();
|
||||
e.Name = new String();
|
||||
Path.GetFileName(buffer, e.Name);
|
||||
e.IsDirectory = entry.IsDirectory;
|
||||
|
||||
_currentDirContent.Add(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawDirectorySideBar()
|
||||
{
|
||||
for(var child in directoryNames.Children)
|
||||
{
|
||||
ImGuiPrintEntityTree(child);
|
||||
}
|
||||
}
|
||||
|
||||
private void ImGuiPrintEntityTree(TreeNode<DirectoryNode> tree)
|
||||
{
|
||||
String name = tree.Value.Name;
|
||||
|
||||
ImGui.TreeNodeFlags flags = .OpenOnArrow | .SpanAvailWidth;
|
||||
|
||||
if(tree.Children.Count == 0)
|
||||
flags |= .Leaf;
|
||||
|
||||
if (tree.Value.Path == _currentDirectory)
|
||||
{
|
||||
flags |= .Selected;
|
||||
}
|
||||
|
||||
bool isOpen = ImGui.TreeNodeEx(name, flags, $"{name}");
|
||||
|
||||
if (ImGui.IsItemClicked(.Left))
|
||||
{
|
||||
if (_currentDirectory != null)
|
||||
delete _currentDirectory;
|
||||
|
||||
_currentDirectory = new String(tree.Value.Path);
|
||||
}
|
||||
|
||||
if(isOpen)
|
||||
{
|
||||
for(var child in tree.Children)
|
||||
{
|
||||
ImGuiPrintEntityTree(child);
|
||||
}
|
||||
|
||||
ImGui.TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector2 DirectoryItemSize = .(100, 100);
|
||||
|
||||
const Vector2 padding = .(24, 24);
|
||||
|
||||
private void DrawCurrentDirectory()
|
||||
{
|
||||
ImGui.Style* style = ImGui.GetStyle();
|
||||
|
||||
float window_visible_x2 = ImGui.GetWindowPos().x + ImGui.GetWindowContentRegionMax().x;
|
||||
for (var entry in _currentDirContent)
|
||||
{
|
||||
ImGui.PushID(entry.Name);
|
||||
|
||||
DrawDirectoryItem(entry);
|
||||
|
||||
float last_button_x2 = ImGui.GetItemRectMax().x;
|
||||
float next_button_x2 = last_button_x2 + style.ItemSpacing.x + DirectoryItemSize.X; // Expected position if next button was on same line
|
||||
if (entry != _currentDirContent.Back && next_button_x2 < window_visible_x2)
|
||||
ImGui.SameLine();
|
||||
|
||||
ImGui.PopID();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawDirectoryItem(Entry entry)
|
||||
{
|
||||
ImGui.BeginChild("item", (.)DirectoryItemSize);
|
||||
|
||||
SubTexture2D image = entry.IsDirectory ? s_FolderTexture : s_FileTexture;
|
||||
|
||||
ImGui.PushStyleColor(.Button, ImGui.Vec4(0, 0, 0, 0));
|
||||
|
||||
ImGui.ImageButton(image, (.)(DirectoryItemSize - padding));
|
||||
|
||||
if (ImGui.BeginDragDropSource())
|
||||
{
|
||||
String fullpath = scope $"{_currentDirectory}{Path.DirectorySeparatorChar}{entry.Name}";
|
||||
|
||||
ImGui.SetDragDropPayload("CONTENT_BROWSER_ITEM", fullpath.CStr(), (.)fullpath.Length, .Once);
|
||||
|
||||
ImGui.EndDragDropSource();
|
||||
}
|
||||
|
||||
if (ImGui.IsItemHovered() && ImGui.IsMouseDoubleClicked(.Left))
|
||||
{
|
||||
EntryDoubleClicked(entry);
|
||||
}
|
||||
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
ImGui.TextUnformatted(entry.Name);
|
||||
|
||||
ImGui.EndChild();
|
||||
}
|
||||
|
||||
private void EntryDoubleClicked(Entry entry)
|
||||
{
|
||||
if (entry.IsDirectory)
|
||||
{
|
||||
_currentDirectory.Append(Path.DirectorySeparatorChar);
|
||||
_currentDirectory.Append(entry.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,12 +35,14 @@ namespace GlitchyEditor.EditWindows
|
||||
_editor = editor;
|
||||
}
|
||||
|
||||
private ImGui.Vec2 oldViewportSize;
|
||||
private ImGui.Vec2 oldViewportSize = .(100, 100);
|
||||
private bool viewPortChanged;
|
||||
|
||||
public uint32 SelectedEntityId;
|
||||
public bool SelectionChanged;
|
||||
|
||||
public Vector2 ViewportSize => (Vector2)oldViewportSize;
|
||||
|
||||
protected override void InternalShow()
|
||||
{
|
||||
ImGui.PushStyleVar(.WindowPadding, ImGui.Vec2(1, 1));
|
||||
@@ -89,6 +91,21 @@ namespace GlitchyEditor.EditWindows
|
||||
//ImGui.Image(_editor.CurrentScene.[Friend]_compositeTarget.GetViewBinding(0), viewportSize);
|
||||
}
|
||||
|
||||
if (ImGui.BeginDragDropTarget())
|
||||
{
|
||||
ImGui.Payload* payload = ImGui.AcceptDragDropPayload("CONTENT_BROWSER_ITEM");
|
||||
|
||||
if (payload != null)
|
||||
{
|
||||
Log.EngineLogger.Warning("");
|
||||
|
||||
StringView path = .((char8*)payload.Data, (int)payload.DataSize);
|
||||
_editor.RequestOpenScene(this, path);
|
||||
}
|
||||
|
||||
ImGui.EndDragDropTarget();
|
||||
}
|
||||
|
||||
bool gizmoUsed = DrawImGuizmo(viewportSize);
|
||||
|
||||
MousePicking(viewportSize, gizmoUsed);
|
||||
|
||||
@@ -15,10 +15,12 @@ namespace GlitchyEditor
|
||||
private EntityHierarchyWindow _entityHierarchyWindow ~ delete _;
|
||||
private ComponentEditWindow _componentEditWindow ~ delete _;
|
||||
private SceneViewportWindow _sceneViewportWindow = new .(this) ~ delete _;
|
||||
private ContentBrowserWindow _contentBrowserWindow = new .() ~ delete _;
|
||||
|
||||
public EntityHierarchyWindow EntityHierarchyWindow => _entityHierarchyWindow;
|
||||
public ComponentEditWindow ComponentEditWindow => _componentEditWindow;
|
||||
public SceneViewportWindow SceneViewportWindow => _sceneViewportWindow;
|
||||
public ContentBrowserWindow ContentBrowserWindow => _contentBrowserWindow;
|
||||
|
||||
public Scene CurrentScene
|
||||
{
|
||||
@@ -32,6 +34,8 @@ namespace GlitchyEditor
|
||||
|
||||
public EditorCamera* CurrentCamera { get; set; }
|
||||
|
||||
public Event<EventHandler<StringView>> RequestOpenScene ~ _.Dispose();
|
||||
|
||||
/// Creates a new editor for the given world
|
||||
public this(Scene scene)
|
||||
{
|
||||
@@ -46,6 +50,7 @@ namespace GlitchyEditor
|
||||
_entityHierarchyWindow.Show();
|
||||
_componentEditWindow.Show();
|
||||
_sceneViewportWindow.Show();
|
||||
_contentBrowserWindow.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using GlitchyEngine.Renderer;
|
||||
using GlitchyEngine.Math;
|
||||
using GlitchyEngine;
|
||||
|
||||
namespace GlitchyEditor
|
||||
{
|
||||
class EditorIcons : RefCounted
|
||||
{
|
||||
Texture2D _texture ~ _.ReleaseRef();
|
||||
|
||||
public SubTexture2D DirectionalLight ~ _.ReleaseRef();
|
||||
public SubTexture2D Camera ~ _.ReleaseRef();
|
||||
public SubTexture2D Folder ~ _.ReleaseRef();
|
||||
public SubTexture2D File ~ _.ReleaseRef();
|
||||
|
||||
public SamplerState SamplerState
|
||||
{
|
||||
get => _texture.SamplerState;
|
||||
set => _texture.SamplerState = value;
|
||||
}
|
||||
|
||||
public this(String texturePath, Vector2 iconSize)
|
||||
{
|
||||
_texture = new Texture2D(texturePath);
|
||||
|
||||
Vector2 pen = .();
|
||||
|
||||
DirectionalLight = GetNextGridTexture(ref pen, iconSize);
|
||||
Camera = GetNextGridTexture(ref pen, iconSize);
|
||||
Folder = GetNextGridTexture(ref pen, iconSize);
|
||||
File = GetNextGridTexture(ref pen, iconSize);
|
||||
}
|
||||
|
||||
private SubTexture2D GetNextGridTexture(ref Vector2 pen, Vector2 iconSize)
|
||||
{
|
||||
SubTexture2D subTexture = .CreateFromGrid(_texture, pen, iconSize);
|
||||
|
||||
pen.X += 1.0f;
|
||||
|
||||
if (pen.X >= (_texture.Width / iconSize.X))
|
||||
{
|
||||
pen.X = 0;
|
||||
pen.Y += 1.0f;
|
||||
}
|
||||
|
||||
Log.EngineLogger.AssertDebug(pen.Y <=(_texture.Height / iconSize.Y));
|
||||
|
||||
return subTexture;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,9 +50,11 @@ namespace GlitchyEditor
|
||||
|
||||
EditorCamera _camera ~ _.Dispose();
|
||||
|
||||
Texture2D _editorIcons ~ _.ReleaseRef();
|
||||
/*Texture2D _editorIcons ~ _.ReleaseRef();
|
||||
SubTexture2D _iconDirectionalLight ~ _.ReleaseRef();
|
||||
SubTexture2D _iconCamera ~ _.ReleaseRef();
|
||||
SubTexture2D _iconCamera ~ _.ReleaseRef();*/
|
||||
|
||||
EditorIcons _editorIcons ~ _.ReleaseRef();
|
||||
|
||||
public this() : base("Example")
|
||||
{
|
||||
@@ -63,9 +65,9 @@ namespace GlitchyEditor
|
||||
_camera = EditorCamera(Vector3(3.5f, 1.25f, 2.75f), Quaternion.FromEulerAngles(MathHelper.ToRadians(40), MathHelper.ToRadians(25), 0), MathHelper.ToRadians(75), 0.1f, 1);
|
||||
_camera.RenderTarget = _cameraTarget;
|
||||
|
||||
NewScene();
|
||||
|
||||
InitEditor();
|
||||
|
||||
NewScene();
|
||||
}
|
||||
|
||||
private void InitGraphics()
|
||||
@@ -104,10 +106,16 @@ namespace GlitchyEditor
|
||||
.(.R8G8B8A8_UNorm))
|
||||
});
|
||||
|
||||
_editorIcons = new Texture2D("Textures/EditorIcons.dds");
|
||||
_editorIcons = new EditorIcons("Textures/EditorIcons.dds", .(64, 64));
|
||||
_editorIcons.SamplerState = SamplerStateManager.AnisotropicClamp;
|
||||
|
||||
ContentBrowserWindow.s_FolderTexture = _editorIcons.Folder;
|
||||
ContentBrowserWindow.s_FileTexture = _editorIcons.File;
|
||||
|
||||
/*_editorIcons = new Texture2D("Textures/EditorIcons.dds");
|
||||
_editorIcons.SamplerState = SamplerStateManager.AnisotropicClamp;
|
||||
_iconDirectionalLight = .CreateFromGrid(_editorIcons, .(0, 0), .(64, 64));
|
||||
_iconCamera = .CreateFromGrid(_editorIcons, .(1, 0), .(64, 64));
|
||||
_iconCamera = .CreateFromGrid(_editorIcons, .(1, 0), .(64, 64));*/
|
||||
}
|
||||
|
||||
private void InitEditor()
|
||||
@@ -115,6 +123,10 @@ namespace GlitchyEditor
|
||||
_editor = new Editor(_scene);
|
||||
_editor.SceneViewportWindow.ViewportSizeChangedEvent.Add(new (s, e) => ViewportSizeChanged(s, e));
|
||||
_editor.CurrentCamera = &_camera;
|
||||
|
||||
_editor.RequestOpenScene.Add(new (s, fileName) => {
|
||||
LoadSceneFile(fileName);
|
||||
});
|
||||
}
|
||||
|
||||
public override void Update(GameTime gameTime)
|
||||
@@ -178,7 +190,7 @@ namespace GlitchyEditor
|
||||
Matrix world = Billboard(transform.WorldTransform);
|
||||
|
||||
float alpha = CalculateAlpha(transform.WorldTransform.Translation);
|
||||
Renderer2D.DrawQuad(world, _iconCamera, ColorRGBA(alpha, alpha, alpha, alpha), .(0, 0, 1, 1), entity.Index);
|
||||
Renderer2D.DrawQuad(world, _editorIcons.Camera, ColorRGBA(alpha, alpha, alpha, alpha), .(0, 0, 1, 1), entity.Index);
|
||||
//Renderer2D.DrawQuad(world, _iconCamera, .White, .(0, 0, 1, 1), entity.Index);
|
||||
}
|
||||
|
||||
@@ -199,7 +211,7 @@ namespace GlitchyEditor
|
||||
Matrix world = Billboard(transform.WorldTransform);
|
||||
|
||||
float alpha = CalculateAlpha(transform.WorldTransform.Translation);
|
||||
Renderer2D.DrawQuad(world, _iconDirectionalLight, ColorRGBA(light.SceneLight.Color.R * alpha, light.SceneLight.Color.G * alpha, light.SceneLight.Color.B * alpha, alpha), .(0, 0, 1, 1), entity.Index);
|
||||
Renderer2D.DrawQuad(world, _editorIcons.DirectionalLight, ColorRGBA(light.SceneLight.Color.R * alpha, light.SceneLight.Color.G * alpha, light.SceneLight.Color.B * alpha, alpha), .(0, 0, 1, 1), entity.Index);
|
||||
//Renderer2D.DrawQuad(world, _iconDirectionalLight, ColorRGBA(light.SceneLight.Color, alpha), .(0, 0, 1, 1), entity.Index);
|
||||
}
|
||||
}
|
||||
@@ -367,6 +379,12 @@ namespace GlitchyEditor
|
||||
{
|
||||
SceneFilePath = null;
|
||||
|
||||
delete _scene;
|
||||
_scene = new Scene();
|
||||
_editor.CurrentScene = _scene;
|
||||
var vpSize = _editor.SceneViewportWindow.ViewportSize;
|
||||
_scene.OnViewportResize((.)vpSize.X, (.)vpSize.Y);
|
||||
|
||||
_camera.Position = .(-1.5f, 1.5f, -2.5f);
|
||||
_camera.RotationEuler = .(MathHelper.ToRadians(25), MathHelper.ToRadians(35), 0);
|
||||
|
||||
@@ -421,17 +439,24 @@ namespace GlitchyEditor
|
||||
{
|
||||
if (val == .OK)
|
||||
{
|
||||
SceneFilePath = ofd.FileNames[0];
|
||||
LoadSceneFile(ofd.FileNames[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Loads the given scene file.
|
||||
private void LoadSceneFile(StringView filename)
|
||||
{
|
||||
SceneFilePath = scope String(filename);
|
||||
|
||||
delete _scene;
|
||||
_scene = new Scene();
|
||||
_editor.CurrentScene = _scene;
|
||||
var vpSize = _editor.SceneViewportWindow.ViewportSize;
|
||||
_scene.OnViewportResize((.)vpSize.X, (.)vpSize.Y);
|
||||
|
||||
SceneSerializer serializer = scope .(_scene);
|
||||
serializer.Deserialize(SceneFilePath);
|
||||
|
||||
_editor.CurrentScene = _scene;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawMainMenuBar()
|
||||
|
||||
@@ -45,4 +45,26 @@ namespace GlitchyEngine.Collections
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
public static mixin DeleteTreeAndChildren<T>(TreeNode<T> tree) where T : class, delete
|
||||
{
|
||||
InternalDeleteTreeAndChildren(tree);
|
||||
}
|
||||
|
||||
private static void InternalDeleteTreeAndChildren<T>(TreeNode<T> tree) where T : class, delete
|
||||
{
|
||||
for (var child in tree.Children)
|
||||
{
|
||||
InternalDeleteTreeAndChildren(child);
|
||||
}
|
||||
|
||||
delete tree.Value;
|
||||
|
||||
tree.Children.Clear();
|
||||
|
||||
delete tree;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using GlitchyEngine.Math;
|
||||
using GlitchyEngine.Renderer;
|
||||
using System;
|
||||
using GlitchyEngine;
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
@@ -34,6 +35,16 @@ namespace ImGui
|
||||
Image(texture.GetViewBinding(), size, uv0, uv1, tint_col, border_col);
|
||||
}
|
||||
|
||||
public static void Image(SubTexture2D subTexture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero)
|
||||
{
|
||||
if (uv0 != .Zero || uv1 != .Ones)
|
||||
Runtime.NotImplemented();
|
||||
|
||||
Vector2 v = (.)subTexture.TexCoords.XY + subTexture.TexCoords.ZW;
|
||||
|
||||
Image(subTexture.Texture.GetViewBinding(), size, (.)subTexture.TexCoords.XY, (.)v, tint_col, border_col);
|
||||
}
|
||||
|
||||
public static void Image(RenderTarget2D texture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero)
|
||||
{
|
||||
Image(texture.GetViewBinding(), size, uv0, uv1, tint_col, border_col);
|
||||
@@ -41,6 +52,18 @@ namespace ImGui
|
||||
|
||||
public static extern void Image(TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero);
|
||||
|
||||
public static bool ImageButton(SubTexture2D subTexture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, int32 frame_padding = -1, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones)
|
||||
{
|
||||
if (uv0 != .Zero || uv1 != .Ones)
|
||||
Runtime.NotImplemented();
|
||||
|
||||
Vector2 v = (.)subTexture.TexCoords.XY + subTexture.TexCoords.ZW;
|
||||
|
||||
return ImageButton(subTexture.Texture.GetViewBinding(), size, (.)subTexture.TexCoords.XY, (.)v, frame_padding, bg_col, tint_col);
|
||||
}
|
||||
|
||||
public static extern bool ImageButton(TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, int32 frame_padding = -1, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones);
|
||||
|
||||
public static void TextUnformatted(StringView text) => TextUnformattedImpl(text.Ptr, text.Ptr + text.Length);
|
||||
|
||||
public static void PushID(StringView id) => PushID(id.Ptr, id.Ptr + id.Length);
|
||||
|
||||
@@ -4,7 +4,7 @@ using System;
|
||||
namespace GlitchyEngine.Math
|
||||
{
|
||||
[BonTarget]
|
||||
[SwizzleVector(2, "Vector")]
|
||||
[SwizzleVector(2, "GlitchyEngine.Math.Vector")]
|
||||
public struct Vector2
|
||||
{
|
||||
public const Vector2 Zero = .(0f, 0f);
|
||||
|
||||
@@ -4,7 +4,7 @@ using System;
|
||||
namespace GlitchyEngine.Math
|
||||
{
|
||||
[BonTarget]
|
||||
[SwizzleVector(3, "Vector")]
|
||||
[SwizzleVector(3, "GlitchyEngine.Math.Vector")]
|
||||
public struct Vector3
|
||||
{
|
||||
public const Vector3 Zero = .(0f, 0f, 0f);
|
||||
|
||||
@@ -4,7 +4,7 @@ using System;
|
||||
namespace GlitchyEngine.Math
|
||||
{
|
||||
[BonTarget]
|
||||
[SwizzleVector(4, "Vector")]
|
||||
[SwizzleVector(4, "GlitchyEngine.Math.Vector")]
|
||||
public struct Vector4
|
||||
{
|
||||
public const Vector4 Zero = .(0f, 0f, 0f, 0f);
|
||||
|
||||
@@ -19,7 +19,19 @@ namespace ImGui
|
||||
|
||||
ImGui.Image(view, size, uv0, uv1, tint_col, border_col);
|
||||
|
||||
textureViewBinding.ReleaseRef();
|
||||
textureViewBinding.Release();
|
||||
}
|
||||
|
||||
public static override bool ImageButton(TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, int32 frame_padding = -1, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones)
|
||||
{
|
||||
var view = textureViewBinding._nativeShaderResourceView..AddRef();
|
||||
_resourceViews.Add(view);
|
||||
|
||||
bool pressed = ImGui.ImageButton(view, size, uv0, uv1, frame_padding, bg_col, tint_col);
|
||||
|
||||
textureViewBinding.Release();
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
protected internal static override void CleanupFrame()
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace GlitchyEngine.Renderer
|
||||
}
|
||||
|
||||
// TODO: Update Texture Arrays!
|
||||
protected override System.Result<void> PlatformSetData(void* data, uint32 elementSize, uint32 destX,
|
||||
protected override Result<void> PlatformSetData(void* data, uint32 elementSize, uint32 destX,
|
||||
uint32 destY, uint32 destWidth, uint32 destHeight, uint32 arraySlice, uint32 mipLevel, GlitchyEngine.Renderer.MapType mapType)
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
@@ -259,7 +259,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
protected override TextureViewBinding PlatformGetViewBinding()
|
||||
{
|
||||
return .(_nativeResourceView, _samplerState.nativeSamplerState);
|
||||
return .(_nativeResourceView, _samplerState?.nativeSamplerState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace GlitchyEngine.Renderer
|
||||
_nativeSamplerState?.AddRef();
|
||||
}
|
||||
|
||||
public override void ReleaseRef()
|
||||
public override void Release()
|
||||
{
|
||||
_nativeShaderResourceView?.Release();
|
||||
_nativeSamplerState?.Release();
|
||||
|
||||
@@ -64,6 +64,12 @@ namespace GlitchyEngine.Renderer
|
||||
Path.GetFileNameWithoutExtension(filepath, name);
|
||||
}
|
||||
|
||||
if (Exists(name))
|
||||
{
|
||||
return Get(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.EngineLogger.AssertDebug(!Exists(name), "Can't add two effects with the same name to library.");
|
||||
|
||||
Effect effect = new Effect(filepath, name);
|
||||
@@ -71,6 +77,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
return effect;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the effect with the given file name.
|
||||
@@ -182,7 +189,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
for(let entry in _textures)
|
||||
{
|
||||
entry.value.BoundTexture.ReleaseRef();
|
||||
entry.value.BoundTexture.Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +199,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
ref TextureEntry entry = ref _textures[name];
|
||||
|
||||
entry.BoundTexture.ReleaseRef();
|
||||
entry.BoundTexture.Release();
|
||||
entry.BoundTexture = texture.GetViewBinding();
|
||||
}
|
||||
|
||||
@@ -205,7 +212,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
ref TextureEntry entry = ref _textures[name];
|
||||
|
||||
entry.BoundTexture.ReleaseRef();
|
||||
entry.BoundTexture.Release();
|
||||
//entry.BoundTexture = .RenderTargetGroup(renderTargetGroup..AddRef(), firstTarget, targetCount);
|
||||
entry.BoundTexture = renderTargetGroup.GetViewBinding(firstTarget);
|
||||
}
|
||||
@@ -216,7 +223,7 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
ref TextureEntry entry = ref _textures[name];
|
||||
|
||||
entry.BoundTexture.ReleaseRef();
|
||||
entry.BoundTexture.Release();
|
||||
entry.BoundTexture = textureViewBinding..AddRef();
|
||||
}
|
||||
|
||||
@@ -226,11 +233,11 @@ namespace GlitchyEngine.Renderer
|
||||
|
||||
for(let (name, entry) in _textures)
|
||||
{
|
||||
entry.VsSlot?.BoundTexture.ReleaseRef();
|
||||
entry.VsSlot?.BoundTexture.Release();
|
||||
entry.VsSlot?.BoundTexture = entry.BoundTexture;
|
||||
entry.VsSlot?.BoundTexture.AddRef();
|
||||
|
||||
entry.PsSlot?.BoundTexture.ReleaseRef();
|
||||
entry.PsSlot?.BoundTexture.Release();
|
||||
entry.PsSlot?.BoundTexture = entry.BoundTexture;
|
||||
entry.PsSlot?.BoundTexture.AddRef();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
for(let (name, texture) in _textures)
|
||||
{
|
||||
texture.ReleaseRef();
|
||||
texture.Release();
|
||||
}
|
||||
|
||||
delete _textures;
|
||||
@@ -90,7 +90,7 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
if(_textures.TryGetValue(name, var entry))
|
||||
{
|
||||
entry.ReleaseRef();
|
||||
entry.Release();
|
||||
_textures[name] = texture.GetViewBinding();
|
||||
//texture?.AddRef();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ namespace GlitchyEngine.Renderer
|
||||
_rendererAPI.Init();
|
||||
}
|
||||
|
||||
[Inline]
|
||||
// REPORT!!!!!!!!!
|
||||
// Inline doesn't compile
|
||||
//[Inline]
|
||||
public static void Clear(RenderTarget2D renderTarget, ColorRGBA color)
|
||||
{
|
||||
_rendererAPI.Clear(renderTarget, color);
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace GlitchyEngine.Renderer
|
||||
for(let entry in entries)
|
||||
{
|
||||
delete entry.Name;
|
||||
entry.BoundTexture.ReleaseRef();
|
||||
entry.BoundTexture.Release();
|
||||
}
|
||||
|
||||
delete entries;
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace GlitchyEngine.Renderer
|
||||
public extern bool IsEmpty { get; }
|
||||
|
||||
public extern void AddRef();
|
||||
public extern void ReleaseRef();
|
||||
public extern void Release();
|
||||
|
||||
public void Dispose() => ReleaseRef();
|
||||
public void Dispose() => Release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ namespace GlitchyEngine.World
|
||||
|
||||
public this()
|
||||
{
|
||||
Entity entity = CreateEntity("Green Quad");
|
||||
/*Entity entity = CreateEntity("Green Quad");
|
||||
entity.AddComponent<SpriterRendererComponent>(.(ColorRGBA.SRgbToLinear(.(0.2f, 0.9f, 0.15f))));
|
||||
|
||||
Entity entity2 = CreateEntity("Red Square");
|
||||
var v = entity2.AddComponent<SpriterRendererComponent>(.(ColorRGBA.SRgbToLinear(.(0.95f, 0.1f, 0.3f))));
|
||||
v.Sprite = new Texture2D("Textures/rocket.dds");
|
||||
v.Sprite.SamplerState = SamplerStateManager.PointClamp;
|
||||
v.Sprite.SamplerState = SamplerStateManager.PointClamp;*/
|
||||
|
||||
_onComponentAddedHandlers.Add(typeof(CameraComponent), (e, t, c) => {
|
||||
CameraComponent* cameraComponent = (.)c;
|
||||
|
||||
Reference in New Issue
Block a user