Monday, May 20, 2024
HomeGame Developmentopengl - How do you handle shaders/graphics while remaining cross-platform?

opengl – How do you handle shaders/graphics while remaining cross-platform?


I’m building a C++ based game engine, and I have my ECS complete as well as some basic components for stuff like graphics & audio. However, I’m currently using a custom interface on top of SFML with GLSL based shaders and OpenGL based graphics. I’d like to switch to a graphics solution where I can switch between OpenGL, Vulkan, DirectX3D, and Metal without rewriting large portioins of my code. The graphics API itself isn’t a problem, since I can easily build an interface on top of it and reimplement it for each desired platform. My issue, however, is with the shaders.

I’m currently writing my test shaders in GLSL targeting OpenGL. I know I can use the SPIR-V translator to generate HLSL/MSL/Vulkan-Style GLSL from my OpenGL source code, but I’m not sure how that will work when I start having to set uniforms, handle shader buffers, and the like.

The big solution I’ve heard of is generating shaders at runtime, which is what Godot does. However, my engine is very performance-oriented, so I’d like to precompile all my shaders if possible. I’ve also seen that Unity uses HLSL2GLSL translator and SPIR-V cross is very common. However, I’m worried about how these will interact with setting uniforms and whatnot, and I’m very concerned about their impact on performance.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments