Project

General

Profile

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

library / src / main / java / org / distorted / library / effectqueue / EffectQueueFragment.java @ 1dec66e0

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
package org.distorted.library.effectqueue;
22

    
23
import android.opengl.GLES30;
24

    
25
import org.distorted.library.effect.EffectType;
26
import org.distorted.library.effect.FragmentEffect;
27
import org.distorted.library.message.EffectMessageSender;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
class EffectQueueFragment extends EffectQueue
32
  {
33
  private static final int NUM_FLOAT_UNIFORMS = FragmentEffect.NUM_FLOAT_UNIFORMS;
34
  private static final int NUM_INT_UNIFORMS   = FragmentEffect.NUM_INT_UNIFORMS;
35
  private static final boolean USE_UBO        = false;
36
  private static final int INDEX = EffectType.FRAGMENT.ordinal();
37

    
38
  private final static int[] mNumEffectsH  = new int[MAIN_VARIANTS];
39
  private final static int[] mIntUniformsH = new int[MAIN_VARIANTS];
40
  private final static int[] mFloUniformsH = new int[MAIN_VARIANTS];
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
   
44
  EffectQueueFragment()
45
    { 
46
    super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
47
    }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
  EffectQueueFragment(EffectQueueFragment source)
52
    {
53
    super(source);
54
    }
55

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

    
58
  static void uniforms(int mProgramH, int variant)
59
    {
60
    mNumEffectsH[variant]   = GLES30.glGetUniformLocation  ( mProgramH, "fNumEffects");
61
    mIntUniformsH[variant]  = GLES30.glGetUniformLocation  ( mProgramH, "fProperties");
62
    mFloUniformsH[variant]  = GLES30.glGetUniformLocation  ( mProgramH, "fUniforms");
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
  
67
  void compute(long currTime, long step)
68
    {
69
    if( mNumEffects>0 )
70
      {
71
      float[] array = mUBF.getBackingArray();
72

    
73
      for(int i=0; i<mNumEffects; i++)
74
        {
75
        if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) )
76
          {
77
          EffectMessageSender.newMessage(mEffects[i]);
78
          }
79
        }
80
      }
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84
  
85
  void send(int programH, int variant)
86
    {
87
    GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);
88

    
89
    if( mNumEffects>0 )
90
      {
91
      int[]   arrayI = mUBI.getBackingArray();
92
      float[] arrayF = mUBF.getBackingArray();
93

    
94
      GLES30.glUniform4iv( mIntUniformsH[variant],                       mNumEffects, arrayI, 0);
95
      GLES30.glUniform4fv( mFloUniformsH[variant],(NUM_FLOAT_UNIFORMS/4)*mNumEffects, arrayF, 0);
96
      }  
97
    }
98
  }
(2-2/5)