Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLRenderPipeline handle stride and offset in buffer map #1786

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/core/src/adapter/types/shader-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export type AttributeLayout = {
format: VertexFormat;
/** @note defaults to vertex */
stepMode?: 'vertex' | 'instance';
/** bytes between successive elements @note `stride` is auto calculated if omitted */
byteStride?: number;
/** offset into buffer. Defaults to `0` */
byteOffset?: number;
};

// BUFFER MAP
Expand Down
4 changes: 2 additions & 2 deletions modules/webgl/src/adapter/helpers/get-shader-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ function overrideShaderLayoutAttribute(
attributeOverride: {name: string; format?: VertexFormat}
): void {
const attribute = getAttributeFromLayout(layout, attributeOverride.name);
if (attribute && attributeOverride.format) {
attribute.format = attributeOverride.format;
if (attribute) {
Object.assign(attribute, attributeOverride);
}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/webgl/src/adapter/resources/webgl-render-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ export class WEBGLRenderPipeline extends RenderPipeline {
this.vertexArrayObject.setBuffer(attribute.location, webglBuffer, {
size,
type,
stride,
offset: 0,
stride: attribute.byteStride || stride,
offset: attribute.byteOffset || 0,
normalized,
integer,
divisor
Expand Down
6 changes: 2 additions & 4 deletions modules/webgl/src/classic/buffer-with-accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ export class BufferWithAccessor extends WEBGLBuffer {

// Create the buffer - binding it here for the first time locks the type
// In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type
// @ts-expect-error
const glTarget = this.gl.webgl2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
const glTarget = this.gl2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
this.gl.bindBuffer(glTarget, this.handle);
// WebGL2: subData supports additional srcOffset and length parameters
if (srcOffset !== 0 || byteLength !== undefined) {
Expand Down Expand Up @@ -431,8 +430,7 @@ export class BufferWithAccessor extends WEBGLBuffer {
// Binding a buffer for the first time locks the type
// In WebGL2, use GL.COPY_WRITE_BUFFER to avoid locking the type
_getTarget() {
// @ts-expect-error
return this.gl.webgl2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
return this.gl2 ? GL.COPY_WRITE_BUFFER : this.glTarget;
}

_getAvailableElementCount(srcByteOffset: number) {
Expand Down
Loading