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

# deRenderStates.hpp

Go to the documentation of this file.

    00001 ///////////////////////////////////////////////////////////////////////////////
    00002 /// @file deRenderStates.hpp
    00003 ///
    00004 /// @brief a header to include all renderstate classes
    00005 ///
    00006 /// @author Lightning
    00007 ///
    00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
    00009 /// contents of this file is subject to the Destiny3D Member License which
    00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
    00011 ///
    00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
    00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
    00014 /// for any particular purpose.
    00015 ///
    00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
    00017 ///
    00018 /// <hr>
    00019 ///                                 Change History
    00020 /// <hr>
    00021 ///
    00022 /// @date Aug 2001
    00023 /// @author Lightning
    00024 /// @remarks Creation
    00025 ///
    00026 /// @date May 2002
    00027 /// @author Assassin
    00028 /// @remarks Interface implementation
    00029 ///
    00030 /// @date Oct 2002
    00031 /// @author Assassin
    00032 /// @remarks deWorld integration
    00033 ///
    00034 ///////////////////////////////////////////////////////////////////////////////
    00035
    00036 #ifndef DERENDERSTATES_HPP
    00037 #define DERENDERSTATES_HPP
    00038
    00039 #include "deGlobalTypes.hpp"
    00040 #include "deWorld.hpp"
    00041
    00042 //define to wether or not we are exporting the classes
    00043 #if defined(DEDRIVER_DLL_EXPORTS) || defined(DESTINY3D_EXPORT_ALL)
    00044 #   define RENDERSTATE_API extern "C" DEDLL_EXPORT
    00045 #elif defined(DESTINY3D_STATIC_LINK)
    00046 #   define RENDERSTATE_API extern "C"
    00047 #else
    00048 #   define RENDERSTATE_API extern "C" DEDLL_IMPORT
    00049 #endif
    00050
    00051 //-------------------------------------------
    00052 // Defines
    00053 //-------------------------------------------
    00054
    00055 //how many texture stages are allowed, this can't really be moved to an ini as it is
    00056 //determined by direct3d's capability
    00057 #define TEXTURESTAGE_COUNT 8
    00058
    00059 //-------------------------------------------
    00060 // Classes
    00061 //-------------------------------------------
    00062 class IdeBitmapProxy;
    00063 class IdeRenderTexture;
    00064 class IdeRenderMaterial;
    00065 class IdeRenderLight;
    00066
    00067 // factory functions
    00068     RENDERSTATE_API deBoolean IdeRenderState_SetDefaultTextureFilters(long MinFilter, long MagFilter, long MipFilter, deBoolean EnableMip);
    00069     /// Get the IdeRenderState WorldObject interface ID
    00070     RENDERSTATE_API long IdeRenderState_GetWOInterfaceID();
    00071     /// Create an instance of IdeRenderTexture
    00072     RENDERSTATE_API IdeRenderTexture* IdeRenderState_CreateRenderTexture();
    00073     /// Create an instance of IdeRenderMaterial
    00074     RENDERSTATE_API IdeRenderMaterial* IdeRenderState_CreateRenderMaterial();
    00075     /// Create an instance of IdeRenderLight
    00076     RENDERSTATE_API IdeRenderLight* IdeRenderState_CreateRenderLight();
    00077
    00078 /// The base renderstate class
    00079 //class IdeRenderState : virtual public IdeWorldObject
    00080 DE3D_INTERFACE(IdeRenderState, IdeWorldObject)
    00081 {
    00082     //constructor and destructor
    00083 protected:
    00084     virtual ~IdeRenderState() {}
    00085 public:
    00086     enum Type
    00087     {
    00088         TYPE_RSTATE = -1,
    00089         TYPE_TEXTURE = 0,
    00090         TYPE_LIGHT,
    00091         TYPE_MATERIAL,
    00092         TYPE_COUNT,
    00093         TYPE_FORCE_32BIT = 0x7FFFFFFF
    00094     };
    00095
    00096     //renderstate info
    00097     virtual IdeRenderState::Type GetRSType() const = 0;
    00098     virtual void * GetRSInterface(IdeRenderState::Type type) const = 0;
    00099
    00100     //lock/unlock functions
    00101     /// You must call this method before calling any Set*** methods.
    00102     virtual deBoolean Lock() = 0;
    00103     /// You must call this method once you are done setting data, so that something else may.
    00104     virtual deBoolean Unlock() = 0;
    00105 };
    00106
    00107 /// the texture renderstate class
    00108 /// @todo split IdeRenderTexture into 2 separate ones - TextureSet and FFPixel
    00109 //class IdeRenderTexture : virtual public IdeRenderState
    00110 DE3D_INTERFACE(IdeRenderTexture, IdeRenderState)
    00111 {
    00112 public:
    00113     /// texture operations
    00114     enum TextureOp
    00115     {
    00116         TEXTUREOP_INVALID = -1,         // invalid texture operation
    00117         TEXTUREOP_DISABLE = 0,          ///< no texture operation
    00118
    00119         //operation selection
    00120         TEXTUREOP_SELECTARG1,           ///< use texture arg1 as output
    00121         TEXTUREOP_SELECTARG2,           ///< use texture arg2 as output
    00122
    00123         //modulation
    00124         TEXTUREOP_MODULATE,             ///< S = A * B
    00125         TEXTUREOP_MODULATE2X,           ///< S = (A * B) << 1
    00126         TEXTUREOP_MODULATE4X,           ///< S = (A * B) << 2
    00127
    00128         //add/subtract
    00129         TEXTUREOP_ADD,                  ///< S = A + B
    00130         TEXTUREOP_ADDSIGNED,            ///< S = A + B - 0.5
    00131         TEXTUREOP_ADDSIGNED2X,          ///< S = (A + B - 0.5) << 1
    00132         TEXTUREOP_SUBTRACT,             ///< S = A - B
    00133         TEXTUREOP_ADDSMOOTH,            ///< S = A + B - (A * B)
    00134
    00135         //blending
    00136         TEXTUREOP_BLENDDIFFUSEALPHA,    ///< blend based on alpha of all previous textures
    00137         TEXTUREOP_BLENDTEXTUREALPHA,    ///< blend based on this texture's alpha
    00138         TEXTUREOP_BLENDFACTORALPHA,     ///< blend based on scalar alpha
    00139         TEXTUREOP_BLENDTEXTUREALPHAPM,  ///< blend based on this texture's alpha (alpha is pre-multiplied)
    00140         TEXTUREOP_BLENDPREVIOUSALPHA,   ///< blend based on alpha of previous texture
    00141
    00142         //specular mapping
    00143         TEXTUREOP_PREMODULATE,                  ///< modulate texture with next texture stage
    00144         TEXTUREOP_MODULATEALPHA_ADDCOLOR,       ///< S = A.rgb + (A.a * B.rgb)
    00145         TEXTUREOP_MODULATECOLOR_ADDALPHA,       ///< S = (A.rgb * B.rgb) + A.a
    00146         TEXTUREOP_MODULATEINVALPHA_ADDCOLOR,    ///< S = (1 - A.a) * B.rgb + A.rgb
    00147         TEXTUREOP_MODULATEINVCOLOR_ADDALPHA,    ///< S = (1 - A.rgb) * B.rgb + A.a
    00148
    00149         //bump mapping
    00150         TEXTUREOP_BUMPENVMAP,               ///< bump mapping using environment of next texture stage without luminance
    00151         TEXTUREOP_BUMPENVMAPLUMINANCE,      ///< bump mapping using environment of next texture stage with luminance
    00152         TEXTUREOP_DOTPRODUCT3,              ///< S = (A.r * B.r) + (A.g * B.g) + (A.b * B.b)
    00153
    00154         //triadic texture blending (whatever this is, just doing whatever d3d allows - Lightning)
    00155         TEXTUREOP_MULTIPLYADD,      ///< S =  A + (B * C)
    00156         TEXTUREOP_LERP,             ///< S = (A * B) + ((1 - A) * C)
    00157
    00158         TEXTUREOP_COUNT,
    00159         TEXTUREOP_FORCE_32BIT = 0x7FFFFFFF
    00160     };
    00161
    00162     /// texture arguments
    00163     enum TextureArg
    00164     {
    00165         TEXTUREARG_INVALID = 0,
    00166         TEXTUREARG_PREVIOUS =       0x0001,     ///< use result of previous blending
    00167         TEXTUREARG_DIFFUSE =        0x0002,     ///< use diffuse color
    00168         TEXTUREARG_SPECULAR =       0x0004,     ///< use specular color
    00169         TEXTUREARG_TEXTURE =        0x0010,     ///< use texture itself
    00170         TEXTUREARG_TFACTOR =        0x0020,     ///< use color argument supplied with RENDER_TEXTUREFACTOR renderstate
    00171         TEXTUREARG_TEMPREG =        0x0040,     ///< can be used as a destination or source for intermediate calculations
    00172
    00173         //texture flag modifiers
    00174         TEXTUREARG_ALPHAREPLICATE = 0x0100,     ///< replicate alpha to all color channels
    00175         TEXTUREARG_COMPLEMENT =     0x0200,     ///< invert the argument
    00176
    00177         TEXTUREARG_COUNT,
    00178         TEXTUREARG_FORCE_32BIT = 0x7FFFFFFF
    00179     };
    00180
    00181     /// texture addressing modes
    00182     enum TextureAddress
    00183     {
    00184         TEXTUREADDRESS_INVALID = -1,        //invalid address mode
    00185         TEXTUREADDRESS_WRAP = 0,            ///< wrap a texture for U or V
    00186         TEXTUREADDRESS_MIRROR,              ///< mirror the texture for U or V
    00187         TEXTUREADDRESS_CLAMP,               ///< clamp the texture
    00188         TEXTUREADDRESS_COUNT,
    00189         TEXTUREADDRESS_FORCE_32BIT = 0x7FFFFFFF
    00190     };
    00191
    00192     /// texture filtering modes
    00193     enum TextureFilter
    00194     {
    00195         TEXTUREFILTER_INVALID = -1,
    00196         TEXTUREFILTER_NONE = 0,             ///< no filterning (default for mip-maps)
    00197         TEXTUREFILTER_POINT,                ///< Closest-point filter
    00198         TEXTUREFILTER_LINEAR,               ///< linear blending filter (bilinear, trilinear)
    00199         TEXTUREFILTER_ANISOTROPIC,          ///< anisotropic blending filter
    00200         TEXTUREFILTER_COUNT,
    00201         TEXTUREFILTER_FORCE_32BIT = 0x7FFFFFFF
    00202     };
    00203
    00204     enum TextureCoordSource
    00205     {
    00206         TEXCOORD_INVALID = -1,
    00207         TEXCOORD_NOPROCESSING                   = 0x00000000,
    00208         TEXCOORD_VIEWSPACE_NORMAL               = 0x00010000,
    00209         TEXCOORD_VIEWSPACE_POSITION             = 0x00020000,
    00210         TEXCOORD_VIEWSPACE_REFLECTIONVECTOR     = 0x00030000,
    00211         TEXCOORD_FORCE_32BIT = 0x7FFFFFFF
    00212     };
    00213
    00214     //constructor/destructor
    00215 protected:
    00216     virtual ~IdeRenderTexture() {}
    00217 public:
    00218
    00219     virtual IdeRenderState::Type GetRSType() const = 0;
    00220
    00221     //functions for setting/returning texture operations
    00222     /// Set the Texture Stage's color operation
    00223     virtual deBoolean SetColorOperation(long Stage, TextureOp ColorOp) = 0;
    00224     /// Set the Texture Stage's alpha operation
    00225     virtual deBoolean SetAlphaOperation(long Stage, TextureOp AlphaOp) = 0;
    00226     /// Set where the result of this operation will go - either PREVIOUS or TEMPREG
    00227     virtual deBoolean SetResultTarget(long Stage, TextureArg Target) = 0;
    00228     virtual TextureOp GetColorOperation(long Stage) const = 0;
    00229     virtual TextureOp GetAlphaOperation(long Stage) const = 0;
    00230     virtual TextureArg GetResultTarget(long Stage) = 0;
    00231
    00232     //functions for setting the arguments
    00233     /// Set the Texture Stage's color input argument
    00234     /// @param ArgNum min:1 max:3
    00235     virtual deBoolean SetColorArg(long Stage, long ArgNum, TextureArg Arg) = 0;
    00236     /// Set the Texture Stage's alpha input argument
    00237     /// @param ArgNum min:1 max:3
    00238     virtual deBoolean SetAlphaArg(long Stage, long ArgNum, TextureArg Arg) = 0;
    00239     virtual TextureArg GetColorArg(long Stage, long ArgNum) const = 0;
    00240     virtual TextureArg GetAlphaArg(long Stage, long ArgNum) const = 0;
    00241
    00242     //texture information
    00243     /// Set the Texture Stage's source bitmap
    00244     virtual deBoolean SetBitmap(long Stage, IdeBitmapProxy* Bitmap) = 0;
    00245     /// Retrieve the Texture Stage's source bitmap
    00246     virtual IdeBitmapProxy*GetBitmap(long Stage) const = 0;
    00247
    00248     //functions to set how the texture looks
    00249     /// Set the Texture Stage's U (horizontal) addressing mode
    00250     virtual deBoolean SetTextureAddressU(long Stage, TextureAddress Address) = 0;
    00251     /// Set the Texture Stage's V (vertical) addressing mode
    00252     virtual deBoolean SetTextureAddressV(long Stage, TextureAddress Address) = 0;
    00253     virtual TextureAddress GetTextureAddressU(long Stage) const = 0;
    00254     virtual TextureAddress GetTextureAddressV(long Stage) const = 0;
    00255
    00256     // functions to set how the texture magnifies and minifies
    00257     // ie, linear filter to magnify is very common
    00258     /// Set the Texture Stage's minification filter (when more than 1 texel is in a screen pixel)
    00259     virtual deBoolean SetTextureMinFilter(long Stage, TextureFilter Filter) = 0;
    00260     /// Set the Texture Stage's magnification filter (when 1 texel affects more than 1 screen pixel)
    00261     virtual deBoolean SetTextureMagFilter(long Stage, TextureFilter Filter) = 0;
    00262     /// Set the Texture Stage's mipmap filter (when blending between two mipmaps)
    00263     virtual deBoolean SetTextureMipFilter(long Stage, TextureFilter Filter) = 0;
    00264     virtual TextureFilter GetTextureMinFilter(long Stage) const = 0;
    00265     virtual TextureFilter GetTextureMagFilter(long Stage) const = 0;
    00266     virtual TextureFilter GetTextureMipFilter(long Stage) const = 0;
    00267
    00268     virtual deBoolean SetTexCoordSource(long Stage, long SourceStage) = 0;
    00269     virtual deBoolean SetTexCoordGen(long Stage, TextureCoordSource SourcePipe, long CopyWrapModeStage = 0) = 0;
    00270     virtual deBoolean GetTexCoordSource(long Stage, long &SourceStage, TextureCoordSource &SourceFlags) = 0;
    00271     virtual long GetTexCoordSourceCombined(long Stage) = 0;
    00272
    00273     virtual deBoolean SetTextureProjection(long Stage, deBoolean Enable) = 0;
    00274     virtual deBoolean GetTextureProjection(long Stage) = 0;
    00275
    00276     virtual deBoolean CopyStageSettings(IdeRenderTexture* Target, long SourceStage, long TargetStage) const = 0;
    00277 };
    00278
    00279 /// the material renderstate class. Methods are pretty self-explanatory
    00280 //class IdeRenderMaterial : virtual public IdeRenderState
    00281 DE3D_INTERFACE(IdeRenderMaterial, IdeRenderState)
    00282 {
    00283 public:
    00284     enum MatSource_t
    00285     {
    00286         MATSOURCE_INVALID = -1,
    00287         MATSOURCE_MATERIAL = 0, ///< Use the material's values
    00288         MATSOURCE_DIFFUSE,      ///< Use the vertex diffuse values
    00289         MATSOURCE_SPECULAR,     ///< Use the vertex diffuse values
    00290         MATSOURCE_COUNT,
    00291         MATSOURCE_FORCE_32BIT = 0x7FFFFFFF
    00292     };
    00293     struct MatData
    00294     {
    00295         deColor     AmbientColor;   //ambient color
    00296         deColor     DiffuseColor;   //diffuse color
    00297         deColor     EmissiveColor;  //emissive color
    00298         deColor     SpecularColor;  //specular color
    00299         MatSource_t AmbientSource;
    00300         MatSource_t DiffuseSource;
    00301         MatSource_t SpecularSource;
    00302         MatSource_t EmissiveSource;
    00303         float       Power;          //power of the light
    00304     };
    00305     //constructor/destructor
    00306 protected:
    00307     virtual ~IdeRenderMaterial() {}
    00308 public:
    00309
    00310     virtual IdeRenderState::Type GetRSType() const = 0;
    00311
    00312     //color information
    00313     virtual deBoolean SetAmbientColor(deColor *AmbientColor) = 0;
    00314     virtual deBoolean GetAmbientColor(deColor *AmbientColor) const = 0;
    00315
    00316     virtual deBoolean SetDiffuseColor(deColor *DiffuseColor) = 0;
    00317     virtual deBoolean GetDiffuseColor(deColor *DiffuseColor) const = 0;
    00318
    00319     virtual deBoolean SetSpecularColor(deColor *SpecularColor) = 0;
    00320     virtual deBoolean GetSpecularColor(deColor *SpecularColor) const = 0;
    00321
    00322     virtual deBoolean SetEmissiveColor(deColor *EmissiveColor) = 0;
    00323     virtual deBoolean GetEmissiveColor(deColor *EmissiveColor) const = 0;
    00324
    00325     // base source info
    00326     virtual deBoolean SetAmbientSource(MatSource_t Source) = 0;
    00327     virtual MatSource_t GetAmbientSource() const = 0;
    00328
    00329     virtual deBoolean SetDiffuseSource(MatSource_t Source) = 0;
    00330     virtual MatSource_t GetDiffuseSource() const = 0;
    00331
    00332     virtual deBoolean SetSpecularSource(MatSource_t Source) = 0;
    00333     virtual MatSource_t GetSpecularSource() const = 0;
    00334
    00335     virtual deBoolean SetEmissiveSource(MatSource_t Source) = 0;
    00336     virtual MatSource_t GetEmissiveSource() const = 0;
    00337
    00338     //power of the light
    00339     virtual deBoolean SetSpecularPower(float Power) = 0;
    00340     virtual float GetSpecularPower() const = 0;
    00341
    00342     virtual const MatData* GetAllData() const = 0;
    00343     virtual deBoolean SetAllData(const MatData* Data) = 0;
    00344 };
    00345
    00346 /// the light renderstate class. Methods are pretty self-explanatory
    00347 //class IdeRenderLight : virtual public IdeRenderState
    00348 DE3D_INTERFACE(IdeRenderLight, IdeRenderState)
    00349 {
    00350 public:
    00351     enum LightType_t
    00352     {
    00353         LIGHTTYPE_INVALID = -1,
    00354         LIGHTTYPE_POINT = 0,        ///< A point light - has position only
    00355         LIGHTTYPE_SPOT,             ///< A spotlight - has position and direction
    00356         LIGHTTYPE_DIRECTIONAL,      ///< A directional light - has direction only
    00357         LIGHTTYPE_COUNT,
    00358         LIGHTTYPE_FORCE_32BIT = 0x7FFFFFFF
    00359     };
    00360     struct LightData
    00361     {
    00362         LightType_t LightType;      //type of light
    00363         deColor     AmbientColor;   //ambient color
    00364         deColor     DiffuseColor;   //diffuse color
    00365         deColor     SpecularColor;  //specular color
    00366         deVec3f     Position;       //position of the light
    00367         deVec3f     Direction;      //direction to face
    00368         deFloat     MaxRange;       //maximum range for the light
    00369         deFloat     FallOff;        //how the light changes as it gets farther away from the source
    00370         deFloat     Attenuation[3]; //light attenuation
    00371         deFloat     Theta;          //angle, in radians, of the inner cone
    00372         deFloat     Phi;            //angle, in radians, of the outer cone
    00373         s32         ID;             //the id/number of the light
    00374         deBoolean   Status;         //the status of the light (on/off)
    00375     };
    00376
    00377     //constructor/destructor
    00378 protected:
    00379     virtual ~IdeRenderLight() {}
    00380 public:
    00381
    00382     virtual IdeRenderState::Type GetRSType() const = 0;
    00383
    00384     //the light type
    00385     virtual deBoolean SetLightType(LightType_t Type) = 0;
    00386     virtual LightType_t GetLightType() const = 0;
    00387
    00388     //color information
    00389     virtual deBoolean SetAmbientColor(deColor *AmbientColor) = 0;
    00390     virtual deBoolean GetAmbientColor(deColor *AmbientColor) const = 0;
    00391
    00392     virtual deBoolean SetDiffuseColor(deColor *DiffuseColor) = 0;
    00393     virtual deBoolean GetDiffuseColor(deColor *DiffuseColor) const = 0;
    00394
    00395     virtual deBoolean SetSpecularColor(deColor *SpecularColor) = 0;
    00396     virtual deBoolean GetSpecularColor(deColor *SpecularColor) const = 0;
    00397
    00398     //position/direction information
    00399     virtual deBoolean SetPosition(deVertex *Position) = 0;
    00400     virtual deBoolean GetPosition(deVertex *Position) const = 0;
    00401
    00402     virtual deBoolean SetDirection(deVertex *Direction) = 0;
    00403     virtual deBoolean GetDirection(deVertex *Direction) const = 0;
    00404
    00405     //anything that affects the way the light looks/acts
    00406     virtual deBoolean SetRange(float MaxRange) = 0;
    00407     virtual float GetRange() const = 0;
    00408
    00409     virtual deBoolean SetFallOff(float FallOff) = 0;
    00410     virtual float GetFallOff() const = 0;
    00411
    00412     virtual deBoolean SetAttenuation(long Number, float Value) = 0;
    00413     virtual float GetAttenuation(long Number) const = 0;
    00414
    00415     virtual deBoolean SetTheta(float Theta) = 0;
    00416     virtual float GetTheta() const = 0;
    00417
    00418     virtual deBoolean SetPhi(float Phi) = 0;
    00419     virtual float GetPhi() const = 0;
    00420
    00421     //which light number it is
    00422     virtual deBoolean SetID(long Number) = 0;
    00423     virtual long GetID() const = 0;
    00424
    00425     //light status (on/off)
    00426     virtual deBoolean SetStatus(deBoolean On) = 0;
    00427     virtual deBoolean GetStatus() const = 0;
    00428
    00429     virtual const LightData* GetAllData() const = 0;
    00430     virtual deBoolean SetAllData(const LightData* Data) = 0;
    00431 };
    00432
    00433 #endif