Android OpenGLES Render-to-Texture

陌路散爱 提交于 2019-12-20 14:15:44

问题


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:

  1. Use brush texture and a line of sprites to create a black paint stroke in texture A
  2. 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).


回答1:


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



来源:https://stackoverflow.com/questions/1716728/android-opengles-render-to-texture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!