Project

General

Profile

« Previous | Next » 

Revision 05403bba

Added by Leszek Koltunski almost 8 years ago

rename all the 'grid' variables to 'mesh'.

View differences:

src/main/java/org/distorted/library/DistortedEffects.java
86 86

  
87 87
///////////////////////////////////////////////////////////////////////////////////////////////////
88 88
   
89
  void drawPriv(float halfInputW, float halfInputH, MeshObject grid, DistortedFramebuffer df, long currTime)
89
  void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df, long currTime)
90 90
    {
91 91
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
92 92

  
93
    float halfZ = halfInputW*grid.zFactor;
93
    float halfZ = halfInputW*mesh.zFactor;
94 94

  
95 95
    mM.compute(currTime);
96 96
    mM.send(df,halfInputW,halfInputH,halfZ);
......
101 101
    mF.compute(currTime);
102 102
    mF.send(halfInputW,halfInputH);
103 103

  
104
    grid.draw();
104
    mesh.draw();
105 105
    }
106 106

  
107 107
///////////////////////////////////////////////////////////////////////////////////////////////////
108 108
   
109
  void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject grid, DistortedFramebuffer df)
109
  void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
110 110
    {
111 111
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
112 112

  
113
    mM.sendZero(df,halfInputW,halfInputH,halfInputW*grid.zFactor);
113
    mM.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
114 114
    mV.sendZero();
115 115
    mF.sendZero();
116 116

  
117
    grid.draw();
117
    mesh.draw();
118 118
    }
119 119
    
120 120
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedFramebuffer.java
261 261

  
262 262
///////////////////////////////////////////////////////////////////////////////////////////////////
263 263
/**
264
 * Draw the (texture,grid,effects) object to the Framebuffer.
264
 * Draw the (texture,mesh,effects) object to the Framebuffer.
265 265
 * <p>
266 266
 * Must be called from a thread holding OpenGL Context.
267 267
 *
268 268
 * @param tex input Texture to use.
269
 * @param grid Class descendant from MeshObject
269
 * @param mesh Class descendant from MeshObject
270 270
 * @param effects The DistortedEffects to use when rendering
271 271
 * @param time Current time, in milliseconds.
272 272
 */
273
  public void renderTo(DistortedTexture tex, MeshObject grid, DistortedEffects effects, long time)
273
  public void renderTo(DistortedTexture tex, MeshObject mesh, DistortedEffects effects, long time)
274 274
    {
275 275
    tex.createTexture();
276 276
    tex.setAsInput();
277 277
    createFBO();
278 278
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
279
    effects.drawPriv(tex.mHalfX, tex.mHalfY, grid, this, time);
279
    effects.drawPriv(tex.mHalfX, tex.mHalfY, mesh, this, time);
280 280
    DistortedFramebuffer.deleteAllMarked();
281 281
    DistortedTexture.deleteAllMarked();
282 282
    }
283 283

  
284 284
///////////////////////////////////////////////////////////////////////////////////////////////////
285 285
/**
286
 * Draw the (framebuffer,grid,effects) object to the Framebuffer.
286
 * Draw the (framebuffer,mesh,effects) object to the Framebuffer.
287 287
 * <p>
288 288
 * Must be called from a thread holding OpenGL Context.
289 289
 *
290 290
 * @param fbo The Framebuffer (previously created with the first constructor, drawing FROM the screen
291 291
 *            is unsupported!) whose COLOR attachment 0 will be used as input texture.
292 292
 *            Please note that rendering from an FBO to itself is unsupported by OpenGL!
293
 * @param grid Class descendant from MeshObject
293
 * @param mesh Class descendant from MeshObject
294 294
 * @param effects The DistortedEffects to use when rendering
295 295
 * @param time Current time, in milliseconds.
296 296
 */
297
  public void renderTo(DistortedFramebuffer fbo, MeshObject grid, DistortedEffects effects, long time)
297
  public void renderTo(DistortedFramebuffer fbo, MeshObject mesh, DistortedEffects effects, long time)
298 298
    {
299 299
    fbo.createFBO();
300 300

  
......
303 303
      createFBO();
304 304
      GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
305 305
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, fbo.texIds[0]);
306
      effects.drawPriv(fbo.mWidth/2, fbo.mHeight/2, grid, this, time);
306
      effects.drawPriv(fbo.mWidth/2, fbo.mHeight/2, mesh, this, time);
307 307
      DistortedFramebuffer.deleteAllMarked();
308 308
      DistortedTexture.deleteAllMarked();
309 309
      }
src/main/java/org/distorted/library/DistortedTexture.java
82 82
      {
83 83
      //android.util.Log.e("Texture", "creating "+mID);
84 84

  
85
      if( mTextureDataH[0]==0 ) GLES20.glGenTextures(1, mTextureDataH, 0);
86

  
87
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
88
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR );
89
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR );
90
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE );
91
      GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE );
