• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2010 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 
33 package com.jme3.terrain.geomipmap;
34 
35 import com.jme3.scene.VertexBuffer.Type;
36 import java.nio.IntBuffer;
37 
38 /**
39  * Stores a terrain patch's details so the LOD background thread can update
40  * the actual terrain patch back on the ogl thread.
41  *
42  * @author Brent Owens
43  *
44  */
45 public class UpdatedTerrainPatch {
46 
47 	private TerrainPatch updatedPatch;
48 	private int newLod;
49 	private int previousLod;
50 	private int rightLod,topLod,leftLod,bottomLod;
51 	private IntBuffer newIndexBuffer;
52 	private boolean reIndexNeeded = false;
53 	private boolean fixEdges = false;
54 
UpdatedTerrainPatch(TerrainPatch updatedPatch, int newLod)55 	public UpdatedTerrainPatch(TerrainPatch updatedPatch, int newLod) {
56 		this.updatedPatch = updatedPatch;
57 		this.newLod = newLod;
58 	}
59 
UpdatedTerrainPatch(TerrainPatch updatedPatch, int newLod, int prevLOD, boolean reIndexNeeded)60 	public UpdatedTerrainPatch(TerrainPatch updatedPatch, int newLod, int prevLOD, boolean reIndexNeeded) {
61 		this.updatedPatch = updatedPatch;
62 		this.newLod = newLod;
63 		this.previousLod = prevLOD;
64 		this.reIndexNeeded = reIndexNeeded;
65 		if (this.newLod <= 0)
66                     throw new IllegalArgumentException();
67 	}
68 
getName()69 	public String getName() {
70 		return updatedPatch.getName();
71 	}
72 
lodChanged()73 	protected boolean lodChanged() {
74 		if (reIndexNeeded && previousLod != newLod)
75 			return true;
76 		else
77 			return false;
78 	}
79 
getUpdatedPatch()80 	protected TerrainPatch getUpdatedPatch() {
81 		return updatedPatch;
82 	}
83 
setUpdatedPatch(TerrainPatch updatedPatch)84 	protected void setUpdatedPatch(TerrainPatch updatedPatch) {
85 		this.updatedPatch = updatedPatch;
86 	}
87 
getNewLod()88 	protected int getNewLod() {
89 		return newLod;
90 	}
91 
setNewLod(int newLod)92 	public void setNewLod(int newLod) {
93 		this.newLod = newLod;
94                 if (this.newLod < 0)
95                     throw new IllegalArgumentException();
96 	}
97 
getNewIndexBuffer()98 	protected IntBuffer getNewIndexBuffer() {
99 		return newIndexBuffer;
100 	}
101 
setNewIndexBuffer(IntBuffer newIndexBuffer)102 	protected void setNewIndexBuffer(IntBuffer newIndexBuffer) {
103 		this.newIndexBuffer = newIndexBuffer;
104 	}
105 
106 
getRightLod()107 	protected int getRightLod() {
108 		return rightLod;
109 	}
110 
111 
setRightLod(int rightLod)112 	protected void setRightLod(int rightLod) {
113 		this.rightLod = rightLod;
114 	}
115 
116 
getTopLod()117 	protected int getTopLod() {
118 		return topLod;
119 	}
120 
121 
setTopLod(int topLod)122 	protected void setTopLod(int topLod) {
123 		this.topLod = topLod;
124 	}
125 
126 
getLeftLod()127 	protected int getLeftLod() {
128 		return leftLod;
129 	}
130 
131 
setLeftLod(int leftLod)132 	protected void setLeftLod(int leftLod) {
133 		this.leftLod = leftLod;
134 	}
135 
136 
getBottomLod()137 	protected int getBottomLod() {
138 		return bottomLod;
139 	}
140 
141 
setBottomLod(int bottomLod)142 	protected void setBottomLod(int bottomLod) {
143 		this.bottomLod = bottomLod;
144 	}
145 
isReIndexNeeded()146 	public boolean isReIndexNeeded() {
147 		return reIndexNeeded;
148 	}
149 
setReIndexNeeded(boolean reIndexNeeded)150 	public void setReIndexNeeded(boolean reIndexNeeded) {
151 		this.reIndexNeeded = reIndexNeeded;
152 	}
153 
isFixEdges()154 	public boolean isFixEdges() {
155 		return fixEdges;
156 	}
157 
setFixEdges(boolean fixEdges)158 	public void setFixEdges(boolean fixEdges) {
159 		this.fixEdges = fixEdges;
160 	}
161 
getPreviousLod()162 	public int getPreviousLod() {
163 		return previousLod;
164 	}
165 
setPreviousLod(int previousLod)166 	public void setPreviousLod(int previousLod) {
167 		this.previousLod = previousLod;
168 	}
169 
updateAll()170 	public void updateAll() {
171 		updatedPatch.setLod(newLod);
172 		updatedPatch.setLodRight(rightLod);
173 		updatedPatch.setLodTop(topLod);
174 		updatedPatch.setLodLeft(leftLod);
175 		updatedPatch.setLodBottom(bottomLod);
176 		if (newIndexBuffer != null && (reIndexNeeded || fixEdges)) {
177 			updatedPatch.setPreviousLod(previousLod);
178 			updatedPatch.getMesh().clearBuffer(Type.Index);
179 			updatedPatch.getMesh().setBuffer(Type.Index, 3, newIndexBuffer);
180 		}
181 	}
182 
183 }
184