问题
I'm fairly new to OpenGL and to ES2.0. I have shared c++ opengl es2 code that i use to draw on ios and android(with ndk CMake)... it mostly works but now I need antialiasing and its kind of confusing, the solutions I'm seeing are platform dependent and android side is more confusing and has limitations. I have been searching for solutions but need some more clarity.
What should have worked on both: Apparently, the Kronos RenderBuffer description says
Renderbuffer objects also natively accommodate Multisampling (MSAA).
but es 2.0 doesn't seem to support this. iOS has its own method glRenderbufferStorageMultisampleAPPLE
that supports it on es 2.0 but android doesn't have it. Nor can android Blit the FrameBuffers while ios has own method(once again) glResolveMultisampleFramebufferAPPLE
to do that.
If this is done platform specific: iOS can do setDrawableMultisample:GLKViewDrawableMultisample4X
which seems to work. But android has limitations, there is EGLConfigChooser
's chooseConfig
to do it but I have read not all android devices support antialiasing like this(i also can't test it on the emulator), so I have to do it again in the native c++ code.
Other: I have been reading and there are some methods like drawing everything a lot of times in a circular (with more precision) or upscaling the whole view to 2x and drawing and then downscaling back to get more smoother lines... Another way I'm not sure if it works or not but drawing to a texture or image which somehow does the antialiasing or supports it (need a better understanding of this)
What I need now: My requirement is to only draw vertices with color (i do my stuff through this) using glDrawArrays
method. And everything that is drawn should be smooth or antialiased. How should I approach this? I need better references or tutorials where I can read properly about any method that should work on both. I don't mind the reading and learning but I'm kind of stuck with so many options and little context with them. EDIT: I'm drawing in 2D(z=0 always), there are no issues of depth.
回答1:
OpenGL ES 2.0 targets low-end platforms and therefore does not require anti-aliasing. Extensions are often implemented however since there is lot of hardware exceeding the ES 2.0 requirements.
Assuming you need to do it on platforms that does not support it, despite being an unfair requirement (hobos should buy effing hardware if they desire visual perfection), there are a couple of things that might work depending on the rendered scene and development budget:
- Calculate fragment coverage manually in shader, set alpha, blend using GL_ALPHA_SATURATE; IMO the best looking AA technique there is, though opaque surfaces only (strangely enough supported on ES 2.0 despite no smooth polygons?)
- Temporal supersampling. Merge a few recent frames together rendered with slight offsets. If things move alot on display it might not preferable.
- Overdraw using transparent lines. For any surface draw its wireframe with transparency. The edges will becomes a little smoother, though the surface will also grow a little.
- Clamp vertices to pixel center in shader. This will slightly reduce moving sensation for near vertical/horizontal edges, but may give a less smooth feeling in some scenarios.
- Choosing a visual style that is more resistant to aliasing. I avoid circles when pixel-aligned quads work just as good. When there is risk of chromatic aliasing due to pixel geometry I select background and foreground colors more carefully. This is in some sense AA on design level, rather than on a rendering level, and should not be under estimated since it is often cheap and portable.
Should you implement any of above I'd be really interested in your results and more details of your scenario.
来源:https://stackoverflow.com/questions/48943394/opengl-es-2-0-antialiasing-or-smoothing-on-ios-and-android-from-shared-c-code