quick backup
[demo] / src / gfxapi.cc
1 #include "opengl/opengl.h"
2 #include "vulkan/vk.h"
3
4 #include "gfxapi.h"
5
6 #include "opengl/mesh-gl.h"
7 #include "opengl/texture-gl.h"
8 #include "opengl/shader-gl.h"
9
10 #include "vulkan/shader-vk.h"
11 #include "vulkan/mesh-vk.h"
12 #include "vulkan/texture-vk.h"
13
14 static Gfx_API api;
15
16 void (*gfx_clear)(float r, float g, float b);
17 void (*gfx_viewport)(int x, int y, int width, int height);
18 void (*gfx_zbuffer)(bool enable);
19 void (*gfx_cull_face)(Gfx_cull_face cf);
20 void (*gfx_reshape)(int width, int height);
21 void (*gfx_wireframe)(bool enable);
22
23 bool gfx_init(Gfx_API api)
24 {
25         switch(api) {
26         case GFX_GL:
27                 if(!init_opengl())
28                         return false;
29                 break;
30         case GFX_VK:
31                 if(!init_vulkan())
32                         return false;
33                 break;
34         default:
35                 return false;
36         }
37
38         ::api = api;
39         return true;
40 }
41
42 void gfx_cleanup()
43 {
44         switch(api) {
45         case GFX_GL:
46                 cleanup_opengl();
47                 break;
48         case GFX_VK:
49                 cleanup_vulkan();
50                 break;
51         }
52 }
53
54 Mesh *gfx_create_mesh()
55 {
56         switch(api) {
57         case GFX_GL:
58                 return new MeshGL;
59         case GFX_VK:
60                 return new MeshVK;
61         }
62         return 0;
63 }
64 Texture *gfx_create_texture()
65 {
66         switch(api) {
67         case GFX_GL:
68                 return new TextureGL;
69         case GFX_VK:
70                 return new TextureVK;
71         }
72         return 0;
73 }
74
75 ShaderProgram *gfx_create_shader_program()
76 {
77         switch(api) {
78         case GFX_GL:
79                 return new ShaderProgramGL;
80         case GFX_VK:
81                 return new ShaderProgramVK;
82         }
83         return 0;
84 }
85
86 Shader *gfx_create_shader()
87 {
88         switch(api) {
89         case GFX_GL:
90                 return new ShaderGL;
91         case GFX_VK:
92                 return new ShaderVK;
93         }
94         return 0;
95 }
96
97 char *gfx_get_shader_path()
98 {
99         switch(api) {
100         case GFX_GL:
101                 return (char *)"gl_shaders";
102         case GFX_VK:
103                 return (char *)"vk_shaders";
104         }
105         return (char *)"";
106 }