Revision 70b6a155
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/library/effect/PostprocessEffect.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.library.effect; |
| 21 | 21 |
|
| 22 |
import org.distorted.library.main.DistortedFramebuffer; |
|
| 23 | 22 |
import org.distorted.library.main.DistortedMaster; |
| 23 |
import org.distorted.library.main.DistortedOutputSurface; |
|
| 24 | 24 |
import org.distorted.library.program.DistortedProgram; |
| 25 | 25 |
|
| 26 | 26 |
import java.nio.ByteBuffer; |
| ... | ... | |
| 139 | 139 |
* |
| 140 | 140 |
* @y.exclude |
| 141 | 141 |
*/ |
| 142 |
public abstract int apply(float[] uniforms, int index, DistortedFramebuffer[] buffers);
|
|
| 142 |
public abstract int apply(float[] uniforms, int index, DistortedOutputSurface[] buffers);
|
|
| 143 | 143 |
|
| 144 | 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 145 | 145 |
/** |
| src/main/java/org/distorted/library/effect/PostprocessEffectBlur.java | ||
|---|---|---|
| 22 | 22 |
import android.opengl.GLES30; |
| 23 | 23 |
|
| 24 | 24 |
import org.distorted.library.main.DistortedFramebuffer; |
| 25 |
import org.distorted.library.main.DistortedOutputSurface; |
|
| 25 | 26 |
import org.distorted.library.main.DistortedRenderState; |
| 26 | 27 |
import org.distorted.library.program.DistortedProgram; |
| 27 | 28 |
import org.distorted.library.type.Data1D; |
| ... | ... | |
| 139 | 140 |
* |
| 140 | 141 |
* @y.exclude |
| 141 | 142 |
*/ |
| 142 |
public int apply(float[] uniforms, int index, DistortedFramebuffer[] buffers)
|
|
| 143 |
public int apply(float[] uniforms, int index, DistortedOutputSurface[] buffers)
|
|
| 143 | 144 |
{
|
| 144 | 145 |
if( mProgram1 ==null) |
| 145 | 146 |
{
|
| ... | ... | |
| 149 | 150 |
|
| 150 | 151 |
DistortedRenderState.useStencilMark(); |
| 151 | 152 |
|
| 152 |
DistortedFramebuffer buffer = buffers[mQualityLevel]; |
|
| 153 |
DistortedFramebuffer buffer = (DistortedFramebuffer)buffers[mQualityLevel];
|
|
| 153 | 154 |
|
| 154 | 155 |
buffer.setAsOutput(); |
| 155 | 156 |
|
| src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java | ||
|---|---|---|
| 23 | 23 |
|
| 24 | 24 |
import org.distorted.library.main.DistortedEffects; |
| 25 | 25 |
import org.distorted.library.main.DistortedFramebuffer; |
| 26 |
import org.distorted.library.main.DistortedOutputSurface; |
|
| 26 | 27 |
import org.distorted.library.main.DistortedRenderState; |
| 27 | 28 |
import org.distorted.library.program.DistortedProgram; |
| 28 | 29 |
import org.distorted.library.type.Data1D; |
| ... | ... | |
| 143 | 144 |
* |
| 144 | 145 |
* @y.exclude |
| 145 | 146 |
*/ |
| 146 |
public int apply(float[] uniforms, int index, DistortedFramebuffer[] buffers)
|
|
| 147 |
public int apply(float[] uniforms, int index, DistortedOutputSurface[] buffers)
|
|
| 147 | 148 |
{
|
| 148 | 149 |
if( mProgram1 ==null) |
| 149 | 150 |
{
|
| ... | ... | |
| 153 | 154 |
|
| 154 | 155 |
DistortedRenderState.useStencilMark(); |
| 155 | 156 |
|
| 156 |
DistortedFramebuffer inBuffer = buffers[0]; |
|
| 157 |
DistortedFramebuffer outBuffer = buffers[mQualityLevel]; |
|
| 157 |
DistortedFramebuffer inBuffer = (DistortedFramebuffer)buffers[0];
|
|
| 158 |
DistortedFramebuffer outBuffer = (DistortedFramebuffer)buffers[mQualityLevel];
|
|
| 158 | 159 |
|
| 159 | 160 |
float w= outBuffer.getWidth(); |
| 160 | 161 |
float h= outBuffer.getHeight(); |
| src/main/java/org/distorted/library/main/DistortedEffects.java | ||
|---|---|---|
| 25 | 25 |
import org.distorted.library.R; |
| 26 | 26 |
import org.distorted.library.effect.Effect; |
| 27 | 27 |
import org.distorted.library.effect.EffectName; |
| 28 |
import org.distorted.library.effect.EffectQuality; |
|
| 29 | 28 |
import org.distorted.library.effect.EffectType; |
| 30 | 29 |
import org.distorted.library.effect.FragmentEffect; |
| 31 | 30 |
import org.distorted.library.effect.VertexEffect; |
| ... | ... | |
| 41 | 40 |
import java.nio.ByteBuffer; |
| 42 | 41 |
import java.nio.ByteOrder; |
| 43 | 42 |
import java.nio.FloatBuffer; |
| 44 |
import java.util.ArrayList; |
|
| 45 | 43 |
|
| 46 | 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 47 | 45 |
/** |
| ... | ... | |
| 231 | 229 |
|
| 232 | 230 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 233 | 231 |
|
| 234 |
int postprocess(DistortedOutputSurface surface)
|
|
| 232 |
EffectQueuePostprocess getPostprocess()
|
|
| 235 | 233 |
{
|
| 236 |
return mP.postprocess(surface); |
|
| 237 |
} |
|
| 238 |
|
|
| 239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 240 |
|
|
| 241 |
long getBucket() |
|
| 242 |
{
|
|
| 243 |
return mP.getID(); |
|
| 244 |
} |
|
| 245 |
|
|
| 246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 247 |
|
|
| 248 |
int getQuality() |
|
| 249 |
{
|
|
| 250 |
return mP.getQuality(); |
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 254 |
|
|
| 255 |
int getInternalQuality() |
|
| 256 |
{
|
|
| 257 |
return mP.getInternalQuality(); |
|
| 258 |
} |
|
| 259 |
|
|
| 260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 261 |
|
|
| 262 |
int getHalo() |
|
| 263 |
{
|
|
| 264 |
return mP.getHalo(); |
|
| 234 |
return mP; |
|
| 265 | 235 |
} |
| 266 | 236 |
|
| 267 | 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/main/DistortedMaster.java | ||
|---|---|---|
| 100 | 100 |
|
| 101 | 101 |
static void addSorted(ArrayList<DistortedNode> mChildren, DistortedNode newChild) |
| 102 | 102 |
{
|
| 103 |
DistortedNode child; |
|
| 104 |
DistortedEffects effects; |
|
| 105 | 103 |
int i,num = mChildren.size(); |
| 106 |
long bucket, newBucket; |
|
| 107 |
|
|
| 108 |
effects = newChild.getEffects(); |
|
| 109 |
newBucket = effects.getBucket(); |
|
| 104 |
long bucket = newChild.getPostprocessQueue().getID(); |
|
| 110 | 105 |
|
| 111 | 106 |
for(i=0; i<num; i++) |
| 112 | 107 |
{
|
| 113 |
child = mChildren.get(i); |
|
| 114 |
effects= child.getEffects(); |
|
| 115 |
bucket = effects.getBucket(); |
|
| 116 |
|
|
| 117 |
if( bucket>newBucket ) break; |
|
| 108 |
if( mChildren.get(i).getPostprocessQueue().getID() > bucket ) break; |
|
| 118 | 109 |
} |
| 119 | 110 |
|
| 120 | 111 |
mChildren.add(i,newChild); |
| 121 | 112 |
|
| 122 |
//android.util.Log.e("newChild", "newBucket="+newBucket+" new child at "+i+" total num ="+num);
|
|
| 113 |
//android.util.Log.e("newChild", "newBucket="+bucket+" new child at "+i+" total num ="+num);
|
|
| 123 | 114 |
} |
| 124 | 115 |
|
| 125 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/main/DistortedNode.java | ||
|---|---|---|
| 256 | 256 |
|
| 257 | 257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 258 | 258 |
|
| 259 |
int markStencilAndDepth(long currTime, DistortedOutputSurface surface, DistortedEffects effects)
|
|
| 259 |
int markStencilAndDepth(long currTime, DistortedOutputSurface surface, EffectQueuePostprocess queue)
|
|
| 260 | 260 |
{
|
| 261 | 261 |
DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO; |
| 262 | 262 |
|
| ... | ... | |
| 264 | 264 |
{
|
| 265 | 265 |
surface.setAsOutput(); |
| 266 | 266 |
DistortedRenderState.setUpStencilMark(); |
| 267 |
mEffects.drawPriv(mSurface.getWidth() /2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, effects.getHalo()*surface.mMipmap);
|
|
| 267 |
mEffects.drawPriv(mSurface.getWidth() /2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, queue.getHalo()*surface.mMipmap);
|
|
| 268 | 268 |
DistortedRenderState.unsetUpStencilMark(); |
| 269 | 269 |
|
| 270 | 270 |
return 1; |
| ... | ... | |
| 352 | 352 |
} |
| 353 | 353 |
} |
| 354 | 354 |
|
| 355 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 356 |
/** |
|
| 357 |
* Not part of the Public API. |
|
| 358 |
* |
|
| 359 |
* @y.exclude |
|
| 360 |
*/ |
|
| 361 |
public EffectQueuePostprocess getPostprocessQueue() |
|
| 362 |
{
|
|
| 363 |
return mEffects.getPostprocess(); |
|
| 364 |
} |
|
| 365 |
|
|
| 355 | 366 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 356 | 367 |
// PUBLIC API |
| 357 | 368 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
|---|---|---|
| 27 | 27 |
import java.util.ArrayList; |
| 28 | 28 |
|
| 29 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 30 |
|
|
| 31 |
abstract class DistortedOutputSurface extends DistortedSurface implements DistortedMaster.Slave |
|
| 30 |
/** |
|
| 31 |
* This is not really part of the public API. |
|
| 32 |
* |
|
| 33 |
* @y.exclude |
|
| 34 |
*/ |
|
| 35 |
public abstract class DistortedOutputSurface extends DistortedSurface implements DistortedMaster.Slave |
|
| 32 | 36 |
{
|
| 33 | 37 |
//////////// DEBUG FLAGS ///////////////////////////////////////////// |
| 34 | 38 |
/** |
| ... | ... | |
| 72 | 76 |
|
| 73 | 77 |
private ArrayList<Job> mJobs = new ArrayList<>(); |
| 74 | 78 |
|
| 75 |
DistortedFramebuffer[] mBuffer;
|
|
| 79 |
DistortedOutputSurface[] mBuffer;
|
|
| 76 | 80 |
|
| 77 | 81 |
private long mTime; |
| 78 | 82 |
private float mFOV; |
| ... | ... | |
| 128 | 132 |
mClearStencil = 0; |
| 129 | 133 |
mClear = GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT; |
| 130 | 134 |
|
| 131 |
mBuffer = new DistortedFramebuffer[EffectQuality.LENGTH];
|
|
| 135 |
mBuffer = new DistortedOutputSurface[1+EffectQuality.LENGTH];
|
|
| 132 | 136 |
|
| 133 | 137 |
mMipmap = 1.0f; |
| 134 | 138 |
|
| ... | ... | |
| 188 | 192 |
mipmap *= EffectQuality.MULTIPLIER; |
| 189 | 193 |
} |
| 190 | 194 |
|
| 195 |
mBuffer[EffectQuality.LENGTH] = this; |
|
| 196 |
|
|
| 191 | 197 |
DistortedObject.toDo(); // create the FBOs immediately. This is safe as we must be holding the OpenGL context now. |
| 192 | 198 |
|
| 193 | 199 |
GLES30.glStencilMask(0xff); |
| ... | ... | |
| 209 | 215 |
|
| 210 | 216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 211 | 217 |
|
| 212 |
private int blitWithDepth(long currTime, DistortedFramebuffer buffer)
|
|
| 218 |
private int blitWithDepth(long currTime, DistortedOutputSurface buffer)
|
|
| 213 | 219 |
{
|
| 214 | 220 |
GLES30.glViewport(0, 0, mWidth, mHeight); |
| 215 | 221 |
setAsOutput(currTime); |
| ... | ... | |
| 253 | 259 |
{
|
| 254 | 260 |
int quality=0, internalQuality = 0, numRenders = 0, bucketChange = 0; |
| 255 | 261 |
DistortedNode child1, child2; |
| 256 |
DistortedEffects lastEffects=null, currEffects;
|
|
| 262 |
EffectQueuePostprocess lastQueue=null, currQueue;
|
|
| 257 | 263 |
long lastBucket=0, currBucket; |
| 258 | 264 |
|
| 259 | 265 |
sCurr = ""; |
| ... | ... | |
| 261 | 267 |
for(int i=0; i<numChildren; i++) |
| 262 | 268 |
{
|
| 263 | 269 |
child1 = children.get(i); |
| 264 |
currEffects = child1.getEffects();
|
|
| 265 |
currBucket = currEffects.getBucket();
|
|
| 270 |
currQueue = child1.getPostprocessQueue();
|
|
| 271 |
currBucket= currQueue.getID();
|
|
| 266 | 272 |
|
| 267 | 273 |
sCurr += (" "+currBucket);
|
| 268 | 274 |
|
| ... | ... | |
| 278 | 284 |
for(int j=bucketChange; j<i; j++) |
| 279 | 285 |
{
|
| 280 | 286 |
child2 = children.get(j); |
| 281 |
numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],lastEffects);
|
|
| 287 |
numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],lastQueue);
|
|
| 282 | 288 |
} |
| 283 | 289 |
|
| 284 |
numRenders += lastEffects.postprocess(this);
|
|
| 290 |
numRenders += lastQueue.postprocess(this);
|
|
| 285 | 291 |
numRenders += blitWithDepth(time, mBuffer[quality]); |
| 286 | 292 |
} |
| 287 | 293 |
|
| 288 |
internalQuality = currEffects.getInternalQuality();
|
|
| 289 |
quality = currEffects.getQuality();
|
|
| 290 |
bucketChange = i; |
|
| 294 |
internalQuality = currQueue.getInternalQuality();
|
|
| 295 |
quality = currQueue.getQuality();
|
|
| 296 |
bucketChange = i;
|
|
| 291 | 297 |
} |
| 292 | 298 |
|
| 293 |
numRenders += child1.draw(time,mBuffer[quality]); |
|
| 299 |
child1.draw(time,mBuffer[quality]); |
|
| 300 |
//numRenders += currQueue.draw(child1,time,mBuffer); |
|
| 294 | 301 |
|
| 295 | 302 |
if( i==numChildren-1 ) |
| 296 | 303 |
{
|
| 297 | 304 |
for(int j=bucketChange; j<numChildren; j++) |
| 298 | 305 |
{
|
| 299 | 306 |
child2 = children.get(j); |
| 300 |
numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],currEffects);
|
|
| 307 |
numRenders += child2.markStencilAndDepth(time,mBuffer[internalQuality],currQueue);
|
|
| 301 | 308 |
} |
| 302 | 309 |
|
| 303 |
numRenders += currEffects.postprocess(this);
|
|
| 310 |
numRenders += currQueue.postprocess(this);
|
|
| 304 | 311 |
numRenders += blitWithDepth(time, mBuffer[quality]); |
| 305 | 312 |
} |
| 306 | 313 |
} |
| 307 | 314 |
|
| 308 |
lastEffects = currEffects;
|
|
| 309 |
lastBucket = currBucket;
|
|
| 315 |
lastQueue = currQueue;
|
|
| 316 |
lastBucket= currBucket; |
|
| 310 | 317 |
} |
| 311 | 318 |
|
| 312 | 319 |
if( !sLast.equals(sCurr) ) android.util.Log.e("surface", "rendering: "+sCurr);
|
Also available in: Unified diff
Internal API change around postprocessing.