1
\$\begingroup\$

I'm building a simple game engine (or mostly rendering engine) and I would like to separate the "engine" part from the "game" part. So, I've come up with an idea to build "engine" part as a library (static or dynamic) and the "game" part will link to this library. Simple.

However, there is one problem - "engine" part needs to reference some assets i.e. files with source code of builtin shaders (defualt shaders of the rendering engine).

Is there a way to include these shader files into an "engine" library? Or is there any other solution to this problem?

\$\endgroup\$
5
  • \$\begingroup\$ It depends. Tell us which grapical API or renderer you are using. For OpenGL you can have shader source code stored in a string buffer defined at compilation time. \$\endgroup\$
    – Ocelot
    Commented Jun 8, 2018 at 20:54
  • \$\begingroup\$ For now I'm using OpenGL, but later I would like to also support Vulkan. I've considered using string buffers for shaders' code but I don't feel that it's a good idea. \$\endgroup\$
    – Shot
    Commented Jun 8, 2018 at 21:43
  • \$\begingroup\$ Can you explain what reservations you have with this approach? Knowing what's holding you back can guide what alternatives to offer, or suggest evidence to show if it might not be as big a problem as expected. \$\endgroup\$
    – DMGregory
    Commented Jun 8, 2018 at 22:37
  • \$\begingroup\$ Are these shaders that would likely be useful to multiple projects (maybe some general lighting that different games could make use of) or are they specific to the game you're working on with it (such as a pattern generator that wouldn't be useful to another game)? \$\endgroup\$ Commented Jun 9, 2018 at 1:44
  • \$\begingroup\$ These shaders are just basic/standard shaders that can be used by any new game. @DMGregory - I think that it's a bad idea because it can't be simply applied to e.g. Vulkan shaders which have to be in binary files stored on disk (according to my knowledge). \$\endgroup\$
    – Shot
    Commented Jun 9, 2018 at 15:31

1 Answer 1

2
\$\begingroup\$

All my engine's core shaders are provided as data files, and we simply expect each game to include those files as part of their game data. We load them exactly the same way we load any other game asset. Creating a new game? First thing you do is copy those default shaders into your game's asset directory. (The engine complains and refuses to start if they're not there)

I felt it was important for individual games to have the ability to modify those default shaders, which is why I wanted them to be included in the game's data, rather than in a separate "engine data" directory. I wanted it to be possible for a particular game to replace the 'default' shaders simply by changing their contents, and without needing to touch the engine itself.

With that said, I do also have a few simple rendering effects (blurs, bloom, etc) which include their own minimal shaders in static string buffers inside the engine, as they're just simple utilities; if somebody wanted something particular, they'd make it themselves rather than use the engine's simple built-in effects.

\$\endgroup\$
2
  • \$\begingroup\$ It seems reasonable. Do you use any library to pack these "standard" assets and then unpack them at runtime? \$\endgroup\$
    – Shot
    Commented Jun 9, 2018 at 15:32
  • 1
    \$\begingroup\$ Nope; they're just plain text files. I just open and read them as text, compile them, and throw away the text. I do use PhysicsFS to handle loading files so that I could theoretically put all my files into a zipfile and load them from there, but for the moment I just leave all the assets loose in a directory. \$\endgroup\$ Commented Jun 10, 2018 at 0:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .