Best way to manage render targets, buffers, etc...?

Started by
5 comments, last by ATC 11 years, 6 months ago
Up late, doing some more work on the engine. And I just started questioning the way I've done things in the past... wondering if there is not a better way than the approach I currently take. I'm wanting to know the best way for the engine to manage its render targets, depth stencils, viewports, etc...

FYI: The engine is completely written in C#, and is built upon a data-driven architecture. It is also fully platform-agnostic and API-agnostic, so I must take care to ensure what I do works across DirectX 10 - 11 and OpenGL (as well as custom software renderers and 3rd party back-ends).

Attached to my post is an example diagram which shows how a platform-specific implementation of the "Renderer" interface (in this case the D3D10 implementation) "plugs in" to the engine. I added this to give you an idea of how the code is structured. Now tell me, if you please, how I need to be managing my render targets, depth stencils and all such things...

EDIT: Note that in the diagram the "Engine" and "Application" parts are NOT actually classes... they are simply representative of how things sort of fit together.
_______________________________________________________________________________
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine

Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________
Advertisement

Now tell me, if you please, how I need to be managing my render targets, depth stencils and all such things...


The "right thing to do" would depend heavilly on the game type that you have in mind. If you're just looking to make some general utilities to communicate with the GPU, via OpenGL or DirectX, then you could do that in the "Renderer" subsystem; Concepts like "render target" and "depth stencil" can be modeled into abstractions that will "do the right thing", regardless of the underlying graphics API.

That said: I would recommend building games, not engines.

+---------------------------------------------------------------------+

| Game Dev video tutorials -> http://www.youtube.com/goranmilovano | +---------------------------------------------------------------------+

The "right thing to do" would depend heavilly on the game type that you have in mind. If you're just looking to make some general utilities to communicate with the GPU, via OpenGL or DirectX, then you could do that in the "Renderer" subsystem; Concepts like "render target" and "depth stencil" can be modeled into abstractions that will "do the right thing", regardless of the underlying graphics API.


I agree... I'm leaning towards the idea of allowing my agnostic "GraphicsManager" class to manage an abstracted form of render targets, depth stencils, etc... and a derrived Renderer implementation can translate the parameters and turn it into usable, API-specific objects...


That said: I would recommend building games, not engines.


This is, in truth, generally good advice. But doesn't apply to everyone. Sometimes writing a good free-standing engine can be incredibly profitable; both financially and through productivity of actual game development.
_______________________________________________________________________________
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine

Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________

Sometimes writing a good free-standing engine can be incredibly profitable; both financially and through productivity of actual game development.


Unfortunately unless you are driving that engine development via a game then you are not likely to end up with a good free-standing engine; I've seen what happens when a group of people, who have experiance with making games, try to do just that... hell, I've been involved in the various rebuilds/rewrites/fixes over the last year to get the thing from a 'we can drive a car around a test level' to 'we can run a game at 60fps across 3 platforms' - some bits of the code are simply not the same any more as they weren't driven by a need.

All, and I mean ALL, the bst engines have been driven by a game to develop and test them.
It's a simple fact of life.

I've seen what happens when a group of people, who have experiance with making games, try to do just that...

I've seen the same happens once too, it is like target practising without target.
I cover this topic in detail here: http://lspiroengine.com/?p=49
My engine runs on 3 platforms (iOS, Macintosh OS X, and Windows x86/x64) and supports 5 rendering API’s (OpenGL ES 2.0, OpenGL 3.2, DirectX 9, DirectX 10, and DirectX 11).
I use the method described in my post and things are extremely clean and easy to manage. It is always easy to add support for new platforms or API’s.

In a nutshell:
CTextureBase
COpenGlStandardTexture : public CTextureBase -OR- CDirectX9StandardTexture : public CTextureBase -ETC.-
CStandardTexture : public *API-specific class here*

The objective is to use as few #ifdef’s (are those allowed in C#? I forgot) as possible. Or whatever way C# has for switching code between multiple platforms.
This keeps the platform-specific code in separate files and simply injects them into a class hierarchy where needed, reducing the mess of trying to handle support for 5 different platforms all inside one file.

The rest of the engine just uses CStandardTexture, which has an interface that does not change across any platforms.

This applies equally well to render targets, vertex buffers, index buffers, shaders, etc.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

You guys are correct... not going to argue against your remarks. But rest assured this engine isn't one of those "shell" projects (an engine that just exists for the sake of being an engine)... As of right now development is fairly generalized. But we shift gears as the engine grows. Right now we're not writing games but working towards developing some very complex demos, sample apps and mini-games to test all fronts and bases of the engine. And by "complex" scenes I mean, for example, an outdoor scene with 100Sq.km of terrain, night/day cycles, wildlife, growing vegetation, bodies of water (filled with fish), fully rigged/animated characters, AI, etc... These sorts of demos/samples ensure everything a next-gen game or simulation might want to do will not only work but work very well and run very fast -- and it takes a fraction of the time a complete, marketable game takes yet still satisfies the need for proofing the engine. Writing such demos and samples will be evolving into full-blown games and simulations as the capacity for producing them matures. I've been working on this for 5+ years, and I've found that this works best for me. Essentially it is the same thing you suggest, but I prefer to let the games/apps evolve into bigger and better things and grow with the engine.

@ L.Spiro:

Thanks again! I always enjoy reading your posts and I like your website as well. I have a lot of respect for you as a programmer. :-)

Yes, C# does indeed allow #if/#else/#define/etc... My code base actually has a very small number of "#ifs", and they are all oriented towards debugging, bounds checking, etc... For instance (contrived example):

public void SetTexture( Texture2D texture ) {
#if DEBUG || PERFORM_CHECKS
if(texture == null)
throw new ArgumentNullException("texture");
#endif

this.Texture = texture;
}

I actually have TOTALLY avoided anything like this:

#if OPEN_GL
// ...
#elif DIRECTX
//...
#endif

...we simply do not do this at all. We make one build per target platform; and by "platform" I mean hardware itself... one build for desktop/laptop, one for XBox, one for PS3, one for iPhone, etc. The engine can switch between OpenGL and DirectX versions and entire APIs at runtime. The design is capable of hosting a game on Windows, for example, where the user can select whether the game runs on DirectX or OpenGL and can switch this setting whilst playing the game.

Your example of "CTextureBase" describes how virtually everything works... from Renderer implementations to Shader and Material implementations. Thank you for describing this, however, as your words are quite helpful. I think I've about gotten this figured out. When I'm done with the re-write I'll let you guys know if I had any problems and/or share my solutions.

Regards,

--ATC--
_______________________________________________________________________________
CEO & Lead Developer at ATCWARE™
"Project X-1"; a 100% managed, platform-agnostic game & simulation engine

Please visit our new forums and help us test them and break the ice!
___________________________________________________________________________________

This topic is closed to new replies.

Advertisement