1 |
97755c02
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 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 |
de77a6c5
|
Leszek Koltunski
|
package org.distorted.library.uniformblock;
|
21 |
97755c02
|
Leszek Koltunski
|
|
22 |
|
|
import android.opengl.GLES30;
|
23 |
|
|
|
24 |
|
|
import org.distorted.library.main.InternalBuffer;
|
25 |
|
|
|
26 |
|
|
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS;
|
27 |
|
|
|
28 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29 |
de77a6c5
|
Leszek Koltunski
|
/**
|
30 |
|
|
* Not part of public API, do not document
|
31 |
|
|
*
|
32 |
|
|
* @y.exclude
|
33 |
|
|
*/
|
34 |
|
|
public class UniformBlockAssociation
|
35 |
97755c02
|
Leszek Koltunski
|
{
|
36 |
a2878a67
|
Leszek Koltunski
|
private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;
|
37 |
97755c02
|
Leszek Koltunski
|
private static final int DEFAULT_ASSOCIATION = 0xffffffff;
|
38 |
|
|
|
39 |
78ff6ea9
|
Leszek Koltunski
|
private final InternalBuffer mUBO;
|
40 |
|
|
private final int[] mAssociations;
|
41 |
97755c02
|
Leszek Koltunski
|
|
42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
41b3ada0
|
Leszek Koltunski
|
|
44 |
de77a6c5
|
Leszek Koltunski
|
public UniformBlockAssociation()
|
45 |
97755c02
|
Leszek Koltunski
|
{
|
46 |
a2878a67
|
Leszek Koltunski
|
mAssociations= new int[BLOCK_SIZE/4];
|
47 |
97755c02
|
Leszek Koltunski
|
|
48 |
|
|
for(int i=0; i<MAX_EFFECT_COMPONENTS; i++)
|
49 |
|
|
{
|
50 |
41b3ada0
|
Leszek Koltunski
|
mAssociations[4*i ] = DEFAULT_ASSOCIATION;
|
51 |
|
|
mAssociations[4*i+2] = i;
|
52 |
97755c02
|
Leszek Koltunski
|
}
|
53 |
|
|
|
54 |
|
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
|
59 |
de77a6c5
|
Leszek Koltunski
|
public UniformBlockAssociation(UniformBlockAssociation original)
|
60 |
97755c02
|
Leszek Koltunski
|
{
|
61 |
|
|
int size = original.mAssociations.length;
|
62 |
|
|
mAssociations= new int[size];
|
63 |
|
|
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size);
|
64 |
|
|
|
65 |
|
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
|
70 |
de77a6c5
|
Leszek Koltunski
|
public boolean matchesAssociation( int comp, int andAssoc, int equAssoc)
|
71 |
728a7820
|
Leszek Koltunski
|
{
|
72 |
|
|
return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]);
|
73 |
|
|
}
|
74 |
97755c02
|
Leszek Koltunski
|
|
75 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76 |
|
|
|
77 |
de77a6c5
|
Leszek Koltunski
|
public void setEffectAssociationNow(int comp, int andAssociation, int equAssociation)
|
78 |
728a7820
|
Leszek Koltunski
|
{
|
79 |
|
|
mAssociations[4*comp ] = andAssociation;
|
80 |
|
|
mAssociations[4*comp+2] = equAssociation;
|
81 |
97755c02
|
Leszek Koltunski
|
|
82 |
728a7820
|
Leszek Koltunski
|
mUBO.invalidate();
|
83 |
|
|
}
|
84 |
97755c02
|
Leszek Koltunski
|
|
85 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86 |
|
|
|
87 |
de77a6c5
|
Leszek Koltunski
|
public int getIndex()
|
88 |
728a7820
|
Leszek Koltunski
|
{
|
89 |
|
|
return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations);
|
90 |
|
|
}
|
91 |
97755c02
|
Leszek Koltunski
|
|
92 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93 |
|
|
|
94 |
de77a6c5
|
Leszek Koltunski
|
public void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom)
|
95 |
728a7820
|
Leszek Koltunski
|
{
|
96 |
|
|
mAssociations[4*compTo ] = assocFrom.mAssociations[4*compFrom ];
|
97 |
|
|
mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2];
|
98 |
|
|
}
|
99 |
|
|
|
100 |
8b36dabf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101 |
|
|
|
102 |
de77a6c5
|
Leszek Koltunski
|
public void markForDeletion()
|
103 |
8b36dabf
|
Leszek Koltunski
|
{
|
104 |
|
|
mUBO.markForDeletion();
|
105 |
|
|
}
|
106 |
|
|
|
107 |
728a7820
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108 |
|
|
|
109 |
de77a6c5
|
Leszek Koltunski
|
public void print()
|
110 |
728a7820
|
Leszek Koltunski
|
{
|
111 |
|
|
StringBuilder builder = new StringBuilder();
|
112 |
|
|
|
113 |
|
|
builder.append(mUBO.getID());
|
114 |
|
|
builder.append(' ');
|
115 |
|
|
|
116 |
|
|
for(int i=0; i<8; i++)
|
117 |
|
|
{
|
118 |
|
|
builder.append(mAssociations[4*i]);
|
119 |
|
|
builder.append(' ');
|
120 |
|
|
builder.append(mAssociations[4*i+2]);
|
121 |
|
|
builder.append(' ');
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
String res = builder.toString();
|
125 |
|
|
|
126 |
|
|
android.util.Log.e("uba", res);
|
127 |
|
|
}
|
128 |
97755c02
|
Leszek Koltunski
|
}
|