use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class VertexBufferObjectWithVAO method bindAttributes.
private void bindAttributes(ShaderProgram shader, int[] locations) {
boolean stillValid = this.cachedLocations.size != 0;
final int numAttributes = attributes.size();
if (stillValid) {
if (locations == null) {
for (int i = 0; stillValid && i < numAttributes; i++) {
VertexAttribute attribute = attributes.get(i);
int location = shader.getAttributeLocation(attribute.alias);
stillValid = location == this.cachedLocations.get(i);
}
} else {
stillValid = locations.length == this.cachedLocations.size;
for (int i = 0; stillValid && i < numAttributes; i++) {
stillValid = locations[i] == this.cachedLocations.get(i);
}
}
}
if (!stillValid) {
Gdx.gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle);
unbindAttributes(shader);
this.cachedLocations.clear();
for (int i = 0; i < numAttributes; i++) {
VertexAttribute attribute = attributes.get(i);
if (locations == null) {
this.cachedLocations.add(shader.getAttributeLocation(attribute.alias));
} else {
this.cachedLocations.add(locations[i]);
}
int location = this.cachedLocations.get(i);
if (location < 0) {
continue;
}
shader.enableVertexAttribute(location);
shader.setVertexAttribute(location, attribute.numComponents, attribute.type, attribute.normalized, attributes.vertexSize, attribute.offset);
}
}
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class VertexBufferObject method bind.
@Override
public void bind(ShaderProgram shader, int[] locations) {
final GL20 gl = Gdx.gl20;
gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle);
if (isDirty) {
byteBuffer.limit(buffer.limit() * 4);
gl.glBufferData(GL20.GL_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage);
isDirty = false;
}
final int numAttributes = attributes.size();
if (locations == null) {
for (int i = 0; i < numAttributes; i++) {
final VertexAttribute attribute = attributes.get(i);
final int location = shader.getAttributeLocation(attribute.alias);
if (location < 0)
continue;
shader.enableVertexAttribute(location);
shader.setVertexAttribute(location, attribute.numComponents, attribute.type, attribute.normalized, attributes.vertexSize, attribute.offset);
}
} else {
for (int i = 0; i < numAttributes; i++) {
final VertexAttribute attribute = attributes.get(i);
final int location = locations[i];
if (location < 0)
continue;
shader.enableVertexAttribute(location);
shader.setVertexAttribute(location, attribute.numComponents, attribute.type, attribute.normalized, attributes.vertexSize, attribute.offset);
}
}
isBound = true;
}
use of com.badlogic.gdx.graphics.VertexAttribute in project nhglib by VoidZombie.
the class ShaderUtils method createPrefix.
public static String createPrefix(Renderable renderable, boolean skinned) {
String prefix = "";
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 == VertexAttributes.Usage.BoneWeight) {
prefix += "#define boneWeight" + attr.unit + "Flag\n";
}
}
if (skinned) {
prefix += "#define skinningFlag\n";
}
Environment environment = renderable.environment;
// Ambient lighting
ColorAttribute ambientLightAttribute = (ColorAttribute) environment.get(ColorAttribute.AmbientLight);
if (ambientLightAttribute != null) {
prefix += "#define ambientLighting\n";
}
// Directional lighting
DirectionalLightsAttribute directionalLightsAttribute = (DirectionalLightsAttribute) environment.get(DirectionalLightsAttribute.Type);
if (directionalLightsAttribute != null) {
Array<DirectionalLight> directionalLights = directionalLightsAttribute.lights;
if (directionalLights.size > 0) {
prefix += "#define numDirectionalLights " + directionalLights.size + "\n";
}
}
// Point lighting
PointLightsAttribute pointLightsAttribute = (PointLightsAttribute) environment.get(PointLightsAttribute.Type);
if (pointLightsAttribute != null) {
Array<PointLight> pointLights = pointLightsAttribute.lights;
if (pointLights.size > 0) {
prefix += "#define numPointLights " + pointLights.size + "\n";
}
}
// Spot lighting
SpotLightsAttribute spotLightsAttribute = (SpotLightsAttribute) environment.get(SpotLightsAttribute.Type);
if (spotLightsAttribute != null) {
Array<SpotLight> spotLights = spotLightsAttribute.lights;
if (spotLights.size > 0) {
prefix += "#define numSpotLights " + spotLights.size + "\n";
}
}
return prefix;
}
Aggregations