Rev 168 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 133 | chris | 1 | package com.gebauz.Bauzoid.graphics; |
| 2 | |||
| 3 | import javax.microedition.khronos.opengles.GL10; |
||
| 4 | |||
| 168 | chris | 5 | import com.gebauz.Bauzoid.graphics.model.SimpleGeometry; |
| 133 | chris | 6 | import com.gebauz.Bauzoid.math.Vector2; |
| 7 | import com.gebauz.Bauzoid.math.Vector3; |
||
| 8 | import com.gebauz.Bauzoid.math.Vector4; |
||
| 9 | |||
| 10 | public class RenderImmediate |
||
| 11 | { |
||
| 12 | public static final int MAX_VERTICES = 512; |
||
| 167 | chris | 13 | private static float mVertices[] = new float[MAX_VERTICES * SimpleGeometry.COORD_ELEMENTS_COUNT]; |
| 14 | private static float mNormals[] = new float[MAX_VERTICES * SimpleGeometry.NORMAL_ELEMENTS_COUNT]; |
||
| 15 | private static float mColors[] = new float[MAX_VERTICES * SimpleGeometry.COLOR_ELEMENTS_COUNT]; |
||
| 16 | private static float mTexCoords[] = new float[MAX_VERTICES * SimpleGeometry.TEX_COORD_ELEMENTS_COUNT]; |
||
| 133 | chris | 17 | |
| 18 | private static Vector3 mCurrentNormal = new Vector3(0.0f, 1.0f, 0.0f); |
||
| 19 | private static Vector4 mCurrentColor = new Vector4(0.0f, 0.0f, 0.0f, 1.0f); |
||
| 20 | private static Vector2 mCurrentTexCoord = new Vector2(0.0f, 0.0f); |
||
| 21 | |||
| 22 | private static short mNumVertices = 0; |
||
| 23 | private static boolean mInsideBeginEnd = false; |
||
| 24 | |||
| 167 | chris | 25 | private static SimpleGeometry mMesh = new SimpleGeometry(); |
| 133 | chris | 26 | private static int mPrimitiveType = GL10.GL_TRIANGLES; |
| 27 | |||
| 28 | private RenderImmediate() |
||
| 29 | { |
||
| 30 | } |
||
| 31 | |||
| 32 | public static void begin(int primitiveType) |
||
| 33 | { |
||
| 34 | if (mInsideBeginEnd) |
||
| 35 | { |
||
| 36 | throw new RuntimeException("Inside begin/end block!"); |
||
| 37 | } |
||
| 38 | |||
| 39 | mInsideBeginEnd = true; |
||
| 40 | mNumVertices = 0; |
||
| 41 | mPrimitiveType = primitiveType; |
||
| 42 | } |
||
| 43 | |||
| 44 | public static void end() |
||
| 45 | { |
||
| 46 | mMesh.setVertices(mVertices); |
||
| 47 | mMesh.setNormals(mNormals); |
||
| 48 | mMesh.setColors(mColors); |
||
| 49 | mMesh.setTexCoords(mTexCoords); |
||
| 50 | |||
| 51 | mMesh.setPrimitiveType(mPrimitiveType); |
||
| 52 | mMesh.render(mNumVertices); |
||
| 53 | |||
| 54 | mInsideBeginEnd = false; |
||
| 55 | mNumVertices = 0; |
||
| 56 | } |
||
| 57 | |||
| 58 | public static void vertex(float x, float y, float z) |
||
| 59 | { |
||
| 167 | chris | 60 | mVertices[mNumVertices * SimpleGeometry.COORD_ELEMENTS_COUNT + 0] = x; |
| 61 | mVertices[mNumVertices * SimpleGeometry.COORD_ELEMENTS_COUNT + 1] = y; |
||
| 62 | mVertices[mNumVertices * SimpleGeometry.COORD_ELEMENTS_COUNT + 2] = z; |
||
| 133 | chris | 63 | |
| 167 | chris | 64 | mNormals[mNumVertices * SimpleGeometry.NORMAL_ELEMENTS_COUNT + 0] = mCurrentNormal.x; |
| 65 | mNormals[mNumVertices * SimpleGeometry.NORMAL_ELEMENTS_COUNT + 1] = mCurrentNormal.y; |
||
| 66 | mNormals[mNumVertices * SimpleGeometry.NORMAL_ELEMENTS_COUNT + 2] = mCurrentNormal.z; |
||
| 133 | chris | 67 | |
| 167 | chris | 68 | mColors[mNumVertices * SimpleGeometry.COLOR_ELEMENTS_COUNT + 0] = mCurrentColor.x; |
| 69 | mColors[mNumVertices * SimpleGeometry.COLOR_ELEMENTS_COUNT + 1] = mCurrentColor.y; |
||
| 70 | mColors[mNumVertices * SimpleGeometry.COLOR_ELEMENTS_COUNT + 2] = mCurrentColor.z; |
||
| 71 | mColors[mNumVertices * SimpleGeometry.COLOR_ELEMENTS_COUNT + 3] = mCurrentColor.w; |
||
| 133 | chris | 72 | |
| 167 | chris | 73 | mTexCoords[mNumVertices * SimpleGeometry.TEX_COORD_ELEMENTS_COUNT + 0] = mCurrentTexCoord.x; |
| 74 | mTexCoords[mNumVertices * SimpleGeometry.TEX_COORD_ELEMENTS_COUNT + 1] = mCurrentTexCoord.y; |
||
| 133 | chris | 75 | |
| 76 | mNumVertices++; |
||
| 77 | } |
||
| 78 | |||
| 79 | public static void normal(float x, float y, float z) |
||
| 80 | { |
||
| 81 | mCurrentNormal.x = x; |
||
| 82 | mCurrentNormal.y = y; |
||
| 83 | mCurrentNormal.z = z; |
||
| 84 | } |
||
| 85 | |||
| 86 | public static void color(float r, float g, float b, float a) |
||
| 87 | { |
||
| 88 | mCurrentColor.x = r; |
||
| 89 | mCurrentColor.y = g; |
||
| 90 | mCurrentColor.z = b; |
||
| 91 | mCurrentColor.w = a; |
||
| 92 | } |
||
| 93 | |||
| 94 | public static void texCoords(float u, float v) |
||
| 95 | { |
||
| 96 | mCurrentTexCoord.x = u; |
||
| 97 | mCurrentTexCoord.y = v; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | |||
| 102 |