Skip to content

Commit a6ab1fc

Browse files
committed
Properly bind bindgroups
1 parent c1e966c commit a6ab1fc

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

packages/arisu-gfx/bind_group.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ BindGroup.__index = BindGroup
1111
---@alias gfx.BindGroupEntry
1212
--- | { type: "buffer", binding: number, buffer: gfx.Buffer, visibility: gfx.ShaderStage[] }
1313
--- | { type: "sampler", binding: number, sampler: gfx.Sampler, visibility: gfx.ShaderStage[] }
14-
--- | { type: "texture", binding: number, textureView: gfx.Texture, visibility: gfx.ShaderStage[] }
14+
--- | { type: "texture", binding: number, texture: gfx.Texture, visibility: gfx.ShaderStage[] }
1515

1616
---@param entries gfx.BindGroupEntry[]
1717
function BindGroup.new(entries)

packages/arisu-gfx/buffer/gl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function GLBuffer.new(descriptor)
1515

1616
local isUniform = false
1717
for _, usage in ipairs(descriptor.usages) do
18-
if usage == "uniform" then
18+
if usage == "UNIFORM" then
1919
isUniform = true
2020
break
2121
end

packages/arisu-gfx/command_buffer/gl.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,22 @@ function GLCommandBuffer:execute()
9797
local buffer = command.buffer --[[@as gfx.gl.Buffer]]
9898
buffer:setSlice(command.size, command.data, command.offset)
9999
elseif command.type == "setBindGroup" then
100-
-- I don't think this needs to exist for OpenGL
100+
for _, entry in ipairs(command.bindGroup.entries) do
101+
if entry.type == "buffer" then
102+
local buffer = entry.buffer --[[@as gfx.gl.Buffer]]
103+
if buffer.isUniform then
104+
gl.bindBufferBase(gl.UNIFORM_BUFFER, entry.binding, buffer.id)
105+
else
106+
error("Only uniform buffers are supported in bind groups for now")
107+
end
108+
elseif entry.type == "texture" then
109+
local texture = entry.texture --[[@as gfx.gl.Texture]]
110+
gl.bindTextureUnit(entry.binding, texture.id)
111+
elseif entry.type == "sampler" then
112+
local sampler = entry.sampler --[[@as gfx.gl.Sampler]]
113+
gl.bindSampler(entry.binding, sampler.id)
114+
end
115+
end
101116
elseif command.type == "drawIndexed" then
102117
gl.drawElements(gl.TRIANGLES, command.indexCount, indexType, nil)
103118
else

packages/arisu/gl/texture_manager.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local gl = require("arisu-opengl")
55
local gfx = require("arisu-gfx")
66

77
local Image = require("arisu-image")
8+
local Texture = require("arisu-gfx.texture.gl")
89

910
local maxWidth = 1024
1011
local maxHeight = 1024
@@ -177,16 +178,19 @@ end
177178
function TextureManager:createBindGroup(binding, samplerBinding, dimsBinding)
178179
return self.device:createBindGroup({
179180
{
181+
type = "texture",
180182
binding = binding,
181-
texture = self.textureHandle,
183+
texture = Texture.new(0, self.textureHandle),
182184
visibility = { "FRAGMENT" },
183185
},
184186
{
187+
type = "sampler",
185188
binding = samplerBinding,
186189
sampler = self.sampler,
187190
visibility = { "FRAGMENT" },
188191
},
189192
{
193+
type = "buffer",
190194
binding = dimsBinding,
191195
buffer = self.textureDimsBuffer,
192196
visibility = { "FRAGMENT" },

0 commit comments

Comments
 (0)