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.effect.Effect;
|
26
|
import org.distorted.library.main.DistortedLibrary;
|
27
|
import org.distorted.library.main.InternalBuffer;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
/**
|
31
|
* Not part of public API, do not document
|
32
|
*
|
33
|
* @y.exclude
|
34
|
*/
|
35
|
public class UniformBlockIntUniforms
|
36
|
{
|
37
|
private InternalBuffer mUBO;
|
38
|
private final int[] mArray;
|
39
|
private final int mNumUniforms, mSize;
|
40
|
private final boolean mReallyUseUBO;
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
|
44
|
public UniformBlockIntUniforms(int numUniforms, int size, boolean reallyUse)
|
45
|
{
|
46
|
mNumUniforms = numUniforms;
|
47
|
mSize = size;
|
48
|
mArray = new int[mNumUniforms*mSize];
|
49
|
mReallyUseUBO= reallyUse;
|
50
|
|
51
|
if( mReallyUseUBO )
|
52
|
{
|
53
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
|
54
|
}
|
55
|
}
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
|
59
|
public UniformBlockIntUniforms(UniformBlockIntUniforms original)
|
60
|
{
|
61
|
mNumUniforms = original.mNumUniforms;
|
62
|
mSize = original.mSize;
|
63
|
mArray = new int[mNumUniforms*mSize];
|
64
|
mReallyUseUBO= original.mReallyUseUBO;
|
65
|
|
66
|
System.arraycopy(original.mArray, 0, mArray, 0, mSize);
|
67
|
|
68
|
if( mReallyUseUBO )
|
69
|
{
|
70
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
|
71
|
}
|
72
|
}
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
public int getIndex()
|
77
|
{
|
78
|
return mUBO.createImmediatelyInt( 4*mNumUniforms*mSize, mArray);
|
79
|
}
|
80
|
|
81
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
82
|
|
83
|
public void remove(int pos, int numEffects)
|
84
|
{
|
85
|
System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) );
|
86
|
|
87
|
if( mReallyUseUBO )
|
88
|
{
|
89
|
mUBO.invalidate();
|
90
|
}
|
91
|
}
|
92
|
|
93
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94
|
|
95
|
public void makeHole(int pos, int numEffects)
|
96
|
{
|
97
|
System.arraycopy(mArray, mNumUniforms*pos, mArray, mNumUniforms*(pos+1), mNumUniforms*(numEffects-pos) );
|
98
|
|
99
|
if( mReallyUseUBO )
|
100
|
{
|
101
|
mUBO.invalidate();
|
102
|
}
|
103
|
}
|
104
|
|
105
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106
|
|
107
|
public void addOrdinal(int pos, int ordinal)
|
108
|
{
|
109
|
mArray[mNumUniforms*pos] = ordinal;
|
110
|
|
111
|
if( mReallyUseUBO )
|
112
|
{
|
113
|
mUBO.invalidate();
|
114
|
}
|
115
|
}
|
116
|
|
117
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118
|
|
119
|
public void addAssociations(int pos, Effect effect)
|
120
|
{
|
121
|
effect.writeAssociations(mArray, mNumUniforms*pos+1, mNumUniforms*pos+3);
|
122
|
|
123
|
if( mReallyUseUBO )
|
124
|
{
|
125
|
mUBO.invalidate();
|
126
|
}
|
127
|
}
|
128
|
|
129
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130
|
|
131
|
public void markForDeletion()
|
132
|
{
|
133
|
if( mReallyUseUBO )
|
134
|
{
|
135
|
mUBO.markForDeletion();
|
136
|
}
|
137
|
}
|
138
|
|
139
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140
|
|
141
|
public int[] getBackingArray()
|
142
|
{
|
143
|
return mArray;
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
public void print(int num)
|
149
|
{
|
150
|
StringBuilder builder = new StringBuilder();
|
151
|
|
152
|
builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED");
|
153
|
builder.append(':');
|
154
|
|
155
|
for(int i=0; i<6; i++)
|
156
|
{
|
157
|
builder.append(' ');
|
158
|
builder.append(mArray[4*i ]);
|
159
|
builder.append(' ');
|
160
|
builder.append(mArray[4*i+1]);
|
161
|
builder.append(' ');
|
162
|
builder.append(mArray[4*i+2]);
|
163
|
builder.append(',');
|
164
|
}
|
165
|
|
166
|
builder.append(' ');
|
167
|
builder.append('(');
|
168
|
builder.append(num);
|
169
|
builder.append(')');
|
170
|
|
171
|
String res = builder.toString();
|
172
|
|
173
|
DistortedLibrary.logMessage("UniformBlockIntUniforms: "+res);
|
174
|
}
|
175
|
}
|