or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

attributes-uniforms.mdbuffer-management.mdcontext-creation.mdextensions.mdframebuffer-operations.mdindex.mdshader-programs.mdtexture-operations.mdwebgl-rendering.md
tile.json

attributes-uniforms.mddocs/

Vertex Attributes and Uniforms

Management of vertex attributes and uniform variables for shader programs with complete type support and array handling.

Capabilities

Vertex Attributes

/**
 * Get attribute location
 * @param program - Program object
 * @param name - Attribute name
 * @returns Attribute location or -1
 */
getAttribLocation(program: WebGLProgram, name: string): number;

/**
 * Bind attribute to location
 * @param program - Program object
 * @param index - Attribute index
 * @param name - Attribute name
 */
bindAttribLocation(program: WebGLProgram, index: number, name: string): void;

/**
 * Enable vertex attribute array
 * @param index - Attribute index
 */
enableVertexAttribArray(index: number): void;

/**
 * Disable vertex attribute array
 * @param index - Attribute index
 */
disableVertexAttribArray(index: number): void;

/**
 * Set vertex attribute pointer
 * @param index - Attribute index
 * @param size - Components per attribute (1-4)
 * @param type - Data type
 * @param normalized - Normalize values
 * @param stride - Byte stride
 * @param offset - Byte offset
 */
vertexAttribPointer(index: number, size: number, type: number,
                   normalized: boolean, stride: number, offset: number): void;

/**
 * Set vertex attribute values directly
 * @param index - Attribute index
 * @param v0 - First component
 */
vertexAttrib1f(index: number, v0: number): void;

/**
 * Set vertex attribute values directly
 * @param index - Attribute index
 * @param v0 - First component
 * @param v1 - Second component
 */
vertexAttrib2f(index: number, v0: number, v1: number): void;

/**
 * Set vertex attribute values directly
 * @param index - Attribute index
 * @param v0 - First component
 * @param v1 - Second component
 * @param v2 - Third component
 */
vertexAttrib3f(index: number, v0: number, v1: number, v2: number): void;

/**
 * Set vertex attribute values directly
 * @param index - Attribute index
 * @param v0 - First component
 * @param v1 - Second component
 * @param v2 - Third component
 * @param v3 - Fourth component
 */
vertexAttrib4f(index: number, v0: number, v1: number, v2: number, v3: number): void;

/**
 * Set vertex attribute from array
 * @param index - Attribute index
 * @param value - Float32Array with 1 component
 */
vertexAttrib1fv(index: number, value: Float32Array): void;

/**
 * Set vertex attribute from array
 * @param index - Attribute index
 * @param value - Float32Array with 2 components
 */
vertexAttrib2fv(index: number, value: Float32Array): void;

/**
 * Set vertex attribute from array
 * @param index - Attribute index
 * @param value - Float32Array with 3 components
 */
vertexAttrib3fv(index: number, value: Float32Array): void;

/**
 * Set vertex attribute from array
 * @param index - Attribute index
 * @param value - Float32Array with 4 components
 */
vertexAttrib4fv(index: number, value: Float32Array): void;

/**
 * Get vertex attribute parameter
 * @param index - Attribute index
 * @param pname - Parameter name
 * @returns Parameter value
 */
getVertexAttrib(index: number, pname: number): any;

/**
 * Get vertex attribute offset
 * @param index - Attribute index
 * @param pname - Parameter name (must be VERTEX_ATTRIB_ARRAY_POINTER)
 * @returns Byte offset
 */
getVertexAttribOffset(index: number, pname: number): number;

/**
 * Get active attribute information
 * @param program - Program object
 * @param index - Attribute index
 * @returns Active attribute info
 */
getActiveAttrib(program: WebGLProgram, index: number): WebGLActiveInfo | null;

Uniforms

/**
 * Get uniform location
 * @param program - Program object
 * @param name - Uniform name
 * @returns WebGLUniformLocation or null
 */
getUniformLocation(program: WebGLProgram, name: string): WebGLUniformLocation | null;

// Scalar uniforms
uniform1f(location: WebGLUniformLocation | null, x: number): void;
uniform1i(location: WebGLUniformLocation | null, x: number): void;

// Vector uniforms
uniform2f(location: WebGLUniformLocation | null, x: number, y: number): void;
uniform2i(location: WebGLUniformLocation | null, x: number, y: number): void;
uniform3f(location: WebGLUniformLocation | null, x: number, y: number, z: number): void;
uniform3i(location: WebGLUniformLocation | null, x: number, y: number, z: number): void;
uniform4f(location: WebGLUniformLocation | null, x: number, y: number, z: number, w: number): void;
uniform4i(location: WebGLUniformLocation | null, x: number, y: number, z: number, w: number): void;

// Array uniforms
uniform1fv(location: WebGLUniformLocation | null, value: Float32Array): void;
uniform1iv(location: WebGLUniformLocation | null, value: Int32Array): void;
uniform2fv(location: WebGLUniformLocation | null, value: Float32Array): void;
uniform2iv(location: WebGLUniformLocation | null, value: Int32Array): void;
uniform3fv(location: WebGLUniformLocation | null, value: Float32Array): void;
uniform3iv(location: WebGLUniformLocation | null, value: Int32Array): void;
uniform4fv(location: WebGLUniformLocation | null, value: Float32Array): void;
uniform4iv(location: WebGLUniformLocation | null, value: Int32Array): void;

// Matrix uniforms
uniformMatrix2fv(location: WebGLUniformLocation | null, transpose: boolean, value: Float32Array): void;
uniformMatrix3fv(location: WebGLUniformLocation | null, transpose: boolean, value: Float32Array): void;
uniformMatrix4fv(location: WebGLUniformLocation | null, transpose: boolean, value: Float32Array): void;

/**
 * Get uniform value
 * @param program - Program object
 * @param location - Uniform location
 * @returns Uniform value
 */
getUniform(program: WebGLProgram, location: WebGLUniformLocation): any;

/**
 * Get active uniform information
 * @param program - Program object
 * @param index - Uniform index
 * @returns Active uniform info
 */
getActiveUniform(program: WebGLProgram, index: number): WebGLActiveInfo | null;

Usage Examples:

// Set up vertex attributes
const positionLocation = context.getAttribLocation(program, 'position');
const uvLocation = context.getAttribLocation(program, 'uv');

// Bind vertex buffer and set up position attribute
context.bindBuffer(context.ARRAY_BUFFER, vertexBuffer);
context.enableVertexAttribArray(positionLocation);
context.vertexAttribPointer(positionLocation, 3, context.FLOAT, false, 20, 0);

// Set up UV attribute (offset by 3 floats)
context.enableVertexAttribArray(uvLocation);
context.vertexAttribPointer(uvLocation, 2, context.FLOAT, false, 20, 12);

// Set uniforms
const mvpLocation = context.getUniformLocation(program, 'mvpMatrix');
const textureLocation = context.getUniformLocation(program, 'texture');

const mvpMatrix = new Float32Array(16); // 4x4 matrix
context.uniformMatrix4fv(mvpLocation, false, mvpMatrix);
context.uniform1i(textureLocation, 0); // Texture unit 0