@Override protected void allocParticlesData (int capacity) { vertices = new float[capacity * CPU_VERTEX_SIZE]; if (renderable.meshPart.mesh != null) renderable.meshPart.mesh.dispose(); renderable.meshPart.mesh = new Mesh(false, capacity, 0, CPU_ATTRIBUTES); }
@Override protected void allocParticlesData (int capacity) { vertices = new float[capacity * CPU_VERTEX_SIZE]; if (renderable.meshPart.mesh != null) renderable.meshPart.mesh.dispose(); renderable.meshPart.mesh = new Mesh(false, capacity, 0, CPU_ATTRIBUTES); }
/** End building the mesh and returns the mesh */ public Mesh end () { return end(new Mesh(true, vertices.size / stride, indices.size, attributes)); }
/** End building the mesh and returns the mesh */ public Mesh end () { return end(new Mesh(true, vertices.size / stride, indices.size, attributes)); }
/** Create a ShapeCache with parameters * @param maxVertices max vertices in mesh * @param maxIndices max indices in mesh * @param attributes vertex attributes * @param primitiveType */ public ShapeCache (int maxVertices, int maxIndices, VertexAttributes attributes, int primitiveType) { // Init mesh mesh = new Mesh(false, maxVertices, maxIndices, attributes); // Init builder builder = new MeshBuilder(); // Init renderable renderable.meshPart.mesh = mesh; renderable.meshPart.primitiveType = primitiveType; renderable.material = new Material(); }
/** Create a ShapeCache with parameters * @param maxVertices max vertices in mesh * @param maxIndices max indices in mesh * @param attributes vertex attributes * @param primitiveType */ public ShapeCache (int maxVertices, int maxIndices, VertexAttributes attributes, int primitiveType) { // Init mesh mesh = new Mesh(false, maxVertices, maxIndices, attributes); // Init builder builder = new MeshBuilder(); // Init renderable renderable.meshPart.mesh = mesh; renderable.meshPart.primitiveType = primitiveType; renderable.material = new Material(); }
protected Renderable allocRenderable () { Renderable renderable = new Renderable(); renderable.meshPart.primitiveType = GL20.GL_TRIANGLES; renderable.meshPart.offset = 0; renderable.material = new Material(this.blendingAttribute, this.depthTestAttribute, TextureAttribute.createDiffuse(texture)); renderable.meshPart.mesh = new Mesh(false, MAX_VERTICES_PER_MESH, MAX_PARTICLES_PER_MESH * 6, currentAttributes); renderable.meshPart.mesh.setIndices(indices); renderable.shader = shader; return renderable; }
@Override public void create () { String vertexShader = "attribute vec4 vPosition; \n" + "void main() \n" + "{ \n" + " gl_Position = vPosition; \n" + "} \n"; String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n" + "void main() \n" + "{ \n" + " gl_FragColor = vec4 ( 1.0, 1.0, 1.0, 1.0 );\n" + "}"; shader = new ShaderProgram(vertexShader, fragmentShader); mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "vPosition")); float[] vertices = {0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f}; mesh.setVertices(vertices); }
protected Renderable allocRenderable () { Renderable renderable = new Renderable(); renderable.meshPart.primitiveType = GL20.GL_TRIANGLES; renderable.meshPart.offset = 0; renderable.material = new Material(this.blendingAttribute, this.depthTestAttribute, TextureAttribute.createDiffuse(texture)); renderable.meshPart.mesh = new Mesh(false, MAX_VERTICES_PER_MESH, MAX_PARTICLES_PER_MESH * 6, currentAttributes); renderable.meshPart.mesh.setIndices(indices); renderable.shader = shader; return renderable; }
@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 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(); }
private void createQuad () { if (quad != null) return; quad = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.ColorUnpacked, 4, "a_color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); quad.setVertices(new float[] {-1, -1, 0, 1, 1, 1, 1, 0, 1, 1, -1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 0, 0}); quad.setIndices(new short[] {0, 1, 2, 2, 3, 0}); }
@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; }
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 void create () { mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); float c1 = Color.toFloatBits(255, 0, 0, 255); float c2 = Color.toFloatBits(255, 0, 0, 255); float c3 = Color.toFloatBits(0, 0, 255, 255); mesh.setVertices(new float[] {-0.5f, -0.5f, 0, c1, 0, 0, 0.5f, -0.5f, 0, c2, 1, 0, 0, 0.5f, 0, c3, 0.5f, 1}); stencilMesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute( Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); stencilMesh.setVertices(new float[] {-0.5f, 0.5f, 0, c1, 0, 0, 0.5f, 0.5f, 0, c2, 1, 0, 0, -0.5f, 0, c3, 0.5f, 1}); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); spriteBatch = new SpriteBatch(); frameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false); stencilFrameBuffer = new FrameBuffer(Format.RGB565, 128, 128, true, true); createShader(Gdx.graphics); }
private void createScreenQuad () { if (screenQuad != null) return; screenQuad = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.ColorUnpacked, 4, "a_color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); Vector3 vec0 = new Vector3(0, 0, 0); screenCamera.unproject(vec0); Vector3 vec1 = new Vector3(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0); screenCamera.unproject(vec1); screenQuad.setVertices(new float[] {vec0.x, vec0.y, 0, 1, 1, 1, 1, 0, 1, vec1.x, vec0.y, 0, 1, 1, 1, 1, 1, 1, vec1.x, vec1.y, 0, 1, 1, 1, 1, 1, 0, vec0.x, vec1.y, 0, 1, 1, 1, 1, 0, 0}); screenQuad.setIndices(new short[] {0, 1, 2, 2, 3, 0}); } }
public void setupScene () { plane = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute( Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); plane.setVertices(new float[] {-10, -1, 10, 0, 1, 0, 10, -1, 10, 0, 1, 0, 10, -1, -10, 0, 1, 0, -10, -1, -10, 0, 1, 0}); plane.setIndices(new short[] {3, 2, 1, 1, 0, 3}); texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true); texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0, 5, 10); cam.lookAt(0, 0, 0); cam.update(); controller = new PerspectiveCamController(cam); projector = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); projector.position.set(2, 3, 2); projector.lookAt(0, 0, 0); projector.normalizeUp(); projector.update(); }