jeudi 28 décembre 2017

Storing OpenGL color attachments in constexpr GLenum array

I am using the following constexpr GLenum array to represent GL_COLOR_ATTACHMENTx (where x is an unsigned integer between 0 and 7):

constexpr std::array<GLenum, 8> opengl_color_attachment{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5, GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7};

This works fine for only the first eight available color attachments (which the OpenGL specification states to be the minimum). However, there is a possibility of more attachments, which is implementation defined. As the macro GL_MAX_COLOR_ATTACHMENTS represents the number of attachments available, I wanted to edit this constexpr array to include ALL available attachments to the limit, instead of the minimum of 8.

I created the following macro in an attempt to solve this issue myself:

#define OPENGL_COLOR_ATTACHMENT(x) GL_COLOR_ATTACHMENT##x

Although I wanted to use this in a constexpr function to create the array in compile-time, it failed because preprocessor macros are obviously processed before compilation. Although the OpenGL standard guarantees that GL_TEXTURE1 == GL_TEXTURE0 + 1, it does not seem to guarantee this for the GL_COLOR_ATTACHMENTx macro.

Is there a way for me to create the constexpr array fully from GL_COLOR_ATTACHMENT0 to GL_COLOR_ATTACHMENTx where x = GL_MAX_COLOR_ATTACHMENTS, with or without preprocessor macros?

Aucun commentaire:

Enregistrer un commentaire