Browse Source

Update render to texture format. Automatically select the texture format by matching the render format.

aignacio_sf 20 years ago
parent
commit
58484fd621

+ 10 - 4
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -117,9 +117,6 @@ DXGraphicsStateGuardian8(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;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -1647,11 +1644,20 @@ 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
   // check for render to texture support
   D3DDEVICE_CREATION_PARAMETERS creation_parameters;
   D3DDEVICE_CREATION_PARAMETERS creation_parameters;
 
 
   _supports_render_texture = false;
   _supports_render_texture = false;
+
   hr = _d3d_device->GetCreationParameters (&creation_parameters);
   hr = _d3d_device->GetCreationParameters (&creation_parameters);
+
+  // default render to texture format
+//  _screen->_render_to_texture_d3d_format = D3DFMT_X8R8G8B8;
+
+  // match the display mode format for render to texture
+  _screen->_render_to_texture_d3d_format = _screen->_display_mode.Format;
+
   if (SUCCEEDED (hr)) {
   if (SUCCEEDED (hr)) {
     hr = _screen->_d3d8->CheckDeviceFormat (
     hr = _screen->_d3d8->CheckDeviceFormat (
         creation_parameters.AdapterOrdinal,
         creation_parameters.AdapterOrdinal,
@@ -1659,7 +1665,7 @@ reset() {
         _screen->_display_mode.Format,
         _screen->_display_mode.Format,
         D3DUSAGE_RENDERTARGET,
         D3DUSAGE_RENDERTARGET,
         D3DRTYPE_TEXTURE,
         D3DRTYPE_TEXTURE,
-        _render_to_texture_d3d_format);
+        _screen->_render_to_texture_d3d_format);
     if (SUCCEEDED (hr)) {
     if (SUCCEEDED (hr)) {
       _supports_render_texture = true;
       _supports_render_texture = true;
     }
     }

+ 0 - 2
panda/src/dxgsg8/dxGraphicsStateGuardian8.h

@@ -234,8 +234,6 @@ 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();

+ 1 - 3
panda/src/dxgsg8/dxTextureContext8.cxx

@@ -637,9 +637,7 @@ create_texture(DXScreenData &scrn) {
     // REQUIRED
     // REQUIRED
     pool = D3DPOOL_DEFAULT;
     pool = D3DPOOL_DEFAULT;
     usage = D3DUSAGE_RENDERTARGET;
     usage = D3DUSAGE_RENDERTARGET;
-
-// *****
-    target_pixel_format = D3DFMT_X8R8G8B8;
+    target_pixel_format = scrn._render_to_texture_d3d_format;
   }
   }
   else {
   else {
     pool = D3DPOOL_MANAGED;
     pool = D3DPOOL_MANAGED;

+ 5 - 4
panda/src/dxgsg8/dxgsg8base.h

@@ -74,7 +74,7 @@ typedef DWORD DXShaderHandle;
     type var;                       \
     type var;                       \
     ZeroMemory(&var, sizeof(type)); \
     ZeroMemory(&var, sizeof(type)); \
     var.dwSize = sizeof(type);
     var.dwSize = sizeof(type);
-    
+
 #define SAFE_DELSHADER(TYPE,HANDLE,PDEVICE)  \
 #define SAFE_DELSHADER(TYPE,HANDLE,PDEVICE)  \
   if((HANDLE!=NULL)&&IS_VALID_PTR(PDEVICE)) { PDEVICE->Delete##TYPE##Shader(HANDLE);  HANDLE=NULL; }
   if((HANDLE!=NULL)&&IS_VALID_PTR(PDEVICE)) { PDEVICE->Delete##TYPE##Shader(HANDLE);  HANDLE=NULL; }
 
 
@@ -90,7 +90,7 @@ typedef DWORD DXShaderHandle;
 #define RELEASE_ONCE false
 #define RELEASE_ONCE false
 
 
 
 
-// uncomment to add refcnt debug output 
+// uncomment to add refcnt debug output
 #define DEBUG_RELEASES
 #define DEBUG_RELEASES
 
 
 #ifdef DEBUG_RELEASES
 #ifdef DEBUG_RELEASES
@@ -112,7 +112,7 @@ typedef DWORD DXShaderHandle;
 
 
 #define PRINT_REFCNT(MODULE,p) { ULONG refcnt;  (p)->AddRef();  refcnt=(p)->Release(); \
 #define PRINT_REFCNT(MODULE,p) { ULONG refcnt;  (p)->AddRef();  refcnt=(p)->Release(); \
                                  MODULE##_cat.debug() << #p << " has refcnt = " << refcnt << " at " << __FILE__ << ":" << __LINE__ << endl; }
                                  MODULE##_cat.debug() << #p << " has refcnt = " << refcnt << " at " << __FILE__ << ":" << __LINE__ << endl; }
-                                 
+
 #else
 #else
 #define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero)   { \
 #define RELEASE(OBJECT,MODULE,DBGSTR,bDoDownToZero)   { \
    ULONG refcnt;                                        \
    ULONG refcnt;                                        \
@@ -128,7 +128,7 @@ typedef DWORD DXShaderHandle;
    }}
    }}
 
 
 #define PRINT_REFCNT(MODULE,p)
 #define PRINT_REFCNT(MODULE,p)
-#endif    
+#endif
 
 
 #ifdef DO_PSTATS
 #ifdef DO_PSTATS
 #define DO_PSTATS_STUFF(XX) XX;
 #define DO_PSTATS_STUFF(XX) XX;
@@ -206,6 +206,7 @@ struct DXScreenData {
   D3DDISPLAYMODE _display_mode;
   D3DDISPLAYMODE _display_mode;
   D3DPRESENT_PARAMETERS _presentation_params;  // not redundant with _display_mode since width/height must be 0 for windowed mode
   D3DPRESENT_PARAMETERS _presentation_params;  // not redundant with _display_mode since width/height must be 0 for windowed mode
   D3DADAPTER_IDENTIFIER8 _dx_device_id;
   D3DADAPTER_IDENTIFIER8 _dx_device_id;
+  D3DFORMAT _render_to_texture_d3d_format;
 };
 };
 
 
 
 

+ 9 - 4
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -117,9 +117,6 @@ 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;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -1743,7 +1740,15 @@ reset() {
   D3DDEVICE_CREATION_PARAMETERS creation_parameters;
   D3DDEVICE_CREATION_PARAMETERS creation_parameters;
 
 
   _supports_render_texture = false;
   _supports_render_texture = false;
+
   hr = _d3d_device->GetCreationParameters (&creation_parameters);
   hr = _d3d_device->GetCreationParameters (&creation_parameters);
+
+  // default render to texture format
+//  _screen->_render_to_texture_d3d_format = D3DFMT_X8R8G8B8;
+
+  // match the display mode format for render to texture
+  _screen->_render_to_texture_d3d_format = _screen->_display_mode.Format;
+
   if (SUCCEEDED (hr)) {
   if (SUCCEEDED (hr)) {
     hr = _screen->_d3d9->CheckDeviceFormat (
     hr = _screen->_d3d9->CheckDeviceFormat (
         creation_parameters.AdapterOrdinal,
         creation_parameters.AdapterOrdinal,
@@ -1751,7 +1756,7 @@ reset() {
         _screen->_display_mode.Format,
         _screen->_display_mode.Format,
         D3DUSAGE_RENDERTARGET,
         D3DUSAGE_RENDERTARGET,
         D3DRTYPE_TEXTURE,
         D3DRTYPE_TEXTURE,
-        _render_to_texture_d3d_format);
+        _screen->_render_to_texture_d3d_format);
     if (SUCCEEDED (hr)) {
     if (SUCCEEDED (hr)) {
       _supports_render_texture = true;
       _supports_render_texture = true;
     }
     }

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

@@ -234,8 +234,6 @@ 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();

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

@@ -640,9 +640,7 @@ create_texture(DXScreenData &scrn) {
     // REQUIRED
     // REQUIRED
     pool = D3DPOOL_DEFAULT;
     pool = D3DPOOL_DEFAULT;
     usage = D3DUSAGE_RENDERTARGET;
     usage = D3DUSAGE_RENDERTARGET;
-
-// *****
-    target_pixel_format = D3DFMT_X8R8G8B8;
+    target_pixel_format = scrn._render_to_texture_d3d_format;
   }
   }
   else {
   else {
     pool = D3DPOOL_MANAGED;
     pool = D3DPOOL_MANAGED;

+ 1 - 0
panda/src/dxgsg9/dxgsg9base.h

@@ -208,6 +208,7 @@ struct DXScreenData {
   D3DDISPLAYMODE _display_mode;
   D3DDISPLAYMODE _display_mode;
   D3DPRESENT_PARAMETERS _presentation_params;  // not redundant with _display_mode since width/height must be 0 for windowed mode
   D3DPRESENT_PARAMETERS _presentation_params;  // not redundant with _display_mode since width/height must be 0 for windowed mode
   D3DADAPTER_IDENTIFIER9 _dx_device_id;
   D3DADAPTER_IDENTIFIER9 _dx_device_id;
+  D3DFORMAT _render_to_texture_d3d_format;
 };
 };