Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdl2): add missing stubs #928

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/reason-sdl2/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(name sdl2)
(public_name Revery.sdl2)
(library_flags (:include flags.sexp))
(js_of_ocaml (javascript_files sdl2_stubs.js))
(c_library_flags (:include c_library_flags.sexp))
(c_flags (:include c_flags.sexp))
(cxx_names sdl2_wrapper stb_image)
Expand Down
57 changes: 57 additions & 0 deletions src/reason-sdl2/sdl2_stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,60 @@ function resdl_SDL_WaitTimeoutEvent() {
function resdl_SDL_GL_SwapWindow() {
// no op
}

// Provides: resdl_SDL_GetNumVideoDisplays
function resdl_SDL_GetNumVideoDisplays() {
return 1;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we can get the the number of displays via the web api. Are we OK with simply returning 1 here?

}

// Provides: resdl_SDL_GL_GetString
function resdl_SDL_GL_GetString(value) {
if (value) {
return value.toString();
} else {
return ""
}
}

// Provides: resdl_SDL_GetWindowPixelFormat
function resdl_SDL_GetWindowPixelFormat(_win) {
return "SDL_PIXELFORMAT_ARGB8888";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what we'd like to return here? Some sort of Unknown tag perhaps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't worry too much about getting this exactly right as I think the dummy stubs approach is fundamentally broken. There ought to be separate platform APIs for desktop, JS and mobile. More on that soon, but for now I'd suggest just going with whatever works short-term.

}

// Provides: resdl_SDL_GetPixelFormatName
function resdl_SDL_GetPixelFormatName(value) {
return "resdl_SDL_GetPixelFormatName: Not implemented";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

}


// Provides: resdl_SDL_GetLinkedVersion
function resdl_SDL_GetLinkedVersion() {
return 1;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

}

// Provides: resdl_SDL_GetScancodeFromName
function resdl_SDL_GetScancodeFromName() {
return "scancodeFromName";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both this and GetKeyFromName could probably be retrieved from the web api, I'd think!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// Provides: resdl_SDL_GetKeyFromName
function resdl_SDL_GetKeyFromName() {
return "keyFromname";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// Provides: resdl_SDL_GetCompiledVersion
function resdl_SDL_GetCompiledVersion() {
return "resdl_SDL_GetCompiledVersion: Not implemented";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

}

// Provides: resdl_SDL_GetDisplayBounds
function resdl_SDL_GetDisplayBounds(display) {
console.log("resdl_SDL_GetDisplayBounds, display:", display);

return {
x: 0,
y: 0,
height: joo_global_object.window.availHeight,
width: joo_global_object.window.availWidth
}
}