DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/output/direct3d/ScalingEffect.h
00001 /*
00002 Copyright (C) 2003 Ryan A. Nunn
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License along
00015 with this program; if not, write to the Free Software Foundation, Inc.,
00016 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #pragma once
00020 
00021 #include <string>
00022 #include <d3d9.h>
00023 #include <d3dx9.h>
00024 
00025 #define SAFE_RELEASE(p)         { if(p) { (p)->Release(); (p)=NULL; } }
00026 
00027 class ScalingEffect
00028 {
00029     float                               m_scale;
00030     float                               m_iDim[2];
00031     BOOL                                m_forceupdate;
00032     LPCSTR                              m_strName;
00033     std::string                         m_strErrors;
00034     LPDIRECT3DDEVICE9                   m_pd3dDevice;
00035 
00036     LPD3DXEFFECT                        m_pEffect;
00037     D3DXEFFECT_DESC                     m_EffectDesc;
00038 
00039     // Matrix Handles
00040     D3DXHANDLE m_MatWorldEffectHandle;
00041     D3DXHANDLE m_MatViewEffectHandle;
00042     D3DXHANDLE m_MatProjEffectHandle;
00043     D3DXHANDLE m_MatWorldViewEffectHandle;
00044     D3DXHANDLE m_MatViewProjEffectHandle;
00045     D3DXHANDLE m_MatWorldViewProjEffectHandle;
00046 
00047     // Texture Handles
00048     D3DXHANDLE m_SourceDimsEffectHandle;
00049     D3DXHANDLE m_TexelSizeEffectHandle;
00050     D3DXHANDLE m_SourceTextureEffectHandle;
00051     D3DXHANDLE m_WorkingTexture1EffectHandle;
00052     D3DXHANDLE m_WorkingTexture2EffectHandle;
00053     D3DXHANDLE m_Hq2xLookupTextureHandle;
00054 
00055     // Technique stuff
00056     D3DXHANDLE  m_PreprocessTechnique1EffectHandle;
00057     D3DXHANDLE  m_PreprocessTechnique2EffectHandle;
00058     D3DXHANDLE  m_CombineTechniqueEffectHandle;
00059 
00060 public:
00061     enum Pass { Preprocess1, Preprocess2, Combine };
00062 
00063     ScalingEffect(LPDIRECT3DDEVICE9 pd3dDevice);
00064     ~ScalingEffect(void);
00065 
00066     void KillThis();
00067 
00068     HRESULT LoadEffect(const TCHAR *filename);
00069 
00070     const char *getErrors() { return m_strErrors.c_str(); }
00071 
00072     LPCSTR getName() { return m_strName; }
00073     float getScale() { return m_scale; }
00074     bool getForceUpdate() { return m_forceupdate != FALSE; }
00075     void setinputDim(float w, float h) { m_iDim[0] = w; m_iDim[1] = h; }
00076 
00077     // Does it have a preprocess step
00078     BOOL hasPreprocess() { return m_PreprocessTechnique1EffectHandle!=0; }
00079     BOOL hasPreprocess2() { return m_PreprocessTechnique2EffectHandle!=0; }
00080 
00081     // Set The Textures
00082     HRESULT SetTextures( LPDIRECT3DTEXTURE9 lpSource, LPDIRECT3DTEXTURE9 lpWorking1,
00083                 LPDIRECT3DTEXTURE9 lpWorking2, LPDIRECT3DVOLUMETEXTURE9 lpHq2xLookupTexture );
00084 
00085     // Set the Matrices for this frame
00086     HRESULT SetMatrices( D3DXMATRIX &matProj, D3DXMATRIX &matView, D3DXMATRIX &matWorld );
00087 
00088     // Begin the technique
00089     // Returns Number of passes for this technique
00090     HRESULT Begin(Pass pass, UINT* pPasses);
00091 
00092     // Render Pass in technique
00093     HRESULT BeginPass(UINT Pass);
00094     HRESULT EndPass();
00095 
00096     // End rendering of this technique
00097     HRESULT End();
00098 
00099     // Validates the effect
00100     HRESULT Validate();
00101 
00102 private:
00103     HRESULT ParseParameters(LPD3DXEFFECTCOMPILER lpEffectCompiler);
00104 };