1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 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.uniformblock;
|
22
|
|
23
|
import android.opengl.GLES30;
|
24
|
|
25
|
import org.distorted.library.main.InternalBuffer;
|
26
|
|
27
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28
|
|
29
|
/**
|
30
|
* Not part of public API, do not document
|
31
|
*
|
32
|
* @y.exclude
|
33
|
*/
|
34
|
public class UniformBlockFloatUniforms
|
35
|
{
|
36
|
private InternalBuffer mUBO;
|
37
|
private final float[] mArray;
|
38
|
private final int mNumUniforms, mSize;
|
39
|
private final boolean mReallyUseUBO;
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
public UniformBlockFloatUniforms(int numUniforms, int size, boolean reallyUse)
|
44
|
{
|
45
|
mNumUniforms = numUniforms;
|
46
|
mSize = size;
|
47
|
mArray = new float[mNumUniforms*mSize];
|
48
|
mReallyUseUBO= reallyUse;
|
49
|
|
50
|
if( mReallyUseUBO )
|
51
|
{
|
52
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
|
53
|
}
|
54
|
}
|
55
|
|
56
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57
|
|
58
|
public UniformBlockFloatUniforms(UniformBlockFloatUniforms original)
|
59
|
{
|
60
|
mNumUniforms = original.mNumUniforms;
|
61
|
mSize = original.mSize;
|
62
|
mArray = new float[mNumUniforms*mSize];
|
63
|
mReallyUseUBO= original.mReallyUseUBO;
|
64
|
|
65
|
System.arraycopy(original.mArray, 0, mArray, 0, 3*mSize);
|
66
|
|
67
|
if( mReallyUseUBO )
|
68
|
{
|
69
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
|
70
|
}
|
71
|
}
|
72
|
|
73
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74
|
|
75
|
public int getIndex()
|
76
|
{
|
77
|
return mUBO.createImmediatelyFloat( 4*mNumUniforms*mSize, mArray);
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
public void remove(int pos, int numEffects)
|
83
|
{
|
84
|
System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) );
|
85
|
|
86
|
if( mReallyUseUBO )
|
87
|
{
|
88
|
mUBO.invalidate();
|
89
|
}
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
public void markForDeletion()
|
95
|
{
|
96
|
if( mReallyUseUBO )
|
97
|
{
|
98
|
mUBO.markForDeletion();
|
99
|
}
|
100
|
}
|
101
|
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103
|
|
104
|
public void invalidate()
|
105
|
{
|
106
|
if( mReallyUseUBO )
|
107
|
{
|
108
|
mUBO.invalidate();
|
109
|
}
|
110
|
}
|
111
|
|
112
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113
|
|
114
|
public float[] getBackingArray()
|
115
|
{
|
116
|
return mArray;
|
117
|
}
|
118
|
|
119
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120
|
|
121
|
public void print(int num)
|
122
|
{
|
123
|
StringBuilder builder = new StringBuilder();
|
124
|
|
125
|
builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED");
|
126
|
builder.append(':');
|
127
|
|
128
|
for(int i=0; i<6; i++)
|
129
|
{
|
130
|
builder.append(' ');
|
131
|
builder.append(mArray[4*i ]);
|
132
|
builder.append(' ');
|
133
|
builder.append(mArray[4*i+1]);
|
134
|
builder.append(' ');
|
135
|
builder.append(mArray[4*i+2]);
|
136
|
builder.append(',');
|
137
|
}
|
138
|
|
139
|
builder.append(' ');
|
140
|
builder.append('(');
|
141
|
builder.append(num);
|
142
|
builder.append(')');
|
143
|
|
144
|
String res = builder.toString();
|
145
|
|
146
|
android.util.Log.e("ubp", res);
|
147
|
}
|
148
|
}
|