Project

General

Profile

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

library / src / main / java / org / distorted / library / effectqueue / EffectQueueVertex.java @ 1e672c1d

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 d333eb6b Leszek Koltunski
//                                                                                               //
6 46b572b5 Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 d333eb6b Leszek Koltunski
// 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 46b572b5 Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 d333eb6b Leszek Koltunski
// 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 46b572b5 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 809dcae3 Leszek Koltunski
package org.distorted.library.effectqueue;
21 6a06a912 Leszek Koltunski
22 b7074bc6 Leszek Koltunski
import android.opengl.GLES30;
23 6a06a912 Leszek Koltunski
24 da9b3f07 Leszek Koltunski
import org.distorted.library.effect.EffectType;
25 fe82a979 Leszek Koltunski
import org.distorted.library.effect.VertexEffect;
26 ed06301f Leszek Koltunski
import org.distorted.library.message.EffectMessageSender;
27 a4835695 Leszek Koltunski
28 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
29 f046b159 Leszek Koltunski
/**
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 6a06a912 Leszek Koltunski
  { 
36 15aa7d94 Leszek Koltunski
  private static final int NUM_UNIFORMS = VertexEffect.NUM_UNIFORMS;
37 da9b3f07 Leszek Koltunski
  private static final int INDEX = EffectType.VERTEX.ordinal();
38 c1a38ba3 Leszek Koltunski
39 809dcae3 Leszek Koltunski
  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 1e672c1d Leszek Koltunski
  private static int[] mAssociationH= new int[MAIN_VARIANTS];
43 809dcae3 Leszek Koltunski
  private static int[] mInflateH    = new int[MAIN_VARIANTS];
44 c1a38ba3 Leszek Koltunski
45 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
46
   
47 f046b159 Leszek Koltunski
  public EffectQueueVertex()
48 6a06a912 Leszek Koltunski
    { 
49 20dbec0e Leszek Koltunski
    super(NUM_UNIFORMS,INDEX);
50 6a06a912 Leszek Koltunski
    }
51
52 f046b159 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
53
54
  public EffectQueueVertex(EffectQueueVertex source)
55
    {
56
    super(source);
57
    }
58
59 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61 809dcae3 Leszek Koltunski
  static void uniforms(int mProgramH, int variant)
62 c1a38ba3 Leszek Koltunski
    {
63 1e672c1d Leszek Koltunski
    mNumEffectsH[variant] = GLES30.glGetUniformLocation( mProgramH, "vNumEffects");
64
    mNameH[variant]       = GLES30.glGetUniformLocation( mProgramH, "vName");
65
    mUniformsH[variant]   = GLES30.glGetUniformLocation( mProgramH, "vUniforms");
66
    mAssociationH[variant]= GLES30.glGetUniformLocation( mProgramH, "vAssociation");
67
    mInflateH[variant]    = GLES30.glGetUniformLocation( mProgramH, "u_Inflate");
68 c1a38ba3 Leszek Koltunski
    }
69
70 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
71 f046b159 Leszek Koltunski
/**
72
 * Not part of public API, do not document (public only because has to be used in Meshes)
73
 *
74
 * @y.exclude
75
 */
76
  public void compute(long currTime)
77 6a06a912 Leszek Koltunski
    {
78
    if( currTime==mTime ) return;
79
    if( mTime==0 ) mTime = currTime;
80
    long step = (currTime-mTime);
81 15aa7d94 Leszek Koltunski
82 6a06a912 Leszek Koltunski
    for(int i=0; i<mNumEffects; i++)
83
      {
84 3a70bd6d leszek
      mCurrentDuration[i] += step;
85 1e672c1d Leszek Koltunski
      mAssociation[i] = mEffects[i].getAssociation();
86 3a70bd6d leszek
87 15aa7d94 Leszek Koltunski
      if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) )
88 6a06a912 Leszek Koltunski
        {
89 20dbec0e Leszek Koltunski
        EffectMessageSender.newMessage(mEffects[i]);
90 6a06a912 Leszek Koltunski
        }
91
      }
92 0a046359 Leszek Koltunski
93 15aa7d94 Leszek Koltunski
    mTime = currTime;
94 6a06a912 Leszek Koltunski
    }
95 15aa7d94 Leszek Koltunski
96 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
97 f046b159 Leszek Koltunski
/**
98
 * Not part of public API, do not document (public only because has to be used in Meshes)
99
 *
100
 * @y.exclude
101
 */
102
  public void send(float inflate, int variant)
103 6a06a912 Leszek Koltunski
    {
104 b7074bc6 Leszek Koltunski
    GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);
105
    GLES30.glUniform1f( mInflateH[variant]   , inflate    );
106 7a5e538a Leszek Koltunski
107 6a06a912 Leszek Koltunski
    if( mNumEffects>0 )
108 0a046359 Leszek Koltunski
      {
109 1e672c1d Leszek Koltunski
      GLES30.glUniform1iv( mNameH[variant]       ,                 mNumEffects, mName       , 0);
110
      GLES30.glUniform1iv( mAssociationH[variant],                 mNumEffects, mAssociation, 0);
111
      GLES30.glUniform4fv( mUniformsH[variant]   ,(NUM_UNIFORMS/4)*mNumEffects, mUniforms   , 0);
112 c1a38ba3 Leszek Koltunski
      }
113
    }
114 6a06a912 Leszek Koltunski
  }