Skip to content

Commit

Permalink
feat(Texture): implement TextureBuilder API
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Feb 24, 2024
1 parent 5dfde14 commit 07268ac
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
12 changes: 12 additions & 0 deletions ZenKit/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,18 @@ public static extern void ZkModelMesh_enumerateAttachments(UIntPtr slf, ZkAttach
[DllImport(DllName)]
public static extern ulong ZkTexture_getMipmapRgba(UIntPtr slf, ulong level, byte[] buf, ulong size);

[DllImport(DllName)]
public static extern UIntPtr ZkTextureBuilder_new(ulong width, ulong height);

[DllImport(DllName)]
public static extern void ZkTextureBuilder_del(UIntPtr slf);

[DllImport(DllName)]
public static extern bool ZkTextureBuilder_addMipmap(UIntPtr slf, byte[] buf, ulong size, TextureFormat fmt);

[DllImport(DllName)]
public static extern UIntPtr ZkTextureBuilder_build(UIntPtr slf, TextureFormat fmt);

[DllImport(DllName)]
public static extern UIntPtr ZkMorphMesh_load(UIntPtr buf);

Expand Down
30 changes: 27 additions & 3 deletions ZenKit/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public Texture(Vfs vfs, string name)
if (Handle == UIntPtr.Zero) throw new Exception("Failed to load texture");
}

internal Texture(UIntPtr handle)
internal Texture(UIntPtr handle, bool delete = false)
{
Handle = handle;
_delete = false;
_delete = delete;
}

public TextureFormat Format => Native.ZkTexture_getFormat(Handle);
Expand Down Expand Up @@ -221,4 +221,28 @@ public int GetHeight(int level)
if (_delete) Native.ZkTexture_del(Handle);
}
}
}

public class TextureBuilder
{
private readonly UIntPtr _handle;
public TextureBuilder(int width, int height)
{
_handle = Native.ZkTextureBuilder_new((ulong)width, (ulong)height);
}

~TextureBuilder()
{
Native.ZkTextureBuilder_del(_handle);
}

public bool AddMipmap(byte[] image, TextureFormat fmt)
{
return Native.ZkTextureBuilder_addMipmap(_handle, image, (ulong)image.LongLength, fmt);
}

public Texture Build(TextureFormat fmt)
{
return new Texture(Native.ZkTextureBuilder_build(_handle, fmt), true);
}
}
}
Binary file modified ZenKit/runtimes/android-arm64/native/libzenkitcapi.so
Binary file not shown.
Binary file modified ZenKit/runtimes/linux-x64/native/libzenkitcapi.so
Binary file not shown.
Binary file modified ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib
Binary file not shown.
Binary file modified ZenKit/runtimes/win-x64/native/zenkitcapi.dll
Binary file not shown.

0 comments on commit 07268ac

Please sign in to comment.