Skip to content

Commit 2232eba

Browse files
[Rendering] Add missing functionality to IndexBuffer;
[Rendering] Started adding support for compute buffers;
1 parent 348cdf0 commit 2232eba

File tree

9 files changed

+502
-508
lines changed

9 files changed

+502
-508
lines changed

Engine/Core/External/BGFX/BGFXUtils.cs

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,220 @@ public static bgfx.AttribType GetBGFXVertexAttributeType(VertexAttributeType typ
303303
_ => bgfx.AttribType.Float,
304304
};
305305
}
306+
307+
public static RenderBufferFlags GetRenderBufferFlags(bgfx.BufferFlags flags)
308+
{
309+
var outValue = RenderBufferFlags.None;
310+
311+
if (flags.HasFlag(bgfx.BufferFlags.Index32))
312+
{
313+
outValue |= RenderBufferFlags.Index32;
314+
}
315+
316+
if (flags.HasFlag(bgfx.BufferFlags.AllowResize))
317+
{
318+
outValue |= RenderBufferFlags.AllowResize;
319+
}
320+
321+
if (flags.HasFlag(bgfx.BufferFlags.ComputeFormat8x1))
322+
{
323+
outValue |= RenderBufferFlags.Compute8x1;
324+
}
325+
326+
if (flags.HasFlag(bgfx.BufferFlags.ComputeFormat8x2))
327+
{
328+
outValue |= RenderBufferFlags.Compute8x2;
329+
}
330+
331+
if (flags.HasFlag(bgfx.BufferFlags.ComputeFormat8x4))
332+
{
333+
outValue |= RenderBufferFlags.Compute8x4;
334+
}
335+
336+
if (flags.HasFlag(bgfx.BufferFlags.ComputeFormat16x1))
337+
{
338+
outValue |= RenderBufferFlags.Compute16x1;
339+
}
340+
341+
if (flags.HasFlag(bgfx.BufferFlags.ComputeFormat16x2))
342+
{
343+
outValue |= RenderBufferFlags.Compute16x2;
344+
}
345+
346+
if (flags.HasFlag(bgfx.BufferFlags.ComputeFormat16x4))
347+
{
348+
outValue |= RenderBufferFlags.Compute16x4;
349+
}
350+
351+
if (flags.HasFlag(bgfx.BufferFlags.ComputeFormat32x1))
352+
{
353+
outValue |= RenderBufferFlags.Compute32x1;
354+
}
355+
356+
if (flags.HasFlag(bgfx.BufferFlags.ComputeFormat32x2))
357+
{
358+
outValue |= RenderBufferFlags.Compute32x2;
359+
}
360+
361+
if (flags.HasFlag(bgfx.BufferFlags.ComputeFormat32x4))
362+
{
363+
outValue |= RenderBufferFlags.Compute32x4;
364+
}
365+
366+
if (flags.HasFlag(bgfx.BufferFlags.ComputeTypeInt))
367+
{
368+
outValue |= RenderBufferFlags.ComputeTypeInt;
369+
}
370+
371+
if (flags.HasFlag(bgfx.BufferFlags.ComputeTypeUint))
372+
{
373+
outValue |= RenderBufferFlags.ComputeTypeUInt;
374+
}
375+
376+
if (flags.HasFlag(bgfx.BufferFlags.ComputeTypeFloat))
377+
{
378+
outValue |= RenderBufferFlags.ComputeTypeFloat;
379+
}
380+
381+
if (flags.HasFlag(bgfx.BufferFlags.ComputeWrite))
382+
{
383+
outValue |= RenderBufferFlags.ComputeWrite;
384+
}
385+
386+
if (flags.HasFlag(bgfx.BufferFlags.ComputeRead))
387+
{
388+
outValue |= RenderBufferFlags.ComputeRead;
389+
}
390+
391+
if (flags.HasFlag(bgfx.BufferFlags.ComputeReadWrite))
392+
{
393+
outValue |= RenderBufferFlags.ComputeReadWrite;
394+
}
395+
396+
if (flags.HasFlag(bgfx.BufferFlags.DrawIndirect))
397+
{
398+
outValue |= RenderBufferFlags.DrawIndirect;
399+
}
400+
401+
return outValue;
402+
}
403+
404+
public static bgfx.BufferFlags GetBGFXBufferFlags(RenderBufferFlags flags)
405+
{
406+
var outValue = bgfx.BufferFlags.None;
407+
408+
if (flags.HasFlag(RenderBufferFlags.Index32))
409+
{
410+
outValue |= bgfx.BufferFlags.Index32;
411+
}
412+
413+
if (flags.HasFlag(RenderBufferFlags.AllowResize))
414+
{
415+
outValue |= bgfx.BufferFlags.AllowResize;
416+
}
417+
418+
if (flags.HasFlag(RenderBufferFlags.Compute8x1))
419+
{
420+
outValue |= bgfx.BufferFlags.ComputeFormat8x1;
421+
}
422+
423+
if (flags.HasFlag(RenderBufferFlags.Compute8x2))
424+
{
425+
outValue |= bgfx.BufferFlags.ComputeFormat8x2;
426+
}
427+
428+
if (flags.HasFlag(RenderBufferFlags.Compute8x4))
429+
{
430+
outValue |= bgfx.BufferFlags.ComputeFormat8x4;
431+
}
432+
433+
if (flags.HasFlag(RenderBufferFlags.Compute16x1))
434+
{
435+
outValue |= bgfx.BufferFlags.ComputeFormat16x1;
436+
}
437+
438+
if (flags.HasFlag(RenderBufferFlags.Compute16x2))
439+
{
440+
outValue |= bgfx.BufferFlags.ComputeFormat16x2;
441+
}
442+
443+
if (flags.HasFlag(RenderBufferFlags.Compute16x4))
444+
{
445+
outValue |= bgfx.BufferFlags.ComputeFormat16x4;
446+
}
447+
448+
if (flags.HasFlag(RenderBufferFlags.Compute32x1))
449+
{
450+
outValue |= bgfx.BufferFlags.ComputeFormat32x1;
451+
}
452+
453+
if (flags.HasFlag(RenderBufferFlags.Compute32x2))
454+
{
455+
outValue |= bgfx.BufferFlags.ComputeFormat32x2;
456+
}
457+
458+
if (flags.HasFlag(RenderBufferFlags.Compute32x4))
459+
{
460+
outValue |= bgfx.BufferFlags.ComputeFormat32x4;
461+
}
462+
463+
if (flags.HasFlag(RenderBufferFlags.ComputeTypeInt))
464+
{
465+
outValue |= bgfx.BufferFlags.ComputeTypeInt;
466+
}
467+
468+
if (flags.HasFlag(RenderBufferFlags.ComputeTypeUInt))
469+
{
470+
outValue |= bgfx.BufferFlags.ComputeTypeUint;
471+
}
472+
473+
if (flags.HasFlag(RenderBufferFlags.ComputeTypeFloat))
474+
{
475+
outValue |= bgfx.BufferFlags.ComputeTypeFloat;
476+
}
477+
478+
if (flags.HasFlag(RenderBufferFlags.ComputeWrite))
479+
{
480+
outValue |= bgfx.BufferFlags.ComputeWrite;
481+
}
482+
483+
if (flags.HasFlag(RenderBufferFlags.ComputeRead))
484+
{
485+
outValue |= bgfx.BufferFlags.ComputeRead;
486+
}
487+
488+
if (flags.HasFlag(RenderBufferFlags.ComputeReadWrite))
489+
{
490+
outValue |= bgfx.BufferFlags.ComputeReadWrite;
491+
}
492+
493+
if (flags.HasFlag(RenderBufferFlags.DrawIndirect))
494+
{
495+
outValue |= bgfx.BufferFlags.DrawIndirect;
496+
}
497+
498+
return outValue;
499+
}
500+
501+
public static Access GetAccess(bgfx.Access access)
502+
{
503+
return access switch
504+
{
505+
bgfx.Access.Read => Access.Read,
506+
bgfx.Access.Write => Access.Write,
507+
bgfx.Access.ReadWrite => Access.ReadWrite,
508+
_ => Access.Read,
509+
};
510+
}
511+
512+
public static bgfx.Access GetBGFXAccess(Access access)
513+
{
514+
return access switch
515+
{
516+
Access.Read => bgfx.Access.Read,
517+
Access.Write => bgfx.Access.Write,
518+
Access.ReadWrite => bgfx.Access.ReadWrite,
519+
_ => bgfx.Access.Read,
520+
};
521+
}
306522
}

