c++ - Changing texture parameters at runtime -
i opengl beginner , have built small engine universitary course. 1 constraint/feature need implement change texture quality (interpolation) @ runtime.
so instead of e.g.:
gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_linear);
it should changed mipmaps
gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_linear_mipmap_linear)
now have texture class abstracts , loads image , creates id texture etc.
what do: i'd bind textures in game 1 one , set parameters again.
or there more advanced or faster way this, if want effect textures?
in opengl 3.2 , higher, there texture sampler objects, can override sampling parameters in textures themselves. use them here.
it particularly convenient if want of textures use same sampling parameters. create single sampler:
gluint samplerid = 0; glgensamplers(1, &samplerid); glsamplerparameteri(samplerid, gl_texture_min_filter, gl_linear);
you can bind single sampler object, in addition regular texture binding, when texturing. or keep bound time if have 1 of them, , want use time:
glbindsampler(gl_texture_2d, samplerid);
then can change sampling attributes single call:
glsamplerparameteri(samplerid, gl_texture_min_filter, gl_linear_mipmap_linear);
if sampler bound, parameters override corresponding values in bound texture. or in words of spec:
when sampler object bound texture unit, state supersedes of texture object bound texture unit. if sampler name 0 bound texture unit, bound texture’s sampler state becomes active.
Comments
Post a Comment