java libgdx帧缓冲区仅在某些机器上获得视觉静态
我有一个系统,在这个系统中,我使用Libgdx的ShapeRenderer沿着帧缓冲区中的样条线生成一条线,将一些纹理渲染到另一个帧缓冲区,将生成的线作为遮罩应用到平铺纹理,然后最终在主相机上将最终产品作为纹理样条线渲染
<>最后的输出看起来是这样的,当前看起来有点像字符中间的一个复选标记: (似乎我需要10个声誉来提交图片,所以这里是expected output的链接)直到今天,我的机器和我与之分享的大多数人都运转良好
只有在这个人的机器上,我无法复制它或看到类似的东西,它看起来是这样的:incorrect output
代码的主要逻辑在这段代码中
public void render(SpriteBatch sb) {
//create the mask
sb.end();
TextureRegion mask = createMask();
//create the tiles
HydrologistMod.beginBuffer(tileBuffer);
sb.begin();
sb.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
effectsMap.get(current).instructor.instruct();
renderTiles(sb); //uses instructions one line above to render a grid of tiled texture based on the size of the spline
... //section of code where sometimes the texture is combined with another, but there was no effect transition happening at the time
//mask the tiles
sb.setBlendFunction(0, GL20.GL_SRC_ALPHA);
sb.setColor(Color.WHITE.cpy());
sb.draw(mask, 0, 0);
//collect the final texture
sb.end();
tileBuffer.end();
TextureRegion texture = HydrologistMod.getBufferTexture(tileBuffer);
sb.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
... //section of code where no relevant effects were active
//render the effect on the main camera
sb.begin();
sb.draw(texture, 0,0);
sb.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
}
从顶部开始,我定义的方法: createMask()处理样条曲线的绘制。基本方法是在所有点之间绘制一个填充矩形,并以几种不同的方式重复该过程,以更好地填充各种碎片和间隙
private TextureRegion createMask() {
HydrologistMod.beginBuffer(maskBuffer);
Color color = Color.BLACK.cpy();
color.a = 0.5f;
renderCurve(color, LINE_WIDTH); //half transparent larger outline for anti-aliasing
color.a = 1.0f;
renderCurve(color, LINE_WIDTH - 1);
maskBuffer.end();
return HydrologistMod.getBufferTexture(maskBuffer);
}
private void renderCurve(Color color, int width) {
shape.begin(ShapeRenderer.ShapeType.Filled);
shape.setColor(color);
int lineWidth;
for (int i = 0; i < spline.size() - 1; ++i) {
if (i < width) {
lineWidth = i + 1;
} else if (i > spline.size() - width) {
lineWidth = spline.size() - i;
} else {
lineWidth = width;
}
Vector2 start = spline.get(i).toVector();
Vector2 mid = spline.get(i+1).toVector();
shape.rectLine(start, mid, lineWidth);
if ((i < spline.size() - 3)) {
Vector2 end = spline.get(i + 2).toVector();
shape.rectLine(start, end, lineWidth);
}
}
shape.end();
}
。beginBuffer是启动和清理帧缓冲区的辅助方法:
public static void beginBuffer(FrameBuffer fbo) {
fbo.begin();
Gdx.gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glColorMask(true,true,true,true);
}
还有。getBufferTexture是一种辅助方法,可以自动从缓冲区检索纹理并将其翻转,因为libgdx帧缓冲区喜欢倒置
public static TextureRegion getBufferTexture(FrameBuffer fbo) {
TextureRegion texture = new TextureRegion(fbo.getColorBufferTexture());
texture.flip(false, true);
return texture;
}
我已经尝试过调查这个问题,据我所知,这可能发生在样条曲线的渲染、缓冲区的信息被破坏,以及遮罩的应用之间的任何地方。在这个过程中的某个地方,引入了很多视觉噪音,但我似乎不知道是什么导致了这个问题,我的搜索也没有发现任何人有类似的问题
对于任何想仔细看看的人来说,我的项目可以在github上找到,我处理这个逻辑的类可以在here.
感谢您的任何帮助,我为其效果感到自豪,不希望任何人的体验被丑陋的静电破坏
共 (0) 个答案