export class Mesh {

	constructor( ) {

		this.shaders		= [];

		this.instanceCount	= 1;

	}


	addShader( shader, options = { } ) {

		this.shaders.push( {
			shader,
			options
		} );

		return this;

	}


	setInstanceCount( count ) {

		this.instanceCount	= count;

		return this;

	}


	draw( passEncoder ) {

		for ( const entry of this.shaders ) {

			const shader	= entry.shader;

			const opts		= entry.options || { };

			const instances	= opts.instances != null ? opts.instances : this.instanceCount;

			// When no explicit vertex count is provided, rely on the shader's indexCount
			const vertexCount = opts.vertexCount != null ? opts.vertexCount : ( shader.indexCount || 0 );

			if ( vertexCount <= 0 ) {

				continue;

			}

			shader.encodeRender( passEncoder, vertexCount, instances );

		}

	}

}

