Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski  leszek@koltunski.pl                                          //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// 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
//                                                                                               //
11
// This library 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 GNU                             //
14
// Lesser General Public License for more details.                                               //
15
//                                                                                               //
16
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
21

    
22
package org.distorted.library.effectqueue;
23

    
24
import android.opengl.GLES30;
25

    
26
import org.distorted.library.effect.EffectType;
27
import org.distorted.library.effect.VertexEffect;
28
import org.distorted.library.message.EffectMessageSender;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31
/**
32
 * Not part of public API, do not document (public only because has to be used in Meshes)
33
 *
34
 * @y.exclude
35
 */
36
public class EffectQueueVertex extends EffectQueue
37
  {
38
  private static final int NUM_FLOAT_UNIFORMS = VertexEffect.NUM_FLOAT_UNIFORMS;
39
  private static final int NUM_INT_UNIFORMS   = VertexEffect.NUM_INT_UNIFORMS;
40
  private static final boolean USE_UBO        = true;
41

    
42
  private static final int INDEX = EffectType.VERTEX.ordinal();
43

    
44
  private final static int[] mNumEffectsH  = new int[MAIN_VARIANTS];
45
  private final static int[] mInflateH     = new int[MAIN_VARIANTS];
46
  private final static int[] mIntBlockIndex= new int[MAIN_VARIANTS];
47
  private final static int[] mFloBlockIndex= new int[MAIN_VARIANTS];
48

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

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

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

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  static void uniforms(int mProgramH, int variant)
66
    {
67
    mNumEffectsH[variant]   = GLES30.glGetUniformLocation  ( mProgramH, "vNumEffects");
68
    mInflateH[variant]      = GLES30.glGetUniformLocation  ( mProgramH, "u_Inflate");
69
    mIntBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformProperties");
70
    mFloBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformFloats");
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
/**
75
 * Not part of public API, do not document (public only because has to be used in Meshes)
76
 *
77
 * @y.exclude
78
 */
79
  public void compute(long currTime, long step)
80
    {
81
    if( mNumEffects>0 )
82
      {
83
      float[] array = mUBF.getBackingArray();
84

    
85
      for(int i=0; i<mNumEffects; i++)
86
        {
87
        if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) )
88
          {
89
          EffectMessageSender.newMessage(mEffects[i]);
90
          }
91
        }
92

    
93
      mUBF.invalidate();
94
      }
95
    }
96

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

    
108
    if( mNumEffects>0 )
109
      {
110
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, VERT_INT_UBO_BINDING, mUBI.getIndex());
111
      GLES30.glUniformBlockBinding(programH, mIntBlockIndex[variant], VERT_INT_UBO_BINDING);
112

    
113
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, VERT_FLO_UBO_BINDING, mUBF.getIndex());
114
      GLES30.glUniformBlockBinding(programH, mFloBlockIndex[variant], VERT_FLO_UBO_BINDING);
115
      }
116
    }
117
  }
(5-5/5)