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
8bit SDL_Surfaces aren't supported when created using SDL_CreateRGBSurface #754
Comments
Hmm, i used 8bpp surface in my projects and it is works fine for me. Implementation of emscripten don`t use BitsPerPixel internally it uses SDL_HWSURFACE flag only. May be you should simple ignore this. I try to look what happen with format descriptor later... |
I made mistake with flag names, currently SLD support 8bpp surface only when SDL_HWPALETTE flag set.
Works as expected. |
Thanks. This seems to indeed work (screen->format->BitsPerPixel == 8), although I'm not entirely sure if this is the normal way of dealing with 8bpp surfaces in SDL. Unfortunately, I can't seem to manipulate the pixels array of the resulting SDL_Surface. Normally, you'd lock the surface, write to the pixels array, and then unlock the surface. However, when I try to do that I get an error at runtime: "CopyOnLock is not supported for SDL_LockSurface with SDL_HWPALETTE flag set". The relevant test (https://github.com/kripken/emscripten/blob/master/tests/sdl_canvas_palette_2.c) crashes for me, as well, with the same error message. If I don't lock and unlock the SDL_Surface, I don't get any output at all (just a white screen), so that doesn't work either. Do you happen to know how I can manually edit the pixels array and still have my changes show up? |
Copy on lock is not supported for now. But it can be easily implemented if needed. To avoid this you should set flag copy on lock = false.
I think test should be fixed to work properly with copyOnLock flag. In my project i use surface in order:
SDL_LockSurface copy canvas pixels to backend storage when copyOnLock == true, in other way SDL_LockSurface do nothing. copyOnLock only needed if you want to draw on canvas through HTML/JS and С++ code Also copyOnLock == true gives a performance penalty |
To run test canvas_2 you also can set default == false in emscripten soruces https://github.com/kripken/emscripten/blob/master/src/library_sdl.js
|
Thank you very much. Setting copyOnLock to false allows me to directly edit the pixels of SDL Surfaces. I'll close this issue, since an acceptable (to me) workaround has been found. |
…h SDL_HWPALETTE flag set' using instructions here: emscripten-core/emscripten#754
The SDL_CreateRGBSurface function allows for a bit depth to be set, but the JavaScript implementation of this function completely ignores this bitdepth function parameter.
The above code returns "BPP is 8" when compiled natively, but "BPP is 32" when compiled with Emscripten.
The text was updated successfully, but these errors were encountered: