Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49431ec
commit 230ffc5
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
function GLInstance(canvasID){ | ||
var canvas = document.getElementById(canvasID), | ||
gl = canvas.getContext("webgl2"); | ||
|
||
if(!gl){ console.error("WebGL context is not available."); return null; } | ||
|
||
//................................................... | ||
//Setup GL, Set all the default configurations we need. | ||
gl.clearColor(1.0,1.0,1.0,1.0); //Set clear color | ||
|
||
|
||
//................................................... | ||
//Methods | ||
|
||
//Reset the canvas with our set background color. | ||
gl.fClear = function(){ this.clear(this.COLOR_BUFFER_BIT | this.DEPTH_BUFFER_BIT); return this; } | ||
|
||
//Create and fill our Array buffer. | ||
gl.fCreateArrayBuffer = function(floatAry,isStatic){ | ||
if(isStatic === undefined) isStatic = true; //So we can call this function without setting isStatic | ||
|
||
var buf = this.createBuffer(); | ||
this.bindBuffer(this.ARRAY_BUFFER,buf); | ||
this.bufferData(this.ARRAY_BUFFER, floatAry, (isStatic)? this.STATIC_DRAW : this.DYNAMIC_DRAW ); | ||
this.bindBuffer(this.ARRAY_BUFFER,null); | ||
return buf; | ||
} | ||
|
||
//................................................... | ||
//Setters - Getters | ||
|
||
//Set the size of the canvas html element and the rendering view port | ||
gl.fSetSize = function(w,h){ | ||
//set the size of the canvas, on chrome we need to set it 3 ways to make it work perfectly. | ||
this.canvas.style.width = w + "px"; | ||
this.canvas.style.height = h + "px"; | ||
this.canvas.width = w; | ||
this.canvas.height = h; | ||
|
||
//when updating the canvas size, must reset the viewport of the canvas | ||
//else the resolution webgl renders at will not change | ||
this.viewport(0,0,w,h); | ||
return this; | ||
} | ||
|
||
return gl; | ||
} |