Project

General

Profile

« Previous | Next » 

Revision 715e7726

Added by Leszek Koltunski about 6 years ago

Rename MeshObject to MeshBase.

View differences:

src/main/java/org/distorted/library/main/DistortedEffects.java
29 29
import org.distorted.library.effect.EffectType;
30 30
import org.distorted.library.effect.FragmentEffect;
31 31
import org.distorted.library.effect.VertexEffect;
32
import org.distorted.library.mesh.MeshObject;
32
import org.distorted.library.mesh.MeshBase;
33 33
import org.distorted.library.message.EffectListener;
34 34
import org.distorted.library.program.DistortedProgram;
35 35

  
......
43 43
/**
44 44
 * Class containing Matrix, Vertex, Fragment and Postprocessing effect queues.
45 45
 * <p>
46
 * The queues hold actual effects to be applied to a given (InputSurface,MeshObject) combo.
46
 * The queues hold actual effects to be applied to a given (InputSurface,MeshBase) combo.
47 47
 */
48 48
public class DistortedEffects
49 49
  {
......
423 423

  
424 424
///////////////////////////////////////////////////////////////////////////////////////////////////
425 425

  
426
  private void displayNormals(MeshObject mesh)
426
  private void displayNormals(MeshBase mesh)
427 427
    {
428 428
    int num = mesh.getNumVertices();
429 429

  
......
438 438
    mNormalProgram.useProgram();
439 439
    GLES31.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, mM.getMVP() , 0);
440 440
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.getTFO() );
441
    GLES31.glVertexAttribPointer(mNormalProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, 0);
441
    GLES31.glVertexAttribPointer(mNormalProgram.mAttribute[0], MeshBase.POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, 0);
442 442
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
443 443
    GLES31.glLineWidth(8.0f);
444 444
    GLES31.glDrawArrays(GLES31.GL_LINES, 0, 2*num);
......
454 454

  
455 455
///////////////////////////////////////////////////////////////////////////////////////////////////
456 456

  
457
  void drawPrivOIT(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
457
  void drawPrivOIT(float halfW, float halfH, MeshBase mesh, DistortedOutputSurface surface, long currTime)
458 458
    {
459 459
    float halfZ = halfW*mesh.getZFactor();
460 460

  
......
471 471
    GLES31.glUniform1ui(mMainOITNumRecordsH, (int)(mBufferSize*surface.mWidth*surface.mHeight) );
472 472

  
473 473
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.getVBO() );
474
    GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET0);
475
    GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET1);
476
    GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
474
    GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[0], MeshBase.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET0);
475
    GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[1], MeshBase.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET1);
476
    GLES31.glVertexAttribPointer(mMainOITProgram.mAttribute[2], MeshBase.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET2);
477 477
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
478 478

  
479 479
    mM.send(surface,halfW,halfH,halfZ,0,1);
......
494 494

  
495 495
///////////////////////////////////////////////////////////////////////////////////////////////////
496 496

  
497
  void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
497
  void drawPriv(float halfW, float halfH, MeshBase mesh, DistortedOutputSurface surface, long currTime)
498 498
    {
499 499
    float halfZ = halfW*mesh.getZFactor();
500 500

  
......
509 509
    GLES31.glUniform1i(mMainTextureH, 0);
510 510

  
511 511
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.getVBO() );
512
    GLES31.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET0);
513
    GLES31.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET1);
514
    GLES31.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
512
    GLES31.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshBase.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET0);
513
    GLES31.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshBase.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET1);
514
    GLES31.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshBase.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET2);
515 515
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
516 516

  
517 517
    mM.send(surface,halfW,halfH,halfZ,0,0);
