Project

General

Profile

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

library / src / main / java / org / distorted / library / effectqueue / EffectQueueVertex.java @ 78ff6ea9

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 final static int[] mNumEffectsH   = new int[MAIN_VARIANTS];
42
  private final static int[] mInflateH      = new int[MAIN_VARIANTS];
43
  private final static int[] mUniformsH     = new int[MAIN_VARIANTS];
44
  private final static int[] mPropBlockIndex= new int[MAIN_VARIANTS];
45

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

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

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

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

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

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
/**
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
    {
78
    if( currTime==mTime ) return;
79
    if( mTime==0 ) mTime = currTime;
80
    long step = (currTime-mTime);
81

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

    
90
    mTime = currTime;
91
    }
92

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

    
104
    if( mNumEffects>0 )
105
      {
106
      int index = mUBP.getIndex();
107
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, PROP_VERT_UBO_BINDING, index);
108
      GLES30.glUniformBlockBinding(programH, mPropBlockIndex[variant], PROP_VERT_UBO_BINDING);
109
      GLES30.glUniform4fv( mUniformsH[variant]  ,(NUM_FLOAT_UNIFORMS/4)*mNumEffects, mFloatUniforms , 0);
110
      }
111
    }
112
  }
(5-5/6)