/** * Constructs a new interleaved VertexBufferObjectWithVAO. * * @param isStatic whether the vertex data is static. * @param numVertices the maximum number of vertices * @param attributes the {@link com.badlogic.gdx.graphics.VertexAttribute}s. */ public VertexBufferObjectWithVAO (boolean isStatic, int numVertices, VertexAttribute... attributes) { this(isStatic, numVertices, new VertexAttributes(attributes)); }
/** Returns the offset for the first VertexAttribute with the specified usage. * @param usage The usage of the VertexAttribute. */ public int getOffset (int usage, int defaultIfNotFound) { VertexAttribute vertexAttribute = findByUsage(usage); if (vertexAttribute == null) return defaultIfNotFound; return vertexAttribute.offset / 4; }
@Override public boolean canRender (Renderable renderable) { final Attributes attributes = combineAttributes(renderable); if (attributes.has(BlendingAttribute.Type)) { if ((attributesMask & BlendingAttribute.Type) != BlendingAttribute.Type) return false; if (attributes.has(TextureAttribute.Diffuse) != ((attributesMask & TextureAttribute.Diffuse) == TextureAttribute.Diffuse)) return false; } final boolean skinned = ((renderable.meshPart.mesh.getVertexAttributes().getMask() & Usage.BoneWeight) == Usage.BoneWeight); if (skinned != (numBones > 0)) return false; if (!skinned) return true; 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); } return w == weights; }
private void unbindAttributes (ShaderProgram shaderProgram) { if (cachedLocations == null) { return; } int numAttributes = attributes.size(); for (int i = 0; i < numAttributes; i++) { int location = cachedLocations.get(i); if (location < 0) { continue; } shaderProgram.disableVertexAttribute(location); } }
private MeshBuilder getBuilder (final VertexAttributes attributes) { for (final MeshBuilder mb : builders) if (mb.getAttributes().equals(attributes) && mb.lastIndex() < Short.MAX_VALUE / 2) return mb; final MeshBuilder result = new MeshBuilder(); result.begin(attributes); builders.add(result); return result; }
/** Returns the offset for the first VertexAttribute with the specified usage. * @param usage The usage of the VertexAttribute. */ public int getOffset (int usage) { return getOffset(usage, 0); }
@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 (Renderable renderable) { final Attributes attributes = combineAttributes(renderable); if (attributes.has(BlendingAttribute.Type)) { if ((attributesMask & BlendingAttribute.Type) != BlendingAttribute.Type) return false; if (attributes.has(TextureAttribute.Diffuse) != ((attributesMask & TextureAttribute.Diffuse) == TextureAttribute.Diffuse)) return false; } final boolean skinned = ((renderable.meshPart.mesh.getVertexAttributes().getMask() & Usage.BoneWeight) == Usage.BoneWeight); if (skinned != (numBones > 0)) return false; if (!skinned) return true; 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); } return w == weights; }
private void unbindAttributes (ShaderProgram shaderProgram) { if (cachedLocations.size == 0) { return; } int numAttributes = attributes.size(); for (int i = 0; i < numAttributes; i++) { int location = cachedLocations.get(i); if (location < 0) { continue; } shaderProgram.disableVertexAttribute(location); } }
private MeshBuilder getBuilder (final VertexAttributes attributes) { for (final MeshBuilder mb : builders) if (mb.getAttributes().equals(attributes) && mb.lastIndex() < Short.MAX_VALUE / 2) return mb; final MeshBuilder result = new MeshBuilder(); result.begin(attributes); builders.add(result); return result; }
/** Returns the offset for the first VertexAttribute with the specified usage. * @param usage The usage of the VertexAttribute. */ public int getOffset (int usage) { return getOffset(usage, 0); }
@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; }
/** Constructs a new interleaved VertexBufferObject. * * @param isStatic whether the vertex data is static. * @param numVertices the maximum number of vertices * @param attributes the {@link VertexAttribute}s. */ public VertexBufferObject (boolean isStatic, int numVertices, VertexAttribute... attributes) { this(isStatic, numVertices, new VertexAttributes(attributes)); }
/** Returns the offset for the first VertexAttribute with the specified usage. * @param usage The usage of the VertexAttribute. */ public int getOffset (int usage, int defaultIfNotFound) { VertexAttribute vertexAttribute = findByUsage(usage); if (vertexAttribute == null) return defaultIfNotFound; return vertexAttribute.offset / 4; }
private void unbindAttributes (ShaderProgram shaderProgram) { if (cachedLocations == null) { return; } int numAttributes = attributes.size(); for (int i = 0; i < numAttributes; i++) { int location = cachedLocations.get(i); if (location < 0) { continue; } shaderProgram.disableVertexAttribute(location); } }
@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 HeightField (boolean isStatic, int width, int height, boolean smooth, VertexAttributes attributes) { this.posPos = attributes.getOffset(Usage.Position, -1); this.norPos = attributes.getOffset(Usage.Normal, -1); this.uvPos = attributes.getOffset(Usage.TextureCoordinates, -1); this.colPos = attributes.getOffset(Usage.ColorUnpacked, -1); smooth = smooth || (norPos < 0); // cant have sharp edges without normals this.width = width; this.height = height; this.smooth = smooth; this.data = new float[width * height]; this.stride = attributes.vertexSize / 4; final int numVertices = smooth ? width * height : (width - 1) * (height - 1) * 4; final int numIndices = (width - 1) * (height - 1) * 6; this.mesh = new Mesh(isStatic, numVertices, numIndices, attributes); this.vertices = new float[numVertices * stride]; setIndices(); }
this.renderable = renderable; attributesMask = attributes.getMask() | optionalAttributes; vertexMask = renderable.meshPart.mesh.getVertexAttributes().getMaskWithSizePacked();