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-2012 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 "OgreMaterialManager.h"
    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 {
    00059     typedef vector<DepthBuffer*>::type DepthBufferVec;
    00060     typedef map< uint16, DepthBufferVec >::type DepthBufferMap;
    00061     typedef map< String, RenderTarget * >::type RenderTargetMap;
    00062     typedef multimap<uchar, RenderTarget * >::type RenderTargetPriorityMap;
    00063
    00064     class TextureManager;
    00066     enum TexCoordCalcMethod
    00067     {
    00069         TEXCALC_NONE,
    00071         TEXCALC_ENVIRONMENT_MAP,
    00073         TEXCALC_ENVIRONMENT_MAP_PLANAR,
    00074         TEXCALC_ENVIRONMENT_MAP_REFLECTION,
    00075         TEXCALC_ENVIRONMENT_MAP_NORMAL,
    00077         TEXCALC_PROJECTIVE_TEXTURE
    00078     };
    00080     enum StencilOperation
    00081     {
    00083         SOP_KEEP,
    00085         SOP_ZERO,
    00087         SOP_REPLACE,
    00089         SOP_INCREMENT,
    00091         SOP_DECREMENT,
    00093         SOP_INCREMENT_WRAP,
    00095         SOP_DECREMENT_WRAP,
    00097         SOP_INVERT
    00098     };
    00099
    00100
    00124     class _OgreExport RenderSystem : public RenderSysAlloc
    00125     {
    00126     public:
    00129         RenderSystem();
    00130
    00133         virtual ~RenderSystem();
    00134
    00137         virtual const String& getName(void) const = 0;
    00138
    00160         virtual ConfigOptionMap& getConfigOptions(void) = 0;
    00161
    00181         virtual void setConfigOption(const String &name, const String &value) = 0;
    00182
    00185         virtual HardwareOcclusionQuery* createHardwareOcclusionQuery(void) = 0;
    00186
    00189         virtual void destroyHardwareOcclusionQuery(HardwareOcclusionQuery *hq);
    00190
    00195         virtual String validateConfigOptions(void) = 0;
    00196
    00213         virtual RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
    00214
    00215
    00217         virtual RenderSystemCapabilities* createRenderSystemCapabilities() const = 0;
    00218
    00226         RenderSystemCapabilities* getMutableCapabilities(){ return mCurrentCapabilities; }
    00227
    00234         virtual void useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities);
    00235
    00238         virtual void reinitialise(void) = 0;
    00239
    00242         virtual void shutdown(void);
    00243
    00244
    00247         virtual void setAmbientLight(float r, float g, float b) = 0;
    00248
    00251         virtual void setShadingType(ShadeOptions so) = 0;
    00252
    00258         virtual void setLightingEnabled(bool enabled) = 0;
    00259
    00266         void setWBufferEnabled(bool enabled);
    00267
    00270         bool getWBufferEnabled(void) const;
    00271
    00508         virtual RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
    00509             bool fullScreen, const NameValuePairList *miscParams = 0) = 0;
    00510
    00526         virtual bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
    00527             RenderWindowList& createdWindows);
    00528
    00529
    00534         virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0;
    00535
    00537         virtual void destroyRenderWindow(const String& name);
    00539         virtual void destroyRenderTexture(const String& name);
    00541         virtual void destroyRenderTarget(const String& name);
    00542
    00545         virtual void attachRenderTarget( RenderTarget &target );
    00549         virtual RenderTarget * getRenderTarget( const String &name );
    00555         virtual RenderTarget * detachRenderTarget( const String &name );
    00556
    00558         typedef MapIterator<Ogre::RenderTargetMap> RenderTargetIterator;
    00559
    00561         virtual RenderTargetIterator getRenderTargetIterator(void) {
    00562             return RenderTargetIterator( mRenderTargets.begin(), mRenderTargets.end() );
    00563         }
    00566         virtual String getErrorDescription(long errorNumber) const = 0;
    00567
    00581         void setWaitForVerticalBlank(bool enabled);
    00582
    00585         bool getWaitForVerticalBlank(void) const;
    00586
    00589         HardwareVertexBufferSharedPtr getGlobalInstanceVertexBuffer() const;
    00592         void setGlobalInstanceVertexBuffer(const HardwareVertexBufferSharedPtr val);
    00595         VertexDeclaration* getGlobalInstanceVertexBufferVertexDeclaration() const;
    00598         void setGlobalInstanceVertexBufferVertexDeclaration( VertexDeclaration* val);
    00601         size_t getGlobalNumberOfInstances() const;
    00604         void setGlobalNumberOfInstances(const size_t val);
    00605
    00606 #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS
    00607
    00609         void setFixedPipelineEnabled(bool enabled);
    00610
    00613         bool getFixedPipelineEnabled(void) const;
    00614 #endif
    00615
    00621         virtual void setDepthBufferFor( RenderTarget *renderTarget );
    00622
    00623         // ------------------------------------------------------------------------
    00624         //                     Internal Rendering Access
    00625         // All methods below here are normally only called by other OGRE classes
    00626         // They can be called by library user if required
    00627         // ------------------------------------------------------------------------
    00628
    00629
    00633         virtual void _useLights(const LightList& lights, unsigned short limit) = 0;
    00636         virtual bool areFixedFunctionLightsInViewSpace() const { return false; }
    00638         virtual void _setWorldMatrix(const Matrix4 &m) = 0;
    00640         virtual void _setWorldMatrices(const Matrix4* m, unsigned short count);
    00642         virtual void _setViewMatrix(const Matrix4 &m) = 0;
    00644         virtual void _setProjectionMatrix(const Matrix4 &m) = 0;
    00650         virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl);
    00652         virtual void _disableTextureUnit(size_t texUnit);
    00654         virtual void _disableTextureUnitsFrom(size_t texUnit);
    00688         virtual void _setSurfaceParams(const ColourValue &ambient,
    00689             const ColourValue &diffuse, const ColourValue &specular,
    00690             const ColourValue &emissive, Real shininess,
    00691             TrackVertexColourType tracking = TVC_NONE) = 0;
    00692
    00698         virtual void _setPointSpritesEnabled(bool enabled) = 0;
    00699
    00710         virtual void _setPointParameters(Real size, bool attenuationEnabled,
    00711             Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) = 0;
    00712
    00713
    00726         virtual void _setTexture(size_t unit, bool enabled,
    00727             const TexturePtr &texPtr) = 0;
    00741         virtual void _setTexture(size_t unit, bool enabled, const String &texname);
    00742
    00752         virtual void _setVertexTexture(size_t unit, const TexturePtr& tex);
    00753
    00763         virtual void _setTextureCoordSet(size_t unit, size_t index) = 0;
    00764
    00772         virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
    00773             const Frustum* frustum = 0) = 0;
    00774
    00781         virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) = 0;
    00782
    00789         virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
    00790             FilterOptions magFilter, FilterOptions mipFilter);
    00791
    00797         virtual void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0;
    00798
    00800         virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
    00801
    00803         virtual void _setTextureAddressingMode(size_t unit, const TextureUnitState::UVWAddressingMode& uvw) = 0;
    00804
    00806         virtual void _setTextureBorderColour(size_t unit, const ColourValue& colour) = 0;
    00807
    00816         virtual void _setTextureMipmapBias(size_t unit, float bias) = 0;
    00817
    00822         virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) = 0;
    00823
    00834         virtual void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD) = 0;
    00835
    00848         virtual void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha,
    00849             SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD) = 0;
    00850
    00857         virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
    00858
    00862         virtual void _setTextureProjectionRelativeTo(bool enabled, const Vector3& pos);
    00863
    00871         virtual DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget ) = 0;
    00872
    00880         void _cleanupDepthBuffers( bool bCleanManualBuffers=true );
    00881
    00886         virtual void _beginFrame(void) = 0;
    00887
    00888         //Dummy structure for render system contexts - implementing RenderSystems can extend
    00889         //as needed
    00890         struct RenderSystemContext { };
    00896         virtual RenderSystemContext* _pauseFrame(void);
    00903         virtual void _resumeFrame(RenderSystemContext* context);
    00904
    00908         virtual void _endFrame(void) = 0;
    00916         virtual void _setViewport(Viewport *vp) = 0;
    00918         virtual Viewport* _getViewport(void);
    00919
    00931         virtual void _setCullingMode(CullingMode mode) = 0;
    00932
    00933         virtual CullingMode _getCullingMode(void) const;
    00934
    00948         virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
    00949
    00954         virtual void _setDepthBufferCheckEnabled(bool enabled = true) = 0;
    00959         virtual void _setDepthBufferWriteEnabled(bool enabled = true) = 0;
    00967         virtual void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
    00975         virtual void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
    00998         virtual void _setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0;
    01010         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;
    01011
    01012
    01014         virtual void _beginGeometryCount(void);
    01016         virtual unsigned int _getFaceCount(void) const;
    01018         virtual unsigned int _getBatchCount(void) const;
    01020         virtual unsigned int _getVertexCount(void) const;
    01021
    01030         virtual void convertColourValue(const ColourValue& colour, uint32* pDest);
    01034         virtual VertexElementType getColourVertexElementType(void) const = 0;
    01035
    01042         virtual void _convertProjectionMatrix(const Matrix4& matrix,
    01043             Matrix4& dest, bool forGpuProgram = false) = 0;
    01044
    01051         virtual void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
    01052             Matrix4& dest, bool forGpuProgram = false) = 0;
    01053
    01060         virtual void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
    01061             Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false) = 0;
    01068         virtual void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
    01069             Matrix4& dest, bool forGpuProgram = false) = 0;
    01070
    01087         virtual void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
    01088             bool forGpuProgram) = 0;
    01089
    01091         virtual void _setPolygonMode(PolygonMode level) = 0;
    01092
    01099         virtual void setStencilCheckEnabled(bool enabled) = 0;
    01115         /*virtual bool hasHardwareStencil(void) = 0;*/
    01116
    01152         virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
    01153             uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
    01154             StencilOperation stencilFailOp = SOP_KEEP,
    01155             StencilOperation depthFailOp = SOP_KEEP,
    01156             StencilOperation passOp = SOP_KEEP,
    01157             bool twoSidedOperation = false) = 0;
    01158
    01159
    01160
    01162         virtual void setVertexDeclaration(VertexDeclaration* decl) = 0;
    01164         virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
    01165
    01176         virtual void setNormaliseNormals(bool normalise) = 0;
    01177
    01190         virtual void _render(const RenderOperation& op);
    01191
    01193         const RenderSystemCapabilities* getCapabilities(void) const { return mCurrentCapabilities; }
    01194
    01195
    01198         virtual const DriverVersion& getDriverVersion(void) const { return mDriverVersion; }
    01199
    01209         virtual const String& _getDefaultViewportMaterialScheme(void) const;
    01210
    01215         virtual void bindGpuProgram(GpuProgram* prg);
    01216
    01222         virtual void bindGpuProgramParameters(GpuProgramType gptype,
    01223             GpuProgramParametersSharedPtr params, uint16 variabilityMask) = 0;
    01224
    01227         virtual void bindGpuProgramPassIterationParameters(GpuProgramType gptype) = 0;
    01232         virtual void unbindGpuProgram(GpuProgramType gptype);
    01233
    01235         virtual bool isGpuProgramBound(GpuProgramType gptype);
    01236
    01239         virtual void setClipPlanes(const PlaneList& clipPlanes);
    01240
    01242         virtual void addClipPlane (const Plane &p);
    01244         virtual void addClipPlane (Real A, Real B, Real C, Real D);
    01245
    01248         virtual void resetClipPlanes();
    01249
    01251         virtual void _initRenderTargets(void);
    01252
    01256         virtual void _notifyCameraRemoved(const Camera* cam);
    01257
    01259         virtual void _updateAllRenderTargets(bool swapBuffers = true);
    01262         virtual void _swapAllRenderTargetBuffers(bool waitForVsync = true);
    01263
    01266         virtual void setInvertVertexWinding(bool invert);
    01267
    01271         virtual bool getInvertVertexWinding(void) const;
    01272
    01284         virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0,
    01285             size_t right = 800, size_t bottom = 600) = 0;
    01286
    01294         virtual void clearFrameBuffer(unsigned int buffers,
    01295             const ColourValue& colour = ColourValue::Black,
    01296             Real depth = 1.0f, unsigned short stencil = 0) = 0;
    01306         virtual Real getHorizontalTexelOffset(void) = 0;
    01316         virtual Real getVerticalTexelOffset(void) = 0;
    01317
    01326         virtual Real getMinimumDepthInputValue(void) = 0;
    01335         virtual Real getMaximumDepthInputValue(void) = 0;
    01341         virtual void setCurrentPassIterationCount(const size_t count) { mCurrentPassIterationCount = count; }
    01342
    01352         virtual void setDeriveDepthBias(bool derive, float baseValue = 0.0f,
    01353             float multiplier = 0.0f, float slopeScale = 0.0f)
    01354         {
    01355             mDerivedDepthBias = derive;
    01356             mDerivedDepthBiasBase = baseValue;
    01357             mDerivedDepthBiasMultiplier = multiplier;
    01358             mDerivedDepthBiasSlopeScale = slopeScale;
    01359         }
    01360
    01364         virtual void _setRenderTarget(RenderTarget *target) = 0;
    01365
    01370         class _OgreExport Listener
    01371         {
    01372         public:
    01373             Listener() {}
    01374             virtual ~Listener() {}
    01375
    01381             virtual void eventOccurred(const String& eventName,
    01382                 const NameValuePairList* parameters = 0) = 0;
    01383         };
    01397         virtual void addListener(Listener* l);
    01400         virtual void removeListener(Listener* l);
    01401
    01406         virtual const StringVector& getRenderSystemEvents(void) const { return mEventNames; }
    01407
    01424         virtual void preExtraThreadsStarted() = 0;
    01425
    01426         /* Tell the rendersystem to perform any tasks it needs to directly
    01427         after other threads which might access the rendering API are registered.
    01428         @see RenderSystem::preExtraThreadsStarted
    01429         */
    01430         virtual void postExtraThreadsStarted() = 0;
    01431
    01444         virtual void registerThread() = 0;
    01445
    01449         virtual void unregisterThread() = 0;
    01450
    01455         virtual unsigned int getDisplayMonitorCount() const = 0;
    01456
    01460         virtual void beginProfileEvent( const String &eventName ) = 0;
    01461
    01465         virtual void endProfileEvent( void ) = 0;
    01466
    01471         virtual void markProfileEvent( const String &event ) = 0;
    01472
    01473     protected:
    01474
    01476         DepthBufferMap mDepthBufferPool;
    01477
    01479         RenderTargetMap mRenderTargets;
    01481         RenderTargetPriorityMap mPrioritisedRenderTargets;
    01483         RenderTarget * mActiveRenderTarget;
    01484
    01486         GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters;
    01487         GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters;
    01488         GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters;
    01489
    01490         // Texture manager
    01491         // A concrete class of this will be created and
    01492         // made available under the TextureManager singleton,
    01493         // managed by the RenderSystem
    01494         TextureManager* mTextureManager;
    01495
    01496         // Active viewport (dest for future rendering operations)
    01497         Viewport* mActiveViewport;
    01498
    01499         CullingMode mCullingMode;
    01500
    01501         bool mVSync;
    01502         unsigned int mVSyncInterval;
    01503         bool mWBuffer;
    01504
    01505         size_t mBatchCount;
    01506         size_t mFaceCount;
    01507         size_t mVertexCount;
    01508
    01510         ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2];
    01511
    01512         bool mInvertVertexWinding;
    01513
    01515         size_t mDisabledTexUnitsFrom;
    01516
    01518         size_t mCurrentPassIterationCount;
    01519         size_t mCurrentPassIterationNum;
    01521         bool mDerivedDepthBias;
    01522         float mDerivedDepthBiasBase;
    01523         float mDerivedDepthBiasMultiplier;
    01524         float mDerivedDepthBiasSlopeScale;
    01525
    01527         HardwareVertexBufferSharedPtr mGlobalInstanceVertexBuffer;
    01529         VertexDeclaration* mGlobalInstanceVertexBufferVertexDeclaration;
    01531         size_t mGlobalNumberOfInstances;
    01532
    01533 #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS
    01534
    01535         bool mEnableFixedPipeline;
    01536 #endif
    01537
    01542         bool updatePassIterationRenderState(void);
    01543
    01545         StringVector mEventNames;
    01546
    01548         virtual void fireEvent(const String& name, const NameValuePairList* params = 0);
    01549
    01550         typedef list<Listener*>::type ListenerList;
    01551         ListenerList mEventListeners;
    01552
    01553         typedef list<HardwareOcclusionQuery*>::type HardwareOcclusionQueryList;
    01554         HardwareOcclusionQueryList mHwOcclusionQueries;
    01555
    01556         bool mVertexProgramBound;
    01557         bool mGeometryProgramBound;
    01558         bool mFragmentProgramBound;
    01559
    01560         // Recording user clip planes
    01561         PlaneList mClipPlanes;
    01562         // Indicator that we need to re-set the clip planes on next render call
    01563         bool mClipPlanesDirty;
    01564
    01566         RenderSystemCapabilities* mRealCapabilities;
    01567         RenderSystemCapabilities* mCurrentCapabilities;
    01568         bool mUseCustomCapabilities;
    01569
    01571         virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0;
    01572
    01574         virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0;
    01575
    01576
    01577         DriverVersion mDriverVersion;
    01578
    01579         bool mTexProjRelative;
    01580         Vector3 mTexProjRelativeOrigin;
    01581
    01582
    01583
    01584     };
    01587 }
    01588
    01589 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:23