......
931 931
///////////////////////////////////////////////////////////////////////////////////////////////////
932 932
/**
933 933
 * Returns the maximum number of effects of a given type that can be simultaneously applied to a
934
 * single (InputSurface,MeshObject) combo.
934
 * single (InputSurface,MeshBase) combo.
935 935
 *
936 936
 * @param type {@link EffectType}
937 937
 * @return The maximum number of effects of a given type.
src/main/java/org/distorted/library/main/DistortedNode.java
21 21

  
22 22
import android.opengl.GLES31;
23 23

  
24
import org.distorted.library.mesh.MeshObject;
24
import org.distorted.library.mesh.MeshBase;
25 25

  
26 26
import java.util.ArrayList;
27 27
import java.util.Collections;
......
68 68
  private boolean mRenderWayOIT;
69 69
  private DistortedNode mParent;
70 70
  private DistortedOutputSurface mSurfaceParent;
71
  private MeshObject mMesh;
71
  private MeshBase mMesh;
72 72
  private DistortedEffects mEffects;
73 73
  private DistortedSurface mSurface;
74 74
  private DistortedRenderState mState;
......
375 375
 *     
376 376
 * @param surface InputSurface to put into the new Node.
377 377
 * @param effects DistortedEffects to put into the new Node.
378
 * @param mesh MeshObject to put into the new Node.
378
 * @param mesh MeshBase to put into the new Node.
379 379
 */
380
  public DistortedNode(DistortedSurface surface, DistortedEffects effects, MeshObject mesh)
380
  public DistortedNode(DistortedSurface surface, DistortedEffects effects, MeshBase mesh)
