I am experimenting with writing a small game engine for Android using OpenGL ES. I have created a Game Thread which updates the game objects and the GLThread with draws the scene. I had read that you need to load the textures in onSurfaceCreated method of GLSurfaceView. I am following that but for some debugging purpose I was trying to load textures from my Game Thread instead of the GLThread. I got no errors and the texture were not showing up on the screen. I spent my entire day trying to figure out the problem and finally I read the below here
"Just be sure to only use OpenGL in the main thread." Very important. You cannot call in your Game Engine (which may be in another thread) a texture-loading function which is not synchronized with the gl-thread. Set there a flag to signal your gl-thread to load a new texture (for example, you can place a function in OnDrawFrame(GL gl) which checks if there must be a new texture loaded.
I will modify my code so that the textures will be loaded from the GL Thread. I just could not understand why is it so? Why do the OpenGL functions do not work from another thread?
I know how to create threads but I do not know what synchronization means. The above extract mentions, "You cannot call in your Game Engine (which may be in another thread) a texture-loading function which is not synchronized with the gl-thread." So I guess my Game Thread might not be synchronized with the GL Thread. Is it possible to create another thread which is synchronized to the GL Thread so that GL functions can be called from it? What should I learn in threading to understand these concepts?