Revision 9d845904
Added by Leszek Koltunski over 6 years ago
src/main/java/org/distorted/library/main/DistortedFramebuffer.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
void create() |
38 | 38 |
{ |
39 |
////////////////////////////////////////////////////////////// |
|
40 |
// COLOR |
|
41 |
|
|
39 | 42 |
if( mColorCreated==NOT_CREATED_YET ) |
40 | 43 |
{ |
41 |
GLES31.glGenTextures( mNumColors, mColorH, 0); |
|
42 |
GLES31.glGenFramebuffers(1, mFBOH, 0); |
|
43 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]); |
|
44 |
GLES31.glGenTextures( mNumFBOs*mNumColors, mColorH, 0); |
|
45 |
GLES31.glGenFramebuffers(mNumFBOs, mFBOH, 0); |
|
44 | 46 |
|
45 |
for(int i=0; i<mNumColors; i++)
|
|
47 |
for(int i=0; i<mNumFBOs; i++)
|
|
46 | 48 |
{ |
47 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[i]); |
|
48 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_S, GLES31.GL_REPEAT); |
|
49 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT); |
|
50 |
GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST); |
|
51 |
GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_LINEAR); |
|
52 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_RGBA, mRealWidth, mRealHeight, 0, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, null); |
|
49 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[i]); |
|
50 |
|
|
51 |
for(int j=0; j<mNumColors; j++) |
|
52 |
{ |
|
53 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[i*mNumColors+j]); |
|
54 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_S, GLES31.GL_REPEAT); |
|
55 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT); |
|
56 |
GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST); |
|
57 |
GLES31.glTexParameterf(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_LINEAR); |
|
58 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_RGBA, mRealWidth, mRealHeight, 0, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, null); |
|
59 |
} |
|
60 |
|
|
61 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[i*mNumColors], 0); |
|
62 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0); |
|
53 | 63 |
} |
54 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_COLOR_ATTACHMENT0, GLES31.GL_TEXTURE_2D, mColorH[0], 0); |
|
55 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0); |
|
56 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0); |
|
57 | 64 |
|
65 |
// TODO |
|
58 | 66 |
mColorCreated = checkStatus("color"); |
67 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0); |
|
59 | 68 |
} |
69 |
|
|
70 |
////////////////////////////////////////////////////////////// |
|
71 |
// DEPTH / STENCIL |
|
72 |
|
|
60 | 73 |
if( mDepthStencilCreated==NOT_CREATED_YET ) // we need to create a new DEPTH or STENCIL attachment |
61 | 74 |
{ |
62 |
GLES31.glGenTextures(1, mDepthStencilH, 0); |
|
63 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mDepthStencilH[0]); |
|
64 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_S, GLES31.GL_REPEAT); |
|
65 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT); |
|
66 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST); |
|
67 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_NEAREST); |
|
68 |
|
|
69 |
if( mDepthStencil==DEPTH_NO_STENCIL ) |
|
70 |
{ |
|
71 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH_COMPONENT, mRealWidth, mRealHeight, 0, GLES31.GL_DEPTH_COMPONENT, GLES31.GL_UNSIGNED_INT, null); |
|
72 |
} |
|
73 |
else if( mDepthStencil==BOTH_DEPTH_STENCIL ) |
|
75 |
GLES31.glGenTextures(mNumFBOs, mDepthStencilH, 0); |
|
76 |
|
|
77 |
for(int i=0; i<mNumFBOs; i++) |
|
74 | 78 |
{ |
75 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH24_STENCIL8, mRealWidth, mRealHeight, 0, GLES31.GL_DEPTH_STENCIL, GLES31.GL_UNSIGNED_INT_24_8, null); |
|
79 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mDepthStencilH[i]); |
|
80 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_S, GLES31.GL_REPEAT); |
|
81 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_WRAP_T, GLES31.GL_REPEAT); |
|
82 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MIN_FILTER, GLES31.GL_NEAREST); |
|
83 |
GLES31.glTexParameteri(GLES31.GL_TEXTURE_2D, GLES31.GL_TEXTURE_MAG_FILTER, GLES31.GL_NEAREST); |
|
84 |
|
|
85 |
if (mDepthStencil == DEPTH_NO_STENCIL) |
|
86 |
{ |
|
87 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH_COMPONENT, mRealWidth, mRealHeight, 0, GLES31.GL_DEPTH_COMPONENT, GLES31.GL_UNSIGNED_INT, null); |
|
88 |
} |
|
89 |
else if (mDepthStencil == BOTH_DEPTH_STENCIL) |
|
90 |
{ |
|
91 |
GLES31.glTexImage2D(GLES31.GL_TEXTURE_2D, 0, GLES31.GL_DEPTH24_STENCIL8, mRealWidth, mRealHeight, 0, GLES31.GL_DEPTH_STENCIL, GLES31.GL_UNSIGNED_INT_24_8, null); |
|
92 |
} |
|
76 | 93 |
} |
77 |
|
|
78 | 94 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, 0); |
79 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]); |
|
80 | 95 |
|
81 |
if( mDepthStencil==DEPTH_NO_STENCIL ) |
|
82 |
{ |
|
83 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_ATTACHMENT, GLES31.GL_TEXTURE_2D, mDepthStencilH[0], 0); |
|
84 |
} |
|
85 |
else if( mDepthStencil==BOTH_DEPTH_STENCIL ) |
|
96 |
for(int i=0; i<mNumFBOs; i++) |
|
86 | 97 |
{ |
87 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_STENCIL_ATTACHMENT, GLES31.GL_TEXTURE_2D, mDepthStencilH[0], 0); |
|
98 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[i]); |
|
99 |
|
|
100 |
if (mDepthStencil == DEPTH_NO_STENCIL) |
|
101 |
{ |
|
102 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_ATTACHMENT, GLES31.GL_TEXTURE_2D, mDepthStencilH[i], 0); |
|
103 |
} |
|
104 |
else if (mDepthStencil == BOTH_DEPTH_STENCIL) |
|
105 |
{ |
|
106 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_STENCIL_ATTACHMENT, GLES31.GL_TEXTURE_2D, mDepthStencilH[i], 0); |
|
107 |
} |
|
88 | 108 |
} |
89 | 109 |
|
90 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0); |
|
91 |
|
|
110 |
// TODO |
|
92 | 111 |
mDepthStencilCreated = checkStatus("depth"); |
112 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0); |
|
93 | 113 |
} |
114 |
|
|
115 |
////////////////////////////////////////////////////////////// |
|
116 |
// DETACH |
|
117 |
|
|
118 |
// TODO |
|
94 | 119 |
if( mDepthStencilCreated==DONT_CREATE && mDepthStencilH[0]>0 ) // we need to detach and recreate the DEPTH attachment. |
95 | 120 |
{ |
96 | 121 |
// OpenGL ES 3.0.5 spec, chapter 4.4.2.4 : |
97 | 122 |
// "Note that the texture image is specifically not detached from any other framebuffer objects. |
98 | 123 |
// Detaching the texture image from any other framebuffer objects is the responsibility of the application." |
99 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]); |
|
100 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_ATTACHMENT , GLES31.GL_TEXTURE_2D, 0, 0); |
|
101 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_STENCIL_ATTACHMENT, GLES31.GL_TEXTURE_2D, 0, 0); |
|
102 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0); |
|
103 | 124 |
|
104 |
GLES31.glDeleteTextures(1, mDepthStencilH, 0); |
|
105 |
mDepthStencilH[0]=0; |
|
125 |
for(int i=0; i<mNumFBOs; i++) |
|
126 |
{ |
|
127 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[i]); |
|
128 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_ATTACHMENT, GLES31.GL_TEXTURE_2D, 0, 0); |
|
129 |
GLES31.glFramebufferTexture2D(GLES31.GL_FRAMEBUFFER, GLES31.GL_DEPTH_STENCIL_ATTACHMENT, GLES31.GL_TEXTURE_2D, 0, 0); |
|
130 |
mDepthStencilH[i]=0; |
|
131 |
} |
|
132 |
|
|
133 |
GLES31.glDeleteTextures(mNumFBOs, mDepthStencilH, 0); |
|
134 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0); |
|
106 | 135 |
} |
107 | 136 |
} |
108 | 137 |
|
109 | 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
139 |
// TODO |
|
110 | 140 |
|
111 | 141 |
private int checkStatus(String message) |
112 | 142 |
{ |
... | ... | |
134 | 164 |
{ |
135 | 165 |
if( mColorH[0]>0 ) |
136 | 166 |
{ |
137 |
GLES31.glDeleteTextures(1, mColorH, 0); |
|
138 |
mColorH[0] = 0; |
|
167 |
GLES31.glDeleteTextures(mNumFBOs*mNumColors, mColorH, 0); |
|
139 | 168 |
mColorCreated = NOT_CREATED_YET; |
169 |
|
|
170 |
for(int i=0; i<mNumFBOs*mNumColors; i++) mColorH[i] = 0; |
|
140 | 171 |
} |
141 | 172 |
|
142 | 173 |
if( mDepthStencilH[0]>0 ) |
143 | 174 |
{ |
144 |
GLES31.glDeleteTextures(1, mDepthStencilH, 0); |
|
145 |
mDepthStencilH[0]=0; |
|
175 |
GLES31.glDeleteTextures(mNumFBOs, mDepthStencilH, 0); |
|
146 | 176 |
mDepthStencilCreated = NOT_CREATED_YET; |
177 |
|
|
178 |
for(int i=0; i<mNumFBOs; i++) mDepthStencilH[i] = 0; |
|
147 | 179 |
} |
148 | 180 |
|
149 |
GLES31.glDeleteFramebuffers(1, mFBOH, 0);
|
|
150 |
mFBOH[0] = 0;
|
|
181 |
GLES31.glDeleteFramebuffers(mNumFBOs, mFBOH, 0);
|
|
182 |
for(int i=0; i<mNumFBOs; i++) mFBOH[i] = 0;
|
|
151 | 183 |
} |
152 | 184 |
|
153 | 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
167 | 199 |
} |
168 | 200 |
} |
169 | 201 |
|
202 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
203 |
|
|
204 |
boolean setAsInput(int fbo, int texture) |
|
205 |
{ |
|
206 |
if( texture>=0 && texture<mNumColors && fbo>=0 && fbo<mNumFBOs && mColorH[mNumColors*fbo + texture]>0 ) |
|
207 |
{ |
|
208 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE0); |
|
209 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, mColorH[mNumColors*fbo + texture]); |
|
210 |
return true; |
|
211 |
} |
|
212 |
|
|
213 |
return false; |
|
214 |
} |
|
215 |
|
|
170 | 216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
171 | 217 |
// create SYSTEM or TREE framebuffers (those are just like normal FBOs, just hold information |
172 | 218 |
// that they were autocreated only for the Library's internal purposes (SYSTEM) or for using |
... | ... | |
175 | 221 |
|
176 | 222 |
DistortedFramebuffer(int numcolors, int depthStencil, int type, int width, int height) |
177 | 223 |
{ |
178 |
super(width,height,NOT_CREATED_YET,numcolors,depthStencil,NOT_CREATED_YET, type); |
|
224 |
super(width,height,NOT_CREATED_YET,1,numcolors,depthStencil,NOT_CREATED_YET, type); |
|
225 |
} |
|
226 |
|
|
227 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
228 |
// create a multi-framebuffer (1 object containing multiple FBOs) |
|
229 |
|
|
230 |
DistortedFramebuffer(int numfbos, int numcolors, int depthStencil, int type, int width, int height) |
|
231 |
{ |
|
232 |
super(width,height,NOT_CREATED_YET,numfbos,numcolors,depthStencil,NOT_CREATED_YET, type); |
|
179 | 233 |
} |
180 | 234 |
|
181 | 235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
193 | 247 |
@SuppressWarnings("unused") |
194 | 248 |
public DistortedFramebuffer(int width, int height, int numcolors, int depthStencil) |
195 | 249 |
{ |
196 |
super(width,height,NOT_CREATED_YET,numcolors,depthStencil,NOT_CREATED_YET,TYPE_USER); |
|
250 |
super(width,height,NOT_CREATED_YET,1,numcolors,depthStencil,NOT_CREATED_YET,TYPE_USER);
|
|
197 | 251 |
} |
198 | 252 |
|
199 | 253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/main/DistortedNode.java | ||
---|---|---|
341 | 341 |
DistortedEffects.blitPriv(mData.mFBO); |
342 | 342 |
} |
343 | 343 |
|
344 |
numRenders += mData.mFBO.renderChildren(currTime,mNumChildren[0],mChildren); |
|
344 |
numRenders += mData.mFBO.renderChildren(currTime,mNumChildren[0],mChildren,0);
|
|
345 | 345 |
} |
346 | 346 |
|
347 | 347 |
return numRenders; |
src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
---|---|---|
72 | 72 |
// Global buffers used for postprocessing. |
73 | 73 |
private static DistortedOutputSurface[] mBuffer = null; |
74 | 74 |
|
75 |
private long mTime; |
|
76 | 75 |
private float mFOV; |
77 | 76 |
float mDistance, mNear; |
78 | 77 |
float[] mProjectionMatrix; |
79 | 78 |
|
80 | 79 |
int mDepthStencilCreated; |
81 | 80 |
int mDepthStencil; |
82 |
int[] mDepthStencilH = new int[1]; |
|
83 |
int[] mFBOH = new int[1]; |
|
81 |
int[] mDepthStencilH; |
|
82 |
int[] mFBOH; |
|
83 |
private long[] mTime; |
|
84 | 84 |
|
85 | 85 |
private float mClearR, mClearG, mClearB, mClearA; |
86 | 86 |
private float mClearDepth; |
... | ... | |
95 | 95 |
|
96 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
97 | 97 |
|
98 |
DistortedOutputSurface(int width, int height, int createColor, int numcolors, int depthStencil, int fbo, int type) |
|
98 |
DistortedOutputSurface(int width, int height, int createColor, int numfbos, int numcolors, int depthStencil, int fbo, int type)
|
|
99 | 99 |
{ |
100 |
super(width,height,createColor,numcolors,type); |
|
100 |
super(width,height,createColor,numfbos,numcolors,type); |
|
101 |
|
|
102 |
mDepthStencilH = new int[numfbos]; |
|
103 |
mFBOH = new int[numfbos]; |
|
104 |
|
|
105 |
mTime = new long[numfbos]; |
|
106 |
for(int i=0; i<mNumFBOs;i++) mTime[i]=0; |
|
101 | 107 |
|
102 | 108 |
mRealWidth = width; |
103 | 109 |
mRealHeight= height; |
... | ... | |
113 | 119 |
mFBOH[0] = fbo; |
114 | 120 |
mDepthStencilH[0]= 0; |
115 | 121 |
|
116 |
mTime = 0; |
|
117 |
|
|
118 | 122 |
mClearR = 0.0f; |
119 | 123 |
mClearG = 0.0f; |
120 | 124 |
mClearB = 0.0f; |
... | ... | |
260 | 264 |
|
261 | 265 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
262 | 266 |
|
263 |
private int blitWithDepth(long currTime, DistortedOutputSurface buffer) |
|
267 |
private int blitWithDepth(long currTime, DistortedOutputSurface buffer,int fbo)
|
|
264 | 268 |
{ |
265 | 269 |
GLES31.glViewport(0, 0, mWidth, mHeight); |
266 |
setAsOutput(currTime); |
|
270 |
setAsOutput(currTime,fbo);
|
|
267 | 271 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE0); |
268 | 272 |
GLES31.glBindTexture(GLES31.GL_TEXTURE_2D, buffer.mColorH[0]); |
269 | 273 |
GLES31.glActiveTexture(GLES31.GL_TEXTURE1); |
... | ... | |
312 | 316 |
// Otherwise, render to a buffer and on each change of Postprocessing Bucket, apply the postprocessing |
313 | 317 |
// to a whole buffer (lastQueue.postprocess) and merge it (this.blitWithDepth). |
314 | 318 |
|
315 |
int renderChildren(long time, int numChildren, ArrayList<DistortedNode> children) |
|
319 |
int renderChildren(long time, int numChildren, ArrayList<DistortedNode> children, int fbo)
|
|
316 | 320 |
{ |
317 | 321 |
int quality=0, internalQuality = 0, numRenders = 0, bucketChange = 0; |
318 | 322 |
DistortedNode child1, child2; |
... | ... | |
327 | 331 |
|
328 | 332 |
if( currBucket==0 ) |
329 | 333 |
{ |
330 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]);
|
|
334 |
setAsOutput(time,fbo);
|
|
331 | 335 |
numRenders += child1.draw(time,this); |
332 | 336 |
} |
333 | 337 |
else |
... | ... | |
349 | 353 |
} |
350 | 354 |
|
351 | 355 |
numRenders += lastQueue.postprocess(mBuffer); |
352 |
numRenders += blitWithDepth(time, mBuffer[quality]); |
|
356 |
numRenders += blitWithDepth(time, mBuffer[quality],fbo);
|
|
353 | 357 |
|
354 | 358 |
mBuffer[quality].setAsOutputAndClear(time); |
355 | 359 |
} |
... | ... | |
371 | 375 |
} |
372 | 376 |
|
373 | 377 |
numRenders += currQueue.postprocess(mBuffer); |
374 |
numRenders += blitWithDepth(time, mBuffer[quality]); |
|
378 |
numRenders += blitWithDepth(time, mBuffer[quality],fbo);
|
|
375 | 379 |
} |
376 | 380 |
} // end postprocessed child case |
377 | 381 |
|
... | ... | |
423 | 427 |
{ |
424 | 428 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]); |
425 | 429 |
|
426 |
mTime = time; // have to do this otherwise on the next setAsOutput() we would clear |
|
430 |
mTime[0] = time; // have to do this otherwise on the next setAsOutput() we would clear
|
|
427 | 431 |
DistortedRenderState.colorDepthStencilOn(); |
428 | 432 |
GLES31.glClearColor(mClearR, mClearG, mClearB, mClearA); |
429 | 433 |
GLES31.glClear(GLES31.GL_COLOR_BUFFER_BIT); |
430 | 434 |
DistortedRenderState.colorDepthStencilRestore(); |
431 | 435 |
} |
432 | 436 |
|
437 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
438 |
|
|
439 |
private void setAsOutput(long time, int fbo) |
|
440 |
{ |
|
441 |
if( fbo>=0 && fbo<mNumFBOs ) |
|
442 |
{ |
|
443 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[fbo]); |
|
444 |
|
|
445 |
if (mTime[fbo] != time) |
|
446 |
{ |
|
447 |
mTime[fbo] = time; |
|
448 |
clear(); |
|
449 |
} |
|
450 |
} |
|
451 |
else |
|
452 |
{ |
|
453 |
android.util.Log.e("surface", "error in setAsOutput, fbo="+fbo); |
|
454 |
} |
|
455 |
} |
|
456 |
|
|
433 | 457 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
434 | 458 |
// PUBLIC API |
435 | 459 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
460 |
/** |
|
461 |
* Draws all the attached children to this OutputSurface's 0th FBO. |
|
462 |
* <p> |
|
463 |
* Must be called from a thread holding OpenGL Context. |
|
464 |
* |
|
465 |
* @param time Current time, in milliseconds. This will be passed to all the Effects stored in the children Nodes. |
|
466 |
* @return Number of objects rendered. |
|
467 |
*/ |
|
468 |
public int render(long time) |
|
469 |
{ |
|
470 |
return render(time,0); |
|
471 |
} |
|
436 | 472 |
|
473 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
437 | 474 |
/** |
438 | 475 |
* Draws all the attached children to this OutputSurface. |
439 | 476 |
* <p> |
440 | 477 |
* Must be called from a thread holding OpenGL Context. |
441 | 478 |
* |
442 | 479 |
* @param time Current time, in milliseconds. This will be passed to all the Effects stored in the children Nodes. |
480 |
* @param fbo The surface can have many FBOs backing it up - render this to FBO number 'fbo'. |
|
443 | 481 |
* @return Number of objects rendered. |
444 | 482 |
*/ |
445 |
public int render(long time) |
|
483 |
public int render(long time, int fbo)
|
|
446 | 484 |
{ |
447 | 485 |
// change tree topology (attach and detach children) |
448 | 486 |
/* |
... | ... | |
485 | 523 |
numRenders += mChildren.get(i).renderRecursive(time); |
486 | 524 |
} |
487 | 525 |
|
488 |
setAsOutput(time); |
|
489 |
numRenders += renderChildren(time,mNumChildren,mChildren); |
|
526 |
numRenders += renderChildren(time,mNumChildren,mChildren,fbo); |
|
490 | 527 |
|
491 | 528 |
return numRenders; |
492 | 529 |
} |
... | ... | |
504 | 541 |
{ |
505 | 542 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, mFBOH[0]); |
506 | 543 |
|
507 |
if( mTime!=time ) |
|
544 |
if( mTime[0]!=time )
|
|
508 | 545 |
{ |
509 |
mTime = time; |
|
546 |
mTime[0] = time;
|
|
510 | 547 |
clear(); |
511 | 548 |
} |
512 | 549 |
} |
src/main/java/org/distorted/library/main/DistortedScreen.java | ||
---|---|---|
55 | 55 |
private static MatrixEffectMove mMoveEffect = new MatrixEffectMove( new Static3D(5,5,0) ); |
56 | 56 |
///// END DEBUGGING ////////////////////////// |
57 | 57 |
|
58 |
private int mCurrFBO; |
|
59 |
private static final int NUM_FBO = 3; |
|
60 |
|
|
58 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
59 | 62 |
// PUBLIC API |
60 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
65 | 68 |
*/ |
66 | 69 |
public DistortedScreen() |
67 | 70 |
{ |
68 |
super(1,1,1,BOTH_DEPTH_STENCIL);
|
|
71 |
super(NUM_FBO,1,BOTH_DEPTH_STENCIL, TYPE_SYST, 1,1);
|
|
69 | 72 |
mShowFPS = false; |
73 |
mCurrFBO = 0; |
|
70 | 74 |
} |
71 | 75 |
|
72 | 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
100 | 104 |
lastTime = time; |
101 | 105 |
} |
102 | 106 |
|
103 |
int numrender = super.render(time); |
|
107 |
int numrender = super.render(time,mCurrFBO);
|
|
104 | 108 |
|
105 | 109 |
GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0); |
106 |
clear(); |
|
107 |
setAsInput(); |
|
110 |
setAsInput(mCurrFBO,0); |
|
108 | 111 |
GLES31.glColorMask(true,true,true,true); |
109 | 112 |
GLES31.glDepthMask(false); |
110 | 113 |
GLES31.glDisable(GLES31.GL_STENCIL_TEST); |
... | ... | |
118 | 121 |
fpsEffects.drawPriv(fpsW / 2.0f, fpsH / 2.0f, fpsMesh, this, time, 0); |
119 | 122 |
} |
120 | 123 |
|
124 |
mCurrFBO++; |
|
125 |
if( mCurrFBO>=NUM_FBO ) mCurrFBO=0; |
|
126 |
|
|
121 | 127 |
return numrender+1; |
122 | 128 |
} |
123 | 129 |
|
src/main/java/org/distorted/library/main/DistortedSurface.java | ||
---|---|---|
25 | 25 |
{ |
26 | 26 |
int mColorCreated; |
27 | 27 |
int mNumColors; |
28 |
int mNumFBOs; |
|
28 | 29 |
int[] mColorH; |
29 | 30 |
int mWidth, mHeight; |
30 | 31 |
|
31 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
32 | 33 |
|
33 |
DistortedSurface(int width, int height, int create, int numcolors, int type) |
|
34 |
DistortedSurface(int width, int height, int create, int numfbos, int numcolors, int type)
|
|
34 | 35 |
{ |
35 | 36 |
super(create,type); |
36 | 37 |
|
38 |
mNumFBOs = numfbos; |
|
37 | 39 |
mNumColors = numcolors; |
38 | 40 |
mWidth = width ; |
39 | 41 |
mHeight = height; |
40 | 42 |
mColorCreated = create; |
41 | 43 |
|
42 |
if( mNumColors>0 ) |
|
44 |
int total = mNumFBOs*mNumColors; |
|
45 |
|
|
46 |
if( total>0 ) |
|
43 | 47 |
{ |
44 |
mColorH = new int[mNumColors];
|
|
45 |
for( int i=0; i<mNumColors; i++ ) mColorH[i] = 0;
|
|
48 |
mColorH = new int[total];
|
|
49 |
for( int i=0; i<total; i++ ) mColorH[i] = 0;
|
|
46 | 50 |
} |
47 | 51 |
} |
48 | 52 |
|
src/main/java/org/distorted/library/main/DistortedTexture.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
public class DistortedTexture extends DistortedSurface implements DistortedInputSurface |
36 | 36 |
{ |
37 |
private Bitmap mBmp= null;
|
|
37 |
private Bitmap mBmp; |
|
38 | 38 |
|
39 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 40 |
// We have to flip vertically every single Bitmap that we get fed with. |
... | ... | |
115 | 115 |
|
116 | 116 |
public DistortedTexture(int width, int height, int type) |
117 | 117 |
{ |
118 |
super(width,height,NOT_CREATED_YET,1,type); |
|
118 |
super(width,height,NOT_CREATED_YET,1,1,type);
|
|
119 | 119 |
mBmp= null; |
120 | 120 |
} |
121 | 121 |
|
... | ... | |
127 | 127 |
*/ |
128 | 128 |
public DistortedTexture(int width, int height) |
129 | 129 |
{ |
130 |
super(width,height,NOT_CREATED_YET,1,TYPE_USER); |
|
130 |
super(width,height,NOT_CREATED_YET,1,1,TYPE_USER);
|
|
131 | 131 |
mBmp= null; |
132 | 132 |
} |
133 | 133 |
|
Also available in: Unified diff
Finally properly fix the flashing on ARM Mali T880 GPU.
The flashing is caused by a 'full pipeline flush' (see DarkPhoton, https://www.opengl.org/discussion_boards/showthread.php/200754-Flashes-on-ARM-Mali?p=1291679&viewfull=1#post1291679 ). In order to combat it, first introduce the possibility that a single DistortedOutputSurface is backed up by more than one FBO. Then make DistortedScreen be derived from DistortedFramebuffer (which itself is derived from DistortedOutputSurface) and make it contain 3 FBOs, render to them in a circular queue fashion, and blit from a given FBO to the system FBO. The 'more than 1 intermediate FBO' queue prevents the pipeline flush.
Still some TODOs in DistortedFramebuffer remain (properly check for Framebuffer completness!)