Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class 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 (c) 2000-2005 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                 OGRE_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);
00200         
00202         RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 
00203             bool fullScreen, const NameValuePairList *miscParams = 0);
00204 
00206         RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height,
00207             TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8, 
00208             const NameValuePairList *miscParams = 0 ); 
00209 
00213         void destroyRenderWindow(RenderWindow* pWin);
00214 
00218         String getErrorDescription(long errorNumber) const;
00219 
00223         void convertColourValue(const ColourValue& colour, uint32* pDest);
00224 
00225         // -----------------------------
00226         // Low-level overridden members
00227         // -----------------------------
00231         void _useLights(const LightList& lights, unsigned short limit);
00235         void _setWorldMatrix(const Matrix4 &m);
00239         void _setViewMatrix(const Matrix4 &m);
00243         void _setProjectionMatrix(const Matrix4 &m);
00247         void _setSurfaceParams(const ColourValue &ambient,
00248             const ColourValue &diffuse, const ColourValue &specular,
00249             const ColourValue &emissive, Real shininess, TrackVertexColourType tracking);
00253         void _setTexture(size_t unit, bool enabled, const String &texname);
00257         void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm);
00261         void _setTextureAddressingMode(size_t unit, TextureUnitState::TextureAddressingMode tam);
00265         void _setTextureMatrix(size_t unit, const Matrix4& xform);
00269         void _setTextureCoordSet( size_t unit, size_t index );
00273         void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m, 
00274             const Frustum* frustum = 0);
00278         void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor);
00282         void _setAlphaRejectSettings(CompareFunction func, unsigned char value);
00286         void _setViewport(Viewport *vp);
00290         void _beginFrame(void);
00294         void _render(const RenderOperation& op);
00298         void _endFrame(void);
00302         void _setCullingMode(CullingMode mode);
00306         void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
00310         void _setDepthBufferCheckEnabled(bool enabled = true);
00314         void _setDepthBufferWriteEnabled(bool enabled = true);
00318         void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
00322         void _setDepthBias(ushort bias);
00329         void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
00330         
00334         void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
00338         void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, 
00339             Real farPlane, Matrix4& dest, bool forGpuProgram = false);
00343         void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
00344             Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
00348         void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
00349             Matrix4& dest, bool forGpuProgram = false);
00353         void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 
00354             bool forGpuProgram);
00358         void _setRasterisationMode(SceneDetailLevel level);
00362         void setStencilCheckEnabled(bool enabled);
00366         void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
00367             uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 
00368             StencilOperation stencilFailOp = SOP_KEEP, 
00369             StencilOperation depthFailOp = SOP_KEEP,
00370             StencilOperation passOp = SOP_KEEP, 
00371             bool twoSidedOperation = false);
00372         void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
00376         void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
00380         void setVertexDeclaration(VertexDeclaration* decl);
00384         void setVertexBufferBinding(VertexBufferBinding* binding);
00388         void setNormaliseNormals(bool normalise);
00392         void bindGpuProgram(GpuProgram* prg) { /* do nothing */}
00396         void unbindGpuProgram(GpuProgramType gptype){ /* do nothing */}
00400         void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params) { /* do nothing */}    
00404         void setClipPlanes(const PlaneList& clipPlanes);
00408         void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600)
00409         { /* do nothing, d3d7 does not support scissor rect */ }
00413         void clearFrameBuffer(unsigned int buffers, 
00414             const ColourValue& colour = ColourValue::Black, 
00415             Real depth = 1.0f, unsigned short stencil = 0);
00416 
00417         void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
00418         void enableClipPlane (ushort index, bool enable);
00422         HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
00423         Real getHorizontalTexelOffset(void);
00424         Real getVerticalTexelOffset(void);
00425         Real getMinimumDepthInputValue(void);
00426         Real getMaximumDepthInputValue(void);
00427         // ----------------------------------
00428         // End Overridden members
00429         // ----------------------------------
00430     };
00431 }
00432 #endif
00433 

Copyright © 2000-2005 by The OGRE Team
Last modified Wed Feb 23 00:19:04 2005