cesium 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (491) hide show
  1. data/LICENSE.md +259 -0
  2. data/README.rdoc +90 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/javascripts/Assets/Assets.profile.js +8 -0
  5. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_0.json +1 -0
  6. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_1.json +1 -0
  7. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_10.json +1 -0
  8. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_11.json +1 -0
  9. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_12.json +1 -0
  10. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_13.json +1 -0
  11. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_14.json +1 -0
  12. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_15.json +1 -0
  13. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_16.json +1 -0
  14. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_17.json +1 -0
  15. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_18.json +1 -0
  16. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_19.json +1 -0
  17. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_2.json +1 -0
  18. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_20.json +1 -0
  19. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_21.json +1 -0
  20. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_22.json +1 -0
  21. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_23.json +1 -0
  22. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_24.json +1 -0
  23. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_25.json +1 -0
  24. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_26.json +1 -0
  25. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_27.json +1 -0
  26. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_3.json +1 -0
  27. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_4.json +1 -0
  28. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_5.json +1 -0
  29. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_6.json +1 -0
  30. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_7.json +1 -0
  31. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_8.json +1 -0
  32. data/app/assets/javascripts/Assets/IAU2006_XYS/IAU2006_XYS_9.json +1 -0
  33. data/app/assets/javascripts/Assets/Textures/NE2_LR_LC_SR_W_DR_2048.jpg +0 -0
  34. data/app/assets/javascripts/Assets/Textures/SkyBox/tycho2t3_80_mx.jpg +0 -0
  35. data/app/assets/javascripts/Assets/Textures/SkyBox/tycho2t3_80_my.jpg +0 -0
  36. data/app/assets/javascripts/Assets/Textures/SkyBox/tycho2t3_80_mz.jpg +0 -0
  37. data/app/assets/javascripts/Assets/Textures/SkyBox/tycho2t3_80_px.jpg +0 -0
  38. data/app/assets/javascripts/Assets/Textures/SkyBox/tycho2t3_80_py.jpg +0 -0
  39. data/app/assets/javascripts/Assets/Textures/SkyBox/tycho2t3_80_pz.jpg +0 -0
  40. data/app/assets/javascripts/Assets/Textures/waterNormals.jpg +0 -0
  41. data/app/assets/javascripts/Assets/package.json +6 -0
  42. data/app/assets/javascripts/Cesium.js +320 -0
  43. data/app/assets/javascripts/Core/AnimationController.js +148 -0
  44. data/app/assets/javascripts/Core/AxisAlignedBoundingBox.js +243 -0
  45. data/app/assets/javascripts/Core/BoundingRectangle.js +364 -0
  46. data/app/assets/javascripts/Core/BoundingSphere.js +819 -0
  47. data/app/assets/javascripts/Core/BoxTessellator.js +93 -0
  48. data/app/assets/javascripts/Core/Cartesian2.js +762 -0
  49. data/app/assets/javascripts/Core/Cartesian3.js +861 -0
  50. data/app/assets/javascripts/Core/Cartesian4.js +762 -0
  51. data/app/assets/javascripts/Core/Cartographic.js +211 -0
  52. data/app/assets/javascripts/Core/CatmullRomSpline.js +232 -0
  53. data/app/assets/javascripts/Core/Clock.js +195 -0
  54. data/app/assets/javascripts/Core/ClockRange.js +37 -0
  55. data/app/assets/javascripts/Core/ClockStep.js +32 -0
  56. data/app/assets/javascripts/Core/Color.js +1629 -0
  57. data/app/assets/javascripts/Core/ComponentDatatype.js +119 -0
  58. data/app/assets/javascripts/Core/Core.profile.js +8 -0
  59. data/app/assets/javascripts/Core/CubeMapEllipsoidTessellator.js +198 -0
  60. data/app/assets/javascripts/Core/CubicRealPolynomial.js +251 -0
  61. data/app/assets/javascripts/Core/DefaultProxy.js +30 -0
  62. data/app/assets/javascripts/Core/DeveloperError.js +60 -0
  63. data/app/assets/javascripts/Core/EarthOrientationParameters.js +383 -0
  64. data/app/assets/javascripts/Core/EarthOrientationParametersSample.js +50 -0
  65. data/app/assets/javascripts/Core/Ellipsoid.js +539 -0
  66. data/app/assets/javascripts/Core/EllipsoidTangentPlane.js +207 -0
  67. data/app/assets/javascripts/Core/EllipsoidalOccluder.js +151 -0
  68. data/app/assets/javascripts/Core/EncodedCartesian3.js +197 -0
  69. data/app/assets/javascripts/Core/Enumeration.js +67 -0
  70. data/app/assets/javascripts/Core/Event.js +122 -0
  71. data/app/assets/javascripts/Core/Extent.js +383 -0
  72. data/app/assets/javascripts/Core/ExtentTessellator.js +384 -0
  73. data/app/assets/javascripts/Core/FAR.js +13 -0
  74. data/app/assets/javascripts/Core/FeatureDetection.js +126 -0
  75. data/app/assets/javascripts/Core/Fullscreen.js +235 -0
  76. data/app/assets/javascripts/Core/GeographicProjection.js +107 -0
  77. data/app/assets/javascripts/Core/HermitePolynomialApproximation.js +176 -0
  78. data/app/assets/javascripts/Core/HermiteSpline.js +234 -0
  79. data/app/assets/javascripts/Core/Iau2006XysData.js +259 -0
  80. data/app/assets/javascripts/Core/Iau2006XysSample.js +36 -0
  81. data/app/assets/javascripts/Core/IndexDatatype.js +28 -0
  82. data/app/assets/javascripts/Core/Intersect.js +40 -0
  83. data/app/assets/javascripts/Core/IntersectionTests.js +359 -0
  84. data/app/assets/javascripts/Core/Interval.js +27 -0
  85. data/app/assets/javascripts/Core/Iso8601.js +46 -0
  86. data/app/assets/javascripts/Core/JulianDate.js +1228 -0
  87. data/app/assets/javascripts/Core/KeyboardEventModifier.js +38 -0
  88. data/app/assets/javascripts/Core/LagrangePolynomialApproximation.js +96 -0
  89. data/app/assets/javascripts/Core/LeapSecond.js +158 -0
  90. data/app/assets/javascripts/Core/LinearApproximation.js +98 -0
  91. data/app/assets/javascripts/Core/Math.js +532 -0
  92. data/app/assets/javascripts/Core/Matrix2.js +833 -0
  93. data/app/assets/javascripts/Core/Matrix3.js +1099 -0
  94. data/app/assets/javascripts/Core/Matrix4.js +2164 -0
  95. data/app/assets/javascripts/Core/MeshFilters.js +568 -0
  96. data/app/assets/javascripts/Core/Occluder.js +474 -0
  97. data/app/assets/javascripts/Core/OrientationInterpolator.js +109 -0
  98. data/app/assets/javascripts/Core/PlaneTessellator.js +74 -0
  99. data/app/assets/javascripts/Core/PolygonPipeline.js +792 -0
  100. data/app/assets/javascripts/Core/PolylinePipeline.js +90 -0
  101. data/app/assets/javascripts/Core/PrimitiveType.js +80 -0
  102. data/app/assets/javascripts/Core/QuadraticRealPolynomial.js +146 -0
  103. data/app/assets/javascripts/Core/QuarticRealPolynomial.js +339 -0
  104. data/app/assets/javascripts/Core/Quaternion.js +947 -0
  105. data/app/assets/javascripts/Core/Queue.js +95 -0
  106. data/app/assets/javascripts/Core/Ray.js +64 -0
  107. data/app/assets/javascripts/Core/ReferenceFrame.js +25 -0
  108. data/app/assets/javascripts/Core/RequestErrorEvent.js +35 -0
  109. data/app/assets/javascripts/Core/RuntimeError.js +59 -0
  110. data/app/assets/javascripts/Core/ScreenSpaceEventHandler.js +658 -0
  111. data/app/assets/javascripts/Core/ScreenSpaceEventType.js +149 -0
  112. data/app/assets/javascripts/Core/Shapes.js +230 -0
  113. data/app/assets/javascripts/Core/Spherical.js +192 -0
  114. data/app/assets/javascripts/Core/TaskProcessor.js +131 -0
  115. data/app/assets/javascripts/Core/TimeConstants.js +85 -0
  116. data/app/assets/javascripts/Core/TimeInterval.js +305 -0
  117. data/app/assets/javascripts/Core/TimeIntervalCollection.js +543 -0
  118. data/app/assets/javascripts/Core/TimeStandard.js +31 -0
  119. data/app/assets/javascripts/Core/Tipsify.js +285 -0
  120. data/app/assets/javascripts/Core/Transforms.js +614 -0
  121. data/app/assets/javascripts/Core/TridiagonalSystemSolver.js +102 -0
  122. data/app/assets/javascripts/Core/Visibility.js +38 -0
  123. data/app/assets/javascripts/Core/WebMercatorProjection.js +154 -0
  124. data/app/assets/javascripts/Core/WindingOrder.js +40 -0
  125. data/app/assets/javascripts/Core/binarySearch.js +69 -0
  126. data/app/assets/javascripts/Core/buildModuleUrl.js +77 -0
  127. data/app/assets/javascripts/Core/clone.js +21 -0
  128. data/app/assets/javascripts/Core/combine.js +81 -0
  129. data/app/assets/javascripts/Core/computeSunPosition.js +116 -0
  130. data/app/assets/javascripts/Core/createGuid.js +25 -0
  131. data/app/assets/javascripts/Core/defaultValue.js +22 -0
  132. data/app/assets/javascripts/Core/destroyObject.js +61 -0
  133. data/app/assets/javascripts/Core/freezeObject.js +20 -0
  134. data/app/assets/javascripts/Core/getImagePixels.js +46 -0
  135. data/app/assets/javascripts/Core/isLeapYear.js +30 -0
  136. data/app/assets/javascripts/Core/jsonp.js +116 -0
  137. data/app/assets/javascripts/Core/loadArrayBuffer.js +76 -0
  138. data/app/assets/javascripts/Core/loadImage.js +85 -0
  139. data/app/assets/javascripts/Core/loadJson.js +54 -0
  140. data/app/assets/javascripts/Core/loadText.js +78 -0
  141. data/app/assets/javascripts/Core/loadXML.js +76 -0
  142. data/app/assets/javascripts/Core/package.json +6 -0
  143. data/app/assets/javascripts/Core/pointInsideTriangle2D.js +41 -0
  144. data/app/assets/javascripts/Core/requestAnimationFrame.js +61 -0
  145. data/app/assets/javascripts/Core/throttleRequestByServer.js +74 -0
  146. data/app/assets/javascripts/Core/writeTextToCanvas.js +92 -0
  147. data/app/assets/javascripts/DynamicScene/CompositeDynamicObjectCollection.js +254 -0
  148. data/app/assets/javascripts/DynamicScene/CzmlBoolean.js +57 -0
  149. data/app/assets/javascripts/DynamicScene/CzmlCartesian2.js +96 -0
  150. data/app/assets/javascripts/DynamicScene/CzmlCartesian3.js +99 -0
  151. data/app/assets/javascripts/DynamicScene/CzmlCartographic.js +125 -0
  152. data/app/assets/javascripts/DynamicScene/CzmlColor.js +127 -0
  153. data/app/assets/javascripts/DynamicScene/CzmlDefaults.js +135 -0
  154. data/app/assets/javascripts/DynamicScene/CzmlHorizontalOrigin.js +59 -0
  155. data/app/assets/javascripts/DynamicScene/CzmlImage.js +61 -0
  156. data/app/assets/javascripts/DynamicScene/CzmlLabelStyle.js +59 -0
  157. data/app/assets/javascripts/DynamicScene/CzmlNumber.js +82 -0
  158. data/app/assets/javascripts/DynamicScene/CzmlString.js +56 -0
  159. data/app/assets/javascripts/DynamicScene/CzmlUnitCartesian3.js +99 -0
  160. data/app/assets/javascripts/DynamicScene/CzmlUnitQuaternion.js +172 -0
  161. data/app/assets/javascripts/DynamicScene/CzmlUnitSpherical.js +98 -0
  162. data/app/assets/javascripts/DynamicScene/CzmlVerticalOrigin.js +59 -0
  163. data/app/assets/javascripts/DynamicScene/DynamicBillboard.js +245 -0
  164. data/app/assets/javascripts/DynamicScene/DynamicBillboardVisualizer.js +347 -0
  165. data/app/assets/javascripts/DynamicScene/DynamicColorMaterial.js +78 -0
  166. data/app/assets/javascripts/DynamicScene/DynamicCone.js +291 -0
  167. data/app/assets/javascripts/DynamicScene/DynamicConeVisualizer.js +350 -0
  168. data/app/assets/javascripts/DynamicScene/DynamicConeVisualizerUsingCustomSensor.js +389 -0
  169. data/app/assets/javascripts/DynamicScene/DynamicDirectionsProperty.js +163 -0
  170. data/app/assets/javascripts/DynamicScene/DynamicEllipsoid.js +158 -0
  171. data/app/assets/javascripts/DynamicScene/DynamicEllipsoidVisualizer.js +277 -0
  172. data/app/assets/javascripts/DynamicScene/DynamicImageMaterial.js +136 -0
  173. data/app/assets/javascripts/DynamicScene/DynamicLabel.js +286 -0
  174. data/app/assets/javascripts/DynamicScene/DynamicLabelVisualizer.js +341 -0
  175. data/app/assets/javascripts/DynamicScene/DynamicMaterialProperty.js +125 -0
  176. data/app/assets/javascripts/DynamicScene/DynamicObject.js +364 -0
  177. data/app/assets/javascripts/DynamicScene/DynamicObjectCollection.js +137 -0
  178. data/app/assets/javascripts/DynamicScene/DynamicObjectView.js +299 -0
  179. data/app/assets/javascripts/DynamicScene/DynamicPath.js +214 -0
  180. data/app/assets/javascripts/DynamicScene/DynamicPathVisualizer.js +402 -0
  181. data/app/assets/javascripts/DynamicScene/DynamicPoint.js +184 -0
  182. data/app/assets/javascripts/DynamicScene/DynamicPointVisualizer.js +323 -0
  183. data/app/assets/javascripts/DynamicScene/DynamicPolygon.js +138 -0
  184. data/app/assets/javascripts/DynamicScene/DynamicPolygonVisualizer.js +251 -0
  185. data/app/assets/javascripts/DynamicScene/DynamicPolyline.js +183 -0
  186. data/app/assets/javascripts/DynamicScene/DynamicPolylineVisualizer.js +268 -0
  187. data/app/assets/javascripts/DynamicScene/DynamicPositionProperty.js +525 -0
  188. data/app/assets/javascripts/DynamicScene/DynamicProperty.js +352 -0
  189. data/app/assets/javascripts/DynamicScene/DynamicPyramid.js +204 -0
  190. data/app/assets/javascripts/DynamicScene/DynamicPyramidVisualizer.js +302 -0
  191. data/app/assets/javascripts/DynamicScene/DynamicScene.profile.js +8 -0
  192. data/app/assets/javascripts/DynamicScene/DynamicVertexPositionsProperty.js +199 -0
  193. data/app/assets/javascripts/DynamicScene/ReferenceProperty.js +155 -0
  194. data/app/assets/javascripts/DynamicScene/VisualizerCollection.js +181 -0
  195. data/app/assets/javascripts/DynamicScene/package.json +6 -0
  196. data/app/assets/javascripts/DynamicScene/processCzml.js +77 -0
  197. data/app/assets/javascripts/Renderer/BlendEquation.js +52 -0
  198. data/app/assets/javascripts/Renderer/BlendFunction.js +158 -0
  199. data/app/assets/javascripts/Renderer/BlendingState.js +64 -0
  200. data/app/assets/javascripts/Renderer/Buffer.js +141 -0
  201. data/app/assets/javascripts/Renderer/BufferUsage.js +48 -0
  202. data/app/assets/javascripts/Renderer/ClearCommand.js +40 -0
  203. data/app/assets/javascripts/Renderer/CommandLists.js +42 -0
  204. data/app/assets/javascripts/Renderer/Context.js +2805 -0
  205. data/app/assets/javascripts/Renderer/CubeMap.js +358 -0
  206. data/app/assets/javascripts/Renderer/CubeMapFace.js +202 -0
  207. data/app/assets/javascripts/Renderer/CullFace.js +50 -0
  208. data/app/assets/javascripts/Renderer/DepthFunction.js +95 -0
  209. data/app/assets/javascripts/Renderer/DrawCommand.js +96 -0
  210. data/app/assets/javascripts/Renderer/Framebuffer.js +435 -0
  211. data/app/assets/javascripts/Renderer/MipmapHint.js +50 -0
  212. data/app/assets/javascripts/Renderer/PickFramebuffer.js +178 -0
  213. data/app/assets/javascripts/Renderer/PixelDatatype.js +86 -0
  214. data/app/assets/javascripts/Renderer/PixelFormat.js +113 -0
  215. data/app/assets/javascripts/Renderer/Renderbuffer.js +102 -0
  216. data/app/assets/javascripts/Renderer/RenderbufferFormat.js +77 -0
  217. data/app/assets/javascripts/Renderer/Renderer.profile.js +8 -0
  218. data/app/assets/javascripts/Renderer/ShaderCache.js +121 -0
  219. data/app/assets/javascripts/Renderer/ShaderProgram.js +2402 -0
  220. data/app/assets/javascripts/Renderer/StencilFunction.js +95 -0
  221. data/app/assets/javascripts/Renderer/StencilOperation.js +95 -0
  222. data/app/assets/javascripts/Renderer/Texture.js +395 -0
  223. data/app/assets/javascripts/Renderer/TextureAtlas.js +472 -0
  224. data/app/assets/javascripts/Renderer/TextureAtlasBuilder.js +133 -0
  225. data/app/assets/javascripts/Renderer/TextureMagnificationFilter.js +41 -0
  226. data/app/assets/javascripts/Renderer/TextureMinificationFilter.js +77 -0
  227. data/app/assets/javascripts/Renderer/TextureWrap.js +50 -0
  228. data/app/assets/javascripts/Renderer/UniformDatatype.js +218 -0
  229. data/app/assets/javascripts/Renderer/UniformState.js +799 -0
  230. data/app/assets/javascripts/Renderer/VertexArray.js +365 -0
  231. data/app/assets/javascripts/Renderer/VertexArrayFacade.js +574 -0
  232. data/app/assets/javascripts/Renderer/VertexLayout.js +49 -0
  233. data/app/assets/javascripts/Renderer/loadCubeMap.js +92 -0
  234. data/app/assets/javascripts/Renderer/package.json +6 -0
  235. data/app/assets/javascripts/Scene/AnimationCollection.js +249 -0
  236. data/app/assets/javascripts/Scene/ArcGisMapServerImageryProvider.js +384 -0
  237. data/app/assets/javascripts/Scene/Billboard.js +680 -0
  238. data/app/assets/javascripts/Scene/BillboardCollection.js +1209 -0
  239. data/app/assets/javascripts/Scene/BingMapsImageryProvider.js +460 -0
  240. data/app/assets/javascripts/Scene/BingMapsStyle.js +55 -0
  241. data/app/assets/javascripts/Scene/Camera.js +358 -0
  242. data/app/assets/javascripts/Scene/CameraColumbusViewMode.js +30 -0
  243. data/app/assets/javascripts/Scene/CameraController.js +1258 -0
  244. data/app/assets/javascripts/Scene/CameraEventAggregator.js +270 -0
  245. data/app/assets/javascripts/Scene/CameraEventType.js +53 -0
  246. data/app/assets/javascripts/Scene/CameraFlightPath.js +495 -0
  247. data/app/assets/javascripts/Scene/CentralBody.js +817 -0
  248. data/app/assets/javascripts/Scene/CentralBodySurface.js +1120 -0
  249. data/app/assets/javascripts/Scene/CentralBodySurfaceShaderSet.js +107 -0
  250. data/app/assets/javascripts/Scene/ComplexConicSensorVolume.js +511 -0
  251. data/app/assets/javascripts/Scene/CompositePrimitive.js +454 -0
  252. data/app/assets/javascripts/Scene/CullingVolume.js +59 -0
  253. data/app/assets/javascripts/Scene/CustomSensorVolume.js +440 -0
  254. data/app/assets/javascripts/Scene/DiscardMissingTileImagePolicy.js +134 -0
  255. data/app/assets/javascripts/Scene/EllipsoidPrimitive.js +412 -0
  256. data/app/assets/javascripts/Scene/EllipsoidTerrainProvider.js +182 -0
  257. data/app/assets/javascripts/Scene/FrameState.js +86 -0
  258. data/app/assets/javascripts/Scene/FrustumCommands.js +32 -0
  259. data/app/assets/javascripts/Scene/GeographicTilingScheme.js +265 -0
  260. data/app/assets/javascripts/Scene/HorizontalOrigin.js +39 -0
  261. data/app/assets/javascripts/Scene/Imagery.js +85 -0
  262. data/app/assets/javascripts/Scene/ImageryLayer.js +876 -0
  263. data/app/assets/javascripts/Scene/ImageryLayerCollection.js +403 -0
  264. data/app/assets/javascripts/Scene/ImageryProvider.js +185 -0
  265. data/app/assets/javascripts/Scene/ImageryProviderError.js +149 -0
  266. data/app/assets/javascripts/Scene/ImageryState.js +20 -0
  267. data/app/assets/javascripts/Scene/Label.js +706 -0
  268. data/app/assets/javascripts/Scene/LabelCollection.js +697 -0
  269. data/app/assets/javascripts/Scene/LabelStyle.js +39 -0
  270. data/app/assets/javascripts/Scene/Material.js +1177 -0
  271. data/app/assets/javascripts/Scene/NeverTileDiscardPolicy.js +38 -0
  272. data/app/assets/javascripts/Scene/OpenStreetMapImageryProvider.js +282 -0
  273. data/app/assets/javascripts/Scene/OrthographicFrustum.js +345 -0
  274. data/app/assets/javascripts/Scene/PerformanceDisplay.js +183 -0
  275. data/app/assets/javascripts/Scene/PerspectiveFrustum.js +239 -0
  276. data/app/assets/javascripts/Scene/PerspectiveOffCenterFrustum.js +394 -0
  277. data/app/assets/javascripts/Scene/Polygon.js +886 -0
  278. data/app/assets/javascripts/Scene/Polyline.js +441 -0
  279. data/app/assets/javascripts/Scene/PolylineCollection.js +1532 -0
  280. data/app/assets/javascripts/Scene/Projections.js +93 -0
  281. data/app/assets/javascripts/Scene/RectangularPyramidSensorVolume.js +224 -0
  282. data/app/assets/javascripts/Scene/Scene.js +632 -0
  283. data/app/assets/javascripts/Scene/Scene.profile.js +8 -0
  284. data/app/assets/javascripts/Scene/SceneMode.js +51 -0
  285. data/app/assets/javascripts/Scene/SceneTransitioner.js +776 -0
  286. data/app/assets/javascripts/Scene/ScreenSpaceCameraController.js +1063 -0
  287. data/app/assets/javascripts/Scene/SensorVolumeCollection.js +192 -0
  288. data/app/assets/javascripts/Scene/SingleTileImageryProvider.js +295 -0
  289. data/app/assets/javascripts/Scene/SkyAtmosphere.js +239 -0
  290. data/app/assets/javascripts/Scene/SkyBox.js +231 -0
  291. data/app/assets/javascripts/Scene/TerrainProvider.js +229 -0
  292. data/app/assets/javascripts/Scene/TexturePool.js +154 -0
  293. data/app/assets/javascripts/Scene/Tile.js +322 -0
  294. data/app/assets/javascripts/Scene/TileDiscardPolicy.js +42 -0
  295. data/app/assets/javascripts/Scene/TileImagery.js +36 -0
  296. data/app/assets/javascripts/Scene/TileLoadQueue.js +123 -0
  297. data/app/assets/javascripts/Scene/TileMapServiceImageryProvider.js +337 -0
  298. data/app/assets/javascripts/Scene/TileReplacementQueue.js +139 -0
  299. data/app/assets/javascripts/Scene/TileState.js +19 -0
  300. data/app/assets/javascripts/Scene/TilingScheme.js +213 -0
  301. data/app/assets/javascripts/Scene/VerticalOrigin.js +39 -0
  302. data/app/assets/javascripts/Scene/ViewportQuad.js +256 -0
  303. data/app/assets/javascripts/Scene/WebMapServiceImageryProvider.js +374 -0
  304. data/app/assets/javascripts/Scene/WebMercatorTilingScheme.js +291 -0
  305. data/app/assets/javascripts/Scene/package.json +6 -0
  306. data/app/assets/javascripts/Shaders/BillboardCollectionFS.glsl +30 -0
  307. data/app/assets/javascripts/Shaders/BillboardCollectionFS.js +31 -0
  308. data/app/assets/javascripts/Shaders/BillboardCollectionVS.glsl +68 -0
  309. data/app/assets/javascripts/Shaders/BillboardCollectionVS.js +54 -0
  310. data/app/assets/javascripts/Shaders/BuiltinFunctions.glsl +927 -0
  311. data/app/assets/javascripts/Shaders/BuiltinFunctions.js +322 -0
  312. data/app/assets/javascripts/Shaders/CentralBodyFS.glsl +106 -0
  313. data/app/assets/javascripts/Shaders/CentralBodyFS.js +82 -0
  314. data/app/assets/javascripts/Shaders/CentralBodyFSDepth.glsl +20 -0
  315. data/app/assets/javascripts/Shaders/CentralBodyFSDepth.js +22 -0
  316. data/app/assets/javascripts/Shaders/CentralBodyFSPole.glsl +29 -0
  317. data/app/assets/javascripts/Shaders/CentralBodyFSPole.js +28 -0
  318. data/app/assets/javascripts/Shaders/CentralBodyVS.glsl +88 -0
  319. data/app/assets/javascripts/Shaders/CentralBodyVS.js +69 -0
  320. data/app/assets/javascripts/Shaders/CentralBodyVSDepth.glsl +9 -0
  321. data/app/assets/javascripts/Shaders/CentralBodyVSDepth.js +13 -0
  322. data/app/assets/javascripts/Shaders/CentralBodyVSPole.glsl +12 -0
  323. data/app/assets/javascripts/Shaders/CentralBodyVSPole.js +15 -0
  324. data/app/assets/javascripts/Shaders/ComplexConicSensorVolumeFS.glsl +448 -0
  325. data/app/assets/javascripts/Shaders/ComplexConicSensorVolumeFS.js +361 -0
  326. data/app/assets/javascripts/Shaders/ComplexConicSensorVolumeVS.glsl +19 -0
  327. data/app/assets/javascripts/Shaders/ComplexConicSensorVolumeVS.js +20 -0
  328. data/app/assets/javascripts/Shaders/ConstructiveSolidGeometry.glsl +886 -0
  329. data/app/assets/javascripts/Shaders/ConstructiveSolidGeometry.js +586 -0
  330. data/app/assets/javascripts/Shaders/CustomSensorVolumeFS.glsl +126 -0
  331. data/app/assets/javascripts/Shaders/CustomSensorVolumeFS.js +95 -0
  332. data/app/assets/javascripts/Shaders/CustomSensorVolumeVS.glsl +14 -0
  333. data/app/assets/javascripts/Shaders/CustomSensorVolumeVS.js +18 -0
  334. data/app/assets/javascripts/Shaders/EllipsoidFS.glsl +40 -0
  335. data/app/assets/javascripts/Shaders/EllipsoidFS.js +38 -0
  336. data/app/assets/javascripts/Shaders/EllipsoidVS.glsl +26 -0
  337. data/app/assets/javascripts/Shaders/EllipsoidVS.js +16 -0
  338. data/app/assets/javascripts/Shaders/Materials/AsphaltMaterial.glsl +25 -0
  339. data/app/assets/javascripts/Shaders/Materials/AsphaltMaterial.js +23 -0
  340. data/app/assets/javascripts/Shaders/Materials/BlobMaterial.glsl +18 -0
  341. data/app/assets/javascripts/Shaders/Materials/BlobMaterial.js +19 -0
  342. data/app/assets/javascripts/Shaders/Materials/BrickMaterial.glsl +42 -0
  343. data/app/assets/javascripts/Shaders/Materials/BrickMaterial.js +36 -0
  344. data/app/assets/javascripts/Shaders/Materials/BumpMapMaterial.glsl +29 -0
  345. data/app/assets/javascripts/Shaders/Materials/BumpMapMaterial.js +27 -0
  346. data/app/assets/javascripts/Shaders/Materials/CementMaterial.glsl +19 -0
  347. data/app/assets/javascripts/Shaders/Materials/CementMaterial.js +20 -0
  348. data/app/assets/javascripts/Shaders/Materials/CheckerboardMaterial.glsl +38 -0
  349. data/app/assets/javascripts/Shaders/Materials/CheckerboardMaterial.js +32 -0
  350. data/app/assets/javascripts/Shaders/Materials/DotMaterial.glsl +17 -0
  351. data/app/assets/javascripts/Shaders/Materials/DotMaterial.js +18 -0
  352. data/app/assets/javascripts/Shaders/Materials/ErosionMaterial.glsl +23 -0
  353. data/app/assets/javascripts/Shaders/Materials/ErosionMaterial.js +24 -0
  354. data/app/assets/javascripts/Shaders/Materials/FacetMaterial.glsl +18 -0
  355. data/app/assets/javascripts/Shaders/Materials/FacetMaterial.js +19 -0
  356. data/app/assets/javascripts/Shaders/Materials/FresnelMaterial.glsl +12 -0
  357. data/app/assets/javascripts/Shaders/Materials/FresnelMaterial.js +15 -0
  358. data/app/assets/javascripts/Shaders/Materials/GrassMaterial.glsl +28 -0
  359. data/app/assets/javascripts/Shaders/Materials/GrassMaterial.js +26 -0
  360. data/app/assets/javascripts/Shaders/Materials/NormalMapMaterial.glsl +19 -0
  361. data/app/assets/javascripts/Shaders/Materials/NormalMapMaterial.js +21 -0
  362. data/app/assets/javascripts/Shaders/Materials/ReflectionMaterial.glsl +13 -0
  363. data/app/assets/javascripts/Shaders/Materials/ReflectionMaterial.js +16 -0
  364. data/app/assets/javascripts/Shaders/Materials/RefractionMaterial.glsl +14 -0
  365. data/app/assets/javascripts/Shaders/Materials/RefractionMaterial.js +17 -0
  366. data/app/assets/javascripts/Shaders/Materials/RimLightingMaterial.glsl +18 -0
  367. data/app/assets/javascripts/Shaders/Materials/RimLightingMaterial.js +19 -0
  368. data/app/assets/javascripts/Shaders/Materials/StripeMaterial.glsl +29 -0
  369. data/app/assets/javascripts/Shaders/Materials/StripeMaterial.js +26 -0
  370. data/app/assets/javascripts/Shaders/Materials/TieDyeMaterial.glsl +17 -0
  371. data/app/assets/javascripts/Shaders/Materials/TieDyeMaterial.js +19 -0
  372. data/app/assets/javascripts/Shaders/Materials/Water.glsl +91 -0
  373. data/app/assets/javascripts/Shaders/Materials/Water.js +60 -0
  374. data/app/assets/javascripts/Shaders/Materials/WoodMaterial.glsl +36 -0
  375. data/app/assets/javascripts/Shaders/Materials/WoodMaterial.js +31 -0
  376. data/app/assets/javascripts/Shaders/Noise.glsl +453 -0
  377. data/app/assets/javascripts/Shaders/Noise.js +242 -0
  378. data/app/assets/javascripts/Shaders/PolygonFS.glsl +27 -0
  379. data/app/assets/javascripts/Shaders/PolygonFS.js +23 -0
  380. data/app/assets/javascripts/Shaders/PolygonFSPick.glsl +6 -0
  381. data/app/assets/javascripts/Shaders/PolygonFSPick.js +11 -0
  382. data/app/assets/javascripts/Shaders/PolygonVS.glsl +38 -0
  383. data/app/assets/javascripts/Shaders/PolygonVS.js +39 -0
  384. data/app/assets/javascripts/Shaders/PolygonVSPick.glsl +30 -0
  385. data/app/assets/javascripts/Shaders/PolygonVSPick.js +32 -0
  386. data/app/assets/javascripts/Shaders/PolylineFS.glsl +6 -0
  387. data/app/assets/javascripts/Shaders/PolylineFS.js +11 -0
  388. data/app/assets/javascripts/Shaders/PolylineVS.glsl +34 -0
  389. data/app/assets/javascripts/Shaders/PolylineVS.js +35 -0
  390. data/app/assets/javascripts/Shaders/Ray.glsl +532 -0
  391. data/app/assets/javascripts/Shaders/Ray.js +357 -0
  392. data/app/assets/javascripts/Shaders/ReprojectWebMercatorFS.glsl +26 -0
  393. data/app/assets/javascripts/Shaders/ReprojectWebMercatorFS.js +22 -0
  394. data/app/assets/javascripts/Shaders/ReprojectWebMercatorVS.glsl +11 -0
  395. data/app/assets/javascripts/Shaders/ReprojectWebMercatorVS.js +14 -0
  396. data/app/assets/javascripts/Shaders/SensorVolume.glsl +43 -0
  397. data/app/assets/javascripts/Shaders/SensorVolume.js +31 -0
  398. data/app/assets/javascripts/Shaders/Shaders.profile.js +8 -0
  399. data/app/assets/javascripts/Shaders/SkyAtmosphereFS.glsl +70 -0
  400. data/app/assets/javascripts/Shaders/SkyAtmosphereFS.js +62 -0
  401. data/app/assets/javascripts/Shaders/SkyAtmosphereVS.glsl +131 -0
  402. data/app/assets/javascripts/Shaders/SkyAtmosphereVS.js +115 -0
  403. data/app/assets/javascripts/Shaders/SkyBoxFS.glsl +10 -0
  404. data/app/assets/javascripts/Shaders/SkyBoxFS.js +14 -0
  405. data/app/assets/javascripts/Shaders/SkyBoxVS.glsl +10 -0
  406. data/app/assets/javascripts/Shaders/SkyBoxVS.js +14 -0
  407. data/app/assets/javascripts/Shaders/ViewportQuadFS.glsl +16 -0
  408. data/app/assets/javascripts/Shaders/ViewportQuadFS.js +17 -0
  409. data/app/assets/javascripts/Shaders/ViewportQuadVS.glsl +10 -0
  410. data/app/assets/javascripts/Shaders/ViewportQuadVS.js +14 -0
  411. data/app/assets/javascripts/Shaders/package.json +6 -0
  412. data/app/assets/javascripts/ThirdParty/ThirdParty.profile.js +8 -0
  413. data/app/assets/javascripts/ThirdParty/Tween.js +678 -0
  414. data/app/assets/javascripts/ThirdParty/Uri.js +277 -0
  415. data/app/assets/javascripts/ThirdParty/measureText.js +197 -0
  416. data/app/assets/javascripts/ThirdParty/package.json +6 -0
  417. data/app/assets/javascripts/ThirdParty/sprintf.js +319 -0
  418. data/app/assets/javascripts/ThirdParty/when.js +748 -0
  419. data/app/assets/javascripts/Widgets/Dojo/CesiumViewerWidget.css +175 -0
  420. data/app/assets/javascripts/Widgets/Dojo/CesiumViewerWidget.html +52 -0
  421. data/app/assets/javascripts/Widgets/Dojo/CesiumViewerWidget.js +1237 -0
  422. data/app/assets/javascripts/Widgets/Dojo/CesiumWidget.html +4 -0
  423. data/app/assets/javascripts/Widgets/Dojo/CesiumWidget.js +349 -0
  424. data/app/assets/javascripts/Widgets/Dojo/TimelineWidget.css +1 -0
  425. data/app/assets/javascripts/Widgets/Dojo/TimelineWidget.js +47 -0
  426. data/app/assets/javascripts/Widgets/Dojo/checkForChromeFrame.js +71 -0
  427. data/app/assets/javascripts/Widgets/Images/Bing_Logo_51x19_White.png +0 -0
  428. data/app/assets/javascripts/Widgets/Images/Cesium_Logo_overlay.png +0 -0
  429. data/app/assets/javascripts/Widgets/Images/TimelineIcons.png +0 -0
  430. data/app/assets/javascripts/Widgets/Images/ajax-loader.gif +0 -0
  431. data/app/assets/javascripts/Widgets/Images/animationBar.png +0 -0
  432. data/app/assets/javascripts/Widgets/Images/viewControlBar.png +0 -0
  433. data/app/assets/javascripts/Widgets/Timeline.css +113 -0
  434. data/app/assets/javascripts/Widgets/Timeline.js +629 -0
  435. data/app/assets/javascripts/Widgets/TimelineHighlightRange.js +51 -0
  436. data/app/assets/javascripts/Widgets/TimelineTrack.js +54 -0
  437. data/app/assets/javascripts/Widgets/Widgets.profile.js +8 -0
  438. data/app/assets/javascripts/Widgets/package.json +6 -0
  439. data/app/assets/javascripts/Workers/Workers.profile.js +8 -0
  440. data/app/assets/javascripts/Workers/cesiumWorkerBootstrapper.js +2015 -0
  441. data/app/assets/javascripts/Workers/createTaskProcessorWorker.js +55 -0
  442. data/app/assets/javascripts/Workers/createVerticesFromExtent.js +24 -0
  443. data/app/assets/javascripts/Workers/package.json +6 -0
  444. data/app/assets/javascripts/copyrightHeader.js +22 -0
  445. data/app/assets/javascripts/main.js +10 -0
  446. data/app/assets/stylesheets/cesium.css +4 -0
  447. data/app/controllers/cesium_controller.rb +4 -0
  448. data/app/helpers/cesium_helper.rb +2 -0
  449. data/app/views/cesium/index.html.erb +3 -0
  450. data/config/routes.rb +3 -0
  451. data/lib/cesium.rb +4 -0
  452. data/lib/cesium/engine.rb +4 -0
  453. data/lib/cesium/version.rb +3 -0
  454. data/lib/tasks/cesium_tasks.rake +4 -0
  455. data/test/cesium_test.rb +7 -0
  456. data/test/dummy/README.rdoc +261 -0
  457. data/test/dummy/Rakefile +7 -0
  458. data/test/dummy/app/assets/javascripts/adapters/jquery-adapter.js.coffee +4 -0
  459. data/test/dummy/app/assets/javascripts/app.js.coffee +11 -0
  460. data/test/dummy/app/assets/javascripts/application.js.coffee +73 -0
  461. data/test/dummy/app/assets/stylesheets/application.css +12 -0
  462. data/test/dummy/app/controllers/application_controller.rb +4 -0
  463. data/test/dummy/app/helpers/application_helper.rb +2 -0
  464. data/test/dummy/app/views/layouts/application.html.erb +21 -0
  465. data/test/dummy/config.ru +4 -0
  466. data/test/dummy/config/application.rb +59 -0
  467. data/test/dummy/config/boot.rb +10 -0
  468. data/test/dummy/config/database.yml +25 -0
  469. data/test/dummy/config/environment.rb +5 -0
  470. data/test/dummy/config/environments/development.rb +37 -0
  471. data/test/dummy/config/environments/production.rb +67 -0
  472. data/test/dummy/config/environments/test.rb +37 -0
  473. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  474. data/test/dummy/config/initializers/inflections.rb +15 -0
  475. data/test/dummy/config/initializers/mime_types.rb +5 -0
  476. data/test/dummy/config/initializers/secret_token.rb +7 -0
  477. data/test/dummy/config/initializers/session_store.rb +8 -0
  478. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  479. data/test/dummy/config/locales/en.yml +5 -0
  480. data/test/dummy/config/requirejs.yml +10 -0
  481. data/test/dummy/config/routes.rb +3 -0
  482. data/test/dummy/public/404.html +26 -0
  483. data/test/dummy/public/422.html +26 -0
  484. data/test/dummy/public/500.html +25 -0
  485. data/test/dummy/public/favicon.ico +0 -0
  486. data/test/dummy/script/rails +6 -0
  487. data/test/functional/cesium_controller_test.rb +9 -0
  488. data/test/integration/navigation_test.rb +10 -0
  489. data/test/test_helper.rb +15 -0
  490. data/test/unit/helpers/cesium_helper_test.rb +4 -0
  491. metadata +641 -0
@@ -0,0 +1,42 @@
1
+ /*global define*/
2
+ define(function() {
3
+ "use strict";
4
+
5
+ /**
6
+ * Represents lists of commands for drawing for each render pass.
7
+ *
8
+ * @alias CommandLists
9
+ * @constructor
10
+ */
11
+ var CommandLists = function() {
12
+ /**
13
+ * The command list for a color pass.
14
+ * @type Array
15
+ */
16
+ this.colorList = [];
17
+
18
+ /**
19
+ * The command list for a pick pass.
20
+ * @type Array
21
+ */
22
+ this.pickList = [];
23
+
24
+ /**
25
+ * The command list for an overlay pass.
26
+ * @type Array
27
+ */
28
+ this.overlayList = [];
29
+ };
30
+
31
+ CommandLists.prototype.empty = function() {
32
+ return this.colorList.length === 0 && this.pickList.length === 0 && this.overlayList.length === 0;
33
+ };
34
+
35
+ CommandLists.prototype.removeAll = function() {
36
+ this.colorList.length = 0;
37
+ this.pickList.length = 0;
38
+ this.overlayList.length = 0;
39
+ };
40
+
41
+ return CommandLists;
42
+ });
@@ -0,0 +1,2805 @@
1
+ /*global define*/
2
+ define([
3
+ '../Core/defaultValue',
4
+ '../Core/DeveloperError',
5
+ '../Core/destroyObject',
6
+ '../Core/Color',
7
+ '../Core/IndexDatatype',
8
+ '../Core/RuntimeError',
9
+ '../Core/PrimitiveType',
10
+ '../Core/WindingOrder',
11
+ '../Core/BoundingRectangle',
12
+ '../Core/createGuid',
13
+ '../Core/Matrix4',
14
+ './Buffer',
15
+ './BufferUsage',
16
+ './BlendEquation',
17
+ './BlendFunction',
18
+ './CubeMap',
19
+ './CullFace',
20
+ './DepthFunction',
21
+ './Framebuffer',
22
+ './MipmapHint',
23
+ './PixelDatatype',
24
+ './PixelFormat',
25
+ './PickFramebuffer',
26
+ './Renderbuffer',
27
+ './RenderbufferFormat',
28
+ './ShaderCache',
29
+ './ShaderProgram',
30
+ './StencilFunction',
31
+ './StencilOperation',
32
+ './Texture',
33
+ './TextureAtlas',
34
+ './TextureMagnificationFilter',
35
+ './TextureMinificationFilter',
36
+ './TextureWrap',
37
+ './UniformState',
38
+ './VertexArray',
39
+ './VertexLayout'
40
+ ], function(
41
+ defaultValue,
42
+ DeveloperError,
43
+ destroyObject,
44
+ Color,
45
+ IndexDatatype,
46
+ RuntimeError,
47
+ PrimitiveType,
48
+ WindingOrder,
49
+ BoundingRectangle,
50
+ createGuid,
51
+ Matrix4,
52
+ Buffer,
53
+ BufferUsage,
54
+ BlendEquation,
55
+ BlendFunction,
56
+ CubeMap,
57
+ CullFace,
58
+ DepthFunction,
59
+ Framebuffer,
60
+ MipmapHint,
61
+ PixelDatatype,
62
+ PixelFormat,
63
+ PickFramebuffer,
64
+ Renderbuffer,
65
+ RenderbufferFormat,
66
+ ShaderCache,
67
+ ShaderProgram,
68
+ StencilFunction,
69
+ StencilOperation,
70
+ Texture,
71
+ TextureAtlas,
72
+ TextureMagnificationFilter,
73
+ TextureMinificationFilter,
74
+ TextureWrap,
75
+ UniformState,
76
+ VertexArray,
77
+ VertexLayout) {
78
+ "use strict";
79
+ /*global Uint8Array*/
80
+
81
+ function _errorToString(gl, error) {
82
+ var message = 'OpenGL Error: ';
83
+ switch (error) {
84
+ case gl.INVALID_ENUM:
85
+ message += 'Invalid enumeration';
86
+ break;
87
+ case gl.INVALID_VALUE:
88
+ message += 'Invalid value';
89
+ break;
90
+ case gl.INVALID_OPERATION:
91
+ message += 'Invalid operation';
92
+ break;
93
+ case gl.OUT_OF_MEMORY:
94
+ message += 'Out of memory';
95
+ break;
96
+ case gl.CONTEXT_LOST_WEBGL:
97
+ message += 'Context lost';
98
+ break;
99
+ default:
100
+ message += 'Unknown';
101
+ }
102
+
103
+ return message;
104
+ }
105
+
106
+ function _createErrorMessage(gl, glFunc, glFuncArguments, error) {
107
+ var message = _errorToString(gl, error) + ': ' + glFunc.name + '(';
108
+
109
+ for ( var i = 0; i < glFuncArguments.length; ++i) {
110
+ if (i !== 0) {
111
+ message += ', ';
112
+ }
113
+ message += glFuncArguments[i];
114
+ }
115
+ message += ');';
116
+
117
+ return message;
118
+ }
119
+
120
+ function throwOnError(gl, glFunc, glFuncArguments) {
121
+ var error = gl.getError();
122
+ if (error !== gl.NO_ERROR) {
123
+ throw new RuntimeError(_createErrorMessage(gl, glFunc, glFuncArguments, error));
124
+ }
125
+ }
126
+
127
+ function wrapGL(gl, logFunc) {
128
+ if (!logFunc) {
129
+ return gl;
130
+ }
131
+
132
+ function wrapFunction(property) {
133
+ return function() {
134
+ var result = property.apply(gl, arguments);
135
+ logFunc(gl, property, arguments);
136
+ return result;
137
+ };
138
+ }
139
+
140
+ var glWrapper = {};
141
+
142
+ /*jslint forin: true*/
143
+ /*jshint forin: false*/
144
+ // JSLint normally demands that a for..in loop must directly contain an if,
145
+ // but in our loop below, we actually intend to iterate all properties, including
146
+ // those in the prototype.
147
+ for ( var propertyName in gl) {
148
+ var property = gl[propertyName];
149
+
150
+ // wrap any functions we encounter, otherwise just copy the property to the wrapper.
151
+ if (typeof property === 'function') {
152
+ glWrapper[propertyName] = wrapFunction(property);
153
+ } else {
154
+ glWrapper[propertyName] = property;
155
+ }
156
+ }
157
+
158
+ return glWrapper;
159
+ }
160
+
161
+ /**
162
+ * DOC_TBA
163
+ *
164
+ * @alias Context
165
+ * @constructor
166
+ *
167
+ * @exception {RuntimeError} The browser does not support WebGL. Visit http://get.webgl.org.
168
+ * @exception {RuntimeError} The browser supports WebGL, but initialization failed.
169
+ * @exception {DeveloperError} canvas is required.
170
+ */
171
+ var Context = function(canvas, options) {
172
+ if (!window.WebGLRenderingContext) {
173
+ throw new RuntimeError('The browser does not support WebGL. Visit http://get.webgl.org.');
174
+ }
175
+
176
+ if (!canvas) {
177
+ throw new DeveloperError('canvas is required.');
178
+ }
179
+
180
+ this._canvas = canvas;
181
+
182
+ if (typeof options === 'undefined') {
183
+ options = {};
184
+ }
185
+ if (typeof options.stencil === 'undefined') {
186
+ options.stencil = true;
187
+ }
188
+ if (typeof options.alpha === 'undefined') {
189
+ options.alpha = false;
190
+ }
191
+
192
+ this._originalGLContext = canvas.getContext('webgl', options) || canvas.getContext('experimental-webgl', options);
193
+
194
+ if (!this._originalGLContext) {
195
+ throw new RuntimeError('The browser supports WebGL, but initialization failed.');
196
+ }
197
+
198
+ this._id = createGuid();
199
+
200
+ // Validation and logging disabled by default for speed.
201
+ this._validateFB = false;
202
+ this._validateSP = false;
203
+ this._logShaderCompilation = false;
204
+ this._throwOnWebGLError = false;
205
+
206
+ // TODO: Also need point_size and point_size_enable for ColladaFX
207
+ // TODO: Also need sample_alpha_to_coverage_enable for ColladaFX
208
+ this._shaderCache = new ShaderCache(this);
209
+
210
+ var gl = this._gl = this._originalGLContext;
211
+
212
+ this._version = gl.getParameter(gl.VERSION);
213
+ this._shadingLanguageVersion = gl.getParameter(gl.SHADING_LANGUAGE_VERSION);
214
+ this._vendor = gl.getParameter(gl.VENDOR);
215
+ this._renderer = gl.getParameter(gl.RENDERER);
216
+ this._redBits = gl.getParameter(gl.RED_BITS);
217
+ this._greenBits = gl.getParameter(gl.GREEN_BITS);
218
+ this._blueBits = gl.getParameter(gl.BLUE_BITS);
219
+ this._alphaBits = gl.getParameter(gl.ALPHA_BITS);
220
+ this._depthBits = gl.getParameter(gl.DEPTH_BITS);
221
+ this._stencilBits = gl.getParameter(gl.STENCIL_BITS);
222
+ this._maximumCombinedTextureImageUnits = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS); // min: 8
223
+ this._maximumCubeMapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); // min: 16
224
+ this._maximumFragmentUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS); // min: 16
225
+ this._maximumTextureImageUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); // min: 8
226
+ this._maximumRenderbufferSize = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE); // min: 1
227
+ this._maximumTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); // min: 64
228
+ this._maximumVaryingVectors = gl.getParameter(gl.MAX_VARYING_VECTORS); // min: 8
229
+ this._maximumVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); // min: 8
230
+ this._maximumVertexTextureImageUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS); // min: 0
231
+ this._maximumVertexUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS); // min: 128
232
+ this._aliasedLineWidthRange = gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE); // must include 1
233
+ this._aliasedPointSizeRange = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE); // must include 1
234
+ this._maximumViewportDimensions = gl.getParameter(gl.MAX_VIEWPORT_DIMS);
235
+
236
+ // Query and initialize extensions
237
+ this._standardDerivatives = gl.getExtension('OES_standard_derivatives');
238
+ this._depthTexture = gl.getExtension('WEBKIT_WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture');
239
+ var textureFilterAnisotropic = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic');
240
+ this._textureFilterAnisotropic = textureFilterAnisotropic;
241
+ this._maximumTextureFilterAnisotropy = textureFilterAnisotropic ? gl.getParameter(textureFilterAnisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1.0;
242
+
243
+ var cc = gl.getParameter(gl.COLOR_CLEAR_VALUE);
244
+ this._clearColor = new Color(cc[0], cc[1], cc[2], cc[3]);
245
+ this._clearDepth = gl.getParameter(gl.DEPTH_CLEAR_VALUE);
246
+ this._clearStencil = gl.getParameter(gl.STENCIL_CLEAR_VALUE);
247
+ this._defaultClearColor = new Color(cc[0], cc[1], cc[2], cc[3]);
248
+ this._defaultClearDepth = this._clearDepth;
249
+ this._defaultClearStencil = this._clearStencil;
250
+
251
+ this._us = new UniformState();
252
+ this._currentFramebuffer = undefined;
253
+ this._currentSp = undefined;
254
+
255
+ this._defaultTexture = undefined;
256
+ this._defaultCubeMap = undefined;
257
+ };
258
+
259
+ Context.prototype._enableOrDisable = function(glEnum, enable) {
260
+ if (enable) {
261
+ this._gl.enable(glEnum);
262
+ } else {
263
+ this._gl.disable(glEnum);
264
+ }
265
+ };
266
+
267
+ Context.prototype._applyFrontFace = function(frontFace) {
268
+ this._gl.frontFace(frontFace);
269
+ };
270
+
271
+ Context.prototype._applyCull = function(cull) {
272
+ var gl = this._gl;
273
+ var enabled = cull.enabled;
274
+
275
+ this._enableOrDisable(gl.CULL_FACE, enabled);
276
+
277
+ if (enabled) {
278
+ gl.cullFace(cull.face);
279
+ }
280
+ };
281
+
282
+ Context.prototype._applyLineWidth = function(lineWidth) {
283
+ this._gl.lineWidth(lineWidth);
284
+ };
285
+
286
+ Context.prototype._applyPolygonOffset = function(polygonOffset) {
287
+ var gl = this._gl;
288
+ var enabled = polygonOffset.enabled;
289
+
290
+ this._enableOrDisable(gl.POLYGON_OFFSET_FILL, enabled);
291
+
292
+ if (enabled) {
293
+ gl.polygonOffset(polygonOffset.factor, polygonOffset.units);
294
+ }
295
+ };
296
+
297
+ Context.prototype._applyScissorTest = function(scissorTest) {
298
+ var gl = this._gl;
299
+ var enabled = scissorTest.enabled;
300
+
301
+ this._enableOrDisable(gl.SCISSOR_TEST, enabled);
302
+
303
+ if (enabled) {
304
+ var newRectangle = scissorTest.rectangle;
305
+ gl.scissor(newRectangle.x, newRectangle.y, newRectangle.width, newRectangle.height);
306
+ }
307
+ };
308
+
309
+ Context.prototype._applyDepthRange = function(depthRange) {
310
+ var near = depthRange.near;
311
+ var far = depthRange.far;
312
+ this._gl.depthRange(near, far);
313
+ };
314
+
315
+ Context.prototype._applyDepthTest = function(depthTest) {
316
+ var gl = this._gl;
317
+ var enabled = depthTest.enabled;
318
+
319
+ this._enableOrDisable(gl.DEPTH_TEST, enabled);
320
+
321
+ if (enabled) {
322
+ gl.depthFunc(depthTest.func);
323
+ }
324
+ };
325
+
326
+ Context.prototype._applyColorMask = function(colorMask) {
327
+ this._gl.colorMask(colorMask.red, colorMask.green, colorMask.blue, colorMask.alpha);
328
+ };
329
+
330
+ Context.prototype._applyDepthMask = function(depthMask) {
331
+ this._gl.depthMask(depthMask);
332
+ };
333
+
334
+ Context.prototype._applyStencilMask = function(stencilMask) {
335
+ this._gl.stencilMask(stencilMask);
336
+ };
337
+
338
+ Context.prototype._applyBlending = function(blending) {
339
+ var gl = this._gl;
340
+ var enabled = blending.enabled;
341
+
342
+ this._enableOrDisable(gl.BLEND, enabled);
343
+
344
+ if (enabled) {
345
+ var color = blending.color;
346
+ var equationRgb = blending.equationRgb;
347
+ var equationAlpha = blending.equationAlpha;
348
+ var functionSourceRgb = blending.functionSourceRgb;
349
+ var functionDestinationRgb = blending.functionDestinationRgb;
350
+ var functionSourceAlpha = blending.functionSourceAlpha;
351
+ var functionDestinationAlpha = blending.functionDestinationAlpha;
352
+
353
+ gl.blendColor(color.red, color.green, color.blue, color.alpha);
354
+ gl.blendEquationSeparate(equationRgb, equationAlpha);
355
+ gl.blendFuncSeparate(functionSourceRgb, functionDestinationRgb, functionSourceAlpha, functionDestinationAlpha);
356
+ }
357
+ };
358
+
359
+ Context.prototype._applyStencilTest = function(stencilTest) {
360
+ var gl = this._gl;
361
+ var enabled = stencilTest.enabled;
362
+
363
+ this._enableOrDisable(gl.STENCIL_TEST, enabled);
364
+
365
+ if (enabled) {
366
+ var frontFunction = stencilTest.frontFunction;
367
+ var backFunction = stencilTest.backFunction;
368
+ var reference = stencilTest.reference;
369
+ var mask = stencilTest.mask;
370
+
371
+ // Section 6.8 of the WebGL spec requires the reference and masks to be the same for
372
+ // front- and back-face tests. This call prevents invalid operation errors when calling
373
+ // stencilFuncSeparate on Firefox. Perhaps they should delay validation to avoid requiring this.
374
+ gl.stencilFunc(stencilTest.frontFunction, stencilTest.reference, stencilTest.mask);
375
+ gl.stencilFuncSeparate(gl.BACK, backFunction, reference, mask);
376
+ gl.stencilFuncSeparate(gl.FRONT, frontFunction, reference, mask);
377
+
378
+ var frontOperation = stencilTest.frontOperation;
379
+ var frontOperationFail = frontOperation.fail;
380
+ var frontOperationZFail = frontOperation.zFail;
381
+ var frontOperationZPass = frontOperation.zPass;
382
+
383
+ gl.stencilOpSeparate(gl.FRONT, frontOperationFail, frontOperationZFail, frontOperationZPass);
384
+
385
+ var backOperation = stencilTest.backOperation;
386
+ var backOperationFail = backOperation.fail;
387
+ var backOperationZFail = backOperation.zFail;
388
+ var backOperationZPass = backOperation.zPass;
389
+
390
+ gl.stencilOpSeparate(gl.BACK, backOperationFail, backOperationZFail, backOperationZPass);
391
+ }
392
+ };
393
+
394
+ Context.prototype._applySampleCoverage = function(sampleCoverage) {
395
+ var gl = this._gl;
396
+ var enabled = sampleCoverage.enabled;
397
+
398
+ this._enableOrDisable(gl.SAMPLE_COVERAGE, enabled);
399
+
400
+ if (enabled) {
401
+ gl.sampleCoverage(sampleCoverage.value, sampleCoverage.invert);
402
+ }
403
+ };
404
+
405
+ Context.prototype._applyDither = function(dither) {
406
+ this._enableOrDisable(this._gl.DITHER, dither);
407
+ };
408
+
409
+ var scratchViewport = new BoundingRectangle();
410
+ Context.prototype._applyViewport = function(viewport) {
411
+ if (typeof viewport === 'undefined') {
412
+ viewport = scratchViewport;
413
+ viewport.width = this._canvas.clientWidth;
414
+ viewport.height = this._canvas.clientHeight;
415
+ }
416
+
417
+ this._us.setViewport(viewport);
418
+ this._gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
419
+ };
420
+
421
+ Context.prototype._applyRenderState = function(state) {
422
+ this._applyFrontFace(state.frontFace);
423
+ this._applyCull(state.cull);
424
+ this._applyLineWidth(state.lineWidth);
425
+ this._applyPolygonOffset(state.polygonOffset);
426
+ this._applyScissorTest(state.scissorTest);
427
+ this._applyDepthRange(state.depthRange);
428
+ this._applyDepthTest(state.depthTest);
429
+ this._applyColorMask(state.colorMask);
430
+ this._applyDepthMask(state.depthMask);
431
+ this._applyStencilMask(state.stencilMask);
432
+ this._applyBlending(state.blending);
433
+ this._applyStencilTest(state.stencilTest);
434
+ this._applySampleCoverage(state.sampleCoverage);
435
+ this._applyDither(state.dither);
436
+ this._applyViewport(state.viewport);
437
+ };
438
+
439
+ /**
440
+ * Returns a unique ID for this context.
441
+ *
442
+ * @memberof Context
443
+ *
444
+ * @returns {String} A unique ID for this context.
445
+ */
446
+ Context.prototype.getId = function() {
447
+ return this._id;
448
+ };
449
+
450
+ /**
451
+ * Returns the canvas assoicated with this context.
452
+ *
453
+ * @memberof Context
454
+ *
455
+ * @returns {HTMLCanvasElement} The canvas assoicated with this context.
456
+ */
457
+ Context.prototype.getCanvas = function() {
458
+ return this._canvas;
459
+ };
460
+
461
+ /**
462
+ * DOC_TBA
463
+ *
464
+ * @memberof Context
465
+ *
466
+ * @see Context#createShaderProgram
467
+ */
468
+ Context.prototype.getShaderCache = function() {
469
+ return this._shaderCache;
470
+ };
471
+
472
+ /**
473
+ * DOC_TBA
474
+ * @memberof Context
475
+ */
476
+ Context.prototype.getUniformState = function() {
477
+ return this._us;
478
+ };
479
+
480
+ /**
481
+ * Returns the WebGL version or release number of the form &lt;WebGL&gt;&lt;space&gt;&lt;version number&gt;&lt;space&gt;&lt;vendor-specific information&gt;.
482
+ *
483
+ * @memberof Context
484
+ *
485
+ * @returns {String} The WebGL version or release number.
486
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetString.xml'>glGetString</a> with <code>VERSION</code>.
487
+ */
488
+ Context.prototype.getVersion = function() {
489
+ return this._version;
490
+ };
491
+
492
+ /**
493
+ * Returns the version or release number for the shading language of the form WebGL&lt;space&gt;GLSL&lt;space&gt;ES&lt;space&gt;&lt;version number&gt;&lt;space&gt;&lt;vendor-specific information&gt;.
494
+ *
495
+ * @memberof Context
496
+ *
497
+ * @returns {String} The version or release number for the shading language.
498
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetString.xml'>glGetString</a> with <code>SHADING_LANGUAGE_VERSION</code>.
499
+ */
500
+ Context.prototype.getShadingLanguageVersion = function() {
501
+ return this._shadingLanguageVersion;
502
+ };
503
+
504
+ /**
505
+ * Returns the company responsible for the WebGL implementation.
506
+ *
507
+ * @memberof Context
508
+ *
509
+ * @returns {String} The company responsible for the WebGL implementation.
510
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetString.xml'>glGetString</a> with <code>VENDOR</code>.
511
+ */
512
+ Context.prototype.getVendor = function() {
513
+ return this._vendor;
514
+ };
515
+
516
+ /**
517
+ * Returns the name of the renderer/configuration/hardware platform. For example, this may be the model of the
518
+ * video card, e.g., 'GeForce 8800 GTS/PCI/SSE2', or the browser-dependent name of the GL implementation, e.g.
519
+ * 'Mozilla' or 'ANGLE.'
520
+ *
521
+ * @memberof Context
522
+ *
523
+ * @returns {String} The name of the renderer.
524
+ *
525
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetString.xml'>glGetString</a> with <code>RENDERER</code>.
526
+ * @see <a href='http://code.google.com/p/angleproject/'>ANGLE</a>
527
+ */
528
+ Context.prototype.getRenderer = function() {
529
+ return this._renderer;
530
+ };
531
+
532
+ /**
533
+ * Returns the number of red bits per component in the default framebuffer's color buffer. The minimum is eight.
534
+ *
535
+ * @memberof Context
536
+ *
537
+ * @returns {Number} The number of red bits per component in the color buffer.
538
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>RED_BITS</code>.
539
+ */
540
+ Context.prototype.getRedBits = function() {
541
+ return this._redBits;
542
+ };
543
+
544
+ /**
545
+ * Returns the number of green bits per component in the default framebuffer's color buffer. The minimum is eight.
546
+ *
547
+ * @memberof Context
548
+ *
549
+ * @returns {Number} The number of green bits per component in the color buffer.
550
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>GREEN_BITS</code>.
551
+ */
552
+ Context.prototype.getGreenBits = function() {
553
+ return this._greenBits;
554
+ };
555
+
556
+ /**
557
+ * Returns the number of blue bits per component in the default framebuffer's color buffer. The minimum is eight.
558
+ *
559
+ * @memberof Context
560
+ *
561
+ * @returns {Number} The number of blue bits per component in the color buffer.
562
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>BLUE_BITS</code>.
563
+ */
564
+ Context.prototype.getBlueBits = function() {
565
+ return this._blueBits;
566
+ };
567
+
568
+ /**
569
+ * Returns the number of alpha bits per component in the default framebuffer's color buffer. The minimum is eight.
570
+ * <br /><br />
571
+ * The alpha channel is used for GL destination alpha operations and by the HTML compositor to combine the color buffer
572
+ * with the rest of the page.
573
+ *
574
+ * @memberof Context
575
+ *
576
+ * @returns {Number} The number of alpha bits per component in the color buffer.
577
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>ALPHA_BITS</code>.
578
+ */
579
+ Context.prototype.getAlphaBits = function() {
580
+ return this._alphaBits;
581
+ };
582
+
583
+ /**
584
+ * Returns the number of depth bits per pixel in the default bound framebuffer. The minimum is 16 bits; most
585
+ * implementations will have 24 bits.
586
+ *
587
+ * @memberof Context
588
+ *
589
+ * @returns {Number} The number of depth bits per pixel in the default bound framebuffer.
590
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>DEPTH_BITS</code>.
591
+ */
592
+ Context.prototype.getDepthBits = function() {
593
+ return this._depthBits;
594
+ };
595
+
596
+ /**
597
+ * Returns the number of stencil bits per pixel in the default bound framebuffer. The minimum is eight bits.
598
+ *
599
+ * @memberof Context
600
+ *
601
+ * @returns {Number} The number of stencil bits per pixel in the default bound framebuffer.
602
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>STENCIL_BITS</code>.
603
+ */
604
+ Context.prototype.getStencilBits = function() {
605
+ return this._stencilBits;
606
+ };
607
+
608
+ /**
609
+ * Returns the maximum number of texture units that can be used from the vertex and fragment
610
+ * shader with this WebGL implementation. The minimum is eight. If both shaders access the
611
+ * same texture unit, this counts as two texture units.
612
+ *
613
+ * @memberof Context
614
+ *
615
+ * @returns {Number} The maximum supported texture image units.
616
+ *
617
+ * @see Context#getMaximumTextureImageUnits
618
+ * @see Context#getMaximumVertexTextureImageUnits
619
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_COMBINED_TEXTURE_IMAGE_UNITS</code>.
620
+ */
621
+ Context.prototype.getMaximumCombinedTextureImageUnits = function() {
622
+ return this._maximumCombinedTextureImageUnits;
623
+ };
624
+
625
+ /**
626
+ * Returns the approximate maximum cube mape width and height supported by this WebGL implementation.
627
+ * The minimum is 16, but most desktop and laptop implementations will support much larger sizes like 8,192.
628
+ *
629
+ * @memberof Context
630
+ *
631
+ * @returns {Number} The approximate maximum cube mape width and height.
632
+ *
633
+ * @see Context#createCubeMap
634
+ * @see Context#getMaximumTextureSize
635
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_CUBE_MAP_TEXTURE_SIZE</code>.
636
+ */
637
+ Context.prototype.getMaximumCubeMapSize = function() {
638
+ return this._maximumCubeMapSize;
639
+ };
640
+
641
+ /**
642
+ * Returns the maximum number of <code>vec4</code>, <code>ivec4</code>, and <code>bvec4</code>
643
+ * uniforms that can be used by a fragment shader with this WebGL implementation. The minimum is 16.
644
+ *
645
+ * @memberof Context
646
+ *
647
+ * @returns {Number} The maximum number of <code>vec4</code>, <code>ivec4</code>, and <code>bvec4</code> uniforms that can be used by a fragment shader.
648
+ *
649
+ * @see Context#getMaximumVertexUniformVectors
650
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_FRAGMENT_UNIFORM_VECTORS</code>.
651
+ */
652
+ Context.prototype.getMaximumFragmentUniformVectors = function() {
653
+ return this._maximumFragmentUniformVectors;
654
+ };
655
+
656
+ /**
657
+ * Returns the maximum number of texture units that can be used from the fragment shader with this WebGL implementation. The minimum is eight.
658
+ *
659
+ * @memberof Context
660
+ *
661
+ * @returns {Number} The maximum number of texture units that can be used from the fragment shader.
662
+ *
663
+ * @see Context#getMaximumCombinedTextureImageUnits
664
+ * @see Context#getMaximumVertexTextureImageUnits
665
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_TEXTURE_IMAGE_UNITS</code>.
666
+ */
667
+ Context.prototype.getMaximumTextureImageUnits = function() {
668
+ return this._maximumTextureImageUnits;
669
+ };
670
+
671
+ /**
672
+ * Returns the maximum renderbuffer width and height supported by this WebGL implementation.
673
+ * The minimum is 16, but most desktop and laptop implementations will support much larger sizes like 8,192.
674
+ *
675
+ * @memberof Context
676
+ *
677
+ * @returns {Number} The maximum renderbuffer width and height.
678
+ *
679
+ * @see Context#createRenderbuffer
680
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_RENDERBUFFER_SIZE</code>.
681
+ */
682
+ Context.prototype.getMaximumRenderbufferSize = function() {
683
+ return this._maximumRenderbufferSize;
684
+ };
685
+
686
+ /**
687
+ * Returns the approximate maximum texture width and height supported by this WebGL implementation.
688
+ * The minimum is 64, but most desktop and laptop implementations will support much larger sizes like 8,192.
689
+ *
690
+ * @memberof Context
691
+ *
692
+ * @returns {Number} The approximate maximum texture width and height.
693
+ *
694
+ * @see Context#createTexture2D
695
+ * @see Context#getMaximumCubeMapSize
696
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_TEXTURE_SIZE</code>.
697
+ */
698
+ Context.prototype.getMaximumTextureSize = function() {
699
+ return this._maximumTextureSize;
700
+ };
701
+
702
+ /**
703
+ * Returns the maximum number of <code>vec4</code> varying variables supported by this WebGL implementation.
704
+ * The minimum is eight. Matrices and arrays count as multiple <code>vec4</code>s.
705
+ *
706
+ * @memberof Context
707
+ *
708
+ * @returns {Number} Returns the maximum number of <code>vec4</code> varying variables.
709
+ *
710
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VARYING_VECTORS</code>.
711
+ */
712
+ Context.prototype.getMaximumVaryingVectors = function() {
713
+ return this._maximumVaryingVectors;
714
+ };
715
+
716
+ /**
717
+ * Returns the maximum number of <code>vec4</code> vertex attributes supported by this WebGL implementation. The minimum is eight.
718
+ *
719
+ * @memberof Context
720
+ *
721
+ * @returns {Number} The maximum number of <code>vec4</code> vertex attributes.
722
+ *
723
+ * @see Context#createVertexArray
724
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VERTEX_ATTRIBS</code>.
725
+ */
726
+ Context.prototype.getMaximumVertexAttributes = function() {
727
+ return this._maximumVertexAttributes;
728
+ };
729
+
730
+ /**
731
+ * Returns the maximum number of texture units that can be used from the vertex shader with this WebGL implementation.
732
+ * The minimum is zero, which means the GL does not support vertex texture fetch.
733
+ *
734
+ * @memberof Context
735
+ *
736
+ * @returns {Number} The maximum number of texture units that can be used from the vertex shader.
737
+ *
738
+ * @see Context#getMaximumCombinedTextureImageUnits
739
+ * @see Context#getMaximumTextureImageUnits
740
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VERTEX_TEXTURE_IMAGE_UNITS</code>.
741
+ */
742
+ Context.prototype.getMaximumVertexTextureImageUnits = function() {
743
+ return this._maximumVertexTextureImageUnits;
744
+ };
745
+
746
+ /**
747
+ * Returns the maximum number of <code>vec4</code>, <code>ivec4</code>, and <code>bvec4</code>
748
+ * uniforms that can be used by a vertex shader with this WebGL implementation. The minimum is 16.
749
+ *
750
+ * @memberof Context
751
+ *
752
+ * @returns {Number} The maximum number of <code>vec4</code>, <code>ivec4</code>, and <code>bvec4</code> uniforms that can be used by a vertex shader.
753
+ *
754
+ * @see Context#getMaximumFragmentUniformVectors
755
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VERTEX_UNIFORM_VECTORS</code>.
756
+ */
757
+ Context.prototype.getMaximumVertexUniformVectors = function() {
758
+ return this._maximumVertexUniformVectors;
759
+ };
760
+
761
+ /**
762
+ * Returns the minimum aliased line width, in pixels, supported by this WebGL implementation. It will be at most one.
763
+ *
764
+ * @memberof Context
765
+ *
766
+ * @returns {Number} The minimum aliased line in pixels.
767
+ *
768
+ * @see Context#getMaximumAliasedLineWidth
769
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>ALIASED_LINE_WIDTH_RANGE</code>.
770
+ */
771
+ Context.prototype.getMinimumAliasedLineWidth = function() {
772
+ return this._aliasedLineWidthRange[0];
773
+ };
774
+
775
+ /**
776
+ * Returns the maximum aliased line width, in pixels, supported by this WebGL implementation. It will be at least one.
777
+ *
778
+ * @memberof Context
779
+ *
780
+ * @returns {Number} The maximum aliased line in pixels.
781
+ *
782
+ * @see Context#getMinimumAliasedLineWidth
783
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>ALIASED_LINE_WIDTH_RANGE</code>.
784
+ */
785
+ Context.prototype.getMaximumAliasedLineWidth = function() {
786
+ return this._aliasedLineWidthRange[1];
787
+ };
788
+
789
+ /**
790
+ * Returns the minimum aliased point size, in pixels, supported by this WebGL implementation. It will be at most one.
791
+ *
792
+ * @memberof Context
793
+ *
794
+ * @returns {Number} The minimum aliased point size in pixels.
795
+ *
796
+ * @see Context#getMaximumAliasedPointSize
797
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>ALIASED_POINT_SIZE_RANGE</code>.
798
+ */
799
+ Context.prototype.getMinimumAliasedPointSize = function() {
800
+ return this._aliasedPointSizeRange[0];
801
+ };
802
+
803
+ /**
804
+ * Returns the maximum aliased point size, in pixels, supported by this WebGL implementation. It will be at least one.
805
+ *
806
+ * @memberof Context
807
+ *
808
+ * @returns {Number} The maximum aliased point size in pixels.
809
+ *
810
+ * @see Context#getMinimumAliasedPointSize
811
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>ALIASED_POINT_SIZE_RANGE</code>.
812
+ */
813
+ Context.prototype.getMaximumAliasedPointSize = function() {
814
+ return this._aliasedPointSizeRange[1];
815
+ };
816
+
817
+ /**
818
+ * Returns the maximum supported width of the viewport. It will be at least as large as the visible width of the associated canvas.
819
+ *
820
+ * @memberof Context
821
+ *
822
+ * @returns {Number} The maximum supported width of the viewport.
823
+ *
824
+ * @see Context#getMaximumViewportHeight
825
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VIEWPORT_DIMS</code>.
826
+ */
827
+ Context.prototype.getMaximumViewportWidth = function() {
828
+ return this._maximumViewportDimensions[0];
829
+ };
830
+
831
+ /**
832
+ * Returns the maximum supported height of the viewport. It will be at least as large as the visible height of the associated canvas.
833
+ *
834
+ * @memberof Context
835
+ *
836
+ * @returns {Number} The maximum supported height of the viewport.
837
+ *
838
+ * @see Context#getMaximumViewportHeight
839
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGet.xml'>glGet</a> with <code>MAX_VIEWPORT_DIMS</code>.
840
+ */
841
+ Context.prototype.getMaximumViewportHeight = function() {
842
+ return this._maximumViewportDimensions[1];
843
+ };
844
+
845
+ /**
846
+ * Returns <code>true</code> if the OES_standard_derivatives extension is supported. This
847
+ * extension provides access to <code>dFdx<code>, <code>dFdy<code>, and <code>fwidth<code>
848
+ * functions from GLSL. A shader using these functions still needs to explicitly enable the
849
+ * extension with <code>#extension GL_OES_standard_derivatives : enable</code>.
850
+ *
851
+ * @memberof Context
852
+ *
853
+ * @returns {Boolean} <code>true</code> if OES_standard_derivatives is supported; otherwise, <code>false</code>.
854
+ *
855
+ * @see <a href='http://www.khronos.org/registry/gles/extensions/OES/OES_standard_derivatives.txt'>OES_standard_derivatives</a>
856
+ */
857
+ Context.prototype.getStandardDerivatives = function() {
858
+ return !!this._standardDerivatives;
859
+ };
860
+
861
+ /**
862
+ * Returns <code>true</code> if WEBGL_depth_texture is supported. This extension provides
863
+ * access to depth textures that, for example, can be attached to framebuffers for shadow mapping.
864
+ *
865
+ * @memberof Context
866
+ *
867
+ * @returns {Boolean} <code>true</code> if WEBGL_depth_texture is supported; otherwise, <code>false</code>.
868
+ *
869
+ * @see <a href='http://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/'>WEBGL_depth_texture</a>
870
+ */
871
+ Context.prototype.getDepthTexture = function() {
872
+ return !!this._depthTexture;
873
+ };
874
+
875
+ /**
876
+ * DOC_TBA
877
+ *
878
+ * @memberof Context
879
+ *
880
+ * @returns {Boolean} <code>true</code> if EXT_texture_filter_anisotropic is supported; otherwise, <code>false</code>.
881
+ *
882
+ * @see <a href='http://www.khronos.org/registry/webgl/extensions/EXT_texture_filter_anisotropic/'>EXT_texture_filter_anisotropic</a>
883
+ */
884
+ Context.prototype.getTextureFilterAnisotropic = function() {
885
+ return !!this._textureFilterAnisotropic;
886
+ };
887
+
888
+ /**
889
+ * DOC_TBA
890
+ *
891
+ * @memberof Context
892
+ *
893
+ * @see Context#getTextureFilterAnisotropic
894
+ */
895
+ Context.prototype.getMaximumTextureFilterAnisotropy = function() {
896
+ return this._maximumTextureFilterAnisotropy;
897
+ };
898
+
899
+ /**
900
+ * DOC_TBA
901
+ *
902
+ * @memberof Context
903
+ *
904
+ * @see Context#setValidateFramebuffer
905
+ */
906
+ Context.prototype.getValidateFramebuffer = function() {
907
+ return this._validateFB;
908
+ };
909
+
910
+ /**
911
+ * DOC_TBA
912
+ *
913
+ * @memberof Context
914
+ *
915
+ * @performance DOC_TBA: slow.
916
+ *
917
+ * @see Context#setValidateShaderProgram
918
+ * @see Context#getValidateFramebuffer
919
+ */
920
+ Context.prototype.setValidateFramebuffer = function(value) {
921
+ this._validateFB = value;
922
+ };
923
+
924
+ /**
925
+ * DOC_TBA
926
+ *
927
+ * @memberof Context
928
+ *
929
+ * @see Context#setValidateShaderProgram
930
+ */
931
+ Context.prototype.getValidateShaderProgram = function() {
932
+ return this._validateSP;
933
+ };
934
+
935
+ /**
936
+ * DOC_TBA
937
+ *
938
+ * @memberof Context
939
+ *
940
+ * @performance DOC_TBA: slow.
941
+ *
942
+ * @see Context#setValidateFramebuffer
943
+ * @see Context#getValidateShaderProgram
944
+ */
945
+ Context.prototype.setValidateShaderProgram = function(value) {
946
+ this._validateSP = value;
947
+ };
948
+
949
+ /**
950
+ * DOC_TBA
951
+ *
952
+ * @memberof Context
953
+ *
954
+ * @see Context#setThrowOnWebGLError
955
+ */
956
+ Context.prototype.getThrowOnWebGLError = function() {
957
+ return this._throwOnWebGLError;
958
+ };
959
+
960
+ /**
961
+ * DOC_TBA
962
+ *
963
+ * @memberof Context
964
+ *
965
+ * @performance DOC_TBA: slow.
966
+ *
967
+ * @see Context#setValidateFramebuffer
968
+ * @see Context#setValidateShaderProgram
969
+ * @see Context#getThrowOnWebGLError
970
+ */
971
+ Context.prototype.setThrowOnWebGLError = function(value) {
972
+ this._throwOnWebGLError = value;
973
+ this._gl = wrapGL(this._originalGLContext, value ? throwOnError : null);
974
+ };
975
+
976
+ /**
977
+ * DOC_TBA
978
+ *
979
+ * @memberof Context
980
+ *
981
+ * @see Context#setLogShaderCompilation
982
+ */
983
+ Context.prototype.getLogShaderCompilation = function() {
984
+ return this._logShaderCompilation;
985
+ };
986
+
987
+ /**
988
+ * DOC_TBA
989
+ *
990
+ * @memberof Context
991
+ *
992
+ * @see Context#getLogShaderCompilation
993
+ */
994
+ Context.prototype.setLogShaderCompilation = function(value) {
995
+ this._logShaderCompilation = value;
996
+ };
997
+
998
+ /**
999
+ * Returns a 1x1 RGBA texture initialized to [255, 255, 255, 255]. This can
1000
+ * be used as a placeholder texture while other textures are downloaded.
1001
+ *
1002
+ * @return {Texture}
1003
+ *
1004
+ * @memberof Context
1005
+ */
1006
+ Context.prototype.getDefaultTexture = function() {
1007
+ if (this._defaultTexture === undefined) {
1008
+ this._defaultTexture = this.createTexture2D({
1009
+ source : {
1010
+ width : 1,
1011
+ height : 1,
1012
+ arrayBufferView : new Uint8Array([255, 255, 255, 255])
1013
+ }
1014
+ });
1015
+ }
1016
+
1017
+ return this._defaultTexture;
1018
+ };
1019
+
1020
+ /**
1021
+ * Returns a cube map, where each face is a 1x1 RGBA texture initialized to
1022
+ * [255, 255, 255, 255]. This can be used as a placeholder cube map while
1023
+ * other cube maps are downloaded.
1024
+ *
1025
+ * @return {CubeMap}
1026
+ *
1027
+ * @memberof Context
1028
+ */
1029
+ Context.prototype.getDefaultCubeMap = function() {
1030
+ if (this._defaultCubeMap === undefined) {
1031
+ var face = {
1032
+ width : 1,
1033
+ height : 1,
1034
+ arrayBufferView : new Uint8Array([255, 255, 255, 255])
1035
+ };
1036
+
1037
+ this._defaultCubeMap = this.createCubeMap({
1038
+ source : {
1039
+ positiveX : face,
1040
+ negativeX : face,
1041
+ positiveY : face,
1042
+ negativeY : face,
1043
+ positiveZ : face,
1044
+ negativeZ : face
1045
+ }
1046
+ });
1047
+ }
1048
+
1049
+ return this._defaultCubeMap;
1050
+ };
1051
+
1052
+ /**
1053
+ * Creates a shader program given the GLSL source for a vertex and fragment shader.
1054
+ * <br /><br />
1055
+ * The vertex and fragment shader are individually compiled, and then linked together
1056
+ * to create a shader program. An exception is thrown if any errors are encountered,
1057
+ * as described below.
1058
+ * <br /><br />
1059
+ * The program's active uniforms and attributes are queried and can be accessed using
1060
+ * the returned shader program. The caller can explicitly define the vertex
1061
+ * attribute indices using the optional <code>attributeLocations</code> argument as
1062
+ * shown in example two below.
1063
+ *
1064
+ * @memberof Context
1065
+ *
1066
+ * @param {String} vertexShaderSource The GLSL source for the vertex shader.
1067
+ * @param {String} fragmentShaderSource The GLSL source for the fragment shader.
1068
+ * @param {Object} [attributeLocations=undefined] An optional object that maps vertex attribute names to indices for use with vertex arrays.
1069
+ *
1070
+ * @return {ShaderProgram} The compiled and linked shader program, ready for use in a draw call.
1071
+ *
1072
+ * @exception {RuntimeError} Vertex shader failed to compile.
1073
+ * @exception {RuntimeError} Fragment shader failed to compile.
1074
+ * @exception {RuntimeError} Program failed to link.
1075
+ *
1076
+ * @see Context#draw
1077
+ * @see Context#createVertexArray
1078
+ * @see Context#getShaderCache
1079
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glCreateShader.xml'>glCreateShader</a>
1080
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glShaderSource.xml'>glShaderSource</a>
1081
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glCompileShader.xml'>glCompileShader</a>
1082
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glCreateProgram.xml'>glCreateProgram</a>
1083
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glAttachShader.xml'>glAttachShader</a>
1084
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glLinkProgram.xml'>glLinkProgram</a>
1085
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetShaderiv.xml'>glGetShaderiv</a>
1086
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetActiveUniform.xml'>glGetActiveUniform</a>
1087
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetUniformLocation.xml'>glGetUniformLocation</a>
1088
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetUniform.xml'>glGetUniform</a>
1089
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glBindAttribLocation.xml'>glBindAttribLocation</a>
1090
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetActiveAttrib.xml'>glGetActiveAttrib</a>
1091
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGetAttribLocation.xml'>glGetAttribLocation</a>
1092
+ *
1093
+ * @example
1094
+ * // Example 1. Create a shader program allowing the GL to determine
1095
+ * // attribute indices.
1096
+ * var vs = 'attribute vec4 position; void main() { gl_Position = position; }';
1097
+ * var fs = 'void main() { gl_FragColor = vec4(1.0); }';
1098
+ * var sp = context.createShaderProgram(vs, fs);
1099
+ *
1100
+ * ////////////////////////////////////////////////////////////////////////////////
1101
+ *
1102
+ * // Example 2. Create a shader program with explicit attribute indices.
1103
+ * var vs = 'attribute vec4 position;' +
1104
+ * 'attribute vec3 normal;' +
1105
+ * 'void main() { ... }';
1106
+ * var fs = 'void main() { gl_FragColor = vec4(1.0); }';
1107
+ * var attributes = {
1108
+ * position : 0,
1109
+ * normal : 1
1110
+ * };
1111
+ * sp = context.createShaderProgram(vs, fs, attributes); *
1112
+ */
1113
+ Context.prototype.createShaderProgram = function(vertexShaderSource, fragmentShaderSource, attributeLocations) {
1114
+ return new ShaderProgram(this._gl, this._logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations);
1115
+ };
1116
+
1117
+ function createBuffer(gl, bufferTarget, typedArrayOrSizeInBytes, usage) {
1118
+ var sizeInBytes;
1119
+
1120
+ if (typeof typedArrayOrSizeInBytes === 'number') {
1121
+ sizeInBytes = typedArrayOrSizeInBytes;
1122
+ } else if (typeof typedArrayOrSizeInBytes === 'object' && typeof typedArrayOrSizeInBytes.byteLength !== 'undefined') {
1123
+ sizeInBytes = typedArrayOrSizeInBytes.byteLength;
1124
+ } else {
1125
+ throw new DeveloperError('typedArrayOrSizeInBytes must be either a typed array or a number.');
1126
+ }
1127
+
1128
+ if (sizeInBytes <= 0) {
1129
+ throw new DeveloperError('typedArrayOrSizeInBytes must be greater than zero.');
1130
+ }
1131
+
1132
+ if (!BufferUsage.validate(usage)) {
1133
+ throw new DeveloperError('usage is invalid.');
1134
+ }
1135
+
1136
+ var buffer = gl.createBuffer();
1137
+ gl.bindBuffer(bufferTarget, buffer);
1138
+ gl.bufferData(bufferTarget, typedArrayOrSizeInBytes, usage);
1139
+ gl.bindBuffer(bufferTarget, null);
1140
+
1141
+ return new Buffer(gl, bufferTarget, sizeInBytes, usage, buffer);
1142
+ }
1143
+
1144
+ /**
1145
+ * Creates a vertex buffer, which contains untyped vertex data in GPU-controlled memory.
1146
+ * <br /><br />
1147
+ * A vertex array defines the actual makeup of a vertex, e.g., positions, normals, texture coordinates,
1148
+ * etc., by interpreting the raw data in one or more vertex buffers.
1149
+ *
1150
+ * @memberof Context
1151
+ *
1152
+ * @param {ArrayBufferView|Number} typedArrayOrSizeInBytes A typed array containing the data to copy to the buffer, or a <code>Number</code> defining the size of the buffer in bytes.
1153
+ * @param {BufferUsage} usage Specifies the expected usage pattern of the buffer. On some GL implementations, this can significantly affect performance. See {@link BufferUsage}.
1154
+ *
1155
+ * @return {VertexBuffer} The vertex buffer, ready to be attached to a vertex array.
1156
+ *
1157
+ * @exception {DeveloperError} The size in bytes must be greater than zero.
1158
+ * @exception {DeveloperError} Invalid <code>usage</code>.
1159
+ *
1160
+ * @see Context#createVertexArray
1161
+ * @see Context#createIndexBuffer
1162
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGenBuffer.xml'>glGenBuffer</a>
1163
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glBindBuffer.xml'>glBindBuffer</a> with <code>ARRAY_BUFFER</code>
1164
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glBufferData.xml'>glBufferData</a> with <code>ARRAY_BUFFER</code>
1165
+ *
1166
+ * @example
1167
+ * // Example 1. Create a dynamic vertex buffer 16 bytes in size.
1168
+ * var buffer = context.createVertexBuffer(16, BufferUsage.DYNAMIC_DRAW);
1169
+ *
1170
+ * ////////////////////////////////////////////////////////////////////////////////
1171
+ *
1172
+ * // Example 2. Create a dynamic vertex buffer from three floating-point values.
1173
+ * // The data copied to the vertex buffer is considered raw bytes until it is
1174
+ * // interpreted as vertices using a vertex array.
1175
+ * var positionBuffer = context.createVertexBuffer(new Float32Array([0, 0, 0]),
1176
+ * BufferUsage.STATIC_DRAW);
1177
+ */
1178
+ Context.prototype.createVertexBuffer = function(typedArrayOrSizeInBytes, usage) {
1179
+ return createBuffer(this._gl, this._gl.ARRAY_BUFFER, typedArrayOrSizeInBytes, usage);
1180
+ };
1181
+
1182
+ /**
1183
+ * Creates an index buffer, which contains typed indices in GPU-controlled memory.
1184
+ * <br /><br />
1185
+ * An index buffer can be attached to a vertex array to select vertices for rendering.
1186
+ * <code>Context.draw</code> can render using the entire index buffer or a subset
1187
+ * of the index buffer defined by an offset and count.
1188
+ *
1189
+ * @memberof Context
1190
+ *
1191
+ * @param {ArrayBufferView|Number} typedArrayOrSizeInBytes A typed array containing the data to copy to the buffer, or a <code>Number</code> defining the size of the buffer in bytes.
1192
+ * @param {BufferUsage} usage Specifies the expected usage pattern of the buffer. On some GL implementations, this can significantly affect performance. See {@link BufferUsage}.
1193
+ * @param {IndexDatatype} indexDatatype The datatype of indices in the buffer.
1194
+ *
1195
+ * @return {IndexBuffer} The index buffer, ready to be attached to a vertex array.
1196
+ *
1197
+ * @exception {DeveloperError} The size in bytes must be greater than zero.
1198
+ * @exception {DeveloperError} Invalid <code>usage</code>.
1199
+ * @exception {DeveloperError} Invalid <code>indexDatatype</code>.
1200
+ *
1201
+ * @see Context#createVertexArray
1202
+ * @see Context#createVertexBuffer
1203
+ * @see Context#draw
1204
+ * @see VertexArray
1205
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glGenBuffer.xml'>glGenBuffer</a>
1206
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glBindBuffer.xml'>glBindBuffer</a> with <code>ELEMENT_ARRAY_BUFFER</code>
1207
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glBufferData.xml'>glBufferData</a> with <code>ELEMENT_ARRAY_BUFFER</code>
1208
+ *
1209
+ * @example
1210
+ * // Example 1. Create a stream index buffer of unsigned shorts that is
1211
+ * // 16 bytes in size.
1212
+ * var buffer = context.createIndexBuffer(16, BufferUsage.STREAM_DRAW,
1213
+ * IndexDatatype.UNSIGNED_SHORT);
1214
+ *
1215
+ * ////////////////////////////////////////////////////////////////////////////////
1216
+ *
1217
+ * // Example 2. Create a static index buffer containing three unsigned shorts.
1218
+ * var buffer = context.createIndexBuffer(new Uint16Array([0, 1, 2]),
1219
+ * BufferUsage.STATIC_DRAW, IndexDatatype.UNSIGNED_SHORT)
1220
+ */
1221
+ Context.prototype.createIndexBuffer = function(typedArrayOrSizeInBytes, usage, indexDatatype) {
1222
+ var bytesPerIndex;
1223
+
1224
+ if (indexDatatype === IndexDatatype.UNSIGNED_BYTE) {
1225
+ bytesPerIndex = Uint8Array.BYTES_PER_ELEMENT;
1226
+ } else if (indexDatatype === IndexDatatype.UNSIGNED_SHORT) {
1227
+ bytesPerIndex = Uint16Array.BYTES_PER_ELEMENT;
1228
+ } else {
1229
+ throw new DeveloperError('Invalid indexDatatype.');
1230
+ }
1231
+
1232
+ var gl = this._gl;
1233
+ var buffer = createBuffer(gl, gl.ELEMENT_ARRAY_BUFFER, typedArrayOrSizeInBytes, usage);
1234
+ var numberOfIndices = buffer.getSizeInBytes() / bytesPerIndex;
1235
+
1236
+ buffer.getIndexDatatype = function() {
1237
+ return indexDatatype;
1238
+ };
1239
+
1240
+ buffer.getBytesPerIndex = function() {
1241
+ return bytesPerIndex;
1242
+ };
1243
+
1244
+ buffer.getNumberOfIndices = function() {
1245
+ return numberOfIndices;
1246
+ };
1247
+
1248
+ return buffer;
1249
+ };
1250
+
1251
+ /**
1252
+ * Creates a vertex array, which defines the attributes making up a vertex, and contains an optional index buffer
1253
+ * to select vertices for rendering. Attributes are defined using object literals as shown in Example 1 below.
1254
+ *
1255
+ * @memberof Context
1256
+ *
1257
+ * @param {Array} [attributes=undefined] An optional array of attributes.
1258
+ * @param {IndexBuffer} [indexBuffer=undefined] An optional index buffer.
1259
+ *
1260
+ * @return {VertexArray} The vertex array, ready for use with drawing.
1261
+ *
1262
+ * @exception {DeveloperError} Attribute must have a <code>vertexBuffer</code>.
1263
+ * @exception {DeveloperError} Attribute must have a <code>componentsPerAttribute</code>.
1264
+ * @exception {DeveloperError} Attribute must have a valid <code>componentDatatype</code> or not specify it.
1265
+ * @exception {DeveloperError} Attribute must have a <code>strideInBytes</code> less than or equal to 255 or not specify it.
1266
+ * @exception {DeveloperError} Index n is used by more than one attribute.
1267
+ *
1268
+ * @see Context#createVertexArrayFromMesh
1269
+ * @see Context#createVertexBuffer
1270
+ * @see Context#createIndexBuffer
1271
+ * @see Context#draw
1272
+ *
1273
+ * @example
1274
+ * // Example 1. Create a vertex array with vertices made up of three floating point
1275
+ * // values, e.g., a position, from a single vertex buffer. No index buffer is used.
1276
+ * var positionBuffer = context.createVertexBuffer(12, BufferUsage.STATIC_DRAW);
1277
+ * var attributes = [
1278
+ * {
1279
+ * index : 0,
1280
+ * enabled : true,
1281
+ * vertexBuffer : positionBuffer,
1282
+ * componentsPerAttribute : 3,
1283
+ * componentDatatype : ComponentDatatype.FLOAT,
1284
+ * normalize : false,
1285
+ * offsetInBytes : 0,
1286
+ * strideInBytes : 0 // tightly packed
1287
+ * }
1288
+ * ];
1289
+ * var va = context.createVertexArray(attributes);
1290
+ *
1291
+ * ////////////////////////////////////////////////////////////////////////////////
1292
+ *
1293
+ * // Example 2. Create a vertex array with vertices from two different vertex buffers.
1294
+ * // Each vertex has a three-component position and three-component normal.
1295
+ * var positionBuffer = context.createVertexBuffer(12, BufferUsage.STATIC_DRAW);
1296
+ * var normalBuffer = context.createVertexBuffer(12, BufferUsage.STATIC_DRAW);
1297
+ * var attributes = [
1298
+ * {
1299
+ * index : 0,
1300
+ * vertexBuffer : positionBuffer,
1301
+ * componentsPerAttribute : 3,
1302
+ * componentDatatype : ComponentDatatype.FLOAT
1303
+ * },
1304
+ * {
1305
+ * index : 1,
1306
+ * vertexBuffer : normalBuffer,
1307
+ * componentsPerAttribute : 3,
1308
+ * componentDatatype : ComponentDatatype.FLOAT
1309
+ * }
1310
+ * ];
1311
+ * var va = context.createVertexArray(attributes);
1312
+ *
1313
+ * ////////////////////////////////////////////////////////////////////////////////
1314
+ *
1315
+ * // Example 3. Creates the same vertex layout as Example 2 using a single
1316
+ * // vertex buffer, instead of two.
1317
+ * var buffer = context.createVertexBuffer(24, BufferUsage.STATIC_DRAW);
1318
+ * var attributes = [
1319
+ * {
1320
+ * vertexBuffer : buffer,
1321
+ * componentsPerAttribute : 3,
1322
+ * componentDatatype : ComponentDatatype.FLOAT,
1323
+ * offsetInBytes : 0,
1324
+ * strideInBytes : 24
1325
+ * },
1326
+ * {
1327
+ * vertexBuffer : buffer,
1328
+ * componentsPerAttribute : 3,
1329
+ * componentDatatype : ComponentDatatype.FLOAT,
1330
+ * normalize : true,
1331
+ * offsetInBytes : 12,
1332
+ * strideInBytes : 24
1333
+ * }
1334
+ * ];
1335
+ * var va = context.createVertexArray(attributes);
1336
+ */
1337
+ Context.prototype.createVertexArray = function(attributes, indexBuffer) {
1338
+ return new VertexArray(this._gl, attributes, indexBuffer);
1339
+ };
1340
+
1341
+ /**
1342
+ * DOC_TBA.
1343
+ *
1344
+ * description.source can be {ImageData}, {HTMLImageElement}, {HTMLCanvasElement}, or {HTMLVideoElement}.
1345
+ *
1346
+ * @memberof Context
1347
+ *
1348
+ * @return {Texture} DOC_TBA.
1349
+ *
1350
+ * @exception {RuntimeError} When description.pixelFormat is DEPTH_COMPONENT or DEPTH_STENCIL, this WebGL implementation must support WEBGL_depth_texture.
1351
+ * @exception {DeveloperError} description is required.
1352
+ * @exception {DeveloperError} description requires a source field to create an initialized texture or width and height fields to create a blank texture.
1353
+ * @exception {DeveloperError} Width must be greater than zero.
1354
+ * @exception {DeveloperError} Width must be less than or equal to the maximum texture size.
1355
+ * @exception {DeveloperError} Height must be greater than zero.
1356
+ * @exception {DeveloperError} Height must be less than or equal to the maximum texture size.
1357
+ * @exception {DeveloperError} Invalid description.pixelFormat.
1358
+ * @exception {DeveloperError} Invalid description.pixelDatatype.
1359
+ * @exception {DeveloperError} When description.pixelFormat is DEPTH_COMPONENT, description.pixelDatatype must be UNSIGNED_SHORT or UNSIGNED_INT.
1360
+ * @exception {DeveloperError} When description.pixelFormat is DEPTH_STENCIL, description.pixelDatatype must be UNSIGNED_INT_24_8_WEBGL.
1361
+ * @exception {DeveloperError} When description.pixelFormat is DEPTH_COMPONENT or DEPTH_STENCIL, source cannot be provided.
1362
+ *
1363
+ * @see Context#createTexture2DFromFramebuffer
1364
+ * @see Context#createCubeMap
1365
+ * @see Context#createSampler
1366
+ */
1367
+ Context.prototype.createTexture2D = function(description) {
1368
+ if (!description) {
1369
+ throw new DeveloperError('description is required.');
1370
+ }
1371
+
1372
+ var source = description.source;
1373
+ var width = typeof source !== 'undefined' ? source.width : description.width;
1374
+ var height = typeof source !== 'undefined' ? source.height : description.height;
1375
+
1376
+ if (typeof width === 'undefined' || typeof height === 'undefined') {
1377
+ throw new DeveloperError('description requires a source field to create an initialized texture or width and height fields to create a blank texture.');
1378
+ }
1379
+
1380
+ if (width <= 0) {
1381
+ throw new DeveloperError('Width must be greater than zero.');
1382
+ }
1383
+
1384
+ if (width > this._maximumTextureSize) {
1385
+ throw new DeveloperError('Width must be less than or equal to the maximum texture size (' + this._maximumTextureSize + '). Check getMaximumTextureSize().');
1386
+ }
1387
+
1388
+ if (height <= 0) {
1389
+ throw new DeveloperError('Height must be greater than zero.');
1390
+ }
1391
+
1392
+ if (height > this._maximumTextureSize) {
1393
+ throw new DeveloperError('Height must be less than or equal to the maximum texture size (' + this._maximumTextureSize + '). Check getMaximumTextureSize().');
1394
+ }
1395
+
1396
+ var pixelFormat = defaultValue(description.pixelFormat, PixelFormat.RGBA);
1397
+ if (!PixelFormat.validate(pixelFormat)) {
1398
+ throw new DeveloperError('Invalid description.pixelFormat.');
1399
+ }
1400
+
1401
+ var pixelDatatype = defaultValue(description.pixelDatatype, PixelDatatype.UNSIGNED_BYTE);
1402
+ if (!PixelDatatype.validate(pixelDatatype)) {
1403
+ throw new DeveloperError('Invalid description.pixelDatatype.');
1404
+ }
1405
+
1406
+ if ((pixelFormat === PixelFormat.DEPTH_COMPONENT) &&
1407
+ ((pixelDatatype !== PixelDatatype.UNSIGNED_SHORT) && (pixelDatatype !== PixelDatatype.UNSIGNED_INT))) {
1408
+ throw new DeveloperError('When description.pixelFormat is DEPTH_COMPONENT, description.pixelDatatype must be UNSIGNED_SHORT or UNSIGNED_INT.');
1409
+ }
1410
+
1411
+ if ((pixelFormat === PixelFormat.DEPTH_STENCIL) && (pixelDatatype !== PixelDatatype.UNSIGNED_INT_24_8_WEBGL)) {
1412
+ throw new DeveloperError('When description.pixelFormat is DEPTH_STENCIL, description.pixelDatatype must be UNSIGNED_INT_24_8_WEBGL.');
1413
+ }
1414
+
1415
+ if (PixelFormat.isDepthFormat(pixelFormat)) {
1416
+ if (source) {
1417
+ throw new DeveloperError('When description.pixelFormat is DEPTH_COMPONENT or DEPTH_STENCIL, source cannot be provided.');
1418
+ }
1419
+
1420
+ if (!this.getDepthTexture()) {
1421
+ throw new RuntimeError('When description.pixelFormat is DEPTH_COMPONENT or DEPTH_STENCIL, this WebGL implementation must support WEBGL_depth_texture. Check getDepthTexture().');
1422
+ }
1423
+ }
1424
+
1425
+ // Use premultiplied alpha for opaque textures should perform better on Chrome:
1426
+ // http://media.tojicode.com/webglCamp4/#20
1427
+ var preMultiplyAlpha = description.preMultiplyAlpha || pixelFormat === PixelFormat.RGB || pixelFormat === PixelFormat.LUMINANCE;
1428
+ var flipY = defaultValue(description.flipY, true);
1429
+
1430
+ var gl = this._gl;
1431
+ var textureTarget = gl.TEXTURE_2D;
1432
+ var texture = gl.createTexture();
1433
+
1434
+ gl.activeTexture(gl.TEXTURE0);
1435
+ gl.bindTexture(textureTarget, texture);
1436
+
1437
+ if (source) {
1438
+ // TODO: _gl.pixelStorei(_gl._UNPACK_ALIGNMENT, 4);
1439
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
1440
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
1441
+
1442
+ if (source.arrayBufferView) {
1443
+ // Source: typed array
1444
+ gl.texImage2D(textureTarget, 0, pixelFormat, width, height, 0, pixelFormat, pixelDatatype, source.arrayBufferView);
1445
+ } else {
1446
+ // Source: ImageData, HTMLImageElement, HTMLCanvasElement, or HTMLVideoElement
1447
+ gl.texImage2D(textureTarget, 0, pixelFormat, pixelFormat, pixelDatatype, source);
1448
+ }
1449
+ } else {
1450
+ gl.texImage2D(textureTarget, 0, pixelFormat, width, height, 0, pixelFormat, pixelDatatype, null);
1451
+ }
1452
+ gl.bindTexture(textureTarget, null);
1453
+
1454
+ return new Texture(gl, this._textureFilterAnisotropic, textureTarget, texture, pixelFormat, pixelDatatype, width, height, preMultiplyAlpha, flipY);
1455
+ };
1456
+
1457
+ /**
1458
+ * Creates a texture, and copies a subimage of the framebuffer to it. When called without arguments,
1459
+ * the texture is the same width and height as the framebuffer and contains its contents.
1460
+ *
1461
+ * @memberof Context
1462
+ *
1463
+ * @param {PixelFormat} [pixelFormat=PixelFormat.RGB] The texture's internal pixel format.
1464
+ * @param {PixelFormat} [framebufferXOffset=0] An offset in the x direction in the framebuffer where copying begins from.
1465
+ * @param {PixelFormat} [framebufferYOffset=0] An offset in the y direction in the framebuffer where copying begins from.
1466
+ * @param {PixelFormat} [width=canvas.clientWidth] The width of the texture in texels.
1467
+ * @param {PixelFormat} [height=canvas.clientHeight] The height of the texture in texels.
1468
+ *
1469
+ * @return {Texture} A texture with contents from the framebuffer.
1470
+ *
1471
+ * @exception {DeveloperError} Invalid pixelFormat.
1472
+ * @exception {DeveloperError} pixelFormat cannot be DEPTH_COMPONENT or DEPTH_STENCIL.
1473
+ * @exception {DeveloperError} framebufferXOffset must be greater than or equal to zero.
1474
+ * @exception {DeveloperError} framebufferYOffset must be greater than or equal to zero.
1475
+ * @exception {DeveloperError} framebufferXOffset + width must be less than or equal to getCanvas().clientWidth.
1476
+ * @exception {DeveloperError} framebufferYOffset + height must be less than or equal to getCanvas().clientHeight.
1477
+ *
1478
+ * @see Context#createTexture2D
1479
+ * @see Context#createCubeMap
1480
+ * @see Context#createSampler
1481
+ *
1482
+ * @example
1483
+ * // Create a texture with the contents of the framebuffer.
1484
+ * var t = context.createTexture2DFromFramebuffer();
1485
+ */
1486
+ Context.prototype.createTexture2DFromFramebuffer = function(pixelFormat, framebufferXOffset, framebufferYOffset, width, height) {
1487
+ pixelFormat = pixelFormat || PixelFormat.RGB;
1488
+ framebufferXOffset = defaultValue(framebufferXOffset, 0);
1489
+ framebufferYOffset = defaultValue(framebufferYOffset, 0);
1490
+ width = defaultValue(width, this._canvas.clientWidth);
1491
+ height = defaultValue(height, this._canvas.clientHeight);
1492
+
1493
+ if (!PixelFormat.validate(pixelFormat)) {
1494
+ throw new DeveloperError('Invalid pixelFormat.');
1495
+ }
1496
+
1497
+ if (PixelFormat.isDepthFormat(pixelFormat)) {
1498
+ throw new DeveloperError('pixelFormat cannot be DEPTH_COMPONENT or DEPTH_STENCIL.');
1499
+ }
1500
+
1501
+ if (framebufferXOffset < 0) {
1502
+ throw new DeveloperError('framebufferXOffset must be greater than or equal to zero.');
1503
+ }
1504
+
1505
+ if (framebufferYOffset < 0) {
1506
+ throw new DeveloperError('framebufferYOffset must be greater than or equal to zero.');
1507
+ }
1508
+
1509
+ if (framebufferXOffset + width > this._canvas.clientWidth) {
1510
+ throw new DeveloperError('framebufferXOffset + width must be less than or equal to getCanvas().clientWidth');
1511
+ }
1512
+
1513
+ if (framebufferYOffset + height > this._canvas.clientHeight) {
1514
+ throw new DeveloperError('framebufferYOffset + height must be less than or equal to getCanvas().clientHeight.');
1515
+ }
1516
+
1517
+ var gl = this._gl;
1518
+ var textureTarget = gl.TEXTURE_2D;
1519
+ var texture = gl.createTexture();
1520
+
1521
+ gl.activeTexture(gl.TEXTURE0);
1522
+ gl.bindTexture(textureTarget, texture);
1523
+ gl.copyTexImage2D(textureTarget, 0, pixelFormat, framebufferXOffset, framebufferYOffset, width, height, 0);
1524
+ gl.bindTexture(textureTarget, null);
1525
+
1526
+ return new Texture(gl, this._textureFilterAnisotropic, textureTarget, texture, pixelFormat, undefined, width, height);
1527
+ };
1528
+
1529
+ /**
1530
+ * Creates a new texture atlas with this context.
1531
+ *
1532
+ * @memberof Context
1533
+ *
1534
+ * @param {PixelFormat} [description.pixelFormat = PixelFormat.RGBA] The pixel format of the texture.
1535
+ * @param {Number} [description.borderWidthInPixels = 1] The amount of spacing between adjacent images in pixels.
1536
+ * @param {Cartesian2} [description.initialSize = new Cartesian2(16.0, 16.0)] The initial side lengths of the texture.
1537
+ * @param {Array} [description.images=undefined] Array of {@link Image} to be added to the atlas. Same as calling addImages(images).
1538
+ * @param {Image} [description.image=undefined] Single image to be added to the atlas. Same as calling addImage(image).
1539
+ *
1540
+ * @returns {TextureAtlas} The new texture atlas.
1541
+ *
1542
+ * @see TextureAtlas
1543
+ */
1544
+ Context.prototype.createTextureAtlas = function(description) {
1545
+ description = description || {};
1546
+ description.context = this;
1547
+ return new TextureAtlas(description);
1548
+ };
1549
+
1550
+ /**
1551
+ * DOC_TBA.
1552
+ *
1553
+ * description.source can be {ImageData}, {HTMLImageElement}, {HTMLCanvasElement}, or {HTMLVideoElement}.
1554
+ *
1555
+ * @memberof Context
1556
+ *
1557
+ * @return {CubeMap} DOC_TBA.
1558
+ *
1559
+ * @exception {DeveloperError} description is required.
1560
+ * @exception {DeveloperError} description.source requires positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ faces.
1561
+ * @exception {DeveloperError} Each face in description.sources must have the same width and height.
1562
+ * @exception {DeveloperError} description requires a source field to create an initialized cube map or width and height fields to create a blank cube map.
1563
+ * @exception {DeveloperError} Width must equal height.
1564
+ * @exception {DeveloperError} Width and height must be greater than zero.
1565
+ * @exception {DeveloperError} Width and height must be less than or equal to the maximum cube map size.
1566
+ * @exception {DeveloperError} Invalid description.pixelFormat.
1567
+ * @exception {DeveloperError} description.pixelFormat cannot be DEPTH_COMPONENT or DEPTH_STENCIL.
1568
+ * @exception {DeveloperError} Invalid description.pixelDatatype.
1569
+ *
1570
+ * @see Context#createTexture2D
1571
+ * @see Context#createTexture2DFromFramebuffer
1572
+ * @see Context#createSampler
1573
+ */
1574
+ Context.prototype.createCubeMap = function(description) {
1575
+ if (!description) {
1576
+ throw new DeveloperError('description is required.');
1577
+ }
1578
+
1579
+ var source = description.source;
1580
+ var width;
1581
+ var height;
1582
+
1583
+ if (source) {
1584
+ var faces = [source.positiveX, source.negativeX, source.positiveY, source.negativeY, source.positiveZ, source.negativeZ];
1585
+
1586
+ if (!faces[0] || !faces[1] || !faces[2] || !faces[3] || !faces[4] || !faces[5]) {
1587
+ throw new DeveloperError('description.source requires positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ faces.');
1588
+ }
1589
+
1590
+ width = faces[0].width;
1591
+ height = faces[0].height;
1592
+
1593
+ for ( var i = 1; i < 6; ++i) {
1594
+ if ((Number(faces[i].width) !== width) || (Number(faces[i].height) !== height)) {
1595
+ throw new DeveloperError('Each face in description.source must have the same width and height.');
1596
+ }
1597
+ }
1598
+ } else {
1599
+ width = description.width;
1600
+ height = description.height;
1601
+ }
1602
+
1603
+ if (typeof width === 'undefined' || typeof height === 'undefined') {
1604
+ throw new DeveloperError('description requires a source field to create an initialized cube map or width and height fields to create a blank cube map.');
1605
+ }
1606
+
1607
+ if (width !== height) {
1608
+ throw new DeveloperError('Width must equal height.');
1609
+ }
1610
+
1611
+ var size = width;
1612
+
1613
+ if (size <= 0) {
1614
+ throw new DeveloperError('Width and height must be greater than zero.');
1615
+ }
1616
+
1617
+ if (size > this._maximumCubeMapSize) {
1618
+ throw new DeveloperError('Width and height must be less than or equal to the maximum cube map size (' + this._maximumCubeMapSize + '). Check getMaximumCubeMapSize().');
1619
+ }
1620
+
1621
+ var pixelFormat = defaultValue(description.pixelFormat, PixelFormat.RGBA);
1622
+ if (!PixelFormat.validate(pixelFormat)) {
1623
+ throw new DeveloperError('Invalid description.pixelFormat.');
1624
+ }
1625
+
1626
+ if (PixelFormat.isDepthFormat(pixelFormat)) {
1627
+ throw new DeveloperError('description.pixelFormat cannot be DEPTH_COMPONENT or DEPTH_STENCIL.');
1628
+ }
1629
+
1630
+ var pixelDatatype = defaultValue(description.pixelDatatype, PixelDatatype.UNSIGNED_BYTE);
1631
+ if (!PixelDatatype.validate(pixelDatatype)) {
1632
+ throw new DeveloperError('Invalid description.pixelDatatype.');
1633
+ }
1634
+
1635
+ // Use premultiplied alpha for opaque textures should perform better on Chrome:
1636
+ // http://media.tojicode.com/webglCamp4/#20
1637
+ var preMultiplyAlpha = description.preMultiplyAlpha || ((pixelFormat === PixelFormat.RGB) || (pixelFormat === PixelFormat.LUMINANCE));
1638
+ var flipY = defaultValue(description.flipY, true);
1639
+
1640
+ var gl = this._gl;
1641
+ var textureTarget = gl.TEXTURE_CUBE_MAP;
1642
+ var texture = gl.createTexture();
1643
+
1644
+ gl.activeTexture(gl.TEXTURE0);
1645
+ gl.bindTexture(textureTarget, texture);
1646
+
1647
+ function createFace(target, sourceFace) {
1648
+ if (sourceFace.arrayBufferView) {
1649
+ gl.texImage2D(target, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, sourceFace.arrayBufferView);
1650
+ } else {
1651
+ gl.texImage2D(target, 0, pixelFormat, pixelFormat, pixelDatatype, sourceFace);
1652
+ }
1653
+ }
1654
+
1655
+ if (source) {
1656
+ // TODO: _gl.pixelStorei(_gl._UNPACK_ALIGNMENT, 4);
1657
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, preMultiplyAlpha);
1658
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
1659
+
1660
+ createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_X, source.positiveX);
1661
+ createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, source.negativeX);
1662
+ createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, source.positiveY);
1663
+ createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, source.negativeY);
1664
+ createFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, source.positiveZ);
1665
+ createFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, source.negativeZ);
1666
+ } else {
1667
+ gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
1668
+ gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
1669
+ gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
1670
+ gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
1671
+ gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
1672
+ gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, pixelFormat, size, size, 0, pixelFormat, pixelDatatype, null);
1673
+ }
1674
+ gl.bindTexture(textureTarget, null);
1675
+
1676
+ return new CubeMap(gl, this._textureFilterAnisotropic, textureTarget, texture, pixelFormat, pixelDatatype, size, preMultiplyAlpha, flipY);
1677
+ };
1678
+
1679
+ /**
1680
+ * Creates a framebuffer with optional initial color, depth, and stencil attachments.
1681
+ * Framebuffers are used for render-to-texture effects; they allow us to render to
1682
+ * a texture in one pass, and read from it in a later pass.
1683
+ *
1684
+ * @memberof Context
1685
+ *
1686
+ * @param {Object} [description] The initial framebuffer attachments as shown in Example 2. The possible properties are <code>colorTexture</code>, <code>colorRenderbuffer</code>, <code>depthTexture</code>, <code>depthRenderbuffer</code>, <code>stencilRenderbuffer</code>, <code>depthStencilTexture</code>, and <code>depthStencilRenderbuffer</code>.
1687
+ *
1688
+ * @return {Framebuffer} The created framebuffer.
1689
+ *
1690
+ * @exception {DeveloperError} Cannot have both a color texture and color renderbuffer attachment.
1691
+ * @exception {DeveloperError} Cannot have both a depth texture and depth renderbuffer attachment.
1692
+ * @exception {DeveloperError} Cannot have both a depth-stencil texture and depth-stencil renderbuffer attachment.
1693
+ * @exception {DeveloperError} Cannot have both a depth and depth-stencil renderbuffer.
1694
+ * @exception {DeveloperError} Cannot have both a stencil and depth-stencil renderbuffer.
1695
+ * @exception {DeveloperError} Cannot have both a depth and stencil renderbuffer.
1696
+ * @exception {DeveloperError} The color-texture pixel-format must be a color format.
1697
+ * @exception {DeveloperError} The depth-texture pixel-format must be DEPTH_COMPONENT.
1698
+ * @exception {DeveloperError} The depth-stencil-texture pixel-format must be DEPTH_STENCIL.
1699
+ *
1700
+ * @see Context#createTexture2D
1701
+ * @see Context#createCubeMap
1702
+ * @see Context#createRenderbuffer
1703
+ *
1704
+ * @example
1705
+ * // Example 1. Create a framebuffer with no initial attachments,
1706
+ * // and then add a color-texture attachment.
1707
+ * var framebuffer = context.createFramebuffer();
1708
+ * framebuffer.setColorTexture(context.createTexture2D({
1709
+ * width : 256,
1710
+ * height : 256,
1711
+ * }));
1712
+ *
1713
+ * //////////////////////////////////////////////////////////////////
1714
+ *
1715
+ * // Example 2. Create a framebuffer with color and depth texture attachments.
1716
+ * var width = context.getCanvas().clientWidth;
1717
+ * var height = context.getCanvas().clientHeight;
1718
+ * var framebuffer = context.createFramebuffer({
1719
+ * colorTexture : context.createTexture2D({
1720
+ * width : width,
1721
+ * height : height,
1722
+ * pixelFormat : PixelFormat.RGBA
1723
+ * }),
1724
+ * depthTexture : context.createTexture2D({
1725
+ * width : width,
1726
+ * height : height,
1727
+ * pixelFormat : PixelFormat.DEPTH_COMPONENT,
1728
+ * pixelDatatype : PixelDatatype.UNSIGNED_SHORT
1729
+ * })
1730
+ * });
1731
+ */
1732
+ Context.prototype.createFramebuffer = function(description) {
1733
+ return new Framebuffer(this._gl, description);
1734
+ };
1735
+
1736
+ /**
1737
+ * DOC_TBA.
1738
+ *
1739
+ * @memberof Context
1740
+ *
1741
+ * @param {Object} [description] DOC_TBA.
1742
+ *
1743
+ * @return {createRenderbuffer} DOC_TBA.
1744
+ *
1745
+ * @exception {DeveloperError} Invalid format.
1746
+ * @exception {DeveloperError} Width must be greater than zero.
1747
+ * @exception {DeveloperError} Width must be less than or equal to the maximum renderbuffer size.
1748
+ * @exception {DeveloperError} Height must be greater than zero.
1749
+ * @exception {DeveloperError} Height must be less than or equal to the maximum renderbuffer size.
1750
+ *
1751
+ * @see Context#createFramebuffer
1752
+ */
1753
+ Context.prototype.createRenderbuffer = function(description) {
1754
+ description = description || {};
1755
+ var format = description.format || RenderbufferFormat.RGBA4;
1756
+ var width = (typeof description.width === 'undefined') ? this._canvas.clientWidth : description.width;
1757
+ var height = (typeof description.height === 'undefined') ? this._canvas.clientHeight : description.height;
1758
+
1759
+
1760
+ var gl = this._gl;
1761
+ if (!RenderbufferFormat.validate(format)) {
1762
+ throw new DeveloperError('Invalid format.');
1763
+ }
1764
+
1765
+ if (width <= 0) {
1766
+ throw new DeveloperError('Width must be greater than zero.');
1767
+ }
1768
+
1769
+ if (width > this.getMaximumRenderbufferSize()) {
1770
+ throw new DeveloperError('Width must be less than or equal to the maximum renderbuffer size (' + this.getMaximumRenderbufferSize() + '). Check getMaximumRenderbufferSize().');
1771
+ }
1772
+
1773
+ if (height <= 0) {
1774
+ throw new DeveloperError('Height must be greater than zero.');
1775
+ }
1776
+
1777
+ if (height > this.getMaximumRenderbufferSize()) {
1778
+ throw new DeveloperError('Height must be less than or equal to the maximum renderbuffer size (' + this.getMaximumRenderbufferSize() + '). Check getMaximumRenderbufferSize().');
1779
+ }
1780
+
1781
+ return new Renderbuffer(gl, format, width, height);
1782
+ };
1783
+
1784
+ /**
1785
+ * DOC_TBA.
1786
+ *
1787
+ * Validates and adds defaults for missing states.
1788
+ *
1789
+ * @memberof Context
1790
+ *
1791
+ * @exception {RuntimeError} renderState.lineWidth is out of range.
1792
+ * @exception {DeveloperError} Invalid renderState.frontFace.
1793
+ * @exception {DeveloperError} Invalid renderState.cull.face.
1794
+ * @exception {DeveloperError} scissorTest.rectangle.width and scissorTest.rectangle.height must be greater than or equal to zero.
1795
+ * @exception {DeveloperError} renderState.depthRange.near can't be greater than renderState.depthRange.far.
1796
+ * @exception {DeveloperError} renderState.depthRange.near must be greater than or equal to zero.
1797
+ * @exception {DeveloperError} renderState.depthRange.far must be less than or equal to zero.
1798
+ * @exception {DeveloperError} Invalid renderState.depthTest.func.
1799
+ * @exception {DeveloperError} renderState.blending.color components must be greater than or equal to zero and less than or equal to one
1800
+ * @exception {DeveloperError} Invalid renderState.blending.equationRgb.
1801
+ * @exception {DeveloperError} Invalid renderState.blending.equationAlpha.
1802
+ * @exception {DeveloperError} Invalid renderState.blending.functionSourceRgb.
1803
+ * @exception {DeveloperError} Invalid renderState.blending.functionSourceAlpha.
1804
+ * @exception {DeveloperError} Invalid renderState.blending.functionDestinationRgb.
1805
+ * @exception {DeveloperError} Invalid renderState.blending.functionDestinationAlpha.
1806
+ * @exception {DeveloperError} Invalid renderState.stencilTest.frontFunction.
1807
+ * @exception {DeveloperError} Invalid renderState.stencilTest.backFunction.
1808
+ * @exception {DeveloperError} Invalid renderState.stencilTest.frontOperation.fail.
1809
+ * @exception {DeveloperError} Invalid renderState.stencilTest.frontOperation.zFail.
1810
+ * @exception {DeveloperError} Invalid renderState.stencilTest.frontOperation.zPass.
1811
+ * @exception {DeveloperError} Invalid renderState.stencilTest.backOperation.fail.
1812
+ * @exception {DeveloperError} Invalid renderState.stencilTest.backOperation.zFail.
1813
+ * @exception {DeveloperError} Invalid renderState.stencilTest.backOperation.zPass.
1814
+ * @exception {DeveloperError} renderState.viewport.width must be greater than or equal to zero.
1815
+ * @exception {DeveloperError} renderState.viewport.width must be less than or equal to the maximum viewport width.
1816
+ * @exception {DeveloperError} renderState.viewport.height must be greater than or equal to zero.
1817
+ * @exception {DeveloperError} renderState.viewport.height must be less than or equal to the maximum viewport height.
1818
+ */
1819
+ Context.prototype.createRenderState = function(renderState) {
1820
+ var rs = renderState || {};
1821
+ var cull = rs.cull || {};
1822
+ var polygonOffset = rs.polygonOffset || {};
1823
+ var scissorTest = rs.scissorTest || {};
1824
+ var scissorTestRectangle = scissorTest.rectangle || {};
1825
+ var depthRange = rs.depthRange || {};
1826
+ var depthTest = rs.depthTest || {};
1827
+ var colorMask = rs.colorMask || {};
1828
+ var blending = rs.blending || {};
1829
+ var blendingColor = blending.color || {};
1830
+ var stencilTest = rs.stencilTest || {};
1831
+ var stencilTestFrontOperation = stencilTest.frontOperation || {};
1832
+ var stencilTestBackOperation = stencilTest.backOperation || {};
1833
+ var sampleCoverage = rs.sampleCoverage || {};
1834
+ var viewport = rs.viewport;
1835
+
1836
+ var r = {
1837
+ frontFace : (typeof rs.frontFace === 'undefined') ? WindingOrder.COUNTER_CLOCKWISE : rs.frontFace,
1838
+ cull : {
1839
+ enabled : (typeof cull.enabled === 'undefined') ? false : cull.enabled,
1840
+ face : (typeof cull.face === 'undefined') ? CullFace.BACK : cull.face
1841
+ },
1842
+ lineWidth : (typeof rs.lineWidth === 'undefined') ? 1 : rs.lineWidth,
1843
+ polygonOffset : {
1844
+ enabled : (typeof polygonOffset.enabled === 'undefined') ? false : polygonOffset.enabled,
1845
+ factor : (typeof polygonOffset.factor === 'undefined') ? 0 : polygonOffset.factor,
1846
+ units : (typeof polygonOffset.units === 'undefined') ? 0 : polygonOffset.units
1847
+ },
1848
+ scissorTest : {
1849
+ enabled : (typeof scissorTest.enabled === 'undefined') ? false : scissorTest.enabled,
1850
+ rectangle : BoundingRectangle.clone(scissorTestRectangle)
1851
+ },
1852
+ depthRange : {
1853
+ near : (typeof depthRange.near === 'undefined') ? 0 : depthRange.near,
1854
+ far : (typeof depthRange.far === 'undefined') ? 1 : depthRange.far
1855
+ },
1856
+ depthTest : {
1857
+ enabled : (typeof depthTest.enabled === 'undefined') ? false : depthTest.enabled,
1858
+ func : (typeof depthTest.func === 'undefined') ? DepthFunction.LESS : depthTest.func // func, because function is a JavaScript keyword
1859
+ },
1860
+ colorMask : {
1861
+ red : (typeof colorMask.red === 'undefined') ? true : colorMask.red,
1862
+ green : (typeof colorMask.green === 'undefined') ? true : colorMask.green,
1863
+ blue : (typeof colorMask.blue === 'undefined') ? true : colorMask.blue,
1864
+ alpha : (typeof colorMask.alpha === 'undefined') ? true : colorMask.alpha
1865
+ },
1866
+ depthMask : (typeof rs.depthMask === 'undefined') ? true : rs.depthMask,
1867
+ stencilMask : (typeof rs.stencilMask === 'undefined') ? ~0 : rs.stencilMask,
1868
+ blending : {
1869
+ enabled : (typeof blending.enabled === 'undefined') ? false : blending.enabled,
1870
+ color : new Color(
1871
+ (typeof blendingColor.red === 'undefined') ? 0.0 : blendingColor.red,
1872
+ (typeof blendingColor.green === 'undefined') ? 0.0 : blendingColor.green,
1873
+ (typeof blendingColor.blue === 'undefined') ? 0.0 : blendingColor.blue,
1874
+ (typeof blendingColor.alpha === 'undefined') ? 0.0 : blendingColor.alpha
1875
+ ),
1876
+ equationRgb : (typeof blending.equationRgb === 'undefined') ? BlendEquation.ADD : blending.equationRgb,
1877
+ equationAlpha : (typeof blending.equationAlpha === 'undefined') ? BlendEquation.ADD : blending.equationAlpha,
1878
+ functionSourceRgb : (typeof blending.functionSourceRgb === 'undefined') ? BlendFunction.ONE : blending.functionSourceRgb,
1879
+ functionSourceAlpha : (typeof blending.functionSourceAlpha === 'undefined') ? BlendFunction.ONE : blending.functionSourceAlpha,
1880
+ functionDestinationRgb : (typeof blending.functionDestinationRgb === 'undefined') ? BlendFunction.ZERO : blending.functionDestinationRgb,
1881
+ functionDestinationAlpha : (typeof blending.functionDestinationAlpha === 'undefined') ? BlendFunction.ZERO : blending.functionDestinationAlpha
1882
+ },
1883
+ stencilTest : {
1884
+ enabled : (typeof stencilTest.enabled === 'undefined') ? false : stencilTest.enabled,
1885
+ frontFunction : (typeof stencilTest.frontFunction === 'undefined') ? StencilFunction.ALWAYS : stencilTest.frontFunction,
1886
+ backFunction : (typeof stencilTest.backFunction === 'undefined') ? StencilFunction.ALWAYS : stencilTest.backFunction,
1887
+ reference : (typeof stencilTest.reference === 'undefined') ? 0 : stencilTest.reference,
1888
+ mask : (typeof stencilTest.mask === 'undefined') ? ~0 : stencilTest.mask,
1889
+ frontOperation : {
1890
+ fail : (typeof stencilTestFrontOperation.fail === 'undefined') ? StencilOperation.KEEP : stencilTestFrontOperation.fail,
1891
+ zFail : (typeof stencilTestFrontOperation.zFail === 'undefined') ? StencilOperation.KEEP : stencilTestFrontOperation.zFail,
1892
+ zPass : (typeof stencilTestFrontOperation.zPass === 'undefined') ? StencilOperation.KEEP : stencilTestFrontOperation.zPass
1893
+ },
1894
+ backOperation : {
1895
+ fail : (typeof stencilTestBackOperation.fail === 'undefined') ? StencilOperation.KEEP : stencilTestBackOperation.fail,
1896
+ zFail : (typeof stencilTestBackOperation.zFail === 'undefined') ? StencilOperation.KEEP : stencilTestBackOperation.zFail,
1897
+ zPass : (typeof stencilTestBackOperation.zPass === 'undefined') ? StencilOperation.KEEP : stencilTestBackOperation.zPass
1898
+ }
1899
+ },
1900
+ // TODO: Also need point_size and point_size_enable for ColladaFX
1901
+ // TODO: Also need sample_alpha_to_coverage_enable for ColladaFX
1902
+ sampleCoverage : {
1903
+ enabled : (typeof sampleCoverage.enabled === 'undefined') ? false : sampleCoverage.enabled,
1904
+ value : (typeof sampleCoverage.value === 'undefined') ? 1.0 : sampleCoverage.value,
1905
+ invert : (typeof sampleCoverage.invert === 'undefined') ? false : sampleCoverage.invert
1906
+ },
1907
+ dither : (typeof rs.dither === 'undefined') ? true : rs.dither
1908
+ // viewport is set below because it is allowed to be undefined - meaning always the canvas size.
1909
+ };
1910
+
1911
+ // Validate
1912
+
1913
+ if (!WindingOrder.validate(r.frontFace)) {
1914
+ throw new DeveloperError('Invalid renderState.frontFace.');
1915
+ }
1916
+
1917
+ if (!CullFace.validate(r.cull.face)) {
1918
+ throw new DeveloperError('Invalid renderState.cull.face.');
1919
+ }
1920
+
1921
+ if ((r.lineWidth < this._aliasedLineWidthRange[0]) ||
1922
+ (r.lineWidth > this._aliasedLineWidthRange[1])) {
1923
+ throw new RuntimeError('renderState.lineWidth is out of range. Check getMinimumAliasedLineWidth() and getMaximumAliasedLineWidth().');
1924
+ }
1925
+
1926
+ if ((r.scissorTest.rectangle.width < 0) ||
1927
+ (r.scissorTest.rectangle.height < 0)) {
1928
+ throw new DeveloperError('renderState.scissorTest.rectangle.width and renderState.scissorTest.rectangle.height must be greater than or equal to zero.');
1929
+ }
1930
+
1931
+ if (r.depthRange.near > r.depthRange.far) {
1932
+ // WebGL specific - not an error in GL ES
1933
+ throw new DeveloperError('renderState.depthRange.near can not be greater than renderState.depthRange.far.');
1934
+ }
1935
+
1936
+ if (r.depthRange.near < 0) {
1937
+ // Would be clamped by GL
1938
+ throw new DeveloperError('renderState.depthRange.near must be greater than or equal to zero.');
1939
+ }
1940
+
1941
+ if (r.depthRange.far > 1) {
1942
+ // Would be clamped by GL
1943
+ throw new DeveloperError('renderState.depthRange.far must be less than or equal to one.');
1944
+ }
1945
+
1946
+
1947
+ if (!DepthFunction.validate(r.depthTest.func)) {
1948
+ throw new DeveloperError('Invalid renderState.depthTest.func.');
1949
+ }
1950
+
1951
+ if ((r.blending.color.red < 0.0) || (r.blending.color.red > 1.0) ||
1952
+ (r.blending.color.green < 0.0) || (r.blending.color.green > 1.0) ||
1953
+ (r.blending.color.blue < 0.0) || (r.blending.color.blue > 1.0) ||
1954
+ (r.blending.color.alpha < 0.0) || (r.blending.color.alpha > 1.0)) {
1955
+ // Would be clamped by GL
1956
+ throw new DeveloperError('renderState.blending.color components must be greater than or equal to zero and less than or equal to one.');
1957
+ }
1958
+
1959
+ if (!BlendEquation.validate(r.blending.equationRgb)) {
1960
+ throw new DeveloperError('Invalid renderState.blending.equationRgb.');
1961
+ }
1962
+
1963
+ if (!BlendEquation.validate(r.blending.equationAlpha)) {
1964
+ throw new DeveloperError('Invalid renderState.blending.equationAlpha.');
1965
+ }
1966
+
1967
+ if (!BlendFunction.validate(r.blending.functionSourceRgb)) {
1968
+ throw new DeveloperError('Invalid renderState.blending.functionSourceRgb.');
1969
+ }
1970
+
1971
+ if (!BlendFunction.validate(r.blending.functionSourceAlpha)) {
1972
+ throw new DeveloperError('Invalid renderState.blending.functionSourceAlpha.');
1973
+ }
1974
+
1975
+ if (!BlendFunction.validate(r.blending.functionDestinationRgb)) {
1976
+ throw new DeveloperError('Invalid renderState.blending.functionDestinationRgb.');
1977
+ }
1978
+
1979
+ if (!BlendFunction.validate(r.blending.functionDestinationAlpha)) {
1980
+ throw new DeveloperError('Invalid renderState.blending.functionDestinationAlpha.');
1981
+ }
1982
+
1983
+ if (!StencilFunction.validate(r.stencilTest.frontFunction)) {
1984
+ throw new DeveloperError('Invalid renderState.stencilTest.frontFunction.');
1985
+ }
1986
+
1987
+ if (!StencilFunction.validate(r.stencilTest.backFunction)) {
1988
+ throw new DeveloperError('Invalid renderState.stencilTest.backFunction.');
1989
+ }
1990
+
1991
+ if (!StencilOperation.validate(r.stencilTest.frontOperation.fail)) {
1992
+ throw new DeveloperError('Invalid renderState.stencilTest.frontOperation.fail.');
1993
+ }
1994
+
1995
+ if (!StencilOperation.validate(r.stencilTest.frontOperation.zFail)) {
1996
+ throw new DeveloperError('Invalid renderState.stencilTest.frontOperation.zFail.');
1997
+ }
1998
+
1999
+ if (!StencilOperation.validate(r.stencilTest.frontOperation.zPass)) {
2000
+ throw new DeveloperError('Invalid renderState.stencilTest.frontOperation.zPass.');
2001
+ }
2002
+
2003
+ if (!StencilOperation.validate(r.stencilTest.backOperation.fail)) {
2004
+ throw new DeveloperError('Invalid renderState.stencilTest.backOperation.fail.');
2005
+ }
2006
+
2007
+ if (!StencilOperation.validate(r.stencilTest.backOperation.zFail)) {
2008
+ throw new DeveloperError('Invalid renderState.stencilTest.backOperation.zFail.');
2009
+ }
2010
+
2011
+ if (!StencilOperation.validate(r.stencilTest.backOperation.zPass)) {
2012
+ throw new DeveloperError('Invalid renderState.stencilTest.backOperation.zPass.');
2013
+ }
2014
+
2015
+ if (typeof vieport !== 'undefined') {
2016
+ if (viewport.width < 0) {
2017
+ throw new DeveloperError('renderState.viewport.width must be greater than or equal to zero.');
2018
+ }
2019
+
2020
+ if (viewport.width > this.getMaximumViewportWidth()) {
2021
+ throw new RuntimeError('renderState.viewport.width must be less than or equal to the maximum viewport width (' + this.getMaximumViewportWidth().toString() + '). Check getMaximumViewportWidth().');
2022
+ }
2023
+
2024
+ if (viewport.height < 0) {
2025
+ throw new DeveloperError('renderState.viewport.height must be greater than or equal to zero.');
2026
+ }
2027
+
2028
+ if (viewport.height > this.getMaximumViewportHeight()) {
2029
+ throw new RuntimeError('renderState.viewport.height must be less than or equal to the maximum viewport height (' + this.getMaximumViewportHeight().toString() + '). Check getMaximumViewportHeight().');
2030
+ }
2031
+
2032
+ r.viewport = new BoundingRectangle(viewport.x, viewport.y,
2033
+ (typeof viewport.width === 'undefined') ? this._canvas.clientWidth : viewport.width,
2034
+ (typeof viewport.height === 'undefined') ? this._canvas.clientHeight : viewport.height);
2035
+ }
2036
+
2037
+ return r;
2038
+ };
2039
+
2040
+ /**
2041
+ * DOC_TBA
2042
+ *
2043
+ * @memberof Context
2044
+ *
2045
+ * @exception {DeveloperError} Invalid sampler.wrapS.
2046
+ * @exception {DeveloperError} Invalid sampler.wrapT.
2047
+ * @exception {DeveloperError} Invalid sampler.minificationFilter.
2048
+ * @exception {DeveloperError} Invalid sampler.magnificationFilter.
2049
+ *
2050
+ * @see Context#createTexture2D
2051
+ * @see Context#createCubeMap
2052
+ */
2053
+ Context.prototype.createSampler = function(sampler) {
2054
+ var s = {
2055
+ wrapS : sampler.wrapS || TextureWrap.CLAMP,
2056
+ wrapT : sampler.wrapT || TextureWrap.CLAMP,
2057
+ minificationFilter : sampler.minificationFilter || TextureMinificationFilter.LINEAR,
2058
+ magnificationFilter : sampler.magnificationFilter || TextureMagnificationFilter.LINEAR,
2059
+ maximumAnisotropy : (typeof sampler.maximumAnisotropy !== 'undefined') ? sampler.maximumAnisotropy : 1.0
2060
+ };
2061
+
2062
+ if (!TextureWrap.validate(s.wrapS)) {
2063
+ throw new DeveloperError('Invalid sampler.wrapS.');
2064
+ }
2065
+
2066
+ if (!TextureWrap.validate(s.wrapT)) {
2067
+ throw new DeveloperError('Invalid sampler.wrapT.');
2068
+ }
2069
+
2070
+ if (!TextureMinificationFilter.validate(s.minificationFilter)) {
2071
+ throw new DeveloperError('Invalid sampler.minificationFilter.');
2072
+ }
2073
+
2074
+ if (!TextureMagnificationFilter.validate(s.magnificationFilter)) {
2075
+ throw new DeveloperError('Invalid sampler.magnificationFilter.');
2076
+ }
2077
+
2078
+ if (s.maximumAnisotropy < 1.0) {
2079
+ throw new DeveloperError('sampler.maximumAnisotropy must be greater than or equal to one.');
2080
+ }
2081
+
2082
+ return s;
2083
+ };
2084
+
2085
+ /**
2086
+ * DOC_TBA.
2087
+ *
2088
+ * @memberof Context
2089
+ *
2090
+ * Validates and adds defaults for missing states.
2091
+ *
2092
+ * @exception {DeveloperError} clearState.scissorTest.rectangle.width and clearState.scissorTest.rectangle.height must be greater than or equal to zero.
2093
+ *
2094
+ * @see Context#clear
2095
+ */
2096
+ Context.prototype.createClearState = function(clearState) {
2097
+ var cs = clearState || {};
2098
+ var scissorTest = cs.scissorTest || {};
2099
+ var scissorTestRectangle = scissorTest.rectangle || {};
2100
+ var colorMask = cs.colorMask || {};
2101
+
2102
+ var color = cs.color;
2103
+ var depth = cs.depth;
2104
+ var stencil = cs.stencil;
2105
+
2106
+ // Clear everything if nothing is specified
2107
+ if ((typeof color === 'undefined') && (typeof depth === 'undefined') && (typeof stencil === 'undefined')) {
2108
+ color = this._defaultClearColor;
2109
+ depth = this._defaultClearDepth;
2110
+ stencil = this._defaultClearStencil;
2111
+ }
2112
+
2113
+ var c = {
2114
+ scissorTest : {
2115
+ enabled : (typeof scissorTest.enabled === 'undefined') ? false : scissorTest.enabled,
2116
+ rectangle : {
2117
+ x : (typeof scissorTestRectangle.x === 'undefined') ? 0 : scissorTestRectangle.x,
2118
+ y : (typeof scissorTestRectangle.y === 'undefined') ? 0 : scissorTestRectangle.y,
2119
+ width : (typeof scissorTestRectangle.width === 'undefined') ? 0 : scissorTestRectangle.width,
2120
+ height : (typeof scissorTestRectangle.height === 'undefined') ? 0 : scissorTestRectangle.height
2121
+ }
2122
+ },
2123
+ colorMask : {
2124
+ red : (typeof colorMask.red === 'undefined') ? true : colorMask.red,
2125
+ green : (typeof colorMask.green === 'undefined') ? true : colorMask.green,
2126
+ blue : (typeof colorMask.blue === 'undefined') ? true : colorMask.blue,
2127
+ alpha : (typeof colorMask.alpha === 'undefined') ? true : colorMask.alpha
2128
+ },
2129
+ depthMask : (typeof cs.depthMask === 'undefined') ? true : cs.depthMask,
2130
+ stencilMask : (typeof cs.stencilMask === 'undefined') ? ~0 : cs.stencilMask,
2131
+ dither : (typeof cs.dither === 'undefined') ? true : cs.dither,
2132
+
2133
+ framebuffer : cs.framebuffer,
2134
+
2135
+ color : (typeof color !== 'undefined') ? Color.clone(color) : undefined,
2136
+ depth : depth,
2137
+ stencil : stencil
2138
+ };
2139
+
2140
+ if ((c.scissorTest.rectangle.width < 0) || (c.scissorTest.rectangle.height < 0)) {
2141
+ throw new DeveloperError('clearState.scissorTest.rectangle.width and clearState.scissorTest.rectangle.height must be greater than or equal to zero.');
2142
+ }
2143
+
2144
+ return c;
2145
+ };
2146
+
2147
+ Context.prototype._validateFramebuffer = function(framebuffer) {
2148
+ if (this._validateFB) {
2149
+ var gl = this._gl;
2150
+ var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
2151
+
2152
+ if (status !== gl.FRAMEBUFFER_COMPLETE) {
2153
+ var message;
2154
+
2155
+ switch (status) {
2156
+ case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
2157
+ message = 'Framebuffer is not complete. Incomplete attachment: at least one attachment point with a renderbuffer or texture attached has its attached object no longer in existence or has an attached image with a width or height of zero, or the color attachment point has a non-color-renderable image attached, or the depth attachment point has a non-depth-renderable image attached, or the stencil attachment point has a non-stencil-renderable image attached. Color-renderable formats include GL_RGBA4, GL_RGB5_A1, and GL_RGB565. GL_DEPTH_COMPONENT16 is the only depth-renderable format. GL_STENCIL_INDEX8 is the only stencil-renderable format.';
2158
+ break;
2159
+ case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
2160
+ message = 'Framebuffer is not complete. Incomplete dimensions: not all attached images have the same width and height.';
2161
+ break;
2162
+ case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
2163
+ message = 'Framebuffer is not complete. Missing attachment: no images are attached to the framebuffer.';
2164
+ break;
2165
+ case gl.FRAMEBUFFER_UNSUPPORTED:
2166
+ message = 'Framebuffer is not complete. Unsupported: the combination of internal formats of the attached images violates an implementation-dependent set of restrictions.';
2167
+ break;
2168
+ }
2169
+
2170
+ throw new DeveloperError(message);
2171
+ }
2172
+ }
2173
+ };
2174
+
2175
+ /**
2176
+ * Executes the specified clear command.
2177
+ *
2178
+ * @memberof Context
2179
+ *
2180
+ * @param {ClearCommand} [clearCommand] The command with which to clear. If this parameter is undefined
2181
+ * or its clearState property is undefined, a default clear state is used.
2182
+ * @param {Framebuffer} [framebuffer] The framebuffer to clear if one is not specified by the command.
2183
+ *
2184
+ * @memberof Context
2185
+ *
2186
+ * @see Context#createClearState
2187
+ */
2188
+ Context.prototype.clear = function(clearCommand, framebuffer) {
2189
+ var clearState;
2190
+ if (typeof clearCommand !== 'undefined' && typeof clearCommand.clearState !== 'undefined') {
2191
+ clearState = clearCommand.clearState;
2192
+ } else {
2193
+ clearState = this.createClearState();
2194
+ }
2195
+
2196
+ var gl = this._gl;
2197
+ var bitmask = 0;
2198
+
2199
+ clearState = clearState || this.createClearState();
2200
+ var c = clearState.color;
2201
+ var d = clearState.depth;
2202
+ var s = clearState.stencil;
2203
+
2204
+ if (typeof c !== 'undefined') {
2205
+ if (!Color.equals(this._clearColor, c)) {
2206
+ Color.clone(c, this._clearColor);
2207
+ gl.clearColor(c.red, c.green, c.blue, c.alpha);
2208
+ }
2209
+ bitmask |= gl.COLOR_BUFFER_BIT;
2210
+ }
2211
+
2212
+ if (typeof d !== 'undefined') {
2213
+ if (d !== this._clearDepth) {
2214
+ this._clearDepth = d;
2215
+ gl.clearDepth(d);
2216
+ }
2217
+ bitmask |= gl.DEPTH_BUFFER_BIT;
2218
+ }
2219
+
2220
+ if (typeof s !== 'undefined') {
2221
+ if (s !== this._clearStencil) {
2222
+ this._clearStencil = s;
2223
+ gl.clearStencil(s);
2224
+ }
2225
+ bitmask |= gl.STENCIL_BUFFER_BIT;
2226
+ }
2227
+
2228
+ this._applyScissorTest(clearState.scissorTest);
2229
+ this._applyColorMask(clearState.colorMask);
2230
+ this._applyDepthMask(clearState.depthMask);
2231
+ this._applyStencilMask(clearState.stencilMask);
2232
+ this._applyDither(clearState.dither);
2233
+
2234
+ framebuffer = defaultValue(clearState.framebuffer, framebuffer);
2235
+
2236
+ if (framebuffer) {
2237
+ framebuffer._bind();
2238
+ this._validateFramebuffer(framebuffer);
2239
+ }
2240
+
2241
+ gl.clear(bitmask);
2242
+
2243
+ if (framebuffer) {
2244
+ framebuffer._unBind();
2245
+ }
2246
+ };
2247
+
2248
+ /**
2249
+ * Executes the specified draw command.
2250
+ *
2251
+ * @memberof Context
2252
+ *
2253
+ * @param {DrawCommand} drawCommand The command with which to draw.
2254
+ * @param {Framebuffer} [framebuffer] The framebuffer to which to draw if one is not specified by the command.
2255
+ *
2256
+ * @memberof Context
2257
+ *
2258
+ * @exception {DeveloperError} drawCommand is required.
2259
+ * @exception {DeveloperError} drawCommand.primitiveType is required and must be valid.
2260
+ * @exception {DeveloperError} drawCommand.shaderProgram is required.
2261
+ * @exception {DeveloperError} drawCommand.vertexArray is required.
2262
+ * @exception {DeveloperError} drawCommand.offset must be omitted or greater than or equal to zero.
2263
+ * @exception {DeveloperError} Program validation failed.
2264
+ * @exception {DeveloperError} Framebuffer is not complete.
2265
+ *
2266
+ * @example
2267
+ * // Example 1. Draw a single triangle specifying only required arguments
2268
+ * context.draw({
2269
+ * primitiveType : PrimitiveType.TRIANGLES,
2270
+ * shaderProgram : sp,
2271
+ * vertexArray : va,
2272
+ * });
2273
+ *
2274
+ * ////////////////////////////////////////////////////////////////////////////////
2275
+ *
2276
+ * // Example 2. Draw a single triangle specifying every argument
2277
+ * context.draw({
2278
+ * primitiveType : PrimitiveType.TRIANGLES,
2279
+ * offset : 0,
2280
+ * count : 3,
2281
+ * framebuffer : fb,
2282
+ * shaderProgram : sp,
2283
+ * vertexArray : va,
2284
+ * renderState : rs
2285
+ * });
2286
+ *
2287
+ * @see Context#createShaderProgram
2288
+ * @see Context#createVertexArray
2289
+ * @see Context#createFramebuffer
2290
+ * @see Context#createRenderState
2291
+ */
2292
+ Context.prototype.draw = function(drawCommand, framebuffer) {
2293
+ this.beginDraw(drawCommand, framebuffer);
2294
+ this.continueDraw(drawCommand);
2295
+ this.endDraw();
2296
+ };
2297
+
2298
+ /**
2299
+ * DOC_TBA
2300
+ *
2301
+ * @memberof Context
2302
+ */
2303
+ Context.prototype.beginDraw = function(command, framebuffer) {
2304
+ if (typeof command === 'undefined') {
2305
+ throw new DeveloperError('command is required.');
2306
+ }
2307
+
2308
+ if (typeof command.shaderProgram === 'undefined') {
2309
+ throw new DeveloperError('command.shaderProgram is required.');
2310
+ }
2311
+
2312
+ framebuffer = defaultValue(command.framebuffer, framebuffer);
2313
+ var sp = command.shaderProgram;
2314
+ var rs = command.renderState || this.createRenderState();
2315
+
2316
+ if (framebuffer && rs.depthTest) {
2317
+ if (rs.depthTest.enabled && !framebuffer.hasDepthAttachment()) {
2318
+ throw new DeveloperError('The depth test can not be enabled (command.renderState.depthTest.enabled) because the framebuffer (command.framebuffer) does not have a depth or depth-stencil renderbuffer.');
2319
+ }
2320
+ }
2321
+
2322
+ ///////////////////////////////////////////////////////////////////////
2323
+
2324
+ this._applyRenderState(rs);
2325
+ if (framebuffer) {
2326
+ framebuffer._bind();
2327
+ this._validateFramebuffer(framebuffer);
2328
+ }
2329
+ sp._bind();
2330
+
2331
+ this._currentFramebuffer = framebuffer;
2332
+ this._currentSp = sp;
2333
+ };
2334
+
2335
+ /**
2336
+ * DOC_TBA
2337
+ *
2338
+ * @memberof Context
2339
+ */
2340
+ Context.prototype.continueDraw = function(command) {
2341
+ var sp = this._currentSp;
2342
+ if (typeof sp === 'undefined') {
2343
+ throw new DeveloperError('beginDraw must be called before continueDraw.');
2344
+ }
2345
+
2346
+ if (typeof command === 'undefined') {
2347
+ throw new DeveloperError('command is required.');
2348
+ }
2349
+
2350
+ var primitiveType = command.primitiveType;
2351
+ if (!PrimitiveType.validate(primitiveType)) {
2352
+ throw new DeveloperError('command.primitiveType is required and must be valid.');
2353
+ }
2354
+
2355
+ if (typeof command.vertexArray === 'undefined') {
2356
+ throw new DeveloperError('command.vertexArray is required.');
2357
+ }
2358
+
2359
+ var va = command.vertexArray;
2360
+ var indexBuffer = va.getIndexBuffer();
2361
+
2362
+ var offset = command.offset;
2363
+ var count = command.count;
2364
+
2365
+ if (indexBuffer) {
2366
+ offset = (offset || 0) * indexBuffer.getBytesPerIndex(); // in bytes
2367
+ count = count || indexBuffer.getNumberOfIndices();
2368
+ } else {
2369
+ offset = offset || 0; // in vertices
2370
+ count = count || va._getNumberOfVertices();
2371
+ }
2372
+
2373
+ if (offset < 0) {
2374
+ throw new DeveloperError('command.offset must be omitted or greater than or equal to zero.');
2375
+ }
2376
+
2377
+ if (count > 0) {
2378
+ this._us.setModel(defaultValue(command.modelMatrix, Matrix4.IDENTITY));
2379
+ sp._setUniforms(command.uniformMap, this._us, this._validateSP);
2380
+
2381
+ va._bind();
2382
+
2383
+ if (indexBuffer) {
2384
+ this._gl.drawElements(primitiveType, count, indexBuffer.getIndexDatatype().value, offset);
2385
+ } else {
2386
+ this._gl.drawArrays(primitiveType, offset, count);
2387
+ }
2388
+
2389
+ va._unBind();
2390
+ }
2391
+ };
2392
+
2393
+ /**
2394
+ * DOC_TBA
2395
+ *
2396
+ * @memberof Context
2397
+ */
2398
+ Context.prototype.endDraw = function() {
2399
+ if (this._currentFramebuffer) {
2400
+ this._currentFramebuffer._unBind();
2401
+ this._currentFramebuffer = undefined;
2402
+ }
2403
+ this._currentSp._unBind();
2404
+ this._currentSp = undefined;
2405
+ };
2406
+
2407
+ /**
2408
+ * DOC_TBA
2409
+ *
2410
+ * @memberof Context
2411
+ *
2412
+ * @exception {DeveloperError} readState.width must be greater than zero.
2413
+ * @exception {DeveloperError} readState.height must be greater than zero.
2414
+ */
2415
+ Context.prototype.readPixels = function(readState) {
2416
+ readState = readState || {};
2417
+ var x = Math.max(readState.x || 0, 0);
2418
+ var y = Math.max(readState.y || 0, 0);
2419
+ var width = readState.width || this._canvas.clientWidth;
2420
+ var height = readState.height || this._canvas.clientHeight;
2421
+ var framebuffer = readState.framebuffer || null;
2422
+
2423
+ if (width <= 0) {
2424
+ throw new DeveloperError('readState.width must be greater than zero.');
2425
+ }
2426
+
2427
+ if (height <= 0) {
2428
+ throw new DeveloperError('readState.height must be greater than zero.');
2429
+ }
2430
+
2431
+ var pixels = new Uint8Array(4 * width * height);
2432
+
2433
+ if (framebuffer) {
2434
+ framebuffer._bind();
2435
+ this._validateFramebuffer(framebuffer);
2436
+ }
2437
+
2438
+ var gl = this._gl;
2439
+ gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
2440
+
2441
+ if (framebuffer) {
2442
+ framebuffer._unBind();
2443
+ }
2444
+
2445
+ return pixels;
2446
+ };
2447
+
2448
+ //////////////////////////////////////////////////////////////////////////////////////////
2449
+
2450
+ Context.prototype._interleaveAttributes = function(attributes) {
2451
+ function computeNumberOfVertices(attribute) {
2452
+ return attribute.values.length / attribute.componentsPerAttribute;
2453
+ }
2454
+
2455
+ function computeAttributeSizeInBytes(attribute) {
2456
+ return attribute.componentDatatype.sizeInBytes * attribute.componentsPerAttribute;
2457
+ }
2458
+
2459
+ var j;
2460
+ var name;
2461
+ var attribute;
2462
+
2463
+ // Extract attribute names.
2464
+ var names = [];
2465
+ for (name in attributes) {
2466
+ // Attribute needs to have per-vertex values; not a constant value for all vertices.
2467
+ if (attributes.hasOwnProperty(name) && attributes[name].values) {
2468
+ names.push(name);
2469
+ }
2470
+ }
2471
+
2472
+ // Validation. Compute number of vertices.
2473
+ var numberOfVertices;
2474
+ var namesLength = names.length;
2475
+
2476
+ if (namesLength > 0) {
2477
+ numberOfVertices = computeNumberOfVertices(attributes[names[0]]);
2478
+
2479
+ for (j = 1; j < namesLength; ++j) {
2480
+ var currentNumberOfVertices = computeNumberOfVertices(attributes[names[j]]);
2481
+
2482
+ if (currentNumberOfVertices !== numberOfVertices) {
2483
+ throw new RuntimeError(
2484
+ 'Each attribute list must have the same number of vertices. ' +
2485
+ 'Attribute ' + names[j] + ' has a different number of vertices ' +
2486
+ '(' + currentNumberOfVertices.toString() + ')' +
2487
+ ' than attribute ' + names[0] +
2488
+ ' (' + numberOfVertices.toString() + ').');
2489
+ }
2490
+ }
2491
+ }
2492
+
2493
+ // Sort attributes by the size of their components. From left to right, a vertex stores floats, shorts, and then bytes.
2494
+ names.sort(function(left, right) {
2495
+ return attributes[right].componentDatatype.sizeInBytes - attributes[left].componentDatatype.sizeInBytes;
2496
+ });
2497
+
2498
+ // Compute sizes and strides.
2499
+ var vertexSizeInBytes = 0;
2500
+ var offsetsInBytes = {};
2501
+
2502
+ for (j = 0; j < namesLength; ++j) {
2503
+ name = names[j];
2504
+ attribute = attributes[name];
2505
+
2506
+ offsetsInBytes[name] = vertexSizeInBytes;
2507
+ vertexSizeInBytes += computeAttributeSizeInBytes(attribute);
2508
+ }
2509
+
2510
+ if (vertexSizeInBytes > 0) {
2511
+ // Pad each vertex to be a multiple of the largest component datatype so each
2512
+ // attribute can be addressed using typed arrays.
2513
+ var maxComponentSizeInBytes = attributes[names[0]].componentDatatype.sizeInBytes; // Sorted large to small
2514
+ var remainder = vertexSizeInBytes % maxComponentSizeInBytes;
2515
+ if (remainder !== 0) {
2516
+ vertexSizeInBytes += (maxComponentSizeInBytes - remainder);
2517
+ }
2518
+
2519
+ // Total vertex buffer size in bytes, including per-vertex padding.
2520
+ var vertexBufferSizeInBytes = numberOfVertices * vertexSizeInBytes;
2521
+
2522
+ // Create array for interleaved vertices. Each attribute has a different view (pointer) into the array.
2523
+ var buffer = new ArrayBuffer(vertexBufferSizeInBytes);
2524
+ var views = {};
2525
+
2526
+ for (j = 0; j < namesLength; ++j) {
2527
+ name = names[j];
2528
+ var sizeInBytes = attributes[name].componentDatatype.sizeInBytes;
2529
+
2530
+ views[name] = {
2531
+ pointer : attributes[name].componentDatatype.toTypedArray(buffer),
2532
+ index : offsetsInBytes[name] / sizeInBytes, // Offset in ComponentType
2533
+ strideInComponentType : vertexSizeInBytes / sizeInBytes
2534
+ };
2535
+ }
2536
+
2537
+ // Copy attributes into one interleaved array.
2538
+ // PERFORMANCE_IDEA: Can we optimize these loops?
2539
+ for (j = 0; j < numberOfVertices; ++j) {
2540
+ for ( var n = 0; n < namesLength; ++n) {
2541
+ name = names[n];
2542
+ attribute = attributes[name];
2543
+ var values = attribute.values;
2544
+ var view = views[name];
2545
+ var pointer = view.pointer;
2546
+
2547
+ var numberOfComponents = attribute.componentsPerAttribute;
2548
+ for ( var k = 0; k < numberOfComponents; ++k) {
2549
+ pointer[view.index + k] = values[(j * numberOfComponents) + k];
2550
+ }
2551
+
2552
+ view.index += view.strideInComponentType;
2553
+ }
2554
+ }
2555
+
2556
+ return {
2557
+ buffer : buffer,
2558
+ offsetsInBytes : offsetsInBytes,
2559
+ vertexSizeInBytes : vertexSizeInBytes
2560
+ };
2561
+ }
2562
+
2563
+ // No attributes to interleave.
2564
+ return undefined;
2565
+ };
2566
+
2567
+ Context.prototype._createVertexArrayAttributes = function(creationArguments) {
2568
+ var ca = creationArguments || {};
2569
+ var mesh = ca.mesh || {};
2570
+ var attributeIndices = ca.attributeIndices || {};
2571
+ var bufferUsage = ca.bufferUsage || BufferUsage.DYNAMIC_DRAW;
2572
+ var interleave = ca.vertexLayout && (ca.vertexLayout === VertexLayout.INTERLEAVED);
2573
+
2574
+ var name;
2575
+ var attribute;
2576
+ var vaAttributes = [];
2577
+ var attributes = mesh.attributes;
2578
+
2579
+ if (interleave) {
2580
+ // Use a single vertex buffer with interleaved vertices.
2581
+ var interleavedAttributes = this._interleaveAttributes(attributes);
2582
+ if (interleavedAttributes) {
2583
+ var vertexBuffer = this.createVertexBuffer(interleavedAttributes.buffer, bufferUsage);
2584
+ var offsetsInBytes = interleavedAttributes.offsetsInBytes;
2585
+ var strideInBytes = interleavedAttributes.vertexSizeInBytes;
2586
+
2587
+ for (name in attributes) {
2588
+ if (attributes.hasOwnProperty(name)) {
2589
+ attribute = attributes[name];
2590
+
2591
+ if (attribute.values) {
2592
+ // Common case: per-vertex attributes
2593
+ vaAttributes.push({
2594
+ index : attributeIndices[name],
2595
+ vertexBuffer : vertexBuffer,
2596
+ componentDatatype : attribute.componentDatatype,
2597
+ componentsPerAttribute : attribute.componentsPerAttribute,
2598
+ normalize : attribute.normalize,
2599
+ offsetInBytes : offsetsInBytes[name],
2600
+ strideInBytes : strideInBytes
2601
+ });
2602
+ } else {
2603
+ // Constant attribute for all vertices
2604
+ vaAttributes.push({
2605
+ index : attributeIndices[name],
2606
+ value : attribute.value,
2607
+ componentDatatype : attribute.componentDatatype,
2608
+ normalize : attribute.normalize
2609
+ });
2610
+ }
2611
+ }
2612
+ }
2613
+ }
2614
+ } else {
2615
+ // One vertex buffer per attribute.
2616
+ for (name in attributes) {
2617
+ if (attributes.hasOwnProperty(name)) {
2618
+ attribute = attributes[name];
2619
+ vaAttributes.push({
2620
+ index : attributeIndices[name],
2621
+ vertexBuffer : attribute.values ? this.createVertexBuffer(attribute.componentDatatype.toTypedArray(attribute.values), bufferUsage) : undefined,
2622
+ value : attribute.value ? attribute.value : undefined,
2623
+ componentDatatype : attribute.componentDatatype,
2624
+ componentsPerAttribute : attribute.componentsPerAttribute,
2625
+ normalize : attribute.normalize
2626
+ });
2627
+ }
2628
+ }
2629
+ }
2630
+
2631
+ return this.createVertexArray(vaAttributes);
2632
+ };
2633
+
2634
+ /**
2635
+ * Creates a vertex array from a mesh. A mesh contains vertex attributes and optional index data
2636
+ * in system memory, whereas a vertex array contains vertex buffers and an optional index buffer in WebGL
2637
+ * memory for use with rendering.
2638
+ * <br /><br />
2639
+ * The <code>mesh</code> argument should use the standard layout like the mesh returned by {@link BoxTessellator}.
2640
+ * <br /><br />
2641
+ * <code>creationArguments</code> can have four properties:
2642
+ * <ul>
2643
+ * <li><code>mesh</code>: The source mesh containing data used to create the vertex array.</li>
2644
+ * <li><code>attributeIndices</code>: An object that maps mesh attribute names to vertex shader attribute indices.</li>
2645
+ * <li><code>bufferUsage</code>: The expected usage pattern of the vertex array's buffers. On some WebGL implementations, this can significantly affect performance. See {@link BufferUsage}. Default: <code>BufferUsage.DYNAMIC_DRAW</code>.</li>
2646
+ * <li><code>vertexLayout</code>: Determines if all attributes are interleaved in a single vertex buffer or if each attribute is stored in a separate vertex buffer. Default: <code>VertexLayout.SEPARATE</code>.</li>
2647
+ * </ul>
2648
+ * <br />
2649
+ * If <code>creationArguments</code> is not specified or the <code>mesh</code> contains no data, the returned vertex array is empty.
2650
+ *
2651
+ * @memberof Context
2652
+ *
2653
+ * @param {Object} [creationArguments=undefined] An object defining the mesh, attribute indices, buffer usage, and vertex layout used to create the vertex array.
2654
+ *
2655
+ * @exception {RuntimeError} Each attribute list must have the same number of vertices.
2656
+ * @exception {DeveloperError} The mesh must have zero or one index lists.
2657
+ * @exception {DeveloperError} Index n is used by more than one attribute.
2658
+ *
2659
+ * @see Context#createVertexArray
2660
+ * @see Context#createVertexBuffer
2661
+ * @see Context#createIndexBuffer
2662
+ * @see MeshFilters.createAttributeIndices
2663
+ * @see ShaderProgram
2664
+ * @see BoxTessellator
2665
+ *
2666
+ * @example
2667
+ * // Example 1. Creates a vertex array for rendering a box. The default dynamic draw
2668
+ * // usage is used for the created vertex and index buffer. The attributes are not
2669
+ * // interleaved by default.
2670
+ * var mesh = BoxTessellator.compute();
2671
+ * var va = context.createVertexArrayFromMesh({
2672
+ * mesh : mesh,
2673
+ * attributeIndices : MeshFilters.createAttributeIndices(mesh),
2674
+ * });
2675
+ *
2676
+ * ////////////////////////////////////////////////////////////////////////////////
2677
+ *
2678
+ * // Example 2. Creates a vertex array with interleaved attributes in a
2679
+ * // single vertex buffer. The vertex and index buffer have static draw usage.
2680
+ * var va = context.createVertexArrayFromMesh({
2681
+ * mesh : mesh,
2682
+ * attributeIndices : MeshFilters.createAttributeIndices(mesh),
2683
+ * bufferUsage : BufferUsage.STATIC_DRAW,
2684
+ * vertexLayout : VertexLayout.INTERLEAVED
2685
+ * });
2686
+ *
2687
+ * ////////////////////////////////////////////////////////////////////////////////
2688
+ *
2689
+ * // Example 3. When the caller destroys the vertex array, it also destroys the
2690
+ * // attached vertex buffer(s) and index buffer.
2691
+ * va = va.destroy();
2692
+ */
2693
+ Context.prototype.createVertexArrayFromMesh = function(creationArguments) {
2694
+ var ca = creationArguments || {};
2695
+ var mesh = ca.mesh || {};
2696
+ var bufferUsage = ca.bufferUsage || BufferUsage.DYNAMIC_DRAW;
2697
+ var indexLists;
2698
+
2699
+ if (mesh.indexLists) {
2700
+ indexLists = mesh.indexLists;
2701
+ if (indexLists.length !== 1) {
2702
+ throw new DeveloperError('The mesh must have zero or one index lists. This mesh has ' + indexLists.length.toString() + ' index lists.');
2703
+ }
2704
+ }
2705
+
2706
+ var va = this._createVertexArrayAttributes(creationArguments);
2707
+
2708
+ if (indexLists) {
2709
+ va.setIndexBuffer(this.createIndexBuffer(new Uint16Array(indexLists[0].values), bufferUsage, IndexDatatype.UNSIGNED_SHORT));
2710
+ }
2711
+
2712
+ return va;
2713
+ };
2714
+
2715
+ /**
2716
+ * DOC_TBA
2717
+ *
2718
+ * @memberof Context
2719
+ *
2720
+ * @see Context#pick
2721
+ */
2722
+ Context.prototype.createPickFramebuffer = function() {
2723
+ return new PickFramebuffer(this);
2724
+ };
2725
+
2726
+ /**
2727
+ * DOC_TBA
2728
+ *
2729
+ * @memberof Context
2730
+ *
2731
+ * @see Context#createPickId
2732
+ */
2733
+ Context.prototype.getObjectByPickId = function(pickId) {
2734
+ return undefined;
2735
+ };
2736
+
2737
+ /**
2738
+ * DOC_TBA
2739
+ *
2740
+ * @memberof Context
2741
+ *
2742
+ * @see Context#getObjectByPickId
2743
+ */
2744
+ Context.prototype.createPickId = function(object) {
2745
+ var objects = {};
2746
+ var nextRgb = new Color(0, 0, 0, 0);
2747
+
2748
+ function rgbToObjectIndex(unnormalizedRgb) {
2749
+ // TODO: Use alpha?
2750
+ var index = 'r' + unnormalizedRgb.red + 'g' + unnormalizedRgb.green + 'b' + unnormalizedRgb.blue;
2751
+ return index;
2752
+ }
2753
+
2754
+ function _createPickId(object) {
2755
+ // TODO: Use alpha?
2756
+ if (++nextRgb.blue === 256) {
2757
+ nextRgb.blue = 0;
2758
+
2759
+ if (++nextRgb.green === 256) {
2760
+ nextRgb.green = 0;
2761
+
2762
+ if (++nextRgb.red === 256) {
2763
+ throw new RuntimeError('Out of unique Rgb colors.');
2764
+ }
2765
+ }
2766
+ }
2767
+
2768
+ var pickId = {
2769
+ unnormalizedRgb : new Color(nextRgb.red, nextRgb.green, nextRgb.blue, 1.0),
2770
+ normalizedRgba : Color.fromBytes(nextRgb.red, nextRgb.green, nextRgb.blue, 255.0),
2771
+ destroy : function() {
2772
+ // TODO: Remove from objects
2773
+ return null;
2774
+ }
2775
+ };
2776
+
2777
+ objects[rgbToObjectIndex(pickId.unnormalizedRgb)] = object;
2778
+
2779
+ return pickId;
2780
+ }
2781
+
2782
+ function _getObjectByPickId(unnormalizedRgb) {
2783
+ return objects[rgbToObjectIndex(unnormalizedRgb)];
2784
+ }
2785
+
2786
+ this.createPickId = _createPickId;
2787
+ this.getObjectByPickId = _getObjectByPickId;
2788
+
2789
+ return _createPickId(object);
2790
+ };
2791
+
2792
+ Context.prototype.isDestroyed = function() {
2793
+ return false;
2794
+ };
2795
+
2796
+ Context.prototype.destroy = function() {
2797
+ this._shaderCache = this._shaderCache.destroy();
2798
+ this._defaultTexture = this._defaultTexture && this._defaultTexture.destroy();
2799
+ this._defaultCubeMap = this._defaultCubeMap && this._defaultCubeMap.destroy();
2800
+
2801
+ return destroyObject(this);
2802
+ };
2803
+
2804
+ return Context;
2805
+ });