Project

General

Profile

« Previous | Next » 

Revision 46d463a4

Added by Leszek Koltunski over 3 years ago

Make per-component centers optional, controlled by API MeshBase.setUseCenters()

View differences:

src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java
129 129
    String mainFragHeader= version + "\n";
130 130

  
131 131
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
132
    if( MeshBase.getUseCenters() ) mainVertHeader += "#define COMP_CENTERS\n";
132 133

  
133 134
    String enabledEffectV= VertexEffect.getGLSL();
134 135

  
src/main/java/org/distorted/library/main/DistortedLibrary.java
115 115
  private static int mFBOQueueSize;
116 116
  private static int mGLSL;
117 117
  private static String mGLSL_VERSION;
118
  private static boolean mOITCompilationAttempted;
119
  private static boolean mNeedsTransformFeedback;
118
  private static boolean mOITCompilationAttempted, mNeedsTransformFeedback;
120 119

  
121 120
  private static int mMaxTextureSize         = Integer.MAX_VALUE;
122 121
  private static int mMaxNumberOfVerUniforms = Integer.MAX_VALUE;
......
248 247
    String mainFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n");
249 248

  
250 249
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
250
    if( MeshBase.getUseCenters() ) mainVertHeader += "#define COMP_CENTERS\n";
251 251

  
252 252
    String enabledEffectV= VertexEffect.getGLSL();
253 253
    String enabledEffectF= FragmentEffect.getGLSL();
......
346 346
    String fullFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " +                                         0   + "\n");
347 347

  
348 348
    fullVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
349
    if( MeshBase.getUseCenters() ) fullVertHeader += "#define COMP_CENTERS\n";
349 350

  
350 351
    String enabledEffectV= VertexEffect.getAllGLSL();
351 352
    String enabledEffectF= "{}";
......
385 386
    String mainFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n") + ("#define OIT\n");
386 387

  
387 388
    mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxEffComponents() + "\n";
389
    if( MeshBase.getUseCenters() ) mainVertHeader += "#define COMP_CENTERS\n";
388 390

  
389 391
    String enabledEffectV= VertexEffect.getGLSL();
390 392
    String enabledEffectF= FragmentEffect.getGLSL();
src/main/java/org/distorted/library/mesh/DeferredJobs.java
48 48
  private static final int JOB_TYPE_CENTER       = 8;
49 49
  private static final int JOB_TYPE_ADD_EMPTY_TEX= 9;
50 50

  
51
  private static ArrayList<JobNode> mJobs = new ArrayList<>();
51
  private static final ArrayList<JobNode> mJobs = new ArrayList<>();
52 52

  
53 53
  //////////////////////////////////////////////////////////////////////////
54 54

  
55 55
  private static class Job
56 56
    {
57
    private int mType;
58
    private MeshBase mTarget;
59
    private MeshBase[] mSource;
57
    private final int mType;
58
    private final MeshBase mTarget;
59
    private final MeshBase[] mSource;
60
    private final MatrixEffect mMatrixEffect;
61
    private final Static4D[] mMaps;
62
    private final int mComp, mAndAssoc, mEquAssoc;
63
    private final float mX,mY,mZ;
64

  
60 65
    private EffectQueueVertex mVertexEffects;
61
    private MatrixEffect mMatrixEffect;
62
    private Static4D[] mMaps;
63
    private int mComp, mAndAssoc, mEquAssoc;
64
    private float mX,mY,mZ;
65 66

  
66 67
    Job(int type, MeshBase target, MeshBase[] source, VertexEffect vEff, MatrixEffect mEff,
67 68
        Static4D[] maps, int comp, int and, int equ, float x, float y, float z)
src/main/java/org/distorted/library/mesh/MeshBase.java
51 51
   {
52 52
   private static final int ASSOC_UBO_BINDING  = 3;
53 53
   private static final int CENTER_UBO_BINDING = 4;
54
   public  static final int MAX_EFFECT_COMPONENTS= 100;
54
   public  static final int MAX_EFFECT_COMPONENTS= 98;
55 55

  
56 56
   // sizes of attributes of an individual vertex.
57 57
   private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
......
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 final int[] mCenterBlockIndex = new int[EffectQueue.MAIN_VARIANTS];
83
   private static final int[] mAssocBlockIndex  = new int[EffectQueue.MAIN_VARIANTS];
84

  
85
   private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component
86

  
87
   private static boolean mUseCenters;
88

  
82 89
   private boolean mShowNormals;              // when rendering this mesh, draw normal vectors?
83 90
   private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer
84 91
   private int mNumVertices;
......
86 93
   private float[] mVertAttribs2;             // packed: TexS,TexT, Component
87 94
   private float mInflate;
88 95
   private final UniformBlockAssociation mUBA;
89
   private final UniformBlockCenter mUBC;
96
   private UniformBlockCenter mUBC;
90 97

  
91 98
   DeferredJobs.JobNode[] mJobNode;
92 99

  
93
   private static final int[] mCenterBlockIndex = new int[EffectQueue.MAIN_VARIANTS];
94
   private static final int[] mAssocBlockIndex  = new int[EffectQueue.MAIN_VARIANTS];
95

  
96
   private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component
97

  
98 100
   private static class TexComponent
99 101
     {
100 102
     private int mEndIndex;
......
137 139
     mJobNode = new DeferredJobs.JobNode[1];
138 140

  
139 141
     mUBA = new UniformBlockAssociation();
140
     mUBC = new UniformBlockCenter();
142

  
143
     if( mUseCenters ) mUBC = new UniformBlockCenter();
141 144

  
142 145
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
143 146
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
......
154 157
     mNumVertices= original.mNumVertices;
155 158

  
156 159
     mUBA = new UniformBlockAssociation(original.mUBA);
157
     mUBC = new UniformBlockCenter(original.mUBC);
160

  
161
     if( mUseCenters ) mUBC = new UniformBlockCenter(original.mUBC);
158 162

  
159 163
     if( deep )
160 164
       {
......
326 330

  
327 331
   void setComponentCenterNow(int component, float x, float y, float z)
328 332
     {
329
     mUBC.setEffectCenterNow(component, x, y, z);
333
     if( mUBC!=null )
334
       {
335
       mUBC.setEffectCenterNow(component, x, y, z);
336
       }
330 337
     }
331 338

  
332 339
///////////////////////////////////////////////////////////////////////////////////////////////////
......
393 400
         if( origEffComponents<MAX_EFFECT_COMPONENTS )
394 401
           {
395 402
           mUBA.copy(origEffComponents, mesh.mUBA, j);
396
           mUBC.copy(origEffComponents, mesh.mUBC, j);
403
           if( mUseCenters ) mUBC.copy(origEffComponents, mesh.mUBC, j);
397 404
           origEffComponents++;
398 405
           }
399 406
         }
......
538 545
     mVBO2.invalidate();
539 546
     }
540 547

  
548
///////////////////////////////////////////////////////////////////////////////////////////////////
549
/**
550
 * Are we going to need per-component centers (needed for correct postprocessing of concave meshes)
551
 * Switching this on allocates 16*MAX_EFFECT_COMPONENTS bytes for uniforms in the vertex shader.
552
 */
553
   public static void setUseCenters()
554
     {
555
     mUseCenters = true;
556
     }
557

  
558
///////////////////////////////////////////////////////////////////////////////////////////////////
559
/**
560
 * Are we using per-component centers?
561
 */
562
   public static boolean getUseCenters()
563
     {
564
     return mUseCenters;
565
     }
566

  
541 567
///////////////////////////////////////////////////////////////////////////////////////////////////
542 568

  
543 569
   public static int getMaxEffComponents()
......
704 730
     GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, ASSOC_UBO_BINDING, indexA);
705 731
     GLES30.glUniformBlockBinding(programH, mAssocBlockIndex[variant], ASSOC_UBO_BINDING);
706 732

  
707
     int indexC = mUBC.getIndex();
708
     GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, CENTER_UBO_BINDING, indexC);