85
      if( mTextureDataH[0]==0 )
86
        {
87
        GLES20.glGenTextures(1, mTextureDataH, 0);
88
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
89
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR );
90
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR );
91
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE );
92
        GLES20.glTexParameteri ( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE );
93
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(mBmp), 0);
94
        }
95
      else
96
        {
97
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]);
98
        GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0,0,0,flipBitmap(mBmp));
99
        }
92 100

  
93
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(mBmp), 0);
94 101
      mBmp = null;
95 102
      }
96 103
    }
......
254 261
/**
255 262
 * Returns the depth of the Texture.
256 263
 * <p>
257
 * Admittedly quite a strange method. Why do we need to pass a Grid to it? Because one cannot determine
258
 * 'depth' of a texture when rendered based only on the texture itself, that depends on the Grid it is
264
 * Admittedly quite a strange method. Why do we need to pass a Mesh to it? Because one cannot determine
265
 * 'depth' of a texture when rendered based only on the texture itself, that depends on the Mesh it is
259 266
 * rendered with.
260 267
 *
261 268
 * @return depth of the Object, in pixels.
262 269
 */
263
  public int getDepth(MeshObject grid)
270
  public int getDepth(MeshObject mesh)
264 271
    {
265
    return grid==null ? 0 : (int)(mSizeX*grid.zFactor);
272
    return mesh==null ? 0 : (int)(mSizeX*mesh.zFactor);
266 273
    }
267 274
  }
src/main/java/org/distorted/library/DistortedTree.java
26 26

  
27 27
///////////////////////////////////////////////////////////////////////////////////////////////////
28 28
/**
29
 * Class which represents a Node in a Tree of (Texture,Grid,Effects) objects.
29
 * Class which represents a Node in a Tree of (Texture,Mesh,Effects) objects.
30 30
 *  
31 31
 * Having organized such sets into a Tree, we can then render any Node to any Framebuffer.
32 32
 * That recursively renders the set held in the Node and all its children.
......
36 36
  private static HashMap<ArrayList<Long>,NodeData> mMapNodeID = new HashMap<>();
37 37
  private static long mNextNodeID =0;
38 38

  
39
  private MeshObject mGrid;
39
  private MeshObject mMesh;
40 40
  private DistortedEffects mEffects;
41 41
  private DistortedTexture mTexture;
42 42
  private NodeData mData;
......
222 222
        GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
223 223

  
224 224
        if( mTexture.setAsInput() )
225
          mEffects.drawNoEffectsPriv(mTexture.mHalfX, mTexture.mHalfY, mGrid, mData.mDF);
225
          mEffects.drawNoEffectsPriv(mTexture.mHalfX, mTexture.mHalfY, mMesh, mData.mDF);
226 226

  
227 227
        synchronized(this)
228 228
          {
......
240 240
      mData.mDF.setAsInput();
241 241
      }
242 242

  
243
    mEffects.drawPriv(mTexture.mHalfX, mTexture.mHalfY, mGrid, df, currTime);
243
    mEffects.drawPriv(mTexture.mHalfX, mTexture.mHalfY, mMesh, df, currTime);
244 244
    }
245 245

  
246 246
///////////////////////////////////////////////////////////////////////////////////////////////////
......
251 251
 *     
252 252
 * @param texture DistortedTexture to put into the new Node.
253 253
 * @param effects DistortedEffects to put into the new Node.
254
 * @param grid MeshObject to put into the new Node.
254
 * @param mesh MeshObject to put into the new Node.
255 255
 */
256
  public DistortedTree(DistortedTexture texture, DistortedEffects effects, MeshObject grid)
256
  public DistortedTree(DistortedTexture texture, DistortedEffects effects, MeshObject mesh)
