Skip to content

Instantly share code, notes, and snippets.

@nanjizal
Created August 7, 2017 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanjizal/8fffba54fe6ab382441faa594e378e53 to your computer and use it in GitHub Desktop.
Save nanjizal/8fffba54fe6ab382441faa594e378e53 to your computer and use it in GitHub Desktop.
Reset
function reset( gl: RenderingContext ): RenderingContext {
var numAttribs = gl.getParameter( RenderingContext.MAX_VERTEX_ATTRIBS );
var tmp = gl.createBuffer();
gl.bindBuffer( RenderingContext.ARRAY_BUFFER, tmp );
for( ii in 0...numAttribs ){
gl.disableVertexAttribArray( ii );
gl.vertexAttribPointer(ii, 4, RenderingContext.FLOAT, false, 0, 0 );
gl.vertexAttrib1f( ii, 0 );
}
gl.deleteBuffer( tmp );
var numTextureUnits = gl.getParameter( RenderingContext.MAX_TEXTURE_IMAGE_UNITS );
for( ii in 0...numTextureUnits ){
gl.activeTexture( RenderingContext.TEXTURE0 + ii );
gl.bindTexture( RenderingContext.TEXTURE_CUBE_MAP, null );
gl.bindTexture( RenderingContext.TEXTURE_2D, null );
}
gl.activeTexture( RenderingContext.TEXTURE0 );
gl.useProgram( null );
gl.bindBuffer( RenderingContext.ARRAY_BUFFER, null );
gl.bindBuffer( RenderingContext.ELEMENT_ARRAY_BUFFER, null );
gl.bindFramebuffer( RenderingContext.FRAMEBUFFER, null );
gl.bindRenderbuffer( RenderingContext.RENDERBUFFER, null );
gl.disable( RenderingContext.BLEND );
gl.disable( RenderingContext.CULL_FACE );
gl.disable( RenderingContext.DEPTH_TEST );
gl.disable( RenderingContext.DITHER );
gl.disable( RenderingContext.SCISSOR_TEST );
gl.blendColor( 0, 0, 0, 0 );
gl.blendEquation( RenderingContext.FUNC_ADD );
gl.blendFunc( RenderingContext.ONE, RenderingContext.ZERO );
gl.clearColor( 0, 0, 0, 0 );
gl.clearDepth( 1 );
gl.clearStencil( -1 );
gl.colorMask( true, true, true, true );
gl.cullFace( RenderingContext.BACK );
gl.depthFunc( RenderingContext.LESS );
gl.depthMask( true );
gl.depthRange( 0, 1 );
gl.frontFace( RenderingContext.CCW );
gl.hint( RenderingContext.GENERATE_MIPMAP_HINT, RenderingContext.DONT_CARE );
gl.lineWidth( 1 );
gl.pixelStorei( RenderingContext.PACK_ALIGNMENT, 4 );
gl.pixelStorei( RenderingContext.UNPACK_ALIGNMENT, 4 );
gl.pixelStorei( RenderingContext.UNPACK_FLIP_Y_WEBGL, 0 );// false?
gl.pixelStorei( RenderingContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0 );// false?
gl.polygonOffset( 0, 0 );
gl.sampleCoverage( 1, false );
gl.scissor( 0, 0, gl.canvas.width, gl.canvas.height );
gl.stencilFunc( RenderingContext.ALWAYS, 0, 0xFFFFFFFF );
gl.stencilMask( 0xFFFFFFFF );
gl.stencilOp( RenderingContext.KEEP, RenderingContext.KEEP, RenderingContext.KEEP );
gl.viewport( 0, 0, gl.canvas.width, gl.canvas.height );
//gl.clear( RenderingContext.COLOR_BUFFER_BIT | RenderingContext.DEPTH_BUFFER_BIT | RenderingContext.STENCIL_BUFFER_BIT );
return gl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment