Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions source/Functions/RenderEnginePluginFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using Worlds;

namespace Rendering.Functions
{
public unsafe readonly struct RenderEnginePluginFunction : IEquatable<RenderEnginePluginFunction>
{
#if NET
private readonly delegate* unmanaged<Input, void> function;

public RenderEnginePluginFunction(delegate* unmanaged<Input, void> function)
{
this.function = function;
}
#else
private readonly delegate*<Input, void> function;

public PluginBeforeRendering(delegate*<Input, void> function)
{
this.function = function;
}
#endif

public readonly void Invoke(World world, sbyte renderGroup, Span<RenderEntity> entities)
{
function(new(world, renderGroup, entities));
}

public readonly override bool Equals(object? obj)
{
return obj is RenderEnginePluginFunction plugin && Equals(plugin);
}

public readonly bool Equals(RenderEnginePluginFunction other)
{
return (nint)function == (nint)other.function;
}

public readonly override int GetHashCode()
{
return ((nint)function).GetHashCode();
}

public static bool operator ==(RenderEnginePluginFunction left, RenderEnginePluginFunction right)
{
return left.Equals(right);
}

public static bool operator !=(RenderEnginePluginFunction left, RenderEnginePluginFunction right)
{
return !(left == right);
}

public readonly struct Input
{
public readonly World world;
public readonly sbyte renderGroup;

private readonly RenderEntity* entities;
private readonly int count;

public readonly Span<RenderEntity> Entities => new(entities, count);

public Input(World world, sbyte renderGroup, Span<RenderEntity> entities)
{
this.world = world;
this.renderGroup = renderGroup;
this.entities = entities.GetPointer();
count = entities.Length;
}
}
}
}
58 changes: 58 additions & 0 deletions source/MaterialData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Materials;
using Materials.Components;
using System;
using Worlds;

namespace Rendering
{
public readonly struct MaterialData : IEquatable<MaterialData>
{
public readonly uint entity;
public readonly ushort version;
public readonly sbyte order;

public MaterialData(uint entity, ushort version, sbyte order)
{
this.entity = entity;
this.version = version;
this.order = order;
}

public MaterialData(uint entity, IsMaterial component)
{
this.entity = entity;
version = component.version;
order = component.renderGroup;
}

public readonly override bool Equals(object? obj)
{
return obj is MaterialData data && Equals(data);
}

public readonly bool Equals(MaterialData other)
{
return entity == other.entity && version == other.version;
}

public readonly Material Get(World world)
{
return new Entity(world, entity).As<Material>();
}

public readonly override int GetHashCode()
{
return HashCode.Combine(entity, version);
}

public static bool operator ==(MaterialData left, MaterialData right)
{
return left.Equals(right);
}

public static bool operator !=(MaterialData left, MaterialData right)
{
return !(left == right);
}
}
}
69 changes: 69 additions & 0 deletions source/RenderEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;

namespace Rendering
{
public readonly struct RenderEntity : IEquatable<RenderEntity>
{
public readonly uint entity;
public readonly uint meshEntity;
public readonly uint materialEntity;
public readonly uint vertexShaderEntity;
public readonly uint fragmentShaderEntity;
public readonly ushort meshVersion;
public readonly ushort vertexShaderVersion;
public readonly ushort fragmentShaderVersion;

public RenderEntity(uint entity, uint meshEntity, uint materialEntity, uint vertexShaderEntity, uint fragmentShaderEntity, ushort meshVersion, ushort vertexShaderVersion, ushort fragmentShaderVersion)
{
this.entity = entity;
this.meshEntity = meshEntity;
this.materialEntity = materialEntity;
this.vertexShaderEntity = vertexShaderEntity;
this.fragmentShaderEntity = fragmentShaderEntity;
this.meshVersion = meshVersion;
this.vertexShaderVersion = vertexShaderVersion;
this.fragmentShaderVersion = fragmentShaderVersion;
}

public readonly override bool Equals(object? obj)
{
return obj is RenderEntity entity && Equals(entity);
}

public readonly bool Equals(RenderEntity other)
{
return entity == other.entity &&
meshEntity == other.meshEntity &&
materialEntity == other.materialEntity &&
vertexShaderEntity == other.vertexShaderEntity &&
fragmentShaderEntity == other.fragmentShaderEntity &&
meshVersion == other.meshVersion &&
vertexShaderVersion == other.vertexShaderVersion &&
fragmentShaderVersion == other.fragmentShaderVersion;
}

public readonly override int GetHashCode()
{
HashCode hash = new();
hash.Add(entity);
hash.Add(meshEntity);
hash.Add(materialEntity);
hash.Add(vertexShaderEntity);
hash.Add(fragmentShaderEntity);
hash.Add(meshVersion);
hash.Add(vertexShaderVersion);
hash.Add(fragmentShaderVersion);
return hash.ToHashCode();
}

public static bool operator ==(RenderEntity left, RenderEntity right)
{
return left.Equals(right);
}

public static bool operator !=(RenderEntity left, RenderEntity right)
{
return !(left == right);
}
}
}
55 changes: 55 additions & 0 deletions source/RendererCombination.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;

