Backlog/engine/rend/src/rend.zig

85 lines
2.3 KiB
Zig

const std = @import("std");
pub const core = @import("core");
// meshes api
pub const meshes = @import("meshes/meshes.zig");
pub const JointNameEntry = meshes.JointNameEntry;
pub const MeshUpdate = meshes.MeshUpdate;
pub const MeshVertex = meshes.MeshVertex;
pub const IndexedMesh = meshes.IndexedMesh;
// components exports
pub const MeshComponent = @import("meshes/MeshComponent.zig");
pub const CameraComponent = @import("camera/CameraComponent.zig");
// asset loaders
pub const gltfLoader = @import("meshes/gltfLoader.zig");
// switch out based on backend implementation
pub const renderer = @import("sgpu/renderer.zig");
pub const context = renderer.context; // context getter func
pub const MeshPool = renderer.MeshPool;
pub const getMesh = renderer.getMesh;
pub const getMeshByName = renderer.getMeshByName;
// camera API
pub const setActiveCamera = renderer.setActiveCamera;
pub const createRendererObject = renderer.createRendererObject;
pub const registerRendererObject = renderer.registerRendererObject;
pub const getTexture = renderer.getTexture;
pub const textureExists = renderer.textureExists;
pub const texture = @import("texture/texture.zig");
pub const Texture = texture.Texture;
pub const setSkyboxTexture = renderer.setSkyboxTexture;
var rendAllocator: std.mem.Allocator = undefined;
pub fn getAllocator() std.mem.Allocator {
return rendAllocator;
}
// controls glfw and general windowing
// graphics depends on this one
pub const Module: core.ModuleDescription = .{
.name = "rend",
.enabledByDefault = true,
};
pub fn start_module(spec: *core.SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void {
_ = args;
_ = spec;
rendAllocator = allocator;
try renderer.createInstance();
try renderer.start();
try core.defineComponentList(ComponentList, allocator);
}
pub const ComponentList = struct {
pub const _MeshComponent = MeshComponent;
pub const _CameraComponent = CameraComponent;
};
pub fn setupFromModule() void {
if (core.getEngineObject(renderer.Renderer)) |r| {
rendAllocator = r.allocator;
}
core.ecs.patchComponentList(ComponentList);
}
pub fn shutdown_module(allocator: std.mem.Allocator) void {
core.undefineComponentList(ComponentList);
_ = allocator;
renderer.shutdown();
}
pub fn getMeshPool() *MeshPool {
return context().meshPool;
}