csplugincommon/rendermanager/autofx_framebuffertex.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2009 by Frank Richter 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library 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 GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_CSPLUGINCOMMON_RENDERMANAGER_AUTOFX_FRAMEBUFFERTEX_H__ 00020 #define __CS_CSPLUGINCOMMON_RENDERMANAGER_AUTOFX_FRAMEBUFFERTEX_H__ 00021 00026 //#include "iengine/mesh.h" 00027 #include "csgfx/shadervarblockalloc.h" 00028 00029 #include "csplugincommon/rendermanager/posteffects.h" 00030 #include "csplugincommon/rendermanager/rendertree.h" 00031 #include "csplugincommon/rendermanager/texturecache.h" 00032 00033 namespace CS 00034 { 00035 namespace RenderManager 00036 { 00037 namespace AutoFX 00038 { 00044 class FramebufferTex_Base 00045 { 00046 public: 00048 enum { svUserFlags = iShader::svuTextures }; 00049 00055 class CS_CRYSTALSPACE_EXPORT PersistentData 00056 { 00057 csRef<iTextureHandle> framebufferTex[rtaNumAttachments]; 00058 00059 TextureCacheT<CS::Utility::ResourceCache::ReuseAlways> texCacheColor; 00060 TextureCacheT<CS::Utility::ResourceCache::ReuseAlways> texCacheDepth; 00061 public: 00062 csShaderVarBlockAlloc<csBlockAllocatorDisposeLeaky<csShaderVariable> > 00063 svAlloc; 00064 /* A number of SVs have to be kept alive even past the expiration 00065 * of the actual step */ 00066 csRefArray<csShaderVariable> svKeeper; 00067 00068 CS::ShaderVarStringID svTexFramebuffer[rtaNumAttachments]; 00069 CS::ShaderVarStringID svFramebufferCoordXform; 00070 00072 PersistentData(); 00073 00081 void Initialize (iObjectRegistry* objReg, 00082 PostEffectManager* postEffects); 00083 00084 iTextureHandle* GetFramebufferTex (size_t n, int width, int height); 00085 00090 void UpdateNewFrame (); 00091 }; 00092 00093 FramebufferTex_Base (PersistentData& persist) : persist (persist) 00094 {} 00095 protected: 00096 PersistentData& persist; 00097 }; 00098 00130 template<typename RenderTree> 00131 class FramebufferTex : public FramebufferTex_Base 00132 { 00133 public: 00134 FramebufferTex (PersistentData& persist) : 00135 FramebufferTex_Base (persist) 00136 {} 00137 00143 void operator() (typename RenderTree::MeshNode* node, 00144 size_t layer, 00145 typename RenderTree::MeshNode::SingleMesh& mesh, 00146 const csBitArray& names) 00147 { 00148 size_t n = 0; 00149 int renderW = -1, renderH; 00150 00151 typename RenderTree::ContextNode& context = node->GetOwner(); 00152 csShaderVariableStack localStack; 00153 context.svArrays.SetupSVStack (localStack, layer, mesh.contextLocalId); 00154 00155 csRef<csShaderVariable> svFBCoordXform; 00156 for (size_t i = 0; i < rtaNumAttachments; i++) 00157 { 00158 CS::ShaderVarStringID svName = persist.svTexFramebuffer[i]; 00159 if (names.IsBitSetTolerant (svName)) 00160 { 00161 if (renderW < 0) 00162 { 00163 renderW = renderH = 512; 00164 context.GetTargetDimensions (renderW, renderH); 00165 } 00166 mesh.preCopyAttachments[n] = (csRenderTargetAttachment)i; 00167 iTextureHandle* tex = persist.GetFramebufferTex (i, renderW, renderH); 00168 mesh.preCopyTextures[n] = tex; 00169 00170 if (!svFBCoordXform.IsValid()) 00171 { 00172 svFBCoordXform.AttachNew (new csShaderVariable ( 00173 persist.svFramebufferCoordXform)); 00174 00175 if (tex->GetTextureType() == iTextureHandle::texTypeRect) 00176 { 00177 svFBCoordXform->SetValue ( 00178 csVector4 (0.5f*renderW, 0.5f*renderH, 00179 0.5f*renderW, 0.5f*renderH)); 00180 } 00181 else 00182 { 00183 int txt_w, txt_h; 00184 tex->GetRendererDimensions (txt_w, txt_h); 00185 svFBCoordXform->SetValue ( 00186 csVector4 (0.5f*renderW/float (txt_w), 0.5f*renderH/float (txt_h), 00187 0.5f, 0.5f)); 00188 } 00189 00190 persist.svKeeper.Push (svFBCoordXform); 00191 localStack[persist.svFramebufferCoordXform] = svFBCoordXform; 00192 } 00193 00194 csRef<csShaderVariable> svFramebufferTex; 00195 svFramebufferTex.AttachNew (new csShaderVariable (svName)); 00196 persist.svKeeper.Push (svFramebufferTex); 00197 svFramebufferTex->SetValue (tex); 00198 localStack[svName] = svFramebufferTex; 00199 00200 n++; 00201 } 00202 } 00203 mesh.preCopyNum = n; 00204 } 00205 }; 00206 00207 } // namespace AutoFX 00208 } // namespace RenderManager 00209 } // namespace CS 00210 00211 #endif // __CS_CSPLUGINCOMMON_RENDERMANAGER_AUTOFX_FRAMEBUFFERTEX_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1
