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 
00455         virtual RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 
00456             bool fullScreen, const NameValuePairList *miscParams = 0) = 0;
00457 
00473         virtual bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions, 
00474             RenderWindowList& createdWindows);
00475 
00476         
00481         virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0; 
00482 
00484         virtual void destroyRenderWindow(const String& name);
00486         virtual void destroyRenderTexture(const String& name);
00488         virtual void destroyRenderTarget(const String& name);
00489 
00492         virtual void attachRenderTarget( RenderTarget &target );
00496         virtual RenderTarget * getRenderTarget( const String &name );
00502         virtual RenderTarget * detachRenderTarget( const String &name );
00503 
00505         typedef MapIterator<Ogre::RenderTargetMap> RenderTargetIterator;
00506 
00508         virtual RenderTargetIterator getRenderTargetIterator(void) {
00509             return RenderTargetIterator( mRenderTargets.begin(), mRenderTargets.end() );
00510         }
00513         virtual String getErrorDescription(long errorNumber) const = 0;
00514 
00528         void setWaitForVerticalBlank(bool enabled);
00529 
00532         bool getWaitForVerticalBlank(void) const;
00533 
00534         // ------------------------------------------------------------------------
00535         //                     Internal Rendering Access
00536         // All methods below here are normally only called by other OGRE classes
00537         // They can be called by library user if required
00538         // ------------------------------------------------------------------------
00539 
00540 
00544         virtual void _useLights(const LightList& lights, unsigned short limit) = 0;
00547         virtual bool areFixedFunctionLightsInViewSpace() const { return false; }
00549         virtual void _setWorldMatrix(const Matrix4 &m) = 0;
00551         virtual void _setWorldMatrices(const Matrix4* m, unsigned short count);
00553         virtual void _setViewMatrix(const Matrix4 &m) = 0;
00555         virtual void _setProjectionMatrix(const Matrix4 &m) = 0;
00561         virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl);
00563         virtual void _disableTextureUnit(size_t texUnit);
00565         virtual void _disableTextureUnitsFrom(size_t texUnit);
00599         virtual void _setSurfaceParams(const ColourValue &ambient,
00600             const ColourValue &diffuse, const ColourValue &specular,
00601             const ColourValue &emissive, Real shininess,
00602             TrackVertexColourType tracking = TVC_NONE) = 0;
00603 
00609         virtual void _setPointSpritesEnabled(bool enabled) = 0;
00610 
00621         virtual void _setPointParameters(Real size, bool attenuationEnabled, 
00622             Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) = 0;
00623 
00624 
00637         virtual void _setTexture(size_t unit, bool enabled, 
00638             const TexturePtr &texPtr) = 0;
00652         virtual void _setTexture(size_t unit, bool enabled, const String &texname);
00653 
00663         virtual void _setVertexTexture(size_t unit, const TexturePtr& tex);
00664 
00674         virtual void _setTextureCoordSet(size_t unit, size_t index) = 0;
00675 
00683         virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m, 
00684             const Frustum* frustum = 0) = 0;
00685 
00692         virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) = 0;
00693 
00700         virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
00701             FilterOptions magFilter, FilterOptions mipFilter);
00702 
00708         virtual void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0;
00709 
00711         virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
00712 
00714         virtual void _setTextureAddressingMode(size_t unit, const TextureUnitState::UVWAddressingMode& uvw) = 0;
00715 
00717         virtual void _setTextureBorderColour(size_t unit, const ColourValue& colour) = 0;
00718 
00727         virtual void _setTextureMipmapBias(size_t unit, float bias) = 0;
00728 
00733         virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) = 0;
00734 
00745         virtual void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD) = 0;
00746 
00759         virtual void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 
00760             SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD) = 0;
00761 
00768         virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
00769 
00773         virtual void _setTextureProjectionRelativeTo(bool enabled, const Vector3& pos);
00778         virtual void _beginFrame(void) = 0;
00779         
00780         //Dummy structure for render system contexts - implementing RenderSystems can extend
00781         //as needed
00782         struct RenderSystemContext { };
00788         virtual RenderSystemContext* _pauseFrame(void);
00795         virtual void _resumeFrame(RenderSystemContext* context);
00796 
00800         virtual void _endFrame(void) = 0;
00808         virtual void _setViewport(Viewport *vp) = 0;
00810         virtual Viewport* _getViewport(void);
00811 
00823         virtual void _setCullingMode(CullingMode mode) = 0;
00824 
00825         virtual CullingMode _getCullingMode(void) const;
00826 
00840         virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
00841 
00846         virtual void _setDepthBufferCheckEnabled(bool enabled = true) = 0;
00851         virtual void _setDepthBufferWriteEnabled(bool enabled = true) = 0;
00859         virtual void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
00867         virtual void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
00890         virtual void _setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0;
00902         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;
00903 
00904 
00906         virtual void _beginGeometryCount(void);
00908         virtual unsigned int _getFaceCount(void) const;
00910         virtual unsigned int _getBatchCount(void) const;
00912         virtual unsigned int _getVertexCount(void) const;
00913 
00922         virtual void convertColourValue(const ColourValue& colour, uint32* pDest);
00926         virtual VertexElementType getColourVertexElementType(void) const = 0;
00927 
00934         virtual void _convertProjectionMatrix(const Matrix4& matrix,
00935             Matrix4& dest, bool forGpuProgram = false) = 0;
00936 
00943         virtual void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
00944             Matrix4& dest, bool forGpuProgram = false) = 0;
00945 
00952         virtual void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 
00953             Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false) = 0;
00960         virtual void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
00961             Matrix4& dest, bool forGpuProgram = false) = 0;
00962 
00979         virtual void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 
00980             bool forGpuProgram) = 0;
00981 
00983         virtual void _setPolygonMode(PolygonMode level) = 0;
00984 
00991         virtual void setStencilCheckEnabled(bool enabled) = 0;
01007         /*virtual bool hasHardwareStencil(void) = 0;*/
01008 
01044         virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
01045             uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 
01046             StencilOperation stencilFailOp = SOP_KEEP, 
01047             StencilOperation depthFailOp = SOP_KEEP,
01048             StencilOperation passOp = SOP_KEEP, 
01049             bool twoSidedOperation = false) = 0;
01050 
01051 
01052 
01054         virtual void setVertexDeclaration(VertexDeclaration* decl) = 0;
01056         virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
01057 
01068         virtual void setNormaliseNormals(bool normalise) = 0;
01069 
01082         virtual void _render(const RenderOperation& op);
01083 
01085         const RenderSystemCapabilities* getCapabilities(void) const { return mCurrentCapabilities; }
01086 
01087 
01090         virtual const DriverVersion& getDriverVersion(void) const { return mDriverVersion; }
01091 
01096         virtual void bindGpuProgram(GpuProgram* prg);
01097 
01103         virtual void bindGpuProgramParameters(GpuProgramType gptype, 
01104             GpuProgramParametersSharedPtr params, uint16 variabilityMask) = 0;
01105 
01108         virtual void bindGpuProgramPassIterationParameters(GpuProgramType gptype) = 0;
01113         virtual void unbindGpuProgram(GpuProgramType gptype);
01114 
01116         virtual bool isGpuProgramBound(GpuProgramType gptype);
01117 
01120         virtual void setClipPlanes(const PlaneList& clipPlanes);
01121 
01123         virtual void addClipPlane (const Plane &p);
01125         virtual void addClipPlane (Real A, Real B, Real C, Real D);
01126 
01129         virtual void resetClipPlanes();
01130 
01132         virtual void _initRenderTargets(void);
01133 
01137         virtual void _notifyCameraRemoved(const Camera* cam);
01138 
01140         virtual void _updateAllRenderTargets(bool swapBuffers = true);
01143         virtual void _swapAllRenderTargetBuffers(bool waitForVsync = true);
01144 
01147         virtual bool getInvertVertexWinding(void);
01148 
01151         virtual void setInvertVertexWinding(bool invert);
01152 
01156         virtual bool getVertexWindingInverted(void) const;
01157 
01169         virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, 
01170             size_t right = 800, size_t bottom = 600) = 0;
01171 
01179         virtual void clearFrameBuffer(unsigned int buffers, 
01180             const ColourValue& colour = ColourValue::Black, 
01181             Real depth = 1.0f, unsigned short stencil = 0) = 0;
01191         virtual Real getHorizontalTexelOffset(void) = 0;
01201         virtual Real getVerticalTexelOffset(void) = 0;
01202 
01211         virtual Real getMinimumDepthInputValue(void) = 0;
01220         virtual Real getMaximumDepthInputValue(void) = 0;
01226         virtual void setCurrentPassIterationCount(const size_t count) { mCurrentPassIterationCount = count; }
01227 
01237         virtual void setDeriveDepthBias(bool derive, float baseValue = 0.0f,
01238             float multiplier = 0.0f, float slopeScale = 0.0f)
01239         {
01240             mDerivedDepthBias = derive;
01241             mDerivedDepthBiasBase = baseValue;
01242             mDerivedDepthBiasMultiplier = multiplier;
01243             mDerivedDepthBiasSlopeScale = slopeScale;
01244         }
01245 
01249         virtual void _setRenderTarget(RenderTarget *target) = 0;
01250 
01255         class _OgreExport Listener
01256         {
01257         public:
01258             Listener() {}
01259             virtual ~Listener() {}
01260 
01266             virtual void eventOccurred(const String& eventName, 
01267                 const NameValuePairList* parameters = 0) = 0;
01268         };
01282         virtual void addListener(Listener* l);
01285         virtual void removeListener(Listener* l);
01286 
01291         virtual const StringVector& getRenderSystemEvents(void) const { return mEventNames; }
01292 
01309         virtual void preExtraThreadsStarted() = 0;
01310 
01311         /* Tell the rendersystem to perform any tasks it needs to directly
01312         after other threads which might access the rendering API are registered.
01313         @see RenderSystem::preExtraThreadsStarted
01314         */
01315         virtual void postExtraThreadsStarted() = 0;
01316 
01329         virtual void registerThread() = 0;
01330 
01334         virtual void unregisterThread() = 0;
01335 
01340         virtual unsigned int getDisplayMonitorCount() const = 0;
01341     protected:
01342 
01343 
01345         RenderTargetMap mRenderTargets;
01347         RenderTargetPriorityMap mPrioritisedRenderTargets;
01349         RenderTarget * mActiveRenderTarget;
01351         GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters;
01352         GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters;
01353         GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters;
01354 
01355         // Texture manager
01356         // A concrete class of this will be created and
01357         // made available under the TextureManager singleton,
01358         // managed by the RenderSystem
01359         TextureManager* mTextureManager;
01360 
01361         // Active viewport (dest for future rendering operations)
01362         Viewport* mActiveViewport;
01363 
01364         CullingMode mCullingMode;
01365 
01366         bool mVSync;
01367         unsigned int mVSyncInterval;
01368         bool mWBuffer;
01369 
01370         size_t mBatchCount;
01371         size_t mFaceCount;
01372         size_t mVertexCount;
01373 
01375         ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2];
01376 
01377         bool mInvertVertexWinding;
01378 
01380         size_t mDisabledTexUnitsFrom;
01381 
01383         size_t mCurrentPassIterationCount;
01384         size_t mCurrentPassIterationNum;
01386         bool mDerivedDepthBias;
01387         float mDerivedDepthBiasBase;
01388         float mDerivedDepthBiasMultiplier;
01389         float mDerivedDepthBiasSlopeScale;
01390 
01395         bool updatePassIterationRenderState(void);
01396 
01398         StringVector mEventNames;
01399 
01401         virtual void fireEvent(const String& name, const NameValuePairList* params = 0);
01402 
01403         typedef list<Listener*>::type ListenerList;
01404         ListenerList mEventListeners;
01405 
01406         typedef list<HardwareOcclusionQuery*>::type HardwareOcclusionQueryList;
01407         HardwareOcclusionQueryList mHwOcclusionQueries;
01408 
01409         bool mVertexProgramBound;
01410         bool mGeometryProgramBound;
01411         bool mFragmentProgramBound;
01412 
01413         // Recording user clip planes
01414         PlaneList mClipPlanes;
01415         // Indicator that we need to re-set the clip planes on next render call
01416         bool mClipPlanesDirty;
01417 
01419         RenderSystemCapabilities* mRealCapabilities;
01420         RenderSystemCapabilities* mCurrentCapabilities;
01421         bool mUseCustomCapabilities;
01422 
01424         virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0;
01425 
01427         virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0;
01428 
01429 
01430         DriverVersion mDriverVersion;
01431 
01432         bool mTexProjRelative;
01433         Vector3 mTexProjRelativeOrigin;
01434 
01435 
01436 
01437     };
01440 }
01441 
01442 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 28 21:10:40 2010