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-2013 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 #include "OgreHeaderPrefix.h" 00050 00051 namespace Ogre 00052 { 00060 typedef vector<DepthBuffer*>::type DepthBufferVec; 00061 typedef map< uint16, DepthBufferVec >::type DepthBufferMap; 00062 typedef map< String, RenderTarget * >::type RenderTargetMap; 00063 typedef multimap<uchar, RenderTarget * >::type RenderTargetPriorityMap; 00064 00065 class TextureManager; 00067 enum TexCoordCalcMethod 00068 { 00070 TEXCALC_NONE, 00072 TEXCALC_ENVIRONMENT_MAP, 00074 TEXCALC_ENVIRONMENT_MAP_PLANAR, 00075 TEXCALC_ENVIRONMENT_MAP_REFLECTION, 00076 TEXCALC_ENVIRONMENT_MAP_NORMAL, 00078 TEXCALC_PROJECTIVE_TEXTURE 00079 }; 00081 enum StencilOperation 00082 { 00084 SOP_KEEP, 00086 SOP_ZERO, 00088 SOP_REPLACE, 00090 SOP_INCREMENT, 00092 SOP_DECREMENT, 00094 SOP_INCREMENT_WRAP, 00096 SOP_DECREMENT_WRAP, 00098 SOP_INVERT 00099 }; 00100 00101 00125 class _OgreExport RenderSystem : public RenderSysAlloc 00126 { 00127 public: 00130 RenderSystem(); 00131 00134 virtual ~RenderSystem(); 00135 00138 virtual const String& getName(void) const = 0; 00139 00161 virtual ConfigOptionMap& getConfigOptions(void) = 0; 00162 00182 virtual void setConfigOption(const String &name, const String &value) = 0; 00183 00186 virtual HardwareOcclusionQuery* createHardwareOcclusionQuery(void) = 0; 00187 00190 virtual void destroyHardwareOcclusionQuery(HardwareOcclusionQuery *hq); 00191 00196 virtual String validateConfigOptions(void) = 0; 00197 00212 virtual RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"); 00213 00214 /* 00215 Returns whether under the current render system buffers marked as TU_STATIC can be locked for update 00216 @remarks 00217 Needed in the implementation of DirectX9 with DirectX9Ex driver 00218 */ 00219 virtual bool isStaticBufferLockable() const { return true; } 00220 00222 virtual RenderSystemCapabilities* createRenderSystemCapabilities() const = 0; 00223 00231 RenderSystemCapabilities* getMutableCapabilities(){ return mCurrentCapabilities; } 00232 00239 virtual void useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities); 00240 00243 virtual void reinitialise(void) = 0; 00244 00247 virtual void shutdown(void); 00248 00249 00252 virtual void setAmbientLight(float r, float g, float b) = 0; 00253 00256 virtual void setShadingType(ShadeOptions so) = 0; 00257 00263 virtual void setLightingEnabled(bool enabled) = 0; 00264 00271 void setWBufferEnabled(bool enabled); 00272 00275 bool getWBufferEnabled(void) const; 00276 00529 virtual RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 00530 bool fullScreen, const NameValuePairList *miscParams = 0) = 0; 00531 00547 virtual bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions, 00548 RenderWindowList& createdWindows); 00549 00550 00555 virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0; 00556 00558 virtual void destroyRenderWindow(const String& name); 00560 virtual void destroyRenderTexture(const String& name); 00562 virtual void destroyRenderTarget(const String& name); 00563 00566 virtual void attachRenderTarget( RenderTarget &target ); 00570 virtual RenderTarget * getRenderTarget( const String &name ); 00576 virtual RenderTarget * detachRenderTarget( const String &name ); 00577 00579 typedef MapIterator<Ogre::RenderTargetMap> RenderTargetIterator; 00580 00582 virtual RenderTargetIterator getRenderTargetIterator(void) { 00583 return RenderTargetIterator( mRenderTargets.begin(), mRenderTargets.end() ); 00584 } 00587 virtual String getErrorDescription(long errorNumber) const = 0; 00588 00591 HardwareVertexBufferSharedPtr getGlobalInstanceVertexBuffer() const; 00594 void setGlobalInstanceVertexBuffer(const HardwareVertexBufferSharedPtr &val); 00597 VertexDeclaration* getGlobalInstanceVertexBufferVertexDeclaration() const; 00600 void setGlobalInstanceVertexBufferVertexDeclaration( VertexDeclaration* val); 00603 size_t getGlobalNumberOfInstances() const; 00606 void setGlobalNumberOfInstances(const size_t val); 00607 00610 void setFixedPipelineEnabled(bool enabled); 00611 00614 bool getFixedPipelineEnabled(void) const; 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 00803 virtual void _setTextureUnitCompareEnabled(size_t unit, bool compare) = 0; 00804 00805 00810 virtual void _setTextureUnitCompareFunction(size_t unit, CompareFunction function) = 0; 00811 00812 00814 virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0; 00815 00817 virtual void _setTextureAddressingMode(size_t unit, const TextureUnitState::UVWAddressingMode& uvw) = 0; 00818 00820 virtual void _setTextureBorderColour(size_t unit, const ColourValue& colour) = 0; 00821 00830 virtual void _setTextureMipmapBias(size_t unit, float bias) = 0; 00831 00836 virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) = 0; 00837 00848 virtual void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD) = 0; 00849 00862 virtual void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, 00863 SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD) = 0; 00864 00871 virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0; 00872 00876 virtual void _setTextureProjectionRelativeTo(bool enabled, const Vector3& pos); 00877 00885 virtual DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget ) = 0; 00886 00894 void _cleanupDepthBuffers( bool bCleanManualBuffers=true ); 00895 00900 virtual void _beginFrame(void) = 0; 00901 00902 //Dummy structure for render system contexts - implementing RenderSystems can extend 00903 //as needed 00904 struct RenderSystemContext { }; 00910 virtual RenderSystemContext* _pauseFrame(void); 00917 virtual void _resumeFrame(RenderSystemContext* context); 00918 00922 virtual void _endFrame(void) = 0; 00930 virtual void _setViewport(Viewport *vp) = 0; 00932 virtual Viewport* _getViewport(void); 00933 00945 virtual void _setCullingMode(CullingMode mode) = 0; 00946 00947 virtual CullingMode _getCullingMode(void) const; 00948 00962 virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0; 00963 00968 virtual void _setDepthBufferCheckEnabled(bool enabled = true) = 0; 00973 virtual void _setDepthBufferWriteEnabled(bool enabled = true) = 0; 00981 virtual void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0; 00989 virtual void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0; 01012 virtual void _setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0; 01024 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; 01025 01026 01028 virtual void _beginGeometryCount(void); 01030 virtual unsigned int _getFaceCount(void) const; 01032 virtual unsigned int _getBatchCount(void) const; 01034 virtual unsigned int _getVertexCount(void) const; 01035 01044 virtual void convertColourValue(const ColourValue& colour, uint32* pDest); 01048 virtual VertexElementType getColourVertexElementType(void) const = 0; 01049 01056 virtual void _convertProjectionMatrix(const Matrix4& matrix, 01057 Matrix4& dest, bool forGpuProgram = false) = 0; 01058 01065 virtual void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 01066 Matrix4& dest, bool forGpuProgram = false) = 0; 01067 01074 virtual void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 01075 Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false) = 0; 01082 virtual void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 01083 Matrix4& dest, bool forGpuProgram = false) = 0; 01084 01101 virtual void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 01102 bool forGpuProgram) = 0; 01103 01105 virtual void _setPolygonMode(PolygonMode level) = 0; 01106 01113 virtual void setStencilCheckEnabled(bool enabled) = 0; 01129 /*virtual bool hasHardwareStencil(void) = 0;*/ 01130 01169 virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 01170 uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF, 01171 StencilOperation stencilFailOp = SOP_KEEP, 01172 StencilOperation depthFailOp = SOP_KEEP, 01173 StencilOperation passOp = SOP_KEEP, 01174 bool twoSidedOperation = false) = 0; 01175 01176 01177 01179 virtual void setVertexDeclaration(VertexDeclaration* decl) = 0; 01181 virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0; 01182 01193 virtual void setNormaliseNormals(bool normalise) = 0; 01194 01207 virtual void _render(const RenderOperation& op); 01208 01210 const RenderSystemCapabilities* getCapabilities(void) const { return mCurrentCapabilities; } 01211 01212 01215 virtual const DriverVersion& getDriverVersion(void) const { return mDriverVersion; } 01216 01226 virtual const String& _getDefaultViewportMaterialScheme(void) const; 01227 01232 virtual void bindGpuProgram(GpuProgram* prg); 01233 01239 virtual void bindGpuProgramParameters(GpuProgramType gptype, 01240 GpuProgramParametersSharedPtr params, uint16 variabilityMask) = 0; 01241 01244 virtual void bindGpuProgramPassIterationParameters(GpuProgramType gptype) = 0; 01249 virtual void unbindGpuProgram(GpuProgramType gptype); 01250 01252 virtual bool isGpuProgramBound(GpuProgramType gptype); 01253 01259 uint16 getNativeShadingLanguageVersion() const { return mNativeShadingLanguageVersion; } 01260 01263 virtual void setClipPlanes(const PlaneList& clipPlanes); 01264 01266 virtual void addClipPlane (const Plane &p); 01268 virtual void addClipPlane (Real A, Real B, Real C, Real D); 01269 01272 virtual void resetClipPlanes(); 01273 01275 virtual void _initRenderTargets(void); 01276 01280 virtual void _notifyCameraRemoved(const Camera* cam); 01281 01283 virtual void _updateAllRenderTargets(bool swapBuffers = true); 01286 virtual void _swapAllRenderTargetBuffers(); 01287 01290 virtual void setInvertVertexWinding(bool invert); 01291 01295 virtual bool getInvertVertexWinding(void) const; 01296 01308 virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, 01309 size_t right = 800, size_t bottom = 600) = 0; 01310 01318 virtual void clearFrameBuffer(unsigned int buffers, 01319 const ColourValue& colour = ColourValue::Black, 01320 Real depth = 1.0f, unsigned short stencil = 0) = 0; 01330 virtual Real getHorizontalTexelOffset(void) = 0; 01340 virtual Real getVerticalTexelOffset(void) = 0; 01341 01350 virtual Real getMinimumDepthInputValue(void) = 0; 01359 virtual Real getMaximumDepthInputValue(void) = 0; 01365 virtual void setCurrentPassIterationCount(const size_t count) { mCurrentPassIterationCount = count; } 01366 01376 virtual void setDeriveDepthBias(bool derive, float baseValue = 0.0f, 01377 float multiplier = 0.0f, float slopeScale = 0.0f) 01378 { 01379 mDerivedDepthBias = derive; 01380 mDerivedDepthBiasBase = baseValue; 01381 mDerivedDepthBiasMultiplier = multiplier; 01382 mDerivedDepthBiasSlopeScale = slopeScale; 01383 } 01384 01388 virtual void _setRenderTarget(RenderTarget *target) = 0; 01389 01394 class _OgreExport Listener 01395 { 01396 public: 01397 Listener() {} 01398 virtual ~Listener() {} 01399 01405 virtual void eventOccurred(const String& eventName, 01406 const NameValuePairList* parameters = 0) = 0; 01407 }; 01421 virtual void addListener(Listener* l); 01424 virtual void removeListener(Listener* l); 01425 01430 virtual const StringVector& getRenderSystemEvents(void) const { return mEventNames; } 01431 01448 virtual void preExtraThreadsStarted() = 0; 01449 01450 /* Tell the rendersystem to perform any tasks it needs to directly 01451 after other threads which might access the rendering API are registered. 01452 @see RenderSystem::preExtraThreadsStarted 01453 */ 01454 virtual void postExtraThreadsStarted() = 0; 01455 01468 virtual void registerThread() = 0; 01469 01473 virtual void unregisterThread() = 0; 01474 01479 virtual unsigned int getDisplayMonitorCount() const = 0; 01480 01484 virtual void beginProfileEvent( const String &eventName ) = 0; 01485 01489 virtual void endProfileEvent( void ) = 0; 01490 01495 virtual void markProfileEvent( const String &event ) = 0; 01496 01499 virtual bool hasAnisotropicMipMapFilter() const = 0; 01500 01506 virtual void getCustomAttribute(const String& name, void* pData); 01507 01508 protected: 01509 01511 DepthBufferMap mDepthBufferPool; 01512 01514 RenderTargetMap mRenderTargets; 01516 RenderTargetPriorityMap mPrioritisedRenderTargets; 01518 RenderTarget * mActiveRenderTarget; 01519 01521 GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters; 01522 GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters; 01523 GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters; 01524 GpuProgramParametersSharedPtr mActiveTesselationHullGpuProgramParameters; 01525 GpuProgramParametersSharedPtr mActiveTesselationDomainGpuProgramParameters; 01526 GpuProgramParametersSharedPtr mActiveComputeGpuProgramParameters; 01527 01528 // Texture manager 01529 // A concrete class of this will be created and 01530 // made available under the TextureManager singleton, 01531 // managed by the RenderSystem 01532 TextureManager* mTextureManager; 01533 01534 // Active viewport (dest for future rendering operations) 01535 Viewport* mActiveViewport; 01536 01537 CullingMode mCullingMode; 01538 01539 bool mWBuffer; 01540 01541 size_t mBatchCount; 01542 size_t mFaceCount; 01543 size_t mVertexCount; 01544 01546 ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2]; 01547 01548 bool mInvertVertexWinding; 01549 01551 size_t mDisabledTexUnitsFrom; 01552 01554 size_t mCurrentPassIterationCount; 01555 size_t mCurrentPassIterationNum; 01557 bool mDerivedDepthBias; 01558 float mDerivedDepthBiasBase; 01559 float mDerivedDepthBiasMultiplier; 01560 float mDerivedDepthBiasSlopeScale; 01561 01563 HardwareVertexBufferSharedPtr mGlobalInstanceVertexBuffer; 01565 VertexDeclaration* mGlobalInstanceVertexBufferVertexDeclaration; 01567 size_t mGlobalNumberOfInstances; 01568 01570 bool mEnableFixedPipeline; 01571 01576 bool updatePassIterationRenderState(void); 01577 01579 StringVector mEventNames; 01580 01582 virtual void fireEvent(const String& name, const NameValuePairList* params = 0); 01583 01584 typedef list<Listener*>::type ListenerList; 01585 ListenerList mEventListeners; 01586 01587 typedef list<HardwareOcclusionQuery*>::type HardwareOcclusionQueryList; 01588 HardwareOcclusionQueryList mHwOcclusionQueries; 01589 01590 bool mVertexProgramBound; 01591 bool mGeometryProgramBound; 01592 bool mFragmentProgramBound; 01593 bool mTesselationHullProgramBound; 01594 bool mTesselationDomainProgramBound; 01595 bool mComputeProgramBound; 01596 01597 // Recording user clip planes 01598 PlaneList mClipPlanes; 01599 // Indicator that we need to re-set the clip planes on next render call 01600 bool mClipPlanesDirty; 01601 01603 RenderSystemCapabilities* mRealCapabilities; 01604 RenderSystemCapabilities* mCurrentCapabilities; 01605 bool mUseCustomCapabilities; 01606 01608 virtual void setClipPlanesImpl(const PlaneList& clipPlanes) = 0; 01609 01611 virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0; 01612 01613 01614 DriverVersion mDriverVersion; 01615 uint16 mNativeShadingLanguageVersion; 01616 01617 bool mTexProjRelative; 01618 Vector3 mTexProjRelativeOrigin; 01619 01620 01621 01622 }; 01625 } 01626 01627 #include "OgreHeaderSuffix.h" 01628 01629 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:45