Selaa lähdekoodia

In Rev 1.130 of GraphicsOut.cxx by drwr, the query for render-to-texture support is no longer made to the gsg directly at line 368, but is instead routed through an internal GraphicsOut.get_supports_render_texture() which defaults to false. In the wgl path, the derived wglGraphicsBuffer supplies its own get_supports_render_texture() that queries the gsg. The DirectX equivalent classes do not supply an overriding get_supports_render_texture() and so fails everytime when trying to render_to_texture.

Hence, why distortion the sample is failing under Dx9.

This set of fixes patches in the requisite get_supports_render_texture() for wdxGraphicsBuffer9 and fixes a few typos between depth and color texture usages. It also fixes a depth buffer bug with render-to-textures where the depth check appeared to be missing.

Thanks to Jonah (11thpenguin) for these fixes.
Zhao Huang 13 vuotta sitten
vanhempi
sitoutus
bc900d2555

+ 3 - 1
panda/src/dxgsg9/dxTextureContext9.cxx

@@ -778,7 +778,6 @@ create_texture(DXScreenData &scrn) {
   DWORD usage;
   D3DPOOL pool;
 
-  usage = 0;
   if (tex->get_render_to_texture ( )) {
     // REQUIRED PARAMETERS
     _managed = false;
@@ -801,6 +800,7 @@ create_texture(DXScreenData &scrn) {
     _managed = scrn._managed_textures;
     if (_managed) {
       pool = D3DPOOL_MANAGED;
+      usage = 0;
     }
     else {
       if (scrn._supports_automatic_mipmap_generation) {
@@ -818,10 +818,12 @@ create_texture(DXScreenData &scrn) {
             // need to use UpdateTexture or UpdateSurface
             _managed = true;
             pool = D3DPOOL_MANAGED;
+            usage = 0;
           }
         }
         else {
           pool = D3DPOOL_DEFAULT;
+          usage = 0;
         }
       }
     }

+ 27 - 0
panda/src/dxgsg9/wdxGraphicsBuffer9.I

@@ -0,0 +1,27 @@
+// Filename: wdxGraphicsBuffer9.I
+// Created by:  zhao (29Sept12)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////
+//     Function: wdxGraphicsBuffer9::get_supports_render_texture
+//       Access: Published, Virtual
+//  Description: Returns true if this particular GraphicsOutput can
+//               render directly into a texture, or false if it must
+//               always copy-to-texture at the end of each frame to
+//               achieve this effect.
+////////////////////////////////////////////////////////////////////
+INLINE bool wdxGraphicsBuffer9::
+get_supports_render_texture() const {
+  // DX9 buffers can always bind-to-texture.
+  return true;
+}

+ 10 - 6
panda/src/dxgsg9/wdxGraphicsBuffer9.cxx

@@ -354,11 +354,15 @@ rebuild_bitplanes() {
       _color_backing_store = NULL;
     }
     if (!_color_backing_store) {
-      hr = _dxgsg -> _d3d_device ->
-        CreateOffscreenPlainSurface(bitplane_x, bitplane_y, _saved_color_desc.Format,
-                                    D3DPOOL_DEFAULT, &_color_backing_store, NULL);
+      hr = _dxgsg->_d3d_device->CreateRenderTarget(bitplane_x, bitplane_y, 
+                                                   _saved_color_desc.Format,
+                                                   _saved_color_desc.MultiSampleType,
+                                                   _saved_color_desc.MultiSampleQuality,
+                                                   FALSE,
+                                                   &_color_backing_store,
+                                                   NULL);
       if (!SUCCEEDED(hr)) {
-        dxgsg9_cat.error ( ) << "CreateImageSurface " << D3DERRORSTRING(hr) FL;
+        dxgsg9_cat.error ( ) << "CreateRenderTarget " << D3DERRORSTRING(hr) FL;
       }
     }
     color_surf = _color_backing_store;
@@ -456,13 +460,13 @@ rebuild_bitplanes() {
     if (depth_ctx) {
       if (!depth_ctx->create_texture(*_dxgsg->_screen)) {
         dxgsg9_cat.error()
-          << "Unable to re-create texture " << *color_ctx->get_texture() << endl;
+          << "Unable to re-create texture " << *depth_ctx->get_texture() << endl;
         return false;
       }
       if (depth_tex->get_texture_type() == Texture::TT_2d_texture) {
         depth_d3d_tex = depth_ctx->_d3d_2d_texture;
         nassertr(depth_d3d_tex != 0, false);
-        hr = color_d3d_tex -> GetSurfaceLevel(0, &depth_surf);
+        hr = depth_d3d_tex -> GetSurfaceLevel(0, &depth_surf);
         if (!SUCCEEDED(hr)) {
           dxgsg9_cat.error ( ) << "GetSurfaceLevel " << D3DERRORSTRING(hr) FL;
         }

+ 5 - 0
panda/src/dxgsg9/wdxGraphicsBuffer9.h

@@ -41,10 +41,13 @@ public:
                      GraphicsOutput *host);
   virtual ~wdxGraphicsBuffer9();
 
+  virtual INLINE bool get_supports_render_texture() const;  
+  
   virtual bool begin_frame(FrameMode mode, Thread *current_thread);
   virtual void end_frame(FrameMode mode, Thread *current_thread);
 
   virtual void select_cube_map(int cube_map_index);
+  
   virtual void process_events();
 
   virtual bool share_depth_buffer(GraphicsOutput *graphics_output);
@@ -101,4 +104,6 @@ private:
   friend class DXTextureContext9;
 };
 
+#include "wdxGraphicsBuffer9.I"
+
 #endif

+ 2 - 4
panda/src/dxgsg9/wdxGraphicsPipe9.cxx

@@ -150,10 +150,8 @@ make_output(const string &name,
     // Early success - if we are sure that this buffer WILL
     // meet specs, we can precertify it.
     // This looks rather overly optimistic -- ie, buggy.
-    if ((gsg != 0)&&
-        (gsg->is_valid())&&
-        (!gsg->needs_reset())&&
-        (DCAST(DXGraphicsStateGuardian9, gsg)->get_supports_render_texture())) {
+    if ((wdxgsg != NULL) && wdxgsg->is_valid() && !wdxgsg->needs_reset() &&
+        wdxgsg->get_supports_render_texture()) {
       precertify = true;
     }
     return new wdxGraphicsBuffer9(engine, this, name, fb_prop, win_prop,