Project

General

Profile

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

library / src / main / java / org / distorted / library / effectqueue / EffectQueueVertex.java @ 7602a827

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of DistortedLibrary.                                                               //
5
//                                                                                               //
6
// DistortedLibrary 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
// DistortedLibrary 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 DistortedLibrary.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library.effectqueue;
21

    
22
import android.opengl.GLES31;
23

    
24
import org.distorted.library.effect.EffectType;
25
import org.distorted.library.effect.VertexEffect;
26
import org.distorted.library.message.EffectMessage;
27
import org.distorted.library.message.EffectMessageSender;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
class EffectQueueVertex extends EffectQueue
32
  { 
33
  private static final int NUM_UNIFORMS = VertexEffect.NUM_UNIFORMS;
34
  private static final int INDEX = EffectType.VERTEX.ordinal();
35

    
36
  private static int[] mNumEffectsH = new int[MAIN_VARIANTS];
37
  private static int[] mNameH       = new int[MAIN_VARIANTS];
38
  private static int[] mUniformsH   = new int[MAIN_VARIANTS];
39
  private static int[] mInflateH    = new int[MAIN_VARIANTS];
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
   
43
  EffectQueueVertex(long id)
44
    { 
45
    super(id,NUM_UNIFORMS,INDEX);
46
    }
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  static void uniforms(int mProgramH, int variant)
51
    {
52
    mNumEffectsH[variant]= GLES31.glGetUniformLocation( mProgramH, "vNumEffects");
53
    mNameH[variant]      = GLES31.glGetUniformLocation( mProgramH, "vName");
54
    mUniformsH[variant]  = GLES31.glGetUniformLocation( mProgramH, "vUniforms");
55
    mInflateH[variant]   = GLES31.glGetUniformLocation( mProgramH, "u_Inflate");
56
    }
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59
  
60
  void compute(long currTime,float halfX, float halfY, float halfZ)
61
    {
62
    if( currTime==mTime ) return;
63
    if( mTime==0 ) mTime = currTime;
64
    long step = (currTime-mTime);
65

    
66
    for(int i=0; i<mNumEffects; i++)
67
      {
68
      mCurrentDuration[i] += step;
69

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

    
76
      mUniforms[NUM_UNIFORMS*i+5] -= halfX;
77
      mUniforms[NUM_UNIFORMS*i+6] -= halfY;
78
      mUniforms[NUM_UNIFORMS*i+7] -= halfZ;
79
      }
80

    
81
    mTime = currTime;
82
    }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
  void send(float inflate, int variant)
87
    {
88
    GLES31.glUniform1i( mNumEffectsH[variant], mNumEffects);
89
    GLES31.glUniform1f( mInflateH[variant]   , inflate    );
90

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