-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Richard
authored and
Richard
committed
Mar 30, 2019
1 parent
2a1a635
commit f818701
Showing
11 changed files
with
151 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,5 @@ | |
}) | ||
.then(results => { | ||
console.log(results.instance.exports.main(42)); | ||
debugger; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build: | ||
cd ../../ && cargo build | ||
../../target/debug/wasp build | ||
serve: | ||
http-server -p 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-US"> | ||
<head> | ||
<title>Wasp</title> | ||
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@latest/webcomponents-loader.js"></script> | ||
<script src="https://unpkg.com/web-dom@latest/web-dom.js"></script> | ||
</head> | ||
<body> | ||
<canvas id="screen" width="500" height="500"></canvas> | ||
<web-dom module="webgl.wasm"></web-dom> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
(def COLOR_BUFFER_BIT 16384) | ||
(def VERTEX_SHADER 35633) | ||
(def FRAGMENT_SHADER 35632) | ||
(def vertex_shader_src " | ||
precision mediump float; | ||
attribute vec2 vertPosition; | ||
attribute vec3 vertColor; | ||
varying vec3 fragColor; | ||
void main() | ||
{ | ||
fragColor = vertColor; | ||
gl_Position = vec4(vertPosition, 0.0, 1.0); | ||
} | ||
") | ||
(def fragment_shader_src " | ||
precision mediump float; | ||
|
||
varying vec3 fragColor; | ||
void main() | ||
{ | ||
gl_FragColor = vec4(fragColor, 1.0); | ||
} | ||
") | ||
|
||
(extern global_get_window []) | ||
(extern window_get_document [window]) | ||
(extern document_query_selector [document query]) | ||
(extern htmlcanvas_get_context [element context]) | ||
(extern webgl_create_shader [ctx shader_type] ) | ||
(extern webgl_shader_source [ctx shader source] ) | ||
(extern webgl_compile_shader [ctx shader] ) | ||
(extern webgl_create_shader [ctx shader_type vertex_shader_src] ) | ||
(extern webgl_create_program [ctx] ) | ||
(extern webgl_attach_shader [ctx program shader] ) | ||
(extern webgl_link_program [ctx program] ) | ||
(extern webgl_use_program [ctx program] ) | ||
(extern webgl_clear_color [ctx r g b a] ) | ||
(extern webgl_clear [ctx buffer_bit] ) | ||
(extern webgl_get_attrib_location [ctx program attrib_name] ) | ||
|
||
(defn create_shader [ctx shader_type source] | ||
(let [shader (webgl_create_shader ctx shader_type)] | ||
(webgl_shader_source ctx shader source) | ||
(webgl_compile_shader ctx shader) | ||
shader)) | ||
|
||
(defn start_program [ctx] | ||
(let [vertex_shader (create_shader ctx VERTEX_SHADER vertex_shader_src) | ||
fragment_shader (create_shader ctx FRAGMENT_SHADER fragment_shader_src) | ||
program (webgl_create_program ctx)] | ||
(webgl_attach_shader ctx program vertex_shader) | ||
(webgl_attach_shader ctx program fragment_shader) | ||
(webgl_link_program ctx program) | ||
(webgl_use_program ctx program) | ||
program)) | ||
|
||
(pub defn main [] | ||
(let [win (global_get_window) | ||
doc (window_get_document win) | ||
canvas (document_query_selector doc "#screen") | ||
ctx (htmlcanvas_get_context canvas "webgl")] | ||
(webgl_clear_color ctx 0.75 0.85 0.8 1.0) | ||
(webgl_clear ctx COLOR_BUFFER_BIT) | ||
(let [program (start_program ctx) | ||
position_location (webgl_get_attrib_location ctx program "vertPosition") | ||
color_location (webgl_get_attrib_location ctx program "vertColor")] | ||
123))) | ||
|
||
|
||
; // create a program and get its attribute and uniforms | ||
; let program = start_program(ctx); | ||
; let position_location = webgl::get_attrib_location(ctx, program, "vertPosition"); | ||
; let color_location = webgl::get_attrib_location(ctx, program, "vertColor"); | ||
; webgl::use_program(ctx, NULL); | ||
; | ||
; // setup data buffer | ||
; let vertices: Vec<f32> = vec![ | ||
; // X, Y, R, G, B | ||
; 0.0, 0.5, 1.0, 1.0, 0.0, -0.5, -0.5, 0.7, 0.0, 1.0, 0.5, -0.5, 0.1, 1.0, 0.6, | ||
; ]; | ||
; let vertices = create_f32array(&vertices.into_bytes()); | ||
; let vertex_buffer = webgl::create_buffer(ctx); | ||
; webgl::bind_buffer(ctx, webgl::ARRAY_BUFFER, vertex_buffer); | ||
; webgl::buffer_data(ctx, webgl::ARRAY_BUFFER, vertices, webgl::STATIC_DRAW); | ||
; webgl::bind_buffer(ctx, webgl::ARRAY_BUFFER, NULL); | ||
; | ||
; // setup for drawing | ||
; webgl::use_program(ctx, program); | ||
; | ||
; // draw | ||
; webgl::bind_buffer(ctx, webgl::ARRAY_BUFFER, vertex_buffer); | ||
; webgl::enable_vertex_attrib_array(ctx, position_location); | ||
; webgl::enable_vertex_attrib_array(ctx, color_location); | ||
; webgl::vertex_attrib_pointer( | ||
; ctx, | ||
; position_location, | ||
; 2.0, | ||
; webgl::FLOAT, | ||
; false, | ||
; 5.0 * 4.0, | ||
; 0.0, | ||
; ); | ||
; webgl::vertex_attrib_pointer( | ||
; ctx, | ||
; color_location, | ||
; 3.0, | ||
; webgl::FLOAT, | ||
; false, | ||
; 5.0 * 4.0, | ||
; 2.0 * 4.0, | ||
; ); | ||
; webgl::bind_buffer(ctx, webgl::ARRAY_BUFFER, NULL); | ||
; | ||
; webgl::draw_arrays(ctx, webgl::TRIANGLES, 0.0, 3.0); | ||
; } |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters