use glCullFace GL_FRONT to avoid having to flip triangles
triangle-jni: some loop optimizations
This commit is contained in:
parent
45b19d6a91
commit
35923938db
@ -41,7 +41,7 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
mylog(buf);
|
mylog(buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
int num_segments = num_points;
|
int num_segments = num_points; // - (closed ? (num_rings - 1) : 0);
|
||||||
in.segmentlist = (int *) malloc(num_segments * 2 * sizeof(int));
|
in.segmentlist = (int *) malloc(num_segments * 2 * sizeof(int));
|
||||||
in.numberofsegments = num_segments;
|
in.numberofsegments = num_segments;
|
||||||
in.numberofholes = num_rings - 1;
|
in.numberofholes = num_rings - 1;
|
||||||
@ -52,8 +52,8 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
rings = (int*) malloc(num_rings * sizeof(int));
|
rings = (int*) malloc(num_rings * sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
int seg = 0;
|
int *seg = in.segmentlist;
|
||||||
int hole = 0;
|
float *hole = in.holelist;
|
||||||
|
|
||||||
int ring;
|
int ring;
|
||||||
int point;
|
int point;
|
||||||
@ -69,7 +69,8 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
// add holes: we need a point inside the hole...
|
// add holes: we need a point inside the hole...
|
||||||
// this is just a heuristic, assuming that two
|
// this is just a heuristic, assuming that two
|
||||||
// 'parallel' lines have a distance of at least
|
// 'parallel' lines have a distance of at least
|
||||||
// 1 unit.
|
// 1 unit. you'll notice when things went wrong
|
||||||
|
// when the hole is rendered instead of the poly
|
||||||
if (ring > 0)
|
if (ring > 0)
|
||||||
{
|
{
|
||||||
int k = point * 2;
|
int k = point * 2;
|
||||||
@ -94,22 +95,24 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
float centerx = cx + vx / 2 - ux;
|
float centerx = cx + vx / 2 - ux;
|
||||||
float centery = cy + vy / 2 - uy;
|
float centery = cy + vy / 2 - uy;
|
||||||
|
|
||||||
snprintf(buf, 128, "a: %f in:(%.2f %.2f) "
|
/* snprintf(buf, 128, "a: %f in:(%.2f %.2f) " */
|
||||||
"cur:(%.2f %.2f), next:(%.2f %.2f)\n",
|
/* "cur:(%.2f %.2f), next:(%.2f %.2f)\n", */
|
||||||
a, centerx, centery, cx, cy, nx,ny);
|
/* a, centerx, centery, cx, cy, nx,ny); */
|
||||||
mylog(buf);
|
/* mylog(buf); */
|
||||||
|
|
||||||
in.holelist[hole++] = centerx;
|
*hole++ = centerx;
|
||||||
in.holelist[hole++] = centery;
|
*hole++ = centery;
|
||||||
}
|
}
|
||||||
|
|
||||||
in.segmentlist[seg++] = point + (num_points - 1);
|
//if (!closed){
|
||||||
in.segmentlist[seg++] = point;
|
*seg++ = point + (num_points - 1);
|
||||||
|
*seg++ = point;
|
||||||
|
//}
|
||||||
|
|
||||||
for (len = point + num_points - 1; point < len; point++)
|
for (len = point + num_points - 1; point < len; point++)
|
||||||
{
|
{
|
||||||
in.segmentlist[seg++] = point;
|
*seg++ = point;
|
||||||
in.segmentlist[seg++] = point + 1;
|
*seg++ = point + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef TESTING
|
#ifdef TESTING
|
||||||
@ -152,24 +155,27 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ----------- fix offset to vertex buffer indices -------------
|
// ----------- fix offset to vertex buffer indices -------------
|
||||||
// scale to stride
|
|
||||||
|
// scale to stride and add offset
|
||||||
short stride = 2;
|
short stride = 2;
|
||||||
int n, m;
|
int n, m;
|
||||||
|
|
||||||
for (i = 0, n = out.numberoftriangles * 3; i < n; i++)
|
|
||||||
out.trianglelist[i] *= stride;
|
|
||||||
|
|
||||||
// correct offsetting is tricky (and probably not a general case):
|
|
||||||
// when a ring has an odd number of points one (or rather two)
|
|
||||||
// additional vertices will be added. so the following rings
|
|
||||||
// needs extra offset...
|
|
||||||
|
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
||||||
short off = offset;
|
INDICE *tri = out.trianglelist;
|
||||||
int add = 0;
|
n = out.numberoftriangles * 3;
|
||||||
int start = 0;
|
|
||||||
|
while (n-- > 0)
|
||||||
|
*tri++ = *tri * stride + offset;
|
||||||
|
|
||||||
|
// correct offsetting is tricky (but this is probably not a
|
||||||
|
// general case):
|
||||||
|
// when a ring has an odd number of points one (or rather two)
|
||||||
|
// additional vertices will be added. so the following rings
|
||||||
|
// needs extra offset...
|
||||||
|
|
||||||
|
int start = offset;
|
||||||
|
|
||||||
for (j = 0, m = in.numberofholes; j < m; j++)
|
for (j = 0, m = in.numberofholes; j < m; j++)
|
||||||
{
|
{
|
||||||
@ -177,35 +183,14 @@ jint Java_org_quake_triangle_TriangleJNI_triangulate(JNIEnv *env, jclass c,
|
|||||||
if (rings[j] % 2 == 0)
|
if (rings[j] % 2 == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
#ifdef TESTING
|
tri = out.trianglelist;
|
||||||
snprintf(buf, 128, "add offset: %d\n", start);
|
n = out.numberoftriangles * 3;
|
||||||
mylog(buf);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i = 0, n = out.numberoftriangles * 3; i < n; i++)
|
for (;n-- > 0; tri++)
|
||||||
if (out.trianglelist[i] >= start)
|
if (*tri >= start)
|
||||||
out.trianglelist[i] += stride;
|
*tri += stride;
|
||||||
|
|
||||||
start += stride;
|
start += stride;
|
||||||
|
|
||||||
#ifdef TESTING
|
|
||||||
for (i = 0; i < out.numberoftriangles; i++)
|
|
||||||
{
|
|
||||||
snprintf(buf, 128, "> %d, %d, %d\n",out.trianglelist[i*3],
|
|
||||||
out.trianglelist[i*3+1],
|
|
||||||
out.trianglelist[i*3+2]);
|
|
||||||
mylog(buf);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// flip direction and add offset
|
|
||||||
for (i = 0, n = out.numberoftriangles * 3; i < n; i += 3)
|
|
||||||
{
|
|
||||||
out.trianglelist[i+0] = out.trianglelist[i+0] + offset;
|
|
||||||
unsigned short tmp = out.trianglelist[i+1];
|
|
||||||
out.trianglelist[i+1] = out.trianglelist[i+2] + offset;
|
|
||||||
out.trianglelist[i+2] = tmp + offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(in.segmentlist);
|
free(in.segmentlist);
|
||||||
|
@ -145,8 +145,8 @@ public class ExtrusionLayer extends Layer {
|
|||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
indices[i++] = first;
|
indices[i++] = first;
|
||||||
indices[i++] = (short) (first + k + 4);
|
|
||||||
indices[i++] = (short) (first + k + 2);
|
indices[i++] = (short) (first + k + 2);
|
||||||
|
indices[i++] = (short) (first + k + 4);
|
||||||
}
|
}
|
||||||
mCurIndices[IND_ROOF].used = i;
|
mCurIndices[IND_ROOF].used = i;
|
||||||
}
|
}
|
||||||
@ -316,12 +316,12 @@ public class ExtrusionLayer extends Layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
indices[ind + 0] = s0;
|
indices[ind + 0] = s0;
|
||||||
indices[ind + 1] = s1;
|
indices[ind + 1] = s2;
|
||||||
indices[ind + 2] = s2;
|
indices[ind + 2] = s1;
|
||||||
|
|
||||||
indices[ind + 3] = s1;
|
indices[ind + 3] = s1;
|
||||||
indices[ind + 4] = s3;
|
indices[ind + 4] = s2;
|
||||||
indices[ind + 5] = s2;
|
indices[ind + 5] = s3;
|
||||||
|
|
||||||
mCurIndices[even].used += 6;
|
mCurIndices[even].used += 6;
|
||||||
even = (even + 1) % 2;
|
even = (even + 1) % 2;
|
||||||
|
@ -184,6 +184,7 @@ public class BuildingOverlay2 extends RenderOverlay {
|
|||||||
GLRenderer.enableVertexArrays(hBuildingVertexPosition, -1);
|
GLRenderer.enableVertexArrays(hBuildingVertexPosition, -1);
|
||||||
|
|
||||||
GLES20.glEnable(GLES20.GL_CULL_FACE);
|
GLES20.glEnable(GLES20.GL_CULL_FACE);
|
||||||
|
GLES20.glCullFace(GLES20.GL_FRONT);
|
||||||
GLES20.glEnable(GLES20.GL_POLYGON_OFFSET_FILL);
|
GLES20.glEnable(GLES20.GL_POLYGON_OFFSET_FILL);
|
||||||
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
|
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
|
||||||
GLES20.glDepthFunc(GLES20.GL_LESS);
|
GLES20.glDepthFunc(GLES20.GL_LESS);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user