Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectQueuePostprocess.java @ c638c1b0

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;
21

    
22
import android.opengl.GLES20;
23

    
24
import org.distorted.library.message.EffectMessage;
25
import org.distorted.library.type.Data1D;
26
import org.distorted.library.type.Data2D;
27
import org.distorted.library.type.Dynamic1D;
28
import org.distorted.library.type.Dynamic2D;
29
import org.distorted.library.type.Static1D;
30
import org.distorted.library.type.Static2D;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
class EffectQueuePostprocess extends EffectQueue
35
  {
36
  private static final int NUM_UNIFORMS = 3;
37
  private static final int NUM_CACHE    = 0;
38
  private static final int INDEX = EffectTypes.POSTPROCESS.ordinal();
39

    
40
  private static int mNumEffectsH;
41
  private static int mTypeH;
42
  private static int mUniformsH;
43
  private static int mObjDH;
44

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

    
47
  EffectQueuePostprocess(long id)
48
    { 
49
    super(id,NUM_UNIFORMS,NUM_CACHE,INDEX );
50
    }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  static void getUniforms(int mProgramH)
55
    {
56
    mNumEffectsH= GLES20.glGetUniformLocation( mProgramH, "pNumEffects");
57
    mTypeH      = GLES20.glGetUniformLocation( mProgramH, "pType");
58
    mUniformsH  = GLES20.glGetUniformLocation( mProgramH, "pUniforms");
59
    mObjDH      = GLES20.glGetUniformLocation( mProgramH, "u_objD");
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
  
64
  synchronized void compute(long currTime) 
65
    {
66
    if( currTime==mTime ) return;
67
    if( mTime==0 ) mTime = currTime;
68
    long step = (currTime-mTime);
69
   
70
    for(int i=0; i<mNumEffects; i++)
71
      {
72
      if( mInter[0][i]!=null && mInter[0][i].interpolateMain(mUniforms ,NUM_UNIFORMS*i, mCurrentDuration[i], step) )
73
        {
74
        for(int j=0; j<mNumListeners; j++)
75
          EffectMessageSender.newMessage( mListeners.elementAt(j),
76
                                          EffectMessage.EFFECT_FINISHED,
77
                                         (mID[i]<<EffectTypes.LENGTH)+EffectTypes.POSTPROCESS.type,
78
                                          mName[i],
79
                                          mObjectID);
80

    
81
        if( EffectNames.isUnity(mName[i], mUniforms, NUM_UNIFORMS*i) )
82
          {
83
          remove(i);
84
          i--;
85
          continue;
86
          }
87
        else mInter[0][i] = null;
88
        }
89

    
90
      if( mInter[1][i]!=null )
91
        {
92
        mInter[1][i].interpolateMain(mUniforms, NUM_UNIFORMS*i+1, mCurrentDuration[i], step);
93
        }
94

    
95
      mCurrentDuration[i] += step;
96
      }
97
     
98
    mTime = currTime;  
99
    }  
100

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

    
103
  protected void moveEffect(int index)
104
    {
105
    mUniforms[NUM_UNIFORMS*index  ] = mUniforms[NUM_UNIFORMS*(index+1)  ];
106
    mUniforms[NUM_UNIFORMS*index+1] = mUniforms[NUM_UNIFORMS*(index+1)+1];
107
    mUniforms[NUM_UNIFORMS*index+2] = mUniforms[NUM_UNIFORMS*(index+1)+2];
108
    }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
  synchronized void send(float halfX, float halfY)
113
    {
114
    GLES20.glUniform1i( mNumEffectsH, mNumEffects);
115
    GLES20.glUniform2f( mObjDH , halfX, halfY);
116

    
117
    if( mNumEffects>0 )
118
      {
119
      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mName    ,0);
120
      GLES20.glUniform4fv( mUniformsH,2*mNumEffects, mUniforms,0);
121
      }
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  synchronized static void sendZero(float halfX, float halfY)
127
    {
128
    GLES20.glUniform1i( mNumEffectsH, 0);
129
    GLES20.glUniform2f( mObjDH , halfX, halfY);
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
// blur
134

    
135
  synchronized long add(EffectNames eln, Data1D degree, Data2D center)
136
    {
137
    if( mMax[INDEX]>mNumEffects )
138
      {
139
      if( degree instanceof Dynamic1D)
140
        {
141
        mInter[0][mNumEffects] = (Dynamic1D)degree;
142
        }
143
      else if( degree instanceof Static1D)
144
        {
145
        mInter[0][mNumEffects] = null;
146
        mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)degree).getX();
147
        }
148
      else return -1;
149

    
150
      if( center instanceof Dynamic2D)
151
        {
152
        mInter[1][mNumEffects] = (Dynamic2D)center;
153
        }
154
      else if( center instanceof Static2D)
155
        {
156
        mInter[1][mNumEffects] = null;
157
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static2D)center).getX();
158
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static2D)center).getY();
159
        }
160
      else return -1;
161

    
162
      return addBase(eln);
163
      }
164
      
165
    return -1;
166
    }
167
  }
(11-11/16)