google-chromeopenglppapi

Multiple OpenGL ppapi plugins in a single webpage


I am using the following example ppapi plugin that renders a spinning cube with openGL: https://chromium.googlesource.com/chromium/src/ppapi/+/master/examples/gles2_spinning_cube.

I am able to embed this in a webpage running in Chrome and it all works fine as expected. The code for my html page is identical to here: https://chromium.googlesource.com/chromium/src/ppapi/+/master/examples/gles2_spinning_cube/gles2_spinning_cube.html

However, if I add another embed html element to load the same plugin twice on the same page, only the second embed shows the spinning cube. The first embed renders a single frame before stopping.

<embed id="plugin" type="application/x-ppapi-example-gles2-spinning-cube" width="800" height="600"/>
<embed id="plugin2" type="application/x-ppapi-example-gles2-spinning-cube" width="800" height="600"/>

Does Chrome support multiple ppapi plugins on the same web page? If this should be working fine, then can someone help me identify why this is happening - is this because I have multiple OpenGL contexts or something? Fwiw, I am on Ubuntu and I can try on Windows/Mac to compare if necessary. I am using --register-pepper-plugin with Chrome.

Ultimately I want to use this with CEF (https://bitbucket.org/chromiumembedded/cef) but as this isn't working with Chrome I want to first get to the bottom of this issue, then move onto CEF.


Solution

  • Yes, Chrome does support multiple ppapi plugins on the same page, and it was due to a missing call to glSetCurrentContextPPAPI in the ppapi example code. It should have been as follows:

    void DemoInstance::Paint(int32_t result) {
      if (result != PP_OK || !context_)
        return;
    
      glSetCurrentContextPPAPI(context_->pp_resource()); // missing from example
    
      cube_.UpdateForTimeDelta(0.02f);
      cube_.Draw();
      context_->SwapBuffers(callback_factory_.NewCallback(&DemoInstance::Paint));
    }