theagentd and I were discussing abstraction of graphics backends and we both couldn’t think of the best solution to the problem.
The issue, for me, is having my software renderer and OpenGL (and possibly other) backends work under the same level of abstraction and theagentd’s issue is the same but with OpenGL and Vulkan.
The main issue is with the symbolic constants. Vulkan, OpenGL and the software renderer have different symbolic constants and we dont know the best way to abstract these symbolic constants.
theagentd currently uses enums like
public enum PrimitiveTopology{
PointList(GL_POINTS, VK_PRIMITIVE_TOPOLOGY_POINT_LIST),
LineList(GL_LINES, VK_PRIMITIVE_TOPOLOGY_LINE_LIST),
TriangleList(GL_TRIANGLES, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST),
private int gl, vk;
private PrimitiveTopology(int gl, int vk){
this.gl = gl;
this.vk = vk;
}
public int gl() {
return gl;
}
public int vk() {
return vk;
}
}
Where the implementation simply gets the appropriate symbolic constant that it needs from the enum by doing .gl() for the OpenGL implementation and .vk() for the Vulkan implementation.
This sounds great but then we realized that in order to add a new implementation, we would have to add its symbolic constants to this “master enum” which kinda ruins the idea of having a contained implementation.
theagentd said that the enum could hold array indices which index into an array of symbolic constants defined by the implementation, but this can be slower.
Does anyone have any ideas?