1 |
97755c02
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
12c2cfcf
|
Leszek Koltunski
|
// Copyright 2020 Leszek Koltunski leszek@koltunski.pl //
|
3 |
97755c02
|
Leszek Koltunski
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
12c2cfcf
|
Leszek Koltunski
|
// 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 |
97755c02
|
Leszek Koltunski
|
// //
|
11 |
12c2cfcf
|
Leszek Koltunski
|
// This library is distributed in the hope that it will be useful, //
|
12 |
97755c02
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
12c2cfcf
|
Leszek Koltunski
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
|
14 |
|
|
// Lesser General Public License for more details. //
|
15 |
97755c02
|
Leszek Koltunski
|
// //
|
16 |
12c2cfcf
|
Leszek Koltunski
|
// 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 |
97755c02
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20 |
|
|
|
21 |
de77a6c5
|
Leszek Koltunski
|
package org.distorted.library.uniformblock;
|
22 |
97755c02
|
Leszek Koltunski
|
|
23 |
|
|
import android.opengl.GLES30;
|
24 |
|
|
|
25 |
|
|
import org.distorted.library.main.InternalBuffer;
|
26 |
7958d843
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshBase;
|
27 |
97755c02
|
Leszek Koltunski
|
|
28 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29 |
de77a6c5
|
Leszek Koltunski
|
/**
|
30 |
|
|
* Not part of public API, do not document
|
31 |
|
|
*
|
32 |
|
|
* @y.exclude
|
33 |
|
|
*/
|
34 |
|
|
public class UniformBlockCenter
|
35 |
97755c02
|
Leszek Koltunski
|
{
|
36 |
78ff6ea9
|
Leszek Koltunski
|
private final InternalBuffer mUBO;
|
37 |
de77a6c5
|
Leszek Koltunski
|
private final float[] mArray;
|
38 |
7958d843
|
Leszek Koltunski
|
private final int mMax;
|
39 |
97755c02
|
Leszek Koltunski
|
|
40 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41 |
41b3ada0
|
Leszek Koltunski
|
|
42 |
de77a6c5
|
Leszek Koltunski
|
public UniformBlockCenter()
|
43 |
97755c02
|
Leszek Koltunski
|
{
|
44 |
7958d843
|
Leszek Koltunski
|
mMax = MeshBase.getMaxEffComponents();
|
45 |
|
|
mArray= new float[4*mMax];
|
46 |
73bcf555
|
Leszek Koltunski
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
|
47 |
97755c02
|
Leszek Koltunski
|
}
|
48 |
|
|
|
49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
de77a6c5
|
Leszek Koltunski
|
public UniformBlockCenter(UniformBlockCenter original)
|
52 |
97755c02
|
Leszek Koltunski
|
{
|
53 |
7958d843
|
Leszek Koltunski
|
mMax = original.mMax;
|
54 |
de77a6c5
|
Leszek Koltunski
|
int size = original.mArray.length;
|
55 |
|
|
mArray= new float[size];
|
56 |
|
|
System.arraycopy(original.mArray, 0, mArray, 0, size);
|
57 |
73bcf555
|
Leszek Koltunski
|
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_DRAW);
|
58 |
97755c02
|
Leszek Koltunski
|
}
|
59 |
|
|
|
60 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61 |
|
|
|
62 |
de77a6c5
|
Leszek Koltunski
|
public void setEffectCenterNow(int comp, float x, float y, float z)
|
63 |
7a9edb92
|
Leszek Koltunski
|
{
|
64 |
06ed13b5
|
Leszek Koltunski
|
if( comp>=0 )
|
65 |
|
|
{
|
66 |
|
|
mArray[4*comp ] = x;
|
67 |
|
|
mArray[4*comp+1] = y;
|
68 |
|
|
mArray[4*comp+2] = z;
|
69 |
|
|
}
|
70 |
|
|
else
|
71 |
|
|
{
|
72 |
|
|
for(int i=0; i<mMax; i++)
|
73 |
|
|
{
|
74 |
|
|
mArray[4*i ] = x;
|
75 |
|
|
mArray[4*i+1] = y;
|
76 |
|
|
mArray[4*i+2] = z;
|
77 |
|
|
}
|
78 |
|
|
}
|
79 |
97755c02
|
Leszek Koltunski
|
|
80 |
7a9edb92
|
Leszek Koltunski
|
mUBO.invalidate();
|
81 |
|
|
}
|
82 |
97755c02
|
Leszek Koltunski
|
|
83 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
84 |
|
|
|
85 |
de77a6c5
|
Leszek Koltunski
|
public int getIndex()
|
86 |
7a9edb92
|
Leszek Koltunski
|
{
|
87 |
7958d843
|
Leszek Koltunski
|
return mUBO.createImmediatelyFloat( 16*mMax, mArray);
|
88 |
7a9edb92
|
Leszek Koltunski
|
}
|
89 |
97755c02
|
Leszek Koltunski
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
de77a6c5
|
Leszek Koltunski
|
public void copy(int compTo, UniformBlockCenter blockFrom, int compFrom)
|
93 |
7a9edb92
|
Leszek Koltunski
|
{
|
94 |
de77a6c5
|
Leszek Koltunski
|
mArray[4*compTo ] = blockFrom.mArray[4*compFrom ];
|
95 |
|
|
mArray[4*compTo+1] = blockFrom.mArray[4*compFrom+1];
|
96 |
|
|
mArray[4*compTo+2] = blockFrom.mArray[4*compFrom+2];
|
97 |
7a9edb92
|
Leszek Koltunski
|
}
|
98 |
|
|
|
99 |
8b36dabf
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100 |
|
|
|
101 |
de77a6c5
|
Leszek Koltunski
|
public void markForDeletion()
|
102 |
8b36dabf
|
Leszek Koltunski
|
{
|
103 |
|
|
mUBO.markForDeletion();
|
104 |
|
|
}
|
105 |
|
|
|
106 |
7a9edb92
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107 |
|
|
|
108 |
de77a6c5
|
Leszek Koltunski
|
public float[] getBackingArray()
|
109 |
7a9edb92
|
Leszek Koltunski
|
{
|
110 |
de77a6c5
|
Leszek Koltunski
|
return mArray;
|
111 |
7a9edb92
|
Leszek Koltunski
|
}
|
112 |
97755c02
|
Leszek Koltunski
|
}
|