Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGDVRIsoShader.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000,2001 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef _OSGDVRISOSHADER_H_
00040 #define _OSGDVRISOSHADER_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044 
00045 #include <vector>
00046 
00047 #include <OSGConfig.h>
00048 #include <OSGWindow.h>
00049 #include <OSGGL.h>
00050 #include <OSGSystemDef.h>
00051 #include <OSGDVRShader.h>
00052 #include <OSGDrawActionBase.h>
00053 #include <OSGDVRVolume.h>
00054 #include <OSGDVRVolumeTexture.h>
00055 #include <OSGCamera.h>
00056 #include <OSGColor.h>
00057 #include <OSGFragmentProgramChunk.h>
00058 
00059 #include <OSGDVRIsoShaderBase.h>
00060 
00061 OSG_BEGIN_NAMESPACE
00062 
00063 
00067 class OSG_SYSTEMLIB_DLLMAPPING DVRIsoShader : public DVRIsoShaderBase
00068 {
00069   private:
00070 
00071     typedef DVRIsoShaderBase Inherited;
00072 
00073     /*==========================  PUBLIC  =================================*/
00074   public:
00075 
00076     //    static bool _initialized;
00077 
00078     // Callback to set up shader - register textures here
00079     virtual bool initialize       (DVRVolume      *volume, 
00080                                    DrawActionBase *action      );
00081     
00082     // Callback before any slice is rendered - setup per volume
00083     virtual void activate         (DVRVolume      *volume, 
00084                                    DrawActionBase *action      );
00085 
00086     // Callback before any brick - state setup per brick
00087     virtual void brickActivate    (DVRVolume      *volume, 
00088                                    DrawActionBase *action, 
00089                                    Brick          *brick       );
00090 
00091     // Callback after all rendering of the volume is done
00092     virtual void deactivate       (DVRVolume      *volume, 
00093                                    DrawActionBase *action      );
00094     
00095     // Callback to clean up shader resources
00096     virtual void cleanup          (DVRVolume      *volume, 
00097                                    DrawActionBase *action      );
00098     
00099     // Callback for rendering not clipped slices
00100     virtual void renderSlice      (DVRVolume      *volume, 
00101                                    DrawActionBase *action,
00102                                    Real32         *data, 
00103                                    UInt32          vertices, 
00104                                    UInt32          values      );
00105 
00106     // Callback for rendering clipped slices
00107     virtual void renderSlice      (DVRVolume      *volume, 
00108                                    DrawActionBase *action,
00109                                    DVRRenderSlice *clippedSlice);
00110     
00111     // Returns whether the shader has an implementation of 'renderSlice'
00112     virtual bool hasRenderCallback(void                        );
00113 
00114     // Returns whether the shader requires multitextured slabs instead 
00115     // of bricks
00116     virtual bool useMTSlabs       (void                        ); 
00117 
00118     /*---------------------------------------------------------------------*/
00122     virtual void changed(BitVector  whichField, 
00123                          UInt32     origin);
00124 
00126     /*---------------------------------------------------------------------*/
00130     virtual void dump(      UInt32     uiIndent = 0, 
00131                       const BitVector  bvFlags  = 0) const;
00133     /*=========================  PROTECTED  ===============================*/
00134 
00135   protected:
00136     
00137     enum ShadingMode 
00138     {
00139         SM_AUTO = 0,
00140         SM_COLORMATRIX_2D, 
00141         SM_COLORMATRIX_3D, 
00142         SM_REGISTER_COMBINERS_2D, 
00143         SM_REGISTER_COMBINERS_MULTI2D, 
00144         SM_REGISTER_COMBINERS_3D,
00145         SM_FRAGMENT_PROGRAM_2D,
00146         SM_FRAGMENT_PROGRAM_3D,
00147         SM_NONE
00148     };
00149     
00150     struct DirLight 
00151     {
00152         Vec3f dir;
00153         Color4f color;
00154     };
00155     
00156     typedef std::vector<DirLight> DirLightList;  
00157 
00158 
00159     ImagePtr                m_gradientImage;
00160 
00161     bool                    m_hasPerStageConstants;
00162     GLint                   m_maxCombiners;
00163 
00164     UInt8                   m_shadingMode;
00165 
00166     FragmentProgramChunkPtr m_pFragProg;
00167 
00168     Int32                   m_textureId; 
00169 
00170     GLint                   m_colorWriteMask[4];
00171 
00172     /*---------------------------------------------------------------------*/
00176     DVRIsoShader(void);
00177     DVRIsoShader(const DVRIsoShader &source);
00178 
00180     /*---------------------------------------------------------------------*/
00184     virtual ~DVRIsoShader(void); 
00185 
00188     // compute gradient image from volume texture
00189     ImagePtr createGradientImage(DVRVolumeTexturePtr volTex);
00190 
00191 
00192     /* checks if the current OpenGL version is greater or equal to the 
00193        given one
00194     */
00195     bool checkGLVersion                       (GLfloat         version       );
00196 
00197     // Checks whether the selected mode is supported
00198     bool isModeSupported                      (DVRVolume      *volume, 
00199                                                DrawActionBase *action, 
00200                                                UInt8           mode          );
00201 
00202     // Automatically select the probably best shading mode
00203     UInt8 selectMode                          (DVRVolume      *volume, 
00204                                                DrawActionBase *action        );
00205 
00206     // try to select the given mode
00207     bool tryMode                              (DVRVolume      *volume, 
00208                                                DrawActionBase *action, 
00209                                                UInt8           mode          );
00210 
00211     // get active light sources from current OpenGL state
00212     void getLightSources                      (DirLightList   &diffuseLights, 
00213                                                DirLightList   &specularLights,
00214                                                Color4f        &ambientLight  );
00215 
00216     void getCoveredScreenRect                 (DVRVolume      *volume, 
00217                                                DrawActionBase *action, 
00218                                                GLfloat         screenRect[4] );
00219       
00220     // setup state for color matrix shading
00221     void activate_ColorMatrixShading          (DVRVolume      *volume, 
00222                                                DrawActionBase *action        );
00223 
00224     // cleanup state for color matrix shading 
00225     void deactivate_ColorMatrixShading        (DVRVolume      *volume, 
00226                                                DrawActionBase *action        );
00227     
00228     // setup state for shading using NV_register_combiners
00229     void activate_NVRegisterCombinerShading   (DVRVolume      *volume, 
00230                                                DrawActionBase *action        );
00231 
00232     // cleanup state used for shading with NV_register_combiners
00233     void deactivate_NVRegisterCombinerShading (DVRVolume      *volume, 
00234                                                DrawActionBase *action        );
00235 
00236     // setup state for shading with fragment program
00237     void activate_FragmentProgramShading      (DVRVolume      *volume, 
00238                                                DrawActionBase *action        );
00239 
00240     // cleanup state for shading with fragment program
00241     void deactivate_FragmentProgramShading    (DVRVolume      *volume, 
00242                                                DrawActionBase *action        );
00243 
00244     // render a slice for 2D multitexture register combiner shading
00245     void renderSlice_NVRegisterCombinerShading(DVRVolume      *volume, 
00246                                                DrawActionBase *action,
00247                                                Real32         *data, 
00248                                                UInt32          vertices, 
00249                                                UInt32          values        );
00250 
00251     // render a clipped slice for 2D multitexture register combiner shading
00252     void renderSlice_NVRegisterCombinerShading(DVRVolume *volume, 
00253                                                DrawActionBase *action,
00254                                                DVRRenderSlice *clippedSlice  );
00255 
00256     // render a slice for 2D multitexture fragment program shading
00257     void renderSlice_FragmentProgramShading   (DVRVolume *volume, 
00258                                                DrawActionBase *action,
00259                                                Real32         *data, 
00260                                                UInt32          vertices, 
00261                                                UInt32          values        );
00262 
00263     // render a clipped slice for 2D multitexture fragment program shading
00264     void renderSlice_FragmentProgramShading   (DVRVolume      *volume, 
00265                                                DrawActionBase *action,
00266                                                DVRRenderSlice *clippedSlice  );
00267     
00268     // setup register combiner parameters for diffuse lighted shading
00269     void setupCombinerParametersDiffuse       (DVRVolume      *volume, 
00270                                                DrawActionBase *action        );
00271 
00272     // setup register combiner parameters for specular lighted shading
00273     void setupCombinerParametersSpecular      (DVRVolume      *volume, 
00274                                                DrawActionBase *action        );
00275 
00276     // setup register combiners for diffuse lighted shading
00277     void initCombiners_IsoSurfaceDiffuse      (DrawActionBase *action        );
00278 
00279     // setup register combiners for diffuse lighted shading, if only 
00280     // two general combiners are available
00281     // this allows up to two diffuse light sources
00282     void initCombiners_Diffuse2Combiners      (DrawActionBase *action        );
00283 
00284     // setup register combiners for diffuse lighted shading, if more
00285     // than two general combiners are available
00286     // this allows a arbitrary number of diffuse light sources, in fact  
00287     // with 8 general register combiners (GeForce3/4) there are up to 6
00288     // lightsources available
00289     void initCombiners_DiffuseMultiCombiners  (DrawActionBase *action        );
00290 
00291     // setup register combiners for specular lighted shading
00292     void initCombiners_IsoSurfaceSpecular     (DrawActionBase *action        );
00293 
00294     // setup register combiners for specular lighted shading, if only 
00295     // two general combiners are available
00296     // this allows one diffuse and one specular white lightsource, only 
00297     // the RED components of the lights colors affect the shading intensity
00298     void initCombiners_Specular2Combiners     (DrawActionBase *action        );
00299 
00300     // setup register combiners for diffuse lighted shading, if more 
00301     // than two general combiners are available
00302     // currently uses 8 general combiners. So up to 3 diffuse and 3 specular
00303     // (fullcolor) lightsources are supported
00304     void initCombiners_SpecularMultiCombiners (DrawActionBase *action        );
00305  
00306 
00307     // fragment programs used by fragment shader mode
00308     static char _fragProg2D[];   
00309     static char _fragProg3D[];
00310 
00311     // extension indices for used extensions
00312     static UInt32 _ARB_multitexture;
00313     static UInt32 _EXT_texture3D; 
00314     static UInt32 _EXT_secondary_color; 
00315 
00316     static UInt32 _NV_register_combiners;
00317     static UInt32 _NV_register_combiners2;
00318 
00319     static UInt32 _SGI_color_matrix;
00320 
00321     static UInt32 _ARB_fragment_program;
00322     
00323     // extension indices for used functions
00324     static UInt32 _funcActiveTextureARB;
00325     static UInt32 _funcMultiTexCoord2dARB;    
00326     static UInt32 _funcTexImage3DEXT;
00327 
00328     static UInt32 _funcCombinerParameteriNV;
00329     static UInt32 _funcCombinerParameterfvNV;
00330     static UInt32 _funcCombinerStageParameterfvNV;
00331     static UInt32 _funcCombinerInputNV;
00332     static UInt32 _funcCombinerOutputNV;
00333     static UInt32 _funcFinalCombinerInputNV;
00334 
00335     static UInt32 _funcSecondaryColor3fEXT;
00336     static UInt32 _funcSecondaryColor3fvEXT;
00337     
00338     /*==========================  PRIVATE  ================================*/
00339 
00340   private:
00341 
00342     friend class FieldContainer;
00343     friend class DVRIsoShaderBase;
00344 
00345     static void initMethod(void);
00346 
00347     // prohibit default functions (move to 'public' if you need one)
00348     void operator =(const DVRIsoShader &source);
00349 };
00350 
00351 typedef DVRIsoShader *DVRIsoShaderP;
00352 
00353 OSG_END_NAMESPACE
00354 
00355 #include "OSGDVRIsoShader.inl"
00356 #include "OSGDVRIsoShaderBase.inl"
00357 
00358 #define OSGDVRISOSHADER_HEADER_CVSID "@(#)$Id: $"
00359 
00360 #endif /* _OSGDVRISOSHADER_H_ */

Generated on Thu Aug 25 04:03:36 2005 for OpenSG by  doxygen 1.4.3