Project

General

Profile

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

library / src / main / java / org / distorted / library / main / EffectQueueFragment.java @ 466450b5

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.FragmentEffect;
26
import org.distorted.library.message.EffectMessage;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
class EffectQueueFragment extends EffectQueue
31
  {
32
  private static final int NUM_UNIFORMS = FragmentEffect.NUM_UNIFORMS;
33
  private static final int INDEX = EffectType.FRAGMENT.ordinal();
34

    
35
  private static int[] mNumEffectsH = new int[Distorted.MAIN_VARIANTS];
36
  private static int[] mNameH       = new int[Distorted.MAIN_VARIANTS];
37
  private static int[] mUniformsH   = new int[Distorted.MAIN_VARIANTS];
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
   
41
  EffectQueueFragment(long id)
42
    { 
43
    super(id,NUM_UNIFORMS,INDEX);
44
    }
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
  static void getUniforms(int mProgramH, int variant)
49
    {
50
    mNumEffectsH[variant]= GLES31.glGetUniformLocation( mProgramH, "fNumEffects");
51
    mNameH[variant]      = GLES31.glGetUniformLocation( mProgramH, "fName");
52
    mUniformsH[variant]  = GLES31.glGetUniformLocation( mProgramH, "fUniforms");
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
  
57
  void compute(long currTime,float halfX, float halfY)
58
    { 
59
    if( currTime==mTime ) return;
60
    if( mTime==0 ) mTime = currTime;
61
    long step = (currTime-mTime);
62

    
63
    for(int i=0; i<mNumEffects; i++)
64
      {
65
      mCurrentDuration[i] += step;
66

    
67
      if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) )
68
        {
69
        for(int j=0; j<mNumListeners; j++)
70
          EffectMessageSender.newMessage( mListeners.get(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
71

    
72
        if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) )
73
          {
74
          remove(i--);
75
          mNumEffectsToBe--;
76
          continue;
77
          }
78
        }
79

    
80
      mUniforms[NUM_UNIFORMS*i+4] = mUniforms[NUM_UNIFORMS*i+4]-halfX;
81
      mUniforms[NUM_UNIFORMS*i+5] =-mUniforms[NUM_UNIFORMS*i+5]+halfY;
82
      }
83

    
84
    mTime = currTime;  
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
  
89
  void send(int variant)
90
    {
91
    GLES31.glUniform1i( mNumEffectsH[variant], mNumEffects);
92

    
93
    if( mNumEffects>0 )
94
      {
95
      GLES31.glUniform1iv( mNameH[variant]    ,                 mNumEffects, mName    ,0);
96
      GLES31.glUniform4fv( mUniformsH[variant],(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
97
      }  
98
    }
99
  }
(15-15/21)