Note that there are some explanatory texts on larger screens.

plurals
  1. POMultisampled rendering to texture
    text
    copied!<p>I am working with the following architecture:</p> <ul> <li>OpenGL ES 2 on iOS</li> <li>Two EAGL contexts with the same ShareGroup</li> <li>Two threads (server, client = main thread); the server renders stuff to textures, the client displays the textures using simple textured quads.</li> </ul> <p><strong>Additional detail to the server thread (working code)</strong></p> <p>An fbo is created during initialization:</p> <pre><code>void init(void) { glGenFramebuffer(1, &amp;fbo); } </code></pre> <p>The render loop of the server looks roughly like this:</p> <pre><code>GLuint loop(void) { glBindFrameBuffer(GL_FRAMEBUFFER, fbo); glViewport(0,0,width,height); GLuint tex; glGenTextures(1, &amp;tex); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); // Framebuffer completeness check omitted glClear(GL_COLOR_BUFFER_BIT); // actual drawing code omitted // the drawing code bound other textures, so.. glBindTexture(GL_TEXTURE_2D, tex); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, GL_NONE); glFlush(); return tex; } </code></pre> <p>All this works fine so far.</p> <p><strong>New (buggy) code</strong></p> <p>Now i want to add Multisampling to the server thread, using the GL_APPLE_framebuffer_multisample extension and modified the the initialization code like this:</p> <pre><code>void init(void) { glGenFramebuffer(1, &amp;resolve_fbo); glGenFramebuffers(1, &amp;sample_fbo); glBindFramebuffer(GL_FRAMEBUFFER, sample_fbo); glGenRenderbuffers(1, &amp;sample_colorRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, sample_colorRenderbuffer); glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER, 4, GL_RGBA8_OES, width, height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, sample_colorRenderbuffer); // Framebuffer completeness check (sample_fbo) omitted glBindRenderbuffer(GL_RENDERBUFFER, GL_NONE); glBindFramebuffer(GL_FRAMEBUFFER, GL_NONE); } </code></pre> <p>The main loop has been changed to:</p> <pre><code>GLuint loop(void) { glBindFrameBuffer(GL_FRAMEBUFFER, sample_fbo); glViewport(0,0,width,height); GLuint tex; glGenTextures(1, &amp;tex); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glClear(GL_COLOR_BUFFER_BIT); // actual drawing code omitted glBindFramebuffer(GL_FRAMEBUFFER, resolve_fbo); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); // Framebuffer completeness check (resolve_fbo) omitted // resolve multisampling glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, resolve_fbo); glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, sample_fbo); glResolveMultisampleFramebufferAPPLE(); // the drawing code bound other textures, so.. glBindTexture(GL_TEXTURE_2D, tex); glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, GL_NONE); glFlush(); return tex; } </code></pre> <p>What i see now is that a texture contains data from multiple loop() calls, blended together. I guess I'm either missing an 'unbind' of some sort, or probably a <code>glFinish()</code> call (I previously had such a problem at a different point, I set texture data with <code>glTexImage2D()</code> and used it right afterwards - that required a <code>glFinish()</code> call to force the texture to be updated).</p> <p>However inserting a <code>glFinish()</code> after the drawing code didn't change anything here..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload