1 回答

TA貢獻1844條經驗 獲得超8個贊
這
function VertexAttribPointerFloat(shaderProgram, shaderVariableName, elementLenght, stepSize, offset, gl) {
var attribLocation = gl.getAttribLocation(shaderProgram, shaderVariableName);
gl.vertexAttribPointer(attribLocation, elementLenght, gl.FLOAT, gl.FALSE, stepSize * Float32Array.BYTES_PER_ELEMENT, offset);
gl.enableVertexAttribArray(attribLocation);
console.log(attribLocation);
this.bind = function() {
gl.enableVertexAttribArray(attribLocation);
}
this.unbind = function() {
gl.disableVertexAttribArray(attribLocation);
}
}
需要這個
function VertexAttribPointerFloat(shaderProgram, shaderVariableName, elementLenght, stepSize, offset, gl) {
var attribLocation = gl.getAttribLocation(shaderProgram, shaderVariableName);
this.bind = function() {
gl.enableVertexAttribArray(attribLocation);
gl.vertexAttribPointer(attribLocation, elementLenght, gl.FLOAT, gl.FALSE, stepSize * Float32Array.BYTES_PER_ELEMENT, offset);
}
this.unbind = function() {
gl.disableVertexAttribArray(attribLocation);
}
}
您的程序使用情況需要移動以進行渲染
function TriangleElementCluster(vertices, uvs, normals, indices, indicesLenght, shader, gl) {
this.render = function() {
shader.use();
...
}
}
您實際上不需要任何解綁的BTW
您可以將綁定視為類似于僅設置全局變量。
const state = {
temp1: 0,
temp2: 0,
temp3: 0,
result: 0,
};
function add() { state.result = state.temp1 + state.temp2; }
function sub() { state.result = state.temp1 - state.temp2; }
function sum() { state.result = state.temp1 + state.temp2 + state.temp3; }
function bind(id, value) { state[id] = value; }
function get(id) { return state[id]; }
bind('temp1', 1);
bind('temp2', 2);
bind('temp3', 3);
sum();
console.log('sum:', get('result'));
bind('temp1', 4);
bind('temp2', 5);
add();
console.log('add:', get('result'));
請注意,我不會解除任何綁定。我只是綁定下一個函數運行所需的內容。
添加回答
舉報