| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 if (o3d_features) { | 73 if (o3d_features) { |
| 74 features = o3d_features; | 74 features = o3d_features; |
| 75 } else { | 75 } else { |
| 76 features = ''; | 76 features = ''; |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 var objElem = o3djs.webgl.createClient(element, features, opt_debug); | 79 var objElem = o3djs.webgl.createClient(element, features, opt_debug); |
| 80 clientElements.push(objElem); | 80 clientElements.push(objElem); |
| 81 } | 81 } |
| 82 | 82 |
| 83 callback(clientElements); | 83 // Wait for the client elements to be fully initialized. This |
| 84 // involves waiting for the page to fully layout and the initial |
| 85 // resize event to be processed. |
| 86 var clearId = window.setInterval(function() { |
| 87 for (var cc = 0; cc < clientElements.length; ++cc) { |
| 88 var element = clientElements[cc]; |
| 89 if (!element.sizeInitialized_) { |
| 90 return; |
| 91 } |
| 92 } |
| 93 window.clearInterval(clearId); |
| 94 callback(clientElements); |
| 95 }); |
| 84 }; | 96 }; |
| 85 | 97 |
| 86 | 98 |
| 87 /** | 99 /** |
| 88 * Adds a wrapper object to single gl function context that checks for errors | 100 * Adds a wrapper object to single gl function context that checks for errors |
| 89 * before the call. | 101 * before the call. |
| 90 * @param {WebGLContext} context | 102 * @param {WebGLContext} context |
| 91 * @param {string} fname The name of the function. | 103 * @param {string} fname The name of the function. |
| 92 * @return {} | 104 * @return {} |
| 93 */ | 105 */ |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // element (div), and initialize its size correctly. | 159 // element (div), and initialize its size correctly. |
| 148 var canvas; | 160 var canvas; |
| 149 canvas = document.createElement('canvas'); | 161 canvas = document.createElement('canvas'); |
| 150 canvas.style.width = "100%"; | 162 canvas.style.width = "100%"; |
| 151 canvas.style.height = "100%"; | 163 canvas.style.height = "100%"; |
| 152 var resizeHandler = function() { | 164 var resizeHandler = function() { |
| 153 var width = Math.max(1, canvas.clientWidth); | 165 var width = Math.max(1, canvas.clientWidth); |
| 154 var height = Math.max(1, canvas.clientHeight); | 166 var height = Math.max(1, canvas.clientHeight); |
| 155 canvas.width = width; | 167 canvas.width = width; |
| 156 canvas.height = height; | 168 canvas.height = height; |
| 169 canvas.sizeInitialized_ = true; |
| 157 }; | 170 }; |
| 158 window.addEventListener('resize', resizeHandler, false); | 171 window.addEventListener('resize', resizeHandler, false); |
| 159 setTimeout(resizeHandler, 0); | 172 setTimeout(resizeHandler, 0); |
| 160 | 173 |
| 161 var client = new o3d.Client; | 174 var client = new o3d.Client; |
| 162 client.initWithCanvas(canvas); | 175 client.initWithCanvas(canvas); |
| 163 canvas.client = client; | 176 canvas.client = client; |
| 164 canvas.o3d = o3d; | 177 canvas.o3d = o3d; |
| 165 | 178 |
| 166 if (opt_debug) { | 179 if (opt_debug) { |
| 167 client.gl = o3djs.webgl.addDebuggingWrapper(client.gl); | 180 client.gl = o3djs.webgl.addDebuggingWrapper(client.gl); |
| 168 } | 181 } |
| 169 | 182 |
| 170 element.appendChild(canvas); | 183 element.appendChild(canvas); |
| 171 return canvas; | 184 return canvas; |
| 172 }; | 185 }; |
| 173 | 186 |
| 174 | 187 |
| OLD | NEW |