RenderManager.java 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  1. /*
  2. * Copyright (c) 2009-2012 jMonkeyEngine
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are
  7. * met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. package com.jme3.renderer;
  33. import com.jme3.material.Material;
  34. import com.jme3.material.MaterialDef;
  35. import com.jme3.material.RenderState;
  36. import com.jme3.material.Technique;
  37. import com.jme3.math.*;
  38. import com.jme3.post.SceneProcessor;
  39. import com.jme3.renderer.queue.GeometryList;
  40. import com.jme3.renderer.queue.RenderQueue;
  41. import com.jme3.renderer.queue.RenderQueue.Bucket;
  42. import com.jme3.renderer.queue.RenderQueue.ShadowMode;
  43. import com.jme3.scene.*;
  44. import com.jme3.shader.Uniform;
  45. import com.jme3.shader.UniformBinding;
  46. import com.jme3.shader.VarType;
  47. import com.jme3.system.NullRenderer;
  48. import com.jme3.system.Timer;
  49. import com.jme3.util.TempVars;
  50. import java.util.ArrayList;
  51. import java.util.Collections;
  52. import java.util.List;
  53. import java.util.logging.Logger;
  54. /**
  55. * <code>RenderManager</code> is a high-level rendering interface that is
  56. * above the Renderer implementation. RenderManager takes care
  57. * of rendering the scene graphs attached to each viewport and
  58. * handling SceneProcessors.
  59. *
  60. * @see SceneProcessor
  61. * @see ViewPort
  62. * @see Spatial
  63. */
  64. public class RenderManager {
  65. private static final Logger logger = Logger.getLogger(RenderManager.class.getName());
  66. private Renderer renderer;
  67. private Timer timer;
  68. private ArrayList<ViewPort> preViewPorts = new ArrayList<ViewPort>();
  69. private ArrayList<ViewPort> viewPorts = new ArrayList<ViewPort>();
  70. private ArrayList<ViewPort> postViewPorts = new ArrayList<ViewPort>();
  71. private Camera prevCam = null;
  72. private Material forcedMaterial = null;
  73. private String forcedTechnique = null;
  74. private RenderState forcedRenderState = null;
  75. private boolean shader;
  76. private int viewX, viewY, viewWidth, viewHeight;
  77. private float near, far;
  78. private Matrix4f orthoMatrix = new Matrix4f();
  79. private Matrix4f viewMatrix = new Matrix4f();
  80. private Matrix4f projMatrix = new Matrix4f();
  81. private Matrix4f viewProjMatrix = new Matrix4f();
  82. private Matrix4f worldMatrix = new Matrix4f();
  83. private Vector3f camUp = new Vector3f(),
  84. camLeft = new Vector3f(),
  85. camDir = new Vector3f(),
  86. camLoc = new Vector3f();
  87. //temp technique
  88. private String tmpTech;
  89. private boolean handleTranlucentBucket = true;
  90. /**
  91. * Create a high-level rendering interface over the
  92. * low-level rendering interface.
  93. * @param renderer
  94. */
  95. public RenderManager(Renderer renderer) {
  96. this.renderer = renderer;
  97. //this.shader = renderer.getCaps().contains(Caps.GLSL100);
  98. }
  99. /**
  100. * Returns the pre ViewPort with the given name.
  101. *
  102. * @param viewName The name of the pre ViewPort to look up
  103. * @return The ViewPort, or null if not found.
  104. *
  105. * @see #createPreView(java.lang.String, com.jme3.renderer.Camera)
  106. */
  107. public ViewPort getPreView(String viewName) {
  108. for (int i = 0; i < preViewPorts.size(); i++) {
  109. if (preViewPorts.get(i).getName().equals(viewName)) {
  110. return preViewPorts.get(i);
  111. }
  112. }
  113. return null;
  114. }
  115. /**
  116. * Removes the specified pre ViewPort.
  117. *
  118. * @param view The pre ViewPort to remove
  119. * @return True if the ViewPort was removed successfully.
  120. *
  121. * @see #createPreView(java.lang.String, com.jme3.renderer.Camera)
  122. */
  123. public boolean removePreView(ViewPort view) {
  124. return preViewPorts.remove(view);
  125. }
  126. /**
  127. * Returns the main ViewPort with the given name.
  128. *
  129. * @param viewName The name of the main ViewPort to look up
  130. * @return The ViewPort, or null if not found.
  131. *
  132. * @see #createMainView(java.lang.String, com.jme3.renderer.Camera)
  133. */
  134. public ViewPort getMainView(String viewName) {
  135. for (int i = 0; i < viewPorts.size(); i++) {
  136. if (viewPorts.get(i).getName().equals(viewName)) {
  137. return viewPorts.get(i);
  138. }
  139. }
  140. return null;
  141. }
  142. /**
  143. * Removes the main ViewPort with the specified name.
  144. *
  145. * @param viewName The main ViewPort name to remove
  146. * @return True if the ViewPort was removed successfully.
  147. *
  148. * @see #createMainView(java.lang.String, com.jme3.renderer.Camera)
  149. */
  150. public boolean removeMainView(String viewName) {
  151. for (int i = 0; i < viewPorts.size(); i++) {
  152. if (viewPorts.get(i).getName().equals(viewName)) {
  153. viewPorts.remove(i);
  154. return true;
  155. }
  156. }
  157. return false;
  158. }
  159. /**
  160. * Removes the specified main ViewPort.
  161. *
  162. * @param view The main ViewPort to remove
  163. * @return True if the ViewPort was removed successfully.
  164. *
  165. * @see #createMainView(java.lang.String, com.jme3.renderer.Camera)
  166. */
  167. public boolean removeMainView(ViewPort view) {
  168. return viewPorts.remove(view);
  169. }
  170. /**
  171. * Returns the post ViewPort with the given name.
  172. *
  173. * @param viewName The name of the post ViewPort to look up
  174. * @return The ViewPort, or null if not found.
  175. *
  176. * @see #createPostView(java.lang.String, com.jme3.renderer.Camera)
  177. */
  178. public ViewPort getPostView(String viewName) {
  179. for (int i = 0; i < postViewPorts.size(); i++) {
  180. if (postViewPorts.get(i).getName().equals(viewName)) {
  181. return postViewPorts.get(i);
  182. }
  183. }
  184. return null;
  185. }
  186. /**
  187. * Removes the post ViewPort with the specified name.
  188. *
  189. * @param viewName The post ViewPort name to remove
  190. * @return True if the ViewPort was removed successfully.
  191. *
  192. * @see #createPostView(java.lang.String, com.jme3.renderer.Camera)
  193. */
  194. public boolean removePostView(String viewName) {
  195. for (int i = 0; i < postViewPorts.size(); i++) {
  196. if (postViewPorts.get(i).getName().equals(viewName)) {
  197. postViewPorts.remove(i);
  198. return true;
  199. }
  200. }
  201. return false;
  202. }
  203. /**
  204. * Removes the specified post ViewPort.
  205. *
  206. * @param view The post ViewPort to remove
  207. * @return True if the ViewPort was removed successfully.
  208. *
  209. * @see #createPostView(java.lang.String, com.jme3.renderer.Camera)
  210. */
  211. public boolean removePostView(ViewPort view) {
  212. return postViewPorts.remove(view);
  213. }
  214. /**
  215. * Returns a read-only list of all pre ViewPorts
  216. * @return a read-only list of all pre ViewPorts
  217. * @see #createPreView(java.lang.String, com.jme3.renderer.Camera)
  218. */
  219. public List<ViewPort> getPreViews() {
  220. return Collections.unmodifiableList(preViewPorts);
  221. }
  222. /**
  223. * Returns a read-only list of all main ViewPorts
  224. * @return a read-only list of all main ViewPorts
  225. * @see #createMainView(java.lang.String, com.jme3.renderer.Camera)
  226. */
  227. public List<ViewPort> getMainViews() {
  228. return Collections.unmodifiableList(viewPorts);
  229. }
  230. /**
  231. * Returns a read-only list of all post ViewPorts
  232. * @return a read-only list of all post ViewPorts
  233. * @see #createPostView(java.lang.String, com.jme3.renderer.Camera)
  234. */
  235. public List<ViewPort> getPostViews() {
  236. return Collections.unmodifiableList(postViewPorts);
  237. }
  238. /**
  239. * Creates a new pre ViewPort, to display the given camera's content.
  240. * <p>
  241. * The view will be processed before the main and post viewports.
  242. */
  243. public ViewPort createPreView(String viewName, Camera cam) {
  244. ViewPort vp = new ViewPort(viewName, cam);
  245. preViewPorts.add(vp);
  246. return vp;
  247. }
  248. /**
  249. * Creates a new main ViewPort, to display the given camera's content.
  250. * <p>
  251. * The view will be processed before the post viewports but after
  252. * the pre viewports.
  253. */
  254. public ViewPort createMainView(String viewName, Camera cam) {
  255. ViewPort vp = new ViewPort(viewName, cam);
  256. viewPorts.add(vp);
  257. return vp;
  258. }
  259. /**
  260. * Creates a new post ViewPort, to display the given camera's content.
  261. * <p>
  262. * The view will be processed after the pre and main viewports.
  263. */
  264. public ViewPort createPostView(String viewName, Camera cam) {
  265. ViewPort vp = new ViewPort(viewName, cam);
  266. postViewPorts.add(vp);
  267. return vp;
  268. }
  269. private void notifyReshape(ViewPort vp, int w, int h) {
  270. List<SceneProcessor> processors = vp.getProcessors();
  271. for (SceneProcessor proc : processors) {
  272. if (!proc.isInitialized()) {
  273. proc.initialize(this, vp);
  274. } else {
  275. proc.reshape(vp, w, h);
  276. }
  277. }
  278. }
  279. /**
  280. * Internal use only.
  281. * Updates the resolution of all on-screen cameras to match
  282. * the given width and height.
  283. */
  284. public void notifyReshape(int w, int h) {
  285. for (ViewPort vp : preViewPorts) {
  286. if (vp.getOutputFrameBuffer() == null) {
  287. Camera cam = vp.getCamera();
  288. cam.resize(w, h, true);
  289. }
  290. notifyReshape(vp, w, h);
  291. }
  292. for (ViewPort vp : viewPorts) {
  293. if (vp.getOutputFrameBuffer() == null) {
  294. Camera cam = vp.getCamera();
  295. cam.resize(w, h, true);
  296. }
  297. notifyReshape(vp, w, h);
  298. }
  299. for (ViewPort vp : postViewPorts) {
  300. if (vp.getOutputFrameBuffer() == null) {
  301. Camera cam = vp.getCamera();
  302. cam.resize(w, h, true);
  303. }
  304. notifyReshape(vp, w, h);
  305. }
  306. }
  307. /**
  308. * Internal use only.
  309. * Updates the given list of uniforms with {@link UniformBinding uniform bindings}
  310. * based on the current world state.
  311. */
  312. public void updateUniformBindings(List<Uniform> params) {
  313. // assums worldMatrix is properly set.
  314. TempVars vars = TempVars.get();
  315. Matrix4f tempMat4 = vars.tempMat4;
  316. Matrix3f tempMat3 = vars.tempMat3;
  317. Vector2f tempVec2 = vars.vect2d;
  318. Quaternion tempVec4 = vars.quat1;
  319. for (int i = 0; i < params.size(); i++) {
  320. Uniform u = params.get(i);
  321. switch (u.getBinding()) {
  322. case WorldMatrix:
  323. u.setValue(VarType.Matrix4, worldMatrix);
  324. break;
  325. case ViewMatrix:
  326. u.setValue(VarType.Matrix4, viewMatrix);
  327. break;
  328. case ProjectionMatrix:
  329. u.setValue(VarType.Matrix4, projMatrix);
  330. break;
  331. case ViewProjectionMatrix:
  332. u.setValue(VarType.Matrix4, viewProjMatrix);
  333. break;
  334. case WorldViewMatrix:
  335. tempMat4.set(viewMatrix);
  336. tempMat4.multLocal(worldMatrix);
  337. u.setValue(VarType.Matrix4, tempMat4);
  338. break;
  339. case NormalMatrix:
  340. tempMat4.set(viewMatrix);
  341. tempMat4.multLocal(worldMatrix);
  342. tempMat4.toRotationMatrix(tempMat3);
  343. tempMat3.invertLocal();
  344. tempMat3.transposeLocal();
  345. u.setValue(VarType.Matrix3, tempMat3);
  346. break;
  347. case WorldViewProjectionMatrix:
  348. tempMat4.set(viewProjMatrix);
  349. tempMat4.multLocal(worldMatrix);
  350. u.setValue(VarType.Matrix4, tempMat4);
  351. break;
  352. case WorldMatrixInverse:
  353. tempMat4.set(worldMatrix);
  354. tempMat4.invertLocal();
  355. u.setValue(VarType.Matrix4, tempMat4);
  356. break;
  357. case WorldMatrixInverseTranspose:
  358. worldMatrix.toRotationMatrix(tempMat3);
  359. tempMat3.invertLocal().transposeLocal();
  360. u.setValue(VarType.Matrix3, tempMat3);
  361. break;
  362. case ViewMatrixInverse:
  363. tempMat4.set(viewMatrix);
  364. tempMat4.invertLocal();
  365. u.setValue(VarType.Matrix4, tempMat4);
  366. break;
  367. case ProjectionMatrixInverse:
  368. tempMat4.set(projMatrix);
  369. tempMat4.invertLocal();
  370. u.setValue(VarType.Matrix4, tempMat4);
  371. break;
  372. case ViewProjectionMatrixInverse:
  373. tempMat4.set(viewProjMatrix);
  374. tempMat4.invertLocal();
  375. u.setValue(VarType.Matrix4, tempMat4);
  376. break;
  377. case WorldViewMatrixInverse:
  378. tempMat4.set(viewMatrix);
  379. tempMat4.multLocal(worldMatrix);
  380. tempMat4.invertLocal();
  381. u.setValue(VarType.Matrix4, tempMat4);
  382. break;
  383. case NormalMatrixInverse:
  384. tempMat4.set(viewMatrix);
  385. tempMat4.multLocal(worldMatrix);
  386. tempMat4.toRotationMatrix(tempMat3);
  387. tempMat3.invertLocal();
  388. tempMat3.transposeLocal();
  389. tempMat3.invertLocal();
  390. u.setValue(VarType.Matrix3, tempMat3);
  391. break;
  392. case WorldViewProjectionMatrixInverse:
  393. tempMat4.set(viewProjMatrix);
  394. tempMat4.multLocal(worldMatrix);
  395. tempMat4.invertLocal();
  396. u.setValue(VarType.Matrix4, tempMat4);
  397. break;
  398. case ViewPort:
  399. tempVec4.set(viewX, viewY, viewWidth, viewHeight);
  400. u.setValue(VarType.Vector4, tempVec4);
  401. break;
  402. case Resolution:
  403. tempVec2.set(viewWidth, viewHeight);
  404. u.setValue(VarType.Vector2, tempVec2);
  405. break;
  406. case ResolutionInverse:
  407. tempVec2.set(1f / viewWidth, 1f / viewHeight);
  408. u.setValue(VarType.Vector2, tempVec2);
  409. break;
  410. case Aspect:
  411. float aspect = ((float) viewWidth) / viewHeight;
  412. u.setValue(VarType.Float, aspect);
  413. break;
  414. case FrustumNearFar:
  415. tempVec2.set(near, far);
  416. u.setValue(VarType.Vector2, tempVec2);
  417. break;
  418. case CameraPosition:
  419. u.setValue(VarType.Vector3, camLoc);
  420. break;
  421. case CameraDirection:
  422. u.setValue(VarType.Vector3, camDir);
  423. break;
  424. case CameraLeft:
  425. u.setValue(VarType.Vector3, camLeft);
  426. break;
  427. case CameraUp:
  428. u.setValue(VarType.Vector3, camUp);
  429. break;
  430. case Time:
  431. u.setValue(VarType.Float, timer.getTimeInSeconds());
  432. break;
  433. case Tpf:
  434. u.setValue(VarType.Float, timer.getTimePerFrame());
  435. break;
  436. case FrameRate:
  437. u.setValue(VarType.Float, timer.getFrameRate());
  438. break;
  439. }
  440. }
  441. vars.release();
  442. }
  443. /**
  444. * Set the material to use to render all future objects.
  445. * This overrides the material set on the geometry and renders
  446. * with the provided material instead.
  447. * Use null to clear the material and return renderer to normal
  448. * functionality.
  449. * @param mat The forced material to set, or null to return to normal
  450. */
  451. public void setForcedMaterial(Material mat) {
  452. forcedMaterial = mat;
  453. }
  454. /**
  455. * Returns the forced render state previously set with
  456. * {@link #setForcedRenderState(com.jme3.material.RenderState) }.
  457. * @return the forced render state
  458. */
  459. public RenderState getForcedRenderState() {
  460. return forcedRenderState;
  461. }
  462. /**
  463. * Set the render state to use for all future objects.
  464. * This overrides the render state set on the material and instead
  465. * forces this render state to be applied for all future materials
  466. * rendered. Set to null to return to normal functionality.
  467. *
  468. * @param forcedRenderState The forced render state to set, or null
  469. * to return to normal
  470. */
  471. public void setForcedRenderState(RenderState forcedRenderState) {
  472. this.forcedRenderState = forcedRenderState;
  473. }
  474. /**
  475. * Set the timer that should be used to query the time based
  476. * {@link UniformBinding}s for material world parameters.
  477. *
  478. * @param timer The timer to query time world parameters
  479. */
  480. public void setTimer(Timer timer) {
  481. this.timer = timer;
  482. }
  483. /**
  484. * Returns the forced technique name set.
  485. *
  486. * @return the forced technique name set.
  487. *
  488. * @see #setForcedTechnique(java.lang.String)
  489. */
  490. public String getForcedTechnique() {
  491. return forcedTechnique;
  492. }
  493. /**
  494. * Sets the forced technique to use when rendering geometries.
  495. * <p>
  496. * If the specified technique name is available on the geometry's
  497. * material, then it is used, otherwise, the
  498. * {@link #setForcedMaterial(com.jme3.material.Material) forced material} is used.
  499. * If a forced material is not set and the forced technique name cannot
  500. * be found on the material, the geometry will <em>not</em> be rendered.
  501. *
  502. * @param forcedTechnique The forced technique name to use, set to null
  503. * to return to normal functionality.
  504. *
  505. * @see #renderGeometry(com.jme3.scene.Geometry)
  506. */
  507. public void setForcedTechnique(String forcedTechnique) {
  508. this.forcedTechnique = forcedTechnique;
  509. }
  510. /**
  511. * Enable or disable alpha-to-coverage.
  512. * <p>
  513. * When alpha to coverage is enabled and the renderer implementation
  514. * supports it, then alpha blending will be replaced with alpha dissolve
  515. * if multi-sampling is also set on the renderer.
  516. * This feature allows avoiding of alpha blending artifacts due to
  517. * lack of triangle-level back-to-front sorting.
  518. *
  519. * @param value True to enable alpha-to-coverage, false otherwise.
  520. */
  521. public void setAlphaToCoverage(boolean value) {
  522. renderer.setAlphaToCoverage(value);
  523. }
  524. /**
  525. * True if the translucent bucket should automatically be rendered
  526. * by the RenderManager.
  527. *
  528. * @return Whether or not the translucent bucket is rendered.
  529. *
  530. * @see #setHandleTranslucentBucket(boolean)
  531. */
  532. public boolean isHandleTranslucentBucket() {
  533. return handleTranlucentBucket;
  534. }
  535. /**
  536. * Enable or disable rendering of the
  537. * {@link Bucket#Translucent translucent bucket}
  538. * by the RenderManager. The default is enabled.
  539. *
  540. * @param handleTranslucentBucket Whether or not the translucent bucket should
  541. * be rendered.
  542. */
  543. public void setHandleTranslucentBucket(boolean handleTranslucentBucket) {
  544. this.handleTranlucentBucket = handleTranslucentBucket;
  545. }
  546. /**
  547. * Internal use only. Sets the world matrix to use for future
  548. * rendering. This has no effect unless objects are rendered manually
  549. * using {@link Material#render(com.jme3.scene.Geometry, com.jme3.renderer.RenderManager) }.
  550. * Using {@link #renderGeometry(com.jme3.scene.Geometry) } will
  551. * override this value.
  552. *
  553. * @param mat The world matrix to set
  554. */
  555. public void setWorldMatrix(Matrix4f mat) {
  556. if (shader) {
  557. worldMatrix.set(mat);
  558. } else {
  559. renderer.setWorldMatrix(mat);
  560. }
  561. }
  562. /**
  563. * Renders the given geometry.
  564. * <p>
  565. * First the proper world matrix is set, if
  566. * the geometry's {@link Geometry#setIgnoreTransform(boolean) ignore transform}
  567. * feature is enabled, the identity world matrix is used, otherwise, the
  568. * geometry's {@link Geometry#getWorldMatrix() world transform matrix} is used.
  569. * <p>
  570. * Once the world matrix is applied, the proper material is chosen for rendering.
  571. * If a {@link #setForcedMaterial(com.jme3.material.Material) forced material} is
  572. * set on this RenderManager, then it is used for rendering the geometry,
  573. * otherwise, the {@link Geometry#getMaterial() geometry's material} is used.
  574. * <p>
  575. * If a {@link #setForcedTechnique(java.lang.String) forced technique} is
  576. * set on this RenderManager, then it is selected automatically
  577. * on the geometry's material and is used for rendering. Otherwise, one
  578. * of the {@link MaterialDef#getDefaultTechniques() default techniques} is
  579. * used.
  580. * <p>
  581. * If a {@link #setForcedRenderState(com.jme3.material.RenderState) forced
  582. * render state} is set on this RenderManager, then it is used
  583. * for rendering the material, and the material's own render state is ignored.
  584. * Otherwise, the material's render state is used as intended.
  585. *
  586. * @param g The geometry to render
  587. *
  588. * @see Technique
  589. * @see RenderState
  590. * @see Material#selectTechnique(java.lang.String, com.jme3.renderer.RenderManager)
  591. * @see Material#render(com.jme3.scene.Geometry, com.jme3.renderer.RenderManager)
  592. */
  593. public void renderGeometry(Geometry g) {
  594. if (g.isIgnoreTransform()) {
  595. setWorldMatrix(Matrix4f.IDENTITY);
  596. } else {
  597. setWorldMatrix(g.getWorldMatrix());
  598. }
  599. //if forcedTechnique we try to force it for render,
  600. //if it does not exists in the mat def, we check for forcedMaterial and render the geom if not null
  601. //else the geom is not rendered
  602. if (forcedTechnique != null) {
  603. if (g.getMaterial().getMaterialDef().getTechniqueDef(forcedTechnique) != null) {
  604. tmpTech = g.getMaterial().getActiveTechnique() != null ? g.getMaterial().getActiveTechnique().getDef().getName() : "Default";
  605. g.getMaterial().selectTechnique(forcedTechnique, this);
  606. // use geometry's material
  607. g.getMaterial().render(g, this);
  608. g.getMaterial().selectTechnique(tmpTech, this);
  609. //Reverted this part from revision 6197
  610. //If forcedTechnique does not exists, and frocedMaterial is not set, the geom MUST NOT be rendered
  611. } else if (forcedMaterial != null) {
  612. // use forced material
  613. forcedMaterial.render(g, this);
  614. }
  615. } else if (forcedMaterial != null) {
  616. // use forced material
  617. forcedMaterial.render(g, this);
  618. } else {
  619. g.getMaterial().render(g, this);
  620. }
  621. }
  622. /**
  623. * Renders the given GeometryList.
  624. * <p>
  625. * For every geometry in the list, the
  626. * {@link #renderGeometry(com.jme3.scene.Geometry) } method is called.
  627. *
  628. * @param gl The geometry list to render.
  629. *
  630. * @see GeometryList
  631. * @see #renderGeometry(com.jme3.scene.Geometry)
  632. */
  633. public void renderGeometryList(GeometryList gl) {
  634. for (int i = 0; i < gl.size(); i++) {
  635. renderGeometry(gl.get(i));
  636. }
  637. }
  638. /**
  639. * If a spatial is not inside the eye frustum, it
  640. * is still rendered in the shadow frustum (shadow casting queue)
  641. * through this recursive method.
  642. */
  643. private void renderShadow(Spatial s, RenderQueue rq) {
  644. if (s instanceof Node) {
  645. Node n = (Node) s;
  646. List<Spatial> children = n.getChildren();
  647. for (int i = 0; i < children.size(); i++) {
  648. renderShadow(children.get(i), rq);
  649. }
  650. } else if (s instanceof Geometry) {
  651. Geometry gm = (Geometry) s;
  652. RenderQueue.ShadowMode shadowMode = s.getShadowMode();
  653. if (shadowMode != RenderQueue.ShadowMode.Off && shadowMode != RenderQueue.ShadowMode.Receive) {
  654. //forcing adding to shadow cast mode, culled objects doesn't have to be in the receiver queue
  655. rq.addToShadowQueue(gm, RenderQueue.ShadowMode.Cast);
  656. }
  657. }
  658. }
  659. /**
  660. * Preloads a scene for rendering.
  661. * <p>
  662. * After invocation of this method, the underlying
  663. * renderer would have uploaded any textures, shaders and meshes
  664. * used by the given scene to the video driver.
  665. * Using this method is useful when wishing to avoid the initial pause
  666. * when rendering a scene for the first time. Note that it is not
  667. * guaranteed that the underlying renderer will actually choose to upload
  668. * the data to the GPU so some pause is still to be expected.
  669. *
  670. * @param scene The scene to preload
  671. */
  672. public void preloadScene(Spatial scene) {
  673. if (scene instanceof Node) {
  674. // recurse for all children
  675. Node n = (Node) scene;
  676. List<Spatial> children = n.getChildren();
  677. for (int i = 0; i < children.size(); i++) {
  678. preloadScene(children.get(i));
  679. }
  680. } else if (scene instanceof Geometry) {
  681. // add to the render queue
  682. Geometry gm = (Geometry) scene;
  683. if (gm.getMaterial() == null) {
  684. throw new IllegalStateException("No material is set for Geometry: " + gm.getName());
  685. }
  686. gm.getMaterial().preload(this);
  687. Mesh mesh = gm.getMesh();
  688. if (mesh != null) {
  689. for (VertexBuffer vb : mesh.getBufferList().getArray()) {
  690. if (vb.getData() != null) {
  691. renderer.updateBufferData(vb);
  692. }
  693. }
  694. }
  695. }
  696. }
  697. /**
  698. * Flattens the given scene graph into the ViewPort's RenderQueue,
  699. * checking for culling as the call goes down the graph recursively.
  700. * <p>
  701. * First, the scene is checked for culling based on the <code>Spatial</code>s
  702. * {@link Spatial#setCullHint(com.jme3.scene.Spatial.CullHint) cull hint},
  703. * if the camera frustum contains the scene, then this method is recursively
  704. * called on its children.
  705. * <p>
  706. * When the scene's leaves or {@link Geometry geometries} are reached,
  707. * they are each enqueued into the
  708. * {@link ViewPort#getQueue() ViewPort's render queue}.
  709. * <p>
  710. * In addition to enqueuing the visible geometries, this method
  711. * also scenes which cast or receive shadows, by putting them into the
  712. * RenderQueue's
  713. * {@link RenderQueue#addToShadowQueue(com.jme3.scene.Geometry, com.jme3.renderer.queue.RenderQueue.ShadowMode)
  714. * shadow queue}. Each Spatial which has its
  715. * {@link Spatial#setShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode) shadow mode}
  716. * set to not off, will be put into the appropriate shadow queue, note that
  717. * this process does not check for frustum culling on any
  718. * {@link ShadowMode#Cast shadow casters}, as they don't have to be
  719. * in the eye camera frustum to cast shadows on objects that are inside it.
  720. *
  721. * @param scene The scene to flatten into the queue
  722. * @param vp The ViewPort provides the {@link ViewPort#getCamera() camera}
  723. * used for culling and the {@link ViewPort#getQueue() queue} used to
  724. * contain the flattened scene graph.
  725. */
  726. public void renderScene(Spatial scene, ViewPort vp) {
  727. if (scene.getParent() == null) {
  728. vp.getCamera().setPlaneState(0);
  729. }
  730. // check culling first.
  731. if (!scene.checkCulling(vp.getCamera())) {
  732. // move on to shadow-only render
  733. if ((scene.getShadowMode() != RenderQueue.ShadowMode.Off || scene instanceof Node) && scene.getCullHint()!=Spatial.CullHint.Always) {
  734. renderShadow(scene, vp.getQueue());
  735. }
  736. return;
  737. }
  738. scene.runControlRender(this, vp);
  739. if (scene instanceof Node) {
  740. // recurse for all children
  741. Node n = (Node) scene;
  742. List<Spatial> children = n.getChildren();
  743. //saving cam state for culling
  744. int camState = vp.getCamera().getPlaneState();
  745. for (int i = 0; i < children.size(); i++) {
  746. //restoring cam state before proceeding children recusively
  747. vp.getCamera().setPlaneState(camState);
  748. renderScene(children.get(i), vp);
  749. }
  750. } else if (scene instanceof Geometry) {
  751. // add to the render queue
  752. Geometry gm = (Geometry) scene;
  753. if (gm.getMaterial() == null) {
  754. throw new IllegalStateException("No material is set for Geometry: " + gm.getName());
  755. }
  756. vp.getQueue().addToQueue(gm, scene.getQueueBucket());
  757. // add to shadow queue if needed
  758. RenderQueue.ShadowMode shadowMode = scene.getShadowMode();
  759. if (shadowMode != RenderQueue.ShadowMode.Off) {
  760. vp.getQueue().addToShadowQueue(gm, shadowMode);
  761. }
  762. }
  763. }
  764. /**
  765. * Returns the camera currently used for rendering.
  766. * <p>
  767. * The camera can be set with {@link #setCamera(com.jme3.renderer.Camera, boolean) }.
  768. *
  769. * @return the camera currently used for rendering.
  770. */
  771. public Camera getCurrentCamera() {
  772. return prevCam;
  773. }
  774. /**
  775. * The renderer implementation used for rendering operations.
  776. *
  777. * @return The renderer implementation
  778. *
  779. * @see #RenderManager(com.jme3.renderer.Renderer)
  780. * @see Renderer
  781. */
  782. public Renderer getRenderer() {
  783. return renderer;
  784. }
  785. /**
  786. * Flushes the ViewPort's {@link ViewPort#getQueue() render queue}
  787. * by rendering each of its visible buckets.
  788. * By default the queues will automatically be cleared after rendering,
  789. * so there's no need to clear them manually.
  790. *
  791. * @param vp The ViewPort of which the queue will be flushed
  792. *
  793. * @see RenderQueue#renderQueue(com.jme3.renderer.queue.RenderQueue.Bucket, com.jme3.renderer.RenderManager, com.jme3.renderer.Camera)
  794. * @see #renderGeometryList(com.jme3.renderer.queue.GeometryList)
  795. */
  796. public void flushQueue(ViewPort vp) {
  797. renderViewPortQueues(vp, true);
  798. }
  799. /**
  800. * Clears the queue of the given ViewPort.
  801. * Simply calls {@link RenderQueue#clear() } on the ViewPort's
  802. * {@link ViewPort#getQueue() render queue}.
  803. *
  804. * @param vp The ViewPort of which the queue will be cleared.
  805. *
  806. * @see RenderQueue#clear()
  807. * @see ViewPort#getQueue()
  808. */
  809. public void clearQueue(ViewPort vp) {
  810. vp.getQueue().clear();
  811. }
  812. /**
  813. * Render the given viewport queues.
  814. * <p>
  815. * Changes the {@link Renderer#setDepthRange(float, float) depth range}
  816. * appropriately as expected by each queue and then calls
  817. * {@link RenderQueue#renderQueue(com.jme3.renderer.queue.RenderQueue.Bucket, com.jme3.renderer.RenderManager, com.jme3.renderer.Camera, boolean) }
  818. * on the queue. Makes sure to restore the depth range to [0, 1]
  819. * at the end of the call.
  820. * Note that the {@link Bucket#Translucent translucent bucket} is NOT
  821. * rendered by this method. Instead the user should call
  822. * {@link #renderTranslucentQueue(com.jme3.renderer.ViewPort) }
  823. * after this call.
  824. *
  825. * @param vp the viewport of which queue should be rendered
  826. * @param flush If true, the queues will be cleared after
  827. * rendering.
  828. *
  829. * @see RenderQueue
  830. * @see #renderTranslucentQueue(com.jme3.renderer.ViewPort)
  831. */
  832. public void renderViewPortQueues(ViewPort vp, boolean flush) {
  833. RenderQueue rq = vp.getQueue();
  834. Camera cam = vp.getCamera();
  835. boolean depthRangeChanged = false;
  836. // render opaque objects with default depth range
  837. // opaque objects are sorted front-to-back, reducing overdraw
  838. rq.renderQueue(Bucket.Opaque, this, cam, flush);
  839. // render the sky, with depth range set to the farthest
  840. if (!rq.isQueueEmpty(Bucket.Sky)) {
  841. renderer.setDepthRange(1, 1);
  842. rq.renderQueue(Bucket.Sky, this, cam, flush);
  843. depthRangeChanged = true;
  844. }
  845. // transparent objects are last because they require blending with the
  846. // rest of the scene's objects. Consequently, they are sorted
  847. // back-to-front.
  848. if (!rq.isQueueEmpty(Bucket.Transparent)) {
  849. if (depthRangeChanged) {
  850. renderer.setDepthRange(0, 1);
  851. depthRangeChanged = false;
  852. }
  853. rq.renderQueue(Bucket.Transparent, this, cam, flush);
  854. }
  855. if (!rq.isQueueEmpty(Bucket.Gui)) {
  856. renderer.setDepthRange(0, 0);
  857. setCamera(cam, true);
  858. rq.renderQueue(Bucket.Gui, this, cam, flush);
  859. setCamera(cam, false);
  860. depthRangeChanged = true;
  861. }
  862. // restore range to default
  863. if (depthRangeChanged) {
  864. renderer.setDepthRange(0, 1);
  865. }
  866. }
  867. /**
  868. * Renders the {@link Bucket#Translucent translucent queue} on the viewPort.
  869. * <p>
  870. * This call does nothing unless {@link #setHandleTranslucentBucket(boolean) }
  871. * is set to true. This method clears the translucent queue after rendering
  872. * it.
  873. *
  874. * @param vp The viewport of which the translucent queue should be rendered.
  875. *
  876. * @see #renderViewPortQueues(com.jme3.renderer.ViewPort, boolean)
  877. * @see #setHandleTranslucentBucket(boolean)
  878. */
  879. public void renderTranslucentQueue(ViewPort vp) {
  880. RenderQueue rq = vp.getQueue();
  881. if (!rq.isQueueEmpty(Bucket.Translucent) && handleTranlucentBucket) {
  882. rq.renderQueue(Bucket.Translucent, this, vp.getCamera(), true);
  883. }
  884. }
  885. private void setViewPort(Camera cam) {
  886. // this will make sure to update viewport only if needed
  887. if (cam != prevCam || cam.isViewportChanged()) {
  888. viewX = (int) (cam.getViewPortLeft() * cam.getWidth());
  889. viewY = (int) (cam.getViewPortBottom() * cam.getHeight());
  890. viewWidth = (int) ((cam.getViewPortRight() - cam.getViewPortLeft()) * cam.getWidth());
  891. viewHeight = (int) ((cam.getViewPortTop() - cam.getViewPortBottom()) * cam.getHeight());
  892. renderer.setViewPort(viewX, viewY, viewWidth, viewHeight);
  893. renderer.setClipRect(viewX, viewY, viewWidth, viewHeight);
  894. cam.clearViewportChanged();
  895. prevCam = cam;
  896. // float translateX = viewWidth == viewX ? 0 : -(viewWidth + viewX) / (viewWidth - viewX);
  897. // float translateY = viewHeight == viewY ? 0 : -(viewHeight + viewY) / (viewHeight - viewY);
  898. // float scaleX = viewWidth == viewX ? 1f : 2f / (viewWidth - viewX);
  899. // float scaleY = viewHeight == viewY ? 1f : 2f / (viewHeight - viewY);
  900. //
  901. // orthoMatrix.loadIdentity();
  902. // orthoMatrix.setTranslation(translateX, translateY, 0);
  903. // orthoMatrix.setScale(scaleX, scaleY, 0);
  904. orthoMatrix.loadIdentity();
  905. orthoMatrix.setTranslation(-1f, -1f, 0f);
  906. orthoMatrix.setScale(2f / cam.getWidth(), 2f / cam.getHeight(), 0f);
  907. }
  908. }
  909. private void setViewProjection(Camera cam, boolean ortho) {
  910. if (shader) {
  911. if (ortho) {
  912. viewMatrix.set(Matrix4f.IDENTITY);
  913. projMatrix.set(orthoMatrix);
  914. viewProjMatrix.set(orthoMatrix);
  915. } else {
  916. viewMatrix.set(cam.getViewMatrix());
  917. projMatrix.set(cam.getProjectionMatrix());
  918. viewProjMatrix.set(cam.getViewProjectionMatrix());
  919. }
  920. camLoc.set(cam.getLocation());
  921. cam.getLeft(camLeft);
  922. cam.getUp(camUp);
  923. cam.getDirection(camDir);
  924. near = cam.getFrustumNear();
  925. far = cam.getFrustumFar();
  926. } else {
  927. if (ortho) {
  928. renderer.setViewProjectionMatrices(Matrix4f.IDENTITY, orthoMatrix);
  929. } else {
  930. renderer.setViewProjectionMatrices(cam.getViewMatrix(),
  931. cam.getProjectionMatrix());
  932. }
  933. }
  934. }
  935. /**
  936. * Set the camera to use for rendering.
  937. * <p>
  938. * First, the camera's
  939. * {@link Camera#setViewPort(float, float, float, float) view port parameters}
  940. * are applied. Then, the camera's {@link Camera#getViewMatrix() view} and
  941. * {@link Camera#getProjectionMatrix() projection} matrices are set
  942. * on the renderer. If <code>ortho</code> is <code>true</code>, then
  943. * instead of using the camera's view and projection matrices, an ortho
  944. * matrix is computed and used instead of the view projection matrix.
  945. * The ortho matrix converts from the range (0 ~ Width, 0 ~ Height, -1 ~ +1)
  946. * to the clip range (-1 ~ +1, -1 ~ +1, -1 ~ +1).
  947. *
  948. * @param cam The camera to set
  949. * @param ortho True if to use orthographic projection (for GUI rendering),
  950. * false if to use the camera's view and projection matrices.
  951. */
  952. public void setCamera(Camera cam, boolean ortho) {
  953. setViewPort(cam);
  954. setViewProjection(cam, ortho);
  955. }
  956. /**
  957. * Draws the viewport but without notifying {@link SceneProcessor scene
  958. * processors} of any rendering events.
  959. *
  960. * @param vp The ViewPort to render
  961. *
  962. * @see #renderViewPort(com.jme3.renderer.ViewPort, float)
  963. */
  964. public void renderViewPortRaw(ViewPort vp) {
  965. setCamera(vp.getCamera(), false);
  966. List<Spatial> scenes = vp.getScenes();
  967. for (int i = scenes.size() - 1; i >= 0; i--) {
  968. renderScene(scenes.get(i), vp);
  969. }
  970. flushQueue(vp);
  971. }
  972. /**
  973. * Renders the {@link ViewPort}.
  974. * <p>
  975. * If the ViewPort is {@link ViewPort#isEnabled() disabled}, this method
  976. * returns immediately. Otherwise, the ViewPort is rendered by
  977. * the following process:<br>
  978. * <ul>
  979. * <li>All {@link SceneProcessor scene processors} that are attached
  980. * to the ViewPort are {@link SceneProcessor#initialize(com.jme3.renderer.RenderManager, com.jme3.renderer.ViewPort) initialized}.
  981. * </li>
  982. * <li>The SceneProcessors' {@link SceneProcessor#preFrame(float) } method
  983. * is called.</li>
  984. * <li>The ViewPort's {@link ViewPort#getOutputFrameBuffer() output framebuffer}
  985. * is set on the Renderer</li>
  986. * <li>The camera is set on the renderer, including its view port parameters.
  987. * (see {@link #setCamera(com.jme3.renderer.Camera, boolean) })</li>
  988. * <li>Any buffers that the ViewPort requests to be cleared are cleared
  989. * and the {@link ViewPort#getBackgroundColor() background color} is set</li>
  990. * <li>Every scene that is attached to the ViewPort is flattened into
  991. * the ViewPort's render queue
  992. * (see {@link #renderViewPortQueues(com.jme3.renderer.ViewPort, boolean) })
  993. * </li>
  994. * <li>The SceneProcessors' {@link SceneProcessor#postQueue(com.jme3.renderer.queue.RenderQueue) }
  995. * method is called.</li>
  996. * <li>The render queue is sorted and then flushed, sending
  997. * rendering commands to the underlying Renderer implementation.
  998. * (see {@link #flushQueue(com.jme3.renderer.ViewPort) })</li>
  999. * <li>The SceneProcessors' {@link SceneProcessor#postFrame(com.jme3.texture.FrameBuffer) }
  1000. * method is called.</li>
  1001. * <li>The translucent queue of the ViewPort is sorted and then flushed
  1002. * (see {@link #renderTranslucentQueue(com.jme3.renderer.ViewPort) })</li>
  1003. * <li>If any objects remained in the render queue, they are removed
  1004. * from the queue. This is generally objects added to the
  1005. * {@link RenderQueue#renderShadowQueue(com.jme3.renderer.queue.RenderQueue.ShadowMode, com.jme3.renderer.RenderManager, com.jme3.renderer.Camera, boolean)
  1006. * shadow queue}
  1007. * which were not rendered because of a missing shadow renderer.</li>
  1008. * </ul>
  1009. *
  1010. * @param vp
  1011. * @param tpf
  1012. */
  1013. public void renderViewPort(ViewPort vp, float tpf) {
  1014. if (!vp.isEnabled()) {
  1015. return;
  1016. }
  1017. List<SceneProcessor> processors = vp.getProcessors();
  1018. if (processors.isEmpty()) {
  1019. processors = null;
  1020. }
  1021. if (processors != null) {
  1022. for (SceneProcessor proc : processors) {
  1023. if (!proc.isInitialized()) {
  1024. proc.initialize(this, vp);
  1025. }
  1026. proc.preFrame(tpf);
  1027. }
  1028. }
  1029. renderer.setFrameBuffer(vp.getOutputFrameBuffer());
  1030. setCamera(vp.getCamera(), false);
  1031. if (vp.isClearDepth() || vp.isClearColor() || vp.isClearStencil()) {
  1032. if (vp.isClearColor()) {
  1033. renderer.setBackgroundColor(vp.getBackgroundColor());
  1034. }
  1035. renderer.clearBuffers(vp.isClearColor(),
  1036. vp.isClearDepth(),
  1037. vp.isClearStencil());
  1038. }
  1039. List<Spatial> scenes = vp.getScenes();
  1040. for (int i = scenes.size() - 1; i >= 0; i--) {
  1041. renderScene(scenes.get(i), vp);
  1042. }
  1043. if (processors != null) {
  1044. for (SceneProcessor proc : processors) {
  1045. proc.postQueue(vp.getQueue());
  1046. }
  1047. }
  1048. flushQueue(vp);
  1049. if (processors != null) {
  1050. for (SceneProcessor proc : processors) {
  1051. proc.postFrame(vp.getOutputFrameBuffer());
  1052. }
  1053. }
  1054. //renders the translucent objects queue after processors have been rendered
  1055. renderTranslucentQueue(vp);
  1056. // clear any remaining spatials that were not rendered.
  1057. clearQueue(vp);
  1058. }
  1059. /**
  1060. * Called by the application to render any ViewPorts
  1061. * added to this RenderManager.
  1062. * <p>
  1063. * Renders any viewports that were added using the following methods:
  1064. * <ul>
  1065. * <li>{@link #createPreView(java.lang.String, com.jme3.renderer.Camera) }</li>
  1066. * <li>{@link #createMainView(java.lang.String, com.jme3.renderer.Camera) }</li>
  1067. * <li>{@link #createPostView(java.lang.String, com.jme3.renderer.Camera) }</li>
  1068. * </ul>
  1069. *
  1070. * @param tpf Time per frame value
  1071. */
  1072. public void render(float tpf, boolean mainFrameBufferActive) {
  1073. if (renderer instanceof NullRenderer) {
  1074. return;
  1075. }
  1076. this.shader = renderer.getCaps().contains(Caps.GLSL100);
  1077. for (int i = 0; i < preViewPorts.size(); i++) {
  1078. ViewPort vp = preViewPorts.get(i);
  1079. if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){
  1080. renderViewPort(vp, tpf);
  1081. }
  1082. }
  1083. for (int i = 0; i < viewPorts.size(); i++) {
  1084. ViewPort vp = viewPorts.get(i);
  1085. if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){
  1086. renderViewPort(vp, tpf);
  1087. }
  1088. }
  1089. for (int i = 0; i < postViewPorts.size(); i++) {
  1090. ViewPort vp = postViewPorts.get(i);
  1091. if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){
  1092. renderViewPort(vp, tpf);
  1093. }
  1094. }
  1095. }
  1096. }