Project

General

Profile

« Previous | Next » 

Revision 227b9bca

Added by Leszek Koltunski almost 6 years ago

Minor simplifications in Mesh.

View differences:

src/main/java/org/distorted/library/mesh/MeshBase.java
31 31

  
32 32
///////////////////////////////////////////////////////////////////////////////////////////////////
33 33
/**
34
 * Abstract class which represents a Mesh, ie 3 arrays of Vertex attributes: 1) positions
35
 * 2) normals 3) texture coordinates.
34
 * Abstract class which represents a Mesh, i.e. an array of vertices (rendered as a TRIANGLE_STRIP)
36 35
 * <p>
37 36
 * If you want to render to a particular shape, extend from here, construct a float array
38 37
 * containing per-vertex attributes, and call back setData().
39 38
 */
40 39
public abstract class MeshBase
41 40
   {
42
   private static final int POS_DATA_SIZE= 3;
43
   private static final int NOR_DATA_SIZE= 3;
44
   private static final int INF_DATA_SIZE= 3;
45
   private static final int TEX_DATA_SIZE= 2;
41
   // sizes of attributes of an individual vertex.
42
   private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
43
   private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z
44
   private static final int INF_DATA_SIZE= 3; // 'inflate' vector: x,y,z
45
   private static final int TEX_DATA_SIZE= 2; // texture coordinates
46 46

  
47 47
   static final int POS_ATTRIB   = 0;
48 48
   static final int NOR_ATTRIB   = POS_DATA_SIZE;
49 49
   static final int INF_ATTRIB   = POS_DATA_SIZE + NOR_DATA_SIZE;
50 50
   static final int TEX_ATTRIB   = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE;
51
   static final int VERT_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE + TEX_DATA_SIZE;
51
   static final int VERT_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE + TEX_DATA_SIZE;  // number of attributes of a 'normal' vertex
52
   static final int TRAN_ATTRIBS = POS_DATA_SIZE + POS_DATA_SIZE;                                  // number of attributes of a transform feedback vertex
52 53

  
53 54
   private static final int BYTES_PER_FLOAT = 4;
54 55

  
......
56 57
   private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT;
57 58
   private static final int OFFSET_INF = INF_ATTRIB*BYTES_PER_FLOAT;
58 59
   private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT;
59

  
60
   private static final int TFSIZE  = (POS_DATA_SIZE+POS_DATA_SIZE                            )*BYTES_PER_FLOAT;
61
   private static final int VERTSIZE= (POS_DATA_SIZE+NOR_DATA_SIZE+INF_DATA_SIZE+TEX_DATA_SIZE)*BYTES_PER_FLOAT;
60
   private static final int TRAN_SIZE  = TRAN_ATTRIBS*BYTES_PER_FLOAT;
61
   private static final int VERT_SIZE  = VERT_ATTRIBS*BYTES_PER_FLOAT;
62 62

  
63 63
   private boolean mShowNormals;       // when rendering this mesh, draw normal vectors?
64 64
   private DistortedBuffer mVBO, mTFO; // main vertex buffer and transform feedback buffer
65 65
   private final float zFactor;        // strange workaround for the fact that we need to somehow store the 'depth'
66 66
                                       // of the Mesh. Used in DistortedEffects. See DistortedTexture.getDepth().
67 67
   private int mNumVertices;
68
   private FloatBuffer mVertAttribs;   // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, TexS,TexT
68
   private FloatBuffer mVertAttribs;   // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ, TexS,TexT
69 69

  
70 70
///////////////////////////////////////////////////////////////////////////////////////////////////
71 71

  
......
81 81
///////////////////////////////////////////////////////////////////////////////////////////////////
82 82
// when a derived class is done computing its mesh, it has to call this method.
83 83

  
84
   void setData(int numVertices, float[] vertexAttribs)
84
   void setAttribs(float[] vertexAttribs)
85 85
     {
86
     mNumVertices = numVertices;
86
     mNumVertices = vertexAttribs.length/VERT_ATTRIBS;
87 87

  
88
     mVertAttribs = ByteBuffer.allocateDirect(mNumVertices*VERTSIZE).order(ByteOrder.nativeOrder()).asFloatBuffer();
88
     mVertAttribs = ByteBuffer.allocateDirect(mNumVertices*VERT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer();
89 89
     mVertAttribs.put(vertexAttribs).position(0);
90 90

  
91
     mVBO.setData(numVertices*VERTSIZE, mVertAttribs);
92
     mTFO.setData(numVertices*TFSIZE  , null        );
91
     mVBO.setData(mNumVertices*VERT_SIZE, mVertAttribs);
92
     mTFO.setData(mNumVertices*TRAN_SIZE, null        );
93 93
     }
94 94

  
95 95
///////////////////////////////////////////////////////////////////////////////////////////////////
......
134 134
   public void bindVertexAttribs(DistortedProgram program)
135 135
     {
136 136
     GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mVBO.mIndex[0] );
137
     GLES31.glVertexAttribPointer(program.mAttribute[0], MeshBase.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET_POS);
138
     GLES31.glVertexAttribPointer(program.mAttribute[1], MeshBase.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET_NOR);
139
     GLES31.glVertexAttribPointer(program.mAttribute[2], MeshBase.INF_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET_INF);
140
     GLES31.glVertexAttribPointer(program.mAttribute[3], MeshBase.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET_TEX);
137
     GLES31.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_POS);
138
     GLES31.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_NOR);
139
     GLES31.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_INF);
140
     GLES31.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES31.GL_FLOAT, false, VERT_SIZE, OFFSET_TEX);
141 141
     GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
142 142
     }
143 143

  
......
150 150
   public void bindTransformAttribs(DistortedProgram program)
151 151
     {
152 152
     GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mTFO.mIndex[0] );
153
     GLES31.glVertexAttribPointer(program.mAttribute[0], MeshBase.POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, 0);
153
     GLES31.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, 0);
154 154
     GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
155 155
     }
156 156

  
src/main/java/org/distorted/library/mesh/MeshCubes.java
750 750
     if( remainingVert!=0 )
751 751
       android.util.Log.e("MeshCubes", "remainingVert " +remainingVert );
752 752

  
753
     setData(numVertices, attribs);
753
     setAttribs(attribs);
754 754
     }
755 755

  
756 756
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/mesh/MeshFlat.java
196 196
    if( remainingVert!=0 )
197 197
      android.util.Log.d("MeshFlat", "remainingVert " +remainingVert );
198 198

  
199
    setData(numVertices, attribs);
199
    setAttribs(attribs);
200 200
    }
201 201
 }

Also available in: Unified diff