Revision 0bd9f644
Added by Leszek Koltunski about 5 years ago
| src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java | ||
|---|---|---|
| 56 | 56 |
private static DistortedProgram mPreProgram; |
| 57 | 57 |
private static int mPreColorH; |
| 58 | 58 |
private static int mPreTextureH; |
| 59 |
private static int mPreProgramH; |
|
| 59 | 60 |
|
| 60 | 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 61 | 62 |
|
| ... | ... | |
| 139 | 140 |
throw new RuntimeException(e.getMessage()); |
| 140 | 141 |
} |
| 141 | 142 |
|
| 142 |
int preProgramH = mPreProgram.getProgramHandle(); |
|
| 143 |
EffectQueueVertex.getUniforms( preProgramH,2 ); |
|
| 144 |
EffectQueueMatrix.getUniforms( preProgramH,2 ); |
|
| 145 |
MeshBase.getUniforms(preProgramH,2); |
|
| 146 |
mPreColorH = GLES30.glGetUniformLocation( preProgramH, "u_Color" ); |
|
| 147 |
mPreTextureH= GLES30.glGetUniformLocation( preProgramH, "u_Texture"); |
|
| 143 |
mPreProgramH = mPreProgram.getProgramHandle(); |
|
| 144 |
EffectQueueVertex.getUniforms( mPreProgramH,2 ); |
|
| 145 |
EffectQueueMatrix.getUniforms( mPreProgramH,2 ); |
|
| 146 |
mPreColorH = GLES30.glGetUniformLocation( mPreProgramH, "u_Color" ); |
|
| 147 |
mPreTextureH= GLES30.glGetUniformLocation( mPreProgramH, "u_Texture"); |
|
| 148 | 148 |
} |
| 149 | 149 |
|
| 150 | 150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 181 | 181 |
mPreProgram.useProgram(); |
| 182 | 182 |
|
| 183 | 183 |
mesh.bindVertexAttribs(mPreProgram); |
| 184 |
mesh.send(2);
|
|
| 184 |
mesh.send(mPreProgramH);
|
|
| 185 | 185 |
|
| 186 | 186 |
EffectQueue[] queues = effects.getQueues(); |
| 187 | 187 |
EffectQueueMatrix matrix = (EffectQueueMatrix)queues[0]; |
| src/main/java/org/distorted/library/main/DistortedLibrary.java | ||
|---|---|---|
| 158 | 158 |
private static int mBlitDepthDepthH; |
| 159 | 159 |
private static int mBlitDepthTexCorrH; |
| 160 | 160 |
|
| 161 |
/// Program Handles /// |
|
| 162 |
private static int mMainProgramH, mFullProgramH, mMainOITProgramH; |
|
| 163 |
|
|
| 161 | 164 |
/// OIT SSBO BUFFER /// |
| 162 | 165 |
private static int[] mLinkedListSSBO = new int[1]; |
| 163 | 166 |
private static int[] mAtomicCounter; |
| ... | ... | |
| 259 | 262 |
throw new RuntimeException(e.getMessage()); |
| 260 | 263 |
} |
| 261 | 264 |
|
| 262 |
int mainProgramH = mMainProgram.getProgramHandle(); |
|
| 263 |
EffectQueue.getUniforms(mainProgramH,0); |
|
| 264 |
MeshBase.getUniforms(mainProgramH,0); |
|
| 265 |
mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture"); |
|
| 266 |
mTransformFeedbackH= GLES30.glGetUniformLocation( mainProgramH, "u_TransformFeedback"); |
|
| 265 |
mMainProgramH = mMainProgram.getProgramHandle(); |
|
| 266 |
EffectQueue.getUniforms(mMainProgramH,0); |
|
| 267 |
mMainTextureH= GLES30.glGetUniformLocation( mMainProgramH, "u_Texture"); |
|
| 268 |
mTransformFeedbackH= GLES30.glGetUniformLocation( mMainProgramH, "u_TransformFeedback"); |
|
| 267 | 269 |
|
| 268 | 270 |
// BLIT PROGRAM //////////////////////////////////// |
| 269 | 271 |
final InputStream blitVertStream = mResources.openRawResource(R.raw.blit_vertex_shader); |
| ... | ... | |
| 302 | 304 |
mBlitDepthDepthTextureH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture"); |
| 303 | 305 |
mBlitDepthDepthH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Depth"); |
| 304 | 306 |
mBlitDepthTexCorrH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_TexCorr"); |
| 307 |
|
|
| 308 |
int[] params = new int[1]; |
|
| 309 |
int index = GLES30.glGetUniformBlockIndex(mMainProgramH, "meshAssociation"); |
|
| 310 |
GLES30.glGetActiveUniformBlockiv( mMainProgramH, index, GLES30.GL_UNIFORM_BLOCK_DATA_SIZE, params, 0); |
|
| 311 |
MeshBase.setAssociationSize(params[0]); |
|
| 305 | 312 |
} |
| 306 | 313 |
|
| 307 | 314 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 358 | 365 |
throw new RuntimeException(e.getMessage()); |
| 359 | 366 |
} |
| 360 | 367 |
|
| 361 |
int fullProgramH = mFullProgram.getProgramHandle(); |
|
| 362 |
EffectQueue.getUniforms(fullProgramH,3); |
|
| 363 |
MeshBase.getUniforms(fullProgramH,3); |
|
| 368 |
mFullProgramH = mFullProgram.getProgramHandle(); |
|
| 369 |
EffectQueue.getUniforms(mFullProgramH,3); |
|
| 364 | 370 |
} |
| 365 | 371 |
|
| 366 | 372 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 393 | 399 |
throw new RuntimeException(e.getMessage()); |
| 394 | 400 |
} |
| 395 | 401 |
|
| 396 |
int mainOITProgramH = mMainOITProgram.getProgramHandle(); |
|
| 397 |
EffectQueue.getUniforms(mainOITProgramH,1); |
|
| 398 |
MeshBase.getUniforms(mainOITProgramH,1); |
|
| 399 |
mMainOITTextureH = GLES30.glGetUniformLocation( mainOITProgramH, "u_Texture"); |
|
| 400 |
mMainOITSizeH = GLES30.glGetUniformLocation( mainOITProgramH, "u_Size"); |
|
| 401 |
mMainOITNumRecordsH = GLES30.glGetUniformLocation( mainOITProgramH, "u_numRecords"); |
|
| 402 |
mMainOITProgramH = mMainOITProgram.getProgramHandle(); |
|
| 403 |
EffectQueue.getUniforms(mMainOITProgramH,1); |
|
| 404 |
mMainOITTextureH = GLES30.glGetUniformLocation( mMainOITProgramH, "u_Texture"); |
|
| 405 |
mMainOITSizeH = GLES30.glGetUniformLocation( mMainOITProgramH, "u_Size"); |
|
| 406 |
mMainOITNumRecordsH = GLES30.glGetUniformLocation( mMainOITProgramH, "u_numRecords"); |
|
| 402 | 407 |
|
| 403 | 408 |
// OIT CLEAR PROGRAM //////////////////////////////////// |
| 404 | 409 |
final InputStream oitClearVertStream = resources.openRawResource(R.raw.oit_vertex_shader); |
| ... | ... | |
| 518 | 523 |
} |
| 519 | 524 |
|
| 520 | 525 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 521 |
// execute all VertexEffects and adjust all vertices |
|
| 522 |
|
|
| 526 |
/** |
|
| 527 |
* Execute all VertexEffects and adjust all vertices |
|
| 528 |
* |
|
| 529 |
* @y.exclude |
|
| 530 |
*/ |
|
| 523 | 531 |
public static void adjustVertices(MeshBase mesh, EffectQueueVertex queue) |
| 524 | 532 |
{
|
| 525 | 533 |
if( mFullProgram==null ) |
| ... | ... | |
| 542 | 550 |
mesh.bindVertexAttribs(mFullProgram); |
| 543 | 551 |
queue.compute(1); |
| 544 | 552 |
queue.send(0.0f,3); |
| 545 |
mesh.send(3);
|
|
| 553 |
mesh.send(mFullProgramH);
|
|
| 546 | 554 |
|
| 547 | 555 |
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo ); |
| 548 | 556 |
GLES30.glBeginTransformFeedback( GLES30.GL_POINTS); |
| ... | ... | |
| 570 | 578 |
GLES30.glUniform2ui(mMainOITSizeH, surface.mWidth, surface.mHeight); |
| 571 | 579 |
GLES30.glUniform1ui(mMainOITNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) ); |
| 572 | 580 |
mesh.bindVertexAttribs(mMainOITProgram); |
| 573 |
mesh.send(1);
|
|
| 581 |
mesh.send(mMainOITProgramH);
|
|
| 574 | 582 |
|
| 575 | 583 |
float inflate = mesh.getInflate(); |
| 576 | 584 |
float distance = surface.mDistance; |
| ... | ... | |
| 583 | 591 |
if( mesh.getShowNormals() ) |
| 584 | 592 |
{
|
| 585 | 593 |
mMainProgram.useProgram(); |
| 586 |
mesh.send(0);
|
|
| 594 |
mesh.send(mMainProgramH);
|
|
| 587 | 595 |
EffectQueue.send(queues, distance, mipmap, projection, inflate, 0 ); |
| 588 | 596 |
displayNormals(projection,mesh); |
| 589 | 597 |
} |
| ... | ... | |
| 604 | 612 |
mMainProgram.useProgram(); |
| 605 | 613 |
GLES30.glUniform1i(DistortedLibrary.mMainTextureH, 0); |
| 606 | 614 |
mesh.bindVertexAttribs(DistortedLibrary.mMainProgram); |
| 607 |
mesh.send(0);
|
|
| 615 |
mesh.send(mMainProgramH);
|
|
| 608 | 616 |
|
| 609 | 617 |
float inflate = mesh.getInflate(); |
| 610 | 618 |
float distance = surface.mDistance; |
| src/main/java/org/distorted/library/main/InternalBuffer.java | ||
|---|---|---|
| 20 | 20 |
package org.distorted.library.main; |
| 21 | 21 |
|
| 22 | 22 |
import android.opengl.GLES30; |
| 23 |
|
|
| 24 |
import java.nio.Buffer; |
|
| 23 | 25 |
import java.nio.ByteBuffer; |
| 24 | 26 |
import java.nio.ByteOrder; |
| 25 | 27 |
import java.nio.FloatBuffer; |
| 28 |
import java.nio.IntBuffer; |
|
| 26 | 29 |
|
| 27 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 | 31 |
/** |
| ... | ... | |
| 37 | 40 |
{
|
| 38 | 41 |
private final int[] mIndex; |
| 39 | 42 |
private int mTarget, mSize, mUsage; |
| 40 |
private FloatBuffer mBuffer;
|
|
| 43 |
private Buffer mBuffer; |
|
| 41 | 44 |
|
| 42 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 43 | 46 |
|
| ... | ... | |
| 57 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 58 | 61 |
// must be called from a thread holding OpenGL Context. |
| 59 | 62 |
|
| 60 |
public int createImmediately(int size, float[] buffer) |
|
| 63 |
public int createImmediatelyFloat(int size, float[] buffer)
|
|
| 61 | 64 |
{
|
| 62 | 65 |
if( mIndex[0]<0 ) |
| 63 | 66 |
{
|
| ... | ... | |
| 85 | 88 |
return mIndex[0]; |
| 86 | 89 |
} |
| 87 | 90 |
|
| 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 92 |
// must be called from a thread holding OpenGL Context. |
|
| 93 |
|
|
| 94 |
public int createImmediatelyInt(int size, int[] buffer) |
|
| 95 |
{
|
|
| 96 |
if( mIndex[0]<0 ) |
|
| 97 |
{
|
|
| 98 |
mSize= size; |
|
| 99 |
|
|
| 100 |
if( buffer!=null ) |
|
| 101 |
{
|
|
| 102 |
IntBuffer buf = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asIntBuffer(); |
|
| 103 |
buf.put(buffer).position(0); |
|
| 104 |
mBuffer = buf; |
|
| 105 |
} |
|
| 106 |
else |
|
| 107 |
{
|
|
| 108 |
mBuffer = null; |
|
| 109 |
} |
|
| 110 |
|
|
| 111 |
GLES30.glGenBuffers( 1, mIndex, 0); |
|
| 112 |
GLES30.glBindBuffer( mTarget, mIndex[0]); |
|
| 113 |
GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage); |
|
| 114 |
GLES30.glBindBuffer( mTarget, 0); |
|
| 115 |
|
|
| 116 |
markWasCreatedImmediately(); |
|
| 117 |
} |
|
| 118 |
|
|
| 119 |
return mIndex[0]; |
|
| 120 |
} |
|
| 121 |
|
|
| 122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 123 |
// buffer non-null!! |
|
| 124 |
|
|
| 125 |
public void updateFloat(float[] buffer) |
|
| 126 |
{
|
|
| 127 |
((FloatBuffer)mBuffer).put(buffer).position(0); |
|
| 128 |
|
|
| 129 |
GLES30.glBindBuffer( mTarget, mIndex[0]); |
|
| 130 |
GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage); |
|
| 131 |
GLES30.glBindBuffer( mTarget, 0); |
|
| 132 |
} |
|
| 133 |
|
|
| 88 | 134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 89 | 135 |
// buffer non-null!! |
| 90 | 136 |
|
| 91 |
public void update(float[] buffer)
|
|
| 137 |
public void updateInt(int[] buffer)
|
|
| 92 | 138 |
{
|
| 93 |
mBuffer.put(buffer).position(0);
|
|
| 139 |
((IntBuffer)mBuffer).put(buffer).position(0);
|
|
| 94 | 140 |
|
| 95 | 141 |
GLES30.glBindBuffer( mTarget, mIndex[0]); |
| 96 | 142 |
GLES30.glBufferData( mTarget, mSize, mBuffer, mUsage); |
| src/main/java/org/distorted/library/mesh/MeshBase.java | ||
|---|---|---|
| 25 | 25 |
|
| 26 | 26 |
import org.distorted.library.effect.MatrixEffect; |
| 27 | 27 |
import org.distorted.library.effect.VertexEffect; |
| 28 |
import org.distorted.library.effectqueue.EffectQueue; |
|
| 29 | 28 |
import org.distorted.library.main.InternalBuffer; |
| 30 | 29 |
import org.distorted.library.program.DistortedProgram; |
| 31 | 30 |
import org.distorted.library.type.Static4D; |
| ... | ... | |
| 47 | 46 |
*/ |
| 48 | 47 |
public abstract class MeshBase |
| 49 | 48 |
{
|
| 49 |
private static final int UBO_BINDING = 1; |
|
| 50 | 50 |
private static final int MAX_EFFECT_COMPONENTS= 100; |
| 51 | 51 |
private static final int DEFAULT_ASSOCIATION = 0xffffffff; |
| 52 | 52 |
|
| ... | ... | |
| 79 | 79 |
private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT; |
| 80 | 80 |
private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT; |
| 81 | 81 |
|
| 82 |
private static int mAssociationSize = 8*MAX_EFFECT_COMPONENTS; |
|
| 83 |
|
|
| 82 | 84 |
private boolean mShowNormals; // when rendering this mesh, draw normal vectors? |
| 83 | 85 |
private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer |
| 86 |
private InternalBuffer mUBO; // Uniform Buffer Object |
|
| 84 | 87 |
private int mNumVertices; |
| 85 | 88 |
private float[] mVertAttribs1; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ |
| 86 | 89 |
private float[] mVertAttribs2; // packed: TexS,TexT, Component |
| 87 | 90 |
private float mInflate; |
| 88 |
private int[] mEquAssociation; |
|
| 89 |
private int[] mAndAssociation; |
|
| 91 |
private int[] mAssociations; |
|
| 92 |
private int mAssociationBlock; |
|
| 93 |
private boolean mNeedAdjustAssociation; |
|
| 90 | 94 |
|
| 91 | 95 |
DeferredJobs.JobNode[] mJobNode; |
| 92 | 96 |
|
| 93 |
private static int[] mEquAssociationH = new int[EffectQueue.MAIN_VARIANTS]; |
|
| 94 |
private static int[] mAndAssociationH = new int[EffectQueue.MAIN_VARIANTS]; |
|
| 95 |
|
|
| 96 | 97 |
private static final int TEX_COMP_SIZE = 5; // 5 four-bytes entities inside the component |
| 97 | 98 |
|
| 98 | 99 |
private static class TexComponent |
| ... | ... | |
| 134 | 135 |
mTexComponent = new ArrayList<>(); |
| 135 | 136 |
mEffComponent = new ArrayList<>(); |
| 136 | 137 |
|
| 137 |
mEquAssociation= new int[MAX_EFFECT_COMPONENTS]; |
|
| 138 |
mAndAssociation= new int[MAX_EFFECT_COMPONENTS]; |
|
| 138 |
mNeedAdjustAssociation = true; |
|
| 139 |
mAssociationBlock = computeAssociationBlockSize(); |
|
| 140 |
mAssociations= new int[mAssociationSize/4]; |
|
| 139 | 141 |
|
| 140 | 142 |
mJobNode = new DeferredJobs.JobNode[1]; |
| 141 | 143 |
|
| 142 | 144 |
for(int i=0; i<MAX_EFFECT_COMPONENTS; i++) |
| 143 | 145 |
{
|
| 144 |
mAndAssociation[i] = DEFAULT_ASSOCIATION;
|
|
| 145 |
mEquAssociation[i] = i;
|
|
| 146 |
mAssociations[getAndIndex(i)] = DEFAULT_ASSOCIATION;
|
|
| 147 |
mAssociations[getEquIndex(i)] = i;
|
|
| 146 | 148 |
} |
| 147 | 149 |
|
| 148 | 150 |
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
| 149 | 151 |
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
| 150 | 152 |
mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ); |
| 153 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER , GLES30.GL_STATIC_READ); |
|
| 151 | 154 |
} |
| 152 | 155 |
|
| 153 | 156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 159 | 162 |
mInflate = original.mInflate; |
| 160 | 163 |
mNumVertices= original.mNumVertices; |
| 161 | 164 |
|
| 162 |
mAndAssociation= new int[MAX_EFFECT_COMPONENTS]; |
|
| 163 |
System.arraycopy(original.mAndAssociation, 0, mAndAssociation, 0, MAX_EFFECT_COMPONENTS); |
|
| 164 |
mEquAssociation= new int[MAX_EFFECT_COMPONENTS]; |
|
| 165 |
System.arraycopy(original.mEquAssociation, 0, mEquAssociation, 0, MAX_EFFECT_COMPONENTS); |
|
| 165 |
mNeedAdjustAssociation = original.mNeedAdjustAssociation; |
|
| 166 |
mAssociationBlock = original.mAssociationBlock; |
|
| 167 |
|
|
| 168 |
int size = original.mAssociations.length; |
|
| 169 |
mAssociations= new int[size]; |
|
| 170 |
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size); |
|
| 166 | 171 |
|
| 167 | 172 |
if( deep ) |
| 168 | 173 |
{
|
| ... | ... | |
| 179 | 184 |
} |
| 180 | 185 |
|
| 181 | 186 |
mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ); |
| 182 |
mTFO.invalidate(); |
|
| 187 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER , GLES30.GL_STATIC_READ); |
|
| 188 |
} |
|
| 189 |
|
|
| 190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 191 |
/** |
|
| 192 |
* @y.exclude |
|
| 193 |
*/ |
|
| 194 |
public static void setAssociationSize(int size) |
|
| 195 |
{
|
|
| 196 |
mAssociationSize = size; |
|
| 197 |
} |
|
| 198 |
|
|
| 199 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 200 |
|
|
| 201 |
private int getAndIndex(int component) |
|
| 202 |
{
|
|
| 203 |
return mAssociationBlock*component; |
|
| 204 |
} |
|
| 205 |
|
|
| 206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 207 |
|
|
| 208 |
private int getEquIndex(int component) |
|
| 209 |
{
|
|
| 210 |
return mAssociationBlock*(MAX_EFFECT_COMPONENTS+component); |
|
| 211 |
} |
|
| 212 |
|
|
| 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 214 |
|
|
| 215 |
private int computeAssociationBlockSize() |
|
| 216 |
{
|
|
| 217 |
return 1 + (mAssociationSize/4 - 2*MAX_EFFECT_COMPONENTS) / (2*MAX_EFFECT_COMPONENTS-1); |
|
| 218 |
} |
|
| 219 |
|
|
| 220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 221 |
// The problem here is that at MeshBase object creation time, we might not know the size of the |
|
| 222 |
// 'meshAssociation' Uniform Block Object in the vertex shader (the UBO is packed according to the |
|
| 223 |
// 'shared' layout, which means the size of the block is known only after linking the shaders). |
|
| 224 |
// |
|
| 225 |
// We thus, in the constructor, guess that the layout will be tight (so we will need 8*MAX_EFFECT_C |
|
| 226 |
// bytes there), allocate mAssociation already, and if later on, as a result of linking the shaders, |
|
| 227 |
// we get a call to setAssociationSize() which changes the size to something else, we need to reallocate. |
|
| 228 |
// |
|
| 229 |
// It can happen that even before the linking the value of mAssociationSize is already 'right' because |
|
| 230 |
// this is a static variable and it might persist from an earlier run. All the better then; this should |
|
| 231 |
// never be wrong. |
|
| 232 |
|
|
| 233 |
private void adjustAssociation() |
|
| 234 |
{
|
|
| 235 |
int oldLen = mAssociations.length; |
|
| 236 |
|
|
| 237 |
if( mAssociationSize != 4*oldLen ) |
|
| 238 |
{
|
|
| 239 |
int[] tmp = new int[oldLen]; |
|
| 240 |
System.arraycopy(mAssociations, 0, tmp, 0, oldLen); |
|
| 241 |
|
|
| 242 |
int newLen = mAssociationSize/4; |
|
| 243 |
mAssociations = new int[newLen]; |
|
| 244 |
mAssociationBlock = computeAssociationBlockSize(); |
|
| 245 |
|
|
| 246 |
for(int i=0; i<oldLen/2; i++) |
|
| 247 |
{
|
|
| 248 |
mAssociations[getAndIndex(i)] = tmp[i]; // oldLen must be equal to |
|
| 249 |
mAssociations[getEquIndex(i)] = tmp[MAX_EFFECT_COMPONENTS+i]; // 8*MAX_EFFECT_COM |
|
| 250 |
} |
|
| 251 |
} |
|
| 183 | 252 |
} |
| 184 | 253 |
|
| 185 | 254 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 270 | 339 |
start = end+1; |
| 271 | 340 |
end = mEffComponent.get(i); |
| 272 | 341 |
|
| 273 |
if( (andAssoc & mAndAssociation[i]) != 0 || (equAssoc == mEquAssociation[i]) )
|
|
| 342 |
if( (andAssoc & mAssociations[getAndIndex(i)]) != 0 || (equAssoc == mAssociations[getEquIndex(i)]) )
|
|
| 274 | 343 |
{
|
| 275 | 344 |
applyMatrixToComponent(matrixP, matrixV, start, end); |
| 276 | 345 |
} |
| ... | ... | |
| 343 | 412 |
|
| 344 | 413 |
void setEffectAssociationNow(int component, int andAssociation, int equAssociation) |
| 345 | 414 |
{
|
| 346 |
mAndAssociation[component] = andAssociation; |
|
| 347 |
mEquAssociation[component] = equAssociation; |
|
| 415 |
mAssociations[getAndIndex(component)] = andAssociation; |
|
| 416 |
mAssociations[getEquIndex(component)] = equAssociation; |
|
| 417 |
|
|
| 418 |
mUBO.invalidate(); |
|
| 348 | 419 |
} |
| 349 | 420 |
|
| 350 | 421 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 410 | 481 |
|
| 411 | 482 |
if( origEffComponents<MAX_EFFECT_COMPONENTS ) |
| 412 | 483 |
{
|
| 413 |
mAndAssociation[origEffComponents] = mesh.mAndAssociation[j];
|
|
| 414 |
mEquAssociation[origEffComponents] = mesh.mEquAssociation[j];
|
|
| 484 |
mAssociations[getAndIndex(origEffComponents)] = mesh.mAssociations[mesh.getAndIndex(j)];
|
|
| 485 |
mAssociations[getEquIndex(origEffComponents)] = mesh.mAssociations[mesh.getEquIndex(j)];
|
|
| 415 | 486 |
origEffComponents++; |
| 416 | 487 |
} |
| 417 | 488 |
} |
| ... | ... | |
| 561 | 632 |
return MAX_EFFECT_COMPONENTS; |
| 562 | 633 |
} |
| 563 | 634 |
|
| 564 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 565 |
|
|
| 566 |
public static void getUniforms(int mProgramH, int variant) |
|
| 567 |
{
|
|
| 568 |
mEquAssociationH[variant] = GLES30.glGetUniformLocation( mProgramH, "vComEquAssoc"); |
|
| 569 |
mAndAssociationH[variant] = GLES30.glGetUniformLocation( mProgramH, "vComAndAssoc"); |
|
| 570 |
} |
|
| 571 |
|
|
| 572 | 635 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 573 | 636 |
/** |
| 574 | 637 |
* Not part of public API, do not document (public only because has to be used from the main package) |
| ... | ... | |
| 583 | 646 |
{
|
| 584 | 647 |
FloatBuffer feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer(); |
| 585 | 648 |
feedback.get(mVertAttribs1,0,VERT1_ATTRIBS*mNumVertices); |
| 586 |
mVBO1.update(mVertAttribs1); |
|
| 649 |
mVBO1.updateFloat(mVertAttribs1);
|
|
| 587 | 650 |
} |
| 588 | 651 |
else |
| 589 | 652 |
{
|
| ... | ... | |
| 694 | 757 |
*/ |
| 695 | 758 |
public int getTFO() |
| 696 | 759 |
{
|
| 697 |
return mTFO.createImmediately(mNumVertices*TRAN_SIZE, null); |
|
| 760 |
return mTFO.createImmediatelyFloat(mNumVertices*TRAN_SIZE, null);
|
|
| 698 | 761 |
} |
| 699 | 762 |
|
| 700 | 763 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 714 | 777 |
* |
| 715 | 778 |
* @y.exclude |
| 716 | 779 |
*/ |
| 717 |
public void send(int variant)
|
|
| 780 |
public void send(int programH)
|
|
| 718 | 781 |
{
|
| 719 |
GLES30.glUniform1iv( mEquAssociationH[variant], MAX_EFFECT_COMPONENTS, mEquAssociation, 0); |
|
| 720 |
GLES30.glUniform1iv( mAndAssociationH[variant], MAX_EFFECT_COMPONENTS, mAndAssociation, 0); |
|
| 782 |
if( mNeedAdjustAssociation ) |
|
| 783 |
{
|
|
| 784 |
mNeedAdjustAssociation = false; |
|
| 785 |
adjustAssociation(); |
|
| 786 |
} |
|
| 787 |
|
|
| 788 |
int index = mUBO.createImmediatelyInt( mAssociationSize, mAssociations); |
|
| 789 |
|
|
| 790 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, UBO_BINDING, index); |
|
| 791 |
GLES30.glUniformBlockBinding(programH, UBO_BINDING, index); |
|
| 721 | 792 |
} |
| 722 | 793 |
|
| 723 | 794 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 746 | 817 |
*/ |
| 747 | 818 |
} |
| 748 | 819 |
|
| 749 |
int index1 = mVBO1.createImmediately(mNumVertices*VERT1_SIZE, mVertAttribs1); |
|
| 750 |
int index2 = mVBO2.createImmediately(mNumVertices*VERT2_SIZE, mVertAttribs2); |
|
| 820 |
int index1 = mVBO1.createImmediatelyFloat(mNumVertices*VERT1_SIZE, mVertAttribs1);
|
|
| 821 |
int index2 = mVBO2.createImmediatelyFloat(mNumVertices*VERT2_SIZE, mVertAttribs2);
|
|
| 751 | 822 |
|
| 752 | 823 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index1 ); |
| 753 | 824 |
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_POS); |
| ... | ... | |
| 767 | 838 |
*/ |
| 768 | 839 |
public void bindTransformAttribs(DistortedProgram program) |
| 769 | 840 |
{
|
| 770 |
int index = mTFO.createImmediately(mNumVertices*TRAN_SIZE, null); |
|
| 841 |
int index = mTFO.createImmediatelyFloat(mNumVertices*TRAN_SIZE, null);
|
|
| 771 | 842 |
|
| 772 | 843 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index ); |
| 773 | 844 |
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0); |
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 39 | 39 |
out vec3 v_Normal; // |
| 40 | 40 |
out vec2 v_TexCoordinate; // |
| 41 | 41 |
|
| 42 |
uniform mat4 u_MVPMatrix; // the combined model/view/projection matrix.
|
|
| 42 |
uniform mat4 u_MVPMatrix; // u_MVMatrixP * projection.
|
|
| 43 | 43 |
uniform mat4 u_MVMatrixP; // the combined model/view matrix. (for points) |
| 44 | 44 |
uniform mat4 u_MVMatrixV; // the combined model/view matrix. (for vectors) |
| 45 | 45 |
// which need to work differently on points and vectors |
| ... | ... | |
| 54 | 54 |
// second vec4: first float - cache, next 3: Center, the third - the Region. |
| 55 | 55 |
uniform int vEffAndAssoc[NUM_VERTEX];// Associations of the vertex effects. Those are used to connect an effect to a Mesh component. |
| 56 | 56 |
uniform int vEffEquAssoc[NUM_VERTEX];// Components the vertex effects work on. Likewise used to connect an effect to a Mesh component. |
| 57 |
uniform int vComAndAssoc[MAX_COMPON];// 'logical AND' association of the component. |
|
| 58 |
uniform int vComEquAssoc[MAX_COMPON];// 'equal' association of the component. |
|
| 57 |
|
|
| 58 |
layout (std140, binding=1) uniform meshAssociation |
|
| 59 |
{
|
|
| 60 |
int vComAndAssoc[MAX_COMPON]; // 'logical AND' association of the component. |
|
| 61 |
int vComEquAssoc[MAX_COMPON]; // 'equal' association of the component. |
|
| 62 |
}; |
|
| 59 | 63 |
|
| 60 | 64 |
////////////////////////////////////////////////////////////////////////////////////////////// |
| 61 | 65 |
// HELPER FUNCTIONS |
Also available in: Unified diff
Introduce an UBO to the vertex shader holding info about mesh effect associations.