-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathindex.html
239 lines (210 loc) · 10.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html>
<head>
<title>PicoGL.js</title>
<meta charset="utf-8">
<link rel="stylesheet" href="site/css/docco.css">
<link rel="stylesheet" href="site/css/picogl.css">
<script src="site/js/highlight.min.js"></script>
</head>
<body>
<a href="https://github.com/tsherif/picogl.js"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png"></a>
<h1>PicoGL.js</h1>
<div class="description">
<a class="badge-link" href="https://travis-ci.org/tsherif/picogl.js">
<img src="https://img.shields.io/travis/tsherif/picogl.js">
</a>
<a href="https://coveralls.io/github/tsherif/picogl.js?branch=master">
<img src="https://img.shields.io/coveralls/github/tsherif/picogl.js" alt="Coverage Status" />
</a>
<a class="badge-link" href="https://github.com/tsherif/picogl.js/blob/master/build/picogl.min.js">
<img src="https://badge-size.herokuapp.com/tsherif/picogl.js/master/build/picogl.min.js.svg?compression=gzip">
</a>
<a class="badge-link" href="https://gitter.im/picogl-js/general">
<img src="https://img.shields.io/gitter/room/picogl.js/general.svg">
</a>
<a class="badge-link" href="https://github.com/tsherif/picogl.js/blob/master/LICENSE">
<img src="https://img.shields.io/github/license/tsherif/picogl.js.svg">
</a>
<a class="badge-link" href="https://www.npmjs.com/package/picogl">
<img src="https://img.shields.io/npm/v/picogl.svg">
</a>
</div>
<div class="description">
<a class="resources-link" href="./docs/">
API Docs
</a> |
<a class="resources-link" href="https://tsherif.wordpress.com/2017/07/26/webgl-2-development-with-picogl-js/">
Tutorial
</a> |
<a class="resources-link" href="https://gitter.im/picogl-js/general">
Chat
</a>
</div>
<div class="description">
PicoGL.js is a minimal WebGL 2 rendering library. It's meant for developers who understand the WebGL 2 rendering pipeline and want to use it, but with a more convenient API. Typical usage of PicoGL.js will involve creating programs, vertex buffers, vertex arrays, uniform buffers, framebuffers, textures, transform feedbacks, and combining them into draw calls.
</div>
<pre><code class="javascript">
// Create a PicoGL.js app to manage GL state.
let app = PicoGL.createApp(canvas)
.clearColor(0.0, 0.0, 0.0, 1.0);
// Create program from shader source.
// Shaders are compiled in parallel if supported by the platform.
app.createPrograms([vertexShaderSource, fragmentShaderSource]).then(([program]) => {
// Scene geometry stored vertex buffer object.
let positions = app.createVertexBuffer(PicoGL.FLOAT, 2, new Float32Array([
-0.5, -0.5,
0.5, -0.5,
0.0, 0.5
]));
// Vertex buffer and attribute pointer state stored
// in vertex array object.
let vertexArray = app.createVertexArray()
.vertexAttributeBuffer(0, positions);
// Scene data stored in uniform buffer object.
let uniformBuffer = app.createUniformBuffer([
PicoGL.FLOAT_VEC4,
PicoGL.FLOAT_VEC4
])
.set(0, new Float32Array([1.0, 0.0, 0.0, 0.3]))
.set(1, new Float32Array([0.0, 0.0, 1.0, 0.7]))
.update();
// Create a draw call from program, vertex array, uniform buffer.
let drawCall = app.createDrawCall(program, vertexArray)
.uniformBlock("ColorUniforms", uniformBuffer);
// Draw!
app.clear()
drawCall.draw();
});
</code></pre>
<div class="description">
PicoGL.js can be used directly by downloading the <a href="https://tsherif.github.io/picogl.js/build/picogl.min.js">built source</a> and loading it via a script tag:
</div>
<pre><code class="html">
<script src="js/picogl.min.js"></script>
</code></pre>
<div class="description">
or it can be installed via <a href="https://www.npmjs.com/package/picogl">npm</a>:
</div>
<pre><code class="bash">
npm install picogl
</code></pre>
<div class="description">
and loaded via ES6-style <code>import</code>:
</div>
<pre><code class="javascript">
import PicoGL from "picogl";
</code></pre>
<div class="description">
Note that PicoGL.js is <strong>not</strong> a scene graph library. There are no objects, hierarchies, transforms, materials, etc. It has been designed only to make management of GPU state more convenient. Its conceptual model maps fairly directly to the constructs one deals with when writing directly with the WebGL 2 API. The only higher-level construct is the draw call, which manages sets of related lower-level constructs.
</div>
<h2>Basic Examples</h2>
<a href="#" class="example-menu-button" id="triangle">Triangle</a>
<a href="#" class="example-menu-button" id="interleaved-triangle">Interleaved Triangle</a>
<a href="#" class="example-menu-button" id="ubo">Uniform Buffers</a>
<a href="#" class="example-menu-button" id="instanced">Instanced Drawing</a>
<a href="#" class="example-menu-button" id="multi-draw">Multi-draw</a>
<a href="#" class="example-menu-button" id="transformfeedback">Transform Feedback</a>
<a href="#" class="example-menu-button" id="interleaved-transformfeedback">Interleaved Transform Feedback</a>
<a href="#" class="example-menu-button" id="cube">Phong-shaded Cube</a>
<a href="#" class="example-menu-button" id="cubemap">Cubemap</a>
<a href="#" class="example-menu-button" id="texturearray">Texture Array</a>
<a href="#" class="example-menu-button" id="3Dtexture">3D Texture</a>
<a href="#" class="example-menu-button" id="rtt">Render to Texture</a>
<a href="#" class="example-menu-button" id="rtt_msaa">Render to MSAA Renderbuffer</a>
<a href="#" class="example-menu-button" id="render-to-cubemap">Render to Cubemap</a>
<a href="#" class="example-menu-button" id="render-to-3Dtexture">Render to 3D texture</a>
<a href="#" class="example-menu-button" id="compressed-textures">Compressed Textures</a>
<a href="#" class="example-menu-button" id="compressed-cubemap">Compressed Cubemap</a>
<a href="#" class="example-menu-button" id="context-loss">Context Loss</a>
<h2>Advanced Examples</h2>
<a href="#" class="example-menu-button" id="picking">Picking</a>
<a href="#" class="example-menu-button" id="shadow">Shadow Mapping</a>
<a href="#" class="example-menu-button" id="dof">Depth of Field</a>
<a href="#" class="example-menu-button" id="ssao">Screen Space Ambient Occlusion</a>
<a href="#" class="example-menu-button" id="deferred">Deferred Rendering</a>
<a href="#" class="example-menu-button" id="oit">Order-independent Transparency</a>
<a href="#" class="example-menu-button" id="particles">Particles</a>
<a href="#" class="example-menu-button" id="bloom">Bloom</a>
<a href="#" class="example-menu-button" id="wandering-triangles">Wandering Triangles</a>
<a href="#" class="example-menu-button" id="cloth">Cloth</a>
<a href="#" class="example-menu-button" id="outline">Outline</a>
<a href="#" class="example-menu-button" id="occlusion">Occlusion Culling</a>
<a href="#" class="example-menu-button" id="motion-blur">Motion Blur</a>
<a href="#" class="example-menu-button" id="mesh-compression">Mesh Compression</a>
<a href="#" class="example-menu-button" id="omni-shadows">Omni-directional Shadows</a>
<h2>Benchmarks</h2>
<a href="#" class="example-menu-button" id="64kcubes">64,000 Cubes</a>
<a href="#" class="example-menu-button" id="125kcubes">125,000 Cubes</a>
<div id="example-div">
<div id="example-title"></div>
<iframe id="examples"></iframe>
</div>
<script>
var exampleFrame = document.getElementById("examples");
var exampleTitle = document.getElementById("example-title");
document.body.addEventListener("click", function(event) {
if (event.target.className !== "example-menu-button") {
return;
}
var link = event.target;
var title = link.text;
if (title === "Wandering Triangles") {
title += "<BR>(Transform Feedback and Instanced Drawing)";
}
if (title === "Cloth") {
title += "<BR>(Use mouse to control ball)";
}
if (title === "Mesh Compression") {
title += "<BR>Sphere on the left is uncompressed, sphere on the right is quantized <BR>and oct-encoded.";
}
var src = "examples/" + event.target.id + ".html";
var sourceCodeURL = "https://github.com/tsherif/picogl.js/blob/master/" + src;
exampleTitle.innerHTML = title + "<div><a href=\"" + sourceCodeURL + "\">Source code</a>";
examples.src = src;
event.stopPropagation();
event.preventDefault();
});
var canvas = document.createElement("canvas");
var gl = canvas.getContext("webgl2");
if (gl) {
var showcase = [
"3Dtexture",
"shadow",
"dof",
"particles",
"64kcubes",
"125kcubes",
"wandering-triangles",
"outline",
"occlusion",
"render-to-3Dtexture",
"omni-shadows"
];
if (gl.getExtension("EXT_color_buffer_float")) {
showcase.push(
"ssao",
"deferred",
"oit",
"bloom",
"cloth",
"motion-blur"
);
}
var showcaseId = showcase[Math.floor(Math.random() * showcase.length)];
document.getElementById(showcaseId).click();
function testAll() {
var buttons = document.getElementsByClassName("example-menu-button");
var index = 0;
setInterval(function() {
buttons[index].click();
index = (index + 1) % buttons.length;
}, 2000);
}
} else {
document.getElementById("example-div").innerHTML = "Sorry your browser does not support WebGL 2.";
}
hljs.initHighlightingOnLoad();
</script>
</body>
</html>