1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
package org.distorted.library.uniformblock;
|
21
|
|
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
|
/**
|
30
|
* Not part of public API, do not document
|
31
|
*
|
32
|
* @y.exclude
|
33
|
*/
|
34
|
public class UniformBlockAssociation
|
35
|
{
|
36
|
private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;
|
37
|
private static final int DEFAULT_ASSOCIATION = 0xffffffff;
|
38
|
|
39
|
private final InternalBuffer mUBO;
|
40
|
private final int[] mAssociations;
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
|
44
|
public UniformBlockAssociation()
|
45
|
{
|
46
|
mAssociations= new int[BLOCK_SIZE/4];
|
47
|
|
48
|
for(int i=0; i<MAX_EFFECT_COMPONENTS; i++)
|
49
|
{
|
50
|
mAssociations[4*i ] = DEFAULT_ASSOCIATION;
|
51
|
mAssociations[4*i+2] = i;
|
52
|
}
|
53
|
|
54
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
|
55
|
}
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
|
59
|
public UniformBlockAssociation(UniformBlockAssociation original)
|
60
|
{
|
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
|
public boolean matchesAssociation( int comp, int andAssoc, int equAssoc)
|
71
|
{
|
72
|
return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]);
|
73
|
}
|
74
|
|
75
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
|
77
|
public void setEffectAssociationNow(int comp, int andAssociation, int equAssociation)
|
78
|
{
|
79
|
mAssociations[4*comp ] = andAssociation;
|
80
|
mAssociations[4*comp+2] = equAssociation;
|
81
|
|
82
|
mUBO.invalidate();
|
83
|
}
|
84
|
|
85
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86
|
|
87
|
public int getIndex()
|
88
|
{
|
89
|
return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations);
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
public void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom)
|
95
|
{
|
96
|
mAssociations[4*compTo ] = assocFrom.mAssociations[4*compFrom ];
|
97
|
mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2];
|
98
|
}
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
|
102
|
public void markForDeletion()
|
103
|
{
|
104
|
mUBO.markForDeletion();
|
105
|
}
|
106
|
|
107
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108
|
|
109
|
public void print()
|
110
|
{
|
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
|
}
|