Browse Source

Add restore gamma.

aignacio_sf 18 years ago
parent
commit
f451758ce4

+ 9 - 0
panda/src/display/graphicsStateGuardian.cxx

@@ -2087,6 +2087,15 @@ get_gamma(float gamma) {
   return _gamma;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::restore_gamma
+//       Access: Published, Virtual
+//  Description: Restore original gamma setting.
+////////////////////////////////////////////////////////////////////
+void GraphicsStateGuardian::
+restore_gamma() {
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsStateGuardian::create_gamma_table
 //       Access: Public, Static

+ 1 - 0
panda/src/display/graphicsStateGuardian.h

@@ -153,6 +153,7 @@ PUBLISHED:
 
   virtual bool set_gamma(float gamma);
   float get_gamma(float gamma);
+  virtual void restore_gamma();
   
 public:
   bool set_scene(SceneSetup *scene_setup);

+ 14 - 5
panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx

@@ -4330,7 +4330,6 @@ void _create_gamma_table (float gamma, unsigned short *original_red_table, unsig
 //       Access: Public, Static
 //  Description: Static function for getting the original gamma.
 ////////////////////////////////////////////////////////////////////
-
 bool DXGraphicsStateGuardian8::
 get_gamma_table(void) {
   bool get;  
@@ -4359,7 +4358,7 @@ get_gamma_table(void) {
 //               for atexit.
 ////////////////////////////////////////////////////////////////////
 bool DXGraphicsStateGuardian8::
-static_set_gamma(float gamma) {
+static_set_gamma(bool restore, float gamma) {
   bool set;  
   HDC hdc = GetDC(NULL);
 
@@ -4367,7 +4366,7 @@ static_set_gamma(float gamma) {
   if (hdc) {   
     unsigned short ramp [256 * 3];
 
-    if (_gamma_table_initialized) {    
+    if (restore && _gamma_table_initialized) {    
       _create_gamma_table (gamma, &_orignial_gamma_table [0], &_orignial_gamma_table [256], &_orignial_gamma_table [512], &ramp [0], &ramp [256], &ramp [512]);
     }
     else {
@@ -4394,7 +4393,7 @@ bool DXGraphicsStateGuardian8::
 set_gamma(float gamma) {
   bool set;
 
-  set = static_set_gamma(gamma);
+  set = static_set_gamma(false, gamma);
   if (set) {
     _gamma = gamma;  
   }
@@ -4402,6 +4401,16 @@ set_gamma(float gamma) {
   return set;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian8::restore_gamma
+//       Access: Published
+//  Description: Restore original gamma.
+////////////////////////////////////////////////////////////////////
+void DXGraphicsStateGuardian8::
+restore_gamma() {
+  static_set_gamma(true, 1.0f);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian8::atexit_function
 //       Access: Public, Static
@@ -4409,5 +4418,5 @@ set_gamma(float gamma) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian8::
 atexit_function(void) {
-  static_set_gamma(1.0);
+  static_set_gamma(true, 1.0);
 }

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

@@ -124,8 +124,9 @@ public:
   LPDIRECT3DDEVICE8 get_d3d_device();
 
   static bool get_gamma_table(void);
-  static bool static_set_gamma(float gamma);
+  static bool static_set_gamma(bool restore, float gamma);
   bool set_gamma(float gamma);
+  void restore_gamma();
   static void atexit_function(void);
 
 protected:

+ 14 - 5
panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx

@@ -5703,7 +5703,6 @@ void _create_gamma_table (float gamma, unsigned short *original_red_table, unsig
 //       Access: Public, Static
 //  Description: Static function for getting the original gamma.
 ////////////////////////////////////////////////////////////////////
-
 bool DXGraphicsStateGuardian9::
 get_gamma_table(void) {
   bool get;  
@@ -5732,7 +5731,7 @@ get_gamma_table(void) {
 //               for atexit.
 ////////////////////////////////////////////////////////////////////
 bool DXGraphicsStateGuardian9::
-static_set_gamma(float gamma) {
+static_set_gamma(bool restore, float gamma) {
   bool set;  
   HDC hdc = GetDC(NULL);
 
@@ -5740,7 +5739,7 @@ static_set_gamma(float gamma) {
   if (hdc) {   
     unsigned short ramp [256 * 3];
 
-    if (_gamma_table_initialized) {    
+    if (restore && _gamma_table_initialized) {    
       _create_gamma_table (gamma, &_orignial_gamma_table [0], &_orignial_gamma_table [256], &_orignial_gamma_table [512], &ramp [0], &ramp [256], &ramp [512]);
     }
     else {
@@ -5767,7 +5766,7 @@ bool DXGraphicsStateGuardian9::
 set_gamma(float gamma) {
   bool set;
 
-  set = static_set_gamma(gamma);
+  set = static_set_gamma(false, gamma);
   if (set) {
     _gamma = gamma;  
   }
@@ -5775,6 +5774,16 @@ set_gamma(float gamma) {
   return set;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: DXGraphicsStateGuardian9::restore_gamma
+//       Access: Published
+//  Description: Restore original gamma.
+////////////////////////////////////////////////////////////////////
+void DXGraphicsStateGuardian9::
+restore_gamma() {
+  static_set_gamma(true, 1.0f);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: DXGraphicsStateGuardian9::atexit_function
 //       Access: Public, Static
@@ -5782,5 +5791,5 @@ set_gamma(float gamma) {
 ////////////////////////////////////////////////////////////////////
 void DXGraphicsStateGuardian9::
 atexit_function(void) {
-  static_set_gamma(1.0);
+  static_set_gamma(true, 1.0f);
 }

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

@@ -170,8 +170,9 @@ public:
   INLINE HRESULT set_sampler_state (DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value);
 
   static bool get_gamma_table(void);
-  static bool static_set_gamma(float gamma);
+  static bool static_set_gamma(bool restore, float gamma);
   bool set_gamma(float gamma);
+  void restore_gamma();
   static void atexit_function(void);
 
 protected:

+ 14 - 5
panda/src/wgldisplay/wglGraphicsStateGuardian.cxx

@@ -800,7 +800,6 @@ void _create_gamma_table (float gamma, unsigned short *original_red_table, unsig
 //       Access: Public, Static
 //  Description: Static function for getting the original gamma.
 ////////////////////////////////////////////////////////////////////
-
 bool wglGraphicsStateGuardian::
 get_gamma_table(void) {
   bool get;  
@@ -829,7 +828,7 @@ get_gamma_table(void) {
 //               for atexit.
 ////////////////////////////////////////////////////////////////////
 bool wglGraphicsStateGuardian::
-static_set_gamma(float gamma) {
+static_set_gamma(bool restore, float gamma) {
   bool set;  
   HDC hdc = GetDC(NULL);
 
@@ -837,7 +836,7 @@ static_set_gamma(float gamma) {
   if (hdc) {   
     unsigned short ramp [256 * 3];
 
-    if (_gamma_table_initialized) {    
+    if (restore && _gamma_table_initialized) {    
       _create_gamma_table (gamma, &_orignial_gamma_table [0], &_orignial_gamma_table [256], &_orignial_gamma_table [512], &ramp [0], &ramp [256], &ramp [512]);
     }
     else {
@@ -864,7 +863,7 @@ bool wglGraphicsStateGuardian::
 set_gamma(float gamma) {
   bool set;
 
-  set = static_set_gamma(gamma);
+  set = static_set_gamma(false, gamma);
   if (set) {
     _gamma = gamma;  
   }
@@ -872,6 +871,16 @@ set_gamma(float gamma) {
   return set;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: wglGraphicsStateGuardian::restore_gamma
+//       Access: Published
+//  Description: Restore original gamma.
+////////////////////////////////////////////////////////////////////
+void wglGraphicsStateGuardian::
+restore_gamma() {
+  static_set_gamma(true, 1.0f);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: wglGraphicsStateGuardian::atexit_function
 //       Access: Public, Static
@@ -879,5 +888,5 @@ set_gamma(float gamma) {
 ////////////////////////////////////////////////////////////////////
 void wglGraphicsStateGuardian::
 atexit_function(void) {
-  static_set_gamma(1.0);
+  static_set_gamma(true, 1.0);
 }

+ 2 - 1
panda/src/wgldisplay/wglGraphicsStateGuardian.h

@@ -51,8 +51,9 @@ public:
   INLINE HDC get_twindow_dc();
 
   static bool get_gamma_table(void);
-  static bool static_set_gamma(float gamma);
+  static bool static_set_gamma(bool restore, float gamma);
   bool set_gamma(float gamma);
+  void restore_gamma();
   static void atexit_function(void);
 
 protected: