cesium 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
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,77 @@
1
+ /*global define*/
2
+ define(['../Core/Enumeration'], function(Enumeration) {
3
+ "use strict";
4
+
5
+ /**
6
+ * DOC_TBA
7
+ *
8
+ * @exports RenderbufferFormat
9
+ */
10
+ var RenderbufferFormat = {
11
+ /**
12
+ * DOC_TBA
13
+ *
14
+ * @constant
15
+ * @type {Enumeration}
16
+ */
17
+ RGBA4 : new Enumeration(0x8056, 'RGBA4'),
18
+
19
+ /**
20
+ * DOC_TBA
21
+ *
22
+ * @constant
23
+ * @type {Enumeration}
24
+ */
25
+ RGB5_A1 : new Enumeration(0x8057, 'RGB5_A1'),
26
+
27
+ /**
28
+ * DOC_TBA
29
+ *
30
+ * @constant
31
+ * @type {Enumeration}
32
+ */
33
+ RGB565 : new Enumeration(0x8D62, 'RGB565'),
34
+
35
+ /**
36
+ * DOC_TBA
37
+ *
38
+ * @constant
39
+ * @type {Enumeration}
40
+ */
41
+ DEPTH_COMPONENT16 : new Enumeration(0x81A5, 'DEPTH_COMPONENT16'),
42
+
43
+ /**
44
+ * DOC_TBA
45
+ *
46
+ * @constant
47
+ * @type {Enumeration}
48
+ */
49
+ STENCIL_INDEX8 : new Enumeration(0x8D48, 'STENCIL_INDEX8'),
50
+
51
+ /**
52
+ * DOC_TBA
53
+ *
54
+ * @constant
55
+ * @type {Enumeration}
56
+ */
57
+ DEPTH_STENCIL : new Enumeration(0x84F9, 'DEPTH_STENCIL'),
58
+
59
+ /**
60
+ * DOC_TBA
61
+ *
62
+ * @param renderbufferFormat
63
+ *
64
+ * @returns {Boolean}
65
+ */
66
+ validate : function(renderbufferFormat) {
67
+ return ((renderbufferFormat === RenderbufferFormat.RGBA4) ||
68
+ (renderbufferFormat === RenderbufferFormat.RGB5_A1) ||
69
+ (renderbufferFormat === RenderbufferFormat.RGB565) ||
70
+ (renderbufferFormat === RenderbufferFormat.DEPTH_COMPONENT16) ||
71
+ (renderbufferFormat === RenderbufferFormat.STENCIL_INDEX8) ||
72
+ (renderbufferFormat === RenderbufferFormat.DEPTH_STENCIL));
73
+ }
74
+ };
75
+
76
+ return RenderbufferFormat;
77
+ });
@@ -0,0 +1,8 @@
1
+ var profile = {
2
+ resourceTags : {
3
+ amd : function(filename, mid) {
4
+ "use strict";
5
+ return (/\.js$/).test(filename);
6
+ }
7
+ }
8
+ };
@@ -0,0 +1,121 @@
1
+ /*global define*/
2
+ define([
3
+ '../Core/destroyObject'
4
+ ], function(
5
+ destroyObject) {
6
+ "use strict";
7
+
8
+ /**
9
+ * DOC_TBA
10
+ *
11
+ * @alias ShaderCache
12
+ *
13
+ * @internalConstructor
14
+ *
15
+ * @see Context#getShaderCache
16
+ */
17
+ var ShaderCache = function(context) {
18
+ this._context = context;
19
+ this._shaders = {};
20
+ this._shadersToRelease = {};
21
+ };
22
+
23
+ /**
24
+ * DOC_TBA
25
+ *
26
+ * @memberof ShaderCache
27
+ *
28
+ * @returns {ShaderProgram} DOC_TBA.
29
+ */
30
+ ShaderCache.prototype.getShaderProgram = function(vertexShaderSource, fragmentShaderSource, attributeLocations) {
31
+ // TODO: compare attributeLocations!
32
+ var keyword = vertexShaderSource + fragmentShaderSource;
33
+ var cachedShader;
34
+
35
+ if (this._shaders[keyword]) {
36
+ cachedShader = this._shaders[keyword];
37
+ } else {
38
+ var sp = this._context.createShaderProgram(vertexShaderSource, fragmentShaderSource, attributeLocations);
39
+
40
+ cachedShader = {
41
+ cache : this,
42
+ shaderProgram : sp,
43
+ keyword : keyword,
44
+ count : 0
45
+ };
46
+
47
+ // A shader can't be in more than one cache.
48
+ sp._cachedShader = cachedShader;
49
+ this._shaders[keyword] = cachedShader;
50
+ }
51
+
52
+ ++cachedShader.count;
53
+ return cachedShader.shaderProgram;
54
+ };
55
+
56
+ /**
57
+ * DOC_TBA
58
+ * @memberof ShaderCache
59
+ */
60
+ ShaderCache.prototype.destroyReleasedShaderPrograms = function() {
61
+ var shadersToRelease = this._shadersToRelease;
62
+
63
+ for ( var keyword in shadersToRelease) {
64
+ if (shadersToRelease.hasOwnProperty(keyword)) {
65
+ // Check the count again here because the shader may have been requested
66
+ // after it was released, in which case, we are avoiding thrashing the cache.
67
+ var cachedShader = shadersToRelease[keyword];
68
+ if (cachedShader.count === 0) {
69
+ delete this._shaders[cachedShader.keyword];
70
+ cachedShader.shaderProgram.destroy();
71
+ }
72
+ }
73
+ }
74
+
75
+ this._shadersToRelease = {};
76
+ };
77
+
78
+ /**
79
+ * DOC_TBA
80
+ *
81
+ * @memberof ShaderCache
82
+ *
83
+ * @parameter {ShaderProgram} shaderProgram DOC_TBA.
84
+ */
85
+ ShaderCache.prototype.releaseShaderProgram = function(shaderProgram) {
86
+ if (shaderProgram) {
87
+ var cachedShader = shaderProgram._cachedShader;
88
+ if (cachedShader && (--cachedShader.count === 0)) {
89
+ this._shadersToRelease[cachedShader.keyword] = cachedShader;
90
+ }
91
+ }
92
+
93
+ return null;
94
+ };
95
+
96
+ /**
97
+ * DOC_TBA
98
+ * @memberof ShaderCache
99
+ */
100
+ ShaderCache.prototype.isDestroyed = function() {
101
+ return false;
102
+ };
103
+
104
+ /**
105
+ * DOC_TBA
106
+ * @memberof ShaderCache
107
+ */
108
+ ShaderCache.prototype.destroy = function() {
109
+ var shaders = this._shaders;
110
+
111
+ for ( var keyword in shaders) {
112
+ if (shaders.hasOwnProperty(keyword)) {
113
+ shaders[keyword].shaderProgram.destroy();
114
+ }
115
+ }
116
+
117
+ return destroyObject(this);
118
+ };
119
+
120
+ return ShaderCache;
121
+ });
@@ -0,0 +1,2402 @@
1
+ /*global define*/
2
+ define([
3
+ '../Core/DeveloperError',
4
+ '../Core/RuntimeError',
5
+ '../Core/destroyObject',
6
+ '../Core/Math',
7
+ '../Core/Matrix2',
8
+ '../Core/Matrix3',
9
+ '../Core/Matrix4',
10
+ './UniformDatatype',
11
+ '../Shaders/BuiltinFunctions'
12
+ ], function(
13
+ DeveloperError,
14
+ RuntimeError,
15
+ destroyObject,
16
+ CesiumMath,
17
+ Matrix2,
18
+ Matrix3,
19
+ Matrix4,
20
+ UniformDatatype,
21
+ ShadersBuiltinFunctions) {
22
+ "use strict";
23
+ /*global console*/
24
+
25
+ var allAutomaticUniforms = {
26
+ /**
27
+ * An automatic GLSL uniform containing the viewport's <code>x</code>, <code>y</code>, <code>width</code>,
28
+ * and <code>height</code> properties in an <code>vec4</code>'s <code>x</code>, <code>y</code>, <code>z</code>,
29
+ * and <code>w</code> components, respectively.
30
+ * <br /><br />
31
+ * Like all automatic uniforms, <code>czm_viewport</code> does not need to be explicitly declared.
32
+ * However, it can be explicitly declared when a shader is also used by other applications such
33
+ * as a third-party authoring tool.
34
+ *
35
+ * @alias czm_viewport
36
+ * @glslUniform
37
+ *
38
+ * @see Context#getViewport
39
+ *
40
+ * @example
41
+ * // GLSL declaration
42
+ * uniform vec4 czm_viewport;
43
+ *
44
+ * // Scale the window coordinate components to [0, 1] by dividing
45
+ * // by the viewport's width and height.
46
+ * vec2 v = gl_FragCoord.xy / czm_viewport.zw;
47
+ */
48
+ czm_viewport : {
49
+ getSize : function() {
50
+ return 1;
51
+ },
52
+
53
+ getDatatype : function() {
54
+ return UniformDatatype.FLOAT_VECTOR4;
55
+ },
56
+
57
+ getValue : function(uniformState) {
58
+ var v = uniformState.getViewport();
59
+ return {
60
+ x : v.x,
61
+ y : v.y,
62
+ z : v.width,
63
+ w : v.height
64
+ };
65
+ }
66
+ },
67
+
68
+ /**
69
+ * An automatic GLSL uniform representing a 4x4 orthographic projection matrix that
70
+ * transforms window coordinates to clip coordinates. Clip coordinates is the
71
+ * coordinate system for a vertex shader's <code>gl_Position</code> output.
72
+ * <br /><br />
73
+ * This transform is useful when a vertex shader inputs or manipulates window coordinates
74
+ * as done by {@link BillboardCollection}.
75
+ * <br /><br />
76
+ * Do not confuse {@link czm_viewportTransformation} with <code>czm_viewportOrthographic</code>.
77
+ * The former transforms from normalized device coordinates to window coordinates; the later transforms
78
+ * from window coordinates to clip coordinates, and is often used to assign to <code>gl_Position</code>.
79
+ * <br /><br />
80
+ * Like all automatic uniforms, <code>czm_viewportOrthographic</code> does not need to be explicitly declared.
81
+ * However, it can be explicitly declared when a shader is also used by other applications such
82
+ * as a third-party authoring tool.
83
+ *
84
+ * @alias czm_viewportOrthographic
85
+ * @glslUniform
86
+ *
87
+ * @see UniformState#getViewportOrthographic
88
+ * @see czm_viewport
89
+ * @see czm_viewportTransformation
90
+ * @see BillboardCollection
91
+ *
92
+ * @example
93
+ * // GLSL declaration
94
+ * uniform mat4 czm_viewportOrthographic;
95
+ *
96
+ * // Example
97
+ * gl_Position = czm_viewportOrthographic * vec4(windowPosition, 0.0, 1.0);
98
+ */
99
+ czm_viewportOrthographic : {
100
+ getSize : function() {
101
+ return 1;
102
+ },
103
+
104
+ getDatatype : function() {
105
+ return UniformDatatype.FLOAT_MATRIX4;
106
+ },
107
+
108
+ getValue : function(uniformState) {
109
+ return uniformState.getViewportOrthographic();
110
+ }
111
+ },
112
+
113
+ /**
114
+ * An automatic GLSL uniform representing a 4x4 transformation matrix that
115
+ * transforms normalized device coordinates to window coordinates. The context's
116
+ * full viewport is used, and the depth range is assumed to be <code>near = 0</code>
117
+ * and <code>far = 1</code>.
118
+ * <br /><br />
119
+ * This transform is useful when there is a need to manipulate window coordinates
120
+ * in a vertex shader as done by {@link BillboardCollection}. In many cases,
121
+ * this matrix will not be used directly; instead, {@link czm_modelToWindowCoordinates}
122
+ * will be used to transform directly from model to window coordinates.
123
+ * <br /><br />
124
+ * Do not confuse <code>czm_viewportTransformation</code> with {@link czm_viewportOrthographic}.
125
+ * The former transforms from normalized device coordinates to window coordinates; the later transforms
126
+ * from window coordinates to clip coordinates, and is often used to assign to <code>gl_Position</code>.
127
+ * <br /><br />
128
+ * Like all automatic uniforms, <code>czm_viewportTransformation</code> does not need to be explicitly declared.
129
+ * However, it can be explicitly declared when a shader is also used by other applications such
130
+ * as a third-party authoring tool.
131
+ *
132
+ * @alias czm_viewportTransformation
133
+ * @glslUniform
134
+ *
135
+ * @see UniformState#getViewportTransformation
136
+ * @see czm_viewport
137
+ * @see czm_viewportOrthographic
138
+ * @see czm_modelToWindowCoordinates
139
+ * @see BillboardCollection
140
+ *
141
+ * @example
142
+ * // GLSL declaration
143
+ * uniform mat4 czm_viewportTransformation;
144
+ *
145
+ * // Use czm_viewportTransformation as part of the
146
+ * // transform from model to window coordinates.
147
+ * vec4 q = czm_modelViewProjection * positionMC; // model to clip coordinates
148
+ * q.xyz /= q.w; // clip to normalized device coordinates (ndc)
149
+ * q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // ndc to window coordinates
150
+ */
151
+ czm_viewportTransformation : {
152
+ getSize : function() {
153
+ return 1;
154
+ },
155
+
156
+ getDatatype : function() {
157
+ return UniformDatatype.FLOAT_MATRIX4;
158
+ },
159
+
160
+ getValue : function(uniformState) {
161
+ return uniformState.getViewportTransformation();
162
+ }
163
+ },
164
+
165
+ /**
166
+ * An automatic GLSL uniform representing a 4x4 model transformation matrix that
167
+ * transforms model coordinates to world coordinates.
168
+ * <br /><br />
169
+ * Like all automatic uniforms, <code>czm_model</code> does not need to be explicitly declared.
170
+ * However, it can be explicitly declared when a shader is also used by other applications such
171
+ * as a third-party authoring tool.
172
+ *
173
+ * @alias czm_model
174
+ * @glslUniform
175
+ *
176
+ * @see UniformState#getModel
177
+ * @see czm_inverseModel
178
+ * @see czm_modelView
179
+ * @see czm_modelViewProjection
180
+ *
181
+ * @example
182
+ * // GLSL declaration
183
+ * uniform mat4 czm_model;
184
+ *
185
+ * // Example
186
+ * vec4 worldPosition = czm_model * modelPosition;
187
+ */
188
+ czm_model : {
189
+ getSize : function() {
190
+ return 1;
191
+ },
192
+
193
+ getDatatype : function() {
194
+ return UniformDatatype.FLOAT_MATRIX4;
195
+ },
196
+
197
+ getValue : function(uniformState) {
198
+ return uniformState.getModel();
199
+ }
200
+ },
201
+
202
+ /**
203
+ * An automatic GLSL uniform representing a 4x4 model transformation matrix that
204
+ * transforms world coordinates to model coordinates.
205
+ * <br /><br />
206
+ * Like all automatic uniforms, <code>czm_inverseModel</code> does not need to be explicitly declared.
207
+ * However, it can be explicitly declared when a shader is also used by other applications such
208
+ * as a third-party authoring tool.
209
+ *
210
+ * @alias czm_inverseModel
211
+ * @glslUniform
212
+ *
213
+ * @see UniformState#getInverseModel
214
+ * @see czm_model
215
+ * @see czm_inverseModelView
216
+ *
217
+ * @example
218
+ * // GLSL declaration
219
+ * uniform mat4 czm_inverseModel;
220
+ *
221
+ * // Example
222
+ * vec4 modelPosition = czm_inverseModel * worldPosition;
223
+ */
224
+ czm_inverseModel : {
225
+ getSize : function() {
226
+ return 1;
227
+ },
228
+
229
+ getDatatype : function() {
230
+ return UniformDatatype.FLOAT_MATRIX4;
231
+ },
232
+
233
+ getValue : function(uniformState) {
234
+ return uniformState.getInverseModel();
235
+ }
236
+ },
237
+
238
+ /**
239
+ * An automatic GLSL uniform representing a 4x4 view transformation matrix that
240
+ * transforms world coordinates to eye coordinates.
241
+ * <br /><br />
242
+ * Like all automatic uniforms, <code>czm_view</code> does not need to be explicitly declared.
243
+ * However, it can be explicitly declared when a shader is also used by other applications such
244
+ * as a third-party authoring tool.
245
+ *
246
+ * @alias czm_view
247
+ * @glslUniform
248
+ *
249
+ * @see UniformState#getView
250
+ * @see czm_viewRotation
251
+ * @see czm_modelView
252
+ * @see czm_viewProjection
253
+ * @see czm_modelViewProjection
254
+ * @see czm_inverseView
255
+ *
256
+ * @example
257
+ * // GLSL declaration
258
+ * uniform mat4 czm_view;
259
+ *
260
+ * // Example
261
+ * vec4 eyePosition = czm_view * worldPosition;
262
+ */
263
+ czm_view : {
264
+ getSize : function() {
265
+ return 1;
266
+ },
267
+
268
+ getDatatype : function() {
269
+ return UniformDatatype.FLOAT_MATRIX4;
270
+ },
271
+
272
+ getValue : function(uniformState) {
273
+ return uniformState.getView();
274
+ }
275
+ },
276
+
277
+ /**
278
+ * An automatic GLSL uniform representing a 3x3 view rotation matrix that
279
+ * transforms vectors in world coordinates to eye coordinates.
280
+ * <br /><br />
281
+ * Like all automatic uniforms, <code>czm_viewRotation</code> does not need to be explicitly declared.
282
+ * However, it can be explicitly declared when a shader is also used by other applications such
283
+ * as a third-party authoring tool.
284
+ *
285
+ * @alias czm_viewRotation
286
+ * @glslUniform
287
+ *
288
+ * @see UniformState#getViewRotation
289
+ * @see czm_view
290
+ * @see czm_inverseView
291
+ * @see czm_inverseViewRotation
292
+ *
293
+ * @example
294
+ * // GLSL declaration
295
+ * uniform mat3 czm_viewRotation;
296
+ *
297
+ * // Example
298
+ * vec3 eyeVector = czm_viewRotation * worldVector;
299
+ */
300
+ czm_viewRotation : {
301
+ getSize : function() {
302
+ return 1;
303
+ },
304
+
305
+ getDatatype : function() {
306
+ return UniformDatatype.FLOAT_MATRIX3;
307
+ },
308
+
309
+ getValue : function(uniformState) {
310
+ return uniformState.getViewRotation();
311
+ }
312
+ },
313
+
314
+ /**
315
+ * An automatic GLSL uniform representing a 4x4 transformation matrix that
316
+ * transforms from eye coordinates to world coordinates.
317
+ * <br /><br />
318
+ * Like all automatic uniforms, <code>czm_inverseView</code> does not need to be explicitly declared.
319
+ * However, it can be explicitly declared when a shader is also used by other applications such
320
+ * as a third-party authoring tool.
321
+ *
322
+ * @alias czm_inverseView
323
+ * @glslUniform
324
+ *
325
+ * @see UniformState#getInverseView
326
+ * @see czm_view
327
+ * @see czm_inverseNormal
328
+ *
329
+ * @example
330
+ * // GLSL declaration
331
+ * uniform mat4 czm_inverseView;
332
+ *
333
+ * // Example
334
+ * vec4 worldPosition = czm_inverseView * eyePosition;
335
+ */
336
+ czm_inverseView : {
337
+ getSize : function() {
338
+ return 1;
339
+ },
340
+
341
+ getDatatype : function() {
342
+ return UniformDatatype.FLOAT_MATRIX4;
343
+ },
344
+
345
+ getValue : function(uniformState) {
346
+ return uniformState.getInverseView();
347
+ }
348
+ },
349
+
350
+ /**
351
+ * An automatic GLSL uniform representing a 3x3 rotation matrix that
352
+ * transforms vectors from eye coordinates to world coordinates.
353
+ * <br /><br />
354
+ * Like all automatic uniforms, <code>czm_inverseViewRotation</code> does not need to be explicitly declared.
355
+ * However, it can be explicitly declared when a shader is also used by other applications such
356
+ * as a third-party authoring tool.
357
+ *
358
+ * @alias czm_inverseViewRotation
359
+ * @glslUniform
360
+ *
361
+ * @see UniformState#getInverseView
362
+ * @see czm_view
363
+ * @see czm_viewRotation
364
+ * @see czm_inverseViewRotation
365
+ *
366
+ * @example
367
+ * // GLSL declaration
368
+ * uniform mat3 czm_inverseViewRotation;
369
+ *
370
+ * // Example
371
+ * vec4 worldVector = czm_inverseViewRotation * eyeVector;
372
+ */
373
+ czm_inverseViewRotation : {
374
+ getSize : function() {
375
+ return 1;
376
+ },
377
+
378
+ getDatatype : function() {
379
+ return UniformDatatype.FLOAT_MATRIX3;
380
+ },
381
+
382
+ getValue : function(uniformState) {
383
+ return uniformState.getInverseViewRotation();
384
+ }
385
+ },
386
+
387
+ /**
388
+ * An automatic GLSL uniform representing a 4x4 projection transformation matrix that
389
+ * transforms eye coordinates to clip coordinates. Clip coordinates is the
390
+ * coordinate system for a vertex shader's <code>gl_Position</code> output.
391
+ * <br /><br />
392
+ * Like all automatic uniforms, <code>czm_projection</code> does not need to be explicitly declared.
393
+ * However, it can be explicitly declared when a shader is also used by other applications such
394
+ * as a third-party authoring tool.
395
+ *
396
+ * @alias czm_projection
397
+ * @glslUniform
398
+ *
399
+ * @see UniformState#getProjection
400
+ * @see czm_viewProjection
401
+ * @see czm_modelViewProjection
402
+ * @see czm_infiniteProjection
403
+ *
404
+ * @example
405
+ * // GLSL declaration
406
+ * uniform mat4 czm_projection;
407
+ *
408
+ * // Example
409
+ * gl_Position = czm_projection * eyePosition;
410
+ */
411
+ czm_projection : {
412
+ getSize : function() {
413
+ return 1;
414
+ },
415
+
416
+ getDatatype : function() {
417
+ return UniformDatatype.FLOAT_MATRIX4;
418
+ },
419
+
420
+ getValue : function(uniformState) {
421
+ return uniformState.getProjection();
422
+ }
423
+ },
424
+
425
+ /**
426
+ * An automatic GLSL uniform representing a 4x4 inverse projection transformation matrix that
427
+ * transforms from clip coordinates to eye coordinates. Clip coordinates is the
428
+ * coordinate system for a vertex shader's <code>gl_Position</code> output.
429
+ * <br /><br />
430
+ * Like all automatic uniforms, <code>czm_inverseProjection</code> does not need to be explicitly declared.
431
+ * However, it can be explicitly declared when a shader is also used by other applications such
432
+ * as a third-party authoring tool.
433
+ *
434
+ * @alias czm_inverseProjection
435
+ * @glslUniform
436
+ *
437
+ * @see UniformState#getInverseProjection
438
+ * @see czm_projection
439
+ *
440
+ * @example
441
+ * // GLSL declaration
442
+ * uniform mat4 czm_inverseProjection;
443
+ *
444
+ * // Example
445
+ * vec4 eyePosition = czm_inverseProjection * clipPosition;
446
+ */
447
+ czm_inverseProjection : {
448
+ getSize : function() {
449
+ return 1;
450
+ },
451
+
452
+ getDatatype : function() {
453
+ return UniformDatatype.FLOAT_MATRIX4;
454
+ },
455
+
456
+ getValue : function(uniformState) {
457
+ return uniformState.getInverseProjection();
458
+ }
459
+ },
460
+
461
+ /**
462
+ * An automatic GLSL uniform representing a 4x4 projection transformation matrix with the far plane at infinity,
463
+ * that transforms eye coordinates to clip coordinates. Clip coordinates is the
464
+ * coordinate system for a vertex shader's <code>gl_Position</code> output. An infinite far plane is used
465
+ * in algorithms like shadow volumes and GPU ray casting with proxy geometry to ensure that triangles
466
+ * are not clipped by the far plane.
467
+ * <br /><br />
468
+ * Like all automatic uniforms, <code>czm_infiniteProjection</code> does not need to be explicitly declared.
469
+ * However, it can be explicitly declared when a shader is also used by other applications such
470
+ * as a third-party authoring tool.
471
+ *
472
+ * @alias czm_infiniteProjection
473
+ * @glslUniform
474
+ *
475
+ * @see UniformState#getInfiniteProjection
476
+ * @see czm_projection
477
+ * @see czm_modelViewInfiniteProjection
478
+ *
479
+ * @example
480
+ * // GLSL declaration
481
+ * uniform mat4 czm_infiniteProjection;
482
+ *
483
+ * // Example
484
+ * gl_Position = czm_infiniteProjection * eyePosition;
485
+ */
486
+ czm_infiniteProjection : {
487
+ getSize : function() {
488
+ return 1;
489
+ },
490
+
491
+ getDatatype : function() {
492
+ return UniformDatatype.FLOAT_MATRIX4;
493
+ },
494
+
495
+ getValue : function(uniformState) {
496
+ return uniformState.getInfiniteProjection();
497
+ }
498
+ },
499
+
500
+ /**
501
+ * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that
502
+ * transforms model coordinates to eye coordinates.
503
+ * <br /><br />
504
+ * Positions should be transformed to eye coordinates using <code>czm_modelView</code> and
505
+ * normals should be transformed using {@link czm_normal}.
506
+ * <br /><br />
507
+ * Like all automatic uniforms, <code>czm_modelView</code> does not need to be explicitly declared.
508
+ * However, it can be explicitly declared when a shader is also used by other applications such
509
+ * as a third-party authoring tool.
510
+ *
511
+ * @alias czm_modelView
512
+ * @glslUniform
513
+ *
514
+ * @see UniformState#getModelView
515
+ * @see czm_model
516
+ * @see czm_view
517
+ * @see czm_modelViewProjection
518
+ * @see czm_normal
519
+ *
520
+ * @example
521
+ * // GLSL declaration
522
+ * uniform mat4 czm_modelView;
523
+ *
524
+ * // Example
525
+ * vec4 eyePosition = czm_modelView * modelPosition;
526
+ *
527
+ * // The above is equivalent to, but more efficient than:
528
+ * vec4 eyePosition = czm_view * czm_model * modelPosition;
529
+ */
530
+ czm_modelView : {
531
+ getSize : function() {
532
+ return 1;
533
+ },
534
+
535
+ getDatatype : function() {
536
+ return UniformDatatype.FLOAT_MATRIX4;
537
+ },
538
+
539
+ getValue : function(uniformState) {
540
+ return uniformState.getModelView();
541
+ }
542
+ },
543
+
544
+ /**
545
+ * An automatic GLSL uniform representing a 4x4 model-view transformation matrix that
546
+ * transforms model coordinates, relative to the eye, to eye coordinates. This is used
547
+ * in conjunction with {@link czm_translateRelativeToEye}.
548
+ * <br /><br />
549
+ * Like all automatic uniforms, <code>czm_modelViewRelativeToEye</code> does not need to be explicitly declared.
550
+ * However, it can be explicitly declared when a shader is also used by other applications such
551
+ * as a third-party authoring tool.
552
+ *
553
+ * @alias czm_modelViewRelativeToEye
554
+ * @glslUniform
555
+ *
556
+ * @example
557
+ * // GLSL declaration
558
+ * uniform mat4 czm_modelViewRelativeToEye;
559
+ *
560
+ * // Example
561
+ * attribute vec3 positionHigh;
562
+ * attribute vec3 positionLow;
563
+ *
564
+ * void main()
565
+ * {
566
+ * vec3 p = czm_translateRelativeToEye(positionHigh, positionLow);
567
+ * gl_Position = czm_projection * (czm_modelViewRelativeToEye * vec4(p, 1.0));
568
+ * }
569
+ *
570
+ * @see czm_modelViewProjectionRelativeToEye
571
+ * @see czm_translateRelativeToEye
572
+ * @see EncodedCartesian3
573
+ */
574
+ czm_modelViewRelativeToEye : {
575
+ getSize : function() {
576
+ return 1;
577
+ },
578
+
579
+ getDatatype : function() {
580
+ return UniformDatatype.FLOAT_MATRIX4;
581
+ },
582
+
583
+ getValue : function(uniformState) {
584
+ return uniformState.getModelViewRelativeToEye();
585
+ }
586
+ },
587
+
588
+ /**
589
+ * An automatic GLSL uniform representing a 4x4 transformation matrix that
590
+ * transforms from eye coordinates to model coordinates.
591
+ * <br /><br />
592
+ * Like all automatic uniforms, <code>czm_inverseModelView</code> does not need to be explicitly declared.
593
+ * However, it can be explicitly declared when a shader is also used by other applications such
594
+ * as a third-party authoring tool.
595
+ *
596
+ * @alias czm_inverseModelView
597
+ * @glslUniform
598
+ *
599
+ * @see UniformState#getInverseModelView
600
+ * @see czm_modelView
601
+ *
602
+ * @example
603
+ * // GLSL declaration
604
+ * uniform mat4 czm_inverseModelView;
605
+ *
606
+ * // Example
607
+ * vec4 modelPosition = czm_inverseModelView * eyePosition;
608
+ */
609
+ czm_inverseModelView : {
610
+ getSize : function() {
611
+ return 1;
612
+ },
613
+
614
+ getDatatype : function() {
615
+ return UniformDatatype.FLOAT_MATRIX4;
616
+ },
617
+
618
+ getValue : function(uniformState) {
619
+ return uniformState.getInverseModelView();
620
+ }
621
+ },
622
+
623
+ /**
624
+ * An automatic GLSL uniform representing a 4x4 view-projection transformation matrix that
625
+ * transforms world coordinates to clip coordinates. Clip coordinates is the
626
+ * coordinate system for a vertex shader's <code>gl_Position</code> output.
627
+ * <br /><br />
628
+ * Like all automatic uniforms, <code>czm_viewProjection</code> does not need to be explicitly declared.
629
+ * However, it can be explicitly declared when a shader is also used by other applications such
630
+ * as a third-party authoring tool.
631
+ *
632
+ * @alias czm_viewProjection
633
+ * @glslUniform
634
+ *
635
+ * @see UniformState#getViewProjection
636
+ * @see czm_view
637
+ * @see czm_projection
638
+ * @see czm_modelViewProjection
639
+ *
640
+ * @example
641
+ * // GLSL declaration
642
+ * uniform mat4 czm_viewProjection;
643
+ *
644
+ * // Example
645
+ * vec4 gl_Position = czm_viewProjection * czm_model * modelPosition;
646
+ *
647
+ * // The above is equivalent to, but more efficient than:
648
+ * gl_Position = czm_projection * czm_view * czm_model * modelPosition;
649
+ */
650
+ czm_viewProjection : {
651
+ getSize : function() {
652
+ return 1;
653
+ },
654
+
655
+ getDatatype : function() {
656
+ return UniformDatatype.FLOAT_MATRIX4;
657
+ },
658
+
659
+ getValue : function(uniformState) {
660
+ return uniformState.getViewProjection();
661
+ }
662
+ },
663
+
664
+ /**
665
+ * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that
666
+ * transforms model coordinates to clip coordinates. Clip coordinates is the
667
+ * coordinate system for a vertex shader's <code>gl_Position</code> output.
668
+ * <br /><br />
669
+ * Like all automatic uniforms, <code>czm_modelViewProjection</code> does not need to be explicitly declared.
670
+ * However, it can be explicitly declared when a shader is also used by other applications such
671
+ * as a third-party authoring tool.
672
+ *
673
+ * @alias czm_modelViewProjection
674
+ * @glslUniform
675
+ *
676
+ * @see UniformState#getModelViewProjection
677
+ * @see czm_model
678
+ * @see czm_view
679
+ * @see czm_projection
680
+ * @see czm_modelView
681
+ * @see czm_viewProjection
682
+ * @see czm_modelViewInfiniteProjection
683
+ *
684
+ * @example
685
+ * // GLSL declaration
686
+ * uniform mat4 czm_modelViewProjection;
687
+ *
688
+ * // Example
689
+ * vec4 gl_Position = czm_modelViewProjection * modelPosition;
690
+ *
691
+ * // The above is equivalent to, but more efficient than:
692
+ * gl_Position = czm_projection * czm_view * czm_model * modelPosition;
693
+ */
694
+ czm_modelViewProjection : {
695
+ getSize : function() {
696
+ return 1;
697
+ },
698
+
699
+ getDatatype : function() {
700
+ return UniformDatatype.FLOAT_MATRIX4;
701
+ },
702
+
703
+ getValue : function(uniformState) {
704
+ return uniformState.getModelViewProjection();
705
+ }
706
+ },
707
+
708
+ /**
709
+ * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that
710
+ * transforms model coordinates, relative to the eye, to clip coordinates. Clip coordinates is the
711
+ * coordinate system for a vertex shader's <code>gl_Position</code> output. This is used in
712
+ * conjunction with {@link czm_translateRelativeToEye}.
713
+ * <br /><br />
714
+ * Like all automatic uniforms, <code>czm_modelViewProjectionRelativeToEye</code> does not need to be explicitly declared.
715
+ * However, it can be explicitly declared when a shader is also used by other applications such
716
+ * as a third-party authoring tool.
717
+ *
718
+ * @alias czm_modelViewProjectionRelativeToEye
719
+ * @glslUniform
720
+ *
721
+ * @example
722
+ * // GLSL declaration
723
+ * uniform mat4 czm_modelViewProjectionRelativeToEye;
724
+ *
725
+ * // Example
726
+ * attribute vec3 positionHigh;
727
+ * attribute vec3 positionLow;
728
+ *
729
+ * void main()
730
+ * {
731
+ * vec3 p = czm_translateRelativeToEye(positionHigh, positionLow);
732
+ * gl_Position = czm_modelViewProjectionRelativeToEye * vec4(p, 1.0);
733
+ * }
734
+ *
735
+ * @see czm_modelViewRelativeToEye
736
+ * @see czm_translateRelativeToEye
737
+ * @see EncodedCartesian3
738
+ */
739
+ czm_modelViewProjectionRelativeToEye : {
740
+ getSize : function() {
741
+ return 1;
742
+ },
743
+
744
+ getDatatype : function() {
745
+ return UniformDatatype.FLOAT_MATRIX4;
746
+ },
747
+
748
+ getValue : function(uniformState) {
749
+ return uniformState.getModelViewProjectionRelativeToEye();
750
+ }
751
+ },
752
+
753
+ /**
754
+ * An automatic GLSL uniform representing a 4x4 model-view-projection transformation matrix that
755
+ * transforms model coordinates to clip coordinates. Clip coordinates is the
756
+ * coordinate system for a vertex shader's <code>gl_Position</code> output. The projection matrix places
757
+ * the far plane at infinity. This is useful in algorithms like shadow volumes and GPU ray casting with
758
+ * proxy geometry to ensure that triangles are not clipped by the far plane.
759
+ * <br /><br />
760
+ * Like all automatic uniforms, <code>czm_modelViewInfiniteProjection</code> does not need to be explicitly declared.
761
+ * However, it can be explicitly declared when a shader is also used by other applications such
762
+ * as a third-party authoring tool.
763
+ *
764
+ * @alias czm_modelViewInfiniteProjection
765
+ * @glslUniform
766
+ *
767
+ * @see UniformState#getModelViewInfiniteProjection
768
+ * @see czm_model
769
+ * @see czm_view
770
+ * @see czm_infiniteProjection
771
+ * @see czm_modelViewProjection
772
+ *
773
+ * @example
774
+ * // GLSL declaration
775
+ * uniform mat4 czm_modelViewInfiniteProjection;
776
+ *
777
+ * // Example
778
+ * vec4 gl_Position = czm_modelViewInfiniteProjection * modelPosition;
779
+ *
780
+ * // The above is equivalent to, but more efficient than:
781
+ * gl_Position = czm_infiniteProjection * czm_view * czm_model * modelPosition;
782
+ */
783
+ czm_modelViewInfiniteProjection : {
784
+ getSize : function() {
785
+ return 1;
786
+ },
787
+
788
+ getDatatype : function() {
789
+ return UniformDatatype.FLOAT_MATRIX4;
790
+ },
791
+
792
+ getValue : function(uniformState) {
793
+ return uniformState.getModelViewInfiniteProjection();
794
+ }
795
+ },
796
+
797
+ /**
798
+ * An automatic GLSL uniform representing a 3x3 normal transformation matrix that
799
+ * transforms normal vectors in model coordinates to eye coordinates.
800
+ * <br /><br />
801
+ * Positions should be transformed to eye coordinates using {@link czm_modelView} and
802
+ * normals should be transformed using <code>czm_normal</code>.
803
+ * <br /><br />
804
+ * Like all automatic uniforms, <code>czm_normal</code> does not need to be explicitly declared.
805
+ * However, it can be explicitly declared when a shader is also used by other applications such
806
+ * as a third-party authoring tool.
807
+ *
808
+ * @alias czm_normal
809
+ * @glslUniform
810
+ *
811
+ * @see UniformState#getNormal
812
+ * @see czm_inverseNormal
813
+ * @see czm_modelView
814
+ *
815
+ * @example
816
+ * // GLSL declaration
817
+ * uniform mat3 czm_normal;
818
+ *
819
+ * // Example
820
+ * vec3 eyeNormal = czm_normal * normal;
821
+ */
822
+ czm_normal : {
823
+ getSize : function() {
824
+ return 1;
825
+ },
826
+
827
+ getDatatype : function() {
828
+ return UniformDatatype.FLOAT_MATRIX3;
829
+ },
830
+
831
+ getValue : function(uniformState) {
832
+ return uniformState.getNormal();
833
+ }
834
+ },
835
+
836
+ /**
837
+ * An automatic GLSL uniform representing a 3x3 normal transformation matrix that
838
+ * transforms normal vectors in eye coordinates to model coordinates. This is
839
+ * in the opposite transform provided by {@link czm_normal}.
840
+ * <br /><br />
841
+ * Like all automatic uniforms, <code>czm_inverseNormal</code> does not need to be explicitly declared.
842
+ * However, it can be explicitly declared when a shader is also used by other applications such
843
+ * as a third-party authoring tool.
844
+ *
845
+ * @alias czm_inverseNormal
846
+ * @glslUniform
847
+ *
848
+ * @see UniformState#getInverseNormal
849
+ * @see czm_normal
850
+ * @see czm_modelView
851
+ * @see czm_inverseView
852
+ *
853
+ * @example
854
+ * // GLSL declaration
855
+ * uniform mat3 czm_inverseNormal;
856
+ *
857
+ * // Example
858
+ * vec3 normalMC = czm_inverseNormal * normalEC;
859
+ */
860
+ czm_inverseNormal : {
861
+ getSize : function() {
862
+ return 1;
863
+ },
864
+
865
+ getDatatype : function() {
866
+ return UniformDatatype.FLOAT_MATRIX3;
867
+ },
868
+
869
+ getValue : function(uniformState) {
870
+ return uniformState.getInverseNormal();
871
+ }
872
+ },
873
+
874
+ /**
875
+ * An automatic GLSL uniform containing the near distance (<code>x</code>) and the far distance (<code>y</code>)
876
+ * of the frustum defined by the camera. This is the largest possible frustum, not an individual
877
+ * frustum used for mult-frustum rendering.
878
+ * <br /><br />
879
+ * Like all automatic uniforms, <code>czm_entireFrustum</code> does not need to be explicitly declared.
880
+ * However, it can be explicitly declared when a shader is also used by other applications such
881
+ * as a third-party authoring tool.
882
+ *
883
+ * @alias czm_entireFrustum
884
+ * @glslUniform
885
+ *
886
+ * @see UniformState#getEntireFrustum
887
+ *
888
+ * @example
889
+ * // GLSL declaration
890
+ * uniform vec2 czm_entireFrustum;
891
+ *
892
+ * // Example
893
+ * float frustumLength = czm_entireFrustum.y - czm_entireFrustum.x;
894
+ */
895
+ czm_entireFrustum : {
896
+ getSize : function() {
897
+ return 1;
898
+ },
899
+
900
+ getDatatype : function() {
901
+ return UniformDatatype.FLOAT_VECTOR2;
902
+ },
903
+
904
+ getValue : function(uniformState) {
905
+ return uniformState.getEntireFrustum();
906
+ }
907
+ },
908
+
909
+ /**
910
+ * An automatic GLSL uniform representing the normalized direction to the sun in eye coordinates.
911
+ * This is commonly used for directional lighting computations.
912
+ * <br /><br />
913
+ * Like all automatic uniforms, <code>czm_sunDirectionEC</code> does not need to be explicitly declared.
914
+ * However, it can be explicitly declared when a shader is also used by other applications such
915
+ * as a third-party authoring tool.
916
+ *
917
+ * @alias czm_sunDirectionEC
918
+ * @glslUniform
919
+ *
920
+ * @see UniformState#getSunDirectionEC
921
+ * @see czm_moonDirectionEC
922
+ * @see czm_sunDirectionWC
923
+ *
924
+ * @example
925
+ * // GLSL declaration
926
+ * uniform vec3 czm_sunDirectionEC;
927
+ *
928
+ * // Example
929
+ * float diffuse = max(dot(czm_sunDirectionEC, normalEC), 0.0);
930
+ */
931
+ czm_sunDirectionEC : {
932
+ getSize : function() {
933
+ return 1;
934
+ },
935
+
936
+ getDatatype : function() {
937
+ return UniformDatatype.FLOAT_VECTOR3;
938
+ },
939
+
940
+ getValue : function(uniformState) {
941
+ return uniformState.getSunDirectionEC();
942
+ }
943
+ },
944
+
945
+ /**
946
+ * An automatic GLSL uniform representing the normalized direction to the sun in world coordinates.
947
+ * This is commonly used for directional lighting computations.
948
+ * <br /><br />
949
+ * Like all automatic uniforms, <code>czm_sunDirectionWC</code> does not need to be explicitly declared.
950
+ * However, it can be explicitly declared when a shader is also used by other applications such
951
+ * as a third-party authoring tool.
952
+ *
953
+ * @alias czm_sunDirectionWC
954
+ * @glslUniform
955
+ *
956
+ * @see UniformState#getSunDirectionWC
957
+ * @see czm_sunDirectionEC
958
+ *
959
+ * @example
960
+ * // GLSL declaration
961
+ * uniform vec3 czm_sunDirectionWC;
962
+ */
963
+ czm_sunDirectionWC : {
964
+ getSize : function() {
965
+ return 1;
966
+ },
967
+
968
+ getDatatype : function() {
969
+ return UniformDatatype.FLOAT_VECTOR3;
970
+ },
971
+
972
+ getValue : function(uniformState) {
973
+ return uniformState.getSunDirectionWC();
974
+ }
975
+ },
976
+
977
+ /**
978
+ * An automatic GLSL uniform representing the normalized direction to the moon in eye coordinates.
979
+ * This is commonly used for directional lighting computations.
980
+ * <br /><br />
981
+ * Like all automatic uniforms, <code>czm_moonDirectionEC</code> does not need to be explicitly declared.
982
+ * However, it can be explicitly declared when a shader is also used by other applications such
983
+ * as a third-party authoring tool.
984
+ *
985
+ * @alias czm_moonDirectionEC
986
+ * @glslUniform
987
+ *
988
+ * @see UniformState#getMoonDirectionEC
989
+ * @see czm_sunDirectionEC
990
+ *
991
+ * @example
992
+ * // GLSL declaration
993
+ * uniform vec3 czm_moonDirectionEC;
994
+ *
995
+ * // Example
996
+ * float diffuse = max(dot(czm_moonDirectionEC, normalEC), 0.0);
997
+ */
998
+ czm_moonDirectionEC : {
999
+ getSize : function() {
1000
+ return 1;
1001
+ },
1002
+
1003
+ getDatatype : function() {
1004
+ return UniformDatatype.FLOAT_VECTOR3;
1005
+ },
1006
+
1007
+ getValue : function(uniformState) {
1008
+ return uniformState.getMoonDirectionEC();
1009
+ }
1010
+ },
1011
+
1012
+ /**
1013
+ * An automatic GLSL uniform representing the high bits of the camera position in model
1014
+ * coordinates. This is used for GPU RTE to eliminate jittering artifacts when rendering
1015
+ * as described in <a href="http://blogs.agi.com/insight3d/index.php/2008/09/03/precisions-precisions/">Precisions, Precisions</a>.
1016
+ * <br /><br />
1017
+ * Like all automatic uniforms, <code>czm_encodedCameraPositionMCHigh</code> does not need to be explicitly declared.
1018
+ * However, it can be explicitly declared when a shader is also used by other applications such
1019
+ * as a third-party authoring tool.
1020
+ *
1021
+ * @alias czm_encodedCameraPositionMCHigh
1022
+ * @glslUniform
1023
+ *
1024
+ * @see czm_encodedCameraPositionMCLow
1025
+ * @see czm_modelViewRelativeToEye
1026
+ * @see czm_modelViewProjectionRelativeToEye
1027
+ *
1028
+ * @example
1029
+ * // GLSL declaration
1030
+ * uniform vec3 czm_encodedCameraPositionMCHigh;
1031
+ */
1032
+ czm_encodedCameraPositionMCHigh : {
1033
+ getSize : function() {
1034
+ return 1;
1035
+ },
1036
+
1037
+ getDatatype : function() {
1038
+ return UniformDatatype.FLOAT_VECTOR3;
1039
+ },
1040
+
1041
+ getValue : function(uniformState) {
1042
+ return uniformState.getEncodedCameraPositionMCHigh();
1043
+ }
1044
+ },
1045
+
1046
+ /**
1047
+ * An automatic GLSL uniform representing the low bits of the camera position in model
1048
+ * coordinates. This is used for GPU RTE to eliminate jittering artifacts when rendering
1049
+ * as described in <a href="http://blogs.agi.com/insight3d/index.php/2008/09/03/precisions-precisions/">Precisions, Precisions</a>.
1050
+ * <br /><br />
1051
+ * Like all automatic uniforms, <code>czm_encodedCameraPositionMCHigh</code> does not need to be explicitly declared.
1052
+ * However, it can be explicitly declared when a shader is also used by other applications such
1053
+ * as a third-party authoring tool.
1054
+ *
1055
+ * @alias czm_encodedCameraPositionMCLow
1056
+ * @glslUniform
1057
+ *
1058
+ * @see czm_encodedCameraPositionMCHigh
1059
+ * @see czm_modelViewRelativeToEye
1060
+ * @see czm_modelViewProjectionRelativeToEye
1061
+ *
1062
+ * @example
1063
+ * // GLSL declaration
1064
+ * uniform vec3 czm_encodedCameraPositionMCLow;
1065
+ */
1066
+ czm_encodedCameraPositionMCLow : {
1067
+ getSize : function() {
1068
+ return 1;
1069
+ },
1070
+
1071
+ getDatatype : function() {
1072
+ return UniformDatatype.FLOAT_VECTOR3;
1073
+ },
1074
+
1075
+ getValue : function(uniformState) {
1076
+ return uniformState.getEncodedCameraPositionMCLow();
1077
+ }
1078
+ },
1079
+
1080
+ /**
1081
+ * An automatic GLSL uniform representing the position of the viewer (camera) in world coordinates.
1082
+ * <br /><br />
1083
+ * Like all automatic uniforms, <code>czm_sunDirectionWC</code> does not need to be explicitly declared.
1084
+ * However, it can be explicitly declared when a shader is also used by other applications such
1085
+ * as a third-party authoring tool.
1086
+ *
1087
+ * @alias czm_viewerPositionWC
1088
+ * @glslUniform
1089
+ *
1090
+ * @example
1091
+ * // GLSL declaration
1092
+ * uniform vec3 czm_viewerPositionWC;
1093
+ */
1094
+ czm_viewerPositionWC : {
1095
+ getSize : function() {
1096
+ return 1;
1097
+ },
1098
+
1099
+ getDatatype : function() {
1100
+ return UniformDatatype.FLOAT_VECTOR3;
1101
+ },
1102
+
1103
+ getValue : function(uniformState) {
1104
+ return uniformState.getInverseView().getTranslation();
1105
+ }
1106
+ },
1107
+
1108
+ /**
1109
+ * An automatic GLSL uniform representing the frame number. This uniform is automatically incremented
1110
+ * every frame.
1111
+ * <br /><br />
1112
+ * Like all automatic uniforms, <code>czm_frameNumber</code> does not need to be explicitly declared.
1113
+ * However, it can be explicitly declared when a shader is also used by other applications such
1114
+ * as a third-party authoring tool.
1115
+ *
1116
+ * @alias czm_frameNumber
1117
+ * @glslUniform
1118
+ *
1119
+ * @example
1120
+ * // GLSL declaration
1121
+ * uniform float czm_frameNumber;
1122
+ */
1123
+ czm_frameNumber : {
1124
+ getSize : function() {
1125
+ return 1;
1126
+ },
1127
+
1128
+ getDatatype : function() {
1129
+ return UniformDatatype.FLOAT;
1130
+ },
1131
+
1132
+ getValue : function(uniformState) {
1133
+ return uniformState.getFrameNumber();
1134
+ }
1135
+ },
1136
+
1137
+ /**
1138
+ * An automatic GLSL uniform representing a 3x3 rotation matrix that transforms
1139
+ * from True Equator Mean Equinox (TEME) axes to the pseudo-fixed axes at the current scene time.
1140
+ * <br /><br />
1141
+ * Like all automatic uniforms, <code>czm_temeToPseudoFixed</code> does not need to be explicitly declared.
1142
+ * However, it can be explicitly declared when a shader is also used by other applications such
1143
+ * as a third-party authoring tool.
1144
+ *
1145
+ * @alias czm_temeToPseudoFixed
1146
+ * @glslUniform
1147
+ *
1148
+ * @see UniformState#getTemeToPseudoFixedMatrix
1149
+ * @see Transforms.computeTemeToPseudoFixedMatrix
1150
+ *
1151
+ * @example
1152
+ * // GLSL declaration
1153
+ * uniform mat3 czm_temeToPseudoFixed;
1154
+ *
1155
+ * // Example
1156
+ * vec3 pseudoFixed = czm_temeToPseudoFixed * teme;
1157
+ */
1158
+ czm_temeToPseudoFixed : {
1159
+ getSize : function() {
1160
+ return 1;
1161
+ },
1162
+
1163
+ getDatatype : function() {
1164
+ return UniformDatatype.FLOAT_MATRIX3;
1165
+ },
1166
+
1167
+ getValue : function(uniformState) {
1168
+ return uniformState.getTemeToPseudoFixedMatrix();
1169
+ }
1170
+ }
1171
+ };
1172
+
1173
+ function getUniformDatatype(gl, activeUniformType) {
1174
+ switch (activeUniformType) {
1175
+ case gl.FLOAT:
1176
+ return function() {
1177
+ return UniformDatatype.FLOAT;
1178
+ };
1179
+ case gl.FLOAT_VEC2:
1180
+ return function() {
1181
+ return UniformDatatype.FLOAT_VECTOR2;
1182
+ };
1183
+ case gl.FLOAT_VEC3:
1184
+ return function() {
1185
+ return UniformDatatype.FLOAT_VECTOR3;
1186
+ };
1187
+ case gl.FLOAT_VEC4:
1188
+ return function() {
1189
+ return UniformDatatype.FLOAT_VECTOR4;
1190
+ };
1191
+ case gl.INT:
1192
+ return function() {
1193
+ return UniformDatatype.INT;
1194
+ };
1195
+ case gl.INT_VEC2:
1196
+ return function() {
1197
+ return UniformDatatype.INT_VECTOR2;
1198
+ };
1199
+ case gl.INT_VEC3:
1200
+ return function() {
1201
+ return UniformDatatype.INT_VECTOR3;
1202
+ };
1203
+ case gl.INT_VEC4:
1204
+ return function() {
1205
+ return UniformDatatype.INT_VECTOR4;
1206
+ };
1207
+ case gl.BOOL:
1208
+ return function() {
1209
+ return UniformDatatype.BOOL;
1210
+ };
1211
+ case gl.BOOL_VEC2:
1212
+ return function() {
1213
+ return UniformDatatype.BOOL_VECTOR2;
1214
+ };
1215
+ case gl.BOOL_VEC3:
1216
+ return function() {
1217
+ return UniformDatatype.BOOL_VECTOR3;
1218
+ };
1219
+ case gl.BOOL_VEC4:
1220
+ return function() {
1221
+ return UniformDatatype.BOOL_VECTOR4;
1222
+ };
1223
+ case gl.FLOAT_MAT2:
1224
+ return function() {
1225
+ return UniformDatatype.FLOAT_MATRIX2;
1226
+ };
1227
+ case gl.FLOAT_MAT3:
1228
+ return function() {
1229
+ return UniformDatatype.FLOAT_MATRIX3;
1230
+ };
1231
+ case gl.FLOAT_MAT4:
1232
+ return function() {
1233
+ return UniformDatatype.FLOAT_MATRIX4;
1234
+ };
1235
+ case gl.SAMPLER_2D:
1236
+ return function() {
1237
+ return UniformDatatype.SAMPLER_2D;
1238
+ };
1239
+ case gl.SAMPLER_CUBE:
1240
+ return function() {
1241
+ return UniformDatatype.SAMPLER_CUBE;
1242
+ };
1243
+ default:
1244
+ throw new RuntimeError('Unrecognized uniform type: ' + activeUniformType);
1245
+ }
1246
+ }
1247
+
1248
+ /**
1249
+ * A shader program's uniform, including the uniform's value. This is most commonly used to change
1250
+ * the value of a uniform, but can also be used retrieve a uniform's name and datatype,
1251
+ * which is useful for creating user interfaces for tweaking shaders.
1252
+ * <br /><br />
1253
+ * Do not create a uniform object with the <code>new</code> keyword; a shader program's uniforms
1254
+ * are available via {@link ShaderProgram#getAllUniforms}.
1255
+ * <br /><br />
1256
+ * Changing a uniform's value will affect future calls to {@link Context#draw}
1257
+ * that use the corresponding shader program.
1258
+ * <br /><br />
1259
+ * The datatype of the <code>value</code> property depends on the datatype
1260
+ * used in the GLSL declaration as shown in the examples in the table below.
1261
+ * <br /><br />
1262
+ * <table border='1'>
1263
+ * <tr>
1264
+ * <td>GLSL</td>
1265
+ * <td>JavaScript</td>
1266
+ * </tr>
1267
+ * <tr>
1268
+ * <td><code>uniform float u_float; </code></td>
1269
+ * <td><code> sp.getAllUniforms().u_float.value = 1.0;</code></td>
1270
+ * </tr>
1271
+ * <tr>
1272
+ * <td><code>uniform vec2 u_vec2; </code></td>
1273
+ * <td><code> sp.getAllUniforms().u_vec2.value = new Cartesian2(1.0, 2.0);</code></td>
1274
+ * </tr>
1275
+ * <tr>
1276
+ * <td><code>uniform vec3 u_vec3; </code></td>
1277
+ * <td><code> sp.getAllUniforms().u_vec3.value = new Cartesian3(1.0, 2.0, 3.0);</code></td>
1278
+ * </tr>
1279
+ * <tr>
1280
+ * <td><code>uniform vec4 u_vec4; </code></td>
1281
+ * <td><code> sp.getAllUniforms().u_vec4.value = new Cartesian4(1.0, 2.0, 3.0, 4.0);</code></td>
1282
+ * </tr>
1283
+ * <tr>
1284
+ * <td><code>uniform int u_int; </code></td>
1285
+ * <td><code> sp.getAllUniforms().u_int.value = 1;</code></td>
1286
+ * </tr>
1287
+ * <tr>
1288
+ * <td><code>uniform ivec2 u_ivec2; </code></td>
1289
+ * <td><code> sp.getAllUniforms().u_ivec2.value = new Cartesian2(1, 2);</code></td>
1290
+ * </tr>
1291
+ * <tr>
1292
+ * <td><code>uniform ivec3 u_ivec3; </code></td>
1293
+ * <td><code> sp.getAllUniforms().u_ivec3.value = new Cartesian3(1, 2, 3);</code></td>
1294
+ * </tr>
1295
+ * <tr>
1296
+ * <td><code>uniform ivec4 u_ivec4; </code></td>
1297
+ * <td><code> sp.getAllUniforms().u_ivec4.value = new Cartesian4(1, 2, 3, 4);</code></td>
1298
+ * </tr>
1299
+ * <tr>
1300
+ * <td><code>uniform bool u_bool; </code></td>
1301
+ * <td><code> sp.getAllUniforms().u_bool.value = true;</code></td>
1302
+ * </tr>
1303
+ * <tr>
1304
+ * <td><code>uniform bvec2 u_bvec2; </code></td>
1305
+ * <td><code> sp.getAllUniforms().u_bvec2.value = new Cartesian2(true, true);</code></td>
1306
+ * </tr>
1307
+ * <tr>
1308
+ * <td><code>uniform bvec3 u_bvec3; </code></td>
1309
+ * <td><code> sp.getAllUniforms().u_bvec3.value = new Cartesian3(true, true, true);</code></td>
1310
+ * </tr>
1311
+ * <tr>
1312
+ * <td><code>uniform bvec4 u_bvec4; </code></td>
1313
+ * <td><code> sp.getAllUniforms().u_bvec4.value = new Cartesian4(true, true, true, true);</code></td>
1314
+ * </tr>
1315
+ * <tr>
1316
+ * <td><code>uniform mat2 u_mat2; </code></td>
1317
+ * <td><code> sp.getAllUniforms().u_mat2.value = new Matrix2(1.0, 2.0, 3.0, 4.0);</code></td>
1318
+ * </tr>
1319
+ * <tr>
1320
+ * <td><code>uniform mat3 u_mat3; </code></td>
1321
+ * <td><code> sp.getAllUniforms().u_mat3.value = new Matrix3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);</code></td>
1322
+ * </tr>
1323
+ * <tr>
1324
+ * <td><code>uniform mat4 u_mat4; </code></td>
1325
+ * <td><code> sp.getAllUniforms().u_mat4.value = new Matrix4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0);</code></td>
1326
+ * </tr>
1327
+ * <tr>
1328
+ * <td><code>uniform sampler2D u_texture; </code></td>
1329
+ * <td><code> sp.getAllUniforms().u_texture.value = context.createTexture2D(...);</code></td>
1330
+ * </tr>
1331
+ * <tr>
1332
+ * <td><code>uniform samplerCube u_cubeMap; </code></td>
1333
+ * <td><code> sp.getAllUniforms().u_cubeMap.value = context.createCubeMap(...);</code></td>
1334
+ * </tr>
1335
+ * </table>
1336
+ * <br />
1337
+ * When the GLSL uniform is declared as an array, <code>value</code> is also an array as shown in Example 2.
1338
+ * Individual members of a <code>struct uniform</code> can be accessed as done in Example 3.
1339
+ * <br /><br />
1340
+ * Uniforms whose names starting with <code>czm_</code>, such as {@link czm_viewProjection}, are called
1341
+ * automatic uniforms; they are implicitly declared and automatically assigned to in
1342
+ * <code>Context.draw</code> based on the {@link UniformState}.
1343
+ *
1344
+ * @alias Uniform
1345
+ * @internalConstructor
1346
+ *
1347
+ * @see Uniform#value
1348
+ * @see UniformDatatype
1349
+ * @see ShaderProgram#getAllUniforms
1350
+ * @see UniformState
1351
+ * @see Context#draw
1352
+ * @see Context#createTexture2D
1353
+ * @see Context#createCubeMap
1354
+ *
1355
+ * @example
1356
+ * // Example 1. Create a shader program and set its
1357
+ * // one uniform, a 4x4 matrix, to the identity matrix
1358
+ * var vs =
1359
+ * 'attribute vec4 position; ' +
1360
+ * 'uniform mat4 u_mvp; ' +
1361
+ * 'void main() { gl_Position = u_mvp * position; }';
1362
+ * var fs = // ...
1363
+ * var sp = context.createShaderProgram(vs, fs);
1364
+ *
1365
+ * var mvp = sp.getAllUniforms().u_mvp;
1366
+ * console.log(mvp.getName()); // 'u_mvp'
1367
+ * console.log(mvp.getDatatype().name); // 'FLOAT_MATRIX4'
1368
+ * mvp.value = Matrix4.IDENTITY;
1369
+ *
1370
+ * //////////////////////////////////////////////////////////////////////
1371
+ *
1372
+ * // Example 2. Setting values for a GLSL array uniform
1373
+ * // GLSL: uniform float u_float[2];
1374
+ * sp.getAllUniforms().u_float.value = new Cartesian2(1.0, 2.0);
1375
+ *
1376
+ * // GLSL: uniform vec4 u_vec4[2];
1377
+ * sp.getAllUniforms().u_vec4.value = [
1378
+ * Cartesian4.UNIT_X,
1379
+ * Cartesian4.UNIT_Y
1380
+ * ];
1381
+ *
1382
+ * //////////////////////////////////////////////////////////////////////
1383
+ *
1384
+ * // Example 3. Setting values for members of a GLSL struct
1385
+ * // GLSL: uniform struct { float f; vec4 v; } u_struct;
1386
+ * sp.getAllUniforms()['u_struct.f'].value = 1.0;
1387
+ * sp.getAllUniforms()['u_struct.v'].value = new Cartesian4(1.0, 2.0, 3.0, 4.0);
1388
+ */
1389
+ var Uniform = function(_gl, activeUniform, _uniformName, _location, uniformValue) {
1390
+ /**
1391
+ * The value of the uniform. The datatype depends on the datatype used in the
1392
+ * GLSL declaration as explained in the {@link Uniform} help and shown
1393
+ * in the examples below.
1394
+ *
1395
+ * @field
1396
+ * @alias Uniform#value
1397
+ *
1398
+ * @see Context#createTexture2D
1399
+ *
1400
+ * @example
1401
+ * // GLSL: uniform float u_float;
1402
+ * sp.getAllUniforms().u_float.value = 1.0;
1403
+ *
1404
+ * // GLSL: uniform vec4 u_vec4;
1405
+ * sp.getAllUniforms().u_vec4.value = Cartesian4.ZERO;
1406
+ *
1407
+ * // GLSL: uniform bvec4 u_bvec4;
1408
+ * sp.getAllUniforms().u_bvec4.value = new Cartesian4(true, true, true, true);
1409
+ *
1410
+ * // GLSL: uniform mat4 u_mat4;
1411
+ * sp.getAllUniforms().u_mat4.value = Matrix4.IDENTITY;
1412
+ *
1413
+ * // GLSL: uniform sampler2D u_texture;
1414
+ * sp.getAllUniforms().u_texture.value = context.createTexture2D(...);
1415
+ *
1416
+ * // GLSL: uniform vec2 u_vec2[2];
1417
+ * sp.getAllUniforms().u_vec2.value = [
1418
+ * new Cartesian2(1.0, 2.0),
1419
+ * new Cartesian2(3.0, 4.0)
1420
+ * ];
1421
+ *
1422
+ * // GLSL: uniform struct { float f; vec4 v; } u_struct;
1423
+ * sp.getAllUniforms()['u_struct.f'].value = 1.0;
1424
+ * sp.getAllUniforms()['u_struct.v'].value = new Cartesian4(1.0, 2.0, 3.0, 4.0);
1425
+ */
1426
+ this.value = uniformValue;
1427
+
1428
+ /**
1429
+ * Returns the case-sensitive name of the GLSL uniform.
1430
+ *
1431
+ * @returns {String} The name of the uniform.
1432
+ * @function
1433
+ * @alias Uniform#getName
1434
+ *
1435
+ * @example
1436
+ * // GLSL: uniform mat4 u_mvp;
1437
+ * console.log(sp.getAllUniforms().u_mvp.getName()); // 'u_mvp'
1438
+ */
1439
+ this.getName = function() {
1440
+ return _uniformName;
1441
+ };
1442
+
1443
+ /**
1444
+ * Returns the datatype of the uniform. This is useful when dynamically
1445
+ * creating a user interface to tweak shader uniform values.
1446
+ *
1447
+ * @returns {UniformDatatype} The datatype of the uniform.
1448
+ * @function
1449
+ * @alias Uniform#getDatatype
1450
+ *
1451
+ * @see UniformDatatype
1452
+ *
1453
+ * @example
1454
+ * // GLSL: uniform mat4 u_mvp;
1455
+ * console.log(sp.getAllUniforms().u_mvp.getDatatype().name); // 'FLOAT_MATRIX4'
1456
+ */
1457
+ this.getDatatype = getUniformDatatype(_gl, activeUniform.type);
1458
+
1459
+ this._getLocation = function() {
1460
+ return _location;
1461
+ };
1462
+
1463
+ this._set = function() {
1464
+ switch (activeUniform.type) {
1465
+ case _gl.FLOAT:
1466
+ return function() {
1467
+ _gl.uniform1f(_location, this.value);
1468
+ };
1469
+ case _gl.FLOAT_VEC2:
1470
+ return function() {
1471
+ var v = this.value;
1472
+ _gl.uniform2f(_location, v.x, v.y);
1473
+ };
1474
+ case _gl.FLOAT_VEC3:
1475
+ return function() {
1476
+ var v = this.value;
1477
+ _gl.uniform3f(_location, v.x, v.y, v.z);
1478
+ };
1479
+ case _gl.FLOAT_VEC4:
1480
+ return function() {
1481
+ var v = this.value;
1482
+
1483
+ if (typeof v.red !== 'undefined') {
1484
+ _gl.uniform4f(_location, v.red, v.green, v.blue, v.alpha);
1485
+ } else if (typeof v.x !== 'undefined') {
1486
+ _gl.uniform4f(_location, v.x, v.y, v.z, v.w);
1487
+ } else {
1488
+ throw new DeveloperError('Invalid vec4 value for uniform "' + activeUniform.name + '".');
1489
+ }
1490
+ };
1491
+ case _gl.SAMPLER_2D:
1492
+ case _gl.SAMPLER_CUBE:
1493
+ // See _setSampler()
1494
+ return undefined;
1495
+ case _gl.INT:
1496
+ case _gl.BOOL:
1497
+ return function() {
1498
+ _gl.uniform1i(_location, this.value);
1499
+ };
1500
+ case _gl.INT_VEC2:
1501
+ case _gl.BOOL_VEC2:
1502
+ return function() {
1503
+ var v = this.value;
1504
+ _gl.uniform2i(_location, v.x, v.y);
1505
+ };
1506
+ case _gl.INT_VEC3:
1507
+ case _gl.BOOL_VEC3:
1508
+ return function() {
1509
+ var v = this.value;
1510
+ _gl.uniform3i(_location, v.x, v.y, v.z);
1511
+ };
1512
+ case _gl.INT_VEC4:
1513
+ case _gl.BOOL_VEC4:
1514
+ return function() {
1515
+ var v = this.value;
1516
+ _gl.uniform4i(_location, v.x, v.y, v.z, v.w);
1517
+ };
1518
+ case _gl.FLOAT_MAT2:
1519
+ return function() {
1520
+ _gl.uniformMatrix2fv(_location, false, Matrix2.toArray(this.value));
1521
+ };
1522
+ case _gl.FLOAT_MAT3:
1523
+ return function() {
1524
+ _gl.uniformMatrix3fv(_location, false, Matrix3.toArray(this.value));
1525
+ };
1526
+ case _gl.FLOAT_MAT4:
1527
+ return function() {
1528
+ _gl.uniformMatrix4fv(_location, false, Matrix4.toArray(this.value));
1529
+ };
1530
+ default:
1531
+ throw new RuntimeError('Unrecognized uniform type: ' + activeUniform.type + ' for uniform "' + activeUniform.name + '".');
1532
+ }
1533
+ }();
1534
+
1535
+ if ((activeUniform.type === _gl.SAMPLER_2D) || (activeUniform.type === _gl.SAMPLER_CUBE)) {
1536
+ this._setSampler = function(textureUnitIndex) {
1537
+ _gl.activeTexture(_gl.TEXTURE0 + textureUnitIndex);
1538
+ _gl.bindTexture(this.value._getTarget(), this.value._getTexture());
1539
+ _gl.uniform1i(_location, textureUnitIndex);
1540
+
1541
+ return textureUnitIndex + 1;
1542
+ };
1543
+
1544
+ this._clearSampler = function(textureUnitIndex) {
1545
+ _gl.activeTexture(_gl.TEXTURE0 + textureUnitIndex);
1546
+ _gl.bindTexture(this.value._getTarget(), null);
1547
+
1548
+ return textureUnitIndex + 1;
1549
+ };
1550
+ }
1551
+ };
1552
+
1553
+ /**
1554
+ * Uniform and UniformArray have the same documentation. It is just an implementation
1555
+ * detail that they are two different types.
1556
+ *
1557
+ * @alias UniformArray
1558
+ * @constructor
1559
+ *
1560
+ * @see Uniform
1561
+ */
1562
+ var UniformArray = function(_gl, activeUniform, _uniformName, locations, value) {
1563
+ this.value = value;
1564
+
1565
+ var _locations = locations;
1566
+
1567
+ /**
1568
+ * @private
1569
+ */
1570
+ this.getName = function() {
1571
+ return _uniformName;
1572
+ };
1573
+
1574
+ this.getDatatype = getUniformDatatype(_gl, activeUniform.type);
1575
+
1576
+ this._getLocations = function() {
1577
+ return _locations;
1578
+ };
1579
+
1580
+ this._set = function() {
1581
+ switch (activeUniform.type) {
1582
+ case _gl.FLOAT:
1583
+ return function() {
1584
+ for ( var i = 0; i < _locations.length; ++i) {
1585
+ _gl.uniform1f(_locations[i], this.value[i]);
1586
+ }
1587
+ };
1588
+ case _gl.FLOAT_VEC2:
1589
+ return function() {
1590
+ for ( var i = 0; i < _locations.length; ++i) {
1591
+ var v = this.value[i];
1592
+ _gl.uniform2f(_locations[i], v.x, v.y);
1593
+ }
1594
+ };
1595
+ case _gl.FLOAT_VEC3:
1596
+ return function() {
1597
+ for ( var i = 0; i < _locations.length; ++i) {
1598
+ var v = this.value[i];
1599
+ _gl.uniform3f(_locations[i], v.x, v.y, v.z);
1600
+ }
1601
+ };
1602
+ case _gl.FLOAT_VEC4:
1603
+ return function() {
1604
+ for ( var i = 0; i < _locations.length; ++i) {
1605
+ var v = this.value[i];
1606
+
1607
+ if (typeof v.red !== 'undefined') {
1608
+ _gl.uniform4f(_locations[i], v.red, v.green, v.blue, v.alpha);
1609
+ } else if (typeof v.x !== 'undefined') {
1610
+ _gl.uniform4f(_locations[i], v.x, v.y, v.z, v.w);
1611
+ } else {
1612
+ throw new DeveloperError('Invalid vec4 value.');
1613
+ }
1614
+ }
1615
+ };
1616
+ case _gl.SAMPLER_2D:
1617
+ case _gl.SAMPLER_CUBE:
1618
+ // See _setSampler()
1619
+ return undefined;
1620
+ case _gl.INT:
1621
+ case _gl.BOOL:
1622
+ return function() {
1623
+ for ( var i = 0; i < _locations.length; ++i) {
1624
+ _gl.uniform1i(_locations[i], this.value[i]);
1625
+ }
1626
+ };
1627
+ case _gl.INT_VEC2:
1628
+ case _gl.BOOL_VEC2:
1629
+ return function() {
1630
+ for ( var i = 0; i < _locations.length; ++i) {
1631
+ var v = this.value[i];
1632
+ _gl.uniform2i(_locations[i], v.x, v.y);
1633
+ }
1634
+ };
1635
+ case _gl.INT_VEC3:
1636
+ case _gl.BOOL_VEC3:
1637
+ return function() {
1638
+ for ( var i = 0; i < _locations.length; ++i) {
1639
+ var v = this.value[i];
1640
+ _gl.uniform3i(_locations[i], v.x, v.y, v.z);
1641
+ }
1642
+ };
1643
+ case _gl.INT_VEC4:
1644
+ case _gl.BOOL_VEC4:
1645
+ return function() {
1646
+ for ( var i = 0; i < _locations.length; ++i) {
1647
+ var v = this.value[i];
1648
+ _gl.uniform4i(_locations[i], v.x, v.y, v.z, v.w);
1649
+ }
1650
+ };
1651
+ case _gl.FLOAT_MAT2:
1652
+ return function() {
1653
+ for ( var i = 0; i < _locations.length; ++i) {
1654
+ _gl.uniformMatrix2fv(_locations[i], false, Matrix2.toArray(this.value[i]));
1655
+ }
1656
+ };
1657
+ case _gl.FLOAT_MAT3:
1658
+ return function() {
1659
+ for ( var i = 0; i < _locations.length; ++i) {
1660
+ _gl.uniformMatrix3fv(_locations[i], false, Matrix3.toArray(this.value[i]));
1661
+ }
1662
+ };
1663
+ case _gl.FLOAT_MAT4:
1664
+ return function() {
1665
+ for ( var i = 0; i < _locations.length; ++i) {
1666
+ _gl.uniformMatrix4fv(_locations[i], false, Matrix4.toArray(this.value[i]));
1667
+ }
1668
+ };
1669
+ default:
1670
+ throw new RuntimeError('Unrecognized uniform type: ' + activeUniform.type);
1671
+ }
1672
+ }();
1673
+
1674
+ if ((activeUniform.type === _gl.SAMPLER_2D) || (activeUniform.type === _gl.SAMPLER_CUBE)) {
1675
+ this._setSampler = function(textureUnitIndex) {
1676
+ for ( var i = 0; i < _locations.length; ++i) {
1677
+ var value = this.value[i];
1678
+ var index = textureUnitIndex + i;
1679
+ _gl.activeTexture(_gl.TEXTURE0 + index);
1680
+ _gl.bindTexture(value._getTarget(), value._getTexture());
1681
+ _gl.uniform1i(_locations[i], index);
1682
+ }
1683
+
1684
+ return textureUnitIndex + _locations.length;
1685
+ };
1686
+
1687
+ this._clearSampler = function(textureUnitIndex) {
1688
+ for ( var i = 0; i < _locations.length; ++i) {
1689
+ _gl.activeTexture(_gl.TEXTURE0 + textureUnitIndex + i);
1690
+ _gl.bindTexture(this.value[i]._getTarget(), null);
1691
+ }
1692
+
1693
+ return textureUnitIndex + _locations.length;
1694
+ };
1695
+ }
1696
+ };
1697
+
1698
+ /**
1699
+ * DOC_TBA
1700
+ *
1701
+ * @alias ShaderProgram
1702
+ * @internalConstructor
1703
+ *
1704
+ * @see Context#createShaderProgram
1705
+ * @see Context#getShaderCache
1706
+ */
1707
+ var ShaderProgram = function(gl, logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations) {
1708
+ var program = createAndLinkProgram(gl, logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations);
1709
+ var numberOfVertexAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
1710
+ var uniforms = findUniforms(gl, program);
1711
+ var partitionedUniforms = partitionUniforms(uniforms.allUniforms);
1712
+
1713
+ this._gl = gl;
1714
+ this._program = program;
1715
+ this._numberOfVertexAttributes = numberOfVertexAttributes;
1716
+ this._vertexAttributes = findVertexAttributes(gl, program, numberOfVertexAttributes);
1717
+ this._allUniforms = uniforms.allUniforms;
1718
+ this._uniforms = uniforms.uniforms;
1719
+ this._samplerUniforms = uniforms.samplerUniforms;
1720
+ this._automaticUniforms = partitionedUniforms.automaticUniforms;
1721
+ this._manualUniforms = partitionedUniforms.manualUniforms;
1722
+ };
1723
+
1724
+ function extractShaderVersion(source) {
1725
+ // This will fail if the first #version is actually in a comment.
1726
+ var index = source.indexOf('#version');
1727
+ if (index !== -1) {
1728
+ var newLineIndex = source.indexOf('\n', index);
1729
+
1730
+ // We could throw an exception if there is not a new line after
1731
+ // #version, but the GLSL compiler will catch it.
1732
+ if (index !== -1) {
1733
+ // Extract #version directive, including the new line.
1734
+ var version = source.substring(index, newLineIndex + 1);
1735
+
1736
+ // Comment out original #version directive so the line numbers
1737
+ // are not off by one. There can be only one #version directive
1738
+ // and it must appear at the top of the source, only preceded by
1739
+ // whitespace and comments.
1740
+ var modified = source.substring(0, index) + '//' + source.substring(index);
1741
+
1742
+ return {
1743
+ versionDirective : version,
1744
+ modifiedSource : modified
1745
+ };
1746
+ }
1747
+ }
1748
+
1749
+ return {
1750
+ versionDirective : '', // defaults to #version 100
1751
+ modifiedSource : source // no modifications required
1752
+ };
1753
+ }
1754
+
1755
+ function getAutomaticUniformDeclaration(uniforms, uniform) {
1756
+ var automaticUniform = uniforms[uniform];
1757
+ var declaration = 'uniform ' + automaticUniform.getDatatype().getGLSL() + ' ' + uniform;
1758
+
1759
+ var size = automaticUniform.getSize();
1760
+ if (size === 1) {
1761
+ declaration += ';';
1762
+ } else {
1763
+ declaration += '[' + size.toString() + '];';
1764
+ }
1765
+
1766
+ return declaration;
1767
+ }
1768
+
1769
+ function commentOutAutomaticUniforms(source) {
1770
+ // Comment out automatic uniforms that the user may have declared, perhaps
1771
+ // because the shader was authored in a third-party tool like RenderMonkey.
1772
+ // At runtime, all automatic uniforms are declared by the engine itself.
1773
+
1774
+ // This function has problems if the automatic uniform was declared with the
1775
+ // wrong datatype or with extra whitespace or comments in the declaration.
1776
+
1777
+ var modifiedSource = source;
1778
+ var uniforms = allAutomaticUniforms;
1779
+ for ( var uniform in uniforms) {
1780
+ if (uniforms.hasOwnProperty(uniform)) {
1781
+ var declaration = getAutomaticUniformDeclaration(uniforms, uniform);
1782
+ var index = modifiedSource.indexOf(declaration);
1783
+ if (index !== -1) {
1784
+ modifiedSource =
1785
+ modifiedSource.substring(0, index) +
1786
+ '/*' +
1787
+ modifiedSource.substring(index, declaration.length) +
1788
+ '*/' +
1789
+ modifiedSource.substring(index + declaration.length);
1790
+ }
1791
+ }
1792
+ }
1793
+
1794
+ return modifiedSource;
1795
+ }
1796
+
1797
+ function getFragmentShaderPrecision() {
1798
+ // TODO: Performance?
1799
+ return '#ifdef GL_FRAGMENT_PRECISION_HIGH \n' +
1800
+ ' precision highp float; \n' +
1801
+ '#else \n' +
1802
+ ' precision mediump float; \n' +
1803
+ '#endif \n\n';
1804
+ }
1805
+
1806
+ function getBuiltinConstants() {
1807
+ var constants = {
1808
+ /**
1809
+ * A built-in GLSL floating-point constant for <code>Math.PI</code>.
1810
+ *
1811
+ * @alias czm_pi
1812
+ * @glslConstant
1813
+ *
1814
+ * @see CesiumMath.PI
1815
+ *
1816
+ * @example
1817
+ * // GLSL declaration
1818
+ * const float czm_pi = ...;
1819
+ *
1820
+ * // Example
1821
+ * float twoPi = 2.0 * czm_pi;
1822
+ */
1823
+ czm_pi : Math.PI.toString(),
1824
+
1825
+ /**
1826
+ * A built-in GLSL floating-point constant for <code>1/pi</code>.
1827
+ *
1828
+ * @alias czm_oneOverPi
1829
+ * @glslConstant
1830
+ *
1831
+ * @see CesiumMath.ONE_OVER_PI
1832
+ *
1833
+ * @example
1834
+ * // GLSL declaration
1835
+ * const float czm_oneOverPi = ...;
1836
+ *
1837
+ * // Example
1838
+ * float pi = 1.0 / czm_oneOverPi;
1839
+ */
1840
+ czm_oneOverPi : CesiumMath.ONE_OVER_PI.toString(),
1841
+
1842
+ /**
1843
+ * A built-in GLSL floating-point constant for <code>pi/2</code>.
1844
+ *
1845
+ * @alias czm_piOverTwo
1846
+ * @glslConstant
1847
+ *
1848
+ * @see CesiumMath.PI_OVER_TWO
1849
+ *
1850
+ * @example
1851
+ * // GLSL declaration
1852
+ * const float czm_piOverTwo = ...;
1853
+ *
1854
+ * // Example
1855
+ * float pi = 2.0 * czm_piOverTwo;
1856
+ */
1857
+ czm_piOverTwo : CesiumMath.PI_OVER_TWO.toString(),
1858
+
1859
+ /**
1860
+ * A built-in GLSL floating-point constant for <code>pi/3</code>.
1861
+ *
1862
+ * @alias czm_piOverThree
1863
+ * @glslConstant
1864
+ *
1865
+ * @see CesiumMath.PI_OVER_THREE
1866
+ *
1867
+ * @example
1868
+ * // GLSL declaration
1869
+ * const float czm_piOverThree = ...;
1870
+ *
1871
+ * // Example
1872
+ * float pi = 3.0 * czm_piOverThree;
1873
+ */
1874
+ czm_piOverThree : CesiumMath.PI_OVER_THREE.toString(),
1875
+
1876
+ /**
1877
+ * A built-in GLSL floating-point constant for <code>pi/4</code>.
1878
+ *
1879
+ * @alias czm_piOverFour
1880
+ * @glslConstant
1881
+ *
1882
+ * @see CesiumMath.PI_OVER_FOUR
1883
+ *
1884
+ * @example
1885
+ * // GLSL declaration
1886
+ * const float czm_piOverFour = ...;
1887
+ *
1888
+ * // Example
1889
+ * float pi = 4.0 * czm_piOverFour;
1890
+ */
1891
+ czm_piOverFour : CesiumMath.PI_OVER_FOUR.toString(),
1892
+
1893
+ /**
1894
+ * A built-in GLSL floating-point constant for <code>pi/6</code>.
1895
+ *
1896
+ * @alias czm_piOverSix
1897
+ * @glslConstant
1898
+ *
1899
+ * @see CesiumMath.PI_OVER_SIX
1900
+ *
1901
+ * @example
1902
+ * // GLSL declaration
1903
+ * const float czm_piOverSix = ...;
1904
+ *
1905
+ * // Example
1906
+ * float pi = 6.0 * czm_piOverSix;
1907
+ */
1908
+ czm_piOverSix : CesiumMath.PI_OVER_SIX.toString(),
1909
+
1910
+ /**
1911
+ * A built-in GLSL floating-point constant for <code>3pi/2</code>.
1912
+ *
1913
+ * @alias czm_threePiOver2
1914
+ * @glslConstant
1915
+ *
1916
+ * @see CesiumMath.THREE_PI_OVER_TWO
1917
+ *
1918
+ * @example
1919
+ * // GLSL declaration
1920
+ * const float czm_threePiOver2 = ...;
1921
+ *
1922
+ * // Example
1923
+ * float pi = (2.0 / 3.0) * czm_threePiOver2;
1924
+ */
1925
+ czm_threePiOver2 : CesiumMath.THREE_PI_OVER_TWO.toString(),
1926
+
1927
+ /**
1928
+ * A built-in GLSL floating-point constant for <code>2pi</code>.
1929
+ *
1930
+ * @alias czm_twoPi
1931
+ * @glslConstant
1932
+ *
1933
+ * @see CesiumMath.TWO_PI
1934
+ *
1935
+ * @example
1936
+ * // GLSL declaration
1937
+ * const float czm_twoPi = ...;
1938
+ *
1939
+ * // Example
1940
+ * float pi = czm_twoPi / 2.0;
1941
+ */
1942
+ czm_twoPi : CesiumMath.TWO_PI.toString(),
1943
+
1944
+ /**
1945
+ * A built-in GLSL floating-point constant for <code>1/2pi</code>.
1946
+ *
1947
+ * @alias czm_oneOverTwoPi
1948
+ * @glslConstant
1949
+ *
1950
+ * @see CesiumMath.ONE_OVER_TWO_PI
1951
+ *
1952
+ * @example
1953
+ * // GLSL declaration
1954
+ * const float czm_oneOverTwoPi = ...;
1955
+ *
1956
+ * // Example
1957
+ * float pi = 2.0 * czm_oneOverTwoPi;
1958
+ */
1959
+ czm_oneOverTwoPi : CesiumMath.ONE_OVER_TWO_PI.toString(),
1960
+
1961
+ /**
1962
+ * A built-in GLSL floating-point constant for converting degrees to radians.
1963
+ *
1964
+ * @alias czm_radiansPerDegree
1965
+ * @glslConstant
1966
+ *
1967
+ * @see CesiumMath.RADIANS_PER_DEGREE
1968
+ *
1969
+ * @example
1970
+ * // GLSL declaration
1971
+ * const float czm_radiansPerDegree = ...;
1972
+ *
1973
+ * // Example
1974
+ * float rad = czm_radiansPerDegree * deg;
1975
+ */
1976
+ czm_radiansPerDegree : CesiumMath.RADIANS_PER_DEGREE.toString(),
1977
+
1978
+ /**
1979
+ * A built-in GLSL floating-point constant for converting radians to degrees.
1980
+ *
1981
+ * @alias czm_degreesPerRadian
1982
+ * @glslConstant
1983
+ *
1984
+ * @see CesiumMath.DEGREES_PER_RADIAN
1985
+ *
1986
+ * @example
1987
+ * // GLSL declaration
1988
+ * const float czm_degreesPerRadian = ...;
1989
+ *
1990
+ * // Example
1991
+ * float deg = czm_degreesPerRadian * rad;
1992
+ */
1993
+ czm_degreesPerRadian : CesiumMath.DEGREES_PER_RADIAN.toString()
1994
+ };
1995
+
1996
+ var glslConstants = '';
1997
+ for ( var name in constants) {
1998
+ if (constants.hasOwnProperty(name)) {
1999
+ glslConstants += 'const float ' + name + ' = ' + constants[name] + '; \n';
2000
+ }
2001
+ }
2002
+ glslConstants += ' \n';
2003
+
2004
+ return glslConstants;
2005
+ }
2006
+
2007
+ function getAutomaticUniforms() {
2008
+ var automatics = '';
2009
+
2010
+ var uniforms = allAutomaticUniforms;
2011
+ for ( var uniform in uniforms) {
2012
+ if (uniforms.hasOwnProperty(uniform)) {
2013
+ automatics += getAutomaticUniformDeclaration(uniforms, uniform) + ' \n';
2014
+ }
2015
+ }
2016
+ automatics += '\n';
2017
+
2018
+ return automatics;
2019
+ }
2020
+
2021
+ var getShaderDefinitions = function() {
2022
+ // I think this should be #line 1 given what the GL ES spec says:
2023
+ //
2024
+ // After processing this directive (including its new-line), the implementation will
2025
+ // behave as if the following line has line number line...
2026
+ //
2027
+ // But this works, at least on NVIDIA hardware.
2028
+
2029
+ // Functions after constants and uniforms because functions depend on them.
2030
+ var definitions = getBuiltinConstants() +
2031
+ getAutomaticUniforms() +
2032
+ ShadersBuiltinFunctions + '\n\n' +
2033
+ '#line 0 \n';
2034
+
2035
+ getShaderDefinitions = function() {
2036
+ return definitions;
2037
+ };
2038
+
2039
+ return definitions;
2040
+ };
2041
+
2042
+ function createAndLinkProgram(gl, logShaderCompilation, vertexShaderSource, fragmentShaderSource, attributeLocations) {
2043
+ var vsSourceVersioned = extractShaderVersion(vertexShaderSource);
2044
+ var fsSourceVersioned = extractShaderVersion(fragmentShaderSource);
2045
+
2046
+ var vsSource = vsSourceVersioned.versionDirective +
2047
+ getShaderDefinitions() +
2048
+ commentOutAutomaticUniforms(vsSourceVersioned.modifiedSource);
2049
+ var fsSource = fsSourceVersioned.versionDirective +
2050
+ getFragmentShaderPrecision() +
2051
+ getShaderDefinitions() +
2052
+ commentOutAutomaticUniforms(fsSourceVersioned.modifiedSource);
2053
+
2054
+ var vertexShader = gl.createShader(gl.VERTEX_SHADER);
2055
+ gl.shaderSource(vertexShader, vsSource);
2056
+ gl.compileShader(vertexShader);
2057
+ var vsLog = gl.getShaderInfoLog(vertexShader);
2058
+
2059
+ if (logShaderCompilation && vsLog && vsLog.length) {
2060
+ console.log('[GL] Vertex shader compile log: ' + vsLog);
2061
+ }
2062
+
2063
+ if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
2064
+ gl.deleteShader(vertexShader);
2065
+ console.error('[GL] Vertex shader compile log: ' + vsLog);
2066
+ throw new RuntimeError('Vertex shader failed to compile. Compile log: ' + vsLog);
2067
+ }
2068
+
2069
+ var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
2070
+ gl.shaderSource(fragmentShader, fsSource);
2071
+ gl.compileShader(fragmentShader);
2072
+ var fsLog = gl.getShaderInfoLog(fragmentShader);
2073
+
2074
+ if (logShaderCompilation && fsLog && fsLog.length) {
2075
+ console.log('[GL] Fragment shader compile log: ' + fsLog);
2076
+ }
2077
+
2078
+ if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
2079
+ gl.deleteShader(vertexShader);
2080
+ gl.deleteShader(fragmentShader);
2081
+ console.error('[GL] Fragment shader compile log: ' + fsLog);
2082
+ throw new RuntimeError('Fragment shader failed to compile. Compile log: ' + fsLog);
2083
+ }
2084
+
2085
+ var program = gl.createProgram();
2086
+ gl.attachShader(program, vertexShader);
2087
+ gl.attachShader(program, fragmentShader);
2088
+
2089
+ gl.deleteShader(vertexShader);
2090
+ gl.deleteShader(fragmentShader);
2091
+
2092
+ if (attributeLocations) {
2093
+ for ( var attribute in attributeLocations) {
2094
+ if (attributeLocations.hasOwnProperty(attribute)) {
2095
+ gl.bindAttribLocation(program, attributeLocations[attribute], attribute);
2096
+ }
2097
+ }
2098
+ }
2099
+
2100
+ gl.linkProgram(program);
2101
+ var linkLog = gl.getProgramInfoLog(program);
2102
+
2103
+ if (logShaderCompilation && linkLog && linkLog.length) {
2104
+ console.log('[GL] Shader program link log: ' + linkLog);
2105
+ }
2106
+
2107
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
2108
+ gl.deleteProgram(program);
2109
+ console.error('[GL] Shader program link log: ' + linkLog);
2110
+ throw new RuntimeError('Program failed to link. Link log: ' + linkLog);
2111
+ }
2112
+
2113
+ return program;
2114
+ }
2115
+
2116
+ function findVertexAttributes(gl, program, numberOfAttributes) {
2117
+ var attributes = {};
2118
+ for ( var i = 0; i < numberOfAttributes; ++i) {
2119
+ var attr = gl.getActiveAttrib(program, i);
2120
+ var location = gl.getAttribLocation(program, attr.name);
2121
+
2122
+ attributes[attr.name] = {
2123
+ name : attr.name,
2124
+ type : attr.type,
2125
+ index : location
2126
+ };
2127
+ }
2128
+
2129
+ return attributes;
2130
+ }
2131
+
2132
+ function findUniforms(gl ,program) {
2133
+ var allUniforms = {};
2134
+ var uniforms = [];
2135
+ var samplerUniforms = [];
2136
+
2137
+ var numberOfUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
2138
+
2139
+ for ( var i = 0; i < numberOfUniforms; ++i) {
2140
+ var activeUniform = gl.getActiveUniform(program, i);
2141
+ var suffix = '[0]';
2142
+ var uniformName = activeUniform.name.indexOf(suffix, activeUniform.name.length - suffix.length) !== -1 ?
2143
+ activeUniform.name.slice(0, activeUniform.name.length - 3) : activeUniform.name;
2144
+
2145
+ // Ignore GLSL built-in uniforms returned in Firefox.
2146
+ if (uniformName.indexOf('gl_') !== 0) {
2147
+ if (activeUniform.name.indexOf('[') < 0) {
2148
+ // Single uniform
2149
+ var location = gl.getUniformLocation(program, uniformName);
2150
+ var uniformValue = gl.getUniform(program, location);
2151
+ var uniform = new Uniform(gl, activeUniform, uniformName, location, uniformValue);
2152
+
2153
+ allUniforms[uniformName] = uniform;
2154
+
2155
+ if (uniform._setSampler) {
2156
+ samplerUniforms.push(uniform);
2157
+ } else {
2158
+ uniforms.push(uniform);
2159
+ }
2160
+ } else {
2161
+ // Uniform array
2162
+
2163
+ var uniformArray;
2164
+ var locations;
2165
+ var value;
2166
+ var loc;
2167
+
2168
+ // On some platforms - Nexus 4 in Firefox for one - an array of sampler2D ends up being represented
2169
+ // as separate uniforms, one for each array element. Check for and handle that case.
2170
+ var indexOfBracket = uniformName.indexOf('[');
2171
+ if (indexOfBracket >= 0) {
2172
+ // We're assuming the array elements show up in numerical order - it seems to be true.
2173
+ uniformArray = allUniforms[uniformName.slice(0, indexOfBracket)];
2174
+ locations = uniformArray._getLocations();
2175
+
2176
+ // On the Nexus 4 in Chrome, we get one uniform per sampler, just like in Firefox,
2177
+ // but the size is not 1 like it is in Firefox. So if we push locations here,
2178
+ // we'll end up adding too many locations.
2179
+ if (locations.length <= 1) {
2180
+ value = uniformArray.value;
2181
+ loc = gl.getUniformLocation(program, uniformName);
2182
+ locations.push(loc);
2183
+ value.push(gl.getUniform(program, loc));
2184
+ }
2185
+ } else {
2186
+ locations = [];
2187
+ value = [];
2188
+ for ( var j = 0; j < activeUniform.size; ++j) {
2189
+ loc = gl.getUniformLocation(program, uniformName + '[' + j + ']');
2190
+ locations.push(loc);
2191
+ value.push(gl.getUniform(program, loc));
2192
+ }
2193
+ uniformArray = new UniformArray(gl, activeUniform, uniformName, locations, value);
2194
+
2195
+ allUniforms[uniformName] = uniformArray;
2196
+
2197
+ if (uniformArray._setSampler) {
2198
+ samplerUniforms.push(uniformArray);
2199
+ } else {
2200
+ uniforms.push(uniformArray);
2201
+ }
2202
+ }
2203
+ }
2204
+ }
2205
+ }
2206
+
2207
+ return {
2208
+ allUniforms : allUniforms,
2209
+ uniforms : uniforms,
2210
+ samplerUniforms : samplerUniforms
2211
+ };
2212
+ }
2213
+
2214
+ function partitionUniforms(uniforms) {
2215
+ var automaticUniforms = [];
2216
+ var manualUniforms = {};
2217
+
2218
+ for (var uniform in uniforms) {
2219
+ if (uniforms.hasOwnProperty(uniform)) {
2220
+ var automaticUniform = allAutomaticUniforms[uniform];
2221
+ if (automaticUniform) {
2222
+ automaticUniforms.push({
2223
+ uniform : uniforms[uniform],
2224
+ automaticUniform : automaticUniform
2225
+ });
2226
+ } else {
2227
+ manualUniforms[uniform] = uniforms[uniform];
2228
+ }
2229
+ }
2230
+ }
2231
+
2232
+ return {
2233
+ automaticUniforms : automaticUniforms,
2234
+ manualUniforms : manualUniforms
2235
+ };
2236
+ }
2237
+
2238
+ /**
2239
+ * DOC_TBA
2240
+ * @memberof ShaderProgram
2241
+ *
2242
+ * @return {Object} DOC_TBA
2243
+ * @exception {DeveloperError} This shader program was destroyed, i.e., destroy() was called.
2244
+ */
2245
+ ShaderProgram.prototype.getVertexAttributes = function() {
2246
+ return this._vertexAttributes;
2247
+ };
2248
+
2249
+ /**
2250
+ * DOC_TBA
2251
+ * @memberof ShaderProgram
2252
+ *
2253
+ * @return {Number} DOC_TBA
2254
+ * @exception {DeveloperError} This shader program was destroyed, i.e., destroy() was called.
2255
+ */
2256
+ ShaderProgram.prototype.getNumberOfVertexAttributes = function() {
2257
+ return this._numberOfVertexAttributes;
2258
+ };
2259
+
2260
+ /**
2261
+ * DOC_TBA
2262
+ * @memberof ShaderProgram
2263
+ *
2264
+ * @return {Object} DOC_TBA
2265
+ *
2266
+ * @exception {DeveloperError} This shader program was destroyed, i.e., destroy() was called.
2267
+ *
2268
+ * @see ShaderProgram#getManualUniforms
2269
+ */
2270
+ ShaderProgram.prototype.getAllUniforms = function() {
2271
+ return this._allUniforms;
2272
+ };
2273
+
2274
+ /**
2275
+ * DOC_TBA
2276
+ * @memberof ShaderProgram
2277
+ *
2278
+ * @exception {DeveloperError} This shader program was destroyed, i.e., destroy() was called.
2279
+ *
2280
+ * @see ShaderProgram#getAllUniforms
2281
+ */
2282
+ ShaderProgram.prototype.getManualUniforms = function() {
2283
+ return this._manualUniforms;
2284
+ };
2285
+
2286
+ ShaderProgram.prototype._bind = function() {
2287
+ this._gl.useProgram(this._program);
2288
+ };
2289
+
2290
+ ShaderProgram.prototype._unBind = function() {
2291
+ this._gl.useProgram(null);
2292
+
2293
+ var samplerUniforms = this._samplerUniforms;
2294
+ var textureUnitIndex = 0;
2295
+ var len = samplerUniforms.length;
2296
+ for ( var i = 0; i < len; ++i) {
2297
+ textureUnitIndex = samplerUniforms[i]._clearSampler(textureUnitIndex);
2298
+ }
2299
+ };
2300
+
2301
+ ShaderProgram.prototype._setUniforms = function(uniformMap, uniformState, validate) {
2302
+ // TODO: Performance
2303
+
2304
+ var len;
2305
+ var i;
2306
+
2307
+ var uniforms = this._uniforms;
2308
+ var samplerUniforms = this._samplerUniforms;
2309
+ var manualUniforms = this._manualUniforms;
2310
+ var automaticUniforms = this._automaticUniforms;
2311
+
2312
+ if (uniformMap) {
2313
+ for (var uniform in manualUniforms) {
2314
+ if (manualUniforms.hasOwnProperty(uniform)) {
2315
+ manualUniforms[uniform].value = uniformMap[uniform]();
2316
+ }
2317
+ }
2318
+ }
2319
+
2320
+ len = automaticUniforms.length;
2321
+ for (i = 0; i < len; ++i) {
2322
+ automaticUniforms[i].uniform.value = automaticUniforms[i].automaticUniform.getValue(uniformState);
2323
+ }
2324
+
2325
+ ///////////////////////////////////////////////////////////////////
2326
+
2327
+ len = uniforms.length;
2328
+ for (i = 0; i < len; ++i) {
2329
+ uniforms[i]._set();
2330
+ }
2331
+
2332
+ var textureUnitIndex = 0;
2333
+ len = samplerUniforms.length;
2334
+ for (i = 0; i < len; ++i) {
2335
+ textureUnitIndex = samplerUniforms[i]._setSampler(textureUnitIndex);
2336
+ }
2337
+
2338
+ if (validate) {
2339
+ var gl = this._gl;
2340
+ var program = this._program;
2341
+
2342
+ gl.validateProgram(program);
2343
+ if (!gl.getProgramParameter(program, gl.VALIDATE_STATUS)) {
2344
+ throw new DeveloperError('Program validation failed. Link log: ' + gl.getProgramInfoLog(program));
2345
+ }
2346
+ }
2347
+ };
2348
+
2349
+ /**
2350
+ * Returns true if this object was destroyed; otherwise, false.
2351
+ * <br /><br />
2352
+ * If this object was destroyed, it should not be used; calling any function other than
2353
+ * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
2354
+ * @memberof ShaderProgram
2355
+ *
2356
+ * @return {Boolean} True if this object was destroyed; otherwise, false.
2357
+ *
2358
+ * @see ShaderProgram#destroy
2359
+ */
2360
+ ShaderProgram.prototype.isDestroyed = function() {
2361
+ return false;
2362
+ };
2363
+
2364
+ /**
2365
+ * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
2366
+ * release of WebGL resources, instead of relying on the garbage collector to destroy this object.
2367
+ * <br /><br />
2368
+ * Once an object is destroyed, it should not be used; calling any function other than
2369
+ * <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
2370
+ * assign the return value (<code>undefined</code>) to the object as done in the example.
2371
+ * @memberof ShaderProgram
2372
+ *
2373
+ * @return {undefined}
2374
+ *
2375
+ * @exception {DeveloperError} This shader program was destroyed, i.e., destroy() was called.
2376
+ *
2377
+ * @see ShaderProgram#isDestroyed
2378
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glDeleteShader.xml'>glDeleteShader</a>
2379
+ * @see <a href='http://www.khronos.org/opengles/sdk/2.0/docs/man/glDeleteProgram.xml'>glDeleteProgram</a>
2380
+ *
2381
+ * @example
2382
+ * shaderProgram = shaderProgram && shaderProgram.destroy();
2383
+ */
2384
+ ShaderProgram.prototype.destroy = function() {
2385
+ this._gl.deleteProgram(this._program);
2386
+ return destroyObject(this);
2387
+ };
2388
+
2389
+ /**
2390
+ * DOC_TBA
2391
+ * @memberof ShaderProgram
2392
+ */
2393
+ ShaderProgram.prototype.release = function() {
2394
+ if (this._cachedShader) {
2395
+ return this._cachedShader.cache.releaseShaderProgram(this);
2396
+ }
2397
+
2398
+ return this.destroy();
2399
+ };
2400
+
2401
+ return ShaderProgram;
2402
+ });