/** Flushes vertices[0,verticesPosition[ to GL verticesPosition % Decal.SIZE must equal 0 * * @param verticesPosition Amount of elements from the vertices array to flush */ protected void flush (ShaderProgram shader, int verticesPosition) { mesh.setVertices(vertices, 0, verticesPosition); mesh.render(shader, GL20.GL_TRIANGLES, 0, verticesPosition / 4); }
/** Flushes vertices[0,verticesPosition[ to GL verticesPosition % Decal.SIZE must equal 0 * * @param verticesPosition Amount of elements from the vertices array to flush */ protected void flush (ShaderProgram shader, int verticesPosition) { mesh.setVertices(vertices, 0, verticesPosition); mesh.render(shader, GL20.GL_TRIANGLES, 0, verticesPosition / 4); }
private void updateSimple () { for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { setVertex(y * width + x, getVertexAt(vertex00, x, y)); } } mesh.setVertices(vertices); }
private void updateSmooth () { for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { VertexInfo v = getVertexAt(vertex00, x, y); getWeightedNormalAt(v.normal, x, y); setVertex(y * width + x, v); } } mesh.setVertices(vertices); }
@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); }
@Override public void getRenderables (Array<Renderable> renderables, Pool<Renderable> pool) { renderedChunks = 0; for (int i = 0; i < chunks.length; i++) { VoxelChunk chunk = chunks[i]; Mesh mesh = meshes[i]; if (dirty[i]) { int numVerts = chunk.calculateVertices(vertices); numVertices[i] = numVerts / 4 * 6; mesh.setVertices(vertices, 0, numVerts * VoxelChunk.VERTEX_SIZE); dirty[i] = false; } if (numVertices[i] == 0) continue; Renderable renderable = pool.obtain(); renderable.material = materials[i]; renderable.meshPart.mesh = mesh; renderable.meshPart.offset = 0; renderable.meshPart.size = numVertices[i]; renderable.meshPart.primitiveType = GL20.GL_TRIANGLES; renderables.add(renderable); renderedChunks++; } } }
protected void transformUV (final Matrix3 matrix, final int start, final int count) { final VertexAttribute posAttr = getVertexAttribute(Usage.TextureCoordinates); final int offset = posAttr.offset / 4; final int vertexSize = getVertexSize() / 4; final int numVertices = getNumVertices(); final float[] vertices = new float[numVertices * vertexSize]; // TODO: getVertices(vertices, start * vertexSize, count * vertexSize); getVertices(0, vertices.length, vertices); transformUV(matrix, vertices, vertexSize, offset, start, count); setVertices(vertices, 0, vertices.length); // TODO: setVertices(start * vertexSize, vertices, 0, vertices.length); }
protected void transformUV (final Matrix3 matrix, final int start, final int count) { final VertexAttribute posAttr = getVertexAttribute(Usage.TextureCoordinates); final int offset = posAttr.offset / 4; final int vertexSize = getVertexSize() / 4; final int numVertices = getNumVertices(); final float[] vertices = new float[numVertices * vertexSize]; // TODO: getVertices(vertices, start * vertexSize, count * vertexSize); getVertices(0, vertices.length, vertices); transformUV(matrix, vertices, vertexSize, offset, start, count); setVertices(vertices, 0, vertices.length); // TODO: setVertices(start * vertexSize, vertices, 0, vertices.length); }
public void flush () { if (numVertices == 0) return; shader.begin(); shader.setUniformMatrix("u_projModelView", projModelView); for (int i = 0; i < numTexCoords; i++) shader.setUniformi(shaderUniformNames[i], i); mesh.setVertices(vertices, 0, vertexIdx); mesh.render(shader, primitiveType); shader.end(); numSetTexCoords = 0; vertexIdx = 0; numVertices = 0; }
public void flush () { if (numVertices == 0) return; shader.begin(); shader.setUniformMatrix("u_projModelView", projModelView); for (int i = 0; i < numTexCoords; i++) shader.setUniformi(shaderUniformNames[i], i); mesh.setVertices(vertices, 0, vertexIdx); mesh.render(shader, primitiveType); shader.end(); numSetTexCoords = 0; vertexIdx = 0; numVertices = 0; }
@Override public void flush () { if (vertexIndex == 0) return; renderCalls++; totalRenderCalls++; int trianglesInBatch = triangleIndex; if (trianglesInBatch > maxTrianglesInBatch) maxTrianglesInBatch = trianglesInBatch; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, vertexIndex); mesh.setIndices(triangles, 0, triangleIndex); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, trianglesInBatch); vertexIndex = 0; triangleIndex = 0; }
@Override public void flush () { if (vertexIndex == 0) return; renderCalls++; totalRenderCalls++; int trianglesInBatch = triangleIndex; if (trianglesInBatch > maxTrianglesInBatch) maxTrianglesInBatch = trianglesInBatch; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, vertexIndex); mesh.setIndices(triangles, 0, triangleIndex); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, trianglesInBatch); vertexIndex = 0; triangleIndex = 0; }
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 void flush () { if (idx == 0) return; renderCalls++; totalRenderCalls++; int spritesInBatch = idx / 20; if (spritesInBatch > maxSpritesInBatch) maxSpritesInBatch = spritesInBatch; int count = spritesInBatch * 6; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, idx); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(count); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, count); idx = 0; }
@Override public void flush () { if (idx == 0) return; renderCalls++; totalRenderCalls++; int spritesInBatch = idx / 20; if (spritesInBatch > maxSpritesInBatch) maxSpritesInBatch = spritesInBatch; int count = spritesInBatch * 6; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, idx); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(count); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, count); idx = 0; }
@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}); } }
/** End building the mesh and returns the mesh * @param mesh The mesh to receive the built vertices and indices, must have the same attributes and must be big enough to hold * the data, any existing data will be overwritten. */ public Mesh end (Mesh mesh) { endpart(); if (attributes == null) throw new GdxRuntimeException("Call begin() first"); if (!attributes.equals(mesh.getVertexAttributes())) throw new GdxRuntimeException("Mesh attributes don't match"); if ((mesh.getMaxVertices() * stride) < vertices.size) throw new GdxRuntimeException("Mesh can't hold enough vertices: " + mesh.getMaxVertices() + " * " + stride + " < " + vertices.size); if (mesh.getMaxIndices() < indices.size) throw new GdxRuntimeException("Mesh can't hold enough indices: " + mesh.getMaxIndices() + " < " + indices.size); mesh.setVertices(vertices.items, 0, vertices.size); mesh.setIndices(indices.items, 0, indices.size); for (MeshPart p : parts) p.mesh = mesh; parts.clear(); attributes = null; vertices.clear(); indices.clear(); return mesh; }
/** End building the mesh and returns the mesh * @param mesh The mesh to receive the built vertices and indices, must have the same attributes and must be big enough to hold * the data, any existing data will be overwritten. */ public Mesh end (Mesh mesh) { endpart(); if (attributes == null) throw new GdxRuntimeException("Call begin() first"); if (!attributes.equals(mesh.getVertexAttributes())) throw new GdxRuntimeException("Mesh attributes don't match"); if ((mesh.getMaxVertices() * stride) < vertices.size) throw new GdxRuntimeException("Mesh can't hold enough vertices: " + mesh.getMaxVertices() + " * " + stride + " < " + vertices.size); if (mesh.getMaxIndices() < indices.size) throw new GdxRuntimeException("Mesh can't hold enough indices: " + mesh.getMaxIndices() + " < " + indices.size); mesh.setVertices(vertices.items, 0, vertices.size); mesh.setIndices(indices.items, 0, indices.size); for (MeshPart p : parts) p.mesh = mesh; parts.clear(); attributes = null; vertices.clear(); indices.clear(); return mesh; }
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(); }