@Override public int compare (Renderable arg0, Renderable arg1) { final VertexAttributes va0 = arg0.meshPart.mesh.getVertexAttributes(); final VertexAttributes va1 = arg1.meshPart.mesh.getVertexAttributes(); final int vc = va0.compareTo(va1); if (vc == 0) { final int mc = arg0.material.compareTo(arg1.material); if (mc == 0) { return arg0.meshPart.primitiveType - arg1.meshPart.primitiveType; } return mc; } return vc; } }
@Override public int compare (Renderable arg0, Renderable arg1) { final VertexAttributes va0 = arg0.meshPart.mesh.getVertexAttributes(); final VertexAttributes va1 = arg1.meshPart.mesh.getVertexAttributes(); final int vc = va0.compareTo(va1); if (vc == 0) { final int mc = arg0.material.compareTo(arg1.material); if (mc == 0) { return arg0.meshPart.primitiveType - arg1.meshPart.primitiveType; } return mc; } return vc; } }
@Override public boolean canRender (final Renderable renderable) { final long renderableMask = combineAttributeMasks(renderable); return (attributesMask == (renderableMask | optionalAttributes)) && (vertexMask == renderable.meshPart.mesh.getVertexAttributes().getMaskWithSizePacked()) && (renderable.environment != null) == lighting; }
@Override public boolean canRender (final Renderable renderable) { return (materialMask == (renderable.material.getMask() | optionalAttributes)) && (vertexMask == renderable.meshPart.mesh.getVertexAttributes().getMask()); }
@Override public boolean canRender (final Renderable renderable) { return (materialMask == (renderable.material.getMask() | optionalAttributes)) && (vertexMask == renderable.meshPart.mesh.getVertexAttributes().getMask()); }
@Override public boolean canRender (final Renderable renderable) { final long renderableMask = combineAttributeMasks(renderable); return (attributesMask == (renderableMask | optionalAttributes)) && (vertexMask == renderable.meshPart.mesh.getVertexAttributes().getMaskWithSizePacked()) && (renderable.environment != null) == lighting; }
public DepthShader (final Renderable renderable, final Config config, final ShaderProgram shaderProgram) { super(renderable, config, shaderProgram); final Attributes attributes = combineAttributes(renderable); this.numBones = renderable.bones == null ? 0 : config.numBones; int w = 0; final int n = renderable.meshPart.mesh.getVertexAttributes().size(); for (int i = 0; i < n; i++) { final VertexAttribute attr = renderable.meshPart.mesh.getVertexAttributes().get(i); if (attr.usage == Usage.BoneWeight) w |= (1 << attr.unit); } weights = w; alphaTestAttribute = new FloatAttribute(FloatAttribute.AlphaTest, config.defaultAlphaTest); }
public DepthShader (final Renderable renderable, final Config config, final ShaderProgram shaderProgram) { super(renderable, config, shaderProgram); final Attributes attributes = combineAttributes(renderable); this.numBones = renderable.bones == null ? 0 : config.numBones; int w = 0; final int n = renderable.meshPart.mesh.getVertexAttributes().size(); for (int i = 0; i < n; i++) { final VertexAttribute attr = renderable.meshPart.mesh.getVertexAttributes().get(i); if (attr.usage == Usage.BoneWeight) w |= (1 << attr.unit); } weights = w; alphaTestAttribute = new FloatAttribute(FloatAttribute.AlphaTest, config.defaultAlphaTest); }
/** Initialize ShapeCache for mesh generation * @param primitiveType OpenGL primitive type */ public MeshPartBuilder begin (int primitiveType) { if (building) throw new GdxRuntimeException("Call end() after calling begin()"); building = true; builder.begin(mesh.getVertexAttributes()); builder.part(id, primitiveType, renderable.meshPart); return builder; }
/** Initialize ShapeCache for mesh generation * @param primitiveType OpenGL primitive type */ public MeshPartBuilder begin (int primitiveType) { if (building) throw new GdxRuntimeException("Call end() after calling begin()"); building = true; builder.begin(mesh.getVertexAttributes()); builder.part(id, primitiveType, renderable.meshPart); return builder; }
public ImmediateModeRenderer20 (int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) { this.maxVertices = maxVertices; this.numTexCoords = numTexCoords; this.shader = shader; VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords); mesh = new Mesh(false, maxVertices, 0, attribs); vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)]; vertexSize = mesh.getVertexAttributes().vertexSize / 4; normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0; colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh .getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; shaderUniformNames = new String[numTexCoords]; for (int i = 0; i < numTexCoords; i++) { shaderUniformNames[i] = "u_sampler" + i; } }
public ImmediateModeRenderer20 (int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) { this.maxVertices = maxVertices; this.numTexCoords = numTexCoords; this.shader = shader; VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords); mesh = new Mesh(false, maxVertices, 0, attribs); vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)]; vertexSize = mesh.getVertexAttributes().vertexSize / 4; normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0; colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh .getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; shaderUniformNames = new String[numTexCoords]; for (int i = 0; i < numTexCoords; i++) { shaderUniformNames[i] = "u_sampler" + i; } }
@Override public Mesh obtain (VertexAttributes vertexAttributes, int vertexCount, int indexCount) { for (int i = 0, n = freeMeshes.size; i < n; ++i) { final Mesh mesh = freeMeshes.get(i); if (mesh.getVertexAttributes().equals(vertexAttributes) && mesh.getMaxVertices() >= vertexCount && mesh.getMaxIndices() >= indexCount) { freeMeshes.removeIndex(i); usedMeshes.add(mesh); return mesh; } } vertexCount = 1 + (int)Short.MAX_VALUE; indexCount = Math.max(1 + (int)Short.MAX_VALUE, 1 << (32 - Integer.numberOfLeadingZeros(indexCount - 1))); Mesh result = new Mesh(false, vertexCount, indexCount, vertexAttributes); usedMeshes.add(result); return result; }
@Override public Mesh obtain (VertexAttributes vertexAttributes, int vertexCount, int indexCount) { for (int i = 0, n = freeMeshes.size; i < n; ++i) { final Mesh mesh = freeMeshes.get(i); if (mesh.getVertexAttributes().equals(vertexAttributes) && mesh.getMaxVertices() >= vertexCount && mesh.getMaxIndices() >= indexCount) { freeMeshes.removeIndex(i); usedMeshes.add(mesh); return mesh; } } vertexCount = 1 + (int)Short.MAX_VALUE; indexCount = Math.max(1 + (int)Short.MAX_VALUE, 1 << (32 - Integer.numberOfLeadingZeros(indexCount - 1))); Mesh result = new Mesh(false, vertexCount, indexCount, vertexAttributes); usedMeshes.add(result); return result; }
public void render (Renderable renderable, final Attributes combinedAttributes) { for (int u, i = 0; i < localUniforms.size; ++i) if (setters.get(u = localUniforms.get(i)) != null) setters.get(u).set(this, u, renderable, combinedAttributes); if (currentMesh != renderable.meshPart.mesh) { if (currentMesh != null) currentMesh.unbind(program, tempArray.items); currentMesh = renderable.meshPart.mesh; currentMesh.bind(program, getAttributeLocations(renderable.meshPart.mesh.getVertexAttributes())); } renderable.meshPart.render(program, false); }
public void render (Renderable renderable, final Attributes combinedAttributes) { for (int u, i = 0; i < localUniforms.size; ++i) if (setters.get(u = localUniforms.get(i)) != null) setters.get(u).set(this, u, renderable, combinedAttributes); if (currentMesh != renderable.meshPart.mesh) { if (currentMesh != null) currentMesh.unbind(program, tempArray.items); currentMesh = renderable.meshPart.mesh; currentMesh.bind(program, getAttributeLocations(renderable.meshPart.mesh.getVertexAttributes())); } renderable.meshPart.render(program, false); }
@Override public Mesh obtain (VertexAttributes vertexAttributes, int vertexCount, int indexCount) { for (int i = 0, n = freeMeshes.size; i < n; ++i) { final Mesh mesh = freeMeshes.get(i); if (mesh.getVertexAttributes().equals(vertexAttributes) && mesh.getMaxVertices() == vertexCount && mesh.getMaxIndices() == indexCount) { freeMeshes.removeIndex(i); usedMeshes.add(mesh); return mesh; } } Mesh result = new Mesh(true, vertexCount, indexCount, vertexAttributes); usedMeshes.add(result); return result; }
@Override public Mesh obtain (VertexAttributes vertexAttributes, int vertexCount, int indexCount) { for (int i = 0, n = freeMeshes.size; i < n; ++i) { final Mesh mesh = freeMeshes.get(i); if (mesh.getVertexAttributes().equals(vertexAttributes) && mesh.getMaxVertices() == vertexCount && mesh.getMaxIndices() == indexCount) { freeMeshes.removeIndex(i); usedMeshes.add(mesh); return mesh; } } Mesh result = new Mesh(true, vertexCount, indexCount, vertexAttributes); usedMeshes.add(result); return result; }
@Override public void addMesh (Mesh mesh, int indexOffset, int numIndices) { if (!attributes.equals(mesh.getVertexAttributes())) throw new GdxRuntimeException("Vertex attributes do not match"); if (numIndices <= 0) return; // silently ignore an empty mesh part // FIXME don't triple copy, instead move the copy to jni int numFloats = mesh.getNumVertices() * stride; tmpVertices.clear(); tmpVertices.ensureCapacity(numFloats); tmpVertices.size = numFloats; mesh.getVertices(tmpVertices.items); tmpIndices.clear(); tmpIndices.ensureCapacity(numIndices); tmpIndices.size = numIndices; mesh.getIndices(indexOffset, numIndices, tmpIndices.items, 0); addMesh(tmpVertices.items, tmpIndices.items, 0, numIndices); }
@Override public void addMesh (Mesh mesh, int indexOffset, int numIndices) { if (!attributes.equals(mesh.getVertexAttributes())) throw new GdxRuntimeException("Vertex attributes do not match"); if (numIndices <= 0) return; // silently ignore an empty mesh part // FIXME don't triple copy, instead move the copy to jni int numFloats = mesh.getNumVertices() * stride; tmpVertices.clear(); tmpVertices.ensureCapacity(numFloats); tmpVertices.size = numFloats; mesh.getVertices(tmpVertices.items); tmpIndices.clear(); tmpIndices.ensureCapacity(numIndices); tmpIndices.size = numIndices; mesh.getIndices(indexOffset, numIndices, tmpIndices.items, 0); addMesh(tmpVertices.items, tmpIndices.items, 0, numIndices); }