Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/functionloading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function debug_opengl_expr(func_name, args)
end
end

# On 32-bit Windows, OpenGL functions use stdcall calling convention (APIENTRY).
# On 64-bit Windows (and all other platforms), there is only one calling convention.
const _gl_calling_convention = (Sys.iswindows() && Sys.WORD_SIZE == 32) ? :stdcall : :cdecl

# based on getCFun macro
macro glfunc(opengl_func)
arguments = map(opengl_func.args[1].args[2:end]) do arg
Expand All @@ -47,14 +51,15 @@ macro glfunc(opengl_func)
func_name_sym = Expr(:quote, func_name)
func_name_str = string(func_name)
ptr_expr = :(getprocaddress_e($func_name_str))
cc = _gl_calling_convention

if Sys.iswindows() # windows has some function pointers statically available and some not, this is how we deal with it:
ptr = Libdl.dlsym_e(gl_lib, func_name)
if (ptr != C_NULL)
ptr_expr = :(($func_name_sym, "opengl32"))
ret = quote
function $func_name($(arg_names...))
result = ccall($ptr_expr, $return_type, ($(input_types...),), $(arg_names...))
result = ccall($ptr_expr, $(cc), $return_type, ($(input_types...),), $(arg_names...))
$(debug_opengl_expr(func_name, arg_names))
result
end
Expand All @@ -70,7 +75,7 @@ macro glfunc(opengl_func)
if $ptr_sym[]::Ptr{Cvoid} == C_NULL
$ptr_sym[]::Ptr{Cvoid} = $ptr_expr
end
result = ccall($ptr_sym[]::Ptr{Cvoid}, $return_type, ($(input_types...),), $(arg_names...))
result = ccall($ptr_sym[]::Ptr{Cvoid}, $(cc), $return_type, ($(input_types...),), $(arg_names...))
$(debug_opengl_expr(func_name, arg_names))
result
end
Expand Down
Loading