LibGDX Saving textures to avoid context loss(LibGDX 保存纹理以避免上下文丢失)
问题描述
我在基于 LibGDX 的 Android 应用程序中有一个纹理,它是通过 FrameBuffers 程序创建的,我需要通过上下文丢失来保留它,而且似乎唯一有效的方法是简单地保存数据,无论是作为完整的图像或原始数据,然后在时机成熟时将其重新加载.不过,我正在努力寻找任何方法来实现这一目标,因为我采取的每条路线都以某种方式导致了彻底的失败.
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 纹理.(从 Pixmap
到 Texture
很容易,但反过来就不那么容易了.)如果您用于在 FBO 中生成数据的原语可用Pixmap
(例如,基本几何图元),这可能是一种替代方法.我相信这是最接近 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 代码用于从帧缓冲区中抓取字节(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
以使用从 ScreenUtils中返回的
byte[]
写出CIM"格式的文件代码> 方法.
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 ...
这篇关于LibGDX 保存纹理以避免上下文丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LibGDX 保存纹理以避免上下文丢失
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01