Skip to content

Commit

Permalink
get rid of half my things
Browse files Browse the repository at this point in the history
  • Loading branch information
Pannoniae committed Nov 21, 2024
1 parent 568552b commit 91accc3
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 278 deletions.
4 changes: 3 additions & 1 deletion .idea/.idea.BlockGame/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions BlockGame.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AColor_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F0ae181a25dcbad0d6ba7bc6ad41d3f4a6ee366953ff464a3d6e115b5587819_003FColor_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AColor_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F921a65827594f7315c1c62fd944c53ecbaaecf73f2b09199752e35371bac4ee9_003FColor_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AColor_002ENamedColors_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Ff7ea64774b1b90b64a1dbb7699259d105d26d5c979d6350536cb979286390_003FColor_002ENamedColors_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACommandOpcodesNV_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa8cc5619785245f59dce931e659795142b09a0_003F03_003Fdfac8116_003FCommandOpcodesNV_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADictionary_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F1a7c247d4ea86c26ff612b299bf7d7ae4397e5fff3bbf7f4305d25ae5bd6fd_003FDictionary_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADictionary_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F59e69cdfed13efa8a6d7821335c5f5d1dd7e4dc2d09a23eec71b142e6f9967_003FDictionary_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADirectoryInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fdec38bbbebe9eb6c9d4e60a455aba51faf519c3ac73ca65ebce5724414d846aa_003FDirectoryInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADrawElementsType_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa8cc5619785245f59dce931e659795142b09a0_003F02_003F23d391c0_003FDrawElementsType_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEngineService_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0875e3e537714cbe9553e6a2a0e88549a9e00_003F0b_003F68db9771_003FEngineService_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEngine_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0875e3e537714cbe9553e6a2a0e88549a9e00_003F45_003F54611c03_003FEngine_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFileInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F2610c78ec589e1aacd82c4428835c427b838e8156a6f346f517d28ef9ffbb9a2_003FFileInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
Expand Down Expand Up @@ -78,6 +80,7 @@
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AObject_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F68b06b8592b1287fd78f3ee68566d6a38d6e2f45b9a9e6ebd4d0e9972f7c29_003FObject_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AOperatingSystem_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F1d9d7e40e3f35e20175d6797af3ff2e38cfeca6f5ccebaaa4b20d5c423b75361_003FOperatingSystem_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AOSPlatform_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F9e988c941e6515999ebab7336243c87df16e340b8faeb57b5f562d2b8a7c2c_003FOSPlatform_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APathParameter_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa8cc5619785245f59dce931e659795142b09a0_003Fcc_003Fa953fde4_003FPathParameter_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlane_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F56d711421813f9c55c53b36da631f65ea41a4e70816a87b292db1115ca4c0_003FPlane_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlane_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fd3dcccdc63aac1732584c75613ee3fe953c5cf50c7c3f96a1d999a7e76c4c_003FPlane_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APlane_00601_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe445a7db98e64ffc9f5bfeafad0d34d7501a0_003F18_003Fe6ee8535_003FPlane_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
Expand Down
1 change: 0 additions & 1 deletion src/GL/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ private void link(uint vert) {
public void use() {
GL.UseProgram(programHandle);
}

// uniforms

public int getUniformLocation(string name) {
Expand Down
123 changes: 44 additions & 79 deletions src/GL/SharedBlockVAO.cs
Original file line number Diff line number Diff line change
@@ -1,117 +1,84 @@
using System.Runtime.CompilerServices;
using Silk.NET.OpenGL;
using PrimitiveType = Silk.NET.OpenGL.PrimitiveType;

namespace BlockGame;


/// <summary>
/// BlockVAO but we use separated vertex attribute format/bindings
/// SharedBlockVAO but we only use one VAO / vertex format then just rebind the vertex/index buffer
/// It also uses only one buffer now instead of two
/// </summary>
public sealed class SharedBlockVAO : VAO {
public sealed class SharedBlockVAO : VAO
{
public uint VAOHandle;
public uint vbo;
public uint ibo;
public uint buffer;
public uint count;

public GL GL;

public SharedBlockVAO() {
GL = Game.GL;
VAOHandle = GL.GenVertexArray();
}

public void upload(float[] data) {
unsafe {
vbo = GL.GenBuffer();
GL.BindBuffer(BufferTargetARB.ArrayBuffer, vbo);
count = (uint)data.Length;
fixed (float* d = data) {
GL.BufferData(BufferTargetARB.ArrayBuffer, (uint)(data.Length * sizeof(float)), d,
BufferUsageARB.DynamicDraw);
}
}

format();
}

public void upload(Span<float> data) {
unsafe {
vbo = GL.GenBuffer();
GL.BindBuffer(BufferTargetARB.ArrayBuffer, vbo);
count = (uint)data.Length;
fixed (float* d = data) {
GL.BufferData(BufferTargetARB.ArrayBuffer, (uint)(data.Length * sizeof(float)), d,
BufferUsageARB.DynamicDraw);
}
}
public readonly GL GL;

format();
public SharedBlockVAO(uint VAOHandle) {
this.VAOHandle = VAOHandle;
GL = Game.GL;
}

public void upload(BlockVertexPacked[] data, ushort[] indices) {
unsafe {
vbo = GL.GenBuffer();
GL.BindBuffer(BufferTargetARB.ArrayBuffer, vbo);
buffer = GL.GenBuffer();
GL.BindBuffer(BufferTargetARB.ArrayBuffer, buffer);
count = (uint)indices.Length;
var vertexSize = (uint)(data.Length * sizeof(BlockVertexPacked));
fixed (BlockVertexPacked* d = data) {
GL.BufferData(BufferTargetARB.ArrayBuffer, (uint)(data.Length * sizeof(BlockVertexPacked)), d,
BufferUsageARB.DynamicDraw);
}

ibo = GL.GenBuffer();
GL.BindBuffer(BufferTargetARB.ElementArrayBuffer, ibo);
fixed (ushort* d = indices) {
GL.BufferData(BufferTargetARB.ElementArrayBuffer, (uint)(indices.Length * sizeof(ushort)), d,
BufferUsageARB.DynamicDraw);
GL.BufferStorage(BufferStorageTarget.ArrayBuffer, vertexSize, d,
BufferStorageMask.None);
}
}

format();
}

public void upload(Span<BlockVertexPacked> data, Span<ushort> indices) {
public void upload(Span<BlockVertexPacked> data, uint _count) {
unsafe {
vbo = GL.GenBuffer();
GL.BindBuffer(BufferTargetARB.ArrayBuffer, vbo);
count = (uint)indices.Length;
buffer = GL.GenBuffer();
count = (uint)(_count * 1.5);
var vertexSize = (uint)(data.Length * sizeof(BlockVertexPacked));
GL.BindBuffer(BufferTargetARB.ArrayBuffer, buffer);
fixed (BlockVertexPacked* d = data) {
GL.BufferData(BufferTargetARB.ArrayBuffer, (uint)(data.Length * sizeof(BlockVertexPacked)), d,
BufferUsageARB.DynamicDraw);
GL.BufferStorage(BufferStorageTarget.ArrayBuffer, vertexSize, d,
BufferStorageMask.None);
}

ibo = GL.GenBuffer();
GL.BindBuffer(BufferTargetARB.ElementArrayBuffer, ibo);
fixed (ushort* d = indices) {
GL.BufferData(BufferTargetARB.ElementArrayBuffer, (uint)(indices.Length * sizeof(ushort)), d,
BufferUsageARB.DynamicDraw);
}
}

format();
}

public void format() {
unsafe {
// 18 bytes in total, 3*4 for pos, 2*2 for uv, 2 bytes for data
GL.EnableVertexAttribArray(0);
GL.EnableVertexAttribArray(1);
GL.EnableVertexAttribArray(2);

GL.VertexAttribIFormat(0, 3, VertexAttribIType.UnsignedShort, 0);
GL.VertexAttribIFormat(1, 2, VertexAttribIType.UnsignedShort, 0 + 3 * sizeof(ushort));
GL.VertexAttribIFormat(2, 1, VertexAttribIType.UnsignedShort, 0 + 5 * sizeof(ushort));

GL.VertexAttribBinding(0, 0);
GL.VertexAttribBinding(1, 0);
GL.VertexAttribBinding(2, 0);
public void upload(Span<BlockVertexPacked> data, Span<ushort> indices) {
throw new Exception("this doesn't work!");
}

GL.BindVertexBuffer(0, vbo, 0, 6 * sizeof(ushort));
public void format() {
// 18 bytes in total, 3*4 for pos, 2*2 for uv, 2 bytes for data
GL.EnableVertexAttribArray(0);
GL.EnableVertexAttribArray(1);
GL.EnableVertexAttribArray(2);

GL.VertexAttribIFormat(0, 3, VertexAttribIType.UnsignedShort, 0);
GL.VertexAttribIFormat(1, 2, VertexAttribIType.UnsignedShort, 0 + 3 * sizeof(ushort));
GL.VertexAttribIFormat(2, 1, VertexAttribIType.UnsignedShort, 0 + 5 * sizeof(ushort));

GL.VertexAttribBinding(0, 0);
GL.VertexAttribBinding(1, 0);
GL.VertexAttribBinding(2, 0);
}

}
public void bindVAO() {
GL.BindVertexArray(VAOHandle);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void bind() {
GL.BindVertexArray(VAOHandle);
GL.VertexArrayVertexBuffer(VAOHandle, 0, buffer, 0, 6 * sizeof(ushort));
}

public uint render() {
Expand All @@ -122,8 +89,6 @@ public uint render() {
}

public void Dispose() {
GL.DeleteBuffer(vbo);
GL.DeleteBuffer(ibo);
GL.DeleteVertexArray(VAOHandle);
GL.DeleteBuffer(buffer);
}
}
131 changes: 0 additions & 131 deletions src/GL/VerySharedBlockVAO.cs

This file was deleted.

Loading

0 comments on commit 91accc3

Please sign in to comment.