@Override public void disableBlending () { if (blendingDisabled) return; flush(); blendingDisabled = true; }
@Override public void setBlendFunctionSeparate (int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha) { if (blendSrcFunc == srcFuncColor && blendDstFunc == dstFuncColor && blendSrcFuncAlpha == srcFuncAlpha && blendDstFuncAlpha == dstFuncAlpha) return; flush(); blendSrcFunc = srcFuncColor; blendDstFunc = dstFuncColor; blendSrcFuncAlpha = srcFuncAlpha; blendDstFuncAlpha = dstFuncAlpha; }
@Override public void setBlendFunctionSeparate (int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha) { if (blendSrcFunc == srcFuncColor && blendDstFunc == dstFuncColor && blendSrcFuncAlpha == srcFuncAlpha && blendDstFuncAlpha == dstFuncAlpha) return; flush(); blendSrcFunc = srcFuncColor; blendDstFunc = dstFuncColor; blendSrcFuncAlpha = srcFuncAlpha; blendDstFuncAlpha = dstFuncAlpha; }
@Override public void enableBlending () { if (!blendingDisabled) return; flush(); blendingDisabled = false; }
@Override public void disableBlending () { if (blendingDisabled) return; flush(); blendingDisabled = true; }
@Override public void enableBlending () { if (!blendingDisabled) return; flush(); blendingDisabled = false; }
@Override public void draw (Texture texture, float[] spriteVertices, int offset, int count) { if (!drawing) throw new IllegalStateException("SpriteBatch.begin must be called before draw."); int verticesLength = vertices.length; int remainingVertices = verticesLength; if (texture != lastTexture) switchTexture(texture); else { remainingVertices -= idx; if (remainingVertices == 0) { flush(); remainingVertices = verticesLength; } } int copyCount = Math.min(remainingVertices, count); System.arraycopy(spriteVertices, offset, vertices, idx, copyCount); idx += copyCount; count -= copyCount; while (count > 0) { offset += copyCount; flush(); copyCount = Math.min(verticesLength, count); System.arraycopy(spriteVertices, offset, vertices, 0, copyCount); idx += copyCount; count -= copyCount; } }
@Override public void draw (Texture texture, float[] spriteVertices, int offset, int count) { if (!drawing) throw new IllegalStateException("SpriteBatch.begin must be called before draw."); int verticesLength = vertices.length; int remainingVertices = verticesLength; if (texture != lastTexture) switchTexture(texture); else { remainingVertices -= idx; if (remainingVertices == 0) { flush(); remainingVertices = verticesLength; } } int copyCount = Math.min(remainingVertices, count); System.arraycopy(spriteVertices, offset, vertices, idx, copyCount); idx += copyCount; count -= copyCount; while (count > 0) { offset += copyCount; flush(); copyCount = Math.min(verticesLength, count); System.arraycopy(spriteVertices, offset, vertices, 0, copyCount); idx += copyCount; count -= copyCount; } }
private void drawAdjusted (Texture texture, float[] spriteVertices, int offset, int count) { if (!drawing) throw new IllegalStateException("CpuSpriteBatch.begin must be called before draw."); if (texture != lastTexture) switchTexture(texture); Affine2 t = adjustAffine; int copyCount = Math.min(vertices.length - idx, count); do { count -= copyCount; while (copyCount > 0) { float x = spriteVertices[offset]; float y = spriteVertices[offset + 1]; vertices[idx] = t.m00 * x + t.m01 * y + t.m02; // x vertices[idx + 1] = t.m10 * x + t.m11 * y + t.m12; // y vertices[idx + 2] = spriteVertices[offset + 2]; // color vertices[idx + 3] = spriteVertices[offset + 3]; // u vertices[idx + 4] = spriteVertices[offset + 4]; // v idx += Sprite.VERTEX_SIZE; offset += Sprite.VERTEX_SIZE; copyCount -= Sprite.VERTEX_SIZE; } if (count > 0) { super.flush(); copyCount = Math.min(vertices.length, count); } } while (count > 0); }
@Override public void setTransformMatrix (Matrix4 transform) { if (drawing) flush(); transformMatrix.set(transform); if (drawing) setupMatrices(); }
protected void switchTexture (Texture texture) { flush(); lastTexture = texture; invTexWidth = 1.0f / texture.getWidth(); invTexHeight = 1.0f / texture.getHeight(); }
@Override public void setTransformMatrix (Matrix4 transform) { if (drawing) flush(); transformMatrix.set(transform); if (drawing) setupMatrices(); }
@Override public void setProjectionMatrix (Matrix4 projection) { if (drawing) flush(); projectionMatrix.set(projection); if (drawing) setupMatrices(); }
@Override public void setProjectionMatrix (Matrix4 projection) { if (drawing) flush(); projectionMatrix.set(projection); if (drawing) setupMatrices(); }
protected void switchTexture (Texture texture) { flush(); lastTexture = texture; invTexWidth = 1.0f / texture.getWidth(); invTexHeight = 1.0f / texture.getHeight(); }
@Override public void end () { if (!drawing) throw new IllegalStateException("SpriteBatch.begin must be called before end."); if (idx > 0) flush(); lastTexture = null; drawing = false; GL20 gl = Gdx.gl; gl.glDepthMask(true); if (isBlendingEnabled()) gl.glDisable(GL20.GL_BLEND); if (customShader != null) customShader.end(); else shader.end(); }
@Override public void end () { if (!drawing) throw new IllegalStateException("SpriteBatch.begin must be called before end."); if (idx > 0) flush(); lastTexture = null; drawing = false; GL20 gl = Gdx.gl; gl.glDepthMask(true); if (isBlendingEnabled()) gl.glDisable(GL20.GL_BLEND); if (customShader != null) customShader.end(); else shader.end(); }
@Override public void setShader (ShaderProgram shader) { if (drawing) { flush(); if (customShader != null) customShader.end(); else this.shader.end(); } customShader = shader; if (drawing) { if (customShader != null) customShader.begin(); else this.shader.begin(); setupMatrices(); } }
@Override public void setShader (ShaderProgram shader) { if (drawing) { flush(); if (customShader != null) customShader.end(); else this.shader.end(); } customShader = shader; if (drawing) { if (customShader != null) customShader.begin(); else this.shader.begin(); setupMatrices(); } }
public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); if (screenshot == null) { int width = Gdx.graphics.getWidth(), height = Gdx.graphics.getHeight(); for (int i = 0; i < 100; i++) batch.draw(badlogic, MathUtils.random(width), MathUtils.random(height)); batch.flush(); FileHandle file = FileHandle.tempFile("screenshot-"); System.out.println(file.file().getAbsolutePath()); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); try { PNG writer = new PNG((int)(pixmap.getWidth() * pixmap.getHeight() * 1.5f)); // writer.setCompression(Deflater.NO_COMPRESSION); writer.write(file, pixmap); writer.write(file, pixmap); // Write twice to make sure the object is reusable. writer.dispose(); } catch (IOException ex) { throw new RuntimeException(ex); } screenshot = new Texture(file); } batch.draw(screenshot, 0, 0); batch.end(); } }