00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_RENDERSYSTEM_DIRECT3D11_H__
00009 #define __SP_RENDERSYSTEM_DIRECT3D11_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #if defined(SP_COMPILE_WITH_DIRECT3D11)
00015
00016
00017 #include "RenderSystem/spRenderSystem.hpp"
00018 #include "RenderSystem/Direct3D11/spDirect3D11Texture.hpp"
00019 #include "RenderSystem/Direct3D11/spDirect3D11Shader.hpp"
00020 #include "RenderSystem/Direct3D11/spDirect3D11DefaultShader.hpp"
00021
00022 #include <d3d11.h>
00023 #include <d3dx11.h>
00024
00025
00026 namespace sp
00027 {
00028 namespace video
00029 {
00030
00031
00033 class SP_EXPORT Direct3D11RenderSystem : public RenderSystem
00034 {
00035
00036 public:
00037
00038 Direct3D11RenderSystem();
00039 ~Direct3D11RenderSystem();
00040
00041
00042
00043 void setupConfiguration();
00044
00045
00046
00047 io::stringc getRenderer() const;
00048 io::stringc getVersion() const;
00049 io::stringc getVendor() const;
00050 io::stringc getShaderVersion() const;
00051
00052 s32 getMultitexCount() const;
00053 s32 getMaxAnisotropicFilter() const;
00054 s32 getMaxLightCount() const;
00055
00056 bool queryVideoSupport(const EVideoFeatureQueries Query) const;
00057
00058 void printWarning();
00059
00060
00061
00062 void clearBuffers(const s32 ClearFlags = BUFFER_COLOR | BUFFER_DEPTH);
00063
00064
00065
00066 void setShadeMode(const EShadeModeTypes ShadeMode);
00067 void setClearColor(const color &Color);
00068 void setColorMask(bool isRed, bool isGreen, bool isBlue, bool isAlpha = true);
00069 void setDepthMask(bool isDepth);
00070 void setAntiAlias(bool isAntiAlias);
00071
00072
00073
00074 bool setupMaterialStates(const MaterialStates* Material, bool Forced);
00075
00076 void bindTextureLayers(const TextureLayerListType &TexLayers);
00077 void unbindTextureLayers(const TextureLayerListType &TexLayers);
00078
00079 void setupShaderClass(const scene::MaterialNode* Object, ShaderClass* ShaderObject);
00080
00081 void updateMaterialStates(MaterialStates* Material, bool isClear = false);
00082
00083 void updateLight(
00084 u32 LightID, const scene::ELightModels LightType, bool isVolumetric,
00085 const dim::vector3df &Direction, f32 SpotInnerConeAngle, f32 SpotOuterConeAngle,
00086 f32 AttenuationConstant, f32 AttenuationLinear, f32 AttenuationQuadratic
00087 );
00088
00089
00090
00091 void createVertexBuffer(void* &BufferID);
00092 void createIndexBuffer(void* &BufferID);
00093
00094 void deleteVertexBuffer(void* &BufferID);
00095 void deleteIndexBuffer(void* &BufferID);
00096
00097 void updateVertexBuffer(
00098 void* BufferID, const dim::UniversalBuffer &BufferData, const VertexFormat* Format, const EHWBufferUsage Usage
00099 );
00100 void updateIndexBuffer(
00101 void* BufferID, const dim::UniversalBuffer &BufferData, const IndexFormat* Format, const EHWBufferUsage Usage
00102 );
00103
00104 void updateVertexBufferElement(void* BufferID, const dim::UniversalBuffer &BufferData, u32 Index);
00105 void updateIndexBufferElement(void* BufferID, const dim::UniversalBuffer &BufferData, u32 Index);
00106
00107 void drawMeshBuffer(const MeshBuffer* MeshBuffer);
00108
00109
00110
00111 void setRenderState(const video::ERenderStates Type, s32 State);
00112 s32 getRenderState(const video::ERenderStates Type) const;
00113
00114
00115
00116 void addDynamicLightSource(
00117 u32 LightID, scene::ELightModels Type,
00118 video::color &Diffuse, video::color &Ambient, video::color &Specular,
00119 f32 AttenuationConstant, f32 AttenuationLinear, f32 AttenuationQuadratic
00120 );
00121
00122 void setLightStatus(u32 LightID, bool Enable, bool UseAllRCs = false);
00123
00124 void setLightColor(
00125 u32 LightID,
00126 const video::color &Diffuse, const video::color &Ambient, const video::color &Specular,
00127 bool UseAllRCs
00128 );
00129
00130
00131
00132 void setFog(const EFogTypes Type);
00133 void setFogColor(const video::color &Color);
00134 void setFogRange(f32 Range, f32 NearPlane = 1.0f, f32 FarPlane = 1000.0f, const EFogModes Mode = FOG_PALE);
00135
00136
00137
00138 void setClipPlane(u32 Index, const dim::plane3df &Plane, bool Enable);
00139
00140
00141
00142 ShaderClass* createShaderClass(VertexFormat* VertexInputLayout = 0);
00143
00144 Shader* createShader(
00145 ShaderClass* ShaderClassObj, const EShaderTypes Type, const EShaderVersions Version,
00146 const std::list<io::stringc> &ShaderBuffer, const io::stringc &EntryPoint = ""
00147 );
00148
00149 Shader* createCgShader(
00150 ShaderClass* ShaderClassObj, const EShaderTypes Type, const EShaderVersions Version,
00151 const std::list<io::stringc> &ShaderBuffer, const io::stringc &EntryPoint = "",
00152 const c8** CompilerOptions = 0
00153 );
00154
00155 void unbindShaders();
00156
00157 bool runComputeShader(
00158 Shader* ShaderObj, ComputeShaderIO* IOInterface, const dim::vector3di &GroupSize
00159 );
00160
00161 ComputeShaderIO* createComputeShaderIO();
00162
00163
00164
00165 void beginDrawing2D();
00166
00167 void setBlending(const EBlendingTypes SourceBlend, const EBlendingTypes DestBlend);
00168 void setClipping(bool Enable, const dim::point2di &Position, const dim::size2di &Dimension);
00169 void setViewport(const dim::point2di &Position, const dim::size2di &Dimension);
00170
00171 bool setRenderTarget(Texture* Target);
00172
00173
00174
00175 void draw2DImage(
00176 const Texture* Tex, const dim::point2di &Position, const color &Color = color(255)
00177 );
00178
00179 void draw2DImage(
00180 const Texture* Tex, const dim::rect2di &Position,
00181 const dim::rect2df &Clipping = dim::rect2df(0.0f, 0.0f, 1.0f, 1.0f),
00182 const color &Color = color(255)
00183 );
00184
00185
00186
00187 Texture* createTexture(const STextureCreationFlags &CreationFlags);
00188
00189
00190
00191 void updateModelviewMatrix();
00192
00193
00194
00195 inline ID3D11Device* getDirect3DDevice() const
00196 {
00197 return D3DDevice_;
00198 }
00199
00200 private:
00201
00202 friend class Direct3D11ShaderClass;
00203 friend class Direct3D11Shader;
00204 friend class Direct3D11Texture;
00205 friend class Direct3D11ComputeShaderIO;
00206 friend class Direct3D11RenderContext;
00207 friend class Direct3D11ConstantBuffer;
00208 friend class D3D11HardwareBuffer;
00209 friend class VertexFormat;
00210
00211
00212
00213 struct SConstantBuffer2D
00214 {
00215 dim::matrix4f Transformation;
00216
00217 dim::vector4df ColorLeftTop;
00218 dim::vector4df ColorRightTop;
00219 dim::vector4df ColorRightBottom;
00220 dim::vector4df ColorLeftBottom;
00221
00222 dim::vector4df TexCoordLeftTop;
00223 dim::vector4df TexCoordRightTop;
00224 dim::vector4df TexCoordRightBottom;
00225 dim::vector4df TexCoordLeftBottom;
00226
00227 bool IsTexturing;
00228 s32 pad[3];
00229 };
00230
00231
00232
00233 void createDefaultResources();
00234 void createRendererStates();
00235 void createQuad2DVertexBuffer();
00236
00237 void updateShaderResources();
00238
00239 ID3D11Buffer* createStructuredBuffer(u32 ElementSize, u32 ElementCount, void* InitData = 0);
00240 ID3D11Buffer* createCPUAccessBuffer(ID3D11Buffer* GPUOutputBuffer);
00241 ID3D11UnorderedAccessView* createUnorderedAccessView(ID3D11Buffer* StructuredBuffer);
00242 ID3D11ShaderResourceView* createShaderResourceView(ID3D11Buffer* StructuredBuffer);
00243
00244 void updateVertexInputLayout(VertexFormat* Format, bool isCreate);
00245 void addVertexInputLayoutAttribute(std::vector<D3D11_INPUT_ELEMENT_DESC>* InputDesc, const SVertexAttribute &Attrib);
00246
00247
00248
00249 template <class T> static inline void releaseObject(T* &Object)
00250 {
00251 if (Object)
00252 {
00253 Object->Release();
00254 Object = 0;
00255 }
00256 }
00257
00258
00259
00260
00261
00262 ID3D11Device* D3DDevice_;
00263 ID3D11DeviceContext* D3DDeviceContext_;
00264
00265 ID3D11RenderTargetView* RenderTargetView_;
00266 ID3D11RenderTargetView* OrigRenderTargetView_;
00267
00268 ID3D11Texture2D* DepthStencil_;
00269 ID3D11DepthStencilView* DepthStencilView_;
00270 ID3D11DepthStencilView* OrigDepthStencilView_;
00271
00272 ID3D11RasterizerState* RasterizerState_;
00273 ID3D11DepthStencilState* DepthStencilState_;
00274 ID3D11BlendState* BlendState_;
00275
00276 IDXGIFactory1* DxGIFactory_;
00277
00278
00279
00280
00281
00282 D3D11_RASTERIZER_DESC RasterizerDesc_;
00283 D3D11_DEPTH_STENCIL_DESC DepthStencilDesc_;
00284 D3D11_BLEND_DESC BlendDesc_;
00285
00286
00287
00288 u32 NumBoundedSamplers_;
00289 ID3D11ShaderResourceView* ShaderResourceViewList_[MAX_COUNT_OF_TEXTURES];
00290 ID3D11RenderTargetView* RenderTargetViewList_[MAX_COUNT_OF_TEXTURES];
00291 ID3D11SamplerState* SamplerStateList_[MAX_COUNT_OF_TEXTURES];
00292
00293 ID3D11Buffer* Quad2DVertexBuffer_;
00294
00295
00296
00297 bool isMultiSampling_;
00298 f32 FinalClearColor_[4];
00299 video::color ClearColor_;
00300
00301 D3D_FEATURE_LEVEL FeatureLevel_;
00302
00303
00304
00305 D3D11DefaultShader DefaultShader_;
00306 bool UseDefaultBasicShader_;
00307
00308 ShaderClass* DefaultBasicShader2D_;
00309
00310 SConstantBuffer2D ConstBuffer2D_;
00311
00312 };
00313
00314
00315 }
00316
00317 }
00318
00319
00320 #endif
00321
00322 #endif
00323
00324
00325
00326