Project

General

Profile

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

library / src / main / java / org / distorted / library / effectqueue / EffectQueueVertex.java @ 96e3b88a

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_FLOAT_UNIFORMS = VertexEffect.NUM_FLOAT_UNIFORMS;
37
  private static final int NUM_INT_UNIFORMS   = VertexEffect.NUM_INT_UNIFORMS;
38

    
39
  private static final int INDEX = EffectType.VERTEX.ordinal();
40

    
41
  private static int[] mNumEffectsH    = new int[MAIN_VARIANTS];
42
  private static int[] mNameH          = new int[MAIN_VARIANTS];
43
  private static int[] mUniformsH      = new int[MAIN_VARIANTS];
44
  private static int[] mAndAssociationH= new int[MAIN_VARIANTS];
45
  private static int[] mEquAssociationH= new int[MAIN_VARIANTS];
46
  private static int[] mInflateH       = new int[MAIN_VARIANTS];
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
   
50
  public EffectQueueVertex()
51
    { 
52
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
53
    }
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  public EffectQueueVertex(EffectQueueVertex source)
58
    {
59
    super(source);
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  static void uniforms(int mProgramH, int variant)
65
    {
66
    mNumEffectsH[variant]    = GLES30.glGetUniformLocation( mProgramH, "vNumEffects");
67
    mNameH[variant]          = GLES30.glGetUniformLocation( mProgramH, "vName");
68
    mUniformsH[variant]      = GLES30.glGetUniformLocation( mProgramH, "vUniforms");
69
    mAndAssociationH[variant]= GLES30.glGetUniformLocation( mProgramH, "vEffAndAssoc");
70
    mEquAssociationH[variant]= GLES30.glGetUniformLocation( mProgramH, "vEffEquAssoc");
71
    mInflateH[variant]       = GLES30.glGetUniformLocation( mProgramH, "u_Inflate");
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
/**
76
 * Not part of public API, do not document (public only because has to be used in Meshes)
77
 *
78
 * @y.exclude
79
 */
80
  public void compute(long currTime)
81
    {
82
    if( currTime==mTime ) return;
83
    if( mTime==0 ) mTime = currTime;
84
    long step = (currTime-mTime);
85

    
86
    for(int i=0; i<mNumEffects; i++)
87
      {
88
      mEffects[i].writeAssociations(mIntUniforms, mMax[INDEX]+i, 2*mMax[INDEX]+i);
89

    
90
      if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) )
91
        {
92
        EffectMessageSender.newMessage(mEffects[i]);
93
        }
94
      }
95

    
96
    mTime = currTime;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
/**
101
 * Not part of public API, do not document (public only because has to be used in Meshes)
102
 *
103
 * @y.exclude
104
 */
105
  public void send(float inflate, int variant)
106
    {
107
    GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);
108
    GLES30.glUniform1f( mInflateH[variant]   , inflate    );
109

    
110
    if( mNumEffects>0 )
111
      {
112
      GLES30.glUniform1iv( mNameH[variant]          ,                       mNumEffects, mIntUniforms   , 0            );
113
      GLES30.glUniform1iv( mAndAssociationH[variant],                       mNumEffects, mIntUniforms   ,   mMax[INDEX]);
114
      GLES30.glUniform1iv( mEquAssociationH[variant],                       mNumEffects, mIntUniforms   , 2*mMax[INDEX]);
115
      GLES30.glUniform4fv( mUniformsH[variant]      ,(NUM_FLOAT_UNIFORMS/4)*mNumEffects, mFloatUniforms , 0            );
116
      }
117
    }
118
  }
(5-5/5)