From f451758ce413a279f0abeb612c8e2a76292d0d1e Mon Sep 17 00:00:00 2001 From: aignacio_sf <> Date: Sat, 13 Oct 2007 01:01:03 +0000 Subject: [PATCH] Add restore gamma. --- panda/src/display/graphicsStateGuardian.cxx | 9 +++++++++ panda/src/display/graphicsStateGuardian.h | 1 + panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 19 ++++++++++++++----- panda/src/dxgsg8/dxGraphicsStateGuardian8.h | 3 ++- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 19 ++++++++++++++----- panda/src/dxgsg9/dxGraphicsStateGuardian9.h | 3 ++- .../wgldisplay/wglGraphicsStateGuardian.cxx | 19 ++++++++++++++----- .../src/wgldisplay/wglGraphicsStateGuardian.h | 3 ++- 8 files changed, 58 insertions(+), 18 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 4435fab321..05ec42aa18 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/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 diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 37f6a5f476..5e375f0c95 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/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); diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index eea6a760f3..e269464bf6 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/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); } diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h index 5494d9a587..142c573774 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h +++ b/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: diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 529fc9dba6..41a88d5383 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/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); } diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h b/panda/src/dxgsg9/dxGraphicsStateGuardian9.h index d0f78b1658..f87f59f574 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.h +++ b/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: diff --git a/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx b/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx index 8fbeab5348..0f80a6f846 100755 --- a/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx +++ b/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); } diff --git a/panda/src/wgldisplay/wglGraphicsStateGuardian.h b/panda/src/wgldisplay/wglGraphicsStateGuardian.h index 99f93f9b53..9d192a760b 100755 --- a/panda/src/wgldisplay/wglGraphicsStateGuardian.h +++ b/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: