public void unbind() { GL11 localGL11 = Gdx.gl11; int i = this.attributes.size(); int j = 0; int k = 0; if (j < i) { VertexAttribute localVertexAttribute = this.attributes.get(j); switch (localVertexAttribute.usage) { case 4: default: throw new GdxRuntimeException("unkown vertex attribute type: " + localVertexAttribute.usage); case 1: case 5: localGL11.glDisableClientState(32886); case 0: case 2: case 3: } while (true) { j++; break; localGL11.glDisableClientState(32885); continue; localGL11.glClientActiveTexture(33984 + k); localGL11.glDisableClientState(32888); k++; } } localGL11.glBindBuffer(34962, 0); this.isBound = false; }
@Override public void create() { rotationSpeed = 0.5f; mesh = new Mesh(true, 4, 6, new VertexAttribute(VertexAttributes.Usage.Position, 3,"attr_Position"), new VertexAttribute(Usage.TextureCoordinates, 2, "attr_texCoords")); texture = new Texture(Gdx.files.internal("data/Jellyfish.jpg")); mesh.setVertices(new float[] { -1024f, -1024f, 0, 0, 1, 1024f, -1024f, 0, 1, 1, 1024f, 1024f, 0, 1, 0, -1024f, 1024f, 0, 0, 0 }); mesh.setIndices(new short[] { 0, 1, 2, 2, 3, 0 }); cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); xScale = Gdx.graphics.getWidth()/(float)TARGET_WIDTH; yScale = Gdx.graphics.getHeight()/(float)TARGET_HEIGHT; font = loadBitmapFont("default.fnt", "default.png"); scale = Math.min(xScale, yScale); cam.zoom = 1/scale; // cam.project(start_position); cam.position.set(0, 0, 0); batch = new SpriteBatch(); }
/** * Instantiates a new ShaderEffect. The ShaderEffect will NOT own shader * program, so it will not dispose it either! * * @param program * the ShaderProgram to use for this effect */ public ShaderEffect(ShaderProgram program) { this.program = program; if (meshRefCount++ <= 0) { mesh = new Mesh(VertexDataType.VertexArray, true, 4, 0, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); // @formatter:off float[] verts = { // vertex texture -1, -1, 0f, 0f, 1, -1, 1f, 0f, 1, 1, 1f, 1f, -1, 1, 0f, 1f, }; // @formatter:on mesh.setVertices(verts); } }
private String createPrefix(Renderable renderable) { String prefix = ""; if (params.useBones) { prefix += "#define numBones " + 12 + "\n"; 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"; } } } return prefix; }
protected final int[] getAttributeLocations(Renderable renderable) { final IntIntMap attributes = new IntIntMap(); 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); } tempArray.clear(); final int n = attrs.size(); for (int i = 0; i < n; i++) { tempArray.add(attributes.get(attrs.get(i).getKey(), -1)); } return tempArray.items; }
public void makeMesh() { int rayon = Math.max(ExterminateGame.rendu, ExterminateGame.MAX_VIEW_DISTANCE)+5; int nbTriangles=ChunkBuilder.GRIDSIZE*ChunkBuilder.GRIDSIZE*2*rayon*2*rayon*2; int nbVertex=(ChunkBuilder.GRIDSIZE+1)*(ChunkBuilder.GRIDSIZE+1)*rayon*2*rayon*2; FloatBuffer vertexL = org.lwjgl.BufferUtils.createFloatBuffer(nbVertex*ChunkBuilder.SOL_VERTICE_SIZE); IntBuffer indicesL = org.lwjgl.BufferUtils.createIntBuffer(nbTriangles*3); mesh = new UniMesh(true, true, nbVertex, nbTriangles*3, new VertexAttributes(VertexAttribute.Position(), VertexAttribute.NormalPacked(), VertexAttribute.TexCoords(0), VertexAttribute.ColorPacked())); mesh.setVertices(vertexL, 0, nbVertex*ChunkBuilder.SOL_VERTICE_SIZE); mesh.setIndices(indicesL, 0, nbTriangles*3); mesh.setCapacity(0); usedSol = new boolean[rayon*2*rayon*2]; forChunk = new Chunk[rayon*2*rayon*2]; for(int i=0;i<rayon*2*rayon*2;i++) { usedSol[i] = false; } UniVertexBufferObject.showMem(); }
public PositionalLight (RayHandler rayHandler, int rays, Color color, float distance, float x, float y, float directionDegree) { super(rayHandler, rays, color, directionDegree, distance); start.x = x; start.y = y; sin = new float[rays]; cos = new float[rays]; endX = new float[rays]; endY = new float[rays]; lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); setMesh(); }
/** Directional lights simulate light source that locations is at infinite distance. Direction and intensity is same everywhere. * -90 direction is straight from up. * * @param rayHandler * @param rays * @param color * @param directionDegree */ public DirectionalLight (RayHandler rayHandler, int rays, Color color, float directionDegree) { super(rayHandler, rays, color, directionDegree, Float.POSITIVE_INFINITY); vertexNum = (vertexNum - 1) * 2; start = new Vector2[rayNum]; end = new Vector2[rayNum]; for (int i = 0; i < rayNum; i++) { start[i] = new Vector2(); end[i] = new Vector2(); } setDirection(direction); lightMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); softShadowMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); update(); }
/** Creates chain light from specified vertices * * @param rayHandler not {@code null} instance of RayHandler * @param rays number of rays - more rays make light to look more realistic but will decrease performance, can't be less than * MIN_RAYS * @param color color, set to {@code null} to use the default color * @param distance distance of light * @param rayDirection direction of rays * <ul> * <li>1 = left</li> * <li>-1 = right</li> * </ul> * @param chain float array of (x, y) vertices from which rays will be evenly distributed */ public RavChainLight (RayHandler rayHandler, int rays, Color color, float distance, int rayDirection, float[] chain) { super(rayHandler, rays, color, distance, 0f); rayStartOffset = ChainLight.defaultRayStartOffset; this.rayDirection = rayDirection; vertexNum = (vertexNum - 1) * 2; endX = new float[rays]; endY = new float[rays]; startX = new float[rays]; startY = new float[rays]; this.chain = (chain != null) ? new FloatArray(chain) : new FloatArray(); lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); setMesh(); }
private void buildMesh() { mesh = new Mesh(true, SIZE, 6, VertexAttribute.Position(), VertexAttribute.TexCoords(0)); mesh.setVertices(vertices); short[] indices = new short[6]; int v = 0; for (int i = 0; i < indices.length; i += 6, v += 4) { indices[i] = (short)(v); indices[i + 1] = (short)(v + 2); indices[i + 2] = (short)(v + 1); indices[i + 3] = (short)(v + 1); indices[i + 4] = (short)(v + 2); indices[i + 5] = (short)(v + 3); } mesh.setIndices(indices); }
public static Mesh build(float size, TextureRegion region) { Mesh mesh = new Mesh(true, SIZE, 6, VertexAttribute.Position(), VertexAttribute.TexCoords(0)); mesh.setVertices(verticies(size, region)); mesh.setAutoBind(false); short[] indices = new short[6]; int v = 0; for (int i = 0; i < indices.length; i += 6, v += 4) { indices[i] = (short)(v); indices[i + 1] = (short)(v + 2); indices[i + 2] = (short)(v + 1); indices[i + 3] = (short)(v + 1); indices[i + 4] = (short)(v + 2); indices[i + 5] = (short)(v + 3); } mesh.setIndices(indices); return mesh; }
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 boolean canRender (Renderable renderable) { if (renderable.material.has(BlendingAttribute.Type)) { if ((materialMask & BlendingAttribute.Type) != BlendingAttribute.Type) return false; if (renderable.material.has(TextureAttribute.Diffuse) != ((materialMask & TextureAttribute.Diffuse) == TextureAttribute.Diffuse)) return false; } final boolean skinned = ((renderable.mesh.getVertexAttributes().getMask() & Usage.BoneWeight) == Usage.BoneWeight); if (skinned != (numBones > 0)) return false; if (!skinned) return true; int w = 0; final int n = renderable.mesh.getVertexAttributes().size(); for (int i = 0; i < n; i++) { final VertexAttribute attr = renderable.mesh.getVertexAttributes().get(i); if (attr.usage == Usage.BoneWeight) w |= (1 << attr.unit); } return w == weights; }
/** Initializes the batch with the given amount of decal objects the buffer is able to hold when full. * * @param size Maximum size of decal objects to hold in memory */ public void initialize (int size) { vertices = new float[size * Decal.SIZE]; mesh = new Mesh(Mesh.VertexDataType.VertexArray, false, size * 4, size * 6, new VertexAttribute( VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute( VertexAttributes.Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute( VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); short[] indices = new short[size * 6]; int v = 0; for (int i = 0; i < indices.length; i += 6, v += 4) { indices[i] = (short)(v); indices[i + 1] = (short)(v + 2); indices[i + 2] = (short)(v + 1); indices[i + 3] = (short)(v + 1); indices[i + 4] = (short)(v + 2); indices[i + 5] = (short)(v + 3); } mesh.setIndices(indices); }
/** @param usage bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal and * TextureCoordinates is supported. */ public static VertexAttributes createAttributes (long usage) { final Array<VertexAttribute> attrs = new Array<VertexAttribute>(); if ((usage & Usage.Position) == Usage.Position) attrs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE)); if ((usage & Usage.Color) == Usage.Color) attrs.add(new VertexAttribute(Usage.Color, 4, ShaderProgram.COLOR_ATTRIBUTE)); if ((usage & Usage.ColorPacked) == Usage.ColorPacked) attrs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE)); if ((usage & Usage.Normal) == Usage.Normal) attrs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); if ((usage & Usage.TextureCoordinates) == Usage.TextureCoordinates) attrs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); final VertexAttribute attributes[] = new VertexAttribute[attrs.size]; for (int i = 0; i < attributes.length; i++) attributes[i] = attrs.get(i); return new VertexAttributes(attributes); }
/** Constructs a new PolygonSpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards, * x-axis point to the right and the origin being in the bottom left corner of the screen. The projection will be pixel perfect * with respect to the current screen resolution. * <p> * The defaultShader specifies the shader to use. Note that the names for uniforms for this default shader are different than * the ones expect for shaders set with {@link #setShader(ShaderProgram)}. See {@link SpriteBatch#createDefaultShader()}. * @param size The max number of vertices and number of triangles in a single batch. Max of 10920. * @param defaultShader The default shader to use. This is not owned by the PolygonSpriteBatch and must be disposed separately. */ public PolygonSpriteBatch (int size, ShaderProgram defaultShader) { // 32767 is max index, so 32767 / 3 - (32767 / 3 % 3) = 10920. if (size > 10920) throw new IllegalArgumentException("Can't have more than 10920 triangles per batch: " + size); mesh = new Mesh(VertexDataType.VertexArray, false, size, size * 3, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); vertices = new float[size * VERTEX_SIZE]; triangles = new short[size * 3]; if (defaultShader == null) { shader = SpriteBatch.createDefaultShader(); ownsShader = true; } else shader = defaultShader; projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); }
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(); }
@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}); texture = new Texture(Gdx.files.internal("data/bobrgb888-32x32.png")); }
@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, false, true); createShader(Gdx.graphics); }
@Override public void create () { String vertexShader = "attribute vec4 a_position; \n" + "attribute vec4 a_color;\n" + "attribute vec2 a_texCoords;\n" + "varying vec4 v_color;" + "varying vec2 v_texCoords;" + "void main() \n" + "{ \n" + " v_color = vec4(a_color.x, a_color.y, a_color.z, 1); \n" + " v_texCoords = a_texCoords; \n" + " gl_Position = 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); vbo = new VertexBufferObject(true, 3, new VertexAttribute(VertexAttributes.Usage.Position, 2, "a_position"), new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "a_texCoords"), new VertexAttribute( VertexAttributes.Usage.ColorPacked, 4, "a_color")); float[] vertices = new float[] {-1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f), 0, 1, 0.5f, 1.0f, Color.toFloatBits(0f, 1f, 0f, 1f), 1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f)}; vbo.setVertices(vertices, 0, vertices.length); ibo = new IndexBufferObject(true, 3); ibo.setIndices(new short[] {0, 1, 2}, 0, 3); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); }
private void init(String tex0, float w, float h) { setTexture0(tex0); // Init comparator comp = new DistToCameraComparator<IRenderable>(); // Init vertices float[] vertices = new float[20]; fillVertices(vertices, w, h); // We wont need indices if we use GL_TRIANGLE_FAN to draw our quad // TRIANGLE_FAN will draw the verts in this order: 0, 1, 2; 0, 2, 3 mesh = new Mesh(VertexDataType.VertexArray, true, 4, 6, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); mesh.setVertices(vertices, 0, vertices.length); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(6); short[] indices = new short[] { 0, 1, 2, 0, 2, 3 }; mesh.setIndices(indices); quaternion = new Quaternion(); aux = new Vector3(); }
@Override protected void initVertices() { meshes = new MeshData[2]; maxVertices = MAX_VERTICES; // ORIGINAL LINES curr = new MeshData(); meshes[0] = curr; VertexAttribute[] attribs = buildVertexAttributes(); curr.mesh = new Mesh(false, maxVertices, 0, attribs); curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)]; curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4; curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; }
private void initVertices(int index) { if (meshes[index] == null) { currext = new MeshDataExt(); meshes[index] = currext; curr = currext; maxVertices = MAX_VERTICES; currext.maxIndices = maxVertices + maxVertices / 2; VertexAttribute[] attribs = buildVertexAttributes(); currext.mesh = new Mesh(Mesh.VertexDataType.VertexArray, false, maxVertices, currext.maxIndices, attribs); currext.indices = new short[currext.maxIndices]; currext.vertexSize = currext.mesh.getVertexAttributes().vertexSize / 4; currext.vertices = new float[maxVertices * currext.vertexSize]; currext.colorOffset = currext.mesh.getVertexAttribute(Usage.ColorPacked) != null ? currext.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; currext.uvOffset = currext.mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? currext.mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; } else { currext = (MeshDataExt) meshes[index]; curr = currext; } }
@Override protected void initVertices() { meshes = new MeshData[1]; curr = new MeshData(); meshes[0] = curr; aux = new Vector3(); /** Init renderer **/ maxVertices = 3000000; VertexAttribute[] attribs = buildVertexAttributes(); curr.mesh = new Mesh(false, maxVertices, 0, attribs); curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)]; curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4; curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; pmOffset = curr.mesh.getVertexAttribute(Usage.Tangent) != null ? curr.mesh.getVertexAttribute(Usage.Tangent).offset / 4 : 0; sizeOffset = curr.mesh.getVertexAttribute(Usage.Generic) != null ? curr.mesh.getVertexAttribute(Usage.Generic).offset / 4 : 0; }
private void init(float w, float h) { // Init comparator comp = new DistToCameraComparator<IRenderable>(); // Init vertices float[] vertices = new float[20]; fillVertices(vertices, w, h); // We wont need indices if we use GL_TRIANGLE_FAN to draw our quad // TRIANGLE_FAN will draw the verts in this order: 0, 1, 2; 0, 2, 3 mesh = new Mesh(VertexDataType.VertexArray, true, 4, 6, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); mesh.setVertices(vertices, 0, vertices.length); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(6); short[] indices = new short[] { 0, 1, 2, 0, 2, 3 }; mesh.setIndices(indices); quaternion = new Quaternion(); aux = new Vector3(); }
@Override protected void initVertices() { /** STARS **/ meshes = new MeshData[1]; curr = new MeshData(); meshes[0] = curr; aux1 = new Vector3(); maxVertices = 10000000; VertexAttribute[] attribs = buildVertexAttributes(); curr.mesh = new Mesh(false, maxVertices, 0, attribs); curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)]; curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4; curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; pmOffset = curr.mesh.getVertexAttribute(Usage.Tangent) != null ? curr.mesh.getVertexAttribute(Usage.Tangent).offset / 4 : 0; additionalOffset = curr.mesh.getVertexAttribute(Usage.Generic) != null ? curr.mesh.getVertexAttribute(Usage.Generic).offset / 4 : 0; }
/** @param usage bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal and * TextureCoordinates is supported. */ public static VertexAttributes createAttributes(long usage) { final Array<VertexAttribute> attrs = new Array<VertexAttribute>(); if ((usage & Usage.Position) == Usage.Position) attrs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE)); if ((usage & Usage.ColorUnpacked) == Usage.ColorUnpacked) attrs.add(new VertexAttribute(Usage.ColorUnpacked, 4, ShaderProgram.COLOR_ATTRIBUTE)); if ((usage & Usage.ColorPacked) == Usage.ColorPacked) attrs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE)); if ((usage & Usage.Normal) == Usage.Normal) attrs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); if ((usage & Usage.TextureCoordinates) == Usage.TextureCoordinates) attrs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); final VertexAttribute attributes[] = new VertexAttribute[attrs.size]; for (int i = 0; i < attributes.length; i++) attributes[i] = attrs.get(i); return new VertexAttributes(attributes); }
public ImmediateRenderer(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 () { // Init camera this.camera = new PerspectiveCamera(70, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); this.camera.position.set(0,0,-20); this.camera.lookAt(0,0,0); this.camera.near = 0.05f; this.camera.far = 600.0f; this.camera.update(); // Init test shader this.testShader = ShaderLoader.loadShader("test"); // Init test buffer this.testBufferObject = new DynamicVertexBufferObject(3, new VertexAttributes(new VertexAttribute(Usage.Position, 4, "a_position"))); float[] vertices = new float[] { -10,0,0,1,0,2.5f,0,1,10,0,0,1 }; this.testBufferObject.setVertices(vertices, 0, vertices.length); }
public VertexAttribute[] getVertexAttributes() { if (attributes == null){ this.attributes = new ArrayList<VertexAttribute>(); } this.attributes.clear(); if (isUsing(MeshVertexData.AttributeType.Position)) { attributes.add(new VertexAttribute(VertexAttributes.Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE)); } if (isUsing(MeshVertexData.AttributeType.Normal)) { attributes.add(new VertexAttribute(VertexAttributes.Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); } if (isUsing(MeshVertexData.AttributeType.TextureCord)) { attributes.add(new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE+ "0")); } if (isUsing(MeshVertexData.AttributeType.Color)) { attributes.add(new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE)); } return attributes.toArray(new VertexAttribute[attributes.size()]); }
public Renderer20 (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; }
public StaticPlaneSimulationObject(Vector3 planeNormal, float planeConstant, float friction, int width, int height, Texture texture, boolean disposeTexture) { super(); this.texture = texture; this.disposeTexture = disposeTexture; this.mesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "position"), new VertexAttribute( Usage.TextureCoordinates, 2, "texture")); this.mesh.setVertices(new float[] { // Bottom left, tex -width / 2f, -height / 2f, 0, 0, 0, // Bottom right, tex width / 2f, -height / 2f, 0, width, 0, // Top right, tex width / 2f, height / 2f, 0, width, height, // Top left, tex -width / 2f, height / 2f, 0, 0, height }); this.mesh.setIndices(new short[] { 0, 1, 2, 0, 3, 2 }); this.staticPlaneShape = new btStaticPlaneShape(planeNormal, planeConstant); initialize(this.staticPlaneShape, 0, -1, DEFAULT_START_TRANSFORM); }
public InputVisualizer() { eventBuffer = new RingBuffer<MouseEvent>(MAX_EVENTS); eventPool = new ReflectionPool<MouseEvent>(MouseEvent.class); shader = new ShaderProgram( Gdx.files.internal("assets/shaders/visualizer.vert"), Gdx.files.internal("assets/shaders/visualizer.frag")); if (!shader.isCompiled()) { Gdx.app.log("InputVisualizer", shader.getLog()); } evBufferLoc = shader.getUniformLocation("u_mouseEvs[0]"); projMatrixLoc = shader.getUniformLocation("u_projTrans"); if (evBufferLoc == -1) { Gdx.app.log("InputVisualizer", "No uniform with name u_mouseEvents found in shader"); } mesh = new Mesh(false, 4, 4, VertexAttribute.Position()); addListener(new MouseListener()); }
public static void buildMeshes() { if (indices == null) { int len = 3 * 6 * 6 / 3; indices = new short[len]; short j = 0; for (int i = 0; i < len; i += 6, j += 4) { indices[i + 0] = (short) (j + 0); indices[i + 1] = (short) (j + 1); indices[i + 2] = (short) (j + 2); indices[i + 3] = (short) (j + 2); indices[i + 4] = (short) (j + 3); indices[i + 5] = (short) (j + 0); } } for (Voxel v : voxels.values()) { v.mesh = new Mesh(true, 24, indices.length, VertexAttribute.Position(), VertexAttribute.Normal(), VertexAttribute.ColorPacked(), VertexAttribute.TexCoords(0), VertexAttribute.TexCoords(1)); v.mesh.setIndices(indices); verts = new FloatArray(); for (Direction d : Direction.values()) new TextureFace(d, new Vector3(), v.getTextureUV(0, 0, 0, d)).getVertexData(verts); v.mesh.setVertices(verts.items, 0, verts.size); } }
/** * Construct handler that manages everything related to updating and * rendering the lights MINIMUM parameters needed are world where collision * geometry is taken. * * Default setting: culling = true, shadows = true, blur = * true(GL2.0),blurNum = 1, ambientLight = 0.0f; * * * @param world * @param camera * @param maxRayCount * @param fboWidth * @param fboHeigth */ public RayHandler(World world, int fboWidth, int fboHeigth) { this.world = world; isGL20 = Gdx.graphics.isGL20Available(); if (isGL20) { lightMap = new LightMap(this, fboWidth, fboHeigth); lightShader = LightShader.createLightShader(); } else { setGammaCorrection(false); if (Gdx.graphics.getBufferFormat().a == 0) { setShadows(false); } else { box = new Mesh(true, 12, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute( Usage.ColorPacked, 4, "quad_colors")); setShadowBox(); } } }
/** * Directional lights simulate light source that locations is at infinite * distance. Direction and intensity is same everywhere. -90 direction is * straight from up. * * @param rayHandler * @param rays * @param color * @param directionDegree */ public DirectionalLight(RayHandler rayHandler, int rays, Color color, float directionDegree) { super(rayHandler, rays, color, directionDegree, Float.POSITIVE_INFINITY); vertexNum = (vertexNum - 1) * 2; start = new Vector2[rayNum]; end = new Vector2[rayNum]; for (int i = 0; i < rayNum; i++) { start[i] = new Vector2(); end[i] = new Vector2(); } setDirection(direction); lightMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute( Usage.Position, 2, "vertex_positions"), new VertexAttribute( Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute( Usage.Generic, 1, "s")); softShadowMesh = new Mesh(VertexDataType.VertexArray,staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); update(); }
private void setupMesh(Model model, MaterialTileMapping textures) { int numVertices = countModelVertices(model); vertices = new Vertices( numVertices, VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.Normal(), VertexAttribute.TexCoords(0) ); model.calculateBoundingBox(tmpModelBounds); if (scaleToSize != null) { MathHelpers.getScaleFactor(tmpModelBounds.getDimensions(), scaleToSize, tmpScaleFactor); bounds = new BoundingBox().set(Vector3.Zero, scaleToSize); } else { bounds = new BoundingBox().set(Vector3.Zero, tmpModelBounds.getDimensions()); tmpScaleFactor.set(1.0f, 1.0f, 1.0f); } for (int i = 0; i < model.nodes.size; ++i) collectModelNodeVertices(model.nodes.get(i), vertices, textures, color, tmpScaleFactor, positionOffset); }
public BackgroundMesh(float w, float h, float x, float y) { center.x = x; center.y = y; halfWidth = w * 0.5f; halfHeight = h * 0.5f; mesh = new Mesh(true, VERTEX_COUNT, INDEX_COUNT, new VertexAttribute(Usage.Position, 3, "a_position"), //$NON-NLS-1$ new VertexAttribute(Usage.ColorPacked, 4, "a_color")); //$NON-NLS-1$ loadVertices(); mesh.setIndices(new short[] { 0, 1, 2, 3, 4, 5 }); }
public VertexBufferObjectSubData(boolean paramBoolean, int paramInt, VertexAttribute[] paramArrayOfVertexAttribute) { this.isStatic = paramBoolean; this.attributes = new VertexAttributes(paramArrayOfVertexAttribute); this.byteBuffer = BufferUtils.newByteBuffer(paramInt * this.attributes.vertexSize); this.isDirect = true; if (paramBoolean); for (int i = 35044; ; i = 35048) { this.usage = i; this.buffer = this.byteBuffer.asFloatBuffer(); this.bufferHandle = createBufferObject(); this.buffer.flip(); this.byteBuffer.flip(); return; } }