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

material.h

Go to the documentation of this file.
00001 /***************************************************************************
00002          material.h  -  Material classes. Z buffer modes, blend modes,
00003                       texture layers, material effects
00004                              -------------------
00005     begin                : Wed Oct 31 2001
00006     copyright            : (C) 2001 by Reality Rift Studios
00007     email                : mattias@realityrift.com
00008  ***************************************************************************
00009 
00010  The contents of this file are subject to the Mozilla Public License Version
00011  1.1 (the "License"); you may not use this file except in compliance with
00012  the License. You may obtain a copy of the License at 
00013  http://www.mozilla.org/MPL/
00014 
00015  Software distributed under the License is distributed on an "AS IS" basis,
00016  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00017  for the specific language governing rights and limitations under the
00018  License.
00019 
00020  The Original Code is the NeoEngine, material.h
00021 
00022  The Initial Developer of the Original Code is Mattias Jansson.
00023  Portions created by Mattias Jansson are Copyright (C) 2001
00024  Reality Rift Studios. All Rights Reserved.
00025 
00026  ***************************************************************************/
00027 
00028 #ifndef __NEMATERIAL_H
00029 #define __NEMATERIAL_H
00030 
00031 
00038 #include "base.h"
00039 #include "program.h"
00040 #include "texture.h"
00041 #include "texmatrixgen.h"
00042 #include "color.h"
00043 #include "hashtable.h"
00044 #include "hashstring.h"
00045 #include "util.h"
00046 
00047 #include <string>
00048 #include <vector>
00049 
00050 
00051 namespace NeoEngine
00052 {
00053 
00054 
00055 // Forward declaractions
00056 class Material;
00057 
00058 
00063 class NEOENGINE_API BlendMode
00064 {
00065     public:
00066 
00071         enum SRCBLENDMODE
00072         {
00074           SRC_ONE                                     = 0x00000000,
00075 
00077           SRC_ZERO                                    = 0x00000001,
00078 
00080           SRC_DESTCOLOR                               = 0x00000004,
00081 
00083           SRC_ONEMINUSDESTCOLOR                       = 0x00000005,
00084 
00086           SRC_SRCCOLOR                                = 0x00000007,
00087 
00089           SRC_FACTOR                                  = 0x00000008,
00090 
00092           SRC_SRCALPHA                                = 0x00000009,
00093 
00095           SRC_ONEMINUSSRCALPHA                        = 0x0000000a,
00096 
00098           SRC_DESTALPHA                               = 0x0000000c,
00099 
00101           SRC_ONEMINUSDESTALPHA                       = 0x0000000d,
00102 
00103           /* min( S_alpha, 1 - D_alpha ) * S_rgb */
00104           SRC_ALPHASATURATE                           = 0x0000000f,
00105 
00107           SRCBITS                                     = 0x0000000f
00108         };
00109 
00110 
00115         enum DESTBLENDMODE
00116         {
00118           DEST_ZERO                                   = 0x00000000,
00119 
00121           DEST_ONE                                    = 0x00000010,
00122 
00124           DEST_SRCCOLOR                               = 0x00000040,
00125 
00127           DEST_ONEMINUSSRCCOLOR                       = 0x00000050,
00128 
00130           DEST_ONEMINUSFACTOR                         = 0x00000060,
00131 
00133           DEST_SRCALPHA                               = 0x00000080,
00134 
00136           DEST_ONEMINUSSRCALPHA                       = 0x00000090,
00137 
00139           DEST_DESTALPHA                              = 0x000000b0,
00140 
00142           DEST_ONEMINUSDESTALPHA                      = 0x000000c0,
00143 
00145           DESTBITS                                    = 0x000000f0
00146         };
00147 
00148 
00152         enum BLENDMODE
00153         {
00155           NORMAL                                      = 0x00000000,
00156 
00158           DECAL                                       = ( SRC_SRCALPHA          | DEST_ONEMINUSSRCALPHA ),
00159 
00161           DECALFACTOR                                 = ( SRC_FACTOR            | DEST_ONEMINUSFACTOR   ),
00162 
00164           MODULATE                                    = ( SRC_DESTCOLOR         | DEST_ZERO             ),
00165 
00167           MODULATE_ALT                                = ( SRC_ZERO              | DEST_SRCCOLOR         ),
00168 
00170           MODULATE_2X                                 = ( SRC_DESTCOLOR         | DEST_SRCCOLOR         ),
00171 
00173           ADD                                         = ( SRC_ONE               | DEST_ONE              ),
00174 
00176           ADDSMOOTH                                   = ( SRC_ONE               | DEST_ONEMINUSSRCCOLOR ),
00177 
00179           ADDSMOOTH_ALT                               = ( SRC_ONEMINUSDESTCOLOR | DEST_ONE              ),
00180 
00182           ZERO                                        = ( SRC_ZERO              | DEST_ZERO             ),
00183 
00185           BITS                                        = ( SRCBITS               | DESTBITS              )
00186         };
00187 
00188 
00189     protected:
00190 
00192         unsigned int                                  m_uiMode;
00193 
00194     public:
00195 
00197         float                                         m_fFactor;
00198 
00199 
00202                                                       BlendMode() : m_uiMode( NORMAL ), m_fFactor( 1.0f ) {}
00203 
00207                                                       BlendMode( const BlendMode &rkMode ) : m_uiMode( rkMode.m_uiMode ), m_fFactor( rkMode.m_fFactor ) {}
00208 
00214         void                                          Set( unsigned int uiSrcMode, unsigned int uiDestMode ) { m_uiMode = ( ( uiSrcMode & SRCBITS ) | ( uiDestMode & DESTBITS ) ); }
00215 
00220         void                                          Set( unsigned int uiMode ) { m_uiMode = uiMode & BITS; }
00221 
00226         int                                           Get() const { return m_uiMode; }
00227 
00233         static std::string                            GetSrcModeAsString( unsigned int uiMode );
00234 
00240         static std::string                            GetDestModeAsString( unsigned int uiMode );
00241 
00247         static unsigned int                           GetSrcModeFromString( const std::string &rstrMode );
00248 
00254         static unsigned int                           GetDestModeFromString( const std::string &rstrMode );
00255 
00261         BlendMode                                    &operator = ( const BlendMode &rkBlendMode ) { m_uiMode = rkBlendMode.m_uiMode; m_fFactor = rkBlendMode.m_fFactor; return( *this ); }
00262 };
00263 
00264 
00269 class NEOENGINE_API ZBufferMode
00270 {
00271     public:
00272 
00276         enum ZTESTFUNC
00277         {
00279           LESS                                        = 0x00000000,
00280 
00282           LEQUAL                                      = 0x00000001,
00283 
00285           EQUAL                                       = 0x00000002,
00286 
00288           GEQUAL                                      = 0x00000003,
00289 
00291           GREATER                                     = 0x00000004,
00292 
00294           ALWAYSPASS                                  = 0x00000005,
00295 
00297           FUNCBITS                                    = 0x00000007
00298         };
00299 
00303         enum ZWRITEMODE
00304         {
00306           ENABLED                                     = 0x00000000,
00307 
00309           DISABLED                                    = 0x00000010,
00310 
00312           MODEBITS                                    = 0x00000010
00313         };
00314 
00318         enum ZBUFFERMODE
00319         {
00321           NORMAL                                      = ( LEQUAL     | ENABLED  ),
00322 
00324           LESSWRITE                                   = ( LESS       | ENABLED  ),
00325 
00327           LEQUALWRITE                                 = ( LEQUAL     | ENABLED  ),
00328 
00330           EQUALWRITE                                  = ( EQUAL      | ENABLED  ),
00331 
00333           GEQUALWRITE                                 = ( GEQUAL     | ENABLED  ),
00334 
00336           GREATERWRITE                                = ( GREATER    | ENABLED  ),
00337 
00339           ALWAYSWRITE                                 = ( ALWAYSPASS | ENABLED  ),
00340 
00342           LESSNOWRITE                                 = ( LESS       | DISABLED ),
00343 
00345           LEQUALNOWRITE                               = ( LEQUAL     | DISABLED ),
00346 
00348           EQUALNOWRITE                                = ( EQUAL      | DISABLED ),
00349 
00351           GEQUALNOWRITE                               = ( GEQUAL     | DISABLED ),
00352 
00354           GREATERNOWRITE                              = ( GREATER    | DISABLED ),
00355 
00357           ALWAYSNOWRITE                               = ( ALWAYSPASS | DISABLED ),
00358 
00360           BITS                                        = ( FUNCBITS   | MODEBITS )
00361         };
00362 
00363 
00364     protected:
00365 
00367         unsigned int                                  m_uiMode;
00368 
00369 
00370     public:
00371     
00374                                                       ZBufferMode() : m_uiMode( NORMAL ) {}
00375 
00379                                                       ZBufferMode( const ZBufferMode &rkMode ) : m_uiMode( rkMode.m_uiMode ) {}
00380 
00386         void                                          Set( unsigned int uiZTest, unsigned int uiZWrite ) { m_uiMode = ( uiZTest | uiZWrite ) & BITS; }
00387 
00392         void                                          Set( unsigned int uiMode ) { m_uiMode = uiMode & BITS; }
00393 
00398         int                                           Get() const { return m_uiMode; }
00399         
00405         static std::string                            GetWriteModeAsString( unsigned int uiMode );
00406 
00412         static std::string                            GetTestFuncAsString( unsigned int uiMode );
00413 
00419         static unsigned int                           GetWriteModeFromString( const std::string &rstrMode );
00420 
00426         static unsigned int                           GetTestFuncFromString( const std::string &rstrFunc );
00427 
00433         ZBufferMode                                  &operator = ( const ZBufferMode &rkMode ) { m_uiMode = rkMode.m_uiMode; return( *this ); }
00434 };
00435 
00436 
00437 #ifdef WIN32
00438 #  ifdef _MSC_VER
00439 #    pragma warning( disable : 4231 )
00440 #  endif
00441 #  ifndef __HAVE_VECTOR_NETEXTUREMATRIXGEN
00442      UDTVectorEXPIMP( class TextureMatrixGen* );
00443 #    define __HAVE_VECTOR_NETEXTUREMATRIXGEN
00444 #  endif
00445 #endif
00446 
00447 
00453 class NEOENGINE_API TextureLayer
00454 {
00455     public:
00456 
00460         enum TEXTURELAYERFLAG
00461         {
00463           NOFLAGS                                     = 0x0000,
00464 
00466           MULTIPASS                                   = 0x0001
00467         };
00468 
00469 
00475         enum TEXTUREADDRESSMODE
00476         {
00478           WRAP                                        = 0x00000000,
00479 
00481           WRAP_U                                      = 0x00000000,
00482 
00484           WRAP_V                                      = 0x00000000,
00485 
00487           WRAP_W                                      = 0x00000000,
00488 
00490           CLAMP                                       = 0x00001111,
00491 
00493           CLAMP_U                                     = 0x00000001,
00494 
00496           CLAMP_V                                     = 0x00000010,
00497 
00499           CLAMP_W                                     = 0x00000100
00500         };
00501 
00505         enum TEXCOORDGENERATION
00506         {
00508           NOGEN                                       = 0,
00509 
00511           REFLECTION                                  = 1,
00512 
00514           NORMAL                                      = 2
00515         };
00516 
00517 
00518 
00519     public:
00520     
00522         BlendMode                                     m_kBlendMode;
00523         
00525         TexturePtr                                    m_pkTexture;
00526 
00528         unsigned int                                  m_uiUVLayer;
00529 
00531         unsigned int                                  m_uiUVAddress;
00532 
00534         std::vector< TextureMatrixGen* >              m_vpkTexMatrixGen;
00535 
00537         unsigned int                                  m_uiLayerFlags;
00538 
00540         TEXCOORDGENERATION                            m_eTexCoordGen;
00541 
00542 
00545                                                       TextureLayer() : m_uiUVLayer( 0 ), m_uiUVAddress( WRAP ), m_uiLayerFlags( NOFLAGS ), m_eTexCoordGen( NOGEN ) {}
00546 
00550                                                       TextureLayer( const TextureLayer &rkLayer ) : m_kBlendMode( rkLayer.m_kBlendMode ), m_pkTexture( rkLayer.m_pkTexture ), m_uiUVLayer( rkLayer.m_uiUVLayer ), m_uiUVAddress( rkLayer.m_uiUVAddress ), m_vpkTexMatrixGen( rkLayer.m_vpkTexMatrixGen.size() ), m_uiLayerFlags( rkLayer.m_uiLayerFlags ), m_eTexCoordGen( rkLayer.m_eTexCoordGen ) { unsigned int uiEnd = rkLayer.m_vpkTexMatrixGen.size(); for( unsigned int i = 0; i < uiEnd; ++i ) { m_vpkTexMatrixGen[i] = rkLayer.m_vpkTexMatrixGen[i]->Duplicate(); } }
00551                                             
00554         virtual                                      ~TextureLayer();
00555 
00561         const TextureLayer                           &operator =( const TextureLayer &rkLayer );
00562 
00566         static unsigned int                           GetFlagFromString( const std::string &rstrIdentifier );
00567 };
00568 
00569 
00570 #ifdef WIN32
00571 #  ifndef __HAVE_VECTOR_NETEXTURELAYER
00572      UDTVectorEXPIMP( class TextureLayer* );
00573 #    define __HAVE_VECTOR_NETEXTURELAYER
00574 #  endif
00575 #endif
00576 
00577 
00578 HashTableExport(Material);
00579 
00580 
00585 typedef HashTable< Material > MaterialTable;
00586 
00587 
00592 class NEOENGINE_API Material : public RefCounter, public TextureLayer
00593 {
00594     protected:
00595 
00597         HashString                                            m_strName;
00598 
00600         MaterialTable                                        *m_pkTable;
00601 
00602 
00603 
00604     public:
00605 
00607         Color                                                 m_kAmbient;
00608 
00610         Color                                                 m_kDiffuse;
00611 
00613         Color                                                 m_kSpecular;
00614 
00616         Color                                                 m_kEmission;
00617 
00619         float                                                 m_fShininess;
00620 
00622         ZBufferMode                                           m_kZBufferMode;
00623 
00625         bool                                                  m_bDynamicShadows;
00626         
00628         ProgramPtr                                            m_pkVertexProgram;
00629 
00631         ProgramPtr                                            m_pkFragmentProgram;
00632 
00634         std::vector< TextureLayer* >                          m_vpkTextureLayers;
00635 
00637         unsigned int                                          m_uiMaxLights;
00638 
00639 
00644                                                               Material( const HashString &rstrName, MaterialTable *pkTable = 0 );
00645 
00651                                                               Material( const Material &rkMaterial, MaterialTable *pkTable = 0 );
00652 
00656         virtual                                              ~Material();
00657 
00661         void                                                  SetName( const std::string &rstrName );
00662 
00666         const HashString                                     &GetName() const { return m_strName; }
00667 
00672         void                                                  SetTable( MaterialTable *pkTable );
00673 
00679         const Material                                       &operator =( const Material &rkMaterial );
00680 };
00681 
00682 
00683 #ifndef __HAVE_SMARTPOINTER_NEMATERIAL
00684    SmartPointer( Material );
00685 #  define __HAVE_SMARTPOINTER_NEMATERIAL
00686 #endif
00687 
00688 
00689 };
00690 
00691 
00692 #endif

Generated on Wed Jan 21 14:21:06 2004 for NeoEngine by doxygen 1.3.5