Android的OpenGLES渲染到纹理纹理、Android、OpenGLES

2023-09-04 11:56:24 作者:晨熙

我写的iPhone图形的应用程序,我希望我的口最近的应用程序,层到Android平台。层是绘画应用程序,允许用户在屏幕上绘制并创造多层次的绘画具有不同的画笔,颜色,等等,并出口到PSD。它有桌面同步,一个涂抹工具,大量的好东西...... http://www.layersforiphone.com/

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/

我开始在Android平台寻找周一和我碰到的一大难题。我使用OpenGL做所有的绘图,因为它提供了最佳的性能。但是,有几个地方我需要渲染到纹理,然后用质地。例如:

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:

使用刷子的质地和线条的精灵来创建一个黑色烤漆行程质感A 把刷色+α的glColor4f然后绘制纹理到屏幕上。

在iPhone上,我这样做是不断地为用户的手指动作,我能够达到12-15fps在第一代的iPod Touch。这是必要的,因为应用颜色和alpha来弥补笔触个别精灵不会产生正确的结果(因为精灵重叠,使行程太黑了)。

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).

Android平台支持OpenGL ES 1.0,但似乎忽略关键功能处理的帧缓冲区。我无法找到一个方法来纹理绑定到帧缓冲区,并绘制成使用OpenGL了。

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.

下面就是我通常会去了解它在iPhone上:

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);

有没有这样的事情在Android平台上?在iPhone,OpenGL是比基于软件的绘图显著快,并且是唯一可行的方案(相信我 - 我写了一个CoreGraphics中画的应用程序太...)。也许还有另一种途径,我可以承担的Andr​​oid?我愿意通过跳火圈什么是必要的,但我不会发布该应用程序,除非性能的好的(10FPS +为你在屏幕上画)。

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).

推荐答案

我很怀疑,所有的Andr​​oid设备将支持完全相同的一套OpenGL ES的扩展,或者说,他们会都支持OpenGL ES的版本完全相同。

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.

帧缓冲对象(宗教组织)是OpenGL ES 2.0的核心规范的一部分;如果您的Andr​​oid设备支持ES 2.0,那么它支持宗教组织。

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.

如果您的Andr​​oid设备支持ES 1.1,然后检查扩展字符串 GL_OES_framebuffer_object 使用的 glGetString(GL_EXTENSIONS)

If your android device supports ES 1.1, then check the extension string for GL_OES_framebuffer_object using glGetString(GL_EXTENSIONS).