| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 wrap.getError = function() { | 133 wrap.getError = function() { |
| 134 return context.getError(); | 134 return context.getError(); |
| 135 }; | 135 }; |
| 136 return wrap; | 136 return wrap; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 | 139 |
| 140 /** | 140 /** |
| 141 * Creates a canvas under the given parent element and an o3d.Client | 141 * Creates a canvas under the given parent element and an o3d.Client |
| 142 * under that. | 142 * under that. |
| 143 * | 143 * |
| 144 * @ param {!Element} element The element under which to insert the client. | 144 * @ param {!Element} element The element under which to insert the client. |
| 145 * @ param {string} opt_features Features to turn on. | 145 * @ param {string} opt_features Features to turn on. |
| 146 * @ param {boolean} opt_debug Whether gl debugging features should be | 146 * @ param {boolean} opt_debug Whether gl debugging features should be |
| 147 * enabled. | 147 * enabled. |
| 148 */ | 148 */ |
| 149 o3djs.webgl.createClient = function(element, opt_features, opt_debug) { | 149 o3djs.webgl.createClient = function(element, opt_features, opt_debug) { |
| 150 opt_features = opt_features || ''; | 150 opt_features = opt_features || ''; |
| 151 opt_debug = opt_debug || false; | 151 opt_debug = opt_debug || false; |
| 152 | 152 |
| 153 // If we're creating a webgl client, the assumption is we're using webgl, | 153 // If we're creating a webgl client, the assumption is we're using webgl, |
| 154 // in which case the only acceptable shader language is glsl. So, here | 154 // in which case the only acceptable shader language is glsl. So, here |
| 155 // we set the shader language to glsl. | 155 // we set the shader language to glsl. |
| 156 o3djs.effect.setLanguage('glsl'); | 156 o3djs.effect.setLanguage('glsl'); |
| 157 | 157 |
| 158 // Make the canvas automatically resize to fill the containing | 158 // Make the canvas automatically resize to fill the containing |
| 159 // element (div), and initialize its size correctly. | 159 // element (div), and initialize its size correctly. |
| 160 var canvas; | 160 var canvas; |
| 161 canvas = document.createElement('canvas'); | 161 canvas = document.createElement('canvas'); |
| 162 canvas.style.width = "100%"; | 162 canvas.style.width = "100%"; |
| 163 canvas.style.height = "100%"; | 163 canvas.style.height = "100%"; |
| 164 |
| 165 var client = new o3d.Client; |
| 166 |
| 164 var resizeHandler = function() { | 167 var resizeHandler = function() { |
| 165 var width = Math.max(1, canvas.clientWidth); | 168 var width = Math.max(1, canvas.clientWidth); |
| 166 var height = Math.max(1, canvas.clientHeight); | 169 var height = Math.max(1, canvas.clientHeight); |
| 167 canvas.width = width; | 170 canvas.width = width; |
| 168 canvas.height = height; | 171 canvas.height = height; |
| 169 canvas.sizeInitialized_ = true; | 172 canvas.sizeInitialized_ = true; |
| 173 client.gl.displayInfo = {width: canvas.width, height: canvas.height}; |
| 170 }; | 174 }; |
| 171 window.addEventListener('resize', resizeHandler, false); | 175 window.addEventListener('resize', resizeHandler, false); |
| 172 setTimeout(resizeHandler, 0); | 176 setTimeout(resizeHandler, 0); |
| 173 | 177 |
| 174 var client = new o3d.Client; | |
| 175 client.initWithCanvas(canvas); | 178 client.initWithCanvas(canvas); |
| 176 canvas.client = client; | 179 canvas.client = client; |
| 177 canvas.o3d = o3d; | 180 canvas.o3d = o3d; |
| 178 | 181 |
| 179 if (opt_debug) { | 182 if (opt_debug) { |
| 180 client.gl = o3djs.webgl.addDebuggingWrapper(client.gl); | 183 client.gl = o3djs.webgl.addDebuggingWrapper(client.gl); |
| 181 } | 184 } |
| 182 | 185 |
| 183 element.appendChild(canvas); | 186 element.appendChild(canvas); |
| 184 return canvas; | 187 return canvas; |
| 185 }; | 188 }; |
| 186 | 189 |
| 187 | 190 |
| OLD | NEW |