Project

General

Profile

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

library / src / main / java / org / distorted / library / effectqueue / EffectQueueFragment.java @ de77a6c5

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.FragmentEffect;
26
import org.distorted.library.message.EffectMessageSender;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
class EffectQueueFragment extends EffectQueue
31
  {
32
  private static final int NUM_FLOAT_UNIFORMS = FragmentEffect.NUM_FLOAT_UNIFORMS;
33
  private static final int NUM_INT_UNIFORMS   = FragmentEffect.NUM_INT_UNIFORMS;
34

    
35
  private static final int INDEX = EffectType.FRAGMENT.ordinal();
36

    
37
  private final static int[] mNumEffectsH  = new int[MAIN_VARIANTS];
38
  private final static int[] mIntBlockIndex= new int[MAIN_VARIANTS];
39
  private final static int[] mFloBlockIndex= new int[MAIN_VARIANTS];
40

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

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

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

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  static void uniforms(int mProgramH, int variant)
58
    {
59
    mNumEffectsH[variant]   = GLES30.glGetUniformLocation  ( mProgramH, "fNumEffects");
60
    mIntBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "fUniformProperties");
61
    mFloBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "fUniformFloats");
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
  
66
  void compute(long currTime)
67
    { 
68
    if( currTime==mTime ) return;
69
    if( mTime==0 ) mTime = currTime;
70

    
71
    if( mNumEffects>0 )
72
      {
73
      long step = (currTime-mTime);
74
      float[] array = mUBF.getBackingArray();
75

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

    
84
      mUBF.invalidate();
85
      }
86

    
87
    mTime = currTime;  
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91
  
92
  void send(int programH, int variant)
93
    {
94
    GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);
95

    
96
    if( mNumEffects>0 )
97
      {
98
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, FRAG_INT_UBO_BINDING, mUBI.getIndex());
99
      GLES30.glUniformBlockBinding(programH, mIntBlockIndex[variant], FRAG_INT_UBO_BINDING);
100

    
101
      GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, FRAG_FLO_UBO_BINDING, mUBF.getIndex());
102
      GLES30.glUniformBlockBinding(programH, mFloBlockIndex[variant], FRAG_FLO_UBO_BINDING);
103
      }  
104
    }
105
  }
(2-2/5)