# 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         bool mDeviceLost;
    00062
    00063
    00064
    00065         // Stored options
    00066         ConfigOptionMap mOptions;
    00067
    00068         // Private utilities
    00069         DDDriverList* getDirectDrawDrivers(void);
    00070         void refreshDDSettings(void);
    00071
    00073         enum eD3DTexType
    00074         {
    00076             D3D_TEX_TYPE_NORMAL,
    00078             D3D_TEX_TYPE_CUBE,
    00080             D3D_TEX_TYPE_VOLUME
    00081         };
    00082
    00084         eD3DTexType _ogreTexTypeToD3DTexType(TextureType ogreTexType)
    00085         {
    00086             eD3DTexType ret;
    00087             switch (ogreTexType)
    00088             {
    00089             case TEX_TYPE_1D :
    00090             case TEX_TYPE_2D :
    00091                 ret = D3D_TEX_TYPE_NORMAL;
    00092                 break;
    00093             case TEX_TYPE_CUBE_MAP :
    00094                 ret = D3D_TEX_TYPE_CUBE;
    00095                 break;
    00096             default :
    00097                 OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, "Invalid tex.type", "D3D9RenderSystem::_ogreTexTypeToD3DTexType" );
    00098                 break;
    00099             }
    00100             return ret;
    00101         }
    00102
    00104         struct sD3DTextureStageDesc
    00105         {
    00107             eD3DTexType texType;
    00109             size_t coordIndex;
    00111             TexCoordCalcMethod autoTexCoordType;
    00113             const Frustum* frustum;
    00115             LPDIRECTDRAWSURFACE7 pTex;
    00116         } mTexStageDesc[OGRE_MAX_TEXTURE_LAYERS];
    00117
    00118
    00119         // Matrix conversion
    00120         D3DMATRIX makeD3DMatrix(const Matrix4& mat);
    00121         Matrix4 convertD3DMatrix(const D3DMATRIX& mat);
    00122
    00123         void initConfigOptions(void);
    00124         void initInputDevices(void);
    00125         void processInputDevices(void);
    00126         void setD3DLight(size_t index, Light* light);
    00127
    00128         D3DCMPFUNC convertCompareFunction(CompareFunction func);
    00129         D3DSTENCILOP convertStencilOp(StencilOperation op);
    00130
    00131         // state management methods, very primitive !!!
    00132         HRESULT __SetRenderState(D3DRENDERSTATETYPE state, DWORD value);
    00133         HRESULT __SetTextureStageState(DWORD stage, D3DTEXTURESTAGESTATETYPE type, DWORD value);
    00134
    00135
    00136         D3DTEXTURESTAGESTATETYPE _getFilterCode(FilterType ft) const;
    00137         DWORD _getFilter(FilterType ft, FilterOptions fo) const;
    00138         DWORD _getCurrentAnisotropy(size_t unit);
    00139
    00140         HardwareBufferManager* mHardwareBufferManager;
    00141         GpuProgramManager* mGpuProgramManager;
    00142
    00143
    00144         unsigned short mCurrentLights;
    00145         Matrix4 mViewMatrix;
    00146         // saved scene blending factors
    00147         SceneBlendFactor mSavedSrcFactor, mSavedDestFactor;
    00148
    00149
    00150     public:
    00151         // Default constructor / destructor
    00152         D3DRenderSystem(HINSTANCE hInstance);
    00153         ~D3DRenderSystem();
    00154
    00155
    00156
    00157         // ----------------------------------
    00158         // Overridden RenderSystem functions
    00159         // ----------------------------------
    00163         const String& getName(void) const;
    00167         ConfigOptionMap& getConfigOptions(void);
    00171         void setConfigOption(const String &name, const String &value);
    00175         String validateConfigOptions(void);
    00179         RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
    00183         void reinitialise(void); // Used if settings changed mid-rendering
    00187         void shutdown(void);
    00188
    00192         void setAmbientLight(float r, float g, float b);
    00196         void setShadingType(ShadeOptions so);
    00200         void setLightingEnabled(bool enabled);
    00201
    00203         RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height,
    00204             bool fullScreen, const NameValuePairList *miscParams = 0);
    00205
    00207         RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height,
    00208             TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8,
    00209             const NameValuePairList *miscParams = 0 );
    00210
    00214         void destroyRenderWindow(RenderWindow* pWin);
    00215
    00219         String getErrorDescription(long errorNumber) const;
    00220
    00224         void convertColourValue(const ColourValue& colour, uint32* pDest);
    00225
    00227         void _notifyDeviceLost(void);
    00229         void _restoreLostDevice(void);
    00231         void _restoreSurfaces(void);
    00233         void _recreateContext(void);
    00234
    00235         // -----------------------------
    00236         // Low-level overridden members
    00237         // -----------------------------
    00241         void _useLights(const LightList& lights, unsigned short limit);
    00245         void _setWorldMatrix(const Matrix4 &m);
    00249         void _setViewMatrix(const Matrix4 &m);
    00253         void _setProjectionMatrix(const Matrix4 &m);
    00257         void _setSurfaceParams(const ColourValue &ambient,
    00258             const ColourValue &diffuse, const ColourValue &specular,
    00259             const ColourValue &emissive, Real shininess, TrackVertexColourType tracking);
    00263         void _setTexture(size_t unit, bool enabled, const String &texname);
    00267         void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm);
    00271         void _setTextureAddressingMode(size_t unit, TextureUnitState::TextureAddressingMode tam);
    00275         void _setTextureMatrix(size_t unit, const Matrix4& xform);
    00279         void _setTextureCoordSet( size_t unit, size_t index );
    00283         void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
    00284             const Frustum* frustum = 0);
    00288         void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor);
    00292         void _setAlphaRejectSettings(CompareFunction func, unsigned char value);
    00296         void _setViewport(Viewport *vp);
    00300         void _beginFrame(void);
    00304         void _render(const RenderOperation& op);
    00308         void _endFrame(void);
    00312         void _setCullingMode(CullingMode mode);
    00316         void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
    00320         void _setDepthBufferCheckEnabled(bool enabled = true);
    00324         void _setDepthBufferWriteEnabled(bool enabled = true);
    00328         void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
    00332         void _setDepthBias(ushort bias);
    00339         void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
    00340
    00344         void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
    00348         void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane,
    00349             Real farPlane, Matrix4& dest, bool forGpuProgram = false);
    00353         void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
    00354             Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
    00358         void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
    00359             Matrix4& dest, bool forGpuProgram = false);
    00363         void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
    00364             bool forGpuProgram);
    00368         void _setRasterisationMode(SceneDetailLevel level);
    00372         void setStencilCheckEnabled(bool enabled);
    00376         void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
    00377             uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
    00378             StencilOperation stencilFailOp = SOP_KEEP,
    00379             StencilOperation depthFailOp = SOP_KEEP,
    00380             StencilOperation passOp = SOP_KEEP,
    00381             bool twoSidedOperation = false);
    00382         void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
    00386         void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
    00390         void setVertexDeclaration(VertexDeclaration* decl);
    00394         void setVertexBufferBinding(VertexBufferBinding* binding);
    00398         void setNormaliseNormals(bool normalise);
    00402         void bindGpuProgram(GpuProgram* prg) { /* do nothing */}
    00406         void unbindGpuProgram(GpuProgramType gptype){ /* do nothing */}
    00410         void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params) { /* do nothing */}
    00414         void setClipPlanes(const PlaneList& clipPlanes);
    00418         void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600)
    00419         { /* do nothing, d3d7 does not support scissor rect */ }
    00423         void clearFrameBuffer(unsigned int buffers,
    00424             const ColourValue& colour = ColourValue::Black,
    00425             Real depth = 1.0f, unsigned short stencil = 0);
    00426
    00427         void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
    00428         void enableClipPlane (ushort index, bool enable);
    00432         HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
    00433         Real getHorizontalTexelOffset(void);
    00434         Real getVerticalTexelOffset(void);
    00435         Real getMinimumDepthInputValue(void);
    00436         Real getMaximumDepthInputValue(void);
    00437         // ----------------------------------
    00438         // End Overridden members
    00439         // ----------------------------------
    00440     };
    00441 }
    00442 #endif
    00443

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Nov 20 12:35:58 2005