Skip to content

Commit 378d647

Browse files
committed
Updated all sources to current WebGL and TypedArray APIs; WebGLFloatArray -> Float32Array, etc.
Removed illegal enables of state like TEXTURE_2D, LINE_SMOOTH, POINT_SMOOTH, and VERTEX_ARRAY. Fixed texture wrap mode specifications in ftexture.js. Changed primitive.compile_program to accept list of attributes to bind. Enabled OES_texture_float extension at beginning of time because it's required throughout. Added precision qualifiers to all fragment shaders. In nurbs.vert, changed outer loops to reference constants, and inner loop to use constant loop bounds and "continue", to match GLSL ES restrictions. Added missing noisetexture.js from webglot3d project.
1 parent 268403a commit 378d647

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

noisetexture.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Copyright (c) 2009-2010 King Abdullah University of Science and Technology
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in all
11+
* copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
* SOFTWARE.
20+
*/
21+
22+
/** Noisetexture-generating function. Some algorithms need
23+
* a random noise texture as input. Notably the flow surface
24+
*
25+
* @param {WebGLContext} context the context in which we'll be working
26+
* @param {int} width the width of the texture to generate
27+
* @param {int} height the height of the texture to generate
28+
*
29+
* @see flow
30+
*/
31+
function noisetexture(context, width, height) {
32+
/** The WebGLTexture object that we'll return */
33+
this.texture = null;
34+
/** @deprecated */
35+
this.image = null;
36+
/** The local copy of the WebGLContext we'll use */
37+
this.gl = context;
38+
/** Local copy of the width of the texture */
39+
this.width = width;
40+
/** Local copy of the height of the texture */
41+
this.height = height;
42+
43+
/** Initialize the randomized noise texture */
44+
this.initialize = function() {
45+
this.texture = this.gl.createTexture();
46+
this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture);
47+
48+
var pixels = new Float32Array(this.width * this.height * 4);
49+
var count = this.width * this.height * 4;
50+
//*
51+
for (var i = 0; i < count; i += 1) {
52+
pixels[i] = Math.random() * 3.0;
53+
//pixels[i] = 4.0 * i / count;
54+
//pixels[i] = 0.0;
55+
}
56+
//*/
57+
58+
/*
59+
for (var i = count / 4; i < count / 2; i += 1) {
60+
pixels[i] = 1.0;
61+
}
62+
*/
63+
this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, this.width, this.height, 0, this.gl.RGBA, this.gl.FLOAT, pixels);
64+
65+
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);
66+
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);
67+
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
68+
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
69+
this.gl.bindTexture(this.gl.TEXTURE_2D, null);
70+
}
71+
72+
this.bind = function() {
73+
this.gl.bindTexture(this.gl.TEXTURE_2D, this.texture);
74+
}
75+
76+
this.initialize();
77+
78+
//return this.texture;
79+
}

0 commit comments

Comments
 (0)