Revision 61c6baa4
Added by Leszek Koltunski 6 months ago
| src/main/java/org/distorted/library/message/EffectListener.kt | ||
|---|---|---|
| 21 | 21 |
package org.distorted.library.message |
| 22 | 22 |
|
| 23 | 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 24 |
|
|
| 25 | 24 |
/** |
| 26 | 25 |
* This interface lets users of the DistortedLibrary library get notified when a given effect finishes. |
| 27 | 26 |
* To receive the notifications, we first have to register with a call to [Effect.notifyWhenFinished]. |
| src/main/java/org/distorted/library/program/DistortedProgram.kt | ||
|---|---|---|
| 78 | 78 |
if (attributes != null) |
| 79 | 79 |
{
|
| 80 | 80 |
val size = attributes.size |
| 81 |
|
|
| 82 |
for (i in 0..<size) |
|
| 83 |
GLES30.glBindAttribLocation(programHandle, i, attributes[i]) |
|
| 81 |
for (i in 0..<size) GLES30.glBindAttribLocation(programHandle, i, attributes[i]) |
|
| 84 | 82 |
} |
| 85 | 83 |
|
| 86 | 84 |
GLES30.glLinkProgram(programHandle) |
| src/main/java/org/distorted/library/uniformblock/UniformBlockAssociation.kt | ||
|---|---|---|
| 1 |
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 | 2 |
// Copyright 2020 Leszek Koltunski leszek@koltunski.pl // |
| 3 | 3 |
// // |
| 4 | 4 |
// This file is part of Distorted. // |
| ... | ... | |
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.uniformblock; |
|
| 22 |
|
|
| 23 |
import org.distorted.library.main.DistortedLibrary; |
|
| 24 |
import org.distorted.library.main.InternalBuffer; |
|
| 25 |
import org.distorted.library.mesh.MeshBase; |
|
| 21 |
package org.distorted.library.uniformblock |
|
| 26 | 22 |
|
| 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 28 |
/** |
|
| 29 |
* Not part of public API, do not document |
|
| 30 |
* |
|
| 31 |
* @y.exclude |
|
| 32 |
*/ |
|
| 33 |
public class UniformBlockAssociation |
|
| 34 |
{
|
|
| 35 |
private static final int DEFAULT_ASSOCIATION = 0x7fffffff; // all effects associated, all components affected |
|
| 36 |
private static final int DEFAULT_STRIDE = 4; |
|
| 37 |
private static final int LOC_AND = 0; |
|
| 38 |
private static final int LOC_EQU = 1; |
|
| 39 |
|
|
| 40 |
private final InternalBuffer mUBO; |
|
| 41 |
private final int mMax; |
|
| 42 |
private int[] mAssociations; |
|
| 43 |
private int mStride; |
|
| 23 |
import org.distorted.library.main.DistortedLibrary |
|
| 24 |
import org.distorted.library.main.InternalBuffer |
|
| 25 |
import org.distorted.library.mesh.MeshBase |
|
| 44 | 26 |
|
| 45 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 46 |
|
|
| 47 |
public UniformBlockAssociation() |
|
| 28 |
/** Not part of public API, do not document |
|
| 29 |
* |
|
| 30 |
* @y.exclude |
|
| 31 |
*/ |
|
| 32 |
class UniformBlockAssociation |
|
| 33 |
{
|
|
| 34 |
private val mUBO: InternalBuffer |
|
| 35 |
private val mMax: Int |
|
| 36 |
private var mAssociations: IntArray |
|
| 37 |
private var mStride: Int |
|
| 38 |
val index: Int get() = mUBO.createImmediatelyInt(4*mStride*mMax, mAssociations) |
|
| 39 |
|
|
| 40 |
companion object |
|
| 48 | 41 |
{
|
| 49 |
mMax = MeshBase.getMaxEffComponents(); |
|
| 50 |
mStride = DEFAULT_STRIDE; |
|
| 51 |
mAssociations= new int[mStride*mMax]; |
|
| 52 |
|
|
| 53 |
for(int i=0; i<mMax; i++) |
|
| 54 |
{
|
|
| 55 |
mAssociations[mStride*i+LOC_AND] = DEFAULT_ASSOCIATION; |
|
| 56 |
mAssociations[mStride*i+LOC_EQU] = i; |
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
mUBO = new InternalBuffer(); |
|
| 42 |
private const val DEFAULT_ASSOCIATION = 0x7fffffff // all effects associated, all components affected |
|
| 43 |
private const val DEFAULT_STRIDE = 4 |
|
| 44 |
private const val LOC_AND = 0 |
|
| 45 |
private const val LOC_EQU = 1 |
|
| 60 | 46 |
} |
| 61 | 47 |
|
| 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 63 |
|
|
| 64 |
public UniformBlockAssociation(UniformBlockAssociation original) |
|
| 48 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 49 |
constructor() |
|
| 65 | 50 |
{
|
| 66 |
mMax = original.mMax; |
|
| 67 |
mStride = original.mStride; |
|
| 68 |
int size = original.mAssociations.length; |
|
| 69 |
mAssociations= new int[size]; |
|
| 70 |
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size); |
|
| 51 |
mMax = MeshBase.getMaxEffComponents() |
|
| 52 |
mStride = DEFAULT_STRIDE |
|
| 53 |
mAssociations = IntArray(mStride*mMax) |
|
| 71 | 54 |
|
| 72 |
mUBO = new InternalBuffer(); |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
// stride can be 0, if we just tried compiling a vertex shader which has NUM_VERTEX=0. |
|
| 77 |
// stride==1 we also don't like because then we have an exception ( stride*mMax-1 < stride*(mMax-1)+1 ) |
|
| 78 |
|
|
| 79 |
public void correctStride(int stride) |
|
| 80 |
{
|
|
| 81 |
if( mStride != stride && stride>1 ) |
|
| 82 |
{
|
|
| 83 |
int[] tmp = new int[stride*mMax]; |
|
| 84 |
|
|
| 85 |
for(int i=0; i<mMax; i++) |
|
| 55 |
for (i in 0..<mMax) |
|
| 86 | 56 |
{
|
| 87 |
tmp[stride*i+LOC_AND] = mAssociations[mStride*i+LOC_AND];
|
|
| 88 |
tmp[stride*i+LOC_EQU] = mAssociations[mStride*i+LOC_EQU];
|
|
| 57 |
mAssociations[mStride*i+LOC_AND] = DEFAULT_ASSOCIATION
|
|
| 58 |
mAssociations[mStride*i+LOC_EQU] = i
|
|
| 89 | 59 |
} |
| 90 | 60 |
|
| 91 |
mAssociations = tmp; |
|
| 92 |
mStride = stride; |
|
| 93 |
} |
|
| 61 |
mUBO = InternalBuffer() |
|
| 94 | 62 |
} |
| 95 | 63 |
|
| 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 97 |
|
|
| 98 |
public boolean matchesAssociation( int comp, int andAssoc, int equAssoc) |
|
| 64 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 65 |
constructor(original: UniformBlockAssociation) |
|
| 99 | 66 |
{
|
| 100 |
return (andAssoc & mAssociations[mStride*comp+LOC_AND]) != 0 || (equAssoc == mAssociations[mStride*comp+LOC_EQU]); |
|
| 67 |
mMax = original.mMax |
|
| 68 |
mStride = original.mStride |
|
| 69 |
val size = original.mAssociations.size |
|
| 70 |
mAssociations = IntArray(size) |
|
| 71 |
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size) |
|
| 72 |
mUBO = InternalBuffer() |
|
| 101 | 73 |
} |
| 102 | 74 |
|
| 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 104 |
|
|
| 105 |
public void setEffectAssociationNow(int comp, int andAssociation, int equAssociation) |
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
// stride can be 0, if we just tried compiling a vertex shader which has NUM_VERTEX=0. |
|
| 77 |
// stride==1 we also don't like because then we have an exception ( stride*mMax-1 < stride*(mMax-1)+1 ) |
|
| 78 |
fun correctStride(stride: Int) |
|
| 106 | 79 |
{
|
| 107 |
int index = mStride*comp; |
|
| 108 |
mAssociations[index+LOC_AND] &= (~DEFAULT_ASSOCIATION); |
|
| 109 |
mAssociations[index+LOC_AND] += (andAssociation & DEFAULT_ASSOCIATION); |
|
| 110 |
mAssociations[index+LOC_EQU] = equAssociation; |
|
| 80 |
if (mStride!=stride && stride>1) |
|
| 81 |
{
|
|
| 82 |
val tmp = IntArray(stride*mMax) |
|
| 83 |
|
|
| 84 |
for (i in 0..<mMax) |
|
| 85 |
{
|
|
| 86 |
tmp[stride*i+LOC_AND] = mAssociations[mStride*i+LOC_AND] |
|
| 87 |
tmp[stride*i+LOC_EQU] = mAssociations[mStride*i+LOC_EQU] |
|
| 88 |
} |
|
| 111 | 89 |
|
| 112 |
mUBO.invalidate(); |
|
| 90 |
mAssociations = tmp |
|
| 91 |
mStride = stride |
|
| 92 |
} |
|
| 113 | 93 |
} |
| 114 | 94 |
|
| 115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 95 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 96 |
fun matchesAssociation(comp: Int, andAssoc: Int, equAssoc: Int): Boolean |
|
| 97 |
{
|
|
| 98 |
return (andAssoc and mAssociations[mStride*comp+LOC_AND]) != 0 || (equAssoc == mAssociations[mStride*comp+LOC_EQU]) |
|
| 99 |
} |
|
| 116 | 100 |
|
| 117 |
public void setNotAffectedComponentsNow(int[] components) |
|
| 101 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 102 |
fun setEffectAssociationNow(comp: Int, andAssociation: Int, equAssociation: Int) |
|
| 118 | 103 |
{
|
| 119 |
for(int c=0; c<mMax; c++) mAssociations[mStride*c+LOC_AND] &= DEFAULT_ASSOCIATION;
|
|
| 104 |
val index = mStride*comp
|
|
| 120 | 105 |
|
| 121 |
if( components!=null ) |
|
| 122 |
{
|
|
| 123 |
for(int c : components) mAssociations[mStride*c+LOC_AND] |= (~DEFAULT_ASSOCIATION); |
|
| 124 |
} |
|
| 106 |
mAssociations[index+LOC_AND] = mAssociations[index+LOC_AND] and (DEFAULT_ASSOCIATION.inv()) |
|
| 107 |
mAssociations[index+LOC_AND] += (andAssociation and DEFAULT_ASSOCIATION) |
|
| 108 |
mAssociations[index+LOC_EQU] = equAssociation |
|
| 125 | 109 |
|
| 126 |
mUBO.invalidate();
|
|
| 110 |
mUBO.invalidate()
|
|
| 127 | 111 |
} |
| 128 | 112 |
|
| 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 130 |
|
|
| 131 |
public int getIndex() |
|
| 113 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 114 |
fun setNotAffectedComponentsNow(components: IntArray?) |
|
| 132 | 115 |
{
|
| 133 |
return mUBO.createImmediatelyInt( 4*mStride*mMax, mAssociations);
|
|
| 134 |
}
|
|
| 116 |
for (c in 0..<mMax)
|
|
| 117 |
mAssociations[mStride*c+LOC_AND] = mAssociations[mStride*c+LOC_AND] and DEFAULT_ASSOCIATION
|
|
| 135 | 118 |
|
| 136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 119 |
if (components != null) |
|
| 120 |
for (c in components) |
|
| 121 |
mAssociations[mStride*c+LOC_AND] = mAssociations[mStride*c+LOC_AND] or (DEFAULT_ASSOCIATION.inv()) |
|
| 137 | 122 |
|
| 138 |
public void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom) |
|
| 139 |
{
|
|
| 140 |
mAssociations[mStride*compTo+LOC_AND] = assocFrom.mAssociations[mStride*compFrom+LOC_AND]; |
|
| 141 |
mAssociations[mStride*compTo+LOC_EQU] = assocFrom.mAssociations[mStride*compFrom+LOC_EQU]; |
|
| 123 |
mUBO.invalidate() |
|
| 142 | 124 |
} |
| 143 | 125 |
|
| 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 145 |
|
|
| 146 |
public void markForDeletion() |
|
| 126 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 127 |
fun copy(compTo: Int, assocFrom: UniformBlockAssociation, compFrom: Int) |
|
| 147 | 128 |
{
|
| 148 |
mUBO.markForDeletion(); |
|
| 129 |
mAssociations[mStride*compTo+LOC_AND] = assocFrom.mAssociations[mStride*compFrom+LOC_AND] |
|
| 130 |
mAssociations[mStride*compTo+LOC_EQU] = assocFrom.mAssociations[mStride*compFrom+LOC_EQU] |
|
| 149 | 131 |
} |
| 150 | 132 |
|
| 151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 133 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 134 |
fun markForDeletion() = mUBO.markForDeletion() |
|
| 152 | 135 |
|
| 153 |
public void print() |
|
| 136 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 137 |
fun print() |
|
| 154 | 138 |
{
|
| 155 |
StringBuilder builder = new StringBuilder();
|
|
| 139 |
val builder = StringBuilder()
|
|
| 156 | 140 |
|
| 157 |
builder.append(mUBO.getID());
|
|
| 158 |
builder.append(' ');
|
|
| 141 |
builder.append(mUBO.id)
|
|
| 142 |
builder.append(' ')
|
|
| 159 | 143 |
|
| 160 |
for(int i=0; i<8; i++)
|
|
| 161 |
{
|
|
| 162 |
builder.append(mAssociations[mStride*i+LOC_AND]);
|
|
| 163 |
builder.append(' ');
|
|
| 164 |
builder.append(mAssociations[mStride*i+LOC_EQU]);
|
|
| 165 |
builder.append(' ');
|
|
| 166 |
} |
|
| 144 |
for (i in 0..7)
|
|
| 145 |
{
|
|
| 146 |
builder.append(mAssociations[mStride*i+LOC_AND])
|
|
| 147 |
builder.append(' ')
|
|
| 148 |
builder.append(mAssociations[mStride*i+LOC_EQU])
|
|
| 149 |
builder.append(' ')
|
|
| 150 |
}
|
|
| 167 | 151 |
|
| 168 |
String res = builder.toString();
|
|
| 152 |
val res = builder.toString()
|
|
| 169 | 153 |
|
| 170 |
DistortedLibrary.logMessage("UniformBlockAssociation: "+res);
|
|
| 154 |
DistortedLibrary.logMessage("UniformBlockAssociation: $res")
|
|
| 171 | 155 |
} |
| 172 |
} |
|
| 156 |
} |
|
| src/main/java/org/distorted/library/uniformblock/UniformBlockCenter.kt | ||
|---|---|---|
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.uniformblock;
|
|
| 21 |
package org.distorted.library.uniformblock |
|
| 22 | 22 |
|
| 23 |
import org.distorted.library.main.InternalBuffer;
|
|
| 24 |
import org.distorted.library.mesh.MeshBase;
|
|
| 23 |
import org.distorted.library.main.InternalBuffer |
|
| 24 |
import org.distorted.library.mesh.MeshBase |
|
| 25 | 25 |
|
| 26 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 27 |
/** |
|
| 28 |
* Not part of public API, do not document |
|
| 29 |
* |
|
| 30 |
* @y.exclude |
|
| 31 |
*/ |
|
| 32 |
public class UniformBlockCenter |
|
| 33 |
{
|
|
| 34 |
private final InternalBuffer mUBO; |
|
| 35 |
private final float[] mArray; |
|
| 36 |
private final int mMax; |
|
| 37 |
|
|
| 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 39 |
|
|
| 40 |
public UniformBlockCenter() |
|
| 27 |
/** Not part of public API, do not document |
|
| 28 |
* |
|
| 29 |
* @y.exclude |
|
| 30 |
*/ |
|
| 31 |
class UniformBlockCenter |
|
| 32 |
{
|
|
| 33 |
private val mUBO: InternalBuffer |
|
| 34 |
private val mMax: Int |
|
| 35 |
val backingArray: FloatArray |
|
| 36 |
val index: Int get() = mUBO.createImmediatelyFloat(16*mMax, backingArray) |
|
| 37 |
|
|
| 38 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 39 |
constructor() |
|
| 41 | 40 |
{
|
| 42 |
mMax = MeshBase.getMaxEffComponents();
|
|
| 43 |
mArray= new float[4*mMax];
|
|
| 44 |
mUBO = new InternalBuffer();
|
|
| 41 |
mMax = MeshBase.getMaxEffComponents()
|
|
| 42 |
backingArray = FloatArray(4*mMax)
|
|
| 43 |
mUBO = InternalBuffer()
|
|
| 45 | 44 |
} |
| 46 | 45 |
|
| 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 48 |
|
|
| 49 |
public UniformBlockCenter(UniformBlockCenter original) |
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
constructor(original: UniformBlockCenter) |
|
| 50 | 48 |
{
|
| 51 |
mMax = original.mMax;
|
|
| 52 |
int size = original.mArray.length;
|
|
| 53 |
mArray= new float[size];
|
|
| 54 |
System.arraycopy(original.mArray, 0, mArray, 0, size);
|
|
| 55 |
mUBO = new InternalBuffer();
|
|
| 49 |
mMax = original.mMax
|
|
| 50 |
val size = original.backingArray.size
|
|
| 51 |
backingArray = FloatArray(size)
|
|
| 52 |
System.arraycopy(original.backingArray, 0, backingArray, 0, size)
|
|
| 53 |
mUBO = InternalBuffer()
|
|
| 56 | 54 |
} |
| 57 | 55 |
|
| 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 59 |
|
|
| 60 |
public void setEffectCenterNow(int comp, float x, float y, float z) |
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
fun setEffectCenterNow(comp: Int, x: Float, y: Float, z: Float) |
|
| 61 | 58 |
{
|
| 62 |
if( comp>=0 ) |
|
| 63 |
{
|
|
| 64 |
mArray[4*comp ] = x; |
|
| 65 |
mArray[4*comp+1] = y; |
|
| 66 |
mArray[4*comp+2] = z; |
|
| 67 |
} |
|
| 68 |
else |
|
| 69 |
{
|
|
| 70 |
for(int i=0; i<mMax; i++) |
|
| 59 |
if (comp >= 0) |
|
| 71 | 60 |
{
|
| 72 |
mArray[4*i ] = x; |
|
| 73 |
mArray[4*i+1] = y; |
|
| 74 |
mArray[4*i+2] = z; |
|
| 61 |
backingArray[4*comp ] = x |
|
| 62 |
backingArray[4*comp+1] = y |
|
| 63 |
backingArray[4*comp+2] = z |
|
| 64 |
} |
|
| 65 |
else |
|
| 66 |
{
|
|
| 67 |
for (i in 0..<mMax) |
|
| 68 |
{
|
|
| 69 |
backingArray[4*i ] = x |
|
| 70 |
backingArray[4*i+1] = y |
|
| 71 |
backingArray[4*i+2] = z |
|
| 72 |
} |
|
| 75 | 73 |
} |
| 76 |
} |
|
| 77 |
|
|
| 78 |
mUBO.invalidate(); |
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 82 |
|
|
| 83 |
public int getIndex() |
|
| 84 |
{
|
|
| 85 |
return mUBO.createImmediatelyFloat( 16*mMax, mArray); |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 89 | 74 |
|
| 90 |
public void copy(int compTo, UniformBlockCenter blockFrom, int compFrom) |
|
| 91 |
{
|
|
| 92 |
mArray[4*compTo ] = blockFrom.mArray[4*compFrom ]; |
|
| 93 |
mArray[4*compTo+1] = blockFrom.mArray[4*compFrom+1]; |
|
| 94 |
mArray[4*compTo+2] = blockFrom.mArray[4*compFrom+2]; |
|
| 75 |
mUBO.invalidate() |
|
| 95 | 76 |
} |
| 96 | 77 |
|
| 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 98 |
|
|
| 99 |
public void markForDeletion() |
|
| 78 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 79 |
fun copy(compTo: Int, blockFrom: UniformBlockCenter, compFrom: Int) |
|
| 100 | 80 |
{
|
| 101 |
mUBO.markForDeletion(); |
|
| 81 |
backingArray[4*compTo ] = blockFrom.backingArray[4*compFrom ] |
|
| 82 |
backingArray[4*compTo+1] = blockFrom.backingArray[4*compFrom+1] |
|
| 83 |
backingArray[4*compTo+2] = blockFrom.backingArray[4*compFrom+2] |
|
| 102 | 84 |
} |
| 103 | 85 |
|
| 104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 105 |
|
|
| 106 |
public float[] getBackingArray() |
|
| 107 |
{
|
|
| 108 |
return mArray; |
|
| 109 |
} |
|
| 110 |
} |
|
| 86 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 87 |
fun markForDeletion() = mUBO.markForDeletion() |
|
| 88 |
} |
|
| src/main/java/org/distorted/library/uniformblock/UniformBlockFloatUniforms.kt | ||
|---|---|---|
| 1 | 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 |
// Copyright 2021 Leszek Koltunski leszek@koltunski.pl //
|
|
| 2 |
// Copyright 2020 Leszek Koltunski leszek@koltunski.pl //
|
|
| 3 | 3 |
// // |
| 4 | 4 |
// This file is part of Distorted. // |
| 5 | 5 |
// // |
| ... | ... | |
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.uniformblock;
|
|
| 21 |
package org.distorted.library.uniformblock |
|
| 22 | 22 |
|
| 23 |
import org.distorted.library.main.DistortedLibrary;
|
|
| 24 |
import org.distorted.library.main.InternalBuffer;
|
|
| 23 |
import org.distorted.library.main.DistortedLibrary |
|
| 24 |
import org.distorted.library.main.InternalBuffer |
|
| 25 | 25 |
|
| 26 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 27 |
|
|
| 28 |
/** |
|
| 29 |
* Not part of public API, do not document |
|
| 30 |
* |
|
| 31 |
* @y.exclude |
|
| 32 |
*/ |
|
| 33 |
public class UniformBlockFloatUniforms |
|
| 34 |
{
|
|
| 35 |
private InternalBuffer mUBO; |
|
| 36 |
private final float[] mArray; |
|
| 37 |
private final int mNumUniforms, mSize; |
|
| 38 |
private final boolean mReallyUseUBO; |
|
| 39 |
|
|
| 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 41 |
|
|
| 42 |
public UniformBlockFloatUniforms(int numUniforms, int size, boolean reallyUse) |
|
| 27 |
/** Not part of public API, do not document |
|
| 28 |
* |
|
| 29 |
* @y.exclude |
|
| 30 |
*/ |
|
| 31 |
class UniformBlockFloatUniforms |
|
| 32 |
{
|
|
| 33 |
private var mUBO: InternalBuffer? = null |
|
| 34 |
val backingArray: FloatArray |
|
| 35 |
private val mNumUniforms: Int |
|
| 36 |
private val mSize: Int |
|
| 37 |
private val mReallyUseUBO: Boolean |
|
| 38 |
val index: Int get() = mUBO!!.createImmediatelyFloat(4*mNumUniforms*mSize, backingArray) |
|
| 39 |
|
|
| 40 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 41 |
constructor(numUniforms: Int, size: Int, reallyUse: Boolean) |
|
| 43 | 42 |
{
|
| 44 |
mNumUniforms = numUniforms; |
|
| 45 |
mSize = size; |
|
| 46 |
mArray = new float[mNumUniforms*mSize]; |
|
| 47 |
mReallyUseUBO= reallyUse; |
|
| 48 |
|
|
| 49 |
if( mReallyUseUBO ) |
|
| 50 |
{
|
|
| 51 |
mUBO = new InternalBuffer(); |
|
| 52 |
} |
|
| 43 |
mNumUniforms = numUniforms |
|
| 44 |
mSize = size |
|
| 45 |
backingArray = FloatArray(mNumUniforms*mSize) |
|
| 46 |
mReallyUseUBO = reallyUse |
|
| 47 |
if (mReallyUseUBO) mUBO = InternalBuffer() |
|
| 53 | 48 |
} |
| 54 | 49 |
|
| 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 56 |
|
|
| 57 |
public UniformBlockFloatUniforms(UniformBlockFloatUniforms original) |
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
constructor(original: UniformBlockFloatUniforms) |
|
| 58 | 52 |
{
|
| 59 |
mNumUniforms = original.mNumUniforms; |
|
| 60 |
mSize = original.mSize; |
|
| 61 |
mArray = new float[mNumUniforms*mSize]; |
|
| 62 |
mReallyUseUBO= original.mReallyUseUBO; |
|
| 63 |
|
|
| 64 |
System.arraycopy(original.mArray, 0, mArray, 0, 3*mSize); |
|
| 65 |
|
|
| 66 |
if( mReallyUseUBO ) |
|
| 67 |
{
|
|
| 68 |
mUBO = new InternalBuffer(); |
|
| 69 |
} |
|
| 53 |
mNumUniforms = original.mNumUniforms |
|
| 54 |
mSize = original.mSize |
|
| 55 |
backingArray = FloatArray(mNumUniforms*mSize) |
|
| 56 |
mReallyUseUBO = original.mReallyUseUBO |
|
| 57 |
System.arraycopy(original.backingArray, 0, backingArray, 0, 3 * mSize) |
|
| 58 |
if (mReallyUseUBO) mUBO = InternalBuffer() |
|
| 70 | 59 |
} |
| 71 | 60 |
|
| 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 73 |
|
|
| 74 |
public int getIndex() |
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 |
fun remove(pos: Int, numEffects: Int) |
|
| 75 | 63 |
{
|
| 76 |
return mUBO.createImmediatelyFloat( 4*mNumUniforms*mSize, mArray); |
|
| 64 |
System.arraycopy( backingArray, mNumUniforms*(pos+1), backingArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) ) |
|
| 65 |
if (mReallyUseUBO) mUBO!!.invalidate() |
|
| 77 | 66 |
} |
| 78 | 67 |
|
| 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 80 |
|
|
| 81 |
public void remove(int pos, int numEffects) |
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
fun markForDeletion() |
|
| 82 | 70 |
{
|
| 83 |
System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) ); |
|
| 84 |
|
|
| 85 |
if( mReallyUseUBO ) |
|
| 86 |
{
|
|
| 87 |
mUBO.invalidate(); |
|
| 88 |
} |
|
| 71 |
if (mReallyUseUBO) mUBO!!.markForDeletion() |
|
| 89 | 72 |
} |
| 90 | 73 |
|
| 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 92 |
|
|
| 93 |
public void markForDeletion() |
|
| 74 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 75 |
fun invalidate() |
|
| 94 | 76 |
{
|
| 95 |
if( mReallyUseUBO ) |
|
| 96 |
{
|
|
| 97 |
mUBO.markForDeletion(); |
|
| 98 |
} |
|
| 77 |
if (mReallyUseUBO) mUBO!!.invalidate() |
|
| 99 | 78 |
} |
| 100 | 79 |
|
| 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 102 |
|
|
| 103 |
public void invalidate() |
|
| 104 |
{
|
|
| 105 |
if( mReallyUseUBO ) |
|
| 106 |
{
|
|
| 107 |
mUBO.invalidate(); |
|
| 108 |
} |
|
| 109 |
} |
|
| 110 |
|
|
| 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 112 |
|
|
| 113 |
public float[] getBackingArray() |
|
| 114 |
{
|
|
| 115 |
return mArray; |
|
| 116 |
} |
|
| 117 |
|
|
| 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 119 |
|
|
| 120 |
public void print(int num) |
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
fun print(num: Int) |
|
| 121 | 82 |
{
|
| 122 |
StringBuilder builder = new StringBuilder();
|
|
| 123 |
|
|
| 124 |
builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED");
|
|
| 125 |
builder.append(':');
|
|
| 126 |
|
|
| 127 |
for(int i=0; i<6; i++)
|
|
| 128 |
{
|
|
| 129 |
builder.append(' ');
|
|
| 130 |
builder.append(mArray[4*i ]);
|
|
| 131 |
builder.append(' ');
|
|
| 132 |
builder.append(mArray[4*i+1]);
|
|
| 133 |
builder.append(' ');
|
|
| 134 |
builder.append(mArray[4*i+2]);
|
|
| 135 |
builder.append(',');
|
|
| 136 |
} |
|
| 137 |
|
|
| 138 |
builder.append(' ');
|
|
| 139 |
builder.append('(');
|
|
| 140 |
builder.append(num);
|
|
| 141 |
builder.append(')');
|
|
| 142 |
|
|
| 143 |
String res = builder.toString();
|
|
| 144 |
|
|
| 145 |
DistortedLibrary.logMessage("UniformBlockFloatUniforms: "+res);
|
|
| 83 |
val builder = StringBuilder()
|
|
| 84 |
|
|
| 85 |
builder.append(if (mReallyUseUBO) mUBO!!.id else "NOT USED")
|
|
| 86 |
builder.append(':')
|
|
| 87 |
|
|
| 88 |
for (i in 0..5)
|
|
| 89 |
{
|
|
| 90 |
builder.append(' ')
|
|
| 91 |
builder.append(backingArray[4*i])
|
|
| 92 |
builder.append(' ')
|
|
| 93 |
builder.append(backingArray[4*i+1])
|
|
| 94 |
builder.append(' ')
|
|
| 95 |
builder.append(backingArray[4*i+2])
|
|
| 96 |
builder.append(',')
|
|
| 97 |
}
|
|
| 98 |
|
|
| 99 |
builder.append(' ')
|
|
| 100 |
builder.append('(')
|
|
| 101 |
builder.append(num)
|
|
| 102 |
builder.append(')')
|
|
| 103 |
|
|
| 104 |
val res = builder.toString()
|
|
| 105 |
|
|
| 106 |
DistortedLibrary.logMessage("UniformBlockFloatUniforms: $res")
|
|
| 146 | 107 |
} |
| 147 |
} |
|
| 108 |
} |
|
| src/main/java/org/distorted/library/uniformblock/UniformBlockIntUniforms.kt | ||
|---|---|---|
| 18 | 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
| 19 | 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
|
| 21 |
package org.distorted.library.uniformblock;
|
|
| 21 |
package org.distorted.library.uniformblock |
|
| 22 | 22 |
|
| 23 |
import org.distorted.library.effect.Effect;
|
|
| 24 |
import org.distorted.library.main.DistortedLibrary;
|
|
| 25 |
import org.distorted.library.main.InternalBuffer;
|
|
| 23 |
import org.distorted.library.effect.Effect |
|
| 24 |
import org.distorted.library.main.DistortedLibrary |
|
| 25 |
import org.distorted.library.main.InternalBuffer |
|
| 26 | 26 |
|
| 27 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 |
/** |
|
| 29 |
* Not part of public API, do not document
|
|
| 30 |
*
|
|
| 31 |
* @y.exclude
|
|
| 32 |
*/
|
|
| 33 |
public class UniformBlockIntUniforms
|
|
| 34 |
{
|
|
| 35 |
private InternalBuffer mUBO;
|
|
| 36 |
private final int[] mArray;
|
|
| 37 |
private final int mNumUniforms, mSize;
|
|
| 38 |
private final boolean mReallyUseUBO;
|
|
| 39 |
|
|
| 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 41 |
|
|
| 42 |
public UniformBlockIntUniforms(int numUniforms, int size, boolean reallyUse)
|
|
| 28 |
/** Not part of public API, do not document
|
|
| 29 |
*
|
|
| 30 |
* @y.exclude
|
|
| 31 |
*/
|
|
| 32 |
class UniformBlockIntUniforms
|
|
| 33 |
{
|
|
| 34 |
private var mUBO: InternalBuffer? = null
|
|
| 35 |
val backingArray: IntArray
|
|
| 36 |
private val mNumUniforms: Int
|
|
| 37 |
private val mSize: Int
|
|
| 38 |
private val mReallyUseUBO: Boolean
|
|
| 39 |
val index: Int get() = mUBO!!.createImmediatelyInt(4*mNumUniforms*mSize, backingArray) |
|
| 40 |
|
|
| 41 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 42 |
constructor(numUniforms: Int, size: Int, reallyUse: Boolean)
|
|
| 43 | 43 |
{
|
| 44 |
mNumUniforms = numUniforms; |
|
| 45 |
mSize = size; |
|
| 46 |
mArray = new int[mNumUniforms*mSize]; |
|
| 47 |
mReallyUseUBO= reallyUse; |
|
| 48 |
|
|
| 49 |
if( mReallyUseUBO ) |
|
| 50 |
{
|
|
| 51 |
mUBO = new InternalBuffer(); |
|
| 52 |
} |
|
| 44 |
mNumUniforms = numUniforms |
|
| 45 |
mSize = size |
|
| 46 |
backingArray = IntArray(mNumUniforms * mSize) |
|
| 47 |
mReallyUseUBO = reallyUse |
|
| 48 |
if (mReallyUseUBO) mUBO = InternalBuffer() |
|
| 53 | 49 |
} |
| 54 | 50 |
|
| 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 56 |
|
|
| 57 |
public UniformBlockIntUniforms(UniformBlockIntUniforms original) |
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 52 |
constructor(original: UniformBlockIntUniforms) |
|
| 58 | 53 |
{
|
| 59 |
mNumUniforms = original.mNumUniforms; |
|
| 60 |
mSize = original.mSize; |
|
| 61 |
mArray = new int[mNumUniforms*mSize]; |
|
| 62 |
mReallyUseUBO= original.mReallyUseUBO; |
|
| 63 |
|
|
| 64 |
System.arraycopy(original.mArray, 0, mArray, 0, mSize); |
|
| 65 |
|
|
| 66 |
if( mReallyUseUBO ) |
|
| 67 |
{
|
|
| 68 |
mUBO = new InternalBuffer(); |
|
| 69 |
} |
|
| 54 |
mNumUniforms = original.mNumUniforms |
|
| 55 |
mSize = original.mSize |
|
| 56 |
backingArray = IntArray(mNumUniforms * mSize) |
|
| 57 |
mReallyUseUBO = original.mReallyUseUBO |
|
| 58 |
System.arraycopy(original.backingArray, 0, backingArray, 0, mSize) |
|
| 59 |
if (mReallyUseUBO) mUBO = InternalBuffer() |
|
| 70 | 60 |
} |
| 71 | 61 |
|
| 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 73 |
|
|
| 74 |
public int getIndex() |
|
| 62 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 63 |
fun remove(pos: Int, numEffects: Int) |
|
| 75 | 64 |
{
|
| 76 |
return mUBO.createImmediatelyInt( 4*mNumUniforms*mSize, mArray); |
|
| 65 |
System.arraycopy(backingArray, mNumUniforms*(pos+1), backingArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) ) |
|
| 66 |
if (mReallyUseUBO) mUBO!!.invalidate() |
|
| 77 | 67 |
} |
| 78 | 68 |
|
| 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 80 |
|
|
| 81 |
public void remove(int pos, int numEffects) |
|
| 69 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 70 |
fun makeHole(pos: Int, numEffects: Int) |
|
| 82 | 71 |
{
|
| 83 |
System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) ); |
|
| 84 |
|
|
| 85 |
if( mReallyUseUBO ) |
|
| 86 |
{
|
|
| 87 |
mUBO.invalidate(); |
|
| 88 |
} |
|
| 72 |
System.arraycopy( backingArray, mNumUniforms*pos, backingArray, mNumUniforms*(pos+1), mNumUniforms*(numEffects-pos) ) |
|
| 73 |
if (mReallyUseUBO) mUBO!!.invalidate() |
|
| 89 | 74 |
} |
| 90 | 75 |
|
| 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 92 |
|
|
| 93 |
public void makeHole(int pos, int numEffects) |
|
| 76 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 77 |
fun addOrdinal(pos: Int, ordinal: Int) |
|
| 94 | 78 |
{
|
| 95 |
System.arraycopy(mArray, mNumUniforms*pos, mArray, mNumUniforms*(pos+1), mNumUniforms*(numEffects-pos) ); |
|
| 96 |
|
|
| 97 |
if( mReallyUseUBO ) |
|
| 98 |
{
|
|
| 99 |
mUBO.invalidate(); |
|
| 100 |
} |
|
| 79 |
backingArray[mNumUniforms*pos] = ordinal |
|
| 80 |
if (mReallyUseUBO) mUBO!!.invalidate() |
|
| 101 | 81 |
} |
| 102 | 82 |
|
| 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 104 |
|
|
| 105 |
public void addOrdinal(int pos, int ordinal) |
|
| 83 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 84 |
fun addAssociations(pos: Int, effect: Effect) |
|
| 106 | 85 |
{
|
| 107 |
mArray[mNumUniforms*pos] = ordinal; |
|
| 108 |
|
|
| 109 |
if( mReallyUseUBO ) |
|
| 110 |
{
|
|
| 111 |
mUBO.invalidate(); |
|
| 112 |
} |
|
| 113 |
} |
|
| 114 |
|
|
| 115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 116 |
|
|
| 117 |
public void addAssociations(int pos, Effect effect) |
|
| 118 |
{
|
|
| 119 |
effect.writeAssociations(mArray, mNumUniforms*pos+1, mNumUniforms*pos+3); |
|
| 120 |
|
|
| 121 |
if( mReallyUseUBO ) |
|
| 122 |
{
|
|
| 123 |
mUBO.invalidate(); |
|
| 124 |
} |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
|
|
| 129 |
public void markForDeletion() |
|
| 130 |
{
|
|
| 131 |
if( mReallyUseUBO ) |
|
| 132 |
{
|
|
| 133 |
mUBO.markForDeletion(); |
|
| 134 |
} |
|
| 86 |
effect.writeAssociations(backingArray, mNumUniforms*pos+1, mNumUniforms*pos+3) |
|
| 87 |
if (mReallyUseUBO) mUBO!!.invalidate() |
|
| 135 | 88 |
} |
| 136 | 89 |
|
| 137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 138 |
|
|
| 139 |
public int[] getBackingArray() |
|
| 90 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 91 |
fun markForDeletion() |
|
| 140 | 92 |
{
|
| 141 |
return mArray;
|
|
| 93 |
if (mReallyUseUBO) mUBO!!.markForDeletion()
|
|
| 142 | 94 |
} |
| 143 | 95 |
|
| 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 145 |
|
|
| 146 |
public void print(int num) |
|
| 96 |
/////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 97 |
fun print(num: Int) |
|
| 147 | 98 |
{
|
| 148 |
StringBuilder builder = new StringBuilder();
|
|
| 149 |
|
|
| 150 |
builder.append( mReallyUseUBO ? mUBO.getID() : "NOT USED");
|
|
| 151 |
builder.append(':');
|
|
| 152 |
|
|
| 153 |
for(int i=0; i<6; i++)
|
|
| 154 |
{
|
|
| 155 |
builder.append(' ');
|
|
| 156 |
builder.append(mArray[4*i ]);
|
|
| 157 |
builder.append(' ');
|
|
| 158 |
builder.append(mArray[4*i+1]);
|
|
| 159 |
builder.append(' ');
|
|
| 160 |
builder.append(mArray[4*i+2]);
|
|
| 161 |
builder.append(',');
|
|
| 162 |
} |
|
| 163 |
|
|
| 164 |
builder.append(' ');
|
|
| 165 |
builder.append('(');
|
|
| 166 |
builder.append(num);
|
|
| 167 |
builder.append(')');
|
|
| 168 |
|
|
| 169 |
String res = builder.toString();
|
|
| 170 |
|
|
| 171 |
DistortedLibrary.logMessage("UniformBlockIntUniforms: "+res);
|
|
| 99 |
val builder = StringBuilder()
|
|
| 100 |
|
|
| 101 |
builder.append(if (mReallyUseUBO) mUBO!!.id else "NOT USED")
|
|
| 102 |
builder.append(':')
|
|
| 103 |
|
|
| 104 |
for (i in 0..5)
|
|
| 105 |
{
|
|
| 106 |
builder.append(' ')
|
|
| 107 |
builder.append(backingArray[4*i])
|
|
| 108 |
builder.append(' ')
|
|
| 109 |
builder.append(backingArray[4*i+1])
|
|
| 110 |
builder.append(' ')
|
|
| 111 |
builder.append(backingArray[4*i+2])
|
|
| 112 |
builder.append(',')
|
|
| 113 |
}
|
|
| 114 |
|
|
| 115 |
builder.append(' ')
|
|
| 116 |
builder.append('(')
|
|
| 117 |
builder.append(num)
|
|
| 118 |
builder.append(')')
|
|
| 119 |
|
|
| 120 |
val res = builder.toString()
|
|
| 121 |
|
|
| 122 |
DistortedLibrary.logMessage("UniformBlockIntUniforms: $res")
|
|
| 172 | 123 |
} |
| 173 |
} |
|
| 124 |
} |
|
Also available in: Unified diff
transition the 'uniformblock' package