This repository was archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathColorProgram.js
More file actions
113 lines (92 loc) · 3.6 KB
/
Copy pathColorProgram.js
File metadata and controls
113 lines (92 loc) · 3.6 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
CAAT.Module( {
/**
* @name ColorProgram
* @memberOf CAAT.WebGL
* @extends CAAT.WebGL.Program
* @constructor
*/
defines : "CAAT.WebGL.ColorProgram",
aliases : ["CAAT.ColorProgram"],
extendsClass : "CAAT.WebGL.Program",
depends : [
"CAAT.WebGL.Program"
],
extendsWith : {
/**
* @lends CAAT.WebGL.ColorProgram.prototype
*/
__init : function(gl) {
this.__super(gl);
return this;
},
/**
* int32 Array for color Buffer
*/
colorBuffer: null,
/**
* GLBuffer for vertex buffer.
*/
vertexPositionBuffer: null,
/**
* Float32 Array for vertex buffer.
*/
vertexPositionArray: null,
getFragmentShader : function() {
return this.getShader(this.gl, "x-shader/x-fragment",
"#ifdef GL_ES \n"+
"precision highp float; \n"+
"#endif \n"+
"varying vec4 color; \n"+
"void main(void) { \n"+
" gl_FragColor = color;\n"+
"}\n"
);
},
getVertexShader : function() {
return this.getShader(this.gl, "x-shader/x-vertex",
"attribute vec3 aVertexPosition; \n"+
"attribute vec4 aColor; \n"+
"uniform mat4 uPMatrix; \n"+
"varying vec4 color; \n"+
"void main(void) { \n"+
"gl_Position = uPMatrix * vec4(aVertexPosition, 1.0); \n"+
"color= aColor; \n"+
"}\n"
);
},
initialize : function() {
this.shaderProgram.vertexPositionAttribute =
this.gl.getAttribLocation(this.shaderProgram, "aVertexPosition");
this.gl.enableVertexAttribArray(
this.shaderProgram.vertexPositionAttribute);
this.shaderProgram.vertexColorAttribute =
this.gl.getAttribLocation(this.shaderProgram, "aColor");
this.gl.enableVertexAttribArray(
this.shaderProgram.vertexColorAttribute);
this.shaderProgram.pMatrixUniform =
this.gl.getUniformLocation(this.shaderProgram, "uPMatrix");
this.useProgram();
this.colorBuffer= this.gl.createBuffer();
this.setColor( [1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1] );
var maxTris=512, i;
/// set vertex data
this.vertexPositionBuffer = this.gl.createBuffer();
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.vertexPositionBuffer );
this.vertexPositionArray= new Float32Array(maxTris*12);
this.gl.bufferData(this.gl.ARRAY_BUFFER, this.vertexPositionArray, this.gl.DYNAMIC_DRAW);
this.gl.vertexAttribPointer(this.shaderProgram.vertexPositionAttribute, 3, this.gl.FLOAT, false, 0, 0);
return CAAT.ColorProgram.superclass.initialize.call(this);
},
setColor : function( colorArray ) {
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.colorBuffer );
this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(colorArray), this.gl.STATIC_DRAW);
this.gl.vertexAttribPointer(
this.shaderProgram.vertexColorAttribute,
this.colorBuffer,
this.gl.FLOAT,
false,
0,
0);
}
}
});