Skip to content

Commit

Permalink
Update examples to use new generated helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed May 1, 2024
1 parent f0f6731 commit f730094
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 75 deletions.
8 changes: 4 additions & 4 deletions example/boxes.odin
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ BOXES_AMOUNT :: BOXES_ROWS * BOXES_ROWS * BOXES_ROWS

@private
State_Boxes :: struct {
using vert: Inputs_Boxes_Vert,
vao : VAO,
rotation : [2]f32,
using locations: Input_Locations_Boxes,
vao : VAO,
rotation: [2]f32,
}

@private
setup_boxes :: proc(s: ^State_Boxes, program: gl.Program) {
s.vao = gl.CreateVertexArray()
gl.BindVertexArray(s.vao)

input_locations_boxes_vert(s, program)
input_locations_boxes(s, program)

gl.Enable(gl.CULL_FACE) // don't draw back faces
gl.Enable(gl.DEPTH_TEST) // draw only closest faces
Expand Down
4 changes: 2 additions & 2 deletions example/camera.odin
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PYRAMID_COLORS: [PYRAMID_VERTICES]RGBA : {

@private
State_Camera :: struct {
using vert: Inputs_Boxes_Vert,
using locations: Input_Locations_Boxes,
vao: VAO,
rotation: f32,
}
Expand All @@ -34,7 +34,7 @@ setup_camera :: proc(s: ^State_Camera, program: gl.Program) {
s.vao = gl.CreateVertexArray()
gl.BindVertexArray(s.vao)

input_locations_boxes_vert(s, program)
input_locations_boxes(s, program)

gl.Enable(gl.CULL_FACE) // don't draw back faces
gl.Enable(gl.DEPTH_TEST) // draw only closest faces
Expand Down
6 changes: 2 additions & 4 deletions example/lighting.odin
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ RING_SPACE :: 30

@private
State_Lighting :: struct {
using vert: Inputs_Lighting_Vert,
using frag: Inputs_Lighting_Frag,
using locations: Input_Locations_Lighting,
vao : VAO,
cube_angle: f32,
ring_angle: f32,
Expand All @@ -37,8 +36,7 @@ setup_lighting :: proc(s: ^State_Lighting, program: gl.Program) {
s.vao = gl.CreateVertexArray()
gl.BindVertexArray(s.vao)

input_locations_lighting_vert(s, program)
input_locations_lighting_frag(s, program)
input_locations_lighting(s, program)

gl.Enable(gl.CULL_FACE) // don't draw back faces
gl.Enable(gl.DEPTH_TEST) // draw only closest faces
Expand Down
4 changes: 2 additions & 2 deletions example/pyramid.odin
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ colors: [VERTICES]RGBA = {

@private
State_Pyramid :: struct {
using vert: Inputs_Pyramid_Vert,
using locations: Input_Locations_Pyramid,
vao : VAO,
rotation : [2]f32,
}
Expand All @@ -51,7 +51,7 @@ setup_pyramid :: proc(s: ^State_Pyramid, program: gl.Program) {
s.vao = gl.CreateVertexArray()
gl.BindVertexArray(s.vao)

input_locations_pyramid_vert(s, program)
input_locations_pyramid(s, program)

gl.Enable(gl.CULL_FACE) // don't draw back faces

Expand Down
4 changes: 2 additions & 2 deletions example/rectangle.odin
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ positions: [VERTICES]vec2 = {

@private
State_Rectangle :: struct {
using vert: Inputs_Rectangle_Vert,
using locations: Input_Locations_Rectangle,
vao : VAO,
rotation : f32,
}
Expand All @@ -40,7 +40,7 @@ setup_rectangle :: proc(s: ^State_Rectangle, program: gl.Program) {
s.vao = gl.CreateVertexArray()
gl.BindVertexArray(s.vao) // need to bind VAO before binding buffers

input_locations_rectangle_vert(s, program)
input_locations_rectangle(s, program)

attribute(s.a_position, gl.CreateBuffer(), positions[:])
attribute(s.a_color , gl.CreateBuffer(), colors[:])
Expand Down
132 changes: 94 additions & 38 deletions example/shaders_generated.odin
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,62 @@ package example
import gl "../wasm/webgl"


Inputs_Rectangle_Vert :: struct {
Input_Locations_Rectangle :: struct {
a_position: Attribute_vec2,
a_color: Attribute_vec4,
u_matrix: Uniform_mat3,
}

input_locations_rectangle_vert :: proc(s: ^Inputs_Rectangle_Vert, program: gl.Program) {
input_locations_rectangle :: proc(s: ^Input_Locations_Rectangle, program: gl.Program) {
s.a_position = attribute_location_vec2(program, "a_position")
s.a_color = attribute_location_vec4(program, "a_color")
s.u_matrix = uniform_location_mat3(program, "u_matrix")
}

Inputs_Lighting_Vert :: struct {
Uniform_Values_Rectangle :: struct {
u_matrix: mat3,
}

Attribute_Values_Rectangle :: struct {
a_position: vec2,
a_color: vec4,
}

Input_Locations_Lighting :: struct {
a_position: Attribute_vec3,
a_normal: Attribute_vec3,
a_color: Attribute_vec4,
u_view: Uniform_mat4,
u_local: Uniform_mat4,
u_light_dir: Uniform_vec3,
u_light_color: Uniform_vec4,
}

input_locations_lighting_vert :: proc(s: ^Inputs_Lighting_Vert, program: gl.Program) {
input_locations_lighting :: proc(s: ^Input_Locations_Lighting, program: gl.Program) {
s.a_position = attribute_location_vec3(program, "a_position")
s.a_normal = attribute_location_vec3(program, "a_normal")
s.a_color = attribute_location_vec4(program, "a_color")
s.u_view = uniform_location_mat4(program, "u_view")
s.u_local = uniform_location_mat4(program, "u_local")
}

Inputs_Specular_Frag :: struct {
u_light_color: Uniform_vec4,
}

input_locations_specular_frag :: proc(s: ^Inputs_Specular_Frag, program: gl.Program) {
s.u_light_dir = uniform_location_vec3(program, "u_light_dir")
s.u_light_color = uniform_location_vec4(program, "u_light_color")
}

Inputs_Lighting_Frag :: struct {
u_light_dir: Uniform_vec3,
u_light_color: Uniform_vec4,
Uniform_Values_Lighting :: struct {
u_view: mat4,
u_local: mat4,
u_light_dir: vec3,
u_light_color: vec4,
}

input_locations_lighting_frag :: proc(s: ^Inputs_Lighting_Frag, program: gl.Program) {
s.u_light_dir = uniform_location_vec3(program, "u_light_dir")
s.u_light_color = uniform_location_vec4(program, "u_light_color")
Attribute_Values_Lighting :: struct {
a_position: vec3,
a_normal: vec3,
a_color: vec4,
}

Inputs_Specular_Vert :: struct {
Input_Locations_Specular :: struct {
u_light_color: Uniform_vec4,
a_position: Attribute_vec3,
a_normal: Attribute_vec3,
a_color: Attribute_vec4,
Expand All @@ -65,7 +74,8 @@ Inputs_Specular_Vert :: struct {
u_local: Uniform_mat4,
}

input_locations_specular_vert :: proc(s: ^Inputs_Specular_Vert, program: gl.Program) {
input_locations_specular :: proc(s: ^Input_Locations_Specular, program: gl.Program) {
s.u_light_color = uniform_location_vec4(program, "u_light_color")
s.a_position = attribute_location_vec3(program, "a_position")
s.a_normal = attribute_location_vec3(program, "a_normal")
s.a_color = attribute_location_vec4(program, "a_color")
Expand All @@ -75,65 +85,111 @@ input_locations_specular_vert :: proc(s: ^Inputs_Specular_Vert, program: gl.Prog
s.u_local = uniform_location_mat4(program, "u_local")
}

Inputs_Boxes_Vert :: struct {
Uniform_Values_Specular :: struct {
u_light_color: vec4,
u_light_pos: vec3,
u_eye_pos: vec3,
u_view: mat4,
u_local: mat4,
}

Attribute_Values_Specular :: struct {
a_position: vec3,
a_normal: vec3,
a_color: vec4,
}

Input_Locations_Boxes :: struct {
a_position: Attribute_vec3,
a_color: Attribute_vec4,
u_matrix: Uniform_mat4,
}

input_locations_boxes_vert :: proc(s: ^Inputs_Boxes_Vert, program: gl.Program) {
input_locations_boxes :: proc(s: ^Input_Locations_Boxes, program: gl.Program) {
s.a_position = attribute_location_vec3(program, "a_position")
s.a_color = attribute_location_vec4(program, "a_color")
s.u_matrix = uniform_location_mat4(program, "u_matrix")
}

Inputs_Spotlight_Vert :: struct {
Uniform_Values_Boxes :: struct {
u_matrix: mat4,
}

Attribute_Values_Boxes :: struct {
a_position: vec3,
a_color: vec4,
}

Input_Locations_Spotlight :: struct {
a_position: Attribute_vec3,
a_normal: Attribute_vec3,
u_light_pos: [2]Uniform_vec3,
u_view: Uniform_mat4,
u_local: Uniform_mat4,
u_light_add: [2]Uniform_float,
u_light_color: [2]Uniform_vec4,
u_light_dir: [2]Uniform_vec3,
}

input_locations_spotlight_vert :: proc(s: ^Inputs_Spotlight_Vert, program: gl.Program) {
input_locations_spotlight :: proc(s: ^Input_Locations_Spotlight, program: gl.Program) {
s.a_position = attribute_location_vec3(program, "a_position")
s.a_normal = attribute_location_vec3(program, "a_normal")
s.u_light_pos[0] = uniform_location_vec3(program, "u_light_pos[0]")
s.u_light_pos[1] = uniform_location_vec3(program, "u_light_pos[1]")
s.u_view = uniform_location_mat4(program, "u_view")
s.u_local = uniform_location_mat4(program, "u_local")
s.u_light_add[0] = uniform_location_float(program, "u_light_add[0]")
s.u_light_add[1] = uniform_location_float(program, "u_light_add[1]")
s.u_light_color[0] = uniform_location_vec4(program, "u_light_color[0]")
s.u_light_color[1] = uniform_location_vec4(program, "u_light_color[1]")
s.u_light_dir[0] = uniform_location_vec3(program, "u_light_dir[0]")
s.u_light_dir[1] = uniform_location_vec3(program, "u_light_dir[1]")
}

Uniform_Values_Spotlight :: struct {
u_light_pos: vec3,
u_view: mat4,
u_local: mat4,
u_light_add: float,
u_light_color: vec4,
u_light_dir: vec3,
}

Attribute_Values_Spotlight :: struct {
a_position: vec3,
a_normal: vec3,
}

Inputs_Pyramid_Vert :: struct {
Input_Locations_Pyramid :: struct {
a_position: Attribute_vec3,
a_color: Attribute_vec4,
u_matrix: Uniform_mat4,
}

input_locations_pyramid_vert :: proc(s: ^Inputs_Pyramid_Vert, program: gl.Program) {
input_locations_pyramid :: proc(s: ^Input_Locations_Pyramid, program: gl.Program) {
s.a_position = attribute_location_vec3(program, "a_position")
s.a_color = attribute_location_vec4(program, "a_color")
s.u_matrix = uniform_location_mat4(program, "u_matrix")
}

Inputs_Simple_Frag :: struct {
Uniform_Values_Pyramid :: struct {
u_matrix: mat4,
}

input_locations_simple_frag :: proc(s: ^Inputs_Simple_Frag, program: gl.Program) {
Attribute_Values_Pyramid :: struct {
a_position: vec3,
a_color: vec4,
}

Inputs_Spotlight_Frag :: struct {
u_light_add: [2]Uniform_float,
u_light_color: [2]Uniform_vec4,
u_light_dir: [2]Uniform_vec3,
Input_Locations_Simple :: struct {
}

input_locations_spotlight_frag :: proc(s: ^Inputs_Spotlight_Frag, program: gl.Program) {
s.u_light_add[0] = uniform_location_float(program, "u_light_add[0]")
s.u_light_add[1] = uniform_location_float(program, "u_light_add[1]")
s.u_light_color[0] = uniform_location_vec4(program, "u_light_color[0]")
s.u_light_color[1] = uniform_location_vec4(program, "u_light_color[1]")
s.u_light_dir[0] = uniform_location_vec3(program, "u_light_dir[0]")
s.u_light_dir[1] = uniform_location_vec3(program, "u_light_dir[1]")
input_locations_simple :: proc(s: ^Input_Locations_Simple, program: gl.Program) {
}

Uniform_Values_Simple :: struct {
}

Attribute_Values_Simple :: struct {
}

6 changes: 2 additions & 4 deletions example/specular.odin
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ BALL_RADIUS :: 200

@private
State_Specular :: struct {
using vert: Inputs_Specular_Vert,
using frag: Inputs_Specular_Frag,
using locations: Input_Locations_Specular,
vao : VAO,
cube_angle: f32,
ball_angle: f32,
Expand All @@ -31,8 +30,7 @@ setup_specular :: proc(s: ^State_Specular, program: gl.Program) {
s.vao = gl.CreateVertexArray()
gl.BindVertexArray(s.vao)

input_locations_specular_vert(s, program)
input_locations_specular_frag(s, program)
input_locations_specular(s, program)

gl.Enable(gl.CULL_FACE) // don't draw back faces
gl.Enable(gl.DEPTH_TEST) // draw only closest faces
Expand Down
6 changes: 2 additions & 4 deletions example/spotlight.odin
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ ALL_VERTICES :: PLANE_VERTICES + CUBE_VERTICES*2 + GUY_VERTICES

@private
State_Spotlight :: struct {
using vert : Inputs_Spotlight_Vert,
using frag : Inputs_Spotlight_Frag,
using locations: Input_Locations_Spotlight,
vao : VAO,
camera_angle: f32,
positions : [ALL_VERTICES]vec3,
Expand All @@ -49,8 +48,7 @@ setup_spotlight :: proc(s: ^State_Spotlight, program: gl.Program) {
s.vao = gl.CreateVertexArray()
gl.BindVertexArray(s.vao)

input_locations_spotlight_vert(s, program)
input_locations_spotlight_frag(s, program)
input_locations_spotlight(s, program)

gl.Enable(gl.CULL_FACE)
gl.Enable(gl.DEPTH_TEST)
Expand Down
Loading

0 comments on commit f730094

Please sign in to comment.