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 |
e0b6c593
|
Leszek Koltunski
|
/**
|
28 |
26df012c
|
Leszek Koltunski
|
* Abstract class which represents a Mesh, ie 3 arrays of Vertex attributes: 1) positions
|
29 |
e0b6c593
|
Leszek Koltunski
|
* 2) normals 3) texture coordinates.
|
30 |
|
|
* <p>
|
31 |
|
|
* If you want to render to a particular shape, extend from here, construct the three FloatBuffers and
|
32 |
|
|
* provide correct dataLength, i.e. the number of vertices.
|
33 |
|
|
*/
|
34 |
26df012c
|
Leszek Koltunski
|
public abstract class MeshObject
|
35 |
6a06a912
|
Leszek Koltunski
|
{
|
36 |
|
|
protected static final int BYTES_PER_FLOAT = 4; //
|
37 |
|
|
protected static final int POSITION_DATA_SIZE= 3; // Size of the position data in elements
|
38 |
|
|
protected static final int NORMAL_DATA_SIZE = 3; // Size of the normal data in elements.
|
39 |
|
|
protected static final int TEX_DATA_SIZE = 2; // Size of the texture coordinate data in elements.
|
40 |
|
|
|
41 |
4e2382f3
|
Leszek Koltunski
|
protected int dataLength;
|
42 |
05403bba
|
Leszek Koltunski
|
protected FloatBuffer mMeshPositions, mMeshNormals, mMeshTexture;
|
43 |
3ef3364d
|
Leszek Koltunski
|
|
44 |
1942537e
|
Leszek Koltunski
|
final float zFactor; // strange workaround for the fact that we need to somehow store the 'depth'
|
45 |
26df012c
|
Leszek Koltunski
|
// of the Mesh. Used in DistortedEffects. See DistortedTexture.getDepth().
|
46 |
3ef3364d
|
Leszek Koltunski
|
|
47 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
3ef3364d
|
Leszek Koltunski
|
|
49 |
26df012c
|
Leszek Koltunski
|
MeshObject(float factor)
|
50 |
3ef3364d
|
Leszek Koltunski
|
{
|
51 |
|
|
zFactor = factor;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
6a06a912
|
Leszek Koltunski
|
void draw()
|
57 |
|
|
{
|
58 |
02de77c9
|
Leszek Koltunski
|
GLES20.glVertexAttribPointer(Distorted.mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mMeshPositions);
|
59 |
|
|
GLES20.glVertexAttribPointer(Distorted.mMainProgram.mAttribute[1], NORMAL_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mMeshNormals);
|
60 |
|
|
GLES20.glVertexAttribPointer(Distorted.mMainProgram.mAttribute[2], TEX_DATA_SIZE , GLES20.GL_FLOAT, false, 0, mMeshTexture);
|
61 |
6a06a912
|
Leszek Koltunski
|
|
62 |
|
|
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, dataLength);
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|