Server Client networking openGL?

Started by tlf30, January 24, 2012, 07:10:55

Previous topic - Next topic

tlf30

Is there a way to directly send openGL commands to a client through a socket then run them thought the main loop, or do I just have build a giant else if chain?

CodeBunny

A client should always manage the graphics on their own. The only data that should be networked is stuff that needs to be networked, because of the potentially volatile nature of connections.

Basically, if you want to have complex graphics at all, this is one of the worst ways to have a networked setup if you want acceptable level of performance. The number of commands being sent to the GPU per frame is really significant, to push all of that onto a potentially unstable internet connection is bad news.

If you can, you should have your server issue general commands that the client interprets. Then, the client figures out what to draw without needing that much data.

Consider a multiplayer fps: the data packets would include minimal data such as all player locations, velocity, rotations, etc, and that's it. The client then renders everything accordingly - it knows what to render because it's built up knowledge about what's going on, so it only needs a tiny update to that information for the rendering to change.

CodeBunny

However, if you absolutely need to send the OpenGL commands via networking, you can do much better than a giant if/else loop. The option I would recommend would be thus:

Use an InputStream (definitely NOT a scanner or similar parser) to read the data.
Have an interface GLCall. Give it one method, callGL(InputStream is).
For every OpenGL method you want to support, define an implementation of this interface that performs the operation, reading whatever parameters it needs from the InputStream. So, to have an object that performs glColor4f, the associated java class would read like:

public class GlColor4f implements GLCall
{
	public void callGL(InputStream is)
	{
		glColor4f(is.read() / 255f, is.read() / 255f, is.read() / 255f, is.read() / 255f);
	}
}


The result is that you execute the correct command in minimal time with only 5-6 bytes of data, and there's virtually no overhead for selecting the correct command. You'll get as fast performance as is possible, and it won't slow down with the more commands you add.

tlf30

I would not send the commands at every frame, I just need a way to tell the client how to render advancd objects, but there is hundreds of these objects, and having the client keep track of them all would bog it down greatly. After the client gets the object data then all the server has to send it is the x,z,direction pointing. If an giant else if would not work good then what would I use? Also how should I send the data, I at a bind. Should I send it by vertex data then send texture data. Or would it be faster to hold the model on the client? The only problem is there are about 250 models.

CodeBunny

Either keep the model on the machine, or, have the user download the model instead of sending raw vertex data. It's probably best to simply have the client program come with all required models already packaged.

The whole point is that if the client can manage something instead of the server, the client should.

PS: Why do you have so many different models? What is this for?

tlf30

Thanks. Its a really big mmo, we have a total of about a thousand models.

CodeBunny

You'll need to keep that on the client side. There's a reason WoW's installed files are so large.

tlf30

Thanks for your help.

PS: I have never played WoW but I'll take your work for it. :)