Project

General

Profile

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

library / src / main / java / org / distorted / library / main / EffectQueuePostprocess.java @ 1dfc9074

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 org.distorted.library.effect.EffectType;
23
import org.distorted.library.effect.PostprocessEffect;
24
import org.distorted.library.message.EffectMessage;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

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

    
33
  int mQualityLevel;
34
  float mQualityScale;
35
  private int mHalo;
36

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

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

    
43
    mQualityLevel = 0;
44
    mQualityScale = 1.0f;
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  private void compute(long currTime)
50
    {
51
    if( currTime==mTime ) return;
52
    if( mTime==0 ) mTime = currTime;
53
    long step = (currTime-mTime);
54

    
55
    mHalo = 0;
56
    int halo;
57

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

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

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

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

    
79
    mTime = currTime;
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

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

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  int postprocess(long time, DistortedOutputSurface surface)
92
    {
93
    int numRenders = 0;
94

    
95
    if( mNumEffects>0 )
96
      {
97
      compute(time);
98

    
99
      for(int i=0; i<mNumEffects; i++)
100
        {
101
        numRenders += ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i,mQualityScale,surface.mBuffer[mQualityLevel]);
102
        }
103
      }
104

    
105
    return numRenders;
106
    }
107
  }
(19-19/23)