0

我正在使用一个正在使用OpenGL ESthrough的应用程序libgdx。我的应用程序中有撤消/重做功能。当用户单击其中一个按钮时,应用程序中的图像(通过 OpenGL ES 创建)被释放。之后,在 OpenGL 线程中加载一个新图像。重做是做同样的功能。有时当我单击撤消/重做时,图像ImageView会变黑,有时文本TextView会变黑。我认为问题出在dispose()方法上,但我不明白为什么图像和文字会变黑。也许有人可以帮助我。处置代码:

if(obj.getTexture() != null){
    obj.getTexture().dispose();
}

加载纹理代码:

texture = new Texture(Gdx.files.absolute(fileName));

撤消代码:

int indexUndo = undoObjects.size() - 1;
SpriteState ss = undoObjects.get(indexUndo);
if(object instanceof PhotoSprite){
     PhotoSpriteState pState = (PhotoSpriteState)ss;
     if(pState.getTypeChanging() == TypeSpriteChanging.ChangeTexture){
        object.saveRedoState(TypeSpriteChanging.ChangeTexture);
        PhotoSprite photoObj = (PhotoSprite)object;
        photoObj.setFileName( pState.getFilename() );
        photoObj.setGeometry( pState.getGeometry() );
        photoObj.setTexture(null);
     }
}

重做代码:

int indexRedo = redoObjects.size() - 1;
SpriteState ss = redoObjects.get(indexRedo);
if(object instanceof PhotoSprite){
     PhotoSpriteState pState = (PhotoSpriteState)ss;
     if(pState.getTypeChanging() == TypeSpriteChanging.ChangeTexture){
        object.saveRedoState(TypeSpriteChanging.ChangeTexture);
        PhotoSprite photoObj = (PhotoSprite)object;
        photoObj.setFileName( pState.getFilename() );
        photoObj.setGeometry( pState.getGeometry() );
        photoObj.setTexture(null);
     }
}

代码加载纹理:

public void render(PhotoSprite psObject, int zIndex) {
    ShaderProgram shader = psObject.getShader();
    if(!shader.isCompiled()){
        Log.i("ERROR", "SHERROR " + shader.getLog());
    }
    if(psObject.getTexture() == null){
        psObject.setTexture(loadTexture(FILE_PATH + psObject.getFileName()));
    }
    psObject.getTexture().bind(0);

    shader.begin();
    shader.setUniformMatrix("u_worldView", psObject.getMatrix(zIndex));
    shader.setUniformi("u_texture", 0);
    // psObject.getMesh()
    MeshUtil.MESH.render(shader, GL20.GL_TRIANGLES);
    shader.end();
}

初始状态:

在此处输入图像描述

使用撤消/重做后

在此处输入图像描述

4

1 回答 1

1

我找到答案。问题在于从 GLThread 中破坏纹理。希望它会帮助某人。

于 2013-12-30T08:27:55.020 回答