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 00114 class _OgreExport RenderSystem 00115 { 00116 public: 00119 RenderSystem(); 00120 00123 virtual ~RenderSystem(); 00124 00127 virtual const String& getName(void) const = 0; 00128 00150 virtual ConfigOptionMap& getConfigOptions(void) = 0; 00151 00171 virtual void setConfigOption(const String &name, const String &value) = 0; 00172 00175 virtual HardwareOcclusionQuery* createHardwareOcclusionQuery(void) = 0; 00176 00179 virtual void destroyHardwareOcclusionQuery(HardwareOcclusionQuery *hq); 00180 00185 virtual String validateConfigOptions(void) = 0; 00186 00203 virtual RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"); 00204 00207 virtual void reinitialise(void) = 0; 00208 00211 virtual void shutdown(void); 00212 00213 00216 virtual void setAmbientLight(float r, float g, float b) = 0; 00217 00220 virtual void setShadingType(ShadeOptions so) = 0; 00221 00227 virtual void setLightingEnabled(bool enabled) = 0; 00228 00235 void setWBufferEnabled(bool enabled); 00236 00239 bool getWBufferEnabled(void) const; 00240 00366 virtual RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 00367 bool fullScreen, const NameValuePairList *miscParams = 0) = 0; 00368 00395 RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height, 00396 TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8, 00397 const NameValuePairList *miscParams = 0 ); 00398 00403 virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0; 00404 00406 virtual void destroyRenderWindow(const String& name); 00408 virtual void destroyRenderTexture(const String& name); 00410 virtual void destroyRenderTarget(const String& name); 00411 00414 virtual void attachRenderTarget( RenderTarget &target ); 00418 virtual RenderTarget * getRenderTarget( const String &name ); 00424 virtual RenderTarget * detachRenderTarget( const String &name ); 00425 00427 typedef MapIterator<Ogre::RenderTargetMap> RenderTargetIterator; 00428 00430 virtual RenderTargetIterator getRenderTargetIterator(void) { 00431 return RenderTargetIterator( mRenderTargets.begin(), mRenderTargets.end() ); 00432 } 00435 virtual String getErrorDescription(long errorNumber) const = 0; 00436 00450 void setWaitForVerticalBlank(bool enabled); 00451 00454 bool getWaitForVerticalBlank(void) const; 00455 00456 // ------------------------------------------------------------------------ 00457 // Internal Rendering Access 00458 // All methods below here are normally only called by other OGRE classes 00459 // They can be called by library user if required 00460 // ------------------------------------------------------------------------ 00461 00462 00466 virtual void _useLights(const LightList& lights, unsigned short limit) = 0; 00468 virtual void _setWorldMatrix(const Matrix4 &m) = 0; 00470 virtual void _setWorldMatrices(const Matrix4* m, unsigned short count); 00472 virtual void _setViewMatrix(const Matrix4 &m) = 0; 00474 virtual void _setProjectionMatrix(const Matrix4 &m) = 0; 00480 virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl); 00482 virtual void _disableTextureUnit(size_t texUnit); 00484 virtual void _disableTextureUnitsFrom(size_t texUnit); 00518 virtual void _setSurfaceParams(const ColourValue &ambient, 00519 const ColourValue &diffuse, const ColourValue &specular, 00520 const ColourValue &emissive, Real shininess, 00521 TrackVertexColourType tracking = TVC_NONE) = 0; 00522 00528 virtual void _setPointSpritesEnabled(bool enabled) = 0; 00529 00540 virtual void _setPointParameters(Real size, bool attenuationEnabled, 00541 Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) = 0; 00542 00543 00556 virtual void _setTexture(size_t unit, bool enabled, 00557 const TexturePtr &texPtr) = 0; 00571 virtual void _setTexture(size_t unit, bool enabled, const String &texname); 00572 00582 virtual void _setVertexTexture(size_t unit, const TexturePtr& tex); 00583 00593 virtual void _setTextureCoordSet(size_t unit, size_t index) = 0; 00594 00602 virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m, 00603 const Frustum* frustum = 0) = 0; 00604 00611 virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) = 0; 00612 00619 virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter, 00620 FilterOptions magFilter, FilterOptions mipFilter); 00621 00627 virtual void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0; 00628 00630 virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0; 00631 00633 virtual void _setTextureAddressingMode(size_t unit, const TextureUnitState::UVWAddressingMode& uvw) = 0; 00634 00636 virtual void _setTextureBorderColour(size_t unit, const ColourValue& colour) = 0; 00637 00646 virtual void _setTextureMipmapBias(size_t unit, float bias) = 0; 00647 00652 virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) = 0; 00653 00662 virtual void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor) = 0; 00663 00669 virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value) = 0; 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 mCapabilities; } 00966 00971 virtual void bindGpuProgram(GpuProgram* prg); 00972 00975 virtual void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params) = 0; 00978 virtual void bindGpuProgramPassIterationParameters(GpuProgramType gptype) = 0; 00983 virtual void unbindGpuProgram(GpuProgramType gptype); 00984 00986 virtual bool isGpuProgramBound(GpuProgramType gptype); 00987 00990 virtual void setClipPlanes(const PlaneList& clipPlanes) = 0; 00991 00993 virtual void _initRenderTargets(void); 00994 00998 virtual void _notifyCameraRemoved(const Camera* cam); 00999 01001 virtual void _updateAllRenderTargets(void); 01002 01004 virtual void setClipPlane (ushort index, const Plane &p); 01006 virtual void setClipPlane (ushort index, Real A, Real B, Real C, Real D) = 0; 01008 virtual void enableClipPlane (ushort index, bool enable) = 0; 01009 01012 virtual void setInvertVertexWinding(bool invert); 01024 virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, 01025 size_t right = 800, size_t bottom = 600) = 0; 01026 01034 virtual void clearFrameBuffer(unsigned int buffers, 01035 const ColourValue& colour = ColourValue::Black, 01036 Real depth = 1.0f, unsigned short stencil = 0) = 0; 01046 virtual Real getHorizontalTexelOffset(void) = 0; 01056 virtual Real getVerticalTexelOffset(void) = 0; 01057 01066 virtual Real getMinimumDepthInputValue(void) = 0; 01075 virtual Real getMaximumDepthInputValue(void) = 0; 01081 void setCurrentPassIterationCount(const size_t count) { mCurrentPassIterationCount = count; } 01082 01087 class _OgreExport Listener 01088 { 01089 public: 01090 Listener() {} 01091 virtual ~Listener() {} 01092 01098 virtual void eventOccurred(const String& eventName, 01099 const NameValuePairList* parameters = 0) = 0; 01100 }; 01114 virtual void addListener(Listener* l); 01117 virtual void removeListener(Listener* l); 01118 01123 virtual const StringVector& getRenderSystemEvents(void) const { return mEventNames; } 01124 01141 virtual void preExtraThreadsStarted() = 0; 01142 01143 /* Tell the rendersystem to perform any tasks it needs to directly 01144 after other threads which might access the rendering API are registered. 01145 @see RenderSystem::preExtraThreadsStarted 01146 */ 01147 virtual void postExtraThreadsStarted() = 0; 01148 01175 virtual void *registerThread() = 0; 01176 01183 virtual void unregisterThread(void *opaque = NULL) = 0; 01184 protected: 01185 01186 01188 RenderTargetMap mRenderTargets; 01190 RenderTargetPriorityMap mPrioritisedRenderTargets; 01192 RenderTarget * mActiveRenderTarget; 01194 GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters; 01195 GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters; 01196 01197 // Texture manager 01198 // A concrete class of this will be created and 01199 // made available under the TextureManager singleton, 01200 // managed by the RenderSystem 01201 TextureManager* mTextureManager; 01202 01204 RenderSystemCapabilities* mCapabilities; 01205 01206 // Active viewport (dest for future rendering operations) 01207 Viewport* mActiveViewport; 01208 01209 CullingMode mCullingMode; 01210 01211 bool mVSync; 01212 bool mWBuffer; 01213 01214 size_t mBatchCount; 01215 size_t mFaceCount; 01216 size_t mVertexCount; 01217 01219 ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2]; 01220 01221 bool mInvertVertexWinding; 01222 01224 size_t mDisabledTexUnitsFrom; 01225 01227 size_t mCurrentPassIterationCount; 01228 01233 bool updatePassIterationRenderState(void); 01234 01236 StringVector mEventNames; 01237 01239 virtual void fireEvent(const String& name, const NameValuePairList* params = 0); 01240 01241 typedef std::list<Listener*> ListenerList; 01242 ListenerList mEventListeners; 01243 01244 typedef std::list<HardwareOcclusionQuery*> HardwareOcclusionQueryList; 01245 HardwareOcclusionQueryList mHwOcclusionQueries; 01246 01247 bool mVertexProgramBound; 01248 bool mFragmentProgramBound; 01249 01250 01251 01252 }; 01253 } 01254 01255 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 25 13:03:16 2007