/** * 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); } }
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(); }
/** 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()); }
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(); }
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(); }
/** * 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(); }
public void initialize(int paramInt) { int i = 0; this.vertices = new float[paramInt * 24]; Mesh.VertexDataType localVertexDataType = Mesh.VertexDataType.VertexArray; int j = paramInt * 4; int k = paramInt * 6; VertexAttribute[] arrayOfVertexAttribute = new VertexAttribute[3]; arrayOfVertexAttribute[0] = new VertexAttribute(0, 3, "a_position"); arrayOfVertexAttribute[1] = new VertexAttribute(5, 4, "a_color"); arrayOfVertexAttribute[2] = new VertexAttribute(3, 2, "a_texCoord0"); this.mesh = new Mesh(localVertexDataType, false, j, k, arrayOfVertexAttribute); short[] arrayOfShort = new short[paramInt * 6]; for (int m = 0; i < arrayOfShort.length; m += 4) { arrayOfShort[i] = ((short)m); arrayOfShort[(i + 1)] = ((short)(m + 2)); arrayOfShort[(i + 2)] = ((short)(m + 1)); arrayOfShort[(i + 3)] = ((short)(m + 1)); arrayOfShort[(i + 4)] = ((short)(m + 2)); arrayOfShort[(i + 5)] = ((short)(m + 3)); i += 6; } this.mesh.setIndices(arrayOfShort); }
public PolygonSpriteBatch(int paramInt1, int paramInt2, ShaderProgram paramShaderProgram) { this.buffers = new Mesh[paramInt2]; for (int i = 0; i < paramInt2; i++) { Mesh[] arrayOfMesh = this.buffers; Mesh.VertexDataType localVertexDataType = Mesh.VertexDataType.VertexArray; VertexAttribute[] arrayOfVertexAttribute = new VertexAttribute[3]; arrayOfVertexAttribute[0] = new VertexAttribute(0, 2, "a_position"); arrayOfVertexAttribute[1] = new VertexAttribute(5, 4, "a_color"); arrayOfVertexAttribute[2] = new VertexAttribute(3, 2, "a_texCoord0"); arrayOfMesh[i] = new Mesh(localVertexDataType, false, paramInt1, 0, arrayOfVertexAttribute); } this.projectionMatrix.setToOrtho2D(0.0F, 0.0F, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); this.vertices = new float[paramInt1 * 5]; this.mesh = this.buffers[0]; if ((Gdx.graphics.isGL20Available()) && (paramShaderProgram == null)) { this.shader = createDefaultShader(); this.ownsShader = true; return; } this.shader = paramShaderProgram; }
public CircularDrawingStatic(Texture texture, int beginDegrees, int endDegrees) { this.texture = texture; List<VertexAttribute> list = new ArrayList<>(); list.add(VertexAttribute.Position()); list.add(VertexAttribute.ColorUnpacked()); list.add(VertexAttribute.TexCoords(0)); List<Float> lvert = new ArrayList<>(30); int n_vtx = 0; lvert.addAll(Arrays.asList(0f, 0f, 0f, 1f, 1f, 1f, 1f, 0.5f, 0.5f)); n_vtx++; Vector2 vert = new Vector2(); calcAnglePoint(beginDegrees, vert); addVertToList(lvert, vert); n_vtx++; for (int deg = (int)(Math.ceil(beginDegrees / 45.0) * 45); deg < endDegrees / 45 * 45; deg++) { n_vtx++; calcAnglePoint(deg, vert); addVertToList(lvert, vert); } calcAnglePoint(endDegrees, vert); addVertToList(lvert, vert); n_vtx++; mesh = new Mesh(VertexDataType.VertexArray, false, n_vtx, n_vtx, list.toArray(new VertexAttribute[list.size()])); short[] indices = new short[n_vtx]; for (short i = 0; i < n_vtx; i++) indices[i] = i; mesh.setIndices(indices); initialVertices = new float[lvert.size()]; operatedVertices = new float[lvert.size()]; for (int i = 0; i < initialVertices.length; i++) { initialVertices[i] = lvert.get(i); } }
/** * 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 ChainLight(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(); }
/** * Creates directional light which source is at infinite distance, * direction and intensity is same everywhere * * <p>-90 direction is straight from up * * @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 directionDegree * direction in degrees */ public DirectionalLight(RayHandler rayHandler, int rays, Color color, float directionDegree) { super(rayHandler, rays, color, Float.POSITIVE_INFINITY, directionDegree); 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(); } 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 Mesh createFullscreenQuad () { // vertex coord verts[X1] = -1; verts[Y1] = -1; verts[X2] = 1; verts[Y2] = -1; verts[X3] = 1; verts[Y3] = 1; verts[X4] = -1; verts[Y4] = 1; // tex coords verts[U1] = 0f; verts[V1] = 0f; verts[U2] = 1f; verts[V2] = 0f; verts[U3] = 1f; verts[V3] = 1f; verts[U4] = 0f; verts[V4] = 1f; Mesh tmpMesh = new Mesh(VertexDataType.VertexArray, true, 4, 0, new VertexAttribute(Usage.Position, 2, "a_position"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0")); tmpMesh.setVertices(verts); return tmpMesh; }
private Mesh createFullscreenQuad() { // vertex coord verts[X1] = -1; verts[Y1] = -1; verts[X2] = 1; verts[Y2] = -1; verts[X3] = 1; verts[Y3] = 1; verts[X4] = -1; verts[Y4] = 1; // tex coords verts[U1] = 0f; verts[V1] = 0f; verts[U2] = 1f; verts[V2] = 0f; verts[U3] = 1f; verts[V3] = 1f; verts[U4] = 0f; verts[V4] = 1f; Mesh tmpMesh = new Mesh(VertexDataType.VertexArray, true, 4, 0, new VertexAttribute(Usage.Position, 2, "a_position"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0")); tmpMesh.setVertices(verts); return tmpMesh; }
/** Constructs a new SpriteBatch. 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 #createDefaultShader()}. * @param size The max number of sprites in a single batch. Max of 5460. * @param defaultShader The default shader to use. This is not owned by the SpriteBatch and must be disposed separately. */ public SpriteBatch (int size, ShaderProgram defaultShader) { // 32767 is max index, so 32767 / 6 - (32767 / 6 % 3) = 5460. if (size > 5460) throw new IllegalArgumentException("Can't have more than 5460 sprites per batch: " + size); mesh = new Mesh(VertexDataType.VertexArray, false, size * 4, size * 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")); projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); vertices = new float[size * Sprite.SPRITE_SIZE]; int len = size * 6; short[] indices = new short[len]; short j = 0; for (int i = 0; i < len; i += 6, j += 4) { indices[i] = j; 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] = j; } mesh.setIndices(indices); if (defaultShader == null) { shader = createDefaultShader(); ownsShader = true; } else shader = defaultShader; }
@Override public void create () { Preferences pref = Gdx.app.getPreferences("test"); boolean resultb = pref.getBoolean("test"); int resulti = pref.getInteger("test"); shader = new ShaderProgram(Gdx.files.internal("data/shaders/shader-vs.glsl"), Gdx.files.internal("data/shaders/shader-fs.glsl")); if (!shader.isCompiled()) throw new GdxRuntimeException(shader.getLog()); mesh = new Mesh(VertexDataType.VertexBufferObject, true, 6, 0, VertexAttribute.Position(), VertexAttribute.TexCoords(0)); mesh.setVertices(new float[] {-0.5f, -0.5f, 0, 0, 1, 0.5f, -0.5f, 0, 1, 1, 0.5f, 0.5f, 0, 1, 0, 0.5f, 0.5f, 0, 1, 0, -0.5f, 0.5f, 0, 0, 0, -0.5f, -0.5f, 0, 0, 1}); texture = new Texture(new Pixmap(Gdx.files.internal("data/badlogic.jpg")), true); texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear); String params = Gdx.files.internal("data/gwttestparams.txt").readString(); numSprites = Integer.parseInt(params); batch = new SpriteBatch(); positions = new ArrayList<Vector2>(); for (int i = 0; i < numSprites; i++) { positions.add(new Vector2(MathUtils.random() * Gdx.graphics.getWidth(), MathUtils.random() * Gdx.graphics.getHeight())); } sprite = new Sprite(texture); sprite.setSize(64, 64); sprite.setOrigin(32, 32); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); cache = new BitmapFontCache(font); cache.setColor(Color.RED); cache.setMultiLineText("This is a Test", 0, 0); atlas = new TextureAtlas(Gdx.files.internal("data/pack")); }
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]; if (rayHandler.isGL20) { 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")); } else { lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors")); softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors")); } setMesh(); }
private Mesh createFullscreenQuad() { // vertex coord verts[X1] = -1; verts[Y1] = -1; verts[X2] = 1; verts[Y2] = -1; verts[X3] = 1; verts[Y3] = 1; verts[X4] = -1; verts[Y4] = 1; // tex coords verts[U1] = 0f; verts[V1] = 0f; verts[U2] = 1f; verts[V2] = 0f; verts[U3] = 1f; verts[V3] = 1f; verts[U4] = 0f; verts[V4] = 1f; Mesh tmpMesh = new Mesh( VertexDataType.VertexArray, true, 4, 0, new VertexAttribute( Usage.Position, 2, "a_position" ), new VertexAttribute( Usage.TextureCoordinates, 2, "a_texCoord0" ) ); tmpMesh.setVertices( verts ); return tmpMesh; }
/** * Construct a FlexBatch capable of drawing the given Batchable type and other compatible Batchables (ones with the same + * * VertexAttributes or subset of beginning VertexAttributes). The FlexBatch will not be limited to FixedSizeBatchables. * * @param batchableType The type of Batchable that defines the VertexAttributes supported by this FlexBatch, and the + * * default Batchable type drawn by the {@link #draw()} method. * @param maxVertices The number of vertices this FlexBatch can batch at once. Maximum of 32767. If the Batchable is a * FixedSizeBatchable and 0 is used for maxTriangles, this value will be rounded down to a multiple of the * Batchable's size. * @param maxTriangles The number of triangles this FlexBatch can batch at once, or 0 to optimize this FlexBatch to draw only * FixedSizeBatchables. */ public FlexBatch (Class<T> batchableType, int maxVertices, int maxTriangles) { // 32767 is max vertex index. if (maxVertices > 32767) throw new IllegalArgumentException("Can't have more than 32767 vertices per batch: " + maxTriangles); if (Modifier.isAbstract(batchableType.getModifiers())) throw new IllegalArgumentException("Can't use an abstract batchableType"); this.batchableType = batchableType; try { internalBatchable = batchableType.newInstance(); } catch (Exception e) { throw new IllegalArgumentException("Batchable classes must be public and have an empty constructor.", e); } Array<VertexAttribute> attributesArray = new Array<VertexAttribute>(true, 10, VertexAttribute.class); internalBatchable.addVertexAttributes(attributesArray); VertexAttributes vertexAttributes = new VertexAttributes(attributesArray.toArray()); attributeOffsets = new AttributeOffsets(vertexAttributes); vertexSize = vertexAttributes.vertexSize / 4; final int vertexArraySize = vertexSize * maxVertices; vertices = new float[vertexArraySize]; fixedIndices = internalBatchable instanceof FixedSizeBatchable && maxTriangles == 0; if (fixedIndices) { FixedSizeBatchable fixedSizeBatchable = (FixedSizeBatchable) internalBatchable; verticesPerBatchable = fixedSizeBatchable.getVerticesPerBatchable(); vertexDataPerBatchable = verticesPerBatchable * vertexSize; this.maxVertices = maxVertices - (maxVertices % verticesPerBatchable); this.maxIndices = (this.maxVertices / verticesPerBatchable) * fixedSizeBatchable.getTrianglesPerBatchable() * 3; indicesPerBatchable = fixedSizeBatchable.getTrianglesPerBatchable() * 3; triangles = new short[maxIndices]; fixedSizeBatchable.populateTriangleIndices(triangles); } else { if (maxTriangles == 0) throw new IllegalArgumentException( "maxTriangles must be greater than 0 if batchableType is not a FixedSizeBatchable"); this.maxVertices = maxVertices; maxIndices = maxTriangles * 3; triangles = new short[maxIndices]; indicesPerBatchable = verticesPerBatchable = vertexDataPerBatchable = 0; } Mesh.VertexDataType vertexDataType = Gdx.gl30 != null ? VertexDataType.VertexBufferObjectWithVAO : Mesh.VertexDataType.VertexArray; mesh = new Mesh(vertexDataType, false, this.maxVertices, maxIndices, attributesArray.toArray()); if (fixedIndices) mesh.setIndices(triangles); textureUnitUniforms = new String[internalBatchable.getNumberOfTextures()]; for (int i = 0; i < textureUnitUniforms.length; i++) { ; textureUnitUniforms[i] = "u_texture" + i; } projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); renderContext = new RenderContextAccumulator(); renderContext.setBlending(true); renderContext.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); }
/** * Creates new positional light and automatically adds it to the specified * {@link RayHandler} instance. * * @param rayHandler * not 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 * light color * @param distance * light distance (if applicable) * @param x * horizontal position in world coordinates * @param y * vertical position in world coordinates * @param directionDegree * direction in degrees (if applicable) */ public PositionalLight(RayHandler rayHandler, int rays, Color color, float distance, float x, float y, float directionDegree) { super(rayHandler, rays, color, distance, directionDegree); start.x = x; start.y = y; 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(); }