1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| public void DigTexture(GL10 gl)
{
GL11ExtensionPack gl2 = (GL11ExtensionPack) gl;
int srcbuf = TextureManager.GetTexFBufferId(srctexid);
int modtex = TextureManager.GetGLTexId(modtexid);
int srctex = TextureManager.GetGLTexId(srctexid);
int tempbuf = TextureManager.GetTempTexFbufferID();
int temptex = TextureManager.GetTempGLTexID();
int tempcrop[] = { 0, 0, 0, 0 };
// modify textures
if (srcbuf != -1) {
gl.glEnable(GL10.GL_BLEND);
gl.glDisable(GL10.GL_ALPHA_TEST);
// Bind temp fbuffer
gl2.glBindFramebufferOES(GLES11ext.GL_FRAMEBUFFER_OES, tempbuf);
// Bind modifier texture
gl.glBindTexture(GL10.GL_TEXTURE_2D, modtex);
// set Alpha Test and Blendfunc (just overwrite the whole area)
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ZERO);
// draw modifier
tempcrop[2] = modcrop[2];
tempcrop[3] = modcrop[3];
GLES11.glTexParameteriv(GL10.GL_TEXTURE_2D, GLES11Ext.GL_TEXTURE_CROP_RECT_OES, modcrop, 0);
GLES11Ext.glDrawTexiOES(tempcrop[0], tempcrop[1], 0, tempcrop[2], tempcrop[3]);
// set Alpha test and Blendfunc (
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glAlphaFunc(GL10.GL_GEQUAL, 1.0f);
gl.glEnable(GL10.GL_ALPHA_TEST);
// bind texture to modify
gl.glBindTexture(GL10.GL_TEXTURE_2D, srctex);
// draw texture to modify
GLES11.glTexParameteriv(GL10.GL_TEXTURE_2D, GLES11ext.GL_TEXTURE_CROP_RECT_OES, srccrop, 0);
GLES11Ext.glDrawTexiOES(tempcrop[0], tempcrop[1], 0, tempcrop[2], tempcrop[3]);
// bind texture to change buffer
gl2.glBindFramebufferOES(GLES11Ext.GL_FRAMEBUFFER_OES, srcbuf);
// bind modified temp texture
gl.glBindTexture(GL10.GL_TEXTURE_2D, temptex);
// set Alpha test and Blendfunc
gl.glBlendFunc(GL10.GL_ZERO, GL10.GL_SRC_ALPHA);
gl.glDisable(GL10.GL_ALPHA_TEST);
// write to main texture the modification
GLES11.glTexParameteriv(GL10.GL_TEXTURE_2D, GLES11ext.GL_TEXTURE_CROP_RECT_OES, tempcrop, 0);
GLES11Ext.glDrawTexiOES(srccrop[0], srccrop[1], 0, srccrop[2], srccrop[3]);
// restore screen framebuffer
gl2.glBindFramebufferOES(GLES11Ext.GL_FRAMEBUFFER_OES, 0);
// restore active texture
gl.glBindTexture(GL10.GL_TEXTURE_2D, G.activetexid);
}
} |
Partager