Engine/Core/Rendering/Access.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Staple;
2+
3+
public enum Access
4+
{
5+
Read,
6+
Write,
7+
ReadWrite
8+
}

Engine/Core/Rendering/Mesh/Mesh.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ public void UploadMeshData()
914914
return;
915915
}
916916

917-
if(vertexBuffer.type == VertexBufferType.Dynamic)
917+
if(vertexBuffer.type == RenderBufferType.Dynamic)
918918
{
919919
vertexBuffer.Update(vertexBlob, 0);
920920
}
@@ -924,7 +924,7 @@ public void UploadMeshData()
924924
case MeshIndexFormat.UInt16:
925925

926926
{
927-
ushort[] data = new ushort[indices.Length];
927+
var data = new ushort[indices.Length];
928928

929929
for (var i = 0; i < indices.Length; i++)
930930
{
@@ -936,7 +936,7 @@ public void UploadMeshData()
936936
data[i] = (ushort)indices[i];
937937
}
938938

939-
indexBuffer = IndexBuffer.Create(data, RenderBufferFlags.None);
939+
indexBuffer = IndexBuffer.Create(data);
940940
}
941941

942942
break;
Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
using Bgfx;
2-
using System;
1+
using System;
32

43
namespace Staple;
54

65
[Flags]
76
public enum RenderBufferFlags
87
{
9-
None = bgfx.BufferFlags.None,
10-
Write = bgfx.BufferFlags.ComputeWrite,
11-
Read = bgfx.BufferFlags.ComputeRead,
12-
Index32 = bgfx.BufferFlags.Index32,
13-
AllowResize = bgfx.BufferFlags.AllowResize,
8+
None = 0,
9+
Index32 = (1 << 0),
10+
AllowResize = (1 << 1),
11+
Compute8x1 = (1 << 2),
12+
Compute8x2 = (1 << 3),
13+
Compute8x4 = (1 << 4),
14+
Compute16x1 = (1 << 5),
15+
Compute16x2 = (1 << 6),
16+
Compute16x4 = (1 << 7),
17+
Compute32x1 = (1 << 8),
18+
Compute32x2 = (1 << 9),
19+
Compute32x4 = (1 << 10),
20+
ComputeTypeInt = (1 << 11),
21+
ComputeTypeUInt = (1 << 12),
22+
ComputeTypeFloat = (1 << 13),
23+
ComputeWrite = (1 << 14),
24+
ComputeRead = (1 << 15),
25+
ComputeReadWrite = (1 << 16),
26+
DrawIndirect = (1 << 17),
1427
}

0 commit comments

Comments
 (0)