Project

General

Profile

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

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

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
  void postprocess(DistortedFramebuffer input, DistortedFramebuffer output)
104
    {
105
    // TODO
106
    }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

    
110
  protected void moveEffect(int index)
111
    {
112
    mUniforms[NUM_UNIFORMS*index  ] = mUniforms[NUM_UNIFORMS*(index+1)  ];
113
    mUniforms[NUM_UNIFORMS*index+1] = mUniforms[NUM_UNIFORMS*(index+1)+1];
114
    mUniforms[NUM_UNIFORMS*index+2] = mUniforms[NUM_UNIFORMS*(index+1)+2];
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  synchronized void send(float objX, float objY)
120
    {
121
    GLES20.glUniform1i( mNumEffectsH, mNumEffects);
122
    GLES20.glUniform2f( mObjDH , objX, objY);
123

    
124
    if( mNumEffects>0 )
125
      {
126
      GLES20.glUniform1iv( mTypeH    ,  mNumEffects, mName    ,0);
127
      GLES20.glUniform4fv( mUniformsH,2*mNumEffects, mUniforms,0);
128
      }
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
  synchronized static void sendZero(float objX, float objY)
134
    {
135
    GLES20.glUniform1i( mNumEffectsH, 0);
136
    GLES20.glUniform2f( mObjDH , objX, objY);
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140
// blur
141

    
142
  synchronized long add(EffectNames eln, Data1D degree, Data2D center)
143
    {
144
    if( mMax[INDEX]>mNumEffects )
145
      {
146
      if( degree instanceof Dynamic1D)
147
        {
148
        mInter[0][mNumEffects] = (Dynamic1D)degree;
149
        }
150
      else if( degree instanceof Static1D)
151
        {
152
        mInter[0][mNumEffects] = null;
153
        mUniforms[NUM_UNIFORMS*mNumEffects] = ((Static1D)degree).getX();
154
        }
155
      else return -1;
156

    
157
      if( center instanceof Dynamic2D)
158
        {
159
        mInter[1][mNumEffects] = (Dynamic2D)center;
160
        }
161
      else if( center instanceof Static2D)
162
        {
163
        mInter[1][mNumEffects] = null;
164
        mUniforms[NUM_UNIFORMS*mNumEffects+1] = ((Static2D)center).getX();
165
        mUniforms[NUM_UNIFORMS*mNumEffects+2] = ((Static2D)center).getY();
166
        }
167
      else return -1;
168

    
169
      return addBase(eln);
170
      }
171
      
172
    return -1;
173
    }
174
  }
(11-11/16)