3
\$\begingroup\$

I have several questions related to OpenGL rendering and the issues I encountered while making 3D enigne. Some of them were asked before, but the answers are old and possibly outdated or ambiguous.

1) Is there a way to make sure that an OpenGL context was initialized before creating a resource?

I know that SMFL executes a function that checks for the existence of an active context in a current thread and creates it if there wasn't one, yet that implies at least some, hopyfully inlined, functions every time such a resource is created. (static hell) There is also a method to enforce creation of OGL resources by context/window but at the same time forces you to pass reference around.

2) Is there a point of doing so? If we gonna throw exception anyway, I don't see one. There is also not-so powerful "don't do it" written in the docs.

3) Do I even have to take into consideration possibility of multiple windows/contexts? What about multithreading?

I've read a little about creating 2 threads, one for rendering, second for passing data. It seems to me that I would have to wait for the other thread to finish before letting another one permission to go.

Huge thanks in advance :)

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I think you miss the point of what an engine is a little bit.

Game engines are developed in order to make game creation easier, without having the users of the engine to take care of complex low-level APIs. Therefore I would manage OpenGL resources internally, inside the engine.

So, let's go through your points.

  1. It depends on how you build your system. In my tiny render engine(s) I used to have factories (Factory-Pattern) which created the resources for me. Thus it wasn't even possible for me to create a resource without having the factory instantiated. For example, you could create a OpenGL context class, which is acting as a factory for resources as well.

  2. I don't get this point. As someone who wants to develop a game engine, you should aim for making game creation easier and more streamlined.

  3. I would take into consideration, that one would create 2 or more windows with a context. This doesn't necessarily mean that each window should have its own context. One context can be shared across multiple windows. However, you can render only to one window at one time.

  4. About multi threading and OpenGL: Just don't. I assume, that you want to issue multiple drawcalls from multiple threads. A OpenGL context is bound to a certain thread, usually by the '*MakeCurrent' calls exposed by the windowing systems. Multi threading won't buy you much using OpenGL. For more, just read here.

Disclaimer: I am not a professional graphics engineer. My complete knowledge is self-taught using the reference or sites like SO.

EDIT: I forgot the obligatory "Write games, not engines!"

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .