| VRS - The Virtual Rendering System |
| version 3.3 |
00001 /********************************************************************** 00002 VRS - The Virtual Rendering System 00003 Copyright (C) 2001 Computer Graphics Systems Group at the 00004 Hasso-Plattner-Institute, Potsdam, Germany. 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 This library is distributed in the hope that it will be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 See the GNU Lesser General Public License for more details. 00013 You should have received a copy of the GNU Lesser+ General Public 00014 License along with this library; if not, write to the FreeSoftware 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA, 02111-1307, USA. 00016 **********************************************************************/ 00017 // $Id: shadowtechniquegl.h 6014 2007-08-09 07:51:16Z Konstantin_Baumann $ 00018 // $Date: 2007-08-09 09:51:16 +0200 (Thu, 09 Aug 2007) $ 00019 // $Revision: 6014 $ 00020 // $State$ 00021 // $Author: Konstantin_Baumann $ 00022 // 00023 // $Log$ 00024 // Revision 1.28 2005/01/03 01:43:09 klimetschek 00025 // - modified win32 project layout, splitted vrs.vcproj into vrs_container, vrs_core, vrs_sg, vrs_image, vrs_opengl and vrs_io 00026 // - removed vrs.vcproj 00027 // minor things: 00028 // - added all glutexamples to vrs4glut.sln 00029 // - fixed some problems in glutexamples 00030 // - removed all project references from all VS projects (using solution wide project dependencies instead) 00031 // 00032 // Revision 1.27 2004/11/09 15:07:24 kirsch 00033 // further changes to class comments due to doxygen 00034 // 00035 // Revision 1.26 2004/08/05 14:47:10 kirsch 00036 // numerous cleanups and minor changes 00037 // 00038 // Revision 1.25 2004/03/12 16:28:40 baumann 00039 // macros VRS_NAMESPACE_BEGIN/_END expanded and removed 00040 // 00041 // Revision 1.24 2004/01/19 11:43:58 baumann 00042 // serialization mechanism improved 00043 // 00044 // Revision 1.23 2004/01/19 07:28:02 baumann 00045 // serialization mechanism improved 00046 // 00047 // Revision 1.22 2003/11/07 14:19:25 kirsch 00048 // removed leading underscore from include guards 00049 // 00050 // Revision 1.21 2003/07/03 16:21:58 kirsch 00051 // added a hack that allows to collapse depthmap projection and light 00052 // application in a single pass 00053 // 00054 // Revision 1.20 2002/12/13 09:32:34 kirsch 00055 // fixed typeinfo bug 00056 // 00057 // Revision 1.19 2002/12/12 13:04:07 kirsch 00058 // Technique constructor does not get a number denoting the number of rendering 00059 // passes anymore, only an empty array of passes is created by default. 00060 // 00061 // Revision 1.18 2002/12/12 09:06:38 kirsch 00062 // removed OpenGL extension ifdefs 00063 // added isSupported() to allow silent extension check. 00064 // rate() now checks extensions silently, canBeUsed() is verbose 00065 // serialization was incomplete 00066 // 00067 // Revision 1.17 2002/12/11 16:22:25 kirsch 00068 // merged with more advanced private version of shadow technique 00069 // - ShadowTechniqueGL is now a factory that choses between the "best" shadow technique 00070 // You best use this technique in the scene graph. 00071 // - ShadowTechniqueTemplateGL is a template pattern which should be used for concrete shadow techniques 00072 // - DepthmapShadowTechniqueGL is abstract base class for 00073 // - DepthTextureShadowTechniqueGL (shadows with depth-textures) 00074 // - AlphaTextureShadowTechniqueGL (shadows with alpha-textures) 00075 // 00076 // Revision 1.16 2002/10/29 10:32:52 baumann 00077 // macros VRS_CLASSNAME_* and VRS_IMPL_TYPEINFO_* removed 00078 // 00079 // Revision 1.15 2002/07/04 14:23:56 kirsch 00080 // removed IteratorWrapper 00081 // 00082 // Revision 1.14 2002/06/24 14:03:38 baumann 00083 // changed List<T> to Array<T> 00084 // 00085 // Revision 1.13 2002/06/12 09:48:46 kirsch 00086 // added constructLightIterator() ( functionality formerly in start() ) 00087 // 00088 // Revision 1.12 2002/03/04 12:00:26 kersting 00089 // directory structure changes 00090 // 00091 // Revision 1.11 2002/03/03 21:44:26 kosta 00092 // VRS_TYPEINFO-macro rewritten 00093 // 00094 // Revision 1.10 2002/02/19 10:34:19 kosta 00095 // undone all changes since 2002-02-15 00096 // 00097 // Revision 1.7 2002/02/04 12:58:41 kirsch 00098 // moved setting of light in shadow application pass to ShadowTechniqueGL 00099 // other minor changes 00100 // 00101 // Revision 1.6 2002/01/15 16:25:55 kosta 00102 // macros rewritten for a better namespace support 00103 // 00104 // Revision 1.5 2001/11/13 16:36:31 kirsch 00105 // changed line feed to unix style (removed control-M) 00106 // 00107 // Revision 1.4 2001/09/05 14:14:36 kirsch 00108 // Documentation updates 00109 // 00110 // Revision 1.3 2001/08/20 13:47:37 kirsch 00111 // Stencilbuffer was cleared unnecessarily in TechniqueGL 00112 // 00113 // Revision 1.2 2001/08/09 15:37:10 kirsch 00114 // Added shadows in OpenGL, created with alpha depthmaps. 00115 // Still experimental, some flaws 00116 // 00117 // Revision 1.1.2.1 2001/06/22 15:28:40 kirsch 00118 // Added shadow-attributes and depthmapshadowtechniquegl. 00119 // Still broken! Don't Use! Only for Distributing! 00120 // 00121 00122 #ifndef VRS_OPENGL_SHADOWTECHNIQUEGL_H 00123 #define VRS_OPENGL_SHADOWTECHNIQUEGL_H 00124 00126 // This header file defines ShadowTechniqueGL and ShadowTechniqueTemplateGL // 00128 00129 #include <vrs/light.h> 00130 #include <vrs/opengl/techniquegl.h> 00131 00132 namespace VRS { 00133 00135 // ShadowTechniqueGL // 00137 00138 class ShadowCaster; 00139 class Shadowed; 00140 class ShadowTechniqueTemplateGL; 00141 template<typename T> class NonPersistentArray; 00142 00143 class VRS_CORE_API ShadowTechniqueGL : public TechniqueGL { 00144 public: 00145 ShadowTechniqueGL(); 00160 static void install(ShadowTechniqueTemplateGL*); 00161 static bool uninstall(ShadowTechniqueTemplateGL*); 00162 static Iterator<SO<ShadowTechniqueTemplateGL> >* shadowTechniques(); 00164 00165 virtual bool canBeUsed(Engine*) const; 00176 virtual void start(Engine*); 00178 virtual void stop(Engine*); 00180 virtual void activatePass(int pass); 00182 virtual bool usesPass(int pass) const; 00184 virtual bool preparePass(Engine*); 00186 virtual void finishPass(Engine*); 00188 virtual void nextPass(Engine*); 00190 virtual bool prepareEval(Engine*, const Shape*); 00192 virtual void finishEval(Engine*, const Shape*); 00195 VRS_TYPEINFO(ShadowTechniqueGL, TechniqueGL); 00196 VRS_SERIALIZABLE(ShadowTechniqueGL); 00197 00198 private: 00199 mutable SO<ShadowTechniqueTemplateGL> realShadowTechnique_; 00200 bool started_; 00201 }; 00202 00204 // ShadowTechniqueTemplateGL // 00206 00207 class VRS_CORE_API ShadowTechniqueTemplateGL : public TechniqueGL { 00208 public: 00209 ShadowTechniqueTemplateGL(); 00242 virtual bool isSupported(Engine*, bool verbose) const = 0; 00247 virtual int rate(Engine*) const = 0; 00257 virtual bool canBeUsed(Engine*) const; 00262 virtual void start(Engine*); 00265 virtual void stop(Engine*); 00269 virtual bool preparePass(Engine*); 00277 virtual void finishPass(Engine*); 00281 virtual void nextPass(Engine*); 00288 virtual bool prepareEval(Engine*, const Shape*); 00297 virtual void finishEval(Engine*, const Shape*); 00302 VRS_TYPEINFO(ShadowTechniqueTemplateGL, TechniqueGL); 00303 VRS_SERIALIZABLE_ABSTRACT_CLASS(ShadowTechniqueTemplateGL); 00304 00305 protected: 00306 00307 virtual void startHook(Engine*) = 0; 00309 virtual void stopHook(Engine*) = 0; 00311 00312 virtual bool preparePassHook(Engine*) = 0; 00317 virtual void finishPassHook(Engine*) = 0; 00319 virtual void nextPassHook(Engine*) = 0; 00321 00322 virtual bool prepareEvalHook(Engine*, const Shape*) = 0; 00327 virtual void finishEvalHook(Engine*, const Shape*, bool render) = 0; 00331 void singleLightAddSettings(Engine* engine, bool on); 00333 00334 virtual void setupShadowTest(bool onOff, Engine*) = 0; 00339 virtual void toggleShadowTest(bool receiving, Engine*) = 0; 00343 virtual Iterator<SO<Light> >* newLightIterator() const; 00348 void setLight(Light* mylight, bool am, bool df, bool sp, Engine* engine); 00351 virtual void resetLight(Engine*); 00355 enum LightAdjustment { OnlyAmbient, OnlyDiffuseAndSpecular }; 00356 VRS_SERIALIZABLE_CLASS_ENUM(LightAdjustment); 00357 virtual void adjustLights(Engine*, LightAdjustment, Light* = 0); 00359 00360 protected: 00361 unsigned int lightIndex_; 00367 Light* currentLight() const; 00369 00370 virtual Iterator<SO<ShadowCaster> >* getShadowCasterAttributesInScene() const; 00372 virtual Iterator<SO<Shadowed> >* getShadowedAttributesInScene() const; 00374 00375 private: 00376 SO<NonPersistentArray<SO<Light> > > lightsWithShadows_; 00377 // list of shadowed lights contained in the scene graph (valid after GATHERLIGHTS) 00378 00379 SO<NonPersistentArray<SO<Light> > > lightsInScene_; 00380 // temp. light list (valid after GATHERLIGHTS) 00381 SO<NonPersistentArray<SO<ShadowCaster> > > castersInScene_; 00382 // shadow casting attributes in the scene graph (valid after GATHERLIGHTS) 00383 SO<NonPersistentArray<SO<Shadowed> > > receiversInScene_; 00384 // shadowed attributes in the scene graph (valid after GATHERLIGHTS) 00385 00386 bool render_; 00387 int recursions_; 00388 }; 00389 00390 template <class T> 00391 class ReferencesTo { 00392 public: 00393 ReferencesTo(const Light* light) : light_(light) {}; 00394 bool operator() (const PolyAttribute* attr) const { 00395 const T* shadowattr = VRS_Cast(T, attr); 00396 return light_ == shadowattr->getLightSource(); 00397 } 00398 private: 00399 const Light* light_; 00400 }; 00401 00402 // usage: 00403 // SO<Iterator<SO<PolyAttribute> > > itr = 00404 // engine->newPolyAttributeIterator(Shadowed::ClassNameVRS(), ...); 00405 // 00406 // found = std::find_if(itr->beginSTL(), itr->endSTL(), 00407 // ReferencesTo<Shadowed>(currentLight())) != itr->endSTL(); 00408 // 00409 // this means a shadow casting attribute that aggregates currentLight() is contained 00410 // in the iterator. 00411 // 00412 // works for shadow casting attribute and shadowed attributes. 00413 00414 } // namespace VRS 00415 00416 #endif // VRS_OPENGL_SHADOWTECHNIQUEGL_H