renderParticleMgr.h
Engine/source/renderInstance/renderParticleMgr.h
Classes:
class
Public Functions
GFXDeclareVertexFormat(CompositeQuadVert )
Detailed Description
Public Functions
GFXDeclareVertexFormat(CompositeQuadVert )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _RENDER_PARTICLE_MGR_H_ 25#define _RENDER_PARTICLE_MGR_H_ 26 27#ifndef _TEXTARGETBIN_MGR_H_ 28#include "renderInstance/renderTexTargetBinManager.h" 29#endif 30 31#ifndef _GFXPRIMITIVEBUFFER_H_ 32#include "gfx/gfxPrimitiveBuffer.h" 33#endif 34 35GFXDeclareVertexFormat( CompositeQuadVert ) 36{ 37 GFXVertexColor uvCoord; 38}; 39 40class RenderParticleMgr : public RenderTexTargetBinManager 41{ 42 typedef RenderTexTargetBinManager Parent; 43 friend class RenderTranslucentMgr; 44 45public: 46 // Generic Deferred Render Instance Type 47 static const RenderInstType RIT_Particles; 48 49 RenderParticleMgr(); 50 RenderParticleMgr( F32 renderOrder, F32 processAddOrder ); 51 virtual ~RenderParticleMgr(); 52 53 // RenderBinManager 54 void render(SceneRenderState * state); 55 void sort(); 56 void clear(); 57 void addElement( RenderInst *inst ); 58 59 // ConsoleObject 60 DECLARE_CONOBJECT(RenderParticleMgr); 61 62 const static U8 HighResStencilRef = 0x80; 63 const static U8 ParticleSystemStencilMask = 0x80; // We are using the top bit 64 const static U32 OffscreenPoolSize = 5; 65 66 virtual void setTargetChainLength(const U32 chainLength); 67 68protected: 69 70 // Override 71 virtual bool _handleGFXEvent(GFXDevice::GFXDeviceEventType event); 72 73 bool _initShader(); 74 void _initGFXResources(); 75 void _onLMActivate( const char*, bool activate ); 76 77 78 // Not only a helper method, but a method for the RenderTranslucentMgr to 79 // request a particle system draw 80 void renderInstance(ParticleRenderInst *ri, SceneRenderState *state); 81public: 82 void renderParticle(ParticleRenderInst *ri, SceneRenderState *state); 83protected: 84 bool mOffscreenRenderEnabled; 85 86 /// The deferred render target used for the 87 /// soft particle shader effect. 88 NamedTexTargetRef mDeferredTarget; 89 90 /// The shader used for particle rendering. 91 GFXShaderRef mParticleShader; 92 93 GFXShaderRef mParticleCompositeShader; 94 NamedTexTargetRef mEdgeTarget; 95 96 struct OffscreenSystemEntry 97 { 98 S32 targetChainIdx; 99 MatrixF clipMatrix; 100 RectF screenRect; 101 bool drawnThisFrame; 102 Vector<ParticleRenderInst*> pInstances; 103 }; 104 Vector<OffscreenSystemEntry> mOffscreenSystems; 105 106 struct ShaderConsts 107 { 108 GFXShaderConstBufferRef mShaderConsts; 109 GFXShaderConstHandle *mModelViewProjSC; 110 GFXShaderConstHandle *mFSModelViewProjSC; 111 GFXShaderConstHandle *mOneOverFarSC; 112 GFXShaderConstHandle *mOneOverSoftnessSC; 113 GFXShaderConstHandle *mDeferredTargetParamsSC; 114 GFXShaderConstHandle *mAlphaFactorSC; 115 GFXShaderConstHandle *mAlphaScaleSC; 116 GFXShaderConstHandle *mSamplerDiffuse; 117 GFXShaderConstHandle *mSamplerDeferredTex; 118 GFXShaderConstHandle *mSamplerParaboloidLightMap; 119 120 } mParticleShaderConsts; 121 122 struct CompositeShaderConsts 123 { 124 GFXShaderConstBufferRef mShaderConsts; 125 GFXShaderConstHandle *mSystemDepth; 126 GFXShaderConstHandle *mScreenRect; 127 GFXShaderConstHandle *mSamplerColorSource; 128 GFXShaderConstHandle *mSamplerEdgeSource; 129 GFXShaderConstHandle *mEdgeTargetParamsSC; 130 GFXShaderConstHandle *mOffscreenTargetParamsSC; 131 } mParticleCompositeShaderConsts; 132 133 GFXVertexBufferHandle<CompositeQuadVert> mScreenQuadVertBuff; 134 GFXPrimitiveBufferHandle mScreenQuadPrimBuff; 135 136 GFXStateBlockRef mStencilClearSB; 137 GFXStateBlockRef mHighResBlocks[ParticleRenderInst::BlendStyle_COUNT]; 138 GFXStateBlockRef mOffscreenBlocks[ParticleRenderInst::BlendStyle_COUNT]; 139 GFXStateBlockRef mBackbufferBlocks[ParticleRenderInst::BlendStyle_COUNT]; 140 GFXStateBlockRef mMixedResBlocks[ParticleRenderInst::BlendStyle_COUNT]; 141 142public: 143 GFXStateBlockRef _getHighResStateBlock(ParticleRenderInst *ri); 144 GFXStateBlockRef _getMixedResStateBlock(ParticleRenderInst *ri); 145 GFXStateBlockRef _getOffscreenStateBlock(ParticleRenderInst *ri); 146 GFXStateBlockRef _getCompositeStateBlock(ParticleRenderInst *ri); 147 ShaderConsts &_getShaderConsts() { return mParticleShaderConsts; }; 148}; 149 150 151#endif // _RENDER_TRANSLUCENT_MGR_H_ 152