131 |
131 |
private static long mNextID =0;
|
132 |
132 |
private long mID;
|
133 |
133 |
|
134 |
|
private EffectQueueMatrix mM;
|
135 |
|
private EffectQueueFragment mF;
|
136 |
|
private EffectQueueVertex mV;
|
137 |
|
private EffectQueuePostprocess mP;
|
138 |
|
|
139 |
|
private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
|
|
134 |
private EffectQueue[] mQueues;
|
140 |
135 |
|
141 |
136 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142 |
137 |
|
... | ... | |
154 |
149 |
String enabledEffectV= VertexEffect.getGLSL();
|
155 |
150 |
String enabledEffectF= FragmentEffect.getGLSL();
|
156 |
151 |
|
157 |
|
//android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
|
158 |
|
//android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
|
159 |
|
//android.util.Log.e("Effects", "enabledV= "+enabledEffectV);
|
160 |
|
//android.util.Log.e("Effects", "enabledF= "+enabledEffectF);
|
161 |
|
|
162 |
152 |
String[] feedback = { "v_Position", "v_endPosition" };
|
163 |
153 |
|
164 |
154 |
try
|
... | ... | |
173 |
163 |
}
|
174 |
164 |
|
175 |
165 |
int mainProgramH = mMainProgram.getProgramHandle();
|
176 |
|
EffectQueueFragment.getUniforms(mainProgramH,0);
|
177 |
|
EffectQueueVertex.getUniforms(mainProgramH,0);
|
178 |
|
EffectQueueMatrix.getUniforms(mainProgramH,0);
|
|
166 |
EffectQueue.getUniforms(mainProgramH,0);
|
179 |
167 |
mMainTextureH= GLES31.glGetUniformLocation( mainProgramH, "u_Texture");
|
180 |
168 |
|
181 |
169 |
// BLIT PROGRAM ////////////////////////////////////
|
... | ... | |
267 |
255 |
}
|
268 |
256 |
|
269 |
257 |
int mainOITProgramH = mMainOITProgram.getProgramHandle();
|
270 |
|
EffectQueueFragment.getUniforms(mainOITProgramH,1);
|
271 |
|
EffectQueueVertex.getUniforms(mainOITProgramH,1);
|
272 |
|
EffectQueueMatrix.getUniforms(mainOITProgramH,1);
|
|
258 |
EffectQueue.getUniforms(mainOITProgramH,1);
|
273 |
259 |
mMainOITTextureH = GLES31.glGetUniformLocation( mainOITProgramH, "u_Texture");
|
274 |
260 |
mMainOITSizeH = GLES31.glGetUniformLocation( mainOITProgramH, "u_Size");
|
275 |
261 |
mMainOITNumRecordsH = GLES31.glGetUniformLocation( mainOITProgramH, "u_numRecords");
|
... | ... | |
357 |
343 |
|
358 |
344 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
359 |
345 |
|
360 |
|
private void initializeEffectLists(DistortedEffects d, int flags)
|
|
346 |
EffectQueue[] getQueues()
|
361 |
347 |
{
|
362 |
|
if( (flags & Distorted.CLONE_MATRIX) != 0 )
|
363 |
|
{
|
364 |
|
mM = d.mM;
|
365 |
|
matrixCloned = true;
|
366 |
|
}
|
367 |
|
else
|
368 |
|
{
|
369 |
|
mM = new EffectQueueMatrix(mID);
|
370 |
|
matrixCloned = false;
|
371 |
|
}
|
372 |
|
|
373 |
|
if( (flags & Distorted.CLONE_VERTEX) != 0 )
|
374 |
|
{
|
375 |
|
mV = d.mV;
|
376 |
|
vertexCloned = true;
|
377 |
|
}
|
378 |
|
else
|
379 |
|
{
|
380 |
|
mV = new EffectQueueVertex(mID);
|
381 |
|
vertexCloned = false;
|
382 |
|
}
|
383 |
|
|
384 |
|
if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
|
385 |
|
{
|
386 |
|
mF = d.mF;
|
387 |
|
fragmentCloned = true;
|
388 |
|
}
|
389 |
|
else
|
390 |
|
{
|
391 |
|
mF = new EffectQueueFragment(mID);
|
392 |
|
fragmentCloned = false;
|
393 |
|
}
|
394 |
|
|
395 |
|
if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
|
396 |
|
{
|
397 |
|
mP = d.mP;
|
398 |
|
postprocessCloned = true;
|
399 |
|
}
|
400 |
|
else
|
401 |
|
{
|
402 |
|
mP = new EffectQueuePostprocess(mID);
|
403 |
|
postprocessCloned = false;
|
404 |
|
}
|
405 |
|
}
|
406 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
407 |
|
|
408 |
|
EffectQueueMatrix getMatrix()
|
409 |
|
{
|
410 |
|
return mM;
|
411 |
|
}
|
412 |
|
|
413 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
414 |
|
|
415 |
|
EffectQueueVertex getVertex()
|
416 |
|
{
|
417 |
|
return mV;
|
418 |
|
}
|
419 |
|
|
420 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
421 |
|
|
422 |
|
EffectQueueFragment getFragment()
|
423 |
|
{
|
424 |
|
return mF;
|
425 |
|
}
|
426 |
|
|
427 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
428 |
|
|
429 |
|
EffectQueuePostprocess getPostprocess()
|
430 |
|
{
|
431 |
|
return mP;
|
|
348 |
return mQueues;
|
432 |
349 |
}
|
433 |
350 |
|
434 |
351 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
435 |
352 |
|
436 |
353 |
void newNode(DistortedNode node)
|
437 |
354 |
{
|
438 |
|
mP.newNode(node);
|
|
355 |
EffectQueue.newNode(mQueues,node);
|
439 |
356 |
}
|
440 |
357 |
|
441 |
358 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
442 |
359 |
|
443 |
360 |
void removeNode(DistortedNode node)
|
444 |
361 |
{
|
445 |
|
mP.removeNode(node);
|
|
362 |
EffectQueue.removeNode(mQueues,node);
|
446 |
363 |
}
|
447 |
364 |
|
448 |
365 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
461 |
378 |
GLES31.glBindBufferBase(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
|
462 |
379 |
|
463 |
380 |
mNormalProgram.useProgram();
|
464 |
|
GLES31.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, mM.getMVP() , 0);
|
|
381 |
GLES31.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, EffectQueue.getMVP(mQueues) , 0);
|
465 |
382 |
mesh.bindTransformAttribs(mNormalProgram);
|
466 |
383 |
GLES31.glLineWidth(8.0f);
|
467 |
384 |
GLES31.glDrawArrays(GLES31.GL_LINES, 0, 2*num);
|
... | ... | |
473 |
390 |
{
|
474 |
391 |
float halfZ = halfW*mesh.getZFactor();
|
475 |
392 |
|
476 |
|
mM.compute(currTime);
|
477 |
|
mV.compute(currTime,halfW,halfH,halfZ);
|
478 |
|
mF.compute(currTime,halfW,halfH,halfZ);
|
479 |
|
mP.compute(currTime);
|
480 |
|
|
|
393 |
EffectQueue.compute(mQueues, currTime, halfW, halfH, halfZ );
|
481 |
394 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
482 |
395 |
|
483 |
396 |
mMainOITProgram.useProgram();
|
... | ... | |
489 |
402 |
|
490 |
403 |
float inflate = mesh.getInflate();
|
491 |
404 |
|
492 |
|
mM.send(surface,halfW,halfH,halfZ,1);
|
493 |
|
mV.send(inflate,1);
|
494 |
|
mF.send(1);
|
495 |
|
|
|
405 |
EffectQueue.send(mQueues, surface, inflate, halfW, halfH, halfZ, 1 );
|
496 |
406 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
|
497 |
407 |
|
498 |
408 |
if( mesh.getShowNormals() )
|
499 |
409 |
{
|
500 |
410 |
mMainProgram.useProgram();
|
501 |
|
mM.send(surface,halfW,halfH,halfZ,0);
|
502 |
|
mV.send(inflate,0);
|
503 |
|
mF.send(0);
|
|
411 |
EffectQueue.send(mQueues, surface, inflate, halfW, halfH, halfZ, 0 );
|
504 |
412 |
displayNormals(mesh);
|
505 |
413 |
}
|
506 |
414 |
}
|
... | ... | |
511 |
419 |
{
|
512 |
420 |
float halfZ = halfW*mesh.getZFactor();
|
513 |
421 |
|
514 |
|
mM.compute(currTime);
|
515 |
|
mV.compute(currTime,halfW,halfH,halfZ);
|
516 |
|
mF.compute(currTime,halfW,halfH,halfZ);
|
517 |
|
mP.compute(currTime);
|
518 |
|
|
|
422 |
EffectQueue.compute(mQueues, currTime, halfW, halfH, halfZ );
|
519 |
423 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
|
520 |
|
|
521 |
424 |
mMainProgram.useProgram();
|
522 |
425 |
GLES31.glUniform1i(mMainTextureH, 0);
|
523 |
|
|
524 |
426 |
mesh.bindVertexAttribs(mMainProgram);
|
525 |
|
|
526 |
|
mM.send(surface,halfW,halfH,halfZ,0);
|
527 |
|
mV.send( mesh.getInflate(),0);
|
528 |
|
mF.send(0);
|
529 |
|
|
|
427 |
EffectQueue.send(mQueues, surface, mesh.getInflate(), halfW, halfH, halfZ, 0 );
|
530 |
428 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() );
|
531 |
429 |
|
532 |
430 |
if( mesh.getShowNormals() ) displayNormals(mesh);
|
... | ... | |
729 |
627 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
|
730 |
628 |
}
|
731 |
629 |
|
732 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
733 |
|
|
734 |
|
private void releasePriv()
|
735 |
|
{
|
736 |
|
if( !matrixCloned ) mM.abortAll(false);
|
737 |
|
if( !vertexCloned ) mV.abortAll(false);
|
738 |
|
if( !fragmentCloned ) mF.abortAll(false);
|
739 |
|
if( !postprocessCloned ) mP.abortAll(false);
|
740 |
|
|
741 |
|
mM = null;
|
742 |
|
mV = null;
|
743 |
|
mF = null;
|
744 |
|
mP = null;
|
745 |
|
}
|
746 |
|
|
747 |
630 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
748 |
631 |
|
749 |
632 |
static void onPause()
|
... | ... | |
776 |
659 |
public DistortedEffects()
|
777 |
660 |
{
|
778 |
661 |
mID = ++mNextID;
|
779 |
|
initializeEffectLists(this,0);
|
|
662 |
mQueues = new EffectQueue[EffectType.LENGTH];
|
|
663 |
EffectQueue.allocateQueues(mQueues,null,0,mID);
|
780 |
664 |
}
|
781 |
665 |
|
782 |
666 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
792 |
676 |
public DistortedEffects(DistortedEffects dc, int flags)
|
793 |
677 |
{
|
794 |
678 |
mID = ++mNextID;
|
795 |
|
initializeEffectLists(dc,flags);
|
796 |
|
}
|
797 |
|
|
798 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
799 |
|
/**
|
800 |
|
* Releases all resources. After this call, the queue should not be used anymore.
|
801 |
|
*/
|
802 |
|
@SuppressWarnings("unused")
|
803 |
|
public synchronized void delete()
|
804 |
|
{
|
805 |
|
releasePriv();
|
|
679 |
mQueues = new EffectQueue[EffectType.LENGTH];
|
|
680 |
EffectQueue.allocateQueues(mQueues,dc.getQueues(),flags,mID);
|
806 |
681 |
}
|
807 |
682 |
|
808 |
683 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
826 |
701 |
@SuppressWarnings("unused")
|
827 |
702 |
public void registerForMessages(EffectListener el)
|
828 |
703 |
{
|
829 |
|
mM.registerForMessages(el);
|
830 |
|
mV.registerForMessages(el);
|
831 |
|
mF.registerForMessages(el);
|
832 |
|
mP.registerForMessages(el);
|
|
704 |
for( int i=0; i<EffectType.LENGTH; i++)
|
|
705 |
{
|
|
706 |
mQueues[i].registerForMessages(el);
|
|
707 |
}
|
833 |
708 |
}
|
834 |
709 |
|
835 |
710 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
841 |
716 |
@SuppressWarnings("unused")
|
842 |
717 |
public void deregisterForMessages(EffectListener el)
|
843 |
718 |
{
|
844 |
|
mM.deregisterForMessages(el);
|
845 |
|
mV.deregisterForMessages(el);
|
846 |
|
mF.deregisterForMessages(el);
|
847 |
|
mP.deregisterForMessages(el);
|
|
719 |
for( int i=0; i<EffectType.LENGTH; i++)
|
|
720 |
{
|
|
721 |
mQueues[i].deregisterForMessages(el);
|
|
722 |
}
|
848 |
723 |
}
|
849 |
724 |
|
850 |
725 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
854 |
729 |
*/
|
855 |
730 |
public int abortAllEffects()
|
856 |
731 |
{
|
857 |
|
return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
|
|
732 |
int aborted = 0;
|
|
733 |
|
|
734 |
for( int i=0; i<EffectType.LENGTH; i++)
|
|
735 |
{
|
|
736 |
aborted += mQueues[i].abortAll(true);
|
|
737 |
}
|
|
738 |
|
|
739 |
return aborted;
|
858 |
740 |
}
|
859 |
741 |
|
860 |
742 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
866 |
748 |
*/
|
867 |
749 |
public int abortByType(EffectType type)
|
868 |
750 |
{
|
869 |
|
switch(type)
|
870 |
|
{
|
871 |
|
case MATRIX : return mM.abortAll(true);
|
872 |
|
case VERTEX : return mV.abortAll(true);
|
873 |
|
case FRAGMENT : return mF.abortAll(true);
|
874 |
|
case POSTPROCESS: return mP.abortAll(true);
|
875 |
|
default : return 0;
|
876 |
|
}
|
|
751 |
int num = type.ordinal();
|
|
752 |
return mQueues[num].abortAll(true);
|
877 |
753 |
}
|
878 |
754 |
|
879 |
755 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
885 |
761 |
*/
|
886 |
762 |
public int abortById(long id)
|
887 |
763 |
{
|
888 |
|
long type = id&EffectType.MASK;
|
889 |
|
|
890 |
|
if( type == EffectType.MATRIX.ordinal() ) return mM.removeById(id);
|
891 |
|
if( type == EffectType.VERTEX.ordinal() ) return mV.removeById(id);
|
892 |
|
if( type == EffectType.FRAGMENT.ordinal() ) return mF.removeById(id);
|
893 |
|
if( type == EffectType.POSTPROCESS.ordinal() ) return mP.removeById(id);
|
894 |
|
|
895 |
|
return 0;
|
|
764 |
int num = (int)(id&EffectType.MASK);
|
|
765 |
return mQueues[num].removeById(id);
|
896 |
766 |
}
|
897 |
767 |
|
898 |
768 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
904 |
774 |
*/
|
905 |
775 |
public int abortEffect(Effect effect)
|
906 |
776 |
{
|
907 |
|
switch(effect.getType())
|
908 |
|
{
|
909 |
|
case MATRIX : return mM.removeEffect(effect);
|
910 |
|
case VERTEX : return mV.removeEffect(effect);
|
911 |
|
case FRAGMENT : return mF.removeEffect(effect);
|
912 |
|
case POSTPROCESS: return mP.removeEffect(effect);
|
913 |
|
default : return 0;
|
914 |
|
}
|
|
777 |
int num = effect.getType().ordinal();
|
|
778 |
return mQueues[num].removeEffect(effect);
|
915 |
779 |
}
|
916 |
780 |
|
917 |
781 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
923 |
787 |
*/
|
924 |
788 |
public int abortByName(EffectName name)
|
925 |
789 |
{
|
926 |
|
switch(name.getType())
|
927 |
|
{
|
928 |
|
case MATRIX : return mM.removeByName(name);
|
929 |
|
case VERTEX : return mV.removeByName(name);
|
930 |
|
case FRAGMENT : return mF.removeByName(name);
|
931 |
|
case POSTPROCESS: return mP.removeByName(name);
|
932 |
|
default : return 0;
|
933 |
|
}
|
|
790 |
int num = name.getType().ordinal();
|
|
791 |
return mQueues[num].removeByName(name);
|
934 |
792 |
}
|
935 |
793 |
|
936 |
794 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
979 |
837 |
*/
|
980 |
838 |
public boolean apply(Effect effect)
|
981 |
839 |
{
|
982 |
|
switch(effect.getType())
|
983 |
|
{
|
984 |
|
case MATRIX : return mM.add(effect);
|
985 |
|
case VERTEX : return mV.add(effect);
|
986 |
|
case FRAGMENT : return mF.add(effect);
|
987 |
|
case POSTPROCESS : return mP.add(effect);
|
988 |
|
}
|
989 |
|
|
990 |
|
return false;
|
|
840 |
int num = effect.getType().ordinal();
|
|
841 |
return mQueues[num].add(effect);
|
991 |
842 |
}
|
992 |
843 |
}
|
Make DistortedEffects oblivious of the effect types.