namespace Rendering
{
public struct RendererCombination : IEquatable<RendererCombination>
{
public uint materialEntity;
public uint meshEntity;
public uint vertexShaderEntity;
public uint fragmentShaderEntity;

public readonly ulong Key => ((ulong)materialEntity << 32) | meshEntity;

public RendererCombination(uint materialEntity, uint meshEntity, uint vertexShaderEntity, uint fragmentShaderEntity)
{
this.materialEntity = materialEntity;
this.meshEntity = meshEntity;
this.vertexShaderEntity = vertexShaderEntity;
this.fragmentShaderEntity = fragmentShaderEntity;
}

public readonly override bool Equals(object? obj)
{
return obj is RendererCombination combination && Equals(combination);
}

public readonly bool Equals(RendererCombination other)
{
return materialEntity == other.materialEntity && meshEntity == other.meshEntity && vertexShaderEntity == other.vertexShaderEntity && fragmentShaderEntity == other.fragmentShaderEntity;
}

public readonly override int GetHashCode()
{
unchecked
{
int hash = 17;
hash = hash * 23 + (int)materialEntity;
hash = hash * 23 + (int)meshEntity;
hash = hash * 23 + (int)vertexShaderEntity;
hash = hash * 23 + (int)fragmentShaderEntity;
return hash;
}
}

public static bool operator ==(RendererCombination left, RendererCombination right)
{
return left.Equals(right);
}

public static bool operator !=(RendererCombination left, RendererCombination right)
{
return !(left == right);
}
}
}
35 changes: 35 additions & 0 deletions source/RendererEnginePlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Rendering.Functions;
using Worlds;

namespace Rendering
{
public readonly partial struct RenderEnginePlugin : IEntity
{
public RenderEnginePlugin(World world, RenderEnginePluginFunction function)
{
this.world = world;
value = world.CreateEntity(function);
}

public unsafe RenderEnginePlugin(World world, delegate* unmanaged<RenderEnginePluginFunction.Input, void> function)
{
this.world = world;
value = world.CreateEntity(new RenderEnginePluginFunction(function));
}

void IEntity.Describe(ref Archetype archetype)
{
archetype.AddComponentType<RenderEnginePluginFunction>();
}

public static RenderEnginePlugin Create(World world, RenderEnginePluginFunction function)
{
return new(world, function);
}

public unsafe static RenderEnginePlugin Create(World world, delegate* unmanaged<RenderEnginePluginFunction.Input, void> function)
{
return new(world, function);
}
}
}
8 changes: 4 additions & 4 deletions source/Rendering.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
<RepositoryUrl>https://github.com/simulation-tree/rendering</RepositoryUrl>
<IsAotCompatible>True</IsAotCompatible>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<PackageId/>
<PackageId />
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\materials\source\Materials.csproj"/>
<ProjectReference Include="..\..\meshes\source\Meshes.csproj"/>
<ProjectReference Include="..\..\shaders\source\Shaders.csproj"/>
<ProjectReference Include="..\..\materials\source\Materials.csproj" />
<ProjectReference Include="..\..\meshes\source\Meshes.csproj" />
<ProjectReference Include="..\..\shaders\source\Shaders.csproj" />
<ProjectReference Include="..\..\types\generator\Types.Generator.csproj">
<OutputItemType>Analyzer</OutputItemType>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
Expand Down