# 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-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028 #ifndef __RenderSystem_H_
    00029 #define __RenderSystem_H_
    00030
    00031 // Precompiler options
    00032 #include "OgrePrerequisites.h"
    00033
    00034 #include "OgreString.h"
    00035
    00036 #include "OgreTextureUnitState.h"
    00037 #include "OgreCommon.h"
    00038
    00039 #include "OgreRenderOperation.h"
    00040 #include "OgreRenderSystemCapabilities.h"
    00041 #include "OgreRenderTarget.h"
    00042 #include "OgreRenderTexture.h"
    00043 #include "OgreFrameListener.h"
    00044 #include "OgreConfigOptionMap.h"
    00045 #include "OgreGpuProgram.h"
    00046 #include "OgrePlane.h"
    00047 #include "OgreIteratorWrappers.h"
    00048
    00049 namespace Ogre
    00050 {
    00058     typedef map< String, RenderTarget * >::type RenderTargetMap;
    00059     typedef multimap<uchar, RenderTarget * >::type RenderTargetPriorityMap;
    00060
    00061     class TextureManager;
    00063     enum TexCoordCalcMethod
    00064     {
    00066         TEXCALC_NONE,
    00068         TEXCALC_ENVIRONMENT_MAP,
    00070         TEXCALC_ENVIRONMENT_MAP_PLANAR,
    00071         TEXCALC_ENVIRONMENT_MAP_REFLECTION,
    00072         TEXCALC_ENVIRONMENT_MAP_NORMAL,
    00074         TEXCALC_PROJECTIVE_TEXTURE
    00075     };
    00077     enum StencilOperation
    00078     {
    00080         SOP_KEEP,
    00082         SOP_ZERO,
    00084         SOP_REPLACE,
    00086         SOP_INCREMENT,
    00088         SOP_DECREMENT,
    00090         SOP_INCREMENT_WRAP,
    00092         SOP_DECREMENT_WRAP,
    00094         SOP_INVERT
    00095     };
    00096
    00097
    00121     class _OgreExport RenderSystem : public RenderSysAlloc
    00122     {
    00123     public:
    00126         RenderSystem();
    00127
    00130         virtual ~RenderSystem();
    00131
    00134         virtual const String& getName(void) const = 0;
    00135
    00157         virtual ConfigOptionMap& getConfigOptions(void) = 0;
    00158
    00178         virtual void setConfigOption(const String &name, const String &value) = 0;
    00179
    00182         virtual HardwareOcclusionQuery* createHardwareOcclusionQuery(void) = 0;
    00183
    00186         virtual void destroyHardwareOcclusionQuery(HardwareOcclusionQuery *hq);
    00187
    00192         virtual String validateConfigOptions(void) = 0;
    00193
    00210         virtual RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
    00211
    00212
    00214         virtual RenderSystemCapabilities* createRenderSystemCapabilities() const = 0;
    00215
    00222         virtual void useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities);
    00223
    00226         virtual void reinitialise(void) = 0;
    00227
    00230         virtual void shutdown(void);
    00231
    00232
    00235         virtual void setAmbientLight(float r, float g, float b) = 0;
    00236
    00239         virtual void setShadingType(ShadeOptions so) = 0;
    00240
    00246         virtual void setLightingEnabled(bool enabled) = 0;
    00247
    00254         void setWBufferEnabled(bool enabled);
    00255
    00258         bool getWBufferEnabled(void) const;
    00259
    00466         virtual RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
    00467             bool fullScreen, const NameValuePairList *miscParams = 0) = 0;
    00468
    00484         virtual bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
    00485             RenderWindowList& createdWindows);
    00486
    00487
    00492         virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0;
    00493
    00495         virtual void destroyRenderWindow(const String& name);
    00497         virtual void destroyRenderTexture(const String& name);
    00499         virtual void destroyRenderTarget(const String& name);
    00500
    00503         virtual void attachRenderTarget( RenderTarget &target );
    00507         virtual RenderTarget * getRenderTarget( const String &name );
    00513         virtual RenderTarget * detachRenderTarget( const String &name );
    00514
    00516         typedef MapIterator<Ogre::RenderTargetMap> RenderTargetIterator;
    00517
    00519         virtual RenderTargetIterator getRenderTargetIterator(void) {
    00520             return RenderTargetIterator( mRenderTargets.begin(), mRenderTargets.end() );
    00521         }
    00524         virtual String getErrorDescription(long errorNumber) const = 0;
    00525
    00539         void setWaitForVerticalBlank(bool enabled);
    00540
    00543         bool getWaitForVerticalBlank(void) const;
    00544
    00545         // ------------------------------------------------------------------------
    00546         //                     Internal Rendering Access
    00547         // All methods below here are normally only called by other OGRE classes
    00548         // They can be called by library user if required
    00549         // ------------------------------------------------------------------------
    00550
    00551
    00555         virtual void _useLights(const LightList& lights, unsigned short limit) = 0;
    00558         virtual bool areFixedFunctionLightsInViewSpace() const { return false; }
    00560         virtual void _setWorldMatrix(const Matrix4 &m) = 0;
    00562         virtual void _setWorldMatrices(const Matrix4* m, unsigned short count);
    00564         virtual void _setViewMatrix(const Matrix4 &m) = 0;
    00566         virtual void _setProjectionMatrix(const Matrix4 &m) = 0;
    00572         virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl);
    00574         virtual void _disableTextureUnit(size_t texUnit);
    00576         virtual void _disableTextureUnitsFrom(size_t texUnit);
    00610         virtual void _setSurfaceParams(const ColourValue &ambient,
    00611             const ColourValue &diffuse, const ColourValue &specular,
    00612             const ColourValue &emissive, Real shininess,
    00613             TrackVertexColourType tracking = TVC_NONE) = 0;
    00614
    00620         virtual void _setPointSpritesEnabled(bool enabled) = 0;
    00621
    00632         virtual void _setPointParameters(Real size, bool attenuationEnabled,
    00633             Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) = 0;
    00634
    00635
    00648         virtual void _setTexture(size_t unit, bool enabled,
    00649             const TexturePtr &texPtr) = 0;
    00663         virtual void _setTexture(size_t unit, bool enabled, const String &texname);
    00664
    00674         virtual void _setVertexTexture(size_t unit, const TexturePtr& tex);
    00675
    00685         virtual void _setTextureCoordSet(size_t unit, size_t index) = 0;
    00686
    00694         virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
    00695             const Frustum* frustum = 0) = 0;
    00696
    00703         virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) = 0;
    00704
    00711         virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
    00712             FilterOptions magFilter, FilterOptions mipFilter);
    00713
    00719         virtual void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0;
    00720
    00722         virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
    00723
    00725         virtual void _setTextureAddressingMode(size_t unit, const TextureUnitState::UVWAddressingMode& uvw) = 0;
    00726
    00728         virtual void _setTextureBorderColour(size_t unit, const ColourValue& colour) = 0;
    00729
    00738         virtual void _setTextureMipmapBias(size_t unit, float bias) = 0;
    00739
    00744         virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) = 0;
    00745
    00756         virtual void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD) = 0;
    00757
    00770         virtual void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha,
    00771             SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD) = 0;
    00772
    00779         virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
    00780
    00784         virtual void _setTextureProjectionRelativeTo(bool enabled, const Vector3& pos);
    00789         virtual void _beginFrame(void) = 0;
    00790
    00791         //Dummy structure for render system contexts - implementing RenderSystems can extend
    00792         //as needed
    00793         struct RenderSystemContext { };
    00799         virtual RenderSystemContext* _pauseFrame(void);
    00806         virtual void _resumeFrame(RenderSystemContext* context);
    00807
    00811         virtual void _endFrame(void) = 0;
    00819         virtual void _setViewport(Viewport *vp) = 0;
    00821         virtual Viewport* _getViewport(void);
    00822
    00834         virtual void _setCullingMode(CullingMode mode) = 0;
    00835
    00836         virtual CullingMode _getCullingMode(void) const;
    00837
    00851         virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
    00852
    00857         virtual void _setDepthBufferCheckEnabled(bool enabled = true) = 0;
    00862         virtual void _setDepthBufferWriteEnabled(bool enabled = true) = 0;
    00870         virtual void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
    00878         virtual void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
    00901         virtual void _setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0;
    00913         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;
    00914
    00915
    00917         virtual void _beginGeometryCount(void);
    00919         virtual unsigned int _getFaceCount(void) const;
    00921         virtual unsigned int _getBatchCount(void) const;
    00923         virtual unsigned int _getVertexCount(void) const;
    00924
    00933         virtual void convertColourValue(const ColourValue& colour, uint32* pDest);
    00937         virtual VertexElementType getColourVertexElementType(void) const = 0;
    00938
    00945         virtual void _convertProjectionMatrix(const Matrix4& matrix,
    00946             Matrix4& dest, bool forGpuProgram = false) = 0;
    00947
    00954         virtual void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
    00955             Matrix4& dest, bool forGpuProgram = false) = 0;
    00956
    00963         virtual void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
    00964             Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false) = 0;
    00971         virtual void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
    00972             Matrix4& dest, bool forGpuProgram = false) = 0;
    00973
    00990         virtual void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
    00991             bool forGpuProgram) = 0;
    00992
    00994         virtual void _setPolygonMode(PolygonMode level) = 0;
    00995
    01002         virtual void setStencilCheckEnabled(bool enabled) = 0;
    01018         /*virtual bool hasHardwareStencil(void) = 0;*/
    01019
    01055         virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
    01056             uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
    01057             StencilOperation stencilFailOp = SOP_KEEP,
    01058             StencilOperation depthFailOp = SOP_KEEP,
    01059             StencilOperation passOp = SOP_KEEP,
    01060             bool twoSidedOperation = false) = 0;
    01061
    01062
    01063
    01065         virtual void setVertexDeclaration(VertexDeclaration* decl) = 0;
    01067         virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
    01068
    01079         virtual void setNormaliseNormals(bool normalise) = 0;
    01080
    01093         virtual void _render(const RenderOperation& op);
    01094
    01096         const RenderSystemCapabilities* getCapabilities(void) const { return mCurrentCapabilities; }
    01097
    01098
    01101         virtual const DriverVersion& getDriverVersion(void) const { return mDriverVersion; }
    01102
    01107         virtual void bindGpuProgram(GpuProgram* prg);
    01108
    01114         virtual void bindGpuProgramParameters(GpuProgramType gptype,
    01115             GpuProgramParametersSharedPtr params, uint16 variabilityMask) = 0;
    01116
    01119         virtual void bindGpuProgramPassIterationParameters(GpuProgramType gptype) = 0;
    01124         virtual void unbindGpuProgram(GpuProgramType gptype);
    01125
    01127         virtual bool isGpuProgramBound(GpuProgramType gptype);
    01128
    01131         virtual void setClipPlanes(const PlaneList& clipPlanes);
    01132
    01134         virtual void addClipPlane (const Plane &p);
    01136         virtual void addClipPlane (Real A, Real B, Real C, Real D);
    01137
    01140         virtual void resetClipPlanes();
    01141
    01143         virtual void _initRenderTargets(void);
    01144
    01148         virtual void _notifyCameraRemoved(const Camera* cam);
    01149
    01151         virtual void _updateAllRenderTargets(bool swapBuffers = true);
    01154         virtual void _swapAllRenderTargetBuffers(bool waitForVsync = true);
    01155
    01158         virtual bool getInvertVertexWinding(void);
    01159
    01162         virtual void setInvertVertexWinding(bool invert);
    01163
    01167         virtual bool getVertexWindingInverted(void) const;
    01168
    01180         virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0,
    01181             size_t right = 800, size_t bottom = 600) = 0;
    01182
    01190         virtual void clearFrameBuffer(unsigned int buffers,
    01191             const ColourValue& colour = ColourValue::Black,
    01192             Real depth = 1.0f, unsigned short stencil = 0) = 0;
    01202         virtual Real getHorizontalTexelOffset(void) = 0;
    01212         virtual Real getVerticalTexelOffset(void) = 0;
    01213
    01222         virtual Real getMinimumDepthInputValue(void) = 0;
    01231         virtual Real getMaximumDepthInputValue(void) = 0;
    01237         virtual void setCurrentPassIterationCount(const size_t count) { mCurrentPassIterationCount = count; }
    01238
    01248         virtual void setDeriveDepthBias(bool derive, float baseValue = 0.0f,
    01249             float multiplier = 0.0f, float slopeScale = 0.0f)
    01250         {
    01251             mDerivedDepthBias = derive;
    01252             mDerivedDepthBiasBase = baseValue;
    01253             mDerivedDepthBiasMultiplier = multiplier;
    01254             mDerivedDepthBiasSlopeScale = slopeScale;
    01255         }
    01256
    01260         virtual void _setRenderTarget(RenderTarget *target) = 0;
    01261
    01266         class _OgreExport Listener
    01267         {
    01268         public:
    01269             Listener() {}
    01270             virtual ~Listener() {}
    01271
    01277             virtual void eventOccurred(const String& eventName,
    01278                 const NameValuePairList* parameters = 0) = 0;
    01279         };
    01293         virtual void addListener(Listener* l);
    01296         virtual void removeListener(Listener* l);
    01297
    01302         virtual const StringVector& getRenderSystemEvents(void) const { return mEventNames; }
    01303
    01320         virtual void preExtraThreadsStarted() = 0;
    01321
    01322         /* Tell the rendersystem to perform any tasks it needs to directly
    01323         after other threads which might access the rendering API are registered.
    01324         @see RenderSystem::preExtraThreadsStarted
    01325         */
    01326         virtual void postExtraThreadsStarted() = 0;
    01327
    01340         virtual void registerThread() = 0;
    01341
    01345         virtual void unregisterThread() = 0;
    01346
    01351         virtual unsigned int getDisplayMonitorCount() const = 0;
    01352     protected:
    01353
    01354
    01356         RenderTargetMap mRenderTargets;
    01358         RenderTargetPriorityMap mPrioritisedRenderTargets;
    01360         RenderTarget * mActiveRenderTarget;
    01362         GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters;
    01363         GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters;
    01364         GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters;
    01365
    01366         // Texture manager
    01367         // A concrete class of this will be created and
    01368         // made available under the TextureManager singleton,
    01369         // managed by the RenderSystem
    01370         TextureManager* mTextureManager;
    01371
    01372         // Active viewport (dest for future rendering operations)
    01373         Viewport* mActiveViewport;
    01374
    01375         CullingMode mCullingMode;
    01376
    01377         bool mVSync;
    01378         unsigned int mVSyncInterval;
    01379         bool mWBuffer;
    01380
    01381         size_t mBatchCount;
    01382         size_t mFaceCount;
    01383         size_t mVertexCount;
    01384
    01386         ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2];
    01387
    01388         bool mInvertVertexWinding;
    01389
    01391         size_t mDisabledTexUnitsFrom;
    01392
    01394         size_t mCurrentPassIterationCount;
    01395         size_t mCurrentPassIterationNum;
    01397         bool mDerivedDepthBias;
    01398         float mDerivedDepthBiasBase;
    01399         float mDerivedDepthBiasMultiplier;
    01400         float mDerivedDepthBiasSlopeScale;
    01401
    01406         bool updatePassIterationRenderState(void);
    01407
    01409         StringVector mEventNames;
    01410
    01412         virtual void fireEvent(const String& name, const NameValuePairList* params = 0);
    01413
    01414         typedef list<Listener*>::type ListenerList;
    01415         ListenerList mEventListeners;
    01416
    01417         typedef list<HardwareOcclusionQuery*>::type HardwareOcclusionQueryList;
    01418         HardwareOcclusionQueryList mHwOcclusionQueries;
    01419
    01420         bool mVertexProgramBound;
    01421         bool mGeometryProgramBound;
    01422         bool mFragmentProgramBound;
    01423
    01424         // Recording user clip planes
    01425         PlaneList mClipPlanes;
    01426         // Indicator that we need to re-set the clip planes on next render call
    01427         bool mClipPlanesDirty;
    01428
    01430         RenderSystemCapabilities* mRealCapabilities;
    01431         RenderSystemCapabilities* mCurrentCapabilities;
    01432         bool mUseCustomCapabilities;
    01433
    01435         virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0;
    01436
    01438         virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0;
    01439
    01440
    01441         DriverVersion mDriverVersion;
    01442
    01443         bool mTexProjRelative;
    01444         Vector3 mTexProjRelativeOrigin;
    01445
    01446
    01447
    01448     };
    01451 }
    01452
    01453 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52