Project

General

Profile

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

library / src / main / java / org / distorted / library / main / EffectQueueVertex.java @ 15aa7d94

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.GLES30;
23

    
24
import org.distorted.library.effect.Effect;
25
import org.distorted.library.effect.VertexEffect;
26
import org.distorted.library.message.EffectMessage;
27

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

    
30
class EffectQueueVertex extends EffectQueue
31
  { 
32
  private static final int NUM_UNIFORMS = VertexEffect.NUM_UNIFORMS;
33
  private static final int INDEX = Effect.VERTEX;
34
  private static int mNumEffectsH;
35
  private static int mNameH;
36
  private static int mUniformsH;
37
  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39
   
40
  EffectQueueVertex(long id)
41
    { 
42
    super(id,NUM_UNIFORMS,INDEX);
43
    }
44

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

    
47
  static void getUniforms(int mProgramH)
48
    {
49
    mNumEffectsH= GLES30.glGetUniformLocation( mProgramH, "vNumEffects");
50
    mNameH      = GLES30.glGetUniformLocation( mProgramH, "vName");
51
    mUniformsH  = GLES30.glGetUniformLocation( mProgramH, "vUniforms");
52
    }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
  
56
  synchronized void compute(long currTime) 
57
    {
58
    if( currTime==mTime ) return;
59
    if( mTime==0 ) mTime = currTime;
60
    long step = (currTime-mTime);
61

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

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

    
71
        if( VertexEffect.isUnity( mEffects[i].getName(), mUniforms, NUM_UNIFORMS*i) )
72
          remove(i--);
73
        }
74
      }
75

    
76
    mTime = currTime;
77
    }
78

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

    
81
  synchronized void send(float halfX, float halfY, float halfZ)
82
    {
83
    GLES30.glUniform1i( mNumEffectsH, mNumEffects);
84
      
85
    if( mNumEffects>0 )
86
      {
87
      for(int i=0; i<mNumEffects; i++)
88
        {
89
        mUniforms[NUM_UNIFORMS*i+5] = mUniforms[NUM_UNIFORMS*i+5]-halfX;
90
        mUniforms[NUM_UNIFORMS*i+6] =-mUniforms[NUM_UNIFORMS*i+6]+halfY;
91
        mUniforms[NUM_UNIFORMS*i+7] = mUniforms[NUM_UNIFORMS*i+7]-halfZ;
92
        }
93

    
94
      GLES30.glUniform1iv( mNameH    ,                 mNumEffects, mName    ,0);
95
      GLES30.glUniform4fv( mUniformsH,(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
96
      }
97
    }
98
  }
(21-21/24)