LibGDX保存纹理,避免环境损失纹理、损失、环境、LibGDX

2023-09-07 12:50:57 作者:我本是凉薄人何陷温柔海

我有基础的,它通过我通过上下文损失需要preserve帧缓冲区程序上创建Android应用程序在我的LibGDX纹理,并且似乎唯一有效的方法,这样做是为了简单地保存数据,无论是作为一个完整的图像或原始数据,出来,并加载它放回在时机成熟时。我挣扎找到任何方式来实现这一点,虽然,因为我已经采取了导致完全失败的这样或那样的每个路径。

I have a texture in my LibGDX based Android app that is created procedurally through FrameBuffers that I need to preserve through context loss, and it seems that the only efficient way to do this is to simply save the data, whether as a full image or raw data, out, and load it back in when the time comes. I'm struggling to find any way to achieve this though, as every route I've taken has lead to complete failure in one way or another.

我已搜索周围不少,但没有我遇到已经解决。我大多只是寻找一个提示正确的方向,而不是漫无目的的搜索和尝试我一直在做迄今。我认为,最好的办法是将所有的纹理数据到一个缓冲某种形式的,内部保存的数据,然后重新加载它,并重新创建质感,但我不知道什么是最好的方式到去这样做的。

I've searched around quite a bit, but nothing I've come across has worked out. I am mostly just looking for a hint into the right direction, rather than the aimless searching and attempts I have been doing thus far. I would assume the best thing would be to convert all of the data from the texture into a "buffer" of some sort, save the data internally, and then reload it and recreate the texture, but I'm not sure what the best way to go about doing that is.

推荐答案

的的 PixmapIO 类应该帮助写一个运行时生成的像素映射出来。它不是你要找完全是用于与FBO的质感,虽然。 (它很容易从像素图纹理,但不是那么容易走另外一条路。)如果原语用于生成可在像素图(例如,基本几何图元)在FBO的数据,这可能是一种选择。我相信这是最接近libGDX来支持机制,节省了运行时的质感,但我并不积极。

The PixmapIO class is supposed to help with writing a run-time generated pixmap out. Its not quite what you're looking for with an FBO texture, though. (Its easy to go from Pixmap to Texture, but not so easy to go the other way.) If the primitives you use to generate the data in your FBO are available on Pixmap (e.g., the basic geometric primitives), that may be an alternative. I believe this is the closest libGDX comes to a supported mechanism for saving a run-time texture, but I'm not positive.

有一些libGDX code周围刮字节掉帧缓冲(FBO一个的纹理数据所有的生命在你的GPU,所以你需要通过一些铁圈跳将其复制到正常的内存)。请参见 ScreenUtils 和这里的链接有关截图和PNG格式

There is some libGDX code around for scraping bytes off the framebuffer (the texture data of an FBO all lives on your GPU, so you need to jump through some hoops to copy it into normal memory). See ScreenUtils and the links here about screenshots and PNGs.

这应该很容易适应 PixmapIO 写出了CIM使用格式文件中的字节[] 从的 ScreenUtils 方法返回。

It should be easy to adapt the PixmapIO to write out a "CIM" formatted file using the byte[] returned from on of the ScreenUtils methods.

另外,你可以跟踪行动是做给FBO这一点,所以你可以重放它们(后重建的内容)的列表。这在很大程度上取决于发生了什么事情到你的纹理,但...

Alternatively, you could track the list of "operations" that were done to the FBO, so you can just replay them (reconstructing the content later). It depends a lot on what's going into your texture, though ...