简体   繁体   English

使用OpenGL ES 3.0进行GLKit多重采样

[英]GLKit Multi-sampling with OpenGL ES 3.0

I am in the process of migrating a small iPad application from OpenGL ES 2.0 to OpenGL ES 3.0. 我正在将一个小型iPad应用程序从OpenGL ES 2.0迁移到OpenGL ES 3.0。 In the App, I use a subclass of GLKView to handle all my drawing, though the only GLKit features I use are: 在App中,我使用GLKView的子类来处理所有图形,尽管我使用的唯一GLKit功能是:

self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; // Or 2
self.drawableDepthFormat = GLKViewDrawableDepthFormatNone;
self.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
self.drawableMultisample = GLKViewDrawableMultisample4X;
self.drawableStencilFormat = GLKViewDrawableStencilFormatNone;
self.enableSetNeedsDisplay = YES;
// ... gl code following

My -drawRect method looks like this: 我的-drawRect方法看起来像这样:

glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);

[_currentProgram use]; // Use program
glUniformMatrix4fv([_currentProgram getUniformLocation:@"modelViewProjectionMatrix"], 1, 0, modelViewProjectionMatrix.m);

// ...
if (isES3) {
    glBindVertexArray(vertexArray);
}
else {
   glBindVertexArrayOES(vertexArray);
}
glDrawArrays(GL_TRIANGLE_STRIP, 0, verticiesLength);

I do not yet have a OpenGL ES 3.0-capable device so all of my OpenGL ES 3.0 testing is being done in the iOS Simulator. 我还没有支持OpenGL ES 3.0的设备,因此所有的OpenGL ES 3.0测试都在iOS Simulator中完成。 OpenGL ES 2.0 testing is done on-device and in-simulator. OpenGL ES 2.0测试是在设备上和模拟器中完成的。

As expected, in ES2 , the screen is cleared to white immediately on startup ( -drawRect having been called once and no vertices to draw yet). 如预期的那样,在ES2 ,启动后屏幕立即清除为白色( -drawRect被调用一次,并且尚未绘制任何顶点)。 However, when I make the swap to ES3 , the context is successfully created, no gl calls fail, and yet the screen does not clear as it should - it just appears as a black screen. 但是,当我进行到ES3的交换时,成功创建了上下文,没有gl调用失败,但是屏幕并没有按照应有的方式清除-它只是显示为黑屏。 Fishing around for what was going wrong, I decided to remove multi-sampling: 钓鱼出什么问题了,我决定删除多重采样:

self.drawableMultisample = GLKViewDrawableMultisampleNone;

And it worked! 而且有效! (Albeit without antialiasing.) My question is therefore, are there any known issues with GLKit multi-sampling with OpenGL ES 3.0 in the iOS Simulator (iPad, iPad Retina and iPad Retina (64-Bit))? (尽管没有抗锯齿。)因此,我的问题是,iOS模拟器(iPad,iPad Retina和iPad Retina(64位))中使用GLKit和OpenGL ES 3.0进行多重采样是否存在任何已知问题? My laptop has more than enough free memory to cope with the multi-sampling. 我的笔记本电脑有足够的可用内存来应付多重采样。

OpenGL is a very asynchronous API. OpenGL是一个非常异步的API。 For example, if you call glClear , you should not expect the screen to be cleared when the call returns. 例如,如果调用glClear ,则不应期望在调用返回时清除屏幕。 You can only reliably look at the result of the rendering you produced after you finished rendering the frame, and it is displayed (typically by swapping the buffers when using double buffered rendering). 您只能在完成渲染帧之后可靠地查看生成的渲染结果,并显示出来(通常在使用双缓冲渲染时通过交换缓冲区)。

So what you're observing most likely does not mean anything. 因此,您最有可能观察到的内容没有任何意义。 Does everything look fine at the end of the frame? 框架结尾处的一切看起来都很好吗? If yes, there's no reason to be worried. 如果是,则没有理由担心。

The difference is likely caused in the different rendering process if multisampling is enabled. 如果启用了多重采样,则差异可能是在不同的渲染过程中引起的。 In this case, rendering goes to a higher resolution buffer first, and is only downsampled to the actual framebuffer at the end of the frame. 在这种情况下,渲染首先进入更高分辨率的缓冲区,并且仅在帧末尾被下采样到实际的帧缓冲区。

部署时,从“常规”>“部署信息”菜单中将设备类型选择为iPad,而不是通用设备,即可对其进行修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM