Porting a few commands from OpenGLES 3.0 to GLES2.0

Hi, I am trying to port some existing GLES3 code to ES2 and I am wondering what would be the equivalent workaround for this, particularly the glDrawBuffers part

This part is the beginning of a post effects render.

GLenum DrawBuffers[9] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, 
				 GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5, GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7,
				 GL_COLOR_ATTACHMENT8};

glBindFramebuffer(GL_FRAMEBUFFER, framebuffer[0]);
glDrawBuffers(pass[0].numColBufs, DrawBuffers);

I am also getting these error defines, so is it safe to just manually add and define them?

GL_DEPTH_STENCIL_ATTACHMENT
GL_DEPTH_STENCIL
GL_COLOR_ATTACHMENT0 to GL_COLOR_ATTACHMENT8
GL_RGBA32F;
GL_RGBA16F;
GL_RGBA8;

What makes you think that there is an “equivalent workaround”? New versions of APIs exist to expose new features. That generally means that functionality specific to a newer version isn’t available on the older one.

In this case, unextended ES 2.0 does not support rendering to multiple render targets. As such, it doesn’t have the glDrawBuffers function. It also doesn’t have floating-point textures or sized internal formats of any kind.

There are extensions written against ES 2.0 that can provide these things if the hardware permits it. But you’ll have to check for those extensions individually.

@Alfonse_Reinheart

Thanks for the info. I was just thinking in general and possibly get some tips or advice on how to achieve postfx or post process in a similar setup as possible on GLES2.

As a follow-up question, how do I do this with just one render target and make it run with ES2 since glDrawBuffers is ES3 only? I also read that using FBO will be an alternative for ES2.

Absent a suitable extension, you’d need to use 9 separate render passes, one for each target. Bear in mind that ES3 doesn’t guarantee support for more than 4 render targets (use glGetIntegerv to query the value of GL_MAX_COLOR_ATTACHMENTS), which tends to suggest that there’s ES3 hardware out there which has that as a limit.

In terms of extensions, look at:
OES_packed_depth_stencil - GL_DEPTH_STENCIL_OES, but not _ATTACHMENT.
OES_required_internalformat - GL_RGBA8_OES
OES_texture_half_float - GL_HALF_FLOAT for glTexImage2D
OES_texture_float - GL_FLOAT for glTexImage2D
EXT_texture_storage - GL_RGBA32F_EXT
EXT_color_buffer_half_float - GL_RGBA16F_EXT
EXT_color_buffer_float - makes RGBA32F a colour-renderable format
EXT_draw_buffers - glDrawBuffersEXT

I have no idea how much hardware (if any) supports all of those without also supporting ES3.

1 Like

@GClements Thanks for this great info! Honestly, I have no idea where to start since I am modifying an existing project and new to post effects + gles 2 commands, but will keep this as reference.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.