Project

General

Profile

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

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

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 dbdf8a73 Leszek Koltunski
// Copyright 2016 Leszek Koltunski  leszek@koltunski.pl                                          //
3 d333eb6b Leszek Koltunski
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 d333eb6b Leszek Koltunski
//                                                                                               //
6 dbdf8a73 Leszek Koltunski
// This library is free software; you can redistribute it and/or                                 //
7
// modify it under the terms of the GNU Lesser General Public                                    //
8
// License as published by the Free Software Foundation; either                                  //
9
// version 2.1 of the License, or (at your option) any later version.                            //
10 d333eb6b Leszek Koltunski
//                                                                                               //
11 dbdf8a73 Leszek Koltunski
// This library 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 dbdf8a73 Leszek Koltunski
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
14
// Lesser General Public License for more details.                                               //
15 d333eb6b Leszek Koltunski
//                                                                                               //
16 dbdf8a73 Leszek Koltunski
// You should have received a copy of the GNU Lesser General Public                              //
17
// License along with this library; if not, write to the Free Software                           //
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20 d333eb6b Leszek Koltunski
21 809dcae3 Leszek Koltunski
package org.distorted.library.effectqueue;
22 6a06a912 Leszek Koltunski
23 b7074bc6 Leszek Koltunski
import android.opengl.GLES30;
24 6a06a912 Leszek Koltunski
25 da9b3f07 Leszek Koltunski
import org.distorted.library.effect.EffectType;
26 fe82a979 Leszek Koltunski
import org.distorted.library.effect.VertexEffect;
27 ed06301f Leszek Koltunski
import org.distorted.library.message.EffectMessageSender;
28 a4835695 Leszek Koltunski
29 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
30 f046b159 Leszek Koltunski
/**
31
 * Not part of public API, do not document (public only because has to be used in Meshes)
32
 *
33
 * @y.exclude
34
 */
35
public class EffectQueueVertex extends EffectQueue
36 96e3b88a Leszek Koltunski
  {
37
  private static final int NUM_FLOAT_UNIFORMS = VertexEffect.NUM_FLOAT_UNIFORMS;
38
  private static final int NUM_INT_UNIFORMS   = VertexEffect.NUM_INT_UNIFORMS;
39 2b7d2abb Leszek Koltunski
  private static final boolean USE_UBO        = true;
40 96e3b88a Leszek Koltunski
41 da9b3f07 Leszek Koltunski
  private static final int INDEX = EffectType.VERTEX.ordinal();
42 c1a38ba3 Leszek Koltunski
43 de77a6c5 Leszek Koltunski
  private final static int[] mNumEffectsH  = new int[MAIN_VARIANTS];
44
  private final static int[] mInflateH     = new int[MAIN_VARIANTS];
45
  private final static int[] mIntBlockIndex= new int[MAIN_VARIANTS];
46
  private final static int[] mFloBlockIndex= new int[MAIN_VARIANTS];
47 c1a38ba3 Leszek Koltunski
48 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
49
   
50 f046b159 Leszek Koltunski
  public EffectQueueVertex()
51 6a06a912 Leszek Koltunski
    { 
52 2b7d2abb Leszek Koltunski
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
53 6a06a912 Leszek Koltunski
    }
54
55 f046b159 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
56
57
  public EffectQueueVertex(EffectQueueVertex source)
58
    {
59
    super(source);
60
    }
61
62 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
63
64 809dcae3 Leszek Koltunski
  static void uniforms(int mProgramH, int variant)
65 c1a38ba3 Leszek Koltunski
    {
66 de77a6c5 Leszek Koltunski
    mNumEffectsH[variant]   = GLES30.glGetUniformLocation  ( mProgramH, "vNumEffects");
67
    mInflateH[variant]      = GLES30.glGetUniformLocation  ( mProgramH, "u_Inflate");
68
    mIntBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformProperties");
69
    mFloBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformFloats");
70 c1a38ba3 Leszek Koltunski
    }
71
72 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
73 f046b159 Leszek Koltunski
/**
74
 * Not part of public API, do not document (public only because has to be used in Meshes)
75
 *
76
 * @y.exclude
77
 */
78 835b197e Leszek Koltunski
  public void compute(long currTime, long step)
79 6a06a912 Leszek Koltunski
    {
80 de77a6c5 Leszek Koltunski
    if( mNumEffects>0 )
81 6a06a912 Leszek Koltunski
      {
82 de77a6c5 Leszek Koltunski
      float[] array = mUBF.getBackingArray();
83
84
      for(int i=0; i<mNumEffects; i++)
85 6a06a912 Leszek Koltunski
        {
86 de77a6c5 Leszek Koltunski
        if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) )
87
          {
88
          EffectMessageSender.newMessage(mEffects[i]);
89
          }
90 6a06a912 Leszek Koltunski
        }
91 de77a6c5 Leszek Koltunski
92
      mUBF.invalidate();
93 6a06a912 Leszek Koltunski
      }
94
    }
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 78ff6ea9 Leszek Koltunski
  public void send(float inflate, int programH, 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 de77a6c5 Leszek Koltunski
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, VERT_INT_UBO_BINDING, mUBI.getIndex());
110
      GLES30.glUniformBlockBinding(programH, mIntBlockIndex[variant], VERT_INT_UBO_BINDING);
111
112
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, VERT_FLO_UBO_BINDING, mUBF.getIndex());
113
      GLES30.glUniformBlockBinding(programH, mFloBlockIndex[variant], VERT_FLO_UBO_BINDING);
114 c1a38ba3 Leszek Koltunski
      }
115
    }
116 6a06a912 Leszek Koltunski
  }