98 lines
3.4 KiB
C#
98 lines
3.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
namespace Aiwaz.Contracts
|
|
{
|
|
public enum CommandFlags : byte
|
|
{
|
|
None = 0x00,
|
|
SubChainStart = 0x01, // Command will start a new command chain (UseShader for example)
|
|
SubChainEnd = 0x02, // Command will end a command chain (Render)
|
|
Unique = 0x04, // Similar commands should not be reduced to one Command
|
|
StartChain = 0x08, // Command will generate a new command chain
|
|
EndChain = 0x10, // Command will end the command chain (RenderGeometry for example)
|
|
FlushChain = 0x20, // Command will end the command chain (RenderGeometry for example)
|
|
}
|
|
|
|
public class Command
|
|
{
|
|
[StructLayout(LayoutKind.Explicit)]
|
|
public struct CommandInfoUnion
|
|
{
|
|
[FieldOffset(0)]
|
|
public uint RawValue;
|
|
[FieldOffset(0)]
|
|
public byte Priority;
|
|
[FieldOffset(1)]
|
|
public byte SubPriority;
|
|
[FieldOffset(2)]
|
|
public CommandFlags Flags;
|
|
[FieldOffset(3)]
|
|
public byte Type;
|
|
}
|
|
|
|
public Command(ICommandUser argOwner, CommandFlags argFlags, byte argType)
|
|
: this(argOwner, argFlags, argType, 0, 0)
|
|
{
|
|
}
|
|
|
|
public Command(ICommandUser argOwner, CommandFlags argFlags, byte argType, byte argPriority)
|
|
: this(argOwner, argFlags, argType, argPriority, 0)
|
|
{
|
|
}
|
|
|
|
public Command(ICommandUser argOwner, CommandFlags argFlags, byte argType, byte argPriority, byte argSubPriority)
|
|
{
|
|
CommandInfo.RawValue = 0;
|
|
Owner = argOwner;
|
|
Flags = argFlags;
|
|
Priority = argPriority;
|
|
SubPriority = argSubPriority;
|
|
Type = argType;
|
|
}
|
|
|
|
|
|
public CommandInfoUnion CommandInfo;
|
|
public byte Priority { get { return CommandInfo.Priority; } set { CommandInfo.Priority = value; } }
|
|
public byte SubPriority { get { return CommandInfo.SubPriority; } set { CommandInfo.SubPriority = value; } }
|
|
public CommandFlags Flags { get { return CommandInfo.Flags; } set { CommandInfo.Flags = value; } }
|
|
public byte Type { get { return CommandInfo.Type; } set { CommandInfo.Type = value; } }
|
|
|
|
public ICommandUser Owner;
|
|
};
|
|
|
|
public enum CommandExecuteResult
|
|
{
|
|
None, // Execution done, proceed to the next Command
|
|
RetrySubChain, // Execution should start from a previous "SubChainStart"-flagged Command
|
|
RetrySubChainSkipHead // Equal to the above result but skips the as "SubChainStart"-flagged Command
|
|
};
|
|
|
|
public interface ICommandUser
|
|
{
|
|
List<Command> Commands { get; }
|
|
|
|
CommandExecuteResult ExecuteCommand(byte argCommandType, ICommandBuffer argCurrentBuffer, int argCurrentPositon);
|
|
|
|
void AssignToRenderCommandNode(IRenderCommandNode argNode);
|
|
void UnassignFromRenderCommandNode(IRenderCommandNode argNode);
|
|
|
|
// Commands should be applied before all following commands
|
|
bool IsPreconditionForNextCommands { get; set; }
|
|
};
|
|
|
|
|
|
public interface ICommandBuffer
|
|
{
|
|
void Clear();
|
|
void Perform(bool argUseOptimizedList);
|
|
void Optimize();
|
|
void AddChildCommandBuffer(ICommandBuffer argCommandBuffer);
|
|
void RemoveChildCommandBuffer(ICommandBuffer argCommandBuffer);
|
|
|
|
List<Command> BufferedCommands { get; }
|
|
List<ICommandBuffer> ChildCommandBuffers { get; }
|
|
ICommandBuffer ParentBuffer { get; set; }
|
|
};
|
|
|
|
}
|