Project

General

Profile

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

library / src / main / java / org / distorted / library / main / EffectQueuePostprocess.java @ 586b5fa1

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
  private int mHalo;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

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

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

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

    
52
    mHalo = 0;
53
    int halo;
54

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

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

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

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

    
77
    mTime = currTime;
78
    }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

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

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

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

    
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95

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

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

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

    
107
    GLES31.glDisable(GLES31.GL_BLEND);
108

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

    
114
    GLES31.glEnable(GLES31.GL_BLEND);
115

    
116
    return numRenders;
117
    }
118
  }
(17-17/21)