import framebuffer from '../framebuffer.js';
import sampler2D from '../sampler2D.js';
import {math, vector3, matrix4} from '../math.js';
import samplerCube from '../samplerCube.js';
import shader from '../shader.js';

class highpassFilter {
	
	constructor(  ) {

	}	

	setViewport( viewport ){
		
		this.viewport = viewport;
		this.gl = viewport.gl;
	}
	
	prepare() {
		
		this.gl = this.engine.gl;
		
		this.width = this.viewport.width;
		this.height = this.viewport.height;
		
		this.targetSampler = new sampler2D();
		this.targetSampler.type = this.gl.FLOAT;
		
		this.framebuffer = new framebuffer();
		this.framebuffer.width = this.width;
		this.framebuffer.height = this.height;
		
		this.framebuffer.addSampler( this.targetSampler );
		this.framebuffer.create();
		
		
		this.shader = new shader();
		this.shader.createFromFile("shaders/highpass.shader");
		
		this.shader.setUniform("viewProjection", this.viewport.quad.viewProjection );

		this.shader.setUniform("screenSize", [this.width, this.height] );

	}
	
	
	render() {

		this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.framebuffer.glFramebuffer);
		this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null);
		
		this.gl.clearColor( 0, 0, 0, 1 );
		this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
		
		this.shader.update();
		
		this.viewport.quad.draw( this.shader, null );

	}
}

export {highpassFilter as default};