forked from WebGLSamples/WebGLSamples.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear.html
More file actions
executable file
·193 lines (178 loc) · 5.3 KB
/
Copy pathclear.html
File metadata and controls
executable file
·193 lines (178 loc) · 5.3 KB
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
<!--
* Copyright 2009, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>WebGL Clear test</title>
<style>
html, body {
width: 100%;
height: 100%;
border: 0px;
padding: 0px;
margin: 0px;
background-color: red;
}
CANVAS {
background-color: gray;
}
#canvas2d {
display: none;
position: absolute;
top: 10px;
left: 10px;
z-index: 3;
}
.fpsContainer {
position: absolute;
top: 10px;
left: 10px;
z-index: 3;
color: white;
font-family: sans-serif;
background-color: rgba(0,0,0,0.5);
border-radius: 10px;
padding: 10px;
}
.fpsContainer a:visited, .fpsContainer a:hover, .fpsContainer a {
color: white;
font-size: xx-small;
}
#viewContainer {
width: 100%;
height: 100%;
}
</style>
<script src="../tdl/base.js"></script>
<script>
tdl.require('tdl.buffers');
tdl.require('tdl.fast');
tdl.require('tdl.fps');
tdl.require('tdl.log');
tdl.require('tdl.math');
tdl.require('tdl.models');
tdl.require('tdl.particles');
tdl.require('tdl.primitives');
tdl.require('tdl.programs');
tdl.require('tdl.textures');
tdl.require('tdl.webgl');
window.onload = initialize;
// globals
var gl; // the gl context.
var canvas; // the canvas
var math; // the math lib.
var fast; // the fast math lib.
var g_fpsTimer; // object to measure frames per second;
var g_logGLCalls = true; // whether or not to log webgl calls
var g_debug = false; // whether or not to debug.
var g_drawOnce = false; // draw just one frame.
//g_drawOnce = true;
//g_debug = true;
function ValidateNoneOfTheArgsAreUndefined(functionName, args) {
for (var ii = 0; ii < args.length; ++ii) {
if (args[ii] === undefined) {
tdl.error("undefined passed to gl." + functionName + "(" +
tdl.webgl.glFunctionArgsToString(functionName, args) + ")");
}
}
}
function Log(msg) {
if (g_logGLCalls) {
tdl.log(msg);
}
}
function LogGLCall(functionName, args) {
if (g_logGLCalls) {
ValidateNoneOfTheArgsAreUndefined(functionName, args)
tdl.log("gl." + functionName + "(" +
tdl.webgl.glFunctionArgsToString(functionName, args) + ")");
}
}
function initialize() {
math = tdl.math;
fast = tdl.fast;
canvas = document.getElementById("canvas");
g_fpsTimer = new tdl.fps.FPSTimer();
gl = tdl.webgl.setupWebGL(canvas);
if (!gl) {
return false;
}
if (g_debug) {
gl = tdl.webgl.makeDebugContext(gl, undefined, LogGLCall);
}
var then = 0.0;
var clock = 0.0;
var fpsElem = document.getElementById("fps");
var frameCount = 0;
var eyeClock = 0;
function render() {
++frameCount;
if (!g_drawOnce) {
requestAnimationFrame(render);
}
var now = (new Date()).getTime() * 0.001;
var elapsedTime;
if(then == 0.0) {
elapsedTime = 0.0;
} else {
elapsedTime = now - then;
}
then = now;
g_fpsTimer.update(elapsedTime);
fpsElem.innerHTML = g_fpsTimer.averageFPS;
clock += elapsedTime;
gl.colorMask(true, true, true, true);
gl.depthMask(true);
gl.clearColor(
frameCount % 2,
frameCount % 4 / 3,
frameCount % 8 / 7,
1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
// turn off logging after 1 frame.
g_logGLCalls = false;
}
render();
return true;
}
</script>
</head>
<body>
<div class="fpsContainer">
<div class="fps">fps: <span id="fps"></div>
</div>
<div id="viewContainer">
<canvas id="canvas" width="1024" height="1024" style="width: 100%; height: 100%;"></canvas>
</div>
</body>
</html>