Android OpenGLES 渲染到纹理
我为 iPhone 编写图形应用程序,并且希望将我最新的应用程序“Layers”移植到 Android 平台。 Layers 是一款绘画应用程序,允许用户在屏幕上绘画并使用不同的画笔、颜色等创建多层绘画......并导出到 PSD。它有桌面同步、涂抹工具、很多好东西... http://www.layersforiphone.com/
我周一开始研究 Android 平台,遇到了一个大问题。我使用 OpenGL 来完成所有绘图,因为它提供了最佳性能。然而,有几个地方我需要渲染成纹理然后使用该纹理。例如:
- 使用画笔纹理和一行精灵在纹理 A 中创建黑色绘画描边
- 将画笔颜色+alpha 放入 glColor4f 中,然后将纹理 A 绘制到屏幕上。
在 iPhone 上,我随着用户手指的移动不断地执行此操作,并且在第一代 iPod Touch 上我能够达到 12-15fps。这是必要的,因为将颜色和 Alpha 应用于构成画笔描边的各个精灵不会产生正确的结果(因为精灵重叠并使描边太暗)。
Android 平台支持 OpenGL ES 1.0,但似乎省略了处理帧缓冲区的关键函数。我找不到将纹理绑定到帧缓冲区并使用 OpenGL 绘制到其中的方法。
我通常在 iPhone 上是这样处理的:
// generate a secondary framebuffer and bind it to OpenGL so we don't mess with existing output.
glGenFramebuffers(1, &compositingFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, compositingFramebuffer);
// attach a texture to the framebuffer.
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
// subsequent drawing operations are rendered into the texture
// restore the primary framebuffer and (possibly) draw the rendered texture
glBindFramebuffer(GL_FRAMEBUFFER, originalActiveFramebuffer);
Android 平台上有类似的东西吗?在 iPhone 上,OpenGL 比基于软件的绘图要快得多,并且是唯一可行的解决方案(相信我 - 我也编写了一个 CoreGraphics 绘图应用程序......)。也许我可以在 Android 上采取另一条路线?我愿意克服任何必要的障碍,但除非性能良好(当您在屏幕上绘制时为 10fps+),否则我不会发布该应用程序。
I write graphics apps for the iPhone and I'm looking to port my most recent app, 'Layers,' to the Android platform. Layers is painting app that allows users to draw on the screen and create multi-layered paintings with different brushes, colors, etc... and export to PSD. It's got desktop sync, a smudge tool, lots of good stuff... http://www.layersforiphone.com/
I started looking at the Android platform Monday and I've run into a major problem. I use OpenGL to do all the drawing because it offers the best performance. However, there are several places where I need to render into a texture and then use the texture. For example:
- Use brush texture and a line of sprites to create a black paint stroke in texture A
- Put brush color+alpha in glColor4f and then draw texture A onto the screen.
On the iPhone, I do this continually as the user's finger moves and I am able to achieve 12-15fps on a 1st gen iPod Touch. It's necessary because applying color and alpha to the individual sprites making up the brush stroke doesn't produce the right result (since sprites overlap and make the stroke too dark).
The android platform supports OpenGL ES 1.0 but seems to omit key functions for dealing with framebuffers. I can't find a way to bind a texture to the framebuffer and draw into it using OpenGL.
Here's how I'd normally go about it on the iPhone:
// generate a secondary framebuffer and bind it to OpenGL so we don't mess with existing output.
glGenFramebuffers(1, &compositingFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, compositingFramebuffer);
// attach a texture to the framebuffer.
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
// subsequent drawing operations are rendered into the texture
// restore the primary framebuffer and (possibly) draw the rendered texture
glBindFramebuffer(GL_FRAMEBUFFER, originalActiveFramebuffer);
Is there anything like this on the Android platform? On the iPhone, OpenGL is significantly faster than software-based drawing and is the only viable solution (trust me - I wrote a CoreGraphics painting app too...). Maybe there's another route I could take on Android? I'm willing to jump through whatever hoops are necessary, but I won't publish the app unless performance is good (10fps+ as you're drawing on the screen).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑所有 Android 设备是否都支持完全相同的 OpenGL ES 扩展集,或者它们都支持完全相同的 OpenGL ES 版本。
帧缓冲对象 (FBO) 是 OpenGL ES 2.0 核心规范的一部分;如果您的 Android 设备支持 ES 2.0,则它支持 FBO。
如果您的 Android 设备支持 ES 1.1,请使用 glGetString(GL_EXTENSIONS) 检查 GL_OES_framebuffer_object 的扩展字符串。
I'm skeptical that all Android devices would support the exact same set of OpenGL ES extensions, or that they'd all support the exact same version of OpenGL ES.
Framebuffer objects (FBOs) are a part of the OpenGL ES 2.0 core specification; if your android device supports ES 2.0, then it supports FBOs.
If your android device supports ES 1.1, then check the extension string for GL_OES_framebuffer_object using glGetString(GL_EXTENSIONS).