use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class BaseShader method init.
/** Initialize this shader, causing all registered uniforms/attributes to be fetched. */
public void init(final ShaderProgram program, final Renderable renderable) {
if (locations != null)
throw new GdxRuntimeException("Already initialized");
if (!program.isCompiled())
throw new GdxRuntimeException(program.getLog());
this.program = program;
final int n = uniforms.size;
locations = new int[n];
for (int i = 0; i < n; i++) {
final String input = uniforms.get(i);
final Validator validator = validators.get(i);
final Setter setter = setters.get(i);
if (validator != null && !validator.validate(this, i, renderable))
locations[i] = -1;
else {
locations[i] = program.fetchUniformLocation(input, false);
if (locations[i] >= 0 && setter != null) {
if (setter.isGlobal(this, i))
globalUniforms.add(i);
else
localUniforms.add(i);
}
}
if (locations[i] < 0) {
validators.set(i, null);
setters.set(i, null);
}
}
if (renderable != null) {
final VertexAttributes attrs = renderable.meshPart.mesh.getVertexAttributes();
final int c = attrs.size();
for (int i = 0; i < c; i++) {
final VertexAttribute attr = attrs.get(i);
final int location = program.getAttributeLocation(attr.alias);
if (location >= 0)
attributes.put(attr.getKey(), location);
}
}
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class G3dModelLoader method parseAttributes.
private VertexAttribute[] parseAttributes(JsonValue attributes) {
Array<VertexAttribute> vertexAttributes = new Array<VertexAttribute>();
int unit = 0;
int blendWeightCount = 0;
for (JsonValue value = attributes.child; value != null; value = value.next) {
String attribute = value.asString();
String attr = (String) attribute;
if (attr.equals("POSITION")) {
vertexAttributes.add(VertexAttribute.Position());
} else if (attr.equals("NORMAL")) {
vertexAttributes.add(VertexAttribute.Normal());
} else if (attr.equals("COLOR")) {
vertexAttributes.add(VertexAttribute.ColorUnpacked());
} else if (attr.equals("COLORPACKED")) {
vertexAttributes.add(VertexAttribute.ColorPacked());
} else if (attr.equals("TANGENT")) {
vertexAttributes.add(VertexAttribute.Tangent());
} else if (attr.equals("BINORMAL")) {
vertexAttributes.add(VertexAttribute.Binormal());
} else if (attr.startsWith("TEXCOORD")) {
vertexAttributes.add(VertexAttribute.TexCoords(unit++));
} else if (attr.startsWith("BLENDWEIGHT")) {
vertexAttributes.add(VertexAttribute.BoneWeight(blendWeightCount++));
} else {
throw new GdxRuntimeException("Unknown vertex attribute '" + attr + "', should be one of position, normal, uv, tangent or binormal");
}
}
return vertexAttributes.toArray(VertexAttribute.class);
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class ImmediateModeRenderer20 method buildVertexAttributes.
private VertexAttribute[] buildVertexAttributes(boolean hasNormals, boolean hasColor, int numTexCoords) {
Array<VertexAttribute> attribs = new Array<VertexAttribute>();
attribs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
if (hasNormals)
attribs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
if (hasColor)
attribs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
for (int i = 0; i < numTexCoords; i++) {
attribs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + i));
}
VertexAttribute[] array = new VertexAttribute[attribs.size];
for (int i = 0; i < attribs.size; i++) array[i] = attribs.get(i);
return array;
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class MeshShaderTest method create.
@Override
public void create() {
String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoord0;\n" + "uniform mat4 u_worldView;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main() \n" + "{ \n" + " v_color = vec4(1, 1, 1, 1); \n" + " v_texCoords = a_texCoord0; \n" + " gl_Position = u_worldView * a_position; \n" + "} \n";
String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "varying vec4 v_color;\n" + "varying vec2 v_texCoords;\n" + "uniform sampler2D u_texture;\n" + "void main() \n" + "{ \n" + " gl_FragColor = v_color * texture2D(u_texture, v_texCoords);\n" + "}";
shader = new ShaderProgram(vertexShader, fragmentShader);
if (shader.isCompiled() == false) {
Gdx.app.log("ShaderTest", shader.getLog());
Gdx.app.exit();
}
mesh = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0));
mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 1, 1, 1, 1, 0, 1, 0.5f, -0.5f, 0, 1, 1, 1, 1, 1, 1, 0.5f, 0.5f, 0, 1, 1, 1, 1, 1, 0, -0.5f, 0.5f, 0, 1, 1, 1, 1, 0, 0 });
mesh.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
//Mesh with texCoords wearing a pair of shorts. :)
meshCustomVA = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute.ColorPacked(), new VertexAttribute(Usage.TextureCoordinates, 2, GL20.GL_UNSIGNED_SHORT, true, ShaderProgram.TEXCOORD_ATTRIBUTE + "0", 0));
meshCustomVA.setVertices(new float[] { -0.5f, -0.5f, 0, FLOAT_WHITE, toSingleFloat(0, 1), 0.5f, -0.5f, 0, FLOAT_WHITE, toSingleFloat(1, 1), 0.5f, 0.5f, 0, FLOAT_WHITE, toSingleFloat(1, 0), -0.5f, 0.5f, 0, FLOAT_WHITE, toSingleFloat(0, 0) });
meshCustomVA.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
texture = new Texture(Gdx.files.internal("data/bobrgb888-32x32.png"));
}
use of com.badlogic.gdx.graphics.VertexAttribute in project libgdx by libgdx.
the class MipMapTest method create.
@Override
public void create() {
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(0, 1.5f, 1.5f);
camera.lookAt(0, 0, 0);
camera.update();
controller = new PerspectiveCamController(camera);
mesh = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE));
mesh.setVertices(new float[] { -1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, -1, 1, 0, -1, 0, -1, 0, 0 });
mesh.setIndices(new short[] { 0, 1, 2, 3 });
shader = new ShaderProgram(Gdx.files.internal("data/shaders/flattex-vert.glsl").readString(), Gdx.files.internal("data/shaders/flattex-frag.glsl").readString());
if (!shader.isCompiled())
throw new GdxRuntimeException("shader error: " + shader.getLog());
textureHW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
MipMapGenerator.setUseHardwareMipMap(false);
textureSW = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
currTexture = textureHW;
createUI();
multiplexer = new InputMultiplexer();
Gdx.input.setInputProcessor(multiplexer);
multiplexer.addProcessor(ui);
multiplexer.addProcessor(controller);
}
Aggregations