optimize this kotlin code in order to maximize performance: fun dumpCache() { if…
- User
optimize this kotlin code in order to maximize performance: fun dumpCache() { if (quadCount == 0) { return } val lastTexture = lastTexture if (lastTexture != null) { if (lastTexture.isLoaded) { // lastTexture.filter = lastFiltering lastTexture.bind(0) } else { quadCount = 0 this.lastTexture = null lastClipRect = null return } } currentDrawCount++ MpGl.glEnable(MpGl.GL_BLEND) if (lastBlendMode == BLEND_NORMAL) { if (renderer.isFboRendering) { // 21 jun 2019 // Reason: Alpha in offscreen buffer (FBO) is applied twice. < //See https://community.khronos.org/t/fbo-and-blending/57555 MpGl.glBlendFuncSeparate( MpGl.GL_SRC_ALPHA, MpGl.GL_ONE_MINUS_SRC_ALPHA, MpGl.GL_ONE, MpGl.GL_ONE_MINUS_SRC_ALPHA ) //> } else { MpGl.glBlendFunc( if (lastIsPmaTexture) { MpGl.GL_ONE } else { MpGl.GL_SRC_ALPHA }, MpGl.GL_ONE_MINUS_SRC_ALPHA ) } } else { MpGl.glBlendFunc(MpGl.GL_SRC_ALPHA, MpGl.GL_ONE) } val lastClipRect = lastClipRect if (lastClipRect != null && lastClipRect.area() > 0) { MpGl.glEnable(MpGl.GL_SCISSOR_TEST) val screenH = (-2.0 / renderer.projection[5]).roundToInt() val x = lastClipRect.x.toInt() val y = lastClipRect.y.toInt() val w = lastClipRect.width.toInt() val h = lastClipRect.height.toInt() MpGl.glScissor(x, screenH - y - h, w, h) }
val shader = if (lastIsPmaTexture) { requestPmaShader() } else { requestDefaultShader() } shader.bind() shader.uniformMat4(Shader.LOCATION_PROJECTION, renderer.projection, 1) // combine for (i in 0 until quadCount*6) { val x = verticesPos[i * VERTEX_SIZE_POS].toRawBits() val y = verticesPos[i * VERTEX_SIZE_POS + 1].toRawBits() val ind = i * VERTEX_SIZE vertices[ind] = (x and 0xFFFF).toShort() vertices[ind + 1] = (x shr 16 and 0xFFFF).toShort() vertices[ind + 2] = (y and 0xFFFF).toShort() vertices[ind + 3] = (y shr 16 and 0xFFFF).toShort() } bufRenderer.renderIndexed(vertices,null,MpGl.GL_TRIANGLES, quadCount*6, quadCount * VERTEX_SIZE * 4) if (lastClipRect != null && lastClipRect.area() > 0) { MpGl.glDisable(MpGl.GL_SCISSOR_TEST) } quadCount = 0 this.lastTexture = null this.lastClipRect = null lastIsPmaTexture = false } - Assistant