# OgreRenderSystem.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://www.ogre3d.org
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    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 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __RenderSystem_H_
    00030 #define __RenderSystem_H_
    00031
    00032 // Precompiler options
    00033 #include "OgrePrerequisites.h"
    00034
    00035 #include "OgreString.h"
    00036
    00037 #include "OgreTextureUnitState.h"
    00038 #include "OgreCommon.h"
    00039
    00040 #include "OgreRenderOperation.h"
    00041 #include "OgreRenderSystemCapabilities.h"
    00042 #include "OgreRenderTarget.h"
    00043 #include "OgreRenderTexture.h"
    00044 #include "OgreFrameListener.h"
    00045 #include "OgreConfigOptionMap.h"
    00046 #include "OgreGpuProgram.h"
    00047 #include "OgrePlane.h"
    00048 #include "OgreIteratorWrappers.h"
    00049
    00050 namespace Ogre
    00051 {
    00052     typedef std::map< String, RenderTarget * > RenderTargetMap;
    00053     typedef std::multimap<uchar, RenderTarget * > RenderTargetPriorityMap;
    00054
    00055     class TextureManager;
    00057     enum TexCoordCalcMethod
    00058     {
    00060         TEXCALC_NONE,
    00062         TEXCALC_ENVIRONMENT_MAP,
    00064         TEXCALC_ENVIRONMENT_MAP_PLANAR,
    00065         TEXCALC_ENVIRONMENT_MAP_REFLECTION,
    00066         TEXCALC_ENVIRONMENT_MAP_NORMAL,
    00068         TEXCALC_PROJECTIVE_TEXTURE
    00069     };
    00071     enum StencilOperation
    00072     {
    00074         SOP_KEEP,
    00076         SOP_ZERO,
    00078         SOP_REPLACE,
    00080         SOP_INCREMENT,
    00082         SOP_DECREMENT,
    00084         SOP_INCREMENT_WRAP,
    00086         SOP_DECREMENT_WRAP,
    00088         SOP_INVERT
    00089     };
    00090
    00091
    00115     class _OgreExport RenderSystem : public RenderSysAlloc
    00116     {
    00117     public:
    00120         RenderSystem();
    00121
    00124         virtual ~RenderSystem();
    00125
    00128         virtual const String& getName(void) const = 0;
    00129
    00151         virtual ConfigOptionMap& getConfigOptions(void) = 0;
    00152
    00172         virtual void setConfigOption(const String &name, const String &value) = 0;
    00173
    00176         virtual HardwareOcclusionQuery* createHardwareOcclusionQuery(void) = 0;
    00177
    00180         virtual void destroyHardwareOcclusionQuery(HardwareOcclusionQuery *hq);
    00181
    00186         virtual String validateConfigOptions(void) = 0;
    00187
    00204         virtual RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
    00205
    00206
    00208         virtual RenderSystemCapabilities* createRenderSystemCapabilities() const = 0;
    00209
    00216         virtual void useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities);
    00217
    00220         virtual void reinitialise(void) = 0;
    00221
    00224         virtual void shutdown(void);
    00225
    00226
    00229         virtual void setAmbientLight(float r, float g, float b) = 0;
    00230
    00233         virtual void setShadingType(ShadeOptions so) = 0;
    00234
    00240         virtual void setLightingEnabled(bool enabled) = 0;
    00241
    00248         void setWBufferEnabled(bool enabled);
    00249
    00252         bool getWBufferEnabled(void) const;
    00253
    00378         virtual RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
    00379             bool fullScreen, const NameValuePairList *miscParams = 0) = 0;
    00380
    00385         virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0;
    00386
    00388         virtual void destroyRenderWindow(const String& name);
    00390         virtual void destroyRenderTexture(const String& name);
    00392         virtual void destroyRenderTarget(const String& name);
    00393
    00396         virtual void attachRenderTarget( RenderTarget &target );
    00400         virtual RenderTarget * getRenderTarget( const String &name );
    00406         virtual RenderTarget * detachRenderTarget( const String &name );
    00407
    00409         typedef MapIterator<Ogre::RenderTargetMap> RenderTargetIterator;
    00410
    00412         virtual RenderTargetIterator getRenderTargetIterator(void) {
    00413             return RenderTargetIterator( mRenderTargets.begin(), mRenderTargets.end() );
    00414         }
    00417         virtual String getErrorDescription(long errorNumber) const = 0;
    00418
    00432         void setWaitForVerticalBlank(bool enabled);
    00433
    00436         bool getWaitForVerticalBlank(void) const;
    00437
    00438         // ------------------------------------------------------------------------
    00439         //                     Internal Rendering Access
    00440         // All methods below here are normally only called by other OGRE classes
    00441         // They can be called by library user if required
    00442         // ------------------------------------------------------------------------
    00443
    00444
    00448         virtual void _useLights(const LightList& lights, unsigned short limit) = 0;
    00450         virtual void _setWorldMatrix(const Matrix4 &m) = 0;
    00452         virtual void _setWorldMatrices(const Matrix4* m, unsigned short count);
    00454         virtual void _setViewMatrix(const Matrix4 &m) = 0;
    00456         virtual void _setProjectionMatrix(const Matrix4 &m) = 0;
    00462         virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl);
    00464         virtual void _disableTextureUnit(size_t texUnit);
    00466         virtual void _disableTextureUnitsFrom(size_t texUnit);
    00500         virtual void _setSurfaceParams(const ColourValue &ambient,
    00501             const ColourValue &diffuse, const ColourValue &specular,
    00502             const ColourValue &emissive, Real shininess,
    00503             TrackVertexColourType tracking = TVC_NONE) = 0;
    00504
    00510         virtual void _setPointSpritesEnabled(bool enabled) = 0;
    00511
    00522         virtual void _setPointParameters(Real size, bool attenuationEnabled,
    00523             Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) = 0;
    00524
    00525
    00538         virtual void _setTexture(size_t unit, bool enabled,
    00539             const TexturePtr &texPtr) = 0;
    00553         virtual void _setTexture(size_t unit, bool enabled, const String &texname);
    00554
    00564         virtual void _setVertexTexture(size_t unit, const TexturePtr& tex);
    00565
    00575         virtual void _setTextureCoordSet(size_t unit, size_t index) = 0;
    00576
    00584         virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
    00585             const Frustum* frustum = 0) = 0;
    00586
    00593         virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) = 0;
    00594
    00601         virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
    00602             FilterOptions magFilter, FilterOptions mipFilter);
    00603
    00609         virtual void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0;
    00610
    00612         virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
    00613
    00615         virtual void _setTextureAddressingMode(size_t unit, const TextureUnitState::UVWAddressingMode& uvw) = 0;
    00616
    00618         virtual void _setTextureBorderColour(size_t unit, const ColourValue& colour) = 0;
    00619
    00628         virtual void _setTextureMipmapBias(size_t unit, float bias) = 0;
    00629
    00634         virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) = 0;
    00635
    00644         virtual void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor) = 0;
    00645
    00656         virtual void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha) = 0;
    00657
    00664         virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
    00665
    00669         virtual void _setTextureProjectionRelativeTo(bool enabled, const Vector3& pos);
    00674         virtual void _beginFrame(void) = 0;
    00675
    00676
    00680         virtual void _endFrame(void) = 0;
    00688         virtual void _setViewport(Viewport *vp) = 0;
    00690         virtual Viewport* _getViewport(void);
    00691
    00703         virtual void _setCullingMode(CullingMode mode) = 0;
    00704
    00705         virtual CullingMode _getCullingMode(void) const;
    00706
    00720         virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
    00721
    00726         virtual void _setDepthBufferCheckEnabled(bool enabled = true) = 0;
    00731         virtual void _setDepthBufferWriteEnabled(bool enabled = true) = 0;
    00739         virtual void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
    00747         virtual void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
    00770         virtual void _setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0;
    00782         virtual void _setFog(FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0) = 0;
    00783
    00784
    00786         virtual void _beginGeometryCount(void);
    00788         virtual unsigned int _getFaceCount(void) const;
    00790         virtual unsigned int _getBatchCount(void) const;
    00792         virtual unsigned int _getVertexCount(void) const;
    00793
    00802         virtual void convertColourValue(const ColourValue& colour, uint32* pDest);
    00806         virtual VertexElementType getColourVertexElementType(void) const = 0;
    00807
    00814         virtual void _convertProjectionMatrix(const Matrix4& matrix,
    00815             Matrix4& dest, bool forGpuProgram = false) = 0;
    00816
    00823         virtual void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
    00824             Matrix4& dest, bool forGpuProgram = false) = 0;
    00825
    00832         virtual void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
    00833             Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false) = 0;
    00840         virtual void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
    00841             Matrix4& dest, bool forGpuProgram = false) = 0;
    00842
    00859         virtual void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
    00860             bool forGpuProgram) = 0;
    00861
    00863         virtual void _setPolygonMode(PolygonMode level) = 0;
    00864
    00871         virtual void setStencilCheckEnabled(bool enabled) = 0;
    00887         /*virtual bool hasHardwareStencil(void) = 0;*/
    00888
    00924         virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
    00925             uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
    00926             StencilOperation stencilFailOp = SOP_KEEP,
    00927             StencilOperation depthFailOp = SOP_KEEP,
    00928             StencilOperation passOp = SOP_KEEP,
    00929             bool twoSidedOperation = false) = 0;
    00930
    00931
    00932
    00934         virtual void setVertexDeclaration(VertexDeclaration* decl) = 0;
    00936         virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
    00937
    00948         virtual void setNormaliseNormals(bool normalise) = 0;
    00949
    00962         virtual void _render(const RenderOperation& op);
    00963
    00965         const RenderSystemCapabilities* getCapabilities(void) const { return mCurrentCapabilities; }
    00966
    00967
    00970         virtual const DriverVersion& getDriverVersion(void) const { return mDriverVersion; }
    00971
    00976         virtual void bindGpuProgram(GpuProgram* prg);
    00977
    00980         virtual void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params) = 0;
    00983         virtual void bindGpuProgramPassIterationParameters(GpuProgramType gptype) = 0;
    00988         virtual void unbindGpuProgram(GpuProgramType gptype);
    00989
    00991         virtual bool isGpuProgramBound(GpuProgramType gptype);
    00992
    00995         virtual void setClipPlanes(const PlaneList& clipPlanes);
    00996
    00998         virtual void addClipPlane (const Plane &p);
    01000         virtual void addClipPlane (Real A, Real B, Real C, Real D);
    01001
    01004         virtual void resetClipPlanes();
    01005
    01007         virtual void _initRenderTargets(void);
    01008
    01012         virtual void _notifyCameraRemoved(const Camera* cam);
    01013
    01015         virtual void _updateAllRenderTargets(bool swapBuffers = true);
    01018         virtual void _swapAllRenderTargetBuffers(bool waitForVsync = true);
    01019
    01022         virtual void setInvertVertexWinding(bool invert);
    01034         virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0,
    01035             size_t right = 800, size_t bottom = 600) = 0;
    01036
    01044         virtual void clearFrameBuffer(unsigned int buffers,
    01045             const ColourValue& colour = ColourValue::Black,
    01046             Real depth = 1.0f, unsigned short stencil = 0) = 0;
    01056         virtual Real getHorizontalTexelOffset(void) = 0;
    01066         virtual Real getVerticalTexelOffset(void) = 0;
    01067
    01076         virtual Real getMinimumDepthInputValue(void) = 0;
    01085         virtual Real getMaximumDepthInputValue(void) = 0;
    01091         virtual void setCurrentPassIterationCount(const size_t count) { mCurrentPassIterationCount = count; }
    01092
    01102         virtual void setDeriveDepthBias(bool derive, float baseValue = 0.0f,
    01103             float multiplier = 0.0f, float slopeScale = 0.0f)
    01104         {
    01105             mDerivedDepthBias = derive;
    01106             mDerivedDepthBiasBase = baseValue;
    01107             mDerivedDepthBiasMultiplier = multiplier;
    01108             mDerivedDepthBiasSlopeScale = slopeScale;
    01109         }
    01110
    01115         class _OgreExport Listener
    01116         {
    01117         public:
    01118             Listener() {}
    01119             virtual ~Listener() {}
    01120
    01126             virtual void eventOccurred(const String& eventName,
    01127                 const NameValuePairList* parameters = 0) = 0;
    01128         };
    01142         virtual void addListener(Listener* l);
    01145         virtual void removeListener(Listener* l);
    01146
    01151         virtual const StringVector& getRenderSystemEvents(void) const { return mEventNames; }
    01152
    01169         virtual void preExtraThreadsStarted() = 0;
    01170
    01171         /* Tell the rendersystem to perform any tasks it needs to directly
    01172         after other threads which might access the rendering API are registered.
    01173         @see RenderSystem::preExtraThreadsStarted
    01174         */
    01175         virtual void postExtraThreadsStarted() = 0;
    01176
    01189         virtual void registerThread() = 0;
    01190
    01194         virtual void unregisterThread() = 0;
    01195     protected:
    01196
    01197
    01199         RenderTargetMap mRenderTargets;
    01201         RenderTargetPriorityMap mPrioritisedRenderTargets;
    01203         RenderTarget * mActiveRenderTarget;
    01205         GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters;
    01206         GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters;
    01207         GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters;
    01208
    01209         // Texture manager
    01210         // A concrete class of this will be created and
    01211         // made available under the TextureManager singleton,
    01212         // managed by the RenderSystem
    01213         TextureManager* mTextureManager;
    01214
    01215         // Active viewport (dest for future rendering operations)
    01216         Viewport* mActiveViewport;
    01217
    01218         CullingMode mCullingMode;
    01219
    01220         bool mVSync;
    01221         bool mWBuffer;
    01222
    01223         size_t mBatchCount;
    01224         size_t mFaceCount;
    01225         size_t mVertexCount;
    01226
    01228         ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2];
    01229
    01230         bool mInvertVertexWinding;
    01231
    01233         size_t mDisabledTexUnitsFrom;
    01234
    01236         size_t mCurrentPassIterationCount;
    01237         size_t mCurrentPassIterationNum;
    01239         bool mDerivedDepthBias;
    01240         float mDerivedDepthBiasBase;
    01241         float mDerivedDepthBiasMultiplier;
    01242         float mDerivedDepthBiasSlopeScale;
    01243
    01248         bool updatePassIterationRenderState(void);
    01249
    01251         StringVector mEventNames;
    01252
    01254         virtual void fireEvent(const String& name, const NameValuePairList* params = 0);
    01255
    01256         typedef std::list<Listener*> ListenerList;
    01257         ListenerList mEventListeners;
    01258
    01259         typedef std::list<HardwareOcclusionQuery*> HardwareOcclusionQueryList;
    01260         HardwareOcclusionQueryList mHwOcclusionQueries;
    01261
    01262         bool mVertexProgramBound;
    01263         bool mGeometryProgramBound;
    01264         bool mFragmentProgramBound;
    01265
    01266         // Recording user clip planes
    01267         PlaneList mClipPlanes;
    01268         // Indicator that we need to re-set the clip planes on next render call
    01269         bool mClipPlanesDirty;
    01270
    01272         RenderSystemCapabilities* mRealCapabilities;
    01273         RenderSystemCapabilities* mCurrentCapabilities;
    01274         bool mUseCustomCapabilities;
    01275
    01277         virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0;
    01278
    01280         virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0;
    01281
    01282
    01283         DriverVersion mDriverVersion;
    01284
    01285         bool mTexProjRelative;
    01286         Vector3 mTexProjRelativeOrigin;
    01287
    01288
    01289
    01290     };
    01291 }
    01292
    01293 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 11 14:26:45 2009