257 257
    {
258 258
    mTexture= texture;
259 259
    mEffects= effects;
260
    mGrid   = grid;
260
    mMesh   = mesh;
261 261
    mParent = null;
262 262
    mChildren = null;
263 263
    mNumChildren = new int[1];
......
293 293
    {
294 294
    mParent = null;
295 295
    mEffects= new DistortedEffects(node.mEffects,flags);
296
    mGrid   = node.mGrid;
296
    mMesh = node.mMesh;
297 297

  
298 298
    if( (flags & Distorted.CLONE_BITMAP) != 0 )
299 299
      {
......
355 355
 * 
356 356
 * @param texture DistortedTexture to initialize our child Node with.
357 357
 * @param effects DistortedEffects to initialize our child Node with.
358
 * @param grid MeshObject to initialize our child Node with.
358
 * @param mesh MeshObject to initialize our child Node with.
359 359
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
360 360
 */
361
  public synchronized DistortedTree attach(DistortedTexture texture, DistortedEffects effects, MeshObject grid)
361
  public synchronized DistortedTree attach(DistortedTexture texture, DistortedEffects effects, MeshObject mesh)
362 362
    {
363 363
    ArrayList<Long> prev = generateIDList(); 
364 364
      
365 365
    if( mChildren==null ) mChildren = new ArrayList<>(2);
366
    DistortedTree node = new DistortedTree(texture,effects,grid);
366
    DistortedTree node = new DistortedTree(texture,effects,mesh);
367 367
    node.mParent = this;
368 368
    mChildren.add(node);
369 369
    mNumChildren[0]++;
src/main/java/org/distorted/library/MeshCubes.java
730 730
     if( remainingVert!=0 )
731 731
       android.util.Log.d("CUBES", "remainingVert " +remainingVert );
732 732

  
733
     mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
734
     mGridPositions.put(positionData).position(0);
733
     mMeshPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
734
     mMeshPositions.put(positionData).position(0);
735 735

  
736
     mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
737
     mGridNormals.put(normalData).position(0);
736
     mMeshNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
737
     mMeshNormals.put(normalData).position(0);
738 738

  
739
     mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
740
     mGridTexture.put(textureData).position(0);
739
     mMeshTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
740
     mMeshTexture.put(textureData).position(0);
741 741
     }
742 742

  
743 743
///////////////////////////////////////////////////////////////////////////////////////////////////
744 744
// PUBLIC API
745 745
///////////////////////////////////////////////////////////////////////////////////////////////////
746 746
/**
747
 * Creates the underlying grid of vertices, normals, texture coords.
747
 * Creates the underlying mesh of vertices, normals, texture coords.
748 748
 *    
749 749
 * @param cols      Integer helping to parse the next parameter.
750 750
 * @param desc      String describing the subset of a MxNx1 cuboid that we want to create.
......
776 776

  
777 777
///////////////////////////////////////////////////////////////////////////////////////////////////
778 778
/**
779
 * Creates a full, hole-less underlying grid of vertices, normals, texture coords and colors.
779
 * Creates a full, hole-less underlying mesh of vertices, normals, texture coords and colors.
780 780
 *
781 781
 * @param cols      Number of columns.
782 782
 * @param rows      Number of rows.
src/main/java/org/distorted/library/MeshFlat.java
24 24

  
25 25
///////////////////////////////////////////////////////////////////////////////////////////////////
26 26
/**
27
 * Create a flat, rectangular Grid.
27
 * Create a flat, rectangular grid.
28 28
 * <p>
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!
......
184 184
      if( remainingVert!=0 )
185 185
        android.util.Log.d("BITMAP", "remainingVert " +remainingVert );
186 186

  
187
      mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
188
      mGridPositions.put(positionData).position(0);
187
      mMeshPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
188
      mMeshPositions.put(positionData).position(0);
189 189

  
190
      mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
191
      mGridNormals.put(normalData).position(0);
190
      mMeshNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
191
      mMeshNormals.put(normalData).position(0);
192 192

  
193
      mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
194
      mGridTexture.put(textureData).position(0);
193
      mMeshTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
194
      mMeshTexture.put(textureData).position(0);
195 195
      }
196 196
  }
src/main/java/org/distorted/library/MeshObject.java
39 39
   protected static final int TEX_DATA_SIZE     = 2; // Size of the texture coordinate data in elements. 
40 40

  
41 41
   protected int dataLength;
42
   protected FloatBuffer mGridPositions,mGridNormals,mGridTexture;
42
   protected FloatBuffer mMeshPositions, mMeshNormals, mMeshTexture;
43 43

  
44 44
   final float zFactor; // strange workaround for the fact that we need to somehow store the 'depth'
45 45
                        // of the Mesh. Used in DistortedEffects. See DistortedTexture.getDepth().
......
55 55

  
56 56
   void draw()
57 57
     { 
58
     GLES20.glVertexAttribPointer(Distorted.mMainProgramAttributes[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mGridPositions);
59
     GLES20.glVertexAttribPointer(Distorted.mMainProgramAttributes[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mGridNormals  );
60
     GLES20.glVertexAttribPointer(Distorted.mMainProgramAttributes[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mGridTexture  );
58
     GLES20.glVertexAttribPointer(Distorted.mMainProgramAttributes[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mMeshPositions);
59
     GLES20.glVertexAttribPointer(Distorted.mMainProgramAttributes[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mMeshNormals);
60
     GLES20.glVertexAttribPointer(Distorted.mMainProgramAttributes[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mMeshTexture);
61 61

  
62 62
     GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, dataLength); 
63 63
     }

Also available in: Unified diff