Project

General

Profile

Download (4.43 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / main / EffectQueuePostprocess.java @ 8dccc3c2

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library.main;
21

    
22
import android.opengl.GLES31;
23

    
24
import org.distorted.library.effect.EffectType;
25
import org.distorted.library.effect.PostprocessEffect;
26
import org.distorted.library.message.EffectMessage;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
class EffectQueuePostprocess extends EffectQueue
31
  {
32
  private static final int NUM_UNIFORMS = PostprocessEffect.NUM_UNIFORMS;
33
  private static final int INDEX = EffectType.POSTPROCESS.ordinal();
34

    
35

    
36
  private int mHalo;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
  EffectQueuePostprocess(long id)
41
    { 
42
    super(id,NUM_UNIFORMS,INDEX );
43
    }
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
  void compute(long currTime)
48
    {
49
    if( currTime==mTime ) return;
50
    if( mTime==0 ) mTime = currTime;
51
    long step = (currTime-mTime);
52

    
53
    mHalo = 0;
54
    int halo;
55

    
56
    for(int i=0; i<mNumEffects; i++)
57
      {
58
      mCurrentDuration[i] += step;
59

    
60
      if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) )
61
        {
62
        for(int j=0; j<mNumListeners; j++)
63
          EffectMessageSender.newMessage( mListeners.get(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
64

    
65
        if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) )
66
          {
67
          remove(i--);
68
          mNumEffectsToBe--;
69
          regenerateIDandSort();
70
          continue;
71
          }
72
        }
73

    
74
      halo = (int)mUniforms[NUM_UNIFORMS*i];
75
      if( halo>mHalo ) mHalo = halo;
76
      }
77

    
78
    mTime = currTime;
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  int getHalo()
84
    {
85
    return mNumEffects>0 ? mHalo : 0;
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  int getQuality()
91
    {
92
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getQuality() : 0;
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  int getInternalQuality()
98
    {
99
    return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getInternalQuality() : 0;
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  int postprocess(DistortedOutputSurface[] buffers)
105
    {
106
    int numRenders = 0;
107

    
108
    GLES31.glDisable(GLES31.GL_BLEND);
109

    
110
    for(int i=0; i<mNumEffects; i++)
111
      {
112
      numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, buffers);
113
      }
114

    
115
    GLES31.glEnable(GLES31.GL_BLEND);
116

    
117
    return numRenders;
118
    }
119
  }
(18-18/22)