Project

General

Profile

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

library / src / main / java / org / distorted / library / effectqueue / EffectQueueVertex.java @ f046b159

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

    
22
import android.opengl.GLES30;
23

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

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29
/**
30
 * Not part of public API, do not document (public only because has to be used in Meshes)
31
 *
32
 * @y.exclude
33
 */
34
public class EffectQueueVertex extends EffectQueue
35
  { 
36
  private static final int NUM_UNIFORMS = VertexEffect.NUM_UNIFORMS;
37
  private static final int INDEX = EffectType.VERTEX.ordinal();
38

    
39
  private static int[] mNumEffectsH = new int[MAIN_VARIANTS];
40
  private static int[] mNameH       = new int[MAIN_VARIANTS];
41
  private static int[] mUniformsH   = new int[MAIN_VARIANTS];
42
  private static int[] mInflateH    = new int[MAIN_VARIANTS];
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
   
46
  public EffectQueueVertex()
47
    { 
48
    super(NUM_UNIFORMS,INDEX);
49
    }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  public EffectQueueVertex(EffectQueueVertex source)
54
    {
55
    super(source);
56
    }
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
  static void uniforms(int mProgramH, int variant)
61
    {
62
    mNumEffectsH[variant]= GLES30.glGetUniformLocation( mProgramH, "vNumEffects");
63
    mNameH[variant]      = GLES30.glGetUniformLocation( mProgramH, "vName");
64
    mUniformsH[variant]  = GLES30.glGetUniformLocation( mProgramH, "vUniforms");
65
    mInflateH[variant]   = GLES30.glGetUniformLocation( mProgramH, "u_Inflate");
66
    }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
/**
70
 * Not part of public API, do not document (public only because has to be used in Meshes)
71
 *
72
 * @y.exclude
73
 */
74
  public void compute(long currTime)
75
    {
76
    if( currTime==mTime ) return;
77
    if( mTime==0 ) mTime = currTime;
78
    long step = (currTime-mTime);
79

    
80
    for(int i=0; i<mNumEffects; i++)
81
      {
82
      mCurrentDuration[i] += step;
83

    
84
      if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) )
85
        {
86
        EffectMessageSender.newMessage(mEffects[i]);
87
        }
88
      }
89

    
90
    mTime = currTime;
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
/**
95
 * Not part of public API, do not document (public only because has to be used in Meshes)
96
 *
97
 * @y.exclude
98
 */
99
  public void send(float inflate, int variant)
100
    {
101
    GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);
102
    GLES30.glUniform1f( mInflateH[variant]   , inflate    );
103

    
104
    if( mNumEffects>0 )
105
      {
106
      GLES30.glUniform1iv( mNameH[variant]    ,                 mNumEffects, mName    ,0);
107
      GLES30.glUniform4fv( mUniformsH[variant],(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0);
108
      }
109
    }
110
  }
(5-5/5)