lispgames / cl-sdl2

Common Lisp bindings for SDL2 using C2FFI.
MIT License
304 stars 82 forks source link

How to request a Core Context using SDL2 #92

Closed Davidbhodge closed 7 years ago

Davidbhodge commented 7 years ago

Hi,

New to SDL2.

I have an oldish Mac that is capable of creating a Core 3.3 GL context. I can do this in C on my machine.

Using SDL2 out of the box I get the default Compatibility context which is 2.1. I would like to know where I should put the incantation for a Core context? This is what I believe is necessary

(sdl2:gl-set-attr :context-major-version 3) (sdl2:gl-set-attr :context-minor-version 3) (sdl2:gl-set-attr :context-profile-mask sdl2-ffi::+SDL-GL-CONTEXT-PROFILE-CORE+))

I also believe that I need to set +SDL-GL-CONTEXT-FORWARD-COMPATIBLE-FLAG+ to true, but not quite sure how to do that.

Any pointers gratefully received!

Cheers

rpav commented 7 years ago

You should be able to use :context-flags with the latter; I don't know if or where this would be necessary and I haven't tested it. Setting the core profile this way should work, however.

Someone should really make sdl2:gl-set-attr smarter and decode profile/context-flags as appropriate. I am not likely to get to this anytime soon myself, though.

ReinUsesLisp commented 7 years ago

Do you mean something like: (sdl2:gl-set-attr :context-profile-mask :core) and: (sdl2:gl-set-attr :context-flags '(:debug :forward-compatible :robust-access :reset-isolation))

Davidbhodge commented 7 years ago

Yes, I mean exactly that. Thanks so much!

Davidbhodge commented 7 years ago

just as a note for other readers the suggested solution above does not work. gl-set-attr complains that the symbols used (eg :forward-compatible) are not numbers. So my issue is really 2 fold - having an old machine and not having enough familiarity with SDL to be able to grok the code base. For the moment I will let this rest and explore some alternatives.

rpav commented 7 years ago

Doing this should be relatively simple, you basically need to define an enum from a bunch of constants; see pixels.lisp. Then you need to look it up in the appropriate places, similar to video.lisp.

Using define-enum-from-constants should automatically remove common prefixes etc. For masks, this is nearly the same, except you need to use define-bitmask-from-enum or define-bitmask-from-constants to create the bitmask name, and mask-apply to create the value.

RobertBColton commented 5 years ago

Hey guys, I know I'm not involved with your project, but I feel I need to promote awareness of this SDL bug. So just to clarify that specifying the core bit only will not give you a core context, this is an SDL bug. SDL also requires that you specify the version number. That is not required when creating a core context under WGL or GLX and it is clarified in the Khronos documentation.

Please see https://github.com/enigma-dev/enigma-dev/issues/1686 on our game engine project if you would like further details about the bug.