00001 #pragma once 00002 00003 class Shader; 00004 00005 #include <d3d10.h> 00006 #include <d3dx10.h> 00007 #include "d3d10drv.h" 00008 #include "geometrybuffer.h" 00009 00010 class Shader 00011 { 00012 00013 protected: 00014 static struct StateStruct 00015 { 00016 ID3D10DepthStencilState* dstate_Enable; 00017 ID3D10DepthStencilState* dstate_Disable; 00018 ID3D10BlendState* bstate_Alpha; 00019 ID3D10BlendState* bstate_Translucent; 00020 ID3D10BlendState* bstate_Modulate; 00021 ID3D10BlendState* bstate_NoBlend; 00022 ID3D10BlendState* bstate_Masked; 00023 ID3D10BlendState* bstate_Invis; 00024 } states; 00025 00026 GeometryBuffer* geometryBuffer; 00027 ID3D10RenderTargetView* renderTargetView; 00028 ID3D10DepthStencilView* depthStencilView; 00029 ID3D10InputLayout* vertexLayout; 00030 ID3D10ShaderResourceView* shaderResourceView; 00031 static ID3D10Blob* blob; 00032 static ID3D10Device *device; 00033 ID3D10Effect* effect; 00034 D3D10_PRIMITIVE_TOPOLOGY topology; 00035 HRESULT hr; 00036 00037 static bool checkCompileResult(HRESULT hr); 00038 bool createRenderTargetViews(DXGI_FORMAT format, DXGI_FORMAT depthFormat,float scaleX, float scaleY, int samples, const DXGI_SWAP_CHAIN_DESC &swapChainDesc); 00039 00040 00041 public: 00042 Shader(); 00043 static bool initShaderSystem(ID3D10Device *device, const D3D10_SHADER_MACRO *macros, DWORD shaderFlags); 00044 virtual bool compile(const D3D10_SHADER_MACRO *macros, DWORD shaderFlags)=0; 00045 virtual bool createRenderTargetViews(ID3D10RenderTargetView *backbuffer, const DXGI_SWAP_CHAIN_DESC &swapChainDesc, int multiSampleCount)=0; 00046 virtual void releaseRenderTargetViews(); 00047 virtual ~Shader(); 00048 virtual void bind(); 00049 virtual void apply(); 00050 GeometryBuffer *getGeometryBuffer() const; 00051 ID3D10ShaderResourceView *getResourceView() const; 00052 virtual void setFlags(int flags); 00053 };