Project

General

Profile

Download (3.46 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / GridObject.java @ 1942537e

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 6a06a912 Leszek Koltunski
package org.distorted.library;
21
22
import java.nio.FloatBuffer;
23
24
import android.opengl.GLES20;
25
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27
28 b455eb48 Leszek Koltunski
public abstract class GridObject
29 6a06a912 Leszek Koltunski
   {
30
   protected static final int BYTES_PER_FLOAT   = 4; //
31
   protected static final int POSITION_DATA_SIZE= 3; // Size of the position data in elements
32
   protected static final int NORMAL_DATA_SIZE  = 3; // Size of the normal data in elements.
33
   protected static final int TEX_DATA_SIZE     = 2; // Size of the texture coordinate data in elements. 
34
35 4e2382f3 Leszek Koltunski
   protected int dataLength;
36 ffbf279e Leszek Koltunski
   protected FloatBuffer mGridPositions,mGridNormals,mGridTexture;
37 3ef3364d Leszek Koltunski
38 1942537e Leszek Koltunski
   final float zFactor; // strange workaround for the fact that we need to somehow store the 'depth'
39 3ef3364d Leszek Koltunski
                        // of the Grid. Used in DistortedEffectQueues. See DistortedTexture.getDepth().
40
41 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
42 3ef3364d Leszek Koltunski
43
   GridObject(float factor)
44
     {
45
     zFactor = factor;
46
     }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50 6a06a912 Leszek Koltunski
   void draw()
51
     { 
52
     GLES20.glVertexAttribPointer(Distorted.mPositionH    , POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mGridPositions);          
53
     GLES20.glVertexAttribPointer(Distorted.mNormalH      , NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mGridNormals  );
54
     GLES20.glVertexAttribPointer(Distorted.mTextureCoordH, TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mGridTexture  );  
55
56
     GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, dataLength); 
57
     }
58
   }
59
60
///////////////////////////////////////////////////////////////////////////////////////////////////