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.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 final InternalBuffer mUBO;
|
36
|
private final float[] mArray;
|
37
|
private final int mNumUniforms, mSize;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
public UniformBlockFloatUniforms(int numUniforms, int size)
|
42
|
{
|
43
|
mNumUniforms = numUniforms;
|
44
|
mSize = size;
|
45
|
mArray= new float[mNumUniforms*mSize];
|
46
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
|
47
|
}
|
48
|
|
49
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50
|
|
51
|
public UniformBlockFloatUniforms(UniformBlockFloatUniforms original)
|
52
|
{
|
53
|
mNumUniforms = original.mNumUniforms;
|
54
|
mSize = original.mSize;
|
55
|
mArray= new float[mNumUniforms*mSize];
|
56
|
System.arraycopy(original.mArray, 0, mArray, 0, 3*mSize);
|
57
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
|
58
|
}
|
59
|
|
60
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61
|
|
62
|
public int getIndex()
|
63
|
{
|
64
|
return mUBO.createImmediatelyFloat( 4*mNumUniforms*mSize, mArray);
|
65
|
}
|
66
|
|
67
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68
|
|
69
|
public void remove(int pos, int numEffects)
|
70
|
{
|
71
|
System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) );
|
72
|
mUBO.invalidate();
|
73
|
}
|
74
|
|
75
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
|
77
|
public void markForDeletion()
|
78
|
{
|
79
|
mUBO.markForDeletion();
|
80
|
}
|
81
|
|
82
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83
|
|
84
|
public void invalidate()
|
85
|
{
|
86
|
mUBO.invalidate();
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
|
91
|
public float[] getBackingArray()
|
92
|
{
|
93
|
return mArray;
|
94
|
}
|
95
|
|
96
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97
|
|
98
|
public void print(int num)
|
99
|
{
|
100
|
StringBuilder builder = new StringBuilder();
|
101
|
|
102
|
builder.append(mUBO.getID());
|
103
|
builder.append(':');
|
104
|
|
105
|
for(int i=0; i<6; i++)
|
106
|
{
|
107
|
builder.append(' ');
|
108
|
builder.append(mArray[4*i ]);
|
109
|
builder.append(' ');
|
110
|
builder.append(mArray[4*i+1]);
|
111
|
builder.append(' ');
|
112
|
builder.append(mArray[4*i+2]);
|
113
|
builder.append(',');
|
114
|
}
|
115
|
|
116
|
builder.append(' ');
|
117
|
builder.append('(');
|
118
|
builder.append(num);
|
119
|
builder.append(')');
|
120
|
|
121
|
String res = builder.toString();
|
122
|
|
123
|
android.util.Log.e("ubp", res);
|
124
|
}
|
125
|
}
|