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

OgreD3D7RenderSystem.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://ogre.sourceforge.net/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #ifndef __D3DRENDERSYSTEM_H__
00026 #define __D3DRENDERSYSTEM_H__
00027 
00028 // Precompiler options
00029 #include "OgreD3D7Prerequisites.h"
00030 #include "OgreString.h"
00031 
00032 
00033 
00034 #include "OgreRenderSystem.h"
00035 #include "OgreD3D7HardwareBufferManager.h"
00036 
00037 namespace Ogre {
00038 
00039     class DDDriverList;
00040     class DDDriver;
00041 
00045     class D3DRenderSystem : public RenderSystem
00046     {
00047     private:
00048         // Direct3D rendering device
00049         // Only created after top-level window created
00050         LPDIRECT3DDEVICE7 mlpD3DDevice;
00051         D3DDEVICEDESC7 mD3DDeviceDesc;
00052 
00053         // List of DD drivers installed (video cards)
00054         // Enumerates itself
00055         DDDriverList* mDriverList;
00056         // Currently active driver
00057         DDDriver* mActiveDDDriver;
00058 
00059 
00060         HINSTANCE mhInstance;
00061 
00062 
00063 
00064         // Stored options
00065         ConfigOptionMap mOptions;
00066 
00067         // Private utilities
00068         DDDriverList* getDirectDrawDrivers(void);
00069         void refreshDDSettings(void);
00070 
00072         enum eD3DTexType
00073         {
00075             D3D_TEX_TYPE_NORMAL,
00077             D3D_TEX_TYPE_CUBE,
00079             D3D_TEX_TYPE_VOLUME
00080         };
00081  
00083         eD3DTexType _ogreTexTypeToD3DTexType(TextureType ogreTexType)
00084         {
00085             eD3DTexType ret;
00086             switch (ogreTexType)
00087             {
00088             case TEX_TYPE_1D :
00089             case TEX_TYPE_2D :
00090                 ret = D3D_TEX_TYPE_NORMAL;
00091                 break;
00092             case TEX_TYPE_CUBE_MAP :
00093                 ret = D3D_TEX_TYPE_CUBE;
00094                 break;
00095             default :
00096                 Except( Exception::ERR_INVALIDPARAMS, "Invalid tex.type", "D3D9RenderSystem::_ogreTexTypeToD3DTexType" );
00097                 break;
00098             }
00099             return ret;
00100         }
00101  
00103         struct sD3DTextureStageDesc
00104         {
00106             eD3DTexType texType;
00108             size_t coordIndex;
00110             TexCoordCalcMethod autoTexCoordType;
00112             const Frustum* frustum;
00114             LPDIRECTDRAWSURFACE7 pTex;
00115         } mTexStageDesc[OGRE_MAX_TEXTURE_LAYERS];
00116 
00117 
00118         // Matrix conversion
00119         D3DMATRIX makeD3DMatrix(const Matrix4& mat);
00120         Matrix4 convertD3DMatrix(const D3DMATRIX& mat);
00121 
00122         void initConfigOptions(void);
00123         void initInputDevices(void);
00124         void processInputDevices(void);
00125         void setD3DLight(size_t index, Light* light);
00126 
00127         D3DCMPFUNC convertCompareFunction(CompareFunction func);
00128         D3DSTENCILOP convertStencilOp(StencilOperation op);
00129 
00130         // state management methods, very primitive !!!
00131         HRESULT __SetRenderState(D3DRENDERSTATETYPE state, DWORD value);
00132         HRESULT __SetTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value);
00133 
00134 
00135         D3DTEXTURESTAGESTATETYPE _getFilterCode(FilterType ft) const;
00136         DWORD _getFilter(FilterType ft, FilterOptions fo) const;
00137         DWORD _getCurrentAnisotropy(size_t unit);
00138 
00139         HardwareBufferManager* mHardwareBufferManager;
00140         GpuProgramManager* mGpuProgramManager;
00141 
00142 
00143         unsigned short mCurrentLights;
00144         Matrix4 mViewMatrix;
00145         // saved scene blending factors
00146         SceneBlendFactor mSavedSrcFactor, mSavedDestFactor;
00147 
00148 
00149     public:
00150         // Default constructor / destructor
00151         D3DRenderSystem(HINSTANCE hInstance);
00152         ~D3DRenderSystem();
00153 
00154 
00155 
00156         // ----------------------------------
00157         // Overridden RenderSystem functions
00158         // ----------------------------------
00162         const String& getName(void) const;
00166         ConfigOptionMap& getConfigOptions(void);
00170         void setConfigOption(const String &name, const String &value);
00174         String validateConfigOptions(void);
00178         RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
00182         void reinitialise(void); // Used if settings changed mid-rendering
00186         void shutdown(void);
00187 
00191         void setAmbientLight(float r, float g, float b);
00195         void setShadingType(ShadeOptions so);
00199         void setLightingEnabled(bool enabled);
00203         RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, unsigned int colourDepth,
00204             bool fullScreen, int left = 0, int top = 0, bool depthBuffer = true,
00205             RenderWindow* parentWindowHandle = 0);
00206 
00207         RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height );
00208 
00212         void destroyRenderWindow(RenderWindow* pWin);
00213 
00217         String getErrorDescription(long errorNumber) const;
00218 
00222         void convertColourValue(const ColourValue& colour, unsigned long* pDest);
00223 
00224         // -----------------------------
00225         // Low-level overridden members
00226         // -----------------------------
00230         void _useLights(const LightList& lights, unsigned short limit);
00234         void _setWorldMatrix(const Matrix4 &m);
00238         void _setViewMatrix(const Matrix4 &m);
00242         void _setProjectionMatrix(const Matrix4 &m);
00246         void _setSurfaceParams(const ColourValue &ambient,
00247             const ColourValue &diffuse, const ColourValue &specular,
00248             const ColourValue &emissive, Real shininess);
00252         void _setTexture(size_t unit, bool enabled, const String &texname);
00256         void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm);
00260         void _setTextureAddressingMode(size_t unit, TextureUnitState::TextureAddressingMode tam);
00264         void _setTextureMatrix(size_t unit, const Matrix4& xform);
00268         void _setTextureCoordSet( size_t unit, size_t index );
00272         void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m, 
00273             const Frustum* frustum = 0);
00277         void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor);
00281         void _setAlphaRejectSettings(CompareFunction func, unsigned char value);
00285         void _setViewport(Viewport *vp);
00289         void _beginFrame(void);
00293         void _render(const RenderOperation& op);
00297         void _endFrame(void);
00301         void _setCullingMode(CullingMode mode);
00305         void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
00309         void _setDepthBufferCheckEnabled(bool enabled = true);
00313         void _setDepthBufferWriteEnabled(bool enabled = true);
00317         void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
00321         void _setDepthBias(ushort bias);
00328         void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
00329         
00333         void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
00337         void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, 
00338             Real farPlane, Matrix4& dest, bool forGpuProgram = false);
00342         void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
00343             Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
00347         void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
00348             Matrix4& dest, bool forGpuProgram = false);
00352         void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 
00353             bool forGpuProgram);
00357         void _setRasterisationMode(SceneDetailLevel level);
00361         void setStencilCheckEnabled(bool enabled);
00365         void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
00366             ulong refValue = 0, ulong mask = 0xFFFFFFFF, 
00367             StencilOperation stencilFailOp = SOP_KEEP, 
00368             StencilOperation depthFailOp = SOP_KEEP,
00369             StencilOperation passOp = SOP_KEEP, 
00370             bool twoSidedOperation = false);
00371         void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
00375         void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
00379         void setVertexDeclaration(VertexDeclaration* decl);
00383         void setVertexBufferBinding(VertexBufferBinding* binding);
00387         void setNormaliseNormals(bool normalise);
00391         void bindGpuProgram(GpuProgram* prg) { /* do nothing */}
00395         void unbindGpuProgram(GpuProgramType gptype){ /* do nothing */}
00399         void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params) { /* do nothing */}    
00403         void setClipPlanes(const PlaneList& clipPlanes);
00407         void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600)
00408         { /* do nothing, d3d7 does not support scissor rect */ }
00412         void clearFrameBuffer(unsigned int buffers, 
00413             const ColourValue& colour = ColourValue::Black, 
00414             Real depth = 1.0f, unsigned short stencil = 0);
00415 
00416         void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
00417         void enableClipPlane (ushort index, bool enable);
00421         HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
00422         Real getHorizontalTexelOffset(void);
00423         Real getVerticalTexelOffset(void);
00424         Real getMinimumDepthInputValue(void);
00425         Real getMaximumDepthInputValue(void);
00426         // ----------------------------------
00427         // End Overridden members
00428         // ----------------------------------
00429     };
00430 }
00431 #endif
00432 

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:19 2004