|
1 | 1 | package br.nullexcept.mux.core.texel; |
2 | 2 |
|
| 3 | +import br.nullexcept.mux.C; |
| 4 | +import br.nullexcept.mux.graphics.Color; |
| 5 | +import br.nullexcept.mux.graphics.Paint; |
3 | 6 | import br.nullexcept.mux.graphics.Rect; |
4 | | -import br.nullexcept.mux.utils.Log; |
| 7 | +import br.nullexcept.mux.hardware.GLES; |
5 | 8 | import br.nullexcept.mux.view.View; |
6 | 9 | import br.nullexcept.mux.view.ViewGroup; |
| 10 | +import org.lwjgl.nanovg.NanoVG; |
| 11 | +import org.lwjgl.nanovg.NanoVGGLES2; |
7 | 12 |
|
8 | 13 | import java.util.HashMap; |
9 | 14 | import java.util.List; |
10 | 15 |
|
11 | 16 | class ViewRenderer { |
12 | 17 | private static final int FLAG_REQUIRES_DRAW = WindowContainer.FLAG_REQUIRES_DRAW; |
13 | 18 | private final HashMap<Integer, RenderCache> registry; |
| 19 | + private final GLFramebuffer tmpFramebuffer; |
| 20 | + private final CacheBitmap cacheAlpha = new CacheBitmap(); |
| 21 | + private final Paint tmpPaint = new Paint(); |
| 22 | + private final int img; |
14 | 23 |
|
15 | 24 | ViewRenderer(HashMap<Integer, RenderCache> registry){ |
16 | 25 | this.registry = registry; |
| 26 | + tmpFramebuffer = new GLFramebuffer(1,1); |
| 27 | + img = NanoVGGLES2.nvglCreateImageFromHandle(C.VG_CONTEXT, tmpFramebuffer.getTexture().getTexture(),0,0, NanoVG.NVG_IMAGE_PREMULTIPLIED|NanoVG.NVG_IMAGE_FLIPY); |
17 | 28 | } |
18 | 29 |
|
19 | 30 | public void drawInternal(CanvasTexel canvas, View view){ |
@@ -54,8 +65,19 @@ public void drawInternal(CanvasTexel canvas, View view){ |
54 | 65 | } |
55 | 66 | } |
56 | 67 |
|
57 | | - canvas.begin(); |
58 | | - GLTexel.drawViewLayers(borders,textures, alphas); |
| 68 | + if (view.getAlpha() == 1.0f) { //FAST DRAW |
| 69 | + canvas.begin(); |
| 70 | + GLTexel.drawViewLayers(borders,textures, alphas); |
| 71 | + } else { |
| 72 | + // For draw container with alpha draw in a tmp fbo after draw in view fbo |
| 73 | + tmpFramebuffer.resize(canvas.getWidth(),canvas.getHeight()); |
| 74 | + tmpFramebuffer.bind(); |
| 75 | + tmpFramebuffer.clear(0); |
| 76 | + GLTexel.drawViewLayers(borders,textures, alphas); |
| 77 | + tmpFramebuffer.unbind(); |
| 78 | + canvas.begin(); |
| 79 | + canvas.drawBitmap(0,0, cacheAlpha, tmpPaint); |
| 80 | + } |
59 | 81 | } |
60 | 82 | view.onDrawForeground(canvas); |
61 | 83 | view.subFlag(FLAG_REQUIRES_DRAW); |
@@ -145,4 +167,25 @@ public float[] createMesh(CanvasTexel dest, View view){ |
145 | 167 | return mesh; |
146 | 168 | } |
147 | 169 |
|
| 170 | + public void dispose() { |
| 171 | + tmpFramebuffer.dispose(); |
| 172 | + NanoVG.nvgDeleteImage(C.VG_CONTEXT, img); |
| 173 | + } |
| 174 | + |
| 175 | + private class CacheBitmap extends TexelBitmap { |
| 176 | + @Override |
| 177 | + public int getWidth() { |
| 178 | + return tmpFramebuffer.getWidth(); |
| 179 | + } |
| 180 | + |
| 181 | + @Override |
| 182 | + public int getHeight() { |
| 183 | + return tmpFramebuffer.getHeight(); |
| 184 | + } |
| 185 | + |
| 186 | + @Override |
| 187 | + public int id() { |
| 188 | + return img; |
| 189 | + } |
| 190 | + } |
148 | 191 | } |
0 commit comments