2

How is it possible to have a multisampled texture as part of an FBO in OpenGL ES 3.0 (Android)?

The method glTexImage2DMultisample does not seem to exist.

I also want to call glReadPixels on this texture later on in this code, so the multisampled texture should also be readable.

Is there some kind of extension or utility I would need to use for this?

BDL
  • 21,052
  • 22
  • 49
  • 55
kirtan-shah
  • 405
  • 7
  • 21

2 Answers2

3

You want glTexStorage2DMultisample. In general writing multisampled data back to memory is expensive, and needs a resolve using glBlitFramebuffer to consolidate to a single sample.

Consider using this extension to get a "free" resolve on most tile-based architectures.

https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_multisampled_render_to_texture.txt

solidpixel
  • 10,688
  • 1
  • 20
  • 33
  • I know I need to use glTexImage2DMultisample, but it doesn't seem to exist in the android environment. My question was how I would get it to work in android? Is there a specific way to import that extension in android? – kirtan-shah Nov 08 '17 at 23:30
  • 1
    glTexImage2DMultisample only exists in OpenGL, it doesn't exist in OpenGL ES at all. So, you really do want to use glTexStorage2DMultisample - it's the only option you have. – solidpixel Nov 13 '17 at 16:44
  • So, is there a way I can accomplish this in OpenGL ES, or are there any alternatives that would provide the same result? – kirtan-shah Nov 14 '17 at 23:32
  • Why do you think glTexStorage2DMultisample doesn't do what you want? It's pretty much the as as glTexImage2DMultisample ... just with a different name. – solidpixel Nov 15 '17 at 20:47
  • Oh, I misread the function name, sorry about that. I see what you are saying now. – kirtan-shah Nov 16 '17 at 01:05
1

Actually, opengl es not support for texture multisampling, glTexStorage2DMultisample not work for texture multisampling. opengl es only support renderbuffer for multisampling, in my case, I resolved multisampling by create a renderbuffer, works charm.

how I did this:

glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glGenRenderbuffers(1, &rbo);
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
    LOGI("ERROR::FRAMEBUFFER:: Framebuffer is not complete!");
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);

then render:

 glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
 glBlitFramebuffer(0, 0, mScreenWidth, mScreenHeight, 0, 0, mScreenWidth, mScreenHeight,
                      GL_COLOR_BUFFER_BIT, GL_NEAREST);

this works in opengl es 3.2, Android platform.

Jishi Chen
  • 634
  • 7
  • 17