HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>


dx9post.h

00001 /*
00002 * Copyright (c) 2007 by Tech Soft 3D, LLC.
00003 * The information contained herein is confidential and proprietary to
00004 * Tech Soft 3D, LLC., and considered a trade secret as defined under
00005 * civil and criminal statutes.  Tech Soft 3D shall pursue its civil
00006 * and criminal remedies in the event of unauthorized use or misappropriation
00007 * of its trade secrets.  Use of this information by anyone other than
00008 * authorized employees of Tech Soft 3D, LLC. is granted only under a
00009 * written non-disclosure agreement, expressly prescribing the scope and
00010 * manner of such use.
00011 *
00012  * $Id: dx9post_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $
00013 */
00014 
00015 
00016 #ifndef __DX9POST_H_DEFINED__
00017 #define __DX9POST_H_DEFINED__
00018 
00019 
00020 /*D3D includes*/
00021 #include <D3D9.h>
00022 #include <d3dx9math.h>
00023 
00024 /*forward declarations*/
00025 class HDX9Post;
00026 struct dx9data_s; typedef struct dx9data_s DX9Data;
00027 struct IDirect3DDevice9;
00028 struct IDirect3DVertexBuffer9;
00029 struct IDirect3DVertexShader9;
00030 struct IDirect3DPixelShader9;
00031 struct ID3DXConstantTable;
00032 
00033 class HDX9Post
00034 {
00035 public:
00036 
00037     HDX9Post( DX9Data& data );
00038     ~HDX9Post();
00039 
00040     bool Begin();                   // Start a post session
00041     void End(); // Finish a post session
00042 
00043     // Which post shaders are available?
00044     enum Shader
00045     {
00046         // General-purpose
00047         SH_COPY,
00048         SH_FILTER_4,
00049         SH_FILTER_8,
00050         SH_FILTER_12,
00051         SH_FILTER_16,
00052 
00053         // Special-purpose
00054         SH_APPLY_REFLECTION,
00055 
00056         NUM_SHADERS,
00057     };
00058 
00059     //
00060     // Drawing primitives
00061     //
00062 
00063     // Copy the specified texture to the target
00064     void Copy( IDirect3DSurface9& dest, IDirect3DTexture9& src, HT_RGBA const * modulation_color = NULL, D3DTEXTUREFILTERTYPE filter = D3DTEXF_POINT );
00065 
00066     // Copy between textures
00067     void Copy( IDirect3DTexture9& dest, IDirect3DTexture9& src, HT_RGBA const * modulation_color = NULL, D3DTEXTUREFILTERTYPE filter = D3DTEXF_POINT )
00068     {
00069         IDirect3DSurface9 *surface = NULL;
00070         dest.GetSurfaceLevel(0, &surface);
00071         if ( surface ) {
00072             Copy( *surface, src, modulation_color, filter );
00073             surface->Release();
00074         }
00075     }
00076 
00077     // Filter the specified texture to the target
00078     void Filter( IDirect3DSurface9& dest, IDirect3DTexture9& src, int num_taps, HT_Vector const *taps, D3DTEXTUREFILTERTYPE filter = D3DTEXF_POINT );
00079 
00080     // Filter the specified texture to the target
00081     void Filter( IDirect3DTexture9& dest, IDirect3DTexture9& src, int num_taps, HT_Vector const *taps, D3DTEXTUREFILTERTYPE filter = D3DTEXF_POINT )
00082     {
00083         IDirect3DSurface9 *surface = NULL;
00084         dest.GetSurfaceLevel(0, &surface);
00085         if ( surface ) {
00086             Filter( *surface, src, num_taps, taps, filter);
00087             surface->Release();
00088         }
00089     }
00090 
00091     // Access a shader in order to configure it
00092     inline ID3DXConstantTable *GetConstants( Shader const which )   { return m_constant_tables[which]; }
00093 
00094     // Activate a shader in order to render manually
00095     ID3DXConstantTable *ActivateShader( Shader which, float depth = 0.0f, D3DXMATRIX const *matrix = NULL );
00096 
00097     // Apply the specified shader to the target
00098     void Apply( IDirect3DSurface9& dest, Shader const which, float depth = 0.0f, D3DXMATRIX const *matrix = NULL );
00099 
00100     // Apply the specified shader to the target
00101     void Apply( IDirect3DTexture9& dest, Shader const which, float depth = 0.0f, D3DXMATRIX const *matrix = NULL  )
00102     {
00103         IDirect3DSurface9 *surface = NULL;
00104         dest.GetSurfaceLevel(0, &surface);
00105         if ( surface ) {
00106             Apply( *surface, which, depth, matrix );
00107             surface->Release();
00108         }
00109     }
00110 
00111     // Get a temporary render-target texture buffer from the cache
00112     IDirect3DTexture9 *GetWorkBuffer( const DWORD width, const DWORD height, const D3DFORMAT format );
00113 
00114     // Indicate that client has finished with a temporary buffer
00115     void ReleaseWorkBuffer( IDirect3DTexture9& buffer );
00116 
00117     // Get a temporary render-target texture buffer from the cache
00118     IDirect3DSurface9 *GetWorkDepthBuffer( const DWORD width, const DWORD height, const D3DFORMAT format = D3DFMT_D24S8 );
00119 
00120     // Indicate that client has finished with a temporary buffer
00121     void ReleaseWorkBuffer( IDirect3DSurface9& buffer );
00122 
00123     // Release default-pool resources
00124     void OnResetDevice();
00125 
00126     //
00127     // Compounds
00128     //
00129 
00130     // Blur a texture using a 7x7 Gaussian kernel
00131     void GaussianBlur7( IDirect3DTexture9 &texture, int iterations = 1 );
00132 
00133     // Blur a texture using a 7x7 box kernel
00134     void BoxBlur7( IDirect3DTexture9& texture, int iterations = 1 );
00135 
00136     // Blur a texture using a 3x3 Gaussian kernel
00137     void GaussianBlur3( IDirect3DTexture9 &texture, int iterations = 1 );
00138 
00139     // Blur a texture using a 3x3 box kernel
00140     void BoxBlur3( IDirect3DTexture9& texture, int iterations = 1 );
00141 
00142 private:
00143 
00144     // Avoid C4512
00145     HDX9Post& operator=( const HDX9Post& other )            { UNREFERENCED(other); ASSERT(0); return *this; }
00146 
00147     DX9Data& m_dx9data;                                     // DX9 driver state
00148     IDirect3DDevice9 &m_device;                             // D3D device
00149     IDirect3DVertexBuffer9 *m_vertices;                     // Vertices for one triangle
00150     IDirect3DVertexDeclaration9 *m_format;                  // Format descriptor for these vertices
00151     IDirect3DVertexShader9 *m_2d_vertex_shader;             // Common vertex shader
00152     IDirect3DVertexShader9 *m_3d_vertex_shader;             // Common vertex shader for 3D
00153     ID3DXConstantTable *m_2d_vertex_constant_table;
00154     ID3DXConstantTable *m_3d_vertex_constant_table;
00155     IDirect3DPixelShader9 *m_pixel_shaders[NUM_SHADERS];    // Different pixel shaders
00156     ID3DXConstantTable *m_constant_tables[NUM_SHADERS];     // Constant tables for binding the pixel shaders.
00157 
00158     struct Buffer
00159     {
00160         bool active;                                        // Is someone using this buffer?
00161         IDirect3DTexture9 *texture;                         // The rendertarget texture
00162         IDirect3DSurface9 *surface;                         // The surface (for depth buffers)
00163         Buffer *next;                                       // Next buffer in the chain
00164     };
00165 
00166     Buffer *m_head;                                         // List of temporary buffers we've allocated
00167 
00168     // Helpers
00169     void SetTexelOffset( IDirect3DTexture9& src );          // Apply texel offset to constants based on given texture 
00170 };
00171 
00172 #endif // __DX9POST_H_DEFINED__
00173 
00174 
Main Index
HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>