Skip to content

Commit b4bfd6d

Browse files
committed
make sure gl options are set after init()
1 parent 03110f7 commit b4bfd6d

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

libs/sdl/sdl/Sdl.hx

+41-15
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,52 @@ typedef ScreenMode = {
1616
var framerate : Int;
1717
};
1818

19+
typedef GLOptions = {
20+
final major : Int;
21+
final minor : Int;
22+
final depth : Int;
23+
final stencil : Int;
24+
final flags : Int;
25+
final samples : Int;
26+
}
27+
1928
@:hlNative("sdl")
2029
class Sdl {
2130

2231
static var initDone = false;
2332
static var isWin32 = false;
2433

25-
public static var requiredGLMajor(default,null) = 3;
26-
public static var requiredGLMinor(default,null) = 2;
34+
public static var glOptions(default,null) : GLOptions = {
35+
major : 3,
36+
minor : 2,
37+
depth : 24,
38+
stencil : 8,
39+
flags : 1,
40+
samples : 1,
41+
};
2742

2843
public static function init() {
2944
if( initDone ) return;
3045
initDone = true;
3146
if( !initOnce() ) throw "Failed to init SDL";
3247
isWin32 = detectWin32();
48+
var opt = glOptions;
49+
gl_options(opt.major, opt.minor, opt.depth, opt.stencil, opt.flags, opt.samples);
50+
}
51+
52+
public static function setGLOptions(options) {
53+
glOptions = options;
3354
}
3455

35-
public static function setGLOptions( major : Int = 3, minor : Int = 2, depth : Int = 24, stencil : Int = 8, flags : Int = 1, samples : Int = 1 ) {
36-
requiredGLMajor = major;
37-
requiredGLMinor = minor;
38-
glOptions(major, minor, depth, stencil, flags, samples);
56+
public static function setGLVersion(major, minor) {
57+
glOptions = {
58+
major : major,
59+
minor : minor,
60+
depth : glOptions.depth,
61+
stencil : glOptions.stencil,
62+
flags : glOptions.flags,
63+
samples : glOptions.samples
64+
};
3965
}
4066

4167
public static function setHint(name:String, value:String) {
@@ -52,7 +78,7 @@ class Sdl {
5278
if( device == null ) device = "Unknown";
5379
var flags = new haxe.EnumFlags<hl.UI.DialogFlags>();
5480
flags.set(IsError);
55-
var msg = 'The application was unable to create an OpenGL context\nfor your $device video card.\nOpenGL $requiredGLMajor.$requiredGLMinor+ is required, please update your driver.';
81+
var msg = 'The application was unable to create an OpenGL context\nfor your $device video card.\nOpenGL ${glOptions.major}.${glOptions.minor}+ is required, please update your driver.';
5682
hl.UI.dialog("OpenGL Error", msg, flags);
5783
Sys.exit( -1);
5884
}
@@ -62,7 +88,7 @@ class Sdl {
6288
public static inline var GL_COMPATIBILITY_PROFILE = 1 << 2;
6389
public static inline var GL_ES = 1 << 3;
6490

65-
static function glOptions( major : Int, minor : Int, depth : Int, stencil : Int, flags : Int, samples : Int ) {}
91+
static function gl_options( major : Int, minor : Int, depth : Int, stencil : Int, flags : Int, samples : Int ) {}
6692

6793
static function initOnce() return false;
6894
static function eventLoop( e : Dynamic ) return false;
@@ -87,7 +113,7 @@ class Sdl {
87113
}
88114

89115
public static function getScreenWidth(?win : sdl.Window) : Int {
90-
return
116+
return
91117
if(win == null)
92118
get_screen_width();
93119
else
@@ -110,7 +136,7 @@ class Sdl {
110136
public static function message( title : String, text : String, error = false ) {
111137
@:privateAccess messageBox(title.toUtf8(), text.toUtf8(), error);
112138
}
113-
139+
114140
public static function getDisplayModes(display : Window.DisplayHandle) : Array<ScreenMode> {
115141
var modes = get_display_modes(display);
116142
if(modes == null)
@@ -129,7 +155,7 @@ class Sdl {
129155
var i = 0;
130156
return [ for(d in get_displays() ) @:privateAccess { handle: d.handle, name: '${String.fromUTF8(d.name)} (${++i})', left: d.left, top: d.top, right: d.right, bottom: d.bottom } ];
131157
}
132-
158+
133159
public static function getDevices() {
134160
var a = [];
135161
var arr = get_devices();
@@ -147,7 +173,7 @@ class Sdl {
147173
public static function setRelativeMouseMode( enable : Bool ) : Int {
148174
return 0;
149175
}
150-
176+
151177
public static function setClipboardText( text : String ) : Bool {
152178
if( text == null )
153179
return false;
@@ -211,7 +237,7 @@ class Sdl {
211237
public static function getRelativeMouseMode() : Bool {
212238
return false;
213239
}
214-
240+
215241
public static function warpMouseGlobal( x : Int, y : Int ) : Int {
216242
return 0;
217243
}
@@ -233,11 +259,11 @@ class Sdl {
233259
private static function _getClipboardText() : hl.Bytes {
234260
return null;
235261
}
236-
262+
237263
@:hlNative("?sdl", "set_drag_and_drop_enabled")
238264
public static function setDragAndDropEnabled( v : Bool ): Void {
239265
}
240-
266+
241267
@:hlNative("?sdl", "get_drag_and_drop_enabled")
242268
public static function getDragAndDropEnabled(): Bool {
243269
return false;

0 commit comments

Comments
 (0)