Replies: 5 comments 5 replies
-
By the way, can you build a version of https://github.com/thenick775/mgba/tree/feature/wasm like this from skyEmu, the control keys and game settings are called from the frontend, not from the in the wasm file like the version that sky builds https://web.skyemu.app |
Beta Was this translation helpful? Give feedback.
-
In the current mGBA version, SDL through emscripten does all the rendering in this case, see here for the full rendering implementation: Meaning in this case, mGBA and emscripten together own drawing to the canvas, which is opaque to the frontend for the most part. For further information on how this works in SDL see the wiki page here: You would need to use shaders that are compatible with the WebGL-friendly subset of OpenGL ES 2.0, I haven't had much luck doing things like that though, see my canvas reset code for an example of why. I was not able to easily work with shaders myself to get the desired LCD fade effect, as I'm not the best with webGL, the best I could do was clear colors with my knowledge, so any LCD fade effects you see here are done on a 2d canvas copy of the webgl canvas that I can then use the usual methods to manipulate and draw. You should be able to use webgl shaders if you have the knowledge, but you'll have to work with mGBA drawing to the canvas buffers itself, I'm not planning to change how that's done at this time. To break down some further talking points:
You could copy the webgl canvas context to a 2d canvas and use that to render what you want, and perform any manipulations manually, but I would expect this to be much slower, where utilizing webgl shaders and attaching this to the webgl canvas context should work, but I don't have enough knowledge with raw webgl to be of much help myself there. In essence this is what emscripten/mGBA is doing for me in my frontend, where the canvas is the pixel grid, specified by width and height attributes, as those specify the buffer dimensions. In the wasm c binding code, I use the mGBA constants |
Beta Was this translation helpful? Give feedback.
-
I understand, you are also quite struggling with this part of OpenGl. I'm trying to learn it too, simply I'm wanting to redraw the canvas with openGl and re-scale the pixel grid every time the canvas changes size. Doing that then I can apply lcd pixel mock filters on the pixel color layers. You also see the colors displayed on skyEmu, right? I really want to do what sky is doing for your emulator. Reading your code, I see that it uses OpenGl 3.0, but it seems that browsers cannot use OpenGl 3.0 yet. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the detailed explanation above. But if possible, can you help me write the code that initializes the canvas with openGl and redraws it to simulate display on the frontend? Like the function screenshot you just wrote for me, but it can only draw the image at that time, not continuously like the canvas is displaying from mgba and emscripten running under the backend. I really want to try applying effects, or standardizing the colors on the canvas |
Beta Was this translation helpful? Give feedback.
-
Just circling back here as I have a better idea of what mGBA is doing under the hood. I don't think it will work well to do anything with the webgl canvas context on the frontend, you'd most likely need to go into the SDL/renderer code in mGBA and write your shaders there with OpenGL instead of attempting to use WebGL |
Beta Was this translation helpful? Give feedback.
-
I'm planning to add shader layers to the surface of the canvas, but I don't know which function allows redrawing the canvas so it can be edited in the frontend. Currently my rendered canvas on the frontend is simply black but in reality the backend is using it to render the simulator
Is there a way for me to use OpenGL to display the emulator on the frontend so that I can easily draw a pixel grid and have the emulator's image displayed on it?
Beta Was this translation helpful? Give feedback.
All reactions