浏览代码

display: Support sharing graphics context between GraphicsEngines

Automatically happens when creating a new window/buffer specifying a GSG that was created with a different engine.
rdb 10 月之前
父节点
当前提交
f872a82422

+ 2 - 1
panda/src/cocoagldisplay/cocoaGLGraphicsBuffer.mm

@@ -98,7 +98,8 @@ open_buffer() {
     // If the old gsg has the wrong pixel format, create a new one that shares
     // with the old gsg.
     DCAST_INTO_R(cocoagsg, _gsg, false);
-    if (!cocoagsg->get_fb_properties().subsumes(_fb_properties)) {
+    if (cocoagsg->get_engine() != _engine ||
+        !cocoagsg->get_fb_properties().subsumes(_fb_properties)) {
       cocoagsg = new CocoaGLGraphicsStateGuardian(_engine, _pipe, cocoagsg);
       cocoagsg->choose_pixel_format(_fb_properties, cocoa_pipe->get_display_id(), false);
       _gsg = cocoagsg;

+ 2 - 2
panda/src/cocoagldisplay/cocoaGLGraphicsPipe.mm

@@ -125,12 +125,12 @@ make_output(const std::string &name,
         precertify = true;
       }
     }
-    if (host != nullptr) {
+    if (host != nullptr && host->get_engine() == _engine) {
       return new GLGraphicsBuffer(engine, this, name, fb_prop, win_prop,
                                   flags, gsg, host);
     } else {
       return new CocoaGLGraphicsBuffer(engine, this, name, fb_prop, win_prop,
-                                       flags, gsg, host);
+                                       flags, gsg, nullptr);
     }
   }
 

+ 2 - 1
panda/src/cocoagldisplay/cocoaGLGraphicsWindow.mm

@@ -200,7 +200,8 @@ open_window() {
     // If the old gsg has the wrong pixel format, create a new one that shares
     // with the old gsg.
     DCAST_INTO_R(cocoagsg, _gsg, false);
-    if (!cocoagsg->get_fb_properties().subsumes(_fb_properties)) {
+    if (cocoagsg->get_engine() != _engine ||
+        !cocoagsg->get_fb_properties().subsumes(_fb_properties)) {
       cocoagsg = new CocoaGLGraphicsStateGuardian(_engine, _pipe, cocoagsg);
       cocoagsg->choose_pixel_format(_fb_properties, _display, false);
       _gsg = cocoagsg;

+ 1 - 1
panda/src/display/graphicsEngine.cxx

@@ -339,7 +339,7 @@ make_output(GraphicsPipe *pipe,
   nassertr(pipe != nullptr, nullptr);
   if (gsg != nullptr) {
     nassertr(pipe == gsg->get_pipe(), nullptr);
-    nassertr(this == gsg->get_engine(), nullptr);
+    //nassertr(this == gsg->get_engine(), nullptr);
   }
 
   // Are we really asking for a callback window?

+ 2 - 1
panda/src/egldisplay/eglGraphicsBuffer.cxx

@@ -190,7 +190,8 @@ open_buffer() {
     // If the old gsg has the wrong pixel format, create a new one that shares
     // with the old gsg.
     DCAST_INTO_R(eglgsg, _gsg, false);
-    if (!eglgsg->get_fb_properties().subsumes(_fb_properties)) {
+    if (eglgsg->get_engine() != _engine ||
+        !eglgsg->get_fb_properties().subsumes(_fb_properties)) {
       eglgsg = new eglGraphicsStateGuardian(_engine, _pipe, eglgsg);
       eglgsg->choose_pixel_format(_fb_properties, egl_pipe, false, true, false);
       _gsg = eglgsg;

+ 3 - 0
panda/src/egldisplay/eglGraphicsPipe.cxx

@@ -288,6 +288,9 @@ make_output(const std::string &name,
         ((flags&BF_require_window)!=0)) {
       return nullptr;
     }
+    if (host->get_engine() != engine) {
+      return nullptr;
+    }
     // Early failure - if we are sure that this buffer WONT meet specs, we can
     // bail out early.
     if ((flags & BF_fb_props_optional) == 0) {

+ 2 - 1
panda/src/egldisplay/eglGraphicsWindow.cxx

@@ -223,7 +223,8 @@ open_window() {
     // If the old gsg has the wrong pixel format, create a new one that shares
     // with the old gsg.
     DCAST_INTO_R(eglgsg, _gsg, false);
-    if (!eglgsg->get_fb_properties().subsumes(_fb_properties)) {
+    if (eglgsg->get_engine() != _engine ||
+        !eglgsg->get_fb_properties().subsumes(_fb_properties)) {
       eglgsg = new eglGraphicsStateGuardian(_engine, _pipe, eglgsg);
       eglgsg->choose_pixel_format(_fb_properties, egl_pipe, true, false, false);
       _gsg = eglgsg;

+ 2 - 1
panda/src/glxdisplay/glxGraphicsBuffer.cxx

@@ -166,7 +166,8 @@ open_buffer() {
     // with the old gsg.
     DCAST_INTO_R(glxgsg, _gsg, false);
 
-    if (!glxgsg->_context_has_pbuffer ||
+    if (glxgsg->get_engine() != _engine ||
+        !glxgsg->_context_has_pbuffer ||
         !glxgsg->get_fb_properties().subsumes(_fb_properties)) {
       // We need a new pixel format, and hence a new GSG.
       glxgsg = new glxGraphicsStateGuardian(_engine, _pipe, glxgsg);

+ 3 - 0
panda/src/glxdisplay/glxGraphicsPipe.cxx

@@ -130,6 +130,9 @@ make_output(const string &name,
         (flags & (BF_require_parasite | BF_require_window)) != 0) {
       return nullptr;
     }
+    if (host->get_engine() != engine) {
+      return nullptr;
+    }
     // Early failure - if we are sure that this buffer WONT meet specs, we can
     // bail out early.
     if ((flags & BF_fb_props_optional) == 0) {

+ 2 - 1
panda/src/glxdisplay/glxGraphicsWindow.cxx

@@ -184,7 +184,8 @@ open_window() {
     // If the old gsg has the wrong pixel format, create a new one that shares
     // with the old gsg.
     DCAST_INTO_R(glxgsg, _gsg, false);
-    if (!glxgsg->get_fb_properties().subsumes(_fb_properties)) {
+    if (glxgsg->get_engine() != _engine ||
+        !glxgsg->get_fb_properties().subsumes(_fb_properties)) {
       glxgsg = new glxGraphicsStateGuardian(_engine, _pipe, glxgsg);
       glxgsg->choose_pixel_format(_fb_properties, glx_pipe->get_display(), glx_pipe->get_screen(), false, false);
       _gsg = glxgsg;

+ 4 - 3
panda/src/wgldisplay/wglGraphicsBuffer.cxx

@@ -301,9 +301,10 @@ open_buffer() {
     // If the old gsg has the wrong pixel format, create a new one that shares
     // with the old gsg.
     DCAST_INTO_R(wglgsg, _gsg, false);
-    if ((!wglgsg->get_fb_properties().subsumes(_fb_properties))||
-        (!wglgsg->get_fb_properties().is_single_buffered())||
-        (!wglgsg->pfnum_supports_pbuffer())) {
+    if (wglgsg->get_engine() != _engine ||
+        !wglgsg->get_fb_properties().subsumes(_fb_properties) ||
+        !wglgsg->get_fb_properties().is_single_buffered() ||
+        !wglgsg->pfnum_supports_pbuffer()) {
       wglgsg = new wglGraphicsStateGuardian(_engine, _pipe, wglgsg);
       wglgsg->choose_pixel_format(_fb_properties, true);
       _gsg = wglgsg;

+ 3 - 0
panda/src/wgldisplay/wglGraphicsPipe.cxx

@@ -148,6 +148,9 @@ make_output(const std::string &name,
         (flags & (BF_require_parasite | BF_require_window)) != 0) {
       return nullptr;
     }
+    if (host->get_engine() != engine) {
+      return nullptr;
+    }
     // Early failure - if we are sure that this buffer WONT meet specs, we can
     // bail out early.
     if ((flags & BF_fb_props_optional) == 0) {

+ 2 - 1
panda/src/wgldisplay/wglGraphicsWindow.cxx

@@ -209,7 +209,8 @@ open_window() {
     // If the old gsg has the wrong pixel format, create a new one that shares
     // with the old gsg.
     DCAST_INTO_R(wglgsg, _gsg, false);
-    if (!wglgsg->get_fb_properties().subsumes(_fb_properties)) {
+    if (wglgsg->get_engine() != _engine ||
+        !wglgsg->get_fb_properties().subsumes(_fb_properties)) {
       wglgsg = new wglGraphicsStateGuardian(_engine, _pipe, wglgsg);
       wglgsg->choose_pixel_format(_fb_properties, false);
       _gsg = wglgsg;