Graphics Interface Layer
Question submitted by (22 January 2000)




Return to The Archives
 
  I like to write an graphics interface layer that can use OpenGL and Dx internally. I read your solution in the FOK column but a still confused about the implementations. I can think of 2 solns.

1. Create an abstract base graphics class and derive classes that use OpenGL or Dx implementations. I don't like this because it requires virtual functions and as a graphics API, speed is a concern.

2. Create two seperate auxillary class that implements OpenGL and Dx8 specifically with same interfaces(implemented in a dll) and graphics interface calls the auxillary class. This is a maintanence nightmare and it's quite troublesome too.

When I decide to add a texture object class that can be implemented by using a Dx surface (dx8) or a series of bytes (OpenGL), both methods does not allow it easily without some ugly friends access (and other nightmarish practices).

I would like to make function calls like this

// use the object to set the texture in graphics object
Texture_Object.SetTexture(Graphics_Interface_Object);

and

// use the graphics layer object to set a texture
Graphcs_Interface_Object.SetTexture(Texture_Object);

What are your suggestions?
 
 

 
  Personally, I would go with #1, but make sure to give your API a high-level interface.

The high level interface will reduce the number of calls placed into it. For example, you won't be calling it per polygon, you'll be calling it per mesh. If you're worried about the calls you do place through the virtual mechanism, don't worry about it. The difference is probably only about 0.001 frames per second, which is a small price to pay for maintainability and cleaner design.

The places where you'll loose a lot of performance from the virtual mechanism is in your low-level APIs, (like a matrix/vector class, for example.)

I think you're running into problems with your Texture_ObjectSetTexture() example because you're not working at a high-enough level. Try placing your texture information in the object data (or class) when you pass it to the rendering DLL.



Response provided by Paul Nettle
 
 

This article was originally an entry in flipCode's Ask Midnight, a Question and Answer column with Paul Nettle that's no longer active.


 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.