Hi guys,

I'm Geoffrey, VR UX product designer since 2005. My mozillian id is Hypergeff

I'm currently digging into Mozilla GFX source code for the first time.
I'd love to help Mozilla stepping into VR, and not only VR based on HMDs 
because VR will be much more than HMDs .
So I'd like to create a proof of concept of webGL active stereoscopic 
rendering. (I'd like to achieve this kind immersive sketchfab viewer on a 
zSpace monitor, that I did with the Chromium Embedded Framwork:  
https://vimeo.com/85780695)

There is only a few lines of code to achieve this, but I don't know where to 
implement it into Firefox code.

The easiest way I think that should work, is to do a WebGL script which does 
left and right view rendering on top of each other, in a 1920*2400 canvas (each 
view sizing 1920*1200 ).



>From this left/right framebuffer image, I will then draw the top part image in 
>the GL_Back_Left buffer and bottom part in the GL_BACK_RIGHT buffer.

Before that, I have to declare stereo support to the openGL webGl layer window 
(pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | 
PFD_STEREO; )



Here is the code I added in CEF that I know is working well for doing active 
stereoscopy

1.      Set the openGL window to support stereo (PFD_STEREO)

// Get the device context.
  hDC_ = GetDC(hWnd_);

  // Set the pixel format for the DC.
  ZeroMemory(&pfd, sizeof(pfd));
  pfd.nSize = sizeof(pfd);
  pfd.nVersion = 1;
  pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | 
PFD_STEREO; 
  pfd.iPixelType = PFD_TYPE_RGBA;
  pfd.cColorBits = 24;
  pfd.cDepthBits = 16;
  pfd.iLayerType = PFD_MAIN_PLANE;
  format = ChoosePixelFormat(hDC_, &pfd);
  SetPixelFormat(hDC_, format, &pfd);



2.      Do the left/right drawing from the top/bottom stereo rendered image

void ClientOSRenderer::Render() {
  if (view_width_ == 0 || view_height_ == 0)
    return;

  ASSERT(initialized_);

  struct {
          float tu, tv;
          float x, y, z;
  } static vertices_imageTopPart[] = { // top half part of the image buffer
          {0.0f, 0.5f, -1.0f, -1.0f, 0.0f}, // bas gauche
          {1.0f, 0.5f,  1.0f, -1.0f, 0.0f}, // bas droite
          {1.0f, 0.0f,  1.0f,  1.0f, 0.0f}, // haut droite
          {0.0f, 0.0f, -1.0f,  1.0f, 0.0f} //  haut gauche
  };
  struct {
          float tu, tv;
          float x, y, z;
  } static vertices_imageBottomPart[] = { // bottom half part of the image 
buffer
          {0.0f, 1.0f, -1.0f, -1.0f, 0.0f}, // bas gauche
          {1.0f, 1.0f,  1.0f, -1.0f, 0.0f}, // bas droite
          {1.0f, 0.5f,  1.0f,  1.0f, 0.0f}, // haut droite
          {0.0f, 0.5f, -1.0f,  1.0f, 0.0f} //  haut gauche
  };
  

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  // Match GL units to screen coordinates.
  glViewport(0, 0, view_width_, view_height_/2);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0, 0, view_width_, view_height_/2, 0.1, 100.0); 

  // clear drawing buffers and z-buffer(s)
  glFlush();
  glDrawBuffer (GL_BACK);
  glClearColor(0.2f, 0.2f, 0.2f, 0.0f);  // non-black bkgr, less ghosting
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Enable 2D textures.
  glEnable(GL_TEXTURE_2D);

  // Draw the facets with the texture.
  ASSERT(texture_id_ != 0);
  glBindTexture(GL_TEXTURE_2D, texture_id_);  // offscreen texture given from 
chromium rendering
 
  // Draw the left eye view
  glFlush();
  glDrawBuffer (GL_BACK_LEFT);      // draws to left buffer

  glInterleavedArrays(GL_T2F_V3F, 0, vertices_imageBottomPart);
  glDrawArrays(GL_QUADS, 0, 4);

  // If we were doing a solid rendering, we would want to clear the
  //    z-buffer before each eye's rendering, since some stereo 
  //    hardware/driver implementations only include one shared 
  //    z-buffer
  glClear (GL_DEPTH_BUFFER_BIT);

  // Draw the right eye view
  glFlush();
  glDrawBuffer (GL_BACK_RIGHT);

  glInterleavedArrays(GL_T2F_V3F, 0, vertices_imageTopPart);
  glDrawArrays(GL_QUADS, 0, 4);

  // Disable 2D textures.
  glDisable(GL_TEXTURE_2D);


  glFlush();

}


My issue:
*************************

In Firefox, I disabled angle and set openGL as the preferred Layer renderer 
from the about:config window.

Then I added PFD_STEREO dwFlag in WGLLibrary::CreateDummyWindow(HDC *aWindowDC) 
from GLContextProviderWGL.cpp at line 58.
(At this point I am still not sure if the final WebGL layer compositing window 
will be openGL or DirectX...)

Now I'm looking for a place where I could do the WebGL stereo image cutting and 
back_left/back_right  glDrawBuffer.
I tried to do it in GLContext.h, in void fFlush()  and in 
raw_fBlitFramebuffer(), but it always crashes at runtime when I add one of 
those 2 openGL commands:  mSymbols.fInterleavedArrays or mSymbols.fDrawArrays



Would you guys have some advice in the way to achieve this ?


Thanks much

Cordialement / Best Regards, 

Geoffrey SUBILEAU
Lead VR UX and R&D manager, immersive Virtuality Lab


_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to