Project

General

Profile

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

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

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 96e3b88a Leszek Koltunski
  {
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 da9b3f07 Leszek Koltunski
  private static final int INDEX = EffectType.VERTEX.ordinal();
40 c1a38ba3 Leszek Koltunski
41 de77a6c5 Leszek Koltunski
  private final static int[] mNumEffectsH  = new int[MAIN_VARIANTS];
42
  private final static int[] mInflateH     = new int[MAIN_VARIANTS];
43
  private final static int[] mIntBlockIndex= new int[MAIN_VARIANTS];
44
  private final static int[] mFloBlockIndex= new int[MAIN_VARIANTS];
45 c1a38ba3 Leszek Koltunski
46 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
47
   
48 f046b159 Leszek Koltunski
  public EffectQueueVertex()
49 6a06a912 Leszek Koltunski
    { 
50 96e3b88a Leszek Koltunski
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, INDEX);
51 6a06a912 Leszek Koltunski
    }
52
53 f046b159 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
54
55
  public EffectQueueVertex(EffectQueueVertex source)
56
    {
57
    super(source);
58
    }
59
60 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
61
62 809dcae3 Leszek Koltunski
  static void uniforms(int mProgramH, int variant)
63 c1a38ba3 Leszek Koltunski
    {
64 de77a6c5 Leszek Koltunski
    mNumEffectsH[variant]   = GLES30.glGetUniformLocation  ( mProgramH, "vNumEffects");
65
    mInflateH[variant]      = GLES30.glGetUniformLocation  ( mProgramH, "u_Inflate");
66
    mIntBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformProperties");
67
    mFloBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformFloats");
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 15aa7d94 Leszek Koltunski
81 de77a6c5 Leszek Koltunski
    if( mNumEffects>0 )
82 6a06a912 Leszek Koltunski
      {
83 de77a6c5 Leszek Koltunski
      long step = (currTime-mTime);
84
      float[] array = mUBF.getBackingArray();
85
86
      for(int i=0; i<mNumEffects; i++)
87 6a06a912 Leszek Koltunski
        {
88 de77a6c5 Leszek Koltunski
        if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) )
89
          {
90
          EffectMessageSender.newMessage(mEffects[i]);
91
          }
92 6a06a912 Leszek Koltunski
        }
93 de77a6c5 Leszek Koltunski
94
      mUBF.invalidate();
95 6a06a912 Leszek Koltunski
      }
96 0a046359 Leszek Koltunski
97 15aa7d94 Leszek Koltunski
    mTime = currTime;
98 6a06a912 Leszek Koltunski
    }
99 15aa7d94 Leszek Koltunski
100 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
101 f046b159 Leszek Koltunski
/**
102
 * Not part of public API, do not document (public only because has to be used in Meshes)
103
 *
104
 * @y.exclude
105
 */
106 78ff6ea9 Leszek Koltunski
  public void send(float inflate, int programH, int variant)
107 6a06a912 Leszek Koltunski
    {
108 b7074bc6 Leszek Koltunski
    GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);
109
    GLES30.glUniform1f( mInflateH[variant]   , inflate    );
110 7a5e538a Leszek Koltunski
111 6a06a912 Leszek Koltunski
    if( mNumEffects>0 )
112 0a046359 Leszek Koltunski
      {
113 de77a6c5 Leszek Koltunski
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, VERT_INT_UBO_BINDING, mUBI.getIndex());
114
      GLES30.glUniformBlockBinding(programH, mIntBlockIndex[variant], VERT_INT_UBO_BINDING);
115
116
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, VERT_FLO_UBO_BINDING, mUBF.getIndex());
117
      GLES30.glUniformBlockBinding(programH, mFloBlockIndex[variant], VERT_FLO_UBO_BINDING);
118 c1a38ba3 Leszek Koltunski
      }
119
    }
120 6a06a912 Leszek Koltunski
  }