Skip to content

Commit ce0c714

Browse files
authored
Merge pull request #100 from guzba/master
add bindUniformBuffer to shaders
2 parents 12f73fb + 2b26057 commit ce0c714

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/fidget/opengl/buffers.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func size*(componentType: GLenum): Positive =
1717
1
1818
of cGL_SHORT, cGL_UNSIGNED_SHORT:
1919
2
20-
of GL_UNSIGNED_INT, cGL_FLOAT:
20+
of cGL_INT, GL_UNSIGNED_INT, cGL_FLOAT:
2121
4
2222
else:
2323
raise newException(Exception, "Unexpected componentType")

src/fidget/opengl/shaders.nim

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ template newShaderStatic*(computePath: string): Shader =
216216
## so it is compiled into the binary.
217217
const
218218
computeCode = staticRead(computePath)
219-
dir = currentSourcePath()
220-
computePathFull = dir.parentDir() / computePath
219+
dir = currentSourcePath().parentDir()
220+
computePathFull = dir / computePath
221221
newShader((computePathFull, computeCode))
222222

223223
proc newShader*(vert, frag: (string, string)): Shader =
@@ -241,9 +241,9 @@ template newShaderStatic*(vertPath, fragPath: string): Shader =
241241
const
242242
vertCode = staticRead(vertPath)
243243
fragCode = staticRead(fragPath)
244-
dir = currentSourcePath()
245-
vertPathFull = dir.parentDir() / vertPath
246-
fragPathFull = dir.parentDir() / fragPath
244+
dir = currentSourcePath().parentDir()
245+
vertPathFull = dir / vertPath
246+
fragPathFull = dir / fragPath
247247
newShader((vertPathFull, vertCode), (fragPathFull, fragCode))
248248

249249
proc hasUniform*(shader: Shader, name: string): bool =
@@ -430,6 +430,14 @@ proc bindUniforms*(shader: Shader) =
430430

431431
uniform.changed = false
432432

433+
proc bindUniformBuffer*(
434+
shader: Shader, name: string, buffer: Buffer, binding: GLuint
435+
) =
436+
assert buffer.target == GL_UNIFORM_BUFFER
437+
let index = glGetUniformBlockIndex(shader.programId, name)
438+
glBindBufferBase(GL_UNIFORM_BUFFER, binding, buffer.bufferId)
439+
glUniformBlockBinding(shader.programId, index, binding)
440+
433441
proc bindAttrib*(
434442
shader: Shader,
435443
name: string,

0 commit comments

Comments
 (0)