381 381
    {
382 382
    mSurface       = surface;
383 383
    mEffects       = effects;
......
559 559
 *
560 560
 * @param surface InputSurface to initialize our child Node with.
561 561
 * @param effects DistortedEffects to initialize our child Node with.
562
 * @param mesh MeshObject to initialize our child Node with.
562
 * @param mesh MeshBase to initialize our child Node with.
563 563
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
564 564
 */
565
  public DistortedNode attach(DistortedSurface surface, DistortedEffects effects, MeshObject mesh)
565
  public DistortedNode attach(DistortedSurface surface, DistortedEffects effects, MeshBase mesh)
566 566
    {
567 567
    DistortedNode node = new DistortedNode(surface,effects,mesh);
568 568
    mJobs.add(new Job(ATTACH,node));
......
748 748
 *
749 749
 * @return Mesh contained in the Node.
750 750
 */
751
  public MeshObject getMesh()
751
  public MeshBase getMesh()
752 752
    {
753 753
    return mMesh;
754 754
    }
src/main/java/org/distorted/library/main/DistortedOutputSurface.java
23 23
import android.opengl.Matrix;
24 24

  
25 25
import org.distorted.library.effect.EffectQuality;
26
import org.distorted.library.mesh.MeshObject;
26
import org.distorted.library.mesh.MeshBase;
27 27

  
28 28
import java.util.ArrayList;
29 29

  
......
921 921
 *
922 922
 * @param surface InputSurface to initialize our child Node with.
923 923
 * @param effects DistortedEffects to initialize our child Node with.
924
 * @param mesh MeshObject to initialize our child Node with.
924
 * @param mesh MeshBase to initialize our child Node with.
925 925
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
926 926
 */
927
  public DistortedNode attach(DistortedSurface surface, DistortedEffects effects, MeshObject mesh)
927
  public DistortedNode attach(DistortedSurface surface, DistortedEffects effects, MeshBase mesh)
928 928
    {
929 929
    DistortedNode node = new DistortedNode(surface,effects,mesh);
930 930
    mJobs.add(new Job(ATTACH,node));
src/main/java/org/distorted/library/main/DistortedScreen.java
27 27
import android.opengl.GLES31;
28 28

  
29 29
import org.distorted.library.effect.MatrixEffectMove;
30
import org.distorted.library.mesh.MeshBase;
30 31
import org.distorted.library.mesh.MeshFlat;
31
import org.distorted.library.mesh.MeshObject;
32 32
import org.distorted.library.type.Static3D;
33 33

  
34 34
/**
......
43 43

  
44 44
  private static final int NUM_FRAMES  = 100;
45 45

  
46
  private MeshObject fpsMesh;
46
  private MeshBase fpsMesh;
47 47
  private DistortedTexture fpsTexture;
48 48
  private DistortedEffects fpsEffects;
49 49
  private Canvas fpsCanvas;
src/main/java/org/distorted/library/main/DistortedSurface.java
21 21

  
22 22
import android.opengl.GLES31;
23 23

  
24
import org.distorted.library.mesh.MeshObject;
24
import org.distorted.library.mesh.MeshBase;
25 25

  
26 26
///////////////////////////////////////////////////////////////////////////////////////////////////
27 27
/**
......
100 100
 *
101 101
 * @return depth of the Object, in pixels.
102 102
 */
103
  public int getDepth(MeshObject mesh)
103
  public int getDepth(MeshBase mesh)
104 104
    {
105 105
    return mesh==null ? 0 : (int)(mWidth*mesh.getZFactor() );
106 106
    }
src/main/java/org/distorted/library/main/EffectQueuePostprocess.java
27 27
import org.distorted.library.effect.EffectType;
28 28
import org.distorted.library.effect.PostprocessEffect;
29 29
import org.distorted.library.effect.VertexEffect;
30
import org.distorted.library.mesh.MeshObject;
30
import org.distorted.library.mesh.MeshBase;
31 31
import org.distorted.library.message.EffectMessage;
32 32
import org.distorted.library.program.DistortedProgram;
33 33

  
......
157 157

  
158 158
    if( input.setAsInput() )
159 159
      {
160
      MeshObject mesh = node.getMesh();
160
      MeshBase mesh = node.getMesh();
161 161
      float    margin = mHalo*buffer.mMipmap;
162 162

  
163 163
      float halfW = input.getWidth() / 2.0f;
......
171 171
      mPreProgram.useProgram();
172 172

  
173 173
      GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.getVBO() );
174
      GLES31.glVertexAttribPointer(mPreProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET0);
175
      GLES31.glVertexAttribPointer(mPreProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET1);
176
      GLES31.glVertexAttribPointer(mPreProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
174
      GLES31.glVertexAttribPointer(mPreProgram.mAttribute[0], MeshBase.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET0);
175
      GLES31.glVertexAttribPointer(mPreProgram.mAttribute[1], MeshBase.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET1);
176
      GLES31.glVertexAttribPointer(mPreProgram.mAttribute[2], MeshBase.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshBase.VERTSIZE, MeshBase.OFFSET2);
177 177
      GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
178 178

  
179 179
      node.getEffects().send(halfW, halfH, halfZ, margin, buffer, 2);
src/main/java/org/distorted/library/mesh/MeshBase.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.library.mesh;
21

  
22
import android.opengl.GLES31;
23

  
24
import org.distorted.library.main.Distorted;
25
import org.distorted.library.main.DistortedBuffer;
26

  
27
import java.nio.FloatBuffer;
28

  
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30
/**
31
 * Abstract class which represents a Mesh, ie 3 arrays of Vertex attributes: 1) positions
32
 * 2) normals 3) texture coordinates.
33
 * <p>
34
 * If you want to render to a particular shape, extend from here, construct the attrib FloatBuffer
35
 * and provide correct numVertices.
36
 */
37
public abstract class MeshBase
38
   {
39
   private static final int BYTES_PER_FLOAT = 4;
40

  
41
   public static final int POS_DATA_SIZE= 3;
42
   public static final int NOR_DATA_SIZE= 3;
43
   public static final int TEX_DATA_SIZE= 2;
44

  
45
   public static final int OFFSET0 =                                                           0;
46
   public static final int OFFSET1 = (POS_DATA_SIZE                            )*BYTES_PER_FLOAT;
47
   public static final int OFFSET2 = (POS_DATA_SIZE+NOR_DATA_SIZE              )*BYTES_PER_FLOAT;
48

  
49
   public static final int TFSIZE  = (POS_DATA_SIZE+POS_DATA_SIZE              )*BYTES_PER_FLOAT;
50
   public static final int VERTSIZE= (POS_DATA_SIZE+NOR_DATA_SIZE+TEX_DATA_SIZE)*BYTES_PER_FLOAT;
51

  
52
   private boolean mShowNormals;       // when rendering this mesh, draw normal vectors?
53
   private DistortedBuffer mVBO, mTFO; // main vertex buffer and transform feedback buffer
54
   private final float zFactor;        // strange workaround for the fact that we need to somehow store the 'depth'
55
                                       // of the Mesh. Used in DistortedEffects. See DistortedTexture.getDepth().
56

  
57
   ////////////////////////////////////////////////////////////////////////////////
58
   // derived classes need to compute and fill up those 2 variables with data
59
   // describing a particular shape. Having done so, call setData()
60
   int numVertices;
61
   FloatBuffer mVertAttribs;   // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, TexS,TexT
62
   ////////////////////////////////////////////////////////////////////////////////
63

  
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

  
66
   MeshBase(float factor)
67
     {
68
     zFactor      = factor;
69
     mShowNormals = false;
70

  
71
     mVBO = new DistortedBuffer(GLES31.GL_ARRAY_BUFFER             , GLES31.GL_STATIC_READ);
72
     mTFO = new DistortedBuffer(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, GLES31.GL_STATIC_READ);
73
     }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// when a derived class is done computing its mesh, it has to call this method.
77

  
78
   void setData(int size, FloatBuffer buffer)
79
     {
80
     mVBO.setData(size*VERTSIZE, buffer);
81
     mTFO.setData(size*TFSIZE  , null  );
82
     }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
/**
86
 * Not part of public API, do not document (public only because has to be used from the main package)
87
 *
88
 * @y.exclude
89
 */
90
   public int getVBO()
91
     {
92
     return mVBO.mIndex[0];
93
     }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
/**
97
 * Not part of public API, do not document (public only because has to be used from the main package)
98
 *
99
 * @y.exclude
100
 */
101
   public int getTFO()
102
     {
103
     return mTFO.mIndex[0];
104
     }
105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
/**
108
 * Not part of public API, do not document (public only because has to be used from the main package)
109
 *
110
 * @y.exclude
111
 */
112
   public int getNumVertices()
113
     {
114
     return numVertices;
115
     }
116

  
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118
/**
119
 * Not part of public API, do not document (public only because has to be used from the main package)
120
 *
121
 * @y.exclude
122
 */
123
   public float getZFactor()
124
     {
125
     return zFactor;
126
     }
127

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
// PUBLIC API
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
/**
132
 * When rendering this Mesh, do we want to render the Normal vectors as well?
133
 * <p>
134
 * Will work only on OpenGL ES >= 3.0 devices.
135
 *
136
 * @param show Controls if we render the Normal vectors or not.
137
 */
138
   public void setShowNormals(boolean show)
139
     {
140
     mShowNormals = (Distorted.GLSL >= 300 && show);
141
     }
142

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
/**
145
 * When rendering this mesh, should we also draw the normal vectors?
146
 *
147
 * @return <i>true</i> if we do render normal vectors
148
 */
149
   public boolean getShowNormals()
150
     {
151
     return mShowNormals;
152
     }
153

  
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155
/**
156
 * Release all internal resources.
157
 */
158
   public void markForDeletion()
159
     {
160
     mVertAttribs.clear();
161

  
162
     mVBO.markForDeletion();
163
     mTFO.markForDeletion();
164
     }
165
   }
166

  
167

  
168

  
src/main/java/org/distorted/library/mesh/MeshCubes.java
29 29
 * <p>
30 30
 * Any subset of a MxNx1 cuboid is possible.
31 31
 */
32
public class MeshCubes extends MeshObject
32
public class MeshCubes extends MeshBase
33 33
   {
34 34
   private static final float R = 0.0f;//0.2f;
35 35

  
src/main/java/org/distorted/library/mesh/MeshFlat.java
29 29
 * Perfect if you just want to display a flat Texture. If you are not planning to apply any VERTEX
30 30
 * effects to it, use MeshFlat(1,1), i.e. a Quad. Otherwise, create more vertices for more realistic effects!
31 31
 */
32
public class MeshFlat extends MeshObject
32
public class MeshFlat extends MeshBase
33 33
  {
34 34
  private int mCols, mRows;
35 35
  private int remainingVert;
src/main/java/org/distorted/library/mesh/MeshObject.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.library.mesh;
21

  
22
import android.opengl.GLES31;
23

  
24
import org.distorted.library.main.Distorted;
25
import org.distorted.library.main.DistortedBuffer;
26

  
27
import java.nio.FloatBuffer;
28

  
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30
/**
31
 * Abstract class which represents a Mesh, ie 3 arrays of Vertex attributes: 1) positions
32
 * 2) normals 3) texture coordinates.
33
 * <p>
34
 * If you want to render to a particular shape, extend from here, construct the attrib FloatBuffer
35
 * and provide correct numVertices.
36
 */
37
public abstract class MeshObject
38
   {
39
   private static final int BYTES_PER_FLOAT = 4;
40

  
41
   public static final int POS_DATA_SIZE= 3;
42
   public static final int NOR_DATA_SIZE= 3;
43
   public static final int TEX_DATA_SIZE= 2;
44

  
45
   public static final int OFFSET0 =                                                           0;
46
   public static final int OFFSET1 = (POS_DATA_SIZE                            )*BYTES_PER_FLOAT;
47
   public static final int OFFSET2 = (POS_DATA_SIZE+NOR_DATA_SIZE              )*BYTES_PER_FLOAT;
48

  
49
   public static final int TFSIZE  = (POS_DATA_SIZE+POS_DATA_SIZE              )*BYTES_PER_FLOAT;
50
   public static final int VERTSIZE= (POS_DATA_SIZE+NOR_DATA_SIZE+TEX_DATA_SIZE)*BYTES_PER_FLOAT;
51

  
52
   private boolean mShowNormals;       // when rendering this mesh, draw normal vectors?
53
   private DistortedBuffer mVBO, mTFO; // main vertex buffer and transform feedback buffer
54
   private final float zFactor;        // strange workaround for the fact that we need to somehow store the 'depth'
55
                                       // of the Mesh. Used in DistortedEffects. See DistortedTexture.getDepth().
56

  
57
   ////////////////////////////////////////////////////////////////////////////////
58
   // derived classes need to compute and fill up those 2 variables with data
59
   // describing a particular shape. Having done so, call setData()
60
   int numVertices;
61
   FloatBuffer mVertAttribs;   // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, TexS,TexT
62
   ////////////////////////////////////////////////////////////////////////////////
63

  
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

  
66
   MeshObject(float factor)
67
     {
68
     zFactor      = factor;
69
     mShowNormals = false;
70

  
71
     mVBO = new DistortedBuffer(GLES31.GL_ARRAY_BUFFER             , GLES31.GL_STATIC_READ);
72
     mTFO = new DistortedBuffer(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, GLES31.GL_STATIC_READ);
73
     }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// when a derived class is done computing its mesh, it has to call this method.
77

  
78
   void setData(int size, FloatBuffer buffer)
79
     {
80
     mVBO.setData(size*VERTSIZE, buffer);
81
     mTFO.setData(size*TFSIZE  , null  );
82
     }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
/**
86
 * Not part of public API, do not document (public only because has to be used from the main package)
87
 *
88
 * @y.exclude
89
 */
90
   public int getVBO()
91
     {
92
     return mVBO.mIndex[0];
93
     }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
/**
97
 * Not part of public API, do not document (public only because has to be used from the main package)
98
 *
99
 * @y.exclude
100
 */
101
   public int getTFO()
102
     {
103
     return mTFO.mIndex[0];
104
     }
105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
/**
108
 * Not part of public API, do not document (public only because has to be used from the main package)
109
 *
110
 * @y.exclude
111
 */
112
   public int getNumVertices()
113
     {
114
     return numVertices;
115
     }
116

  
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118
/**
119
 * Not part of public API, do not document (public only because has to be used from the main package)
120
 *
121
 * @y.exclude
122
 */
123
   public float getZFactor()
124
     {
125
     return zFactor;
126
     }
127

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
// PUBLIC API
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
/**
132
 * When rendering this Mesh, do we want to render the Normal vectors as well?
133
 * <p>
134
 * Will work only on OpenGL ES >= 3.0 devices.
135
 *
136
 * @param show Controls if we render the Normal vectors or not.
137
 */
138
   public void setShowNormals(boolean show)
139
     {
140
     mShowNormals = (Distorted.GLSL >= 300 && show);
141
     }
142

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
/**
145
 * When rendering this mesh, should we also draw the normal vectors?
146
 *
147
 * @return <i>true</i> if we do render normal vectors
148
 */
149
   public boolean getShowNormals()
150
     {
151
     return mShowNormals;
152
     }
153

  
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155
/**
156
 * Release all internal resources.
157
 */
158
   public void markForDeletion()
159
     {
160
     mVertAttribs.clear();
161

  
162
     mVBO.markForDeletion();
163
     mTFO.markForDeletion();
164
     }
165
   }
166

  
167

  
168

  

Also available in: Unified diff