@@ -88,6 +88,10 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
88
88
try c_source_files .append ("rtextures.c" );
89
89
}
90
90
91
+ if (options .opengl_version != .auto ) {
92
+ raylib .defineCMacro (options .opengl_version .toCMacroStr (), null );
93
+ }
94
+
91
95
switch (target .result .os .tag ) {
92
96
.windows = > {
93
97
try c_source_files .append ("rglfw.c" );
@@ -134,7 +138,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
134
138
135
139
raylib .defineCMacro ("PLATFORM_DESKTOP" , null );
136
140
} else {
137
- raylib .linkSystemLibrary ("GLESv2" );
141
+ if (options .opengl_version == .auto ) {
142
+ raylib .linkSystemLibrary ("GLESv2" );
143
+ raylib .defineCMacro ("GRAPHICS_API_OPENGL_ES2" , null );
144
+ }
145
+
138
146
raylib .linkSystemLibrary ("EGL" );
139
147
raylib .linkSystemLibrary ("drm" );
140
148
raylib .linkSystemLibrary ("gbm" );
@@ -145,7 +153,6 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
145
153
raylib .addIncludePath (.{ .cwd_relative = "/usr/include/libdrm" });
146
154
147
155
raylib .defineCMacro ("PLATFORM_DRM" , null );
148
- raylib .defineCMacro ("GRAPHICS_API_OPENGL_ES2" , null );
149
156
raylib .defineCMacro ("EGL_NO_X11" , null );
150
157
raylib .defineCMacro ("DEFAULT_BATCH_BUFFER_ELEMENT" , "2048" );
151
158
}
@@ -183,7 +190,9 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
183
190
},
184
191
.emscripten = > {
185
192
raylib .defineCMacro ("PLATFORM_WEB" , null );
186
- raylib .defineCMacro ("GRAPHICS_API_OPENGL_ES2" , null );
193
+ if (options .opengl_version == .auto ) {
194
+ raylib .defineCMacro ("GRAPHICS_API_OPENGL_ES2" , null );
195
+ }
187
196
188
197
if (b .sysroot == null ) {
189
198
@panic ("Pass '--sysroot \" $EMSDK/upstream/emscripten\" '" );
@@ -239,11 +248,34 @@ pub const Options = struct {
239
248
platform_drm : bool = false ,
240
249
shared : bool = false ,
241
250
linux_display_backend : LinuxDisplayBackend = .X11 ,
251
+ opengl_version : OpenglVersion = .auto ,
242
252
243
253
raylib_dependency_name : []const u8 = "raylib" ,
244
254
raygui_dependency_name : []const u8 = "raygui" ,
245
255
};
246
256
257
+ pub const OpenglVersion = enum {
258
+ auto ,
259
+ gl_1_1 ,
260
+ gl_2_1 ,
261
+ gl_3_3 ,
262
+ gl_4_3 ,
263
+ gles_2 ,
264
+ gles_3 ,
265
+
266
+ pub fn toCMacroStr (self : @This ()) []const u8 {
267
+ switch (self ) {
268
+ .auto = > @panic ("OpenglVersion.auto cannot be turned into a C macro string" ),
269
+ .gl_1_1 = > return "GRAPHICS_API_OPENGL_11" ,
270
+ .gl_2_1 = > return "GRAPHICS_API_OPENGL_21" ,
271
+ .gl_3_3 = > return "GRAPHICS_API_OPENGL_33" ,
272
+ .gl_4_3 = > return "GRAPHICS_API_OPENGL_43" ,
273
+ .gles_2 = > return "GRAPHICS_API_OPENGL_ES2" ,
274
+ .gles_3 = > return "GRAPHICS_API_OPENGL_ES3" ,
275
+ }
276
+ }
277
+ };
278
+
247
279
pub const LinuxDisplayBackend = enum {
248
280
X11 ,
249
281
Wayland ,
@@ -270,6 +302,7 @@ pub fn build(b: *std.Build) !void {
270
302
.rshapes = b .option (bool , "rshapes" , "Compile with shapes support" ) orelse defaults .rshapes ,
271
303
.shared = b .option (bool , "shared" , "Compile as shared library" ) orelse defaults .shared ,
272
304
.linux_display_backend = b .option (LinuxDisplayBackend , "linux_display_backend" , "Linux display backend to use" ) orelse defaults .linux_display_backend ,
305
+ .opengl_version = b .option (OpenglVersion , "opengl_version" , "OpenGL version to use" ) orelse defaults .opengl_version ,
273
306
};
274
307
275
308
const lib = try compileRaylib (b , target , optimize , options );
0 commit comments