Revision 4f61d20e
Added by Leszek Koltunski about 18 hours ago
src/main/java/org/distorted/library/uniformblock/UniformBlockAssociation.java | ||
---|---|---|
1 |
//////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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 org.distorted.library.main.DistortedLibrary; |
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
import org.distorted.library.mesh.MeshBase; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
/** |
|
29 |
* Not part of public API, do not document |
|
30 |
* |
|
31 |
* @y.exclude |
|
32 |
*/ |
|
33 |
public class UniformBlockAssociation |
|
34 |
{ |
|
35 |
private static final int DEFAULT_ASSOCIATION = 0x7fffffff; // all effects associated, all components affected |
|
36 |
private static final int DEFAULT_STRIDE = 4; |
|
37 |
private static final int LOC_AND = 0; |
|
38 |
private static final int LOC_EQU = 1; |
|
39 |
|
|
40 |
private final InternalBuffer mUBO; |
|
41 |
private final int mMax; |
|
42 |
private int[] mAssociations; |
|
43 |
private int mStride; |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
public UniformBlockAssociation() |
|
48 |
{ |
|
49 |
mMax = MeshBase.getMaxEffComponents(); |
|
50 |
mStride = DEFAULT_STRIDE; |
|
51 |
mAssociations= new int[mStride*mMax]; |
|
52 |
|
|
53 |
for(int i=0; i<mMax; i++) |
|
54 |
{ |
|
55 |
mAssociations[mStride*i+LOC_AND] = DEFAULT_ASSOCIATION; |
|
56 |
mAssociations[mStride*i+LOC_EQU] = i; |
|
57 |
} |
|
58 |
|
|
59 |
mUBO = new InternalBuffer(); |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
public UniformBlockAssociation(UniformBlockAssociation original) |
|
65 |
{ |
|
66 |
mMax = original.mMax; |
|
67 |
mStride = original.mStride; |
|
68 |
int size = original.mAssociations.length; |
|
69 |
mAssociations= new int[size]; |
|
70 |
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size); |
|
71 |
|
|
72 |
mUBO = new InternalBuffer(); |
|
73 |
} |
|
74 |
|
|
75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 |
// stride can be 0, if we just tried compiling a vertex shader which has NUM_VERTEX=0. |
|
77 |
// stride==1 we also don't like because then we have an exception ( stride*mMax-1 < stride*(mMax-1)+1 ) |
|
78 |
|
|
79 |
public void correctStride(int stride) |
|
80 |
{ |
|
81 |
if( mStride != stride && stride>1 ) |
|
82 |
{ |
|
83 |
int[] tmp = new int[stride*mMax]; |
|
84 |
|
|
85 |
for(int i=0; i<mMax; i++) |
|
86 |
{ |
|
87 |
tmp[stride*i+LOC_AND] = mAssociations[mStride*i+LOC_AND]; |
|
88 |
tmp[stride*i+LOC_EQU] = mAssociations[mStride*i+LOC_EQU]; |
|
89 |
} |
|
90 |
|
|
91 |
mAssociations = tmp; |
|
92 |
mStride = stride; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
public boolean matchesAssociation( int comp, int andAssoc, int equAssoc) |
|
99 |
{ |
|
100 |
return (andAssoc & mAssociations[mStride*comp+LOC_AND]) != 0 || (equAssoc == mAssociations[mStride*comp+LOC_EQU]); |
|
101 |
} |
|
102 |
|
|
103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
104 |
|
|
105 |
public void setEffectAssociationNow(int comp, int andAssociation, int equAssociation) |
|
106 |
{ |
|
107 |
int index = mStride*comp; |
|
108 |
mAssociations[index+LOC_AND] &= (~DEFAULT_ASSOCIATION); |
|
109 |
mAssociations[index+LOC_AND] += (andAssociation & DEFAULT_ASSOCIATION); |
|
110 |
mAssociations[index+LOC_EQU] = equAssociation; |
|
111 |
|
|
112 |
mUBO.invalidate(); |
|
113 |
} |
|
114 |
|
|
115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
116 |
|
|
117 |
public void setNotAffectedComponentsNow(int[] components) |
|
118 |
{ |
|
119 |
for(int c=0; c<mMax; c++) mAssociations[mStride*c+LOC_AND] &= DEFAULT_ASSOCIATION; |
|
120 |
|
|
121 |
if( components!=null ) |
|
122 |
{ |
|
123 |
for(int c : components) mAssociations[mStride*c+LOC_AND] |= (~DEFAULT_ASSOCIATION); |
|
124 |
} |
|
125 |
|
|
126 |
mUBO.invalidate(); |
|
127 |
} |
|
128 |
|
|
129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
130 |
|
|
131 |
public int getIndex() |
|
132 |
{ |
|
133 |
return mUBO.createImmediatelyInt( 4*mStride*mMax, mAssociations); |
|
134 |
} |
|
135 |
|
|
136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
137 |
|
|
138 |
public void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom) |
|
139 |
{ |
|
140 |
mAssociations[mStride*compTo+LOC_AND] = assocFrom.mAssociations[mStride*compFrom+LOC_AND]; |
|
141 |
mAssociations[mStride*compTo+LOC_EQU] = assocFrom.mAssociations[mStride*compFrom+LOC_EQU]; |
|
142 |
} |
|
143 |
|
|
144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
145 |
|
|
146 |
public void markForDeletion() |
|
147 |
{ |
|
148 |
mUBO.markForDeletion(); |
|
149 |
} |
|
150 |
|
|
151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
152 |
|
|
153 |
public void print() |
|
154 |
{ |
|
155 |
StringBuilder builder = new StringBuilder(); |
|
156 |
|
|
157 |
builder.append(mUBO.getID()); |
|
158 |
builder.append(' '); |
|
159 |
|
|
160 |
for(int i=0; i<8; i++) |
|
161 |
{ |
|
162 |
builder.append(mAssociations[mStride*i+LOC_AND]); |
|
163 |
builder.append(' '); |
|
164 |
builder.append(mAssociations[mStride*i+LOC_EQU]); |
|
165 |
builder.append(' '); |
|
166 |
} |
|
167 |
|
|
168 |
String res = builder.toString(); |
|
169 |
|
|
170 |
DistortedLibrary.logMessage("UniformBlockAssociation: "+res); |
|
171 |
} |
|
172 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockAssociation.kt | ||
---|---|---|
1 |
//////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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 org.distorted.library.main.DistortedLibrary; |
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
import org.distorted.library.mesh.MeshBase; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
/** |
|
29 |
* Not part of public API, do not document |
|
30 |
* |
|
31 |
* @y.exclude |
|
32 |
*/ |
|
33 |
public class UniformBlockAssociation |
|
34 |
{ |
|
35 |
private static final int DEFAULT_ASSOCIATION = 0x7fffffff; // all effects associated, all components affected |
|
36 |
private static final int DEFAULT_STRIDE = 4; |
|
37 |
private static final int LOC_AND = 0; |
|
38 |
private static final int LOC_EQU = 1; |
|
39 |
|
|
40 |
private final InternalBuffer mUBO; |
|
41 |
private final int mMax; |
|
42 |
private int[] mAssociations; |
|
43 |
private int mStride; |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
public UniformBlockAssociation() |
|
48 |
{ |
|
49 |
mMax = MeshBase.getMaxEffComponents(); |
|
50 |
mStride = DEFAULT_STRIDE; |
|
51 |
mAssociations= new int[mStride*mMax]; |
|
52 |
|
|
53 |
for(int i=0; i<mMax; i++) |
|
54 |
{ |
|
55 |
mAssociations[mStride*i+LOC_AND] = DEFAULT_ASSOCIATION; |
|
56 |
mAssociations[mStride*i+LOC_EQU] = i; |
|
57 |
} |
|
58 |
|
|
59 |
mUBO = new InternalBuffer(); |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
public UniformBlockAssociation(UniformBlockAssociation original) |
|
65 |
{ |
|
66 |
mMax = original.mMax; |
|
67 |
mStride = original.mStride; |
|
68 |
int size = original.mAssociations.length; |
|
69 |
mAssociations= new int[size]; |
|
70 |
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size); |
|
71 |
|
|
72 |
mUBO = new InternalBuffer(); |
|
73 |
} |
|
74 |
|
|
75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 |
// stride can be 0, if we just tried compiling a vertex shader which has NUM_VERTEX=0. |
|
77 |
// stride==1 we also don't like because then we have an exception ( stride*mMax-1 < stride*(mMax-1)+1 ) |
|
78 |
|
|
79 |
public void correctStride(int stride) |
|
80 |
{ |
|
81 |
if( mStride != stride && stride>1 ) |
|
82 |
{ |
|
83 |
int[] tmp = new int[stride*mMax]; |
|
84 |
|
|
85 |
for(int i=0; i<mMax; i++) |
|
86 |
{ |
|
87 |
tmp[stride*i+LOC_AND] = mAssociations[mStride*i+LOC_AND]; |
|
88 |
tmp[stride*i+LOC_EQU] = mAssociations[mStride*i+LOC_EQU]; |
|
89 |
} |
|
90 |
|
|
91 |
mAssociations = tmp; |
|
92 |
mStride = stride; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
public boolean matchesAssociation( int comp, int andAssoc, int equAssoc) |
|
99 |
{ |
|
100 |
return (andAssoc & mAssociations[mStride*comp+LOC_AND]) != 0 || (equAssoc == mAssociations[mStride*comp+LOC_EQU]); |
|
101 |
} |
|
102 |
|
|
103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
104 |
|
|
105 |
public void setEffectAssociationNow(int comp, int andAssociation, int equAssociation) |
|
106 |
{ |
|
107 |
int index = mStride*comp; |
|
108 |
mAssociations[index+LOC_AND] &= (~DEFAULT_ASSOCIATION); |
|
109 |
mAssociations[index+LOC_AND] += (andAssociation & DEFAULT_ASSOCIATION); |
|
110 |
mAssociations[index+LOC_EQU] = equAssociation; |
|
111 |
|
|
112 |
mUBO.invalidate(); |
|
113 |
} |
|
114 |
|
|
115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
116 |
|
|
117 |
public void setNotAffectedComponentsNow(int[] components) |
|
118 |
{ |
|
119 |
for(int c=0; c<mMax; c++) mAssociations[mStride*c+LOC_AND] &= DEFAULT_ASSOCIATION; |
|
120 |
|
|
121 |
if( components!=null ) |
|
122 |
{ |
|
123 |
for(int c : components) mAssociations[mStride*c+LOC_AND] |= (~DEFAULT_ASSOCIATION); |
|
124 |
} |
|
125 |
|
|
126 |
mUBO.invalidate(); |
|
127 |
} |
|
128 |
|
|
129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
130 |
|
|
131 |
public int getIndex() |
|
132 |
{ |
|
133 |
return mUBO.createImmediatelyInt( 4*mStride*mMax, mAssociations); |
|
134 |
} |
|
135 |
|
|
136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
137 |
|
|
138 |
public void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom) |
|
139 |
{ |
|
140 |
mAssociations[mStride*compTo+LOC_AND] = assocFrom.mAssociations[mStride*compFrom+LOC_AND]; |
|
141 |
mAssociations[mStride*compTo+LOC_EQU] = assocFrom.mAssociations[mStride*compFrom+LOC_EQU]; |
|
142 |
} |
|
143 |
|
|
144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
145 |
|
|
146 |
public void markForDeletion() |
|
147 |
{ |
|
148 |
mUBO.markForDeletion(); |
|
149 |
} |
|
150 |
|
|
151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
152 |
|
|
153 |
public void print() |
|
154 |
{ |
|
155 |
StringBuilder builder = new StringBuilder(); |
|
156 |
|
|
157 |
builder.append(mUBO.getID()); |
|
158 |
builder.append(' '); |
|
159 |
|
|
160 |
for(int i=0; i<8; i++) |
|
161 |
{ |
|
162 |
builder.append(mAssociations[mStride*i+LOC_AND]); |
|
163 |
builder.append(' '); |
|
164 |
builder.append(mAssociations[mStride*i+LOC_EQU]); |
|
165 |
builder.append(' '); |
|
166 |
} |
|
167 |
|
|
168 |
String res = builder.toString(); |
|
169 |
|
|
170 |
DistortedLibrary.logMessage("UniformBlockAssociation: "+res); |
|
171 |
} |
|
172 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockCenter.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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 org.distorted.library.main.InternalBuffer; |
|
24 |
import org.distorted.library.mesh.MeshBase; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
/** |
|
28 |
* Not part of public API, do not document |
|
29 |
* |
|
30 |
* @y.exclude |
|
31 |
*/ |
|
32 |
public class UniformBlockCenter |
|
33 |
{ |
|
34 |
private final InternalBuffer mUBO; |
|
35 |
private final float[] mArray; |
|
36 |
private final int mMax; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
public UniformBlockCenter() |
|
41 |
{ |
|
42 |
mMax = MeshBase.getMaxEffComponents(); |
|
43 |
mArray= new float[4*mMax]; |
|
44 |
mUBO = new InternalBuffer(); |
|
45 |
} |
|
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
public UniformBlockCenter(UniformBlockCenter original) |
|
50 |
{ |
|
51 |
mMax = original.mMax; |
|
52 |
int size = original.mArray.length; |
|
53 |
mArray= new float[size]; |
|
54 |
System.arraycopy(original.mArray, 0, mArray, 0, size); |
|
55 |
mUBO = new InternalBuffer(); |
|
56 |
} |
|
57 |
|
|
58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 |
|
|
60 |
public void setEffectCenterNow(int comp, float x, float y, float z) |
|
61 |
{ |
|
62 |
if( comp>=0 ) |
|
63 |
{ |
|
64 |
mArray[4*comp ] = x; |
|
65 |
mArray[4*comp+1] = y; |
|
66 |
mArray[4*comp+2] = z; |
|
67 |
} |
|
68 |
else |
|
69 |
{ |
|
70 |
for(int i=0; i<mMax; i++) |
|
71 |
{ |
|
72 |
mArray[4*i ] = x; |
|
73 |
mArray[4*i+1] = y; |
|
74 |
mArray[4*i+2] = z; |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
mUBO.invalidate(); |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
public int getIndex() |
|
84 |
{ |
|
85 |
return mUBO.createImmediatelyFloat( 16*mMax, mArray); |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 |
|
|
90 |
public void copy(int compTo, UniformBlockCenter blockFrom, int compFrom) |
|
91 |
{ |
|
92 |
mArray[4*compTo ] = blockFrom.mArray[4*compFrom ]; |
|
93 |
mArray[4*compTo+1] = blockFrom.mArray[4*compFrom+1]; |
|
94 |
mArray[4*compTo+2] = blockFrom.mArray[4*compFrom+2]; |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
public void markForDeletion() |
|
100 |
{ |
|
101 |
mUBO.markForDeletion(); |
|
102 |
} |
|
103 |
|
|
104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
105 |
|
|
106 |
public float[] getBackingArray() |
|
107 |
{ |
|
108 |
return mArray; |
|
109 |
} |
|
110 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockCenter.kt | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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 org.distorted.library.main.InternalBuffer; |
|
24 |
import org.distorted.library.mesh.MeshBase; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
/** |
|
28 |
* Not part of public API, do not document |
|
29 |
* |
|
30 |
* @y.exclude |
|
31 |
*/ |
|
32 |
public class UniformBlockCenter |
|
33 |
{ |
|
34 |
private final InternalBuffer mUBO; |
|
35 |
private final float[] mArray; |
|
36 |
private final int mMax; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
public UniformBlockCenter() |
|
41 |
{ |
|
42 |
mMax = MeshBase.getMaxEffComponents(); |
|
43 |
mArray= new float[4*mMax]; |
|
44 |
mUBO = new InternalBuffer(); |
|
45 |
} |
|
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
public UniformBlockCenter(UniformBlockCenter original) |
|
50 |
{ |
|
51 |
mMax = original.mMax; |
|
52 |
int size = original.mArray.length; |
|
53 |
mArray= new float[size]; |
|
54 |
System.arraycopy(original.mArray, 0, mArray, 0, size); |
|
55 |
mUBO = new InternalBuffer(); |
|
56 |
} |
|
57 |
|
|
58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 |
|
|
60 |
public void setEffectCenterNow(int comp, float x, float y, float z) |
|
61 |
{ |
|
62 |
if( comp>=0 ) |
|
63 |
{ |
|
64 |
mArray[4*comp ] = x; |
|
65 |
mArray[4*comp+1] = y; |
|
66 |
mArray[4*comp+2] = z; |
|
67 |
} |
|
68 |
else |
|
69 |
{ |
|
70 |
for(int i=0; i<mMax; i++) |
|
71 |
{ |
|
72 |
mArray[4*i ] = x; |
|
73 |
mArray[4*i+1] = y; |
|
74 |
mArray[4*i+2] = z; |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
mUBO.invalidate(); |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
public int getIndex() |
|
84 |
{ |
|
85 |
return mUBO.createImmediatelyFloat( 16*mMax, mArray); |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 |
|
|
90 |
public void copy(int compTo, UniformBlockCenter blockFrom, int compFrom) |
|
91 |
{ |
|
92 |
mArray[4*compTo ] = blockFrom.mArray[4*compFrom ]; |
|
93 |
mArray[4*compTo+1] = blockFrom.mArray[4*compFrom+1]; |
|
94 |
mArray[4*compTo+2] = blockFrom.mArray[4*compFrom+2]; |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
public void markForDeletion() |
|
100 |
{ |
|
101 |
mUBO.markForDeletion(); |
|
102 |
} |
|
103 |
|
|
104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
105 |
|
|
106 |
public float[] getBackingArray() |
|
107 |
{ |
|
108 |
return mArray; |
|
109 |
} |
|
110 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockFloatUniforms.java | ||
---|---|---|
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 org.distorted.library.main.DistortedLibrary; |
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
/** |
|
29 |
* Not part of public API, do not document |
|
30 |
* |
|
31 |
* @y.exclude |
|
32 |
*/ |
|
33 |
public class UniformBlockFloatUniforms |
|
34 |
{ |
|
35 |
private InternalBuffer mUBO; |
|
36 |
private final float[] mArray; |
|
37 |
private final int mNumUniforms, mSize; |
|
38 |
private final boolean mReallyUseUBO; |
|
39 |
|
|
40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
|
42 |
public UniformBlockFloatUniforms(int numUniforms, int size, boolean reallyUse) |
|
43 |
{ |
|
44 |
mNumUniforms = numUniforms; |
|
45 |
mSize = size; |
|
46 |
mArray = new float[mNumUniforms*mSize]; |
|
47 |
mReallyUseUBO= reallyUse; |
|
48 |
|
|
49 |
if( mReallyUseUBO ) |
|
50 |
{ |
|
51 |
mUBO = new InternalBuffer(); |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
|
57 |
public UniformBlockFloatUniforms(UniformBlockFloatUniforms original) |
|
58 |
{ |
|
59 |
mNumUniforms = original.mNumUniforms; |
|
60 |
mSize = original.mSize; |
|
61 |
mArray = new float[mNumUniforms*mSize]; |
|
62 |
mReallyUseUBO= original.mReallyUseUBO; |
|
63 |
|
|
64 |
System.arraycopy(original.mArray, 0, mArray, 0, 3*mSize); |
|
65 |
|
|
66 |
if( mReallyUseUBO ) |
|
67 |
{ |
|
68 |
mUBO = new InternalBuffer(); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
public int getIndex() |
|
75 |
{ |
|
76 |
return mUBO.createImmediatelyFloat( 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 markForDeletion() |
|
94 |
{ |
|
95 |
if( mReallyUseUBO ) |
|
96 |
{ |
|
97 |
mUBO.markForDeletion(); |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
102 |
|
|
103 |
public void invalidate() |
|
104 |
{ |
|
105 |
if( mReallyUseUBO ) |
|
106 |
{ |
|
107 |
mUBO.invalidate(); |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
112 |
|
|
113 |
public float[] getBackingArray() |
|
114 |
{ |
|
115 |
return mArray; |
|
116 |
} |
|
117 |
|
|
118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
|
|
120 |
public void print(int num) |
|
121 |
{ |
|
122 |
StringBuilder builder = new StringBuilder(); |
|
123 |
|
|
124 |
builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED"); |
|
125 |
builder.append(':'); |
|
126 |
|
|
127 |
for(int i=0; i<6; i++) |
|
128 |
{ |
|
129 |
builder.append(' '); |
|
130 |
builder.append(mArray[4*i ]); |
|
131 |
builder.append(' '); |
|
132 |
builder.append(mArray[4*i+1]); |
|
133 |
builder.append(' '); |
|
134 |
builder.append(mArray[4*i+2]); |
|
135 |
builder.append(','); |
|
136 |
} |
|
137 |
|
|
138 |
builder.append(' '); |
|
139 |
builder.append('('); |
|
140 |
builder.append(num); |
|
141 |
builder.append(')'); |
|
142 |
|
|
143 |
String res = builder.toString(); |
|
144 |
|
|
145 |
DistortedLibrary.logMessage("UniformBlockFloatUniforms: "+res); |
|
146 |
} |
|
147 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockFloatUniforms.kt | ||
---|---|---|
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 org.distorted.library.main.DistortedLibrary; |
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
/** |
|
29 |
* Not part of public API, do not document |
|
30 |
* |
|
31 |
* @y.exclude |
|
32 |
*/ |
|
33 |
public class UniformBlockFloatUniforms |
|
34 |
{ |
|
35 |
private InternalBuffer mUBO; |
|
36 |
private final float[] mArray; |
|
37 |
private final int mNumUniforms, mSize; |
|
38 |
private final boolean mReallyUseUBO; |
|
39 |
|
|
40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
|
42 |
public UniformBlockFloatUniforms(int numUniforms, int size, boolean reallyUse) |
|
43 |
{ |
|
44 |
mNumUniforms = numUniforms; |
|
45 |
mSize = size; |
|
46 |
mArray = new float[mNumUniforms*mSize]; |
|
47 |
mReallyUseUBO= reallyUse; |
|
48 |
|
|
49 |
if( mReallyUseUBO ) |
|
50 |
{ |
|
51 |
mUBO = new InternalBuffer(); |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
|
57 |
public UniformBlockFloatUniforms(UniformBlockFloatUniforms original) |
|
58 |
{ |
|
59 |
mNumUniforms = original.mNumUniforms; |
|
60 |
mSize = original.mSize; |
|
61 |
mArray = new float[mNumUniforms*mSize]; |
|
62 |
mReallyUseUBO= original.mReallyUseUBO; |
|
63 |
|
|
64 |
System.arraycopy(original.mArray, 0, mArray, 0, 3*mSize); |
|
65 |
|
|
66 |
if( mReallyUseUBO ) |
|
67 |
{ |
|
68 |
mUBO = new InternalBuffer(); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
public int getIndex() |
|
75 |
{ |
|
76 |
return mUBO.createImmediatelyFloat( 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 markForDeletion() |
|
94 |
{ |
|
95 |
if( mReallyUseUBO ) |
|
96 |
{ |
|
97 |
mUBO.markForDeletion(); |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
102 |
|
|
103 |
public void invalidate() |
|
104 |
{ |
|
105 |
if( mReallyUseUBO ) |
|
106 |
{ |
|
107 |
mUBO.invalidate(); |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
112 |
|
|
113 |
public float[] getBackingArray() |
|
114 |
{ |
|
115 |
return mArray; |
|
116 |
} |
|
117 |
|
|
118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
|
|
120 |
public void print(int num) |
|
121 |
{ |
|
122 |
StringBuilder builder = new StringBuilder(); |
|
123 |
|
|
124 |
builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED"); |
|
125 |
builder.append(':'); |
|
126 |
|
|
127 |
for(int i=0; i<6; i++) |
|
128 |
{ |
|
129 |
builder.append(' '); |
|
130 |
builder.append(mArray[4*i ]); |
|
131 |
builder.append(' '); |
|
132 |
builder.append(mArray[4*i+1]); |
|
133 |
builder.append(' '); |
|
134 |
builder.append(mArray[4*i+2]); |
|
135 |
builder.append(','); |
|
136 |
} |
|
137 |
|
|
138 |
builder.append(' '); |
|
139 |
builder.append('('); |
|
140 |
builder.append(num); |
|
141 |
builder.append(')'); |
|
142 |
|
|
143 |
String res = builder.toString(); |
|
144 |
|
|
145 |
DistortedLibrary.logMessage("UniformBlockFloatUniforms: "+res); |
|
146 |
} |
|
147 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockIntUniforms.java | ||
---|---|---|
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 org.distorted.library.effect.Effect; |
|
24 |
import org.distorted.library.main.DistortedLibrary; |
|
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(); |
|
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(); |
|
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 |
DistortedLibrary.logMessage("UniformBlockIntUniforms: "+res); |
|
172 |
} |
|
173 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockIntUniforms.kt | ||
---|---|---|
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 org.distorted.library.effect.Effect; |
|
24 |
import org.distorted.library.main.DistortedLibrary; |
|
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(); |
|
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(); |
|
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 |
DistortedLibrary.logMessage("UniformBlockIntUniforms: "+res); |
|
172 |
} |
|
173 |
} |
Also available in: Unified diff
Rename .java to .kt