2 /* ***************************************************************************
\r
3 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a
\r
6 * copy of this software and associated documentation files (the "Software"),
\r
7 * to deal in the Software without restriction, including without limitation
\r
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
\r
9 * and/or sell copies of the Software, and to permit persons to whom the
\r
10 * Software is furnished to do so, subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
\r
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
\r
21 * DEALINGS IN THE SOFTWARE.
\r
22 * ***************************************************************************
\r
24 * Authors: Hyunsook Park <hyunsook.park@samsung.com>
\r
25 * Wonseop Kim <wonseop.kim@samsung.com>
\r
28 ( function ( $, undefined ) {
\r
32 _vertexShader: null,
\r
33 _fragmentShader: null,
\r
35 deleteShaders: function ( gl ) {
\r
36 gl.deleteShader( this._vertexShader );
\r
37 gl.deleteShader( this._fragmentShader );
\r
40 addShaderProgram : function ( gl, vs, fs, isFile ) {
\r
42 vertexShaderSource = {},
\r
43 fragmentShaderSource = {};
\r
46 vertexShaderSource = this.loadShaderFile( vs );
\r
47 fragmentShaderSource = this.loadShaderFile( fs );
\r
49 vertexShaderSource.source = vs;
\r
50 fragmentShaderSource.source = fs;
\r
53 this._vertexShader = this.getShader( gl, gl.VERTEX_SHADER, vertexShaderSource );
\r
54 this._fragmentShader = this.getShader( gl, gl.FRAGMENT_SHADER, fragmentShaderSource );
\r
56 shaderProgram = gl.createProgram();
\r
57 gl.attachShader( shaderProgram, this._vertexShader);
\r
58 gl.attachShader( shaderProgram, this._fragmentShader);
\r
59 gl.linkProgram( shaderProgram );
\r
61 if ( !gl.getProgramParameter( shaderProgram, gl.LINK_STATUS ) ) {
\r
62 window.alert( "Could not initialize Shaders!" );
\r
64 return shaderProgram;
\r
67 loadShaderFile : function ( path ) {
\r
72 success : function ( result ) {
\r
81 getShader: function ( gl, type, script ) {
\r
84 if ( !gl || !type || !script ) {
\r
88 shader = gl.createShader( type );
\r
90 gl.shaderSource( shader, script.source );
\r
91 gl.compileShader( shader );
\r
93 if ( !gl.getShaderParameter( shader, gl.COMPILE_STATUS ) ) {
\r
94 window.alert( gl.getShaderInfoLog( shader ) );
\r
95 gl.deleteShader( shader );
\r
103 attribBufferData: function ( gl, attribArray ) {
\r
104 var attribBuffer = gl.createBuffer();
\r
106 gl.bindBuffer( gl.ARRAY_BUFFER, attribBuffer );
\r
107 gl.bufferData( gl.ARRAY_BUFFER, attribArray, gl.STATIC_DRAW );
\r
108 gl.bindBuffer( gl.ARRAY_BUFFER, null );
\r
110 return attribBuffer;
\r