Revision d5b709df
Added by Leszek Koltunski over 5 years ago
src/main/java/org/distorted/library/main/DistortedChildrenList.java | ||
---|---|---|
53 | 53 |
public interface Parent |
54 | 54 |
{ |
55 | 55 |
void adjustIsomorphism(); |
56 |
DistortedChildrenList getChildren(); |
|
57 | 56 |
} |
58 | 57 |
|
59 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
82 | 81 |
|
83 | 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
84 | 83 |
|
85 |
void removeChild(DistortedNode node)
|
|
84 |
void rearrangeByBuckets(int index,long bucket)
|
|
86 | 85 |
{ |
87 |
if( mChildren.remove(node) ) |
|
86 |
DistortedNode child = mChildren.remove(index); |
|
87 |
int i; |
|
88 |
|
|
89 |
for(i=0; i<index; i++) |
|
88 | 90 |
{ |
89 |
mNumChildren--;
|
|
91 |
if( mChildren.get(i).getBucket() > bucket ) break;
|
|
90 | 92 |
} |
93 |
|
|
94 |
mChildren.add(i,child); |
|
91 | 95 |
} |
92 | 96 |
|
93 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
96 | 100 |
// We want to keep same buckets next to each other, while avoiding changes in order of the children |
97 | 101 |
// (if possible!) We want to keep bucket=0 (i.e. the non-postprocessed children) at the beginning. |
98 | 102 |
|
99 |
void addSortingByBuckets(DistortedNode newChild) |
|
103 |
private void addSortingByBuckets(DistortedNode newChild)
|
|
100 | 104 |
{ |
101 | 105 |
int i; |
102 |
EffectQueue queue = newChild.getEffects().getQueues()[3]; |
|
103 |
long bucket = queue.getID(); |
|
106 |
long bucket = newChild.getBucket(); |
|
104 | 107 |
boolean sameBucket = false; |
105 | 108 |
|
106 | 109 |
for(i=0; i<mNumChildren; i++) |
107 | 110 |
{ |
108 |
queue = mChildren.get(i).getEffects().getQueues()[3]; |
|
109 |
|
|
110 |
if( queue.getID() == bucket ) |
|
111 |
if( mChildren.get(i).getBucket() == bucket ) |
|
111 | 112 |
{ |
112 | 113 |
sameBucket=true; |
113 | 114 |
} |
src/main/java/org/distorted/library/main/DistortedEffects.java | ||
---|---|---|
43 | 43 |
return mQueues; |
44 | 44 |
} |
45 | 45 |
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
void newNode(DistortedNode node) |
|
49 |
{ |
|
50 |
EffectQueue.newNode(mQueues,node); |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
void removeNode(DistortedNode node) |
|
56 |
{ |
|
57 |
EffectQueue.removeNode(mQueues,node); |
|
58 |
} |
|
59 |
|
|
60 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 47 |
|
62 | 48 |
static void onDestroy() |
src/main/java/org/distorted/library/main/DistortedNode.java | ||
---|---|---|
59 | 59 |
mData.mFBO.markForDeletion(); |
60 | 60 |
mData.mFBO = null; |
61 | 61 |
} |
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
62 | 65 |
|
63 |
mEffects.removeNode(this); |
|
66 |
long getBucket() |
|
67 |
{ |
|
68 |
return mEffects.getQueues()[3].getID(); |
|
64 | 69 |
} |
65 | 70 |
|
66 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
140 | 145 |
if( mParent!=null ) mParent.adjustIsomorphism(); |
141 | 146 |
} |
142 | 147 |
|
143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
144 |
/** |
|
145 |
* This is not really part of the public API. Has to be public only because it is a part of the |
|
146 |
* DistortedChildrenList.Parent interface. |
|
147 |
* |
|
148 |
* @y.exclude |
|
149 |
*/ |
|
150 |
public DistortedChildrenList getChildren() |
|
151 |
{ |
|
152 |
return mChildren; |
|
153 |
} |
|
154 |
|
|
155 | 148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
156 | 149 |
// return the total number of render calls issued |
157 | 150 |
|
... | ... | |
215 | 208 |
|
216 | 209 |
if( numChildren>0 && mData.notRenderedYetAtThisTime(currTime) ) |
217 | 210 |
{ |
211 |
DistortedNode node; |
|
212 |
long oldBucket=0, newBucket; |
|
213 |
|
|
218 | 214 |
for (int i=0; i<numChildren; i++) |
219 | 215 |
{ |
220 |
numRenders += mChildren.getChild(i).renderRecursive(currTime); |
|
216 |
node = mChildren.getChild(i); |
|
217 |
newBucket = node.getBucket(); |
|
218 |
numRenders += node.renderRecursive(currTime); |
|
219 |
if( newBucket<oldBucket ) mChildren.rearrangeByBuckets(i,newBucket); |
|
220 |
else oldBucket=newBucket; |
|
221 | 221 |
} |
222 | 222 |
|
223 | 223 |
if( mData.mFBO==null ) mData.mFBO = allocateNewFBO(); |
... | ... | |
251 | 251 |
mParent = parent; |
252 | 252 |
} |
253 | 253 |
|
254 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
255 |
|
|
256 |
void sort() |
|
257 |
{ |
|
258 |
if( mParent!=null ) |
|
259 |
{ |
|
260 |
DistortedChildrenList siblings = mParent.getChildren(); |
|
261 |
siblings.removeChild(this); |
|
262 |
siblings.addSortingByBuckets(this); |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 | 254 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
267 | 255 |
// PUBLIC API |
268 | 256 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
288 | 276 |
mFboDepthStencil = DistortedFramebuffer.DEPTH_NO_STENCIL; |
289 | 277 |
|
290 | 278 |
mData = DistortedNodeData.returnData(generateIDList()); |
291 |
mEffects.newNode(this); |
|
292 | 279 |
} |
293 | 280 |
|
294 | 281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
350 | 337 |
} |
351 | 338 |
|
352 | 339 |
mData = DistortedNodeData.returnData(generateIDList()); |
353 |
mEffects.newNode(this); |
|
354 | 340 |
} |
355 | 341 |
|
356 | 342 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
---|---|---|
352 | 352 |
|
353 | 353 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
354 | 354 |
|
355 |
void clear() |
|
355 |
private void clear()
|
|
356 | 356 |
{ |
357 | 357 |
DistortedRenderState.colorDepthStencilOn(); |
358 | 358 |
GLES31.glClearColor(mClearR, mClearG, mClearB, mClearA); |
... | ... | |
503 | 503 |
|
504 | 504 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
505 | 505 |
/** |
506 |
* This is not really part of the public API. Has to be public only because it is a part of the |
|
507 |
* DistortedChildrenList.Parent interface. |
|
506 |
* Not part of the public API. |
|
508 | 507 |
* |
509 | 508 |
* @y.exclude |
510 | 509 |
*/ |
511 |
public DistortedChildrenList getChildren() |
|
512 |
{ |
|
513 |
return mChildren; |
|
514 |
} |
|
515 |
|
|
516 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
517 |
/** |
|
518 |
* This is not really part of the public API. Has to be public only because it is a part of the |
|
519 |
* DistortedChildrenList.Parent interface. |
|
520 |
* |
|
521 |
* @y.exclude |
|
522 |
*/ |
|
523 |
public void adjustIsomorphism() |
|
524 |
{ |
|
525 |
|
|
526 |
} |
|
510 |
public void adjustIsomorphism() { } |
|
527 | 511 |
|
528 | 512 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
529 | 513 |
/** |
... | ... | |
599 | 583 |
DistortedRenderState.reset(); |
600 | 584 |
|
601 | 585 |
int numRenders=0, numChildren = mChildren.getNumChildren(); |
586 |
DistortedNode node; |
|
587 |
long oldBucket=0, newBucket; |
|
602 | 588 |
|
603 | 589 |
for(int i=0; i<numChildren; i++) |
604 | 590 |
{ |
605 |
numRenders += mChildren.getChild(i).renderRecursive(time); |
|
591 |
node = mChildren.getChild(i); |
|
592 |
newBucket = node.getBucket(); |
|
593 |
numRenders += node.renderRecursive(time); |
|
594 |
if( newBucket<oldBucket ) mChildren.rearrangeByBuckets(i,newBucket); |
|
595 |
else oldBucket=newBucket; |
|
606 | 596 |
} |
607 | 597 |
|
608 | 598 |
numRenders += renderChildren(time,numChildren,mChildren,fbo, mRenderWayOIT); |
src/main/java/org/distorted/library/main/EffectQueue.java | ||
---|---|---|
53 | 53 |
private static long mNextID; |
54 | 54 |
private static HashMap<ArrayList<Long>,Long> mMapID = new HashMap<>(); // maps lists of Effect IDs (longs) to a |
55 | 55 |
// single long - the queue ID. |
56 |
private ArrayList<DistortedNode> mNodes = null; |
|
57 | 56 |
private long mID; |
58 | 57 |
private int mIndex; |
59 | 58 |
private boolean mCreated; |
... | ... | |
97 | 96 |
} |
98 | 97 |
|
99 | 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
100 |
// queues - guaranteed to be an array of EffectType.LENGTH length. |
|
101 |
// Change this when creating a new ty[e of effect! |
|
102 | 99 |
|
103 | 100 |
static void allocateQueues(EffectQueue[] queues, EffectQueue[] from, int flags, long id) |
104 | 101 |
{ |
... | ... | |
109 | 106 |
} |
110 | 107 |
|
111 | 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
112 |
// queues - guaranteed to be an array of EffectType.LENGTH length. |
|
113 |
// Change this when creating a new ty[e of effect! |
|
114 | 109 |
|
115 | 110 |
static void compute(EffectQueue[] queues, long currTime, float halfW, float halfH, float halfZ ) |
116 | 111 |
{ |
... | ... | |
121 | 116 |
} |
122 | 117 |
|
123 | 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
124 |
// queues - guaranteed to be an array of EffectType.LENGTH length. |
|
125 |
// Change this when creating a new ty[e of effect! |
|
126 | 119 |
|
127 | 120 |
static void send(EffectQueue[] queues, DistortedOutputSurface surface, float inflate, float halfW, float halfH, float halfZ, int variant ) |
128 | 121 |
{ |
... | ... | |
132 | 125 |
} |
133 | 126 |
|
134 | 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
135 |
// queues - guaranteed to be an array of EffectType.LENGTH length. |
|
136 |
// Change this when creating a new ty[e of effect! |
|
137 | 128 |
|
138 | 129 |
static float[] getMVP(EffectQueue[] queues) |
139 | 130 |
{ |
140 |
return ((EffectQueueMatrix )queues[0]).getMVP();
|
|
131 |
return ((EffectQueueMatrix)queues[0]).getMVP(); |
|
141 | 132 |
} |
142 | 133 |
|
143 | 134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
144 |
// queues - guaranteed to be an array of EffectType.LENGTH length. |
|
145 |
// Change this when creating a new ty[e of effect! |
|
146 |
|
|
147 |
static void newNode(EffectQueue[] queues, DistortedNode node) |
|
148 |
{ |
|
149 |
queues[3].newNode(node); |
|
150 |
} |
|
151 |
|
|
152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
153 |
// queues - guaranteed to be an array of EffectType.LENGTH length. |
|
154 |
// Change this when creating a new ty[e of effect! |
|
155 |
|
|
156 |
static void removeNode(EffectQueue[] queues, DistortedNode node) |
|
157 |
{ |
|
158 |
queues[3].removeNode(node); |
|
159 |
} |
|
160 |
|
|
161 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
162 |
// queues - guaranteed to be an array of EffectType.LENGTH length. |
|
163 |
// Change this when creating a new ty[e of effect! |
|
164 | 135 |
|
165 | 136 |
static void getUniforms(int programH, int variant) |
166 | 137 |
{ |
... | ... | |
174 | 145 |
// (this is a speedup: then both queues can be applied once, which seriously speeds up stuff - |
175 | 146 |
// especially important in case of postprocessing) |
176 | 147 |
|
177 |
private void regenerateIDandSort()
|
|
148 |
private void regenerateID() |
|
178 | 149 |
{ |
179 | 150 |
if( mNumEffects>0 ) |
180 | 151 |
{ |
... | ... | |
196 | 167 |
{ |
197 | 168 |
mID = 0; |
198 | 169 |
} |
199 |
|
|
200 |
int numNodes = (mNodes==null ? 0: mNodes.size()); |
|
201 |
for(int i=0; i<numNodes; i++) mNodes.get(i).sort(); |
|
202 |
} |
|
203 |
|
|
204 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
205 |
|
|
206 |
private void newNode(DistortedNode node) |
|
207 |
{ |
|
208 |
if( mNodes==null ) mNodes = new ArrayList<>(); |
|
209 |
|
|
210 |
mNodes.add(node); |
|
211 |
} |
|
212 |
|
|
213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
214 |
|
|
215 |
private void removeNode(DistortedNode node) |
|
216 |
{ |
|
217 |
mNodes.remove(node); |
|
218 | 170 |
} |
219 | 171 |
|
220 | 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
465 | 417 |
} |
466 | 418 |
} |
467 | 419 |
|
468 |
if( changed && mIndex==EffectType.POSTPROCESS.ordinal() ) regenerateIDandSort();
|
|
420 |
if( changed && mIndex==EffectType.POSTPROCESS.ordinal() ) regenerateID(); |
|
469 | 421 |
} |
470 | 422 |
} |
Also available in: Unified diff
Cut another interdependency between the Queues and the rest: it is no longer necessary to add DNodes to PostprocessQueue to rearrange the Nodes by buckets. The rearranging is now done on next render instead.