Main repository of MikuMikuStudio
Revision | e9a605974100af99c1f34f4533f8d73c031ad03a (tree) |
---|---|
Time | 2013-07-06 10:37:51 |
Author | Kazuhiko Kobayashi <chototsu_moushinp@yaho...> |
Commiter | kobayasi |
Update renderer.
@@ -75,7 +75,7 @@ import java.util.logging.Level; | ||
75 | 75 | import java.util.logging.Logger; |
76 | 76 | import javax.microedition.khronos.opengles.GL10; |
77 | 77 | |
78 | -public class OGLESShaderRenderer implements Renderer { | |
78 | +public final class OGLESShaderRenderer implements Renderer { | |
79 | 79 | |
80 | 80 | private static final Logger logger = Logger.getLogger(OGLESShaderRenderer.class.getName()); |
81 | 81 | private static final boolean VALIDATE_SHADER = false; |
@@ -1691,6 +1691,7 @@ public class OGLESShaderRenderer implements Renderer { | ||
1691 | 1691 | |
1692 | 1692 | public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) { |
1693 | 1693 | logger.warning("readFrameBuffer is not supported."); |
1694 | + GLES20.glReadPixels(vpX, vpY, vpW, vpH, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, byteBuf); | |
1694 | 1695 | } |
1695 | 1696 | /* |
1696 | 1697 | public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf){ |
@@ -2017,20 +2018,18 @@ public class OGLESShaderRenderer implements Renderer { | ||
2017 | 2018 | Image[] textures = context.boundTextures; |
2018 | 2019 | |
2019 | 2020 | int type = convertTextureType(tex.getType()); |
2020 | - if (!context.textureIndexList.moveToNew(unit)) { | |
2021 | +// if (!context.textureIndexList.moveToNew(unit)) { | |
2021 | 2022 | // if (context.boundTextureUnit != unit){ |
2022 | 2023 | // glActiveTexture(GL_TEXTURE0 + unit); |
2023 | 2024 | // context.boundTextureUnit = unit; |
2024 | 2025 | // } |
2025 | 2026 | // glEnable(type); |
2026 | - } | |
2027 | +// } | |
2027 | 2028 | |
2028 | 2029 | if (context.boundTextureUnit != unit) { |
2029 | 2030 | if (verboseLogging) { |
2030 | 2031 | logger.info("GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + " + unit + ")"); |
2031 | 2032 | } |
2032 | - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + unit); | |
2033 | - context.boundTextureUnit = unit; | |
2034 | 2033 | } |
2035 | 2034 | if (textures[unit] != image) { |
2036 | 2035 |
@@ -2038,6 +2037,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
2038 | 2037 | logger.info("GLES20.glBindTexture(" + type + ", " + texId + ")"); |
2039 | 2038 | } |
2040 | 2039 | |
2040 | + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + unit); | |
2041 | + context.boundTextureUnit = unit; | |
2041 | 2042 | GLES20.glBindTexture(type, texId); |
2042 | 2043 | textures[unit] = image; |
2043 | 2044 |
@@ -2050,18 +2051,18 @@ public class OGLESShaderRenderer implements Renderer { | ||
2050 | 2051 | } |
2051 | 2052 | |
2052 | 2053 | public void clearTextureUnits() { |
2053 | - IDList textureList = context.textureIndexList; | |
2054 | - Image[] textures = context.boundTextures; | |
2055 | - for (int i = 0; i < textureList.oldLen; i++) { | |
2056 | - int idx = textureList.oldList[i]; | |
2054 | +// IDList textureList = context.textureIndexList; | |
2055 | +// Image[] textures = context.boundTextures; | |
2056 | +// for (int i = 0; i < textureList.oldLen; i++) { | |
2057 | +// int idx = textureList.oldList[i]; | |
2057 | 2058 | // if (context.boundTextureUnit != idx){ |
2058 | -// glActiveTexture(GL_TEXTURE0 + idx); | |
2059 | +// GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + idx); | |
2059 | 2060 | // context.boundTextureUnit = idx; |
2060 | 2061 | // } |
2061 | -// glDisable(convertTextureType(textures[idx].getType())); | |
2062 | - textures[idx] = null; | |
2063 | - } | |
2064 | - context.textureIndexList.copyNewToOld(); | |
2062 | +// GLES20.glDisable(GLES20.GL_TEXTURE_2D/*convertTextureType(textures[idx].getType())*/); | |
2063 | +// textures[idx] = null; | |
2064 | +// } | |
2065 | +// context.textureIndexList.copyNewToOld(); | |
2065 | 2066 | } |
2066 | 2067 | |
2067 | 2068 | public void deleteImage(Image image) { |
@@ -2345,15 +2346,17 @@ public class OGLESShaderRenderer implements Renderer { | ||
2345 | 2346 | |
2346 | 2347 | public void clearVertexAttribs() { |
2347 | 2348 | IDList attribList = context.attribIndexList; |
2348 | - for (int i = 0; i < attribList.oldLen; i++) { | |
2349 | + int oldLen = attribList.oldLen; | |
2350 | + for (int i = 0; i < oldLen; i++) { | |
2349 | 2351 | int idx = attribList.oldList[i]; |
2350 | 2352 | |
2351 | 2353 | if (verboseLogging) { |
2352 | 2354 | logger.info("GLES20.glDisableVertexAttribArray(" + idx + ")"); |
2353 | 2355 | } |
2354 | - | |
2355 | - GLES20.glDisableVertexAttribArray(idx); | |
2356 | - context.boundAttribs[idx] = null; | |
2356 | + if (idx != -1) { | |
2357 | + GLES20.glDisableVertexAttribArray(idx); | |
2358 | + context.boundAttribs[idx] = null; | |
2359 | + } | |
2357 | 2360 | } |
2358 | 2361 | context.attribIndexList.copyNewToOld(); |
2359 | 2362 | } |
@@ -2704,6 +2707,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
2704 | 2707 | } else { |
2705 | 2708 | indices = mesh.getBuffer(Type.Index);//buffers.get(Type.Index.ordinal()); |
2706 | 2709 | } |
2710 | + clearVertexAttribs(); | |
2711 | +// clearTextureUnits(); | |
2707 | 2712 | if (indices != null) { |
2708 | 2713 | drawTriangleList_Array(indices, mesh, count); |
2709 | 2714 | } else { |
@@ -2714,8 +2719,6 @@ public class OGLESShaderRenderer implements Renderer { | ||
2714 | 2719 | |
2715 | 2720 | GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); |
2716 | 2721 | } |
2717 | - clearVertexAttribs(); | |
2718 | - clearTextureUnits(); | |
2719 | 2722 | } |
2720 | 2723 | |
2721 | 2724 | private void renderMeshDefault(Mesh mesh, int lod, int count) { |
@@ -2754,6 +2757,8 @@ public class OGLESShaderRenderer implements Renderer { | ||
2754 | 2757 | setVertexAttrib(vb, interleavedData); |
2755 | 2758 | } |
2756 | 2759 | } |
2760 | + clearVertexAttribs(); | |
2761 | +// clearTextureUnits(); | |
2757 | 2762 | if (indices != null) { |
2758 | 2763 | drawTriangleList(indices, mesh, count); |
2759 | 2764 | } else { |
@@ -2765,8 +2770,6 @@ public class OGLESShaderRenderer implements Renderer { | ||
2765 | 2770 | |
2766 | 2771 | GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount()); |
2767 | 2772 | } |
2768 | - clearVertexAttribs(); | |
2769 | - clearTextureUnits(); | |
2770 | 2773 | } |
2771 | 2774 | |
2772 | 2775 | public void renderMesh(Mesh mesh, int lod, int count) { |
@@ -3002,4 +3005,35 @@ public class OGLESShaderRenderer implements Renderer { | ||
3002 | 3005 | boundShader = null; |
3003 | 3006 | lastFb = null; |
3004 | 3007 | } |
3008 | + public void resetBoundsTexture() { | |
3009 | + context.boundTextures[0] = null; | |
3010 | + if (context.boundTextureUnit != 0) { | |
3011 | + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); | |
3012 | + context.boundTextureUnit = 0; | |
3013 | + } | |
3014 | +// GLES20.glDisable(GLES20.GL_TEXTURE_2D); | |
3015 | + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); | |
3016 | + // context.boundTextureUnit = -2; | |
3017 | +// context.boundElementArrayVBO = -2; | |
3018 | +// context.boundShaderProgram = -1; | |
3019 | +// context.boundArrayVBO = -1; | |
3020 | +// context.boundElementArrayVBO = -1; | |
3021 | + | |
3022 | + if (context.boundElementArrayVBO != 0) { | |
3023 | + | |
3024 | + | |
3025 | + GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); | |
3026 | + context.boundElementArrayVBO = 0; | |
3027 | + } | |
3028 | + if (context.boundArrayVBO != 0) { | |
3029 | + GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); | |
3030 | + context.boundArrayVBO = 0; | |
3031 | + } | |
3032 | + if (context.boundShaderProgram != 0) { | |
3033 | + GLES20.glUseProgram(0); | |
3034 | + checkGLError(); | |
3035 | + boundShader = null; | |
3036 | + context.boundShaderProgram = 0; | |
3037 | + } | |
3038 | + } | |
3005 | 3039 | } |
@@ -75,10 +75,11 @@ public class IDList { | ||
75 | 75 | if (oldList[i] == idx){ |
76 | 76 | // found index in slot i |
77 | 77 | // delete index from old list |
78 | - oldLen --; | |
79 | - for (int j = i; j < oldLen; j++){ | |
80 | - oldList[j] = oldList[j+1]; | |
81 | - } | |
78 | +// oldLen --; | |
79 | +// for (int j = i; j < oldLen; j++){ | |
80 | +// oldList[j] = oldList[j+1]; | |
81 | +// } | |
82 | + oldList[i] = -1; | |
82 | 83 | return true; |
83 | 84 | } |
84 | 85 | } |
@@ -2191,8 +2191,10 @@ public class LwjglRenderer implements Renderer { | ||
2191 | 2191 | IDList attribList = context.attribIndexList; |
2192 | 2192 | for (int i = 0; i < attribList.oldLen; i++) { |
2193 | 2193 | int idx = attribList.oldList[i]; |
2194 | - glDisableVertexAttribArray(idx); | |
2195 | - context.boundAttribs[idx] = null; | |
2194 | + if (idx >= 0) { | |
2195 | + glDisableVertexAttribArray(idx); | |
2196 | + context.boundAttribs[idx] = null; | |
2197 | + } | |
2196 | 2198 | } |
2197 | 2199 | context.attribIndexList.copyNewToOld(); |
2198 | 2200 | } |