mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 19:28:49 -04:00
Use glBufferStorage
to tell the driver that certain buffers are only uploaded once and never changed.
Should fix #144
This commit is contained in:
parent
bfb6466f7e
commit
d6ab3d587b
@ -345,9 +345,9 @@ pub const meshes = struct {
|
||||
break :blk names;
|
||||
};
|
||||
|
||||
var animationSSBO: SSBO = undefined;
|
||||
var textureDataSSBO: SSBO = undefined;
|
||||
var animatedTextureDataSSBO: SSBO = undefined;
|
||||
var animationSSBO: ?SSBO = null;
|
||||
var textureDataSSBO: ?SSBO = null;
|
||||
var animatedTextureDataSSBO: ?SSBO = null;
|
||||
|
||||
var animationShader: Shader = undefined;
|
||||
var animationUniforms: struct {
|
||||
@ -366,12 +366,6 @@ pub const meshes = struct {
|
||||
const emptyImage = Image{.width = 1, .height = 1, .imageData = emptyTexture[0..]};
|
||||
|
||||
pub fn init() !void {
|
||||
animationSSBO = SSBO.init();
|
||||
animationSSBO.bind(0);
|
||||
textureDataSSBO = SSBO.init();
|
||||
textureDataSSBO.bind(6);
|
||||
animatedTextureDataSSBO = SSBO.init();
|
||||
animatedTextureDataSSBO.bind(1);
|
||||
animationShader = try Shader.initComputeAndGetUniforms("assets/cubyz/shaders/animation_pre_processing.glsl", &animationUniforms);
|
||||
blockTextureArray = TextureArray.init();
|
||||
emissionTextureArray = TextureArray.init();
|
||||
@ -384,9 +378,15 @@ pub const meshes = struct {
|
||||
}
|
||||
|
||||
pub fn deinit() void {
|
||||
animationSSBO.deinit();
|
||||
textureDataSSBO.deinit();
|
||||
animatedTextureDataSSBO.deinit();
|
||||
if(animationSSBO) |ssbo| {
|
||||
ssbo.deinit();
|
||||
}
|
||||
if(textureDataSSBO) |ssbo| {
|
||||
ssbo.deinit();
|
||||
}
|
||||
if(animatedTextureDataSSBO) |ssbo| {
|
||||
ssbo.deinit();
|
||||
}
|
||||
animationShader.deinit();
|
||||
blockTextureArray.deinit();
|
||||
emissionTextureArray.deinit();
|
||||
@ -576,8 +576,20 @@ pub const meshes = struct {
|
||||
try emissionTextureArray.generate(emissionTextures.items, true);
|
||||
|
||||
// Also generate additional buffers:
|
||||
animationSSBO.bufferData(AnimationData, animation.items);
|
||||
textureDataSSBO.bufferData(TextureData, textureData[0..meshes.size]);
|
||||
animatedTextureDataSSBO.bufferData(TextureData, textureData[0..meshes.size]);
|
||||
if(animationSSBO) |ssbo| {
|
||||
ssbo.deinit();
|
||||
}
|
||||
if(textureDataSSBO) |ssbo| {
|
||||
ssbo.deinit();
|
||||
}
|
||||
if(animatedTextureDataSSBO) |ssbo| {
|
||||
ssbo.deinit();
|
||||
}
|
||||
animationSSBO = SSBO.initStatic(AnimationData, animation.items);
|
||||
animationSSBO.?.bind(0);
|
||||
textureDataSSBO = SSBO.initStatic(TextureData, textureData[0..meshes.size]);
|
||||
textureDataSSBO.?.bind(6);
|
||||
animatedTextureDataSSBO = SSBO.initStatic(TextureData, textureData[0..meshes.size]);
|
||||
animatedTextureDataSSBO.?.bind(1);
|
||||
}
|
||||
};
|
||||
|
@ -1170,6 +1170,14 @@ pub const SSBO = struct {
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn initStatic(comptime T: type, data: []const T) SSBO {
|
||||
var self = SSBO{.bufferID = undefined};
|
||||
c.glGenBuffers(1, &self.bufferID);
|
||||
c.glBindBuffer(c.GL_SHADER_STORAGE_BUFFER, self.bufferID);
|
||||
c.glBufferStorage(c.GL_SHADER_STORAGE_BUFFER, @intCast(data.len*@sizeOf(T)), data.ptr, 0);
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn deinit(self: SSBO) void {
|
||||
c.glDeleteBuffers(1, &self.bufferID);
|
||||
}
|
||||
|
@ -174,9 +174,6 @@ pub var fullCube: u16 = 0;
|
||||
// TODO: Allow loading from world assets.
|
||||
// TODO: Editable player models.
|
||||
pub fn init() !void {
|
||||
voxelModelSSBO = graphics.SSBO.init();
|
||||
voxelModelSSBO.bind(4);
|
||||
|
||||
voxelModels = std.ArrayList(VoxelModel).init(main.threadAllocator);
|
||||
|
||||
nameToIndex = std.StringHashMap(u16).init(main.threadAllocator);
|
||||
@ -199,7 +196,8 @@ pub fn init() !void {
|
||||
try nameToIndex.put("octahedron", @intCast(voxelModels.items.len));
|
||||
(try voxelModels.addOne()).init(octahedron);
|
||||
|
||||
voxelModelSSBO.bufferData(VoxelModel, voxelModels.items);
|
||||
voxelModelSSBO = graphics.SSBO.initStatic(VoxelModel, voxelModels.items);
|
||||
voxelModelSSBO.bind(4);
|
||||
}
|
||||
|
||||
pub fn deinit() void {
|
||||
|
Loading…
x
Reference in New Issue
Block a user