macroquad icon indicating copy to clipboard operation
macroquad copied to clipboard

render_target not working in wgsl

Open ddmills opened this issue 4 months ago • 2 comments

minimal reproduction here: https://github.com/ddmills/quads-gl-wasm

use macroquad::prelude::*;

fn window_conf() -> Conf { 
    Conf::default()
}

#[macroquad::main(window_conf)]
async fn main() {
    println!("Hello, world!");

    // [warning] "Missed function: glCheckFramebufferStatus"
    // [panic] .cargo/registry/src/index.crates.io-1949cf8c6b5b557f/miniquad-0.4.8/src/graphics/gl.rs, line: 1144, column: 21
    render_target(100, 100);

    loop {
        draw_fps();
        next_frame().await;
    }
}
[warning] "Missed function: glCheckFramebufferStatus"
[panic] .cargo/registry/src/index.crates.io-1949cf8c6b5b557f/miniquad-0.4.8/src/graphics/gl.rs, line: 1144, column: 21
Image

ddmills avatar Aug 16 '25 00:08 ddmills

Looks like render target support needs a few more functions than just glCheckFramebufferStatus - I needed to add the following to mq_js_bundle.js to make the wasm build work with render targets:

var importObject = {
  env: {
    // Begin lines to add
    glCheckFramebufferStatus: function (e) {
      return gl.checkFramebufferStatus(e);
    },
    glReadBuffer: function (e) {
      gl.readBuffer(e);
    },
    glBlitFramebuffer: function (
      srcX0,
      srcY0,
      srcX1,
      srcY1,
      dstX0,
      dstY0,
      dstX1,
      dstY1,
      mask,
      filter
    ) {
      gl.blitFramebuffer(
        srcX0,
        srcY0,
        srcX1,
        srcY1,
        dstX0,
        dstY0,
        dstX1,
        dstY1,
        mask,
        filter
      );
    },
    // End lines to add
    console_debug: function (ptr) {
      console.debug(UTF8ToString(ptr));
    },

With that in place, the lighting prototype for my noita-like works on the wasm build.

For the benefit of others (/future me), here's an easy to repro example: copy-paste examples/post_processing.rs, update the provided index.html to load the patched mq_js_bundle.js, serve it up some way (e.g. python -m http.server) and then it'll run in the browser:

Image

caspark avatar Sep 03 '25 08:09 caspark

Looks like render target support needs a few more functions than just glCheckFramebufferStatus - I needed to add the following to mq_js_bundle.js to make the wasm build work with render targets:

var importObject = {
  env: {
    // Begin lines to add
    glCheckFramebufferStatus: function (e) {
      return gl.checkFramebufferStatus(e);
    },
    glReadBuffer: function (e) {
      gl.readBuffer(e);
    },
    glBlitFramebuffer: function (
      srcX0,
      srcY0,
      srcX1,
      srcY1,
      dstX0,
      dstY0,
      dstX1,
      dstY1,
      mask,
      filter
    ) {
      gl.blitFramebuffer(
        srcX0,
        srcY0,
        srcX1,
        srcY1,
        dstX0,
        dstY0,
        dstX1,
        dstY1,
        mask,
        filter
      );
    },
    // End lines to add
    console_debug: function (ptr) {
      console.debug(UTF8ToString(ptr));
    },

With that in place, the lighting prototype for my noita-like works on the wasm build.

For the benefit of others (/future me), here's an easy to repro example: copy-paste examples/post_processing.rs, update the provided index.html to load the patched mq_js_bundle.js, serve it up some way (e.g. python -m http.server) and then it'll run in the browser: Image

Thanks for your code. Thanks to you, I was finally able to fix this bug.

Kiyotoko avatar Sep 29 '25 19:09 Kiyotoko