Project

General

Profile

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

library / src / main / java / org / distorted / library / main / EffectQueuePostprocess.java @ 4b9fe2e9

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

    
34
  private int mHalo;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

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

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

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

    
51
    mHalo = 0;
52
    int halo;
53

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

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

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

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

    
76
    mTime = currTime;
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

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

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

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

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
// TODO: for now, we assume each postprocessing effect issues 2 drawing calls (this is for statistical
95
// purposes only anyway)
96

    
97
  int getNumRenders()
98
    {
99
    return 2*mNumEffects;
100
    }
101

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

    
104
  int postprocess(DistortedOutputSurface surface, int quality)
105
    {
106
    DistortedRenderState.useStencilMark();
107

    
108
    for(int i=0; i<mNumEffects; i++)
109
      {
110
      quality = ((PostprocessEffect)mEffects[i]).apply(mUniforms,NUM_UNIFORMS*i, quality, surface.mBuffer);
111
      }
112

    
113
    DistortedRenderState.unuseStencilMark();
114

    
115
    return quality;
116
    }
117
  }
(17-17/21)