Browse Source

preliminary version of render to texture, still needs cleanup, testing

aignacio_sf 20 years ago
parent
commit
830d509665

+ 3 - 1
panda/src/dxgsg9/Sources.pp

@@ -38,7 +38,9 @@
     dxTextureContext9.cxx \
     dxTextureContext9.cxx \
     dxGeomMunger9.cxx \
     dxGeomMunger9.cxx \
     dxGraphicsDevice9.cxx \
     dxGraphicsDevice9.cxx \
-    wdxGraphicsPipe9.cxx wdxGraphicsWindow9.cxx
+    wdxGraphicsPipe9.cxx \
+    wdxGraphicsWindow9.cxx \
+    wdxGraphicsBuffer9.cxx
 
 
 
 
 #end lib_target
 #end lib_target

+ 26 - 0
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -117,6 +117,9 @@ DXGraphicsStateGuardian9(const FrameBufferProperties &properties) :
     Geom::GR_indexed_other |
     Geom::GR_indexed_other |
     Geom::GR_triangle_strip | Geom::GR_triangle_fan |
     Geom::GR_triangle_strip | Geom::GR_triangle_fan |
     Geom::GR_flat_first_vertex;
     Geom::GR_flat_first_vertex;
+
+  // default render to texture format
+  _render_to_texture_d3d_format = D3DFMT_X8R8G8B8;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -1730,6 +1733,29 @@ reset() {
   _supports_texture_saved_result = ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP) != 0);
   _supports_texture_saved_result = ((d3d_caps.PrimitiveMiscCaps & D3DPMISCCAPS_TSSARGTEMP) != 0);
   _supports_texture_dot3 = true;
   _supports_texture_dot3 = true;
 
 
+  // check for render to texture support
+  D3DDEVICE_CREATION_PARAMETERS creation_parameters;
+
+  _d3d_device->GetCreationParameters (&creation_parameters);
+
+  hr = _screen->_d3d9->CheckDeviceFormat
+     (creation_parameters.AdapterOrdinal,
+      creation_parameters.DeviceType,
+      _screen->_display_mode.Format,
+      D3DUSAGE_RENDERTARGET,
+      D3DRTYPE_TEXTURE,
+      _render_to_texture_d3d_format);
+  if (SUCCEEDED (hr)) {
+    _supports_render_texture = true;
+  }
+  else {
+    _supports_render_texture = false;
+  }
+
+  if (dxgsg9_cat.is_debug()) {
+    dxgsg9_cat.debug() << "Render to Texture Support = " << _supports_render_texture << "\n";
+  }
+
   _supports_3d_texture = ((d3d_caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP) != 0);
   _supports_3d_texture = ((d3d_caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP) != 0);
   if (_supports_3d_texture) {
   if (_supports_3d_texture) {
     _max_3d_texture_dimension = d3d_caps.MaxVolumeExtent;
     _max_3d_texture_dimension = d3d_caps.MaxVolumeExtent;

+ 3 - 0
panda/src/dxgsg9/dxGraphicsStateGuardian9.h

@@ -234,6 +234,8 @@ protected:
   static unsigned char *_temp_buffer;
   static unsigned char *_temp_buffer;
   static unsigned char *_safe_buffer_start;
   static unsigned char *_safe_buffer_start;
 
 
+  D3DFORMAT _render_to_texture_d3d_format;
+
 public:
 public:
   virtual TypeHandle get_type() const {
   virtual TypeHandle get_type() const {
     return get_class_type();
     return get_class_type();
@@ -258,6 +260,7 @@ private:
   friend class wdxGraphicsPipe9;
   friend class wdxGraphicsPipe9;
   friend class wdxGraphicsWindowGroup9;
   friend class wdxGraphicsWindowGroup9;
   friend class DXTextureContext9;
   friend class DXTextureContext9;
+  friend class wdxGraphicsBuffer9;
 };
 };
 
 
 #include "dxGraphicsStateGuardian9.I"
 #include "dxGraphicsStateGuardian9.I"

+ 2 - 0
panda/src/dxgsg9/dxTextureContext9.h

@@ -77,6 +77,8 @@ public:
 
 
 private:
 private:
   static TypeHandle _type_handle;
   static TypeHandle _type_handle;
+
+  friend class wdxGraphicsBuffer9;
 };
 };
 
 
 #include "dxTextureContext9.I"
 #include "dxTextureContext9.I"

+ 2 - 0
panda/src/dxgsg9/dxgsg9_composite1.cxx

@@ -1,4 +1,5 @@
 #include "dxgsg9base.h"
 #include "dxgsg9base.h"
+#include "wdxGraphicsBuffer9.cxx"
 #include "config_dxgsg9.cxx"
 #include "config_dxgsg9.cxx"
 #include "dxTextureContext9.cxx"
 #include "dxTextureContext9.cxx"
 #include "dxVertexBufferContext9.cxx"
 #include "dxVertexBufferContext9.cxx"
@@ -7,3 +8,4 @@
 #include "wdxGraphicsPipe9.cxx"
 #include "wdxGraphicsPipe9.cxx"
 #include "wdxGraphicsWindow9.cxx"
 #include "wdxGraphicsWindow9.cxx"
 #include "dxGraphicsDevice9.cxx"
 #include "dxGraphicsDevice9.cxx"
+

+ 13 - 0
panda/src/dxgsg9/wdxGraphicsPipe9.cxx

@@ -19,6 +19,7 @@
 #include "wdxGraphicsPipe9.h"
 #include "wdxGraphicsPipe9.h"
 #include "dxGraphicsDevice9.h"
 #include "dxGraphicsDevice9.h"
 #include "wdxGraphicsWindow9.h"
 #include "wdxGraphicsWindow9.h"
+#include "wdxGraphicsBuffer9.h"
 #include "config_dxgsg9.h"
 #include "config_dxgsg9.h"
 
 
 TypeHandle wdxGraphicsPipe9::_type_handle;
 TypeHandle wdxGraphicsPipe9::_type_handle;
@@ -97,6 +98,18 @@ make_window(GraphicsStateGuardian *gsg, const string &name) {
   return new wdxGraphicsWindow9(this, gsg, name);
   return new wdxGraphicsWindow9(this, gsg, name);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: wdxGraphicsPipe9::make_buffer
+//       Access: Protected, Virtual
+//  Description: Creates a new offscreen buffer on the pipe, if possible.
+////////////////////////////////////////////////////////////////////
+PT(GraphicsBuffer) wdxGraphicsPipe9::
+make_buffer(GraphicsStateGuardian *gsg, const string &name,
+            int x_size, int y_size) {
+
+  return new wdxGraphicsBuffer9(this, gsg, name, x_size, y_size);
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: wdxGraphicsPipe9::init
 //     Function: wdxGraphicsPipe9::init
 //       Access: Private
 //       Access: Private

+ 2 - 1
panda/src/dxgsg9/wdxGraphicsPipe9.h

@@ -59,7 +59,8 @@ public:
 
 
 protected:
 protected:
   virtual PT(GraphicsWindow) make_window(GraphicsStateGuardian *gsg, const string &name);
   virtual PT(GraphicsWindow) make_window(GraphicsStateGuardian *gsg, const string &name);
-
+  virtual PT(GraphicsBuffer) make_buffer(GraphicsStateGuardian *gsg, const string &name,
+            int x_size, int y_size);
 private:
 private:
   bool init();
   bool init();
   bool find_all_card_memavails();
   bool find_all_card_memavails();