通过共享的C ++代码在ios和android上进行OpenGL ES 2.0抗锯齿或平滑 [英] OpenGL ES 2.0 Antialiasing or smoothing on ios and android from shared c++ code

查看:377
本文介绍了通过共享的C ++代码在ios和android上进行OpenGL ES 2.0抗锯齿或平滑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对OpenGL和ES2.0还是很陌生.我已经共享了我用来在ios和android上绘制的c ++ opengl es2代码(使用ndk CMake)...它大部分都可以工作,但是现在我需要抗锯齿和其令人困惑的地方,我看到的解决方案取决于平台和android方面更令人困惑并且有局限性.我一直在寻找解决方案,但需要更多说明.

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.

两者都应该起作用: 显然, Kronos RenderBuffer 描述说

Renderbuffer对象本身还包含多重采样(MSAA).

Renderbuffer objects also natively accommodate Multisampling (MSAA).

,但是es 2.0似乎不支持此功能. iOS有自己的方法glRenderbufferStorageMultisampleAPPLE,它在es 2.0上支持它,但android没有.当ios有自己的方法(再次一次)glResolveMultisampleFramebufferAPPLE来执行此操作时,android也无法关闭FrameBuffers.

but es 2.0 doesn't seem to support this. iOS has its own method glRenderbufferStorageMultisampleAPPLEthat 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.

如果这是针对特定平台完成的:iOS可以执行setDrawableMultisample:GLKViewDrawableMultisample4X,这似乎可行.但是android有局限性,有EGLConfigChooserchooseConfig可以做到这一点,但是我已经读到并非所有的android设备都支持像这样的抗锯齿(我也无法在模拟器上对其进行测试),所以我必须再次做一次在本地c ++代码中.

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.

其他:我一直在阅读,有一些方法,例如多次绘制所有内容(更精确),或者将整个视图放大到2倍,然后再缩小到获得更平滑的线条...另一种方式,我不确定它是否有效,而是绘制纹理或图像,从而以某种方式进行抗锯齿或支持抗锯齿(需要对此有更好的理解)

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)

我现在需要的:我的要求是仅使用glDrawArrays方法绘制带有颜色的顶点(我通过它来做我的工作).并且所绘制的所有内容均应平滑或抗锯齿.我应该如何处理?我需要更好的参考资料或教程,在这里我可以正确阅读有关两种方法均适用的任何方法.我不介意阅读和学习,但我被太多的选择所困,几乎没有上下文.我在2D中绘图(始终为z = 0),没有深度问题.

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. I'm drawing in 2D(z=0 always), there are no issues of depth.

推荐答案

OpenGL ES 2.0以低端平台为目标,因此不要求抗锯齿.通常会实施扩展,因为有很多硬件超出了ES 2.0的要求.

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:

  1. 在着色器中手动计算片段覆盖率,设置alpha,使用GL_ALPHA_SATURATE进行混合; IMO是最好看的AA技术,尽管只有不透明的表面(尽管没有光滑的多边形,ES 2.0上支持的奇怪程度如何?)
  2. 时间超采样.将一些最近的帧合并在一起,并稍加偏移.如果事物在显示器上大量移动,则可能不是可取的.
  3. 使用透明线进行透支.对于任何表面,请绘制具有透明度的线框.边缘会变得更平滑,尽管表面也会有所增长.
  4. 将顶点固定到着色器中的像素中心.这样会略微减少垂直/水平边缘附近的移动感觉,但在某些情况下可能会产生较不光滑的感觉.
  5. 选择一种更抗锯齿的视觉样式.当像素对齐的四边形同样有效时,我会避免使用圆.当由于像素几何形状而导致出现色混叠的风险时,我会更仔细地选择背景色和前景色.从某种意义上说,这是设计级别的AA,而不是渲染级别的AA,并且由于价格便宜且便于携带,因此不应低估它.
  1. 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?)
  2. Temporal supersampling. Merge a few recent frames together rendered with slight offsets. If things move alot on display it might not preferable.
  3. 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.
  4. 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.
  5. 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.

这篇关于通过共享的C ++代码在ios和android上进行OpenGL ES 2.0抗锯齿或平滑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