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.VertexEffect;
|
27
|
import org.distorted.library.message.EffectMessageSender;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
/**
|
31
|
* Not part of public API, do not document (public only because has to be used in Meshes)
|
32
|
*
|
33
|
* @y.exclude
|
34
|
*/
|
35
|
public class EffectQueueVertex extends EffectQueue
|
36
|
{
|
37
|
private static final int NUM_FLOAT_UNIFORMS = VertexEffect.NUM_FLOAT_UNIFORMS;
|
38
|
private static final int NUM_INT_UNIFORMS = VertexEffect.NUM_INT_UNIFORMS;
|
39
|
private static final boolean USE_UBO = true;
|
40
|
|
41
|
private static final int INDEX = EffectType.VERTEX.ordinal();
|
42
|
|
43
|
private final static int[] mNumEffectsH = new int[MAIN_VARIANTS];
|
44
|
private final static int[] mInflateH = new int[MAIN_VARIANTS];
|
45
|
private final static int[] mIntBlockIndex= new int[MAIN_VARIANTS];
|
46
|
private final static int[] mFloBlockIndex= new int[MAIN_VARIANTS];
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
public EffectQueueVertex()
|
51
|
{
|
52
|
super(NUM_FLOAT_UNIFORMS, NUM_INT_UNIFORMS, USE_UBO, INDEX);
|
53
|
}
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
public EffectQueueVertex(EffectQueueVertex source)
|
58
|
{
|
59
|
super(source);
|
60
|
}
|
61
|
|
62
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63
|
|
64
|
static void uniforms(int mProgramH, int variant)
|
65
|
{
|
66
|
mNumEffectsH[variant] = GLES30.glGetUniformLocation ( mProgramH, "vNumEffects");
|
67
|
mInflateH[variant] = GLES30.glGetUniformLocation ( mProgramH, "u_Inflate");
|
68
|
mIntBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformProperties");
|
69
|
mFloBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformFloats");
|
70
|
}
|
71
|
|
72
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73
|
/**
|
74
|
* Not part of public API, do not document (public only because has to be used in Meshes)
|
75
|
*
|
76
|
* @y.exclude
|
77
|
*/
|
78
|
public void compute(long currTime, long step)
|
79
|
{
|
80
|
if( mNumEffects>0 )
|
81
|
{
|
82
|
float[] array = mUBF.getBackingArray();
|
83
|
|
84
|
for(int i=0; i<mNumEffects; i++)
|
85
|
{
|
86
|
if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
87
|
{
|
88
|
EffectMessageSender.newMessage(mEffects[i]);
|
89
|
}
|
90
|
}
|
91
|
|
92
|
mUBF.invalidate();
|
93
|
}
|
94
|
}
|
95
|
|
96
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97
|
/**
|
98
|
* Not part of public API, do not document (public only because has to be used in Meshes)
|
99
|
*
|
100
|
* @y.exclude
|
101
|
*/
|
102
|
public void send(float inflate, int programH, int variant)
|
103
|
{
|
104
|
GLES30.glUniform1i( mNumEffectsH[variant], mNumEffects);
|
105
|
GLES30.glUniform1f( mInflateH[variant] , inflate );
|
106
|
|
107
|
if( mNumEffects>0 )
|
108
|
{
|
109
|
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, VERT_INT_UBO_BINDING, mUBI.getIndex());
|
110
|
GLES30.glUniformBlockBinding(programH, mIntBlockIndex[variant], VERT_INT_UBO_BINDING);
|
111
|
|
112
|
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, VERT_FLO_UBO_BINDING, mUBF.getIndex());
|
113
|
GLES30.glUniformBlockBinding(programH, mFloBlockIndex[variant], VERT_FLO_UBO_BINDING);
|
114
|
}
|
115
|
}
|
116
|
}
|