c++ - How to Get Max Number of Multitextured Units -
lets have function want user able select appropriate texture in type safe manner. instead of using glenum of gl_texturex define method follows.
void activate_enable_bind(uint32_t texture_num) { const uint32_t max_textures = gl_max_combined_texture_image_units - gl_texture0; const uint32_t actual_texture = (gl_texture0 + texture_num); if (texture_num > max_textures) { throw std::runtime_error("error: texture::activate_enable_bind()"); } glactivetexture(actual_texture); glenable(target_type); glbindtexture(target_type, texture_id_); }
is guaranteed work under implementations based on opengl specification, or implementers allowed have
`gl_texture0 - gl_texture(gl_max_combined_texture_image_units -1)`
defined in non-contiguous manner?
i modifying code aswell here in have:
void activate_enable_bind(uint32_t texture_num = 0) { glint max_textures = 0; glgetintegerv(gl_max_combined_texture_image_units, &max_textures); if (static_cast<glint>(texture_num) > max_textures - 1) { throw std::runtime_error("error: texture::activate_enable_bind()"); } const uint32_t actual_texture = (gl_texture0 + texture_num); glactivetexture(actual_texture); glenable(target_type); glbindtexture(target_type, texture_id_); }
i think gl_max_combined_texture_image_units
not on own useful value, pass glget
retrieve actual value. account that, you'd retrieve this:
glint max_combined_texture_image_units; glgetintegerv(gl_max_combined_texture_image_units, &max_combined_texture_image_units); // , maybe check errors
as adding gl_texture0
, safe; §3.8 of the opengl 3.2 core specification says this:
activetexture generates error
invalid_enum
if invalid texture speciļ¬ed. texture symbolic constant of formtexture
i, indicating texture unit i modified. constants obeytexture
i= texture0+
i (i in range 0 k − 1, k value ofmax_combined_texture_image_units
).
Comments
Post a Comment