zahirtezcan's picture

GL functions as part of GraphicsContext

[Discussion moved from here]

I just want to mention some comments:

the Fiddler wrote:

Also known as an "OpenGL context", it is the glue that routes OpenGL commands to the OpenGL driver for execution. Obviously, you cannot use any OpenGL commands without a GraphicsContext.

Since context implies commands, commands may be member functions for the context object. (I am not curious about the cost for virtual function call.) This is actually default for Direct3D device class. So, several OpenGL profiles may be supported by instantiating a context for such profile (e.g. Context2_1, Context3_0 etc.). Well, with deprecated(or removed in 3.1) features, OpenGL call count is not that much as in immediate modes.(Virtual call issue was indicated when DirectX first declared its usage by COM interop, but it turned out to be good). As i have said, this is my comment for future compliant issues, but most of the users are happy with immediate modes so it will remain as intended

the Fiddler wrote:

The GLControl provides the GLControl.BeginInvoke() method to simplify asynchronous method calls from secondary threads to the main System.Windows.Forms.Application thread. The GameWindow does not provide a similar API.

Such API can be supported by usage of System.Threading.SynchronizationContext class.(Video is talking about a .NET 4.0 feature but in the beginning gives example for a SynchronizationContext usage)


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture
zahirtezcan wrote:

I just want to mention some comments:

the Fiddler wrote:

Also known as an "OpenGL context", it is the glue that routes OpenGL commands to the OpenGL driver for execution. Obviously, you cannot use any OpenGL commands without a GraphicsContext.

Since context implies commands, commands may be member functions for the context object. (I am not curious about the cost for virtual function call.) This is actually default for Direct3D device class. So, several OpenGL profiles may be supported by instantiating a context for such profile (e.g. Context2_1, Context3_0 etc.). [...]

About methods as part of GraphicsContext: I actually have such a prototype but I'm not convinced the improvement is worth breaking every single program. The issue isn't so much the cost of virtual method calls (they don't actually *need* to be virtual, each subset can be independent) or the additional cost of passing a "this" pointer (negligible), as much as the jump in memory consumption.

Then, there's the issue of having everything and the kitchen sync as part of the GraphicsContext class. Ideally, you'd have separate classes for Textures, Framebuffers, Shaders etc, and the GraphicsContext would be the glue that ties everything together. As it happens, I'm also working on such a prototype right now and its a matter greater improvement than moving the flat API from one class to another. :-)

zahirtezcan wrote:
the Fiddler wrote:

The GLControl provides the GLControl.BeginInvoke() method to simplify asynchronous method calls from secondary threads to the main System.Windows.Forms.Application thread. The GameWindow does not provide a similar API.

Such API can be supported by usage of System.Threading.SynchronizationContext class.(Video is talking about a .NET 4.0 feature but in the beginning gives example for a SynchronizationContext usage)

Thanks for the link. I wasn't aware of this class and it sounds *very* useful.