mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
opengl: uniforms
This commit is contained in:
@ -70,6 +70,8 @@ pub fn main() !void {
|
|||||||
c.glClear(c.GL_COLOR_BUFFER_BIT);
|
c.glClear(c.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
try program.use();
|
try program.use();
|
||||||
|
try program.setUniform("vertexColor", @Vector(4, f32){ 0.0, 1.0, 0.0, 1.0 });
|
||||||
|
|
||||||
try vao.bind();
|
try vao.bind();
|
||||||
c.glDrawArrays(c.GL_TRIANGLES, 0, 3);
|
c.glDrawArrays(c.GL_TRIANGLES, 0, 3);
|
||||||
|
|
||||||
@ -95,8 +97,10 @@ const fs_source =
|
|||||||
\\#version 330 core
|
\\#version 330 core
|
||||||
\\out vec4 FragColor;
|
\\out vec4 FragColor;
|
||||||
\\
|
\\
|
||||||
|
\\uniform vec4 vertexColor;
|
||||||
|
\\
|
||||||
\\void main()
|
\\void main()
|
||||||
\\{
|
\\{
|
||||||
\\ FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
\\ FragColor = vertexColor;
|
||||||
\\}
|
\\}
|
||||||
;
|
;
|
||||||
|
@ -45,6 +45,22 @@ pub inline fn use(p: Program) !void {
|
|||||||
c.glUseProgram(p.id);
|
c.glUseProgram(p.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Requires the program is currently in use.
|
||||||
|
pub inline fn setUniform(p: Program, n: [:0]const u8, value: anytype) !void {
|
||||||
|
const loc = c.glGetUniformLocation(p.id, n);
|
||||||
|
if (loc < 0) {
|
||||||
|
return error.UniformNameInvalid;
|
||||||
|
}
|
||||||
|
try errors.getError();
|
||||||
|
|
||||||
|
// Perform the correct call depending on the type of the value.
|
||||||
|
switch (@TypeOf(value)) {
|
||||||
|
@Vector(4, f32) => c.glUniform4f(loc, value[0], value[1], value[2], value[3]),
|
||||||
|
else => unreachable,
|
||||||
|
}
|
||||||
|
try errors.getError();
|
||||||
|
}
|
||||||
|
|
||||||
/// getInfoLog returns the info log for this program. This attempts to
|
/// getInfoLog returns the info log for this program. This attempts to
|
||||||
/// keep the log fully stack allocated and is therefore limited to a max
|
/// keep the log fully stack allocated and is therefore limited to a max
|
||||||
/// amount of elements.
|
/// amount of elements.
|
||||||
|
Reference in New Issue
Block a user