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