Project

General

Profile

« Previous | Next » 

Revision 7958d843

Added by Leszek Koltunski about 3 years ago

MeshBase's 'MAX_NUM_COMPONENTS' is not a constant - rename!

View differences:

src/main/java/org/distorted/library/effect/PostprocessEffectGlow.java
35 35
  {
36 36
  private static final int MAX_RADIUS = 50;
37 37

  
38
  private Data2D mGlowHaloAndRadius;
39
  private Data4D mColor;
38
  private final Data2D mGlowHaloAndRadius;
39
  private final Data4D mColor;
40 40

  
41 41
  private static final float[] GAUSSIAN =   // G(0.00), G(0.03), G(0.06), ..., G(3.00), 0
42 42
    {                                       // where G(x)= (1/(sqrt(2*PI))) * e^(-(x^2)/2). The last 0 terminates.
......
58 58
  // i.e. k(i)=floor((i+3)/2).  (the 'i' in k(i) means 'blur taking into account the present pixel and 'i' pixels
59 59
  // in all 4 directions)
60 60
  // We need room for MAX_BLUR of them, and sum(i=0...N, floor((i+3)/2)) = N + floor(N*N/4)
61
  private static float[] weightsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
62
  private static float[] offsetsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
63
  private static float[] mWeights = new float[MAX_RADIUS];
64
  private static float[] mOffsets = new float[MAX_RADIUS];
61
  private static final float[] weightsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
62
  private static final float[] offsetsCache = new float[MAX_RADIUS + MAX_RADIUS*MAX_RADIUS/4];
63
  private static final float[] mWeights = new float[MAX_RADIUS];
64
  private static final float[] mOffsets = new float[MAX_RADIUS];
65 65

  
66 66
  private static DistortedProgram mProgram1, mProgram2;
67 67
  private static int mIndex1, mIndex2;
src/main/java/org/distorted/library/mesh/MeshBase.java
52 52
   private static final int ASSOC_UBO_BINDING  = 3;
53 53
   private static final int CENTER_UBO_BINDING = 4;
54 54

  
55
   public static int MAX_EFFECT_COMPONENTS= 100;
56

  
57 55
   // sizes of attributes of an individual vertex.
58 56
   private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
59 57
   private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z
......
86 84
   private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component
87 85

  
88 86
   private static boolean mUseCenters;
87
   private static int mStride;
88
   private static int mMaxComponents = 100;
89 89

  
90 90
   private boolean mShowNormals;              // when rendering this mesh, draw normal vectors?
91 91
   private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer
......
96 96
   private final UniformBlockAssociation mUBA;
97 97
   private UniformBlockCenter mUBC;
98 98
   private boolean mStrideCorrected;
99
   private static int mStride;
100 99

  
101 100
   DeferredJobs.JobNode[] mJobNode;
102 101

  
......
399 398
         if( j==numEffComponents-1 ) index += extraVerticesAfter;
400 399
         mEffComponent.add(index);
401 400

  
402
         if( origEffComponents<MAX_EFFECT_COMPONENTS )
401
         if( origEffComponents<mMaxComponents )
403 402
           {
404 403
           mUBA.copy(origEffComponents, mesh.mUBA, j);
405 404
           if( mUseCenters ) mUBC.copy(origEffComponents, mesh.mUBC, j);
......
570 569

  
571 570
   public static int getMaxEffComponents()
572 571
     {
573
     return MAX_EFFECT_COMPONENTS;
572
     return mMaxComponents;
574 573
     }
575 574

  
576 575
///////////////////////////////////////////////////////////////////////////////////////////////////
......
579 578
 */
580 579
   public static void setMaxEffComponents(int max)
581 580
     {
582
     MAX_EFFECT_COMPONENTS = max;
581
     mMaxComponents = max;
583 582
     }
584 583

  
585 584
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1246 1245
 */
1247 1246
   public void setEffectAssociation(int component, int andAssociation, int equAssociation)
1248 1247
     {
1249
     if( component>=0 && component<MAX_EFFECT_COMPONENTS )
1248
     if( component>=0 && component<mMaxComponents )
1250 1249
       {
1251 1250
       if( mJobNode[0]==null )
1252 1251
         {
......
1274 1273
 */
1275 1274
   public void setComponentCenter(int component, float centerX, float centerY, float centerZ)
1276 1275
     {
1277
     if( component>=0 && component<MAX_EFFECT_COMPONENTS )
1276
     if( component>=0 && component<mMaxComponents )
1278 1277
       {
1279 1278
       if( mJobNode[0]==null )
1280 1279
         {
src/main/java/org/distorted/library/uniformblock/UniformBlockAssociation.java
22 22
import android.opengl.GLES30;
23 23

  
24 24
import org.distorted.library.main.InternalBuffer;
25

  
26
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS;
25
import org.distorted.library.mesh.MeshBase;
27 26

  
28 27
///////////////////////////////////////////////////////////////////////////////////////////////////
29 28
/**
......
39 38
  private static final int LOC_EQU = 1;
40 39

  
41 40
  private final InternalBuffer mUBO;
41
  private final int mMax;
42 42
  private int[] mAssociations;
43 43
  private int mStride;
44 44

  
......
46 46

  
47 47
  public UniformBlockAssociation()
48 48
    {
49
    mMax = MeshBase.getMaxEffComponents();
49 50
    mStride = DEFAULT_STRIDE;
50
    mAssociations= new int[mStride*MAX_EFFECT_COMPONENTS];
51
    mAssociations= new int[mStride*mMax];
51 52

  
52
    for(int i=0; i<MAX_EFFECT_COMPONENTS; i++)
53
    for(int i=0; i<mMax; i++)
53 54
      {
54 55
      mAssociations[mStride*i+LOC_AND] = DEFAULT_ASSOCIATION;
55 56
      mAssociations[mStride*i+LOC_EQU] = i;
......
62 63

  
63 64
  public UniformBlockAssociation(UniformBlockAssociation original)
64 65
    {
66
    mMax = original.mMax;
65 67
    mStride = original.mStride;
66 68
    int size = original.mAssociations.length;
67 69
    mAssociations= new int[size];
......
77 79
    {
78 80
    if( mStride != stride && stride!=0 )
79 81
      {
80
      int[] tmp = new int[stride*MAX_EFFECT_COMPONENTS];
82
      int[] tmp = new int[stride*mMax];
81 83

  
82
      for(int i=0; i<MAX_EFFECT_COMPONENTS; i++)
84
      for(int i=0; i<mMax; i++)
83 85
        {
84 86
        tmp[stride*i+LOC_AND] = mAssociations[mStride*i+LOC_AND];
85 87
        tmp[stride*i+LOC_EQU] = mAssociations[mStride*i+LOC_EQU];
......
111 113

  
112 114
  public int getIndex()
113 115
    {
114
    return mUBO.createImmediatelyInt( 4*mStride*MAX_EFFECT_COMPONENTS, mAssociations);
116
    return mUBO.createImmediatelyInt( 4*mStride*mMax, mAssociations);
115 117
    }
116 118

  
117 119
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/uniformblock/UniformBlockCenter.java
22 22
import android.opengl.GLES30;
23 23

  
24 24
import org.distorted.library.main.InternalBuffer;
25

  
26
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS;
25
import org.distorted.library.mesh.MeshBase;
27 26

  
28 27
///////////////////////////////////////////////////////////////////////////////////////////////////
29 28
/**
......
33 32
 */
34 33
public class UniformBlockCenter
35 34
  {
36
  private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS;
37

  
38 35
  private final InternalBuffer mUBO;
39 36
  private final float[] mArray;
37
  private final int mMax;
40 38

  
41 39
///////////////////////////////////////////////////////////////////////////////////////////////////
42 40

  
43 41
  public UniformBlockCenter()
44 42
    {
45
    mArray= new float[BLOCK_SIZE/4];
46
    mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
43
    mMax  = MeshBase.getMaxEffComponents();
44
    mArray= new float[4*mMax];
45
    mUBO  = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ);
47 46
    }
48 47

  
49 48
///////////////////////////////////////////////////////////////////////////////////////////////////
50 49

  
51 50
  public UniformBlockCenter(UniformBlockCenter original)
52 51
    {
52
    mMax = original.mMax;
53 53
    int size = original.mArray.length;
54 54
    mArray= new float[size];
55 55
    System.arraycopy(original.mArray, 0, mArray, 0, size);
......
71 71

  
72 72
  public int getIndex()
73 73
    {
74
    return mUBO.createImmediatelyFloat( BLOCK_SIZE, mArray);
74
    return mUBO.createImmediatelyFloat( 16*mMax, mArray);
75 75
    }
76 76

  
77 77
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff