final void startGeometry(Geometry geom) { if (lineShader != null) lineShader.startGeometry(geom); if (faceShader != null) faceShader.startGeometry(geom); if (pointShader != null) pointShader.startGeometry(geom); if (geom instanceof PointSet) { vertexColor = ((PointSet) geom).getVertexAttributes(Attribute.COLORS); vertexColors = vertexColor != null; if (vertexColors) vertexColorLength = vertexColor.getStorageModel().getDimensions()[1]; // System.out.println("PolygonPipeline.startGeometry("+geom.getName() // +"): colors: "+vertexColors); } else { vertexColor = null; vertexColors = false; } }
private final void compute(int verticesLength) { // boolean isTransparent = shader.getVertexShader().getTransparency() != 0.; if (polygonCount + 1 >= this.polygons.length) increasePolygonCapacity(); Polygon p = polygons[polygonCount++]; p.length = verticesLength; // We store the current shader for later shading p.setShader(shader); for (int i = 0; i < verticesLength; i++) { p.vertices[i] = vertexCount; vertexCount += Polygon.VERTEX_LENGTH; } // sky box shaders need the matrix... environment.setMatrix(matrix); // **** shader.shadePolygon(p, vertexData, environment); int numClip = environment.getNumClippingPlanes(); if (numClip > 0) { ClippingPlaneSoft[] cp = environment.getClippingPlanes(); // Intersector.dehomogenize(p,vertexData); for (int k = 0; k < numClip; k++) { double d = VecMat.dot(cp[k].getNormal(), cp[k].getPoint()); // System.out.println("d "+d); int res = Intersector.clipToHalfspace(p, cp[k].getNormal(), -1, d, this); if (res == -1) { // clipped out p.setShader(null); vertexCount -= p.length * Polygon.VERTEX_LENGTH; polygonCount--; return; } } } for (int i = 0; i < p.length; i++) { perspective.perspective(vertexData, p.vertices[i]); } boolean clippedAway = clipPolygon(); if (!clippedAway) { // if (p.length == 0) // System.out.println("ZEROLENGTH!"); // TODO: check wether we sort before computing this. // boolean isTransparent = (shader.getVertexShader().getTransparency() != // 0.)||shader.hasTexture()||shader.interpolateAlpha(); // shader might have changed after lighting: boolean isTransparent = p.getShader().needsSorting(); //// isTransparent = false; if (triangulate) { PolygonShader ps = p.getShader(); if (polygonCount + 1 >= this.polygons.length) increasePolygonCapacity(); polygonCount--; for (int i = 0, pl = p.length - 2; i < pl; i++) { Polygon pi = polygons[polygonCount++]; pi.length = 3; pi.vertices[0] = p.vertices[0]; pi.vertices[1] = p.vertices[i + 1]; pi.vertices[2] = p.vertices[i + 2]; pi.setShader(ps); if (queueOpaque || isTransparent) { if (sortOpaque || isTransparent) pi.computeCenterZ(vertexData); // pi.computeMaxZ(vertexData); // return; } else { renderer.renderPolygon(pi, vertexData, ps.isOutline()); pi.setShader(null); // TODO:check wether this is save // vertexCount -= p.length * Polygon.VERTEX_LENGTH; polygonCount--; } } return; } else { if (queueOpaque || isTransparent) { if (sortOpaque || isTransparent) p.computeCenterZ(vertexData); // p.computeMaxZ(vertexData); return; } else { renderer.renderPolygon(p, vertexData, p.getShader().isOutline()); } } } // if the polygon was clipped completely or if the polygon was opaque and therefore // rendered already, we can free its resources: p.setShader(null); vertexCount -= p.length * Polygon.VERTEX_LENGTH; polygonCount--; }