709
     GLES30.glUniformBlockBinding(programH, mCenterBlockIndex[variant], CENTER_UBO_BINDING);
733
     if( mUseCenters )
734
       {
735
       int indexC = mUBC.getIndex();
736
       GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, CENTER_UBO_BINDING, indexC);
737
       GLES30.glUniformBlockBinding(programH, mCenterBlockIndex[variant], CENTER_UBO_BINDING);
738
       }
710 739
     }
711 740

  
712 741
///////////////////////////////////////////////////////////////////////////////////////////////////
......
902 931
         case 2 : float[] centers = new float[3*numEff];
903 932
                  floatBuf.get(centers,0,3*numEff);
904 933

  
905
                  for(int eff=0; eff<numEff; eff++)
934
                  if( mUseCenters )
906 935
                    {
907
                    mUBC.setEffectCenterNow(eff, centers[3*eff], centers[3*eff+1], centers[3*eff+2]);
936
                    for(int eff=0; eff<numEff; eff++)
937
                      {
938
                      mUBC.setEffectCenterNow(eff, centers[3*eff], centers[3*eff+1], centers[3*eff+2]);
939
                      }
908 940
                    }
909 941

  
910 942
                  floatBuf.get(mVertAttribs1, 0, VERT1_ATTRIBS*mNumVertices);
......
983 1015
         stream.writeFloat((float)mEffComponent.get(i));
984 1016
         }
985 1017

  
986
       float[] centers = mUBC.getBackingArray();
1018
       float[] centers = mUseCenters ? mUBC.getBackingArray() : new float[4*numEff];
987 1019

  
988 1020
       for(int i=0; i<numEff; i++)
989 1021
         {
......
1075 1107
     mVBO2.markForDeletion();
1076 1108
     mTFO.markForDeletion();
1077 1109
     mUBA.markForDeletion();
1078
     mUBC.markForDeletion();
1110

  
1111
     if( mUBC!=null )
1112
       {
1113
       mUBC.markForDeletion();
1114
       }
1079 1115
     }
1080 1116

  
1081 1117
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/raw/main_vertex_shader.glsl
39 39
uniform float u_Inflate;              // how much should we inflate (>0.0) or deflate (<0.0) the mesh.
40 40
uniform int u_TransformFeedback;      // are we doing the transform feedback now?
41 41

  
42
#ifdef COMP_CENTERS
42 43
layout (std140) uniform componentCenter
43 44
  {
44 45
  vec4 vComCenter[MAX_COMPON];        // centers of mesh components. 4 floats: (x,y,z,unused)
45 46
  };
47
#endif
46 48

  
47 49
#if NUM_VERTEX>0
48 50
uniform int vNumEffects;              // total number of vertex effects
......
117 119
void main()
118 120
  {
119 121
  int component = int(a_Component);
120
  vec3 v = a_Position + u_Inflate*(a_Position - vComCenter[component].xyz);
121 122
  vec3 n = a_Normal;
123
#ifdef COMP_CENTERS
124
  vec3 v = a_Position + u_Inflate*(a_Position - vComCenter[component].xyz);
125
#else
126
  vec3 v = a_Position + u_Inflate*a_Position;
127
#endif
122 128

  
123 129
#if NUM_VERTEX>0
124 130
  int effect=0;

Also available in: Unified diff