本文整理匯總了TypeScript中neuroglancer/webgl/buffer.Buffer類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Buffer類的具體用法?TypeScript Buffer怎麽用?TypeScript Buffer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Buffer類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: draw
draw(mat: Mat4, blend = true) {
let shader = this.trivialColorShader;
let gl = this.gl;
shader.bind();
gl.uniformMatrix4fv(shader.uniform('uProjectionMatrix'), false, mat);
let aVertexPosition = shader.attribute('aVertexPosition');
this.vertexBuffer.bindToVertexAttrib(aVertexPosition, 4);
let aColor = shader.attribute('aColor');
this.colorBuffer.bindToVertexAttrib(aColor, 4);
if (blend) {
gl.colorMask(false, false, false, true);
gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.colorMask(true, true, true, true);
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE_MINUS_DST_ALPHA, gl.DST_ALPHA);
}
gl.lineWidth(1);
gl.drawArrays(gl.LINES, 0, 6);
if (blend) {
gl.disable(gl.BLEND);
}
gl.disableVertexAttribArray(aVertexPosition);
gl.disableVertexAttribArray(aColor);
}
示例2: constructor
constructor(public gl: GL) {
super();
this.vertexBuffer = this.registerDisposer(Buffer.fromData(
gl, new Float32Array([
0, 0, 0, 1, //
1, 0, 0, 1, //
0, 0, 0, 1, //
0, 1, 0, 1, //
0, 0, 0, 1, //
0, 0, 1, 1, //
]),
gl.ARRAY_BUFFER, gl.STATIC_DRAW));
let alpha = 0.5;
this.colorBuffer = this.registerDisposer(Buffer.fromData(
gl, new Float32Array([
1, 0, 0, alpha, //
1, 0, 0, alpha, //
0, 1, 0, alpha, //
0, 1, 0, alpha, //
0, 0, 1, alpha, //
0, 0, 1, alpha, //
]),
gl.ARRAY_BUFFER, gl.STATIC_DRAW));
this.trivialColorShader = this.registerDisposer(trivialColorShader(gl));
}
示例3: draw
draw(shader: ShaderProgram, numInstances: number) {
const aSphereVertex = shader.attribute('aSphereVertex');
this.vertexBuffer.bindToVertexAttrib(
aSphereVertex, /*components=*/3, /*attributeType=*/WebGL2RenderingContext.FLOAT,
/*normalized=*/false);
this.indexBuffer.bind();
shader.gl.drawElementsInstanced(
WebGL2RenderingContext.TRIANGLES, this.numIndices, WebGL2RenderingContext.UNSIGNED_SHORT,
/*offset=*/0, numInstances);
shader.gl.disableVertexAttribArray(aSphereVertex);
}
示例4: RefCountedValue
() => new RefCountedValue(Buffer.fromData(
gl, new Float32Array([
startX, startY, //
startX, endY, //
endX, endY, //
endX, startY, //
]),
GL_ARRAY_BUFFER, GL_STATIC_DRAW)))
示例5: draw
draw(gl: GL, numInstances: number) {
if (this.quadsPerInstance === 1) {
gl.drawArraysInstanced(WebGL2RenderingContext.TRIANGLE_FAN, 0, 4, numInstances);
} else {
this.quadIndexBuffer.bind();
gl.drawElementsInstanced(
WebGL2RenderingContext.TRIANGLES, INDICES_PER_QUAD * this.quadsPerInstance,
WebGL2RenderingContext.UNSIGNED_SHORT, /*offset=*/0, numInstances);
}
}
示例6: resize
resize(length: number) {
let bufferData: ArrayBufferView;
if (length < 256) {
let data = bufferData = new Uint8Array(length);
for (let i = 0; i < length; ++i) {
data[i] = i;
}
this.webglType = WebGL2RenderingContext.UNSIGNED_BYTE;
} else if (length < 65536) {
const data = bufferData = new Uint16Array(length);
for (let i = 0; i < length; ++i) {
data[i] = i;
}
this.webglType = WebGL2RenderingContext.UNSIGNED_SHORT;
} else {
const data = bufferData = new Uint32Array(length);
for (let i = 0; i < length; ++i) {
data[i] = i;
}
this.webglType = WebGL2RenderingContext.UNSIGNED_INT;
}
this.buffer.setData(bufferData);
this.length = length;
}
示例7: makeIndexBuffer
export function makeIndexBuffer(gl: WebGL2RenderingContext, data: Uint32Array) {
return Buffer.fromData(
gl, data, WebGL2RenderingContext.ARRAY_BUFFER, WebGL2RenderingContext.STATIC_DRAW);
}
示例8: bind
bind(buffer: Buffer, shader: ShaderProgram) {
const attrib = shader.attribute(this.name);
buffer.bindToVertexAttribI(attrib, /*components=*/ 1, WebGL2RenderingContext.UNSIGNED_INT);
}
示例9: bindToVertexAttrib
bindToVertexAttrib(location: number) {
this.buffer.bindToVertexAttribI(location, 1, this.webglType);
}