2
\$\begingroup\$

I have a program which imports models from .obj files and then draws them with OpenGL. I have a model which contains many shapes (meshes?). Not every shape has texcoords defined inside .obj file (it looks like 1//1 instead of 1/1/1) and I try to use one shader program which depends on texcoords.

What would be the best solution for that problem? Should I use separate programs for shapes that have texcoords and another for shape without texcoords defined?

Maybe there is a way to check if some attributes were passed to shader program?

This is the gist with .obj, .mtl and shader files, maybe that will help you to understand my problem.

\$\endgroup\$
1
\$\begingroup\$

Make seperate programs, and make sure to split your meshes into two lists: one for the ones with texcoords and one for thise without. Make sure to render first all of one list and then all of the other list, you do not want to switch between the two shaders more than once because of the overhead associated with state changes.

The reason I think this is better is because you're going to have gibberish UV values if you do a general program, so the shaders are probably going to render quite different anyway.

If you want to use the same program, just create an uv buffer even for the .obj shapes missing uv coordinates, and fill it with like, (0.0, 0.0) for every vertice that is part of the shape.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.