本文整理汇总了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);
}