Project

General

Profile

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

library / src / main / java / org / distorted / library / effectqueue / EffectQueueVertex.java @ 835b197e

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
  private static final boolean USE_UBO        = true;
39

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

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

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

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

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

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

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

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

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

    
91
      mUBF.invalidate();
92
      }
93
    }
94

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

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

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