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.mesh;
|
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
|
class UniformBlockCenter
|
31
|
{
|
32
|
private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;
|
33
|
|
34
|
private InternalBuffer mUBO;
|
35
|
private float[] mCenter;
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
|
39
|
UniformBlockCenter()
|
40
|
{
|
41
|
mCenter= new float[BLOCK_SIZE/4];
|
42
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
|
43
|
}
|
44
|
|
45
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46
|
|
47
|
UniformBlockCenter(UniformBlockCenter original)
|
48
|
{
|
49
|
int size = original.mCenter.length;
|
50
|
mCenter= new float[size];
|
51
|
System.arraycopy(original.mCenter, 0, mCenter, 0, size);
|
52
|
|
53
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
|
54
|
}
|
55
|
|
56
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57
|
|
58
|
void setEffectCenterNow(int comp, float x, float y, float z)
|
59
|
{
|
60
|
mCenter[4*comp ] = x;
|
61
|
mCenter[4*comp+1] = y;
|
62
|
mCenter[4*comp+2] = z;
|
63
|
|
64
|
mUBO.invalidate();
|
65
|
}
|
66
|
|
67
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68
|
|
69
|
int getIndex()
|
70
|
{
|
71
|
return mUBO.createImmediatelyFloat( BLOCK_SIZE, mCenter);
|
72
|
}
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
void copy(int compTo, UniformBlockCenter blockFrom, int compFrom)
|
77
|
{
|
78
|
mCenter[4*compTo ] = blockFrom.mCenter[4*compFrom ];
|
79
|
mCenter[4*compTo+1] = blockFrom.mCenter[4*compFrom+1];
|
80
|
mCenter[4*compTo+2] = blockFrom.mCenter[4*compFrom+2];
|
81
|
}
|
82
|
|
83
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84
|
|
85
|
float[] getBackingArray()
|
86
|
{
|
87
|
return mCenter;
|
88
|
}
|
89
|
}
|