public BasicTexture copyTexture(int x, int y, int width, int height) {
if (isMatrixRotatedOrFlipped(mMatrixValues)) {
throw new IllegalArgumentException("cannot support rotated matrix");
}
float points[] = mapPoints(mMatrixValues, x, y + height, x + width, y);
x = (int) points[0];
y = (int) points[1];
width = (int) points[2] - x;
height = (int) points[3] - y;
GL11 gl = mGL;
RawTexture texture = RawTexture.newInstance(this);
gl.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId());
texture.setSize(width, height);
int[] cropRect = {0, 0, width, height};
gl.glTexParameteriv(GL11.GL_TEXTURE_2D,
GL11Ext.GL_TEXTURE_CROP_RECT_OES, cropRect, 0);
gl.glTexParameteri(GL11.GL_TEXTURE_2D,
GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL11.GL_TEXTURE_2D,
GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL11.GL_TEXTURE_2D,
GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
gl.glTexParameterf(GL11.GL_TEXTURE_2D,
GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
gl.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0,
GL11.GL_RGB, x, y, texture.getTextureWidth(),
texture.getTextureHeight(), 0);
return texture;
}