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 00354 virtual RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 00355 bool fullScreen, const NameValuePairList *miscParams = 0) = 0; 00356 00383 RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height, 00384 TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8, 00385 const NameValuePairList *miscParams = 0 ); 00386 00391 virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0; 00392 00394 virtual void destroyRenderWindow(const String& name); 00396 virtual void destroyRenderTexture(const String& name); 00398 virtual void destroyRenderTarget(const String& name); 00399 00402 virtual void attachRenderTarget( RenderTarget &target ); 00406 virtual RenderTarget * getRenderTarget( const String &name ); 00412 virtual RenderTarget * detachRenderTarget( const String &name ); 00413 00415 typedef MapIterator<Ogre::RenderTargetMap> RenderTargetIterator; 00416 00418 virtual RenderTargetIterator getRenderTargetIterator(void) { 00419 return RenderTargetIterator( mRenderTargets.begin(), mRenderTargets.end() ); 00420 } 00423 virtual String getErrorDescription(long errorNumber) const = 0; 00424 00438 void setWaitForVerticalBlank(bool enabled); 00439 00442 bool getWaitForVerticalBlank(void) const; 00443 00444 // ------------------------------------------------------------------------ 00445 // Internal Rendering Access 00446 // All methods below here are normally only called by other OGRE classes 00447 // They can be called by library user if required 00448 // ------------------------------------------------------------------------ 00449 00450 00454 virtual void _useLights(const LightList& lights, unsigned short limit) = 0; 00456 virtual void _setWorldMatrix(const Matrix4 &m) = 0; 00458 virtual void _setWorldMatrices(const Matrix4* m, unsigned short count); 00460 virtual void _setViewMatrix(const Matrix4 &m) = 0; 00462 virtual void _setProjectionMatrix(const Matrix4 &m) = 0; 00468 virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl); 00470 virtual void _disableTextureUnit(size_t texUnit); 00472 virtual void _disableTextureUnitsFrom(size_t texUnit); 00506 virtual void _setSurfaceParams(const ColourValue &ambient, 00507 const ColourValue &diffuse, const ColourValue &specular, 00508 const ColourValue &emissive, Real shininess, 00509 TrackVertexColourType tracking = TVC_NONE) = 0; 00510 00516 virtual void _setPointSpritesEnabled(bool enabled) = 0; 00517 00528 virtual void _setPointParameters(Real size, bool attenuationEnabled, 00529 Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) = 0; 00530 00531 00544 virtual void _setTexture(size_t unit, bool enabled, 00545 const TexturePtr &texPtr) = 0; 00559 virtual void _setTexture(size_t unit, bool enabled, const String &texname); 00560 00570 virtual void _setVertexTexture(size_t unit, const TexturePtr& tex); 00571 00581 virtual void _setTextureCoordSet(size_t unit, size_t index) = 0; 00582 00590 virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m, 00591 const Frustum* frustum = 0) = 0; 00592 00599 virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) = 0; 00600 00607 virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter, 00608 FilterOptions magFilter, FilterOptions mipFilter); 00609 00615 virtual void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0; 00616 00618 virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0; 00619 00621 virtual void _setTextureAddressingMode(size_t unit, const TextureUnitState::UVWAddressingMode& uvw) = 0; 00622 00624 virtual void _setTextureBorderColour(size_t unit, const ColourValue& colour) = 0; 00625 00634 virtual void _setTextureMipmapBias(size_t unit, float bias) = 0; 00635 00640 virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) = 0; 00641 00650 virtual void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor) = 0; 00651 00657 virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value) = 0; 00662 virtual void _beginFrame(void) = 0; 00663 00664 00668 virtual void _endFrame(void) = 0; 00676 virtual void _setViewport(Viewport *vp) = 0; 00678 virtual Viewport* _getViewport(void); 00679 00691 virtual void _setCullingMode(CullingMode mode) = 0; 00692 00693 virtual CullingMode _getCullingMode(void) const; 00694 00708 virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0; 00709 00714 virtual void _setDepthBufferCheckEnabled(bool enabled = true) = 0; 00719 virtual void _setDepthBufferWriteEnabled(bool enabled = true) = 0; 00727 virtual void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0; 00735 virtual void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0; 00758 virtual void _setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0; 00770 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; 00771 00772 00774 virtual void _beginGeometryCount(void); 00776 virtual unsigned int _getFaceCount(void) const; 00778 virtual unsigned int _getBatchCount(void) const; 00780 virtual unsigned int _getVertexCount(void) const; 00781 00790 virtual void convertColourValue(const ColourValue& colour, uint32* pDest); 00794 virtual VertexElementType getColourVertexElementType(void) const = 0; 00795 00802 virtual void _convertProjectionMatrix(const Matrix4& matrix, 00803 Matrix4& dest, bool forGpuProgram = false) = 0; 00804 00811 virtual void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00812 Matrix4& dest, bool forGpuProgram = false) = 0; 00813 00820 virtual void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 00821 Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false) = 0; 00828 virtual void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00829 Matrix4& dest, bool forGpuProgram = false) = 0; 00830 00847 virtual void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 00848 bool forGpuProgram) = 0; 00849 00851 virtual void _setPolygonMode(PolygonMode level) = 0; 00852 00859 virtual void setStencilCheckEnabled(bool enabled) = 0; 00875 /*virtual bool hasHardwareStencil(void) = 0;*/ 00876 00912 virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 00913 uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 00914 StencilOperation stencilFailOp = SOP_KEEP, 00915 StencilOperation depthFailOp = SOP_KEEP, 00916 StencilOperation passOp = SOP_KEEP, 00917 bool twoSidedOperation = false) = 0; 00918 00919 00920 00922 virtual void setVertexDeclaration(VertexDeclaration* decl) = 0; 00924 virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0; 00925 00936 virtual void setNormaliseNormals(bool normalise) = 0; 00937 00950 virtual void _render(const RenderOperation& op); 00951 00953 const RenderSystemCapabilities* getCapabilities(void) const { return mCapabilities; } 00954 00959 virtual void bindGpuProgram(GpuProgram* prg); 00960 00963 virtual void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params) = 0; 00966 virtual void bindGpuProgramPassIterationParameters(GpuProgramType gptype) = 0; 00971 virtual void unbindGpuProgram(GpuProgramType gptype); 00972 00974 virtual bool isGpuProgramBound(GpuProgramType gptype); 00975 00978 virtual void setClipPlanes(const PlaneList& clipPlanes) = 0; 00979 00981 virtual void _initRenderTargets(void); 00982 00986 virtual void _notifyCameraRemoved(const Camera* cam); 00987 00989 virtual void _updateAllRenderTargets(void); 00990 00992 virtual void setClipPlane (ushort index, const Plane &p); 00994 virtual void setClipPlane (ushort index, Real A, Real B, Real C, Real D) = 0; 00996 virtual void enableClipPlane (ushort index, bool enable) = 0; 00997 01000 virtual void setInvertVertexWinding(bool invert); 01012 virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, 01013 size_t right = 800, size_t bottom = 600) = 0; 01014 01022 virtual void clearFrameBuffer(unsigned int buffers, 01023 const ColourValue& colour = ColourValue::Black, 01024 Real depth = 1.0f, unsigned short stencil = 0) = 0; 01034 virtual Real getHorizontalTexelOffset(void) = 0; 01044 virtual Real getVerticalTexelOffset(void) = 0; 01045 01054 virtual Real getMinimumDepthInputValue(void) = 0; 01063 virtual Real getMaximumDepthInputValue(void) = 0; 01069 void setCurrentPassIterationCount(const size_t count) { mCurrentPassIterationCount = count; } 01070 01075 class _OgreExport Listener 01076 { 01077 public: 01078 Listener() {} 01079 virtual ~Listener() {} 01080 01086 virtual void eventOccurred(const String& eventName, 01087 const NameValuePairList* parameters = 0) = 0; 01088 }; 01102 virtual void addListener(Listener* l); 01105 virtual void removeListener(Listener* l); 01106 01111 virtual const StringVector& getRenderSystemEvents(void) const { return mEventNames; } 01112 01129 virtual void preExtraThreadsStarted() = 0; 01130 01131 /* Tell the rendersystem to perform any tasks it needs to directly 01132 after other threads which might access the rendering API are registered. 01133 @see RenderSystem::preExtraThreadsStarted 01134 */ 01135 virtual void postExtraThreadsStarted() = 0; 01136 01149 virtual void registerThread() = 0; 01150 01154 virtual void unregisterThread() = 0; 01155 protected: 01156 01157 01159 RenderTargetMap mRenderTargets; 01161 RenderTargetPriorityMap mPrioritisedRenderTargets; 01163 RenderTarget * mActiveRenderTarget; 01165 GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters; 01166 GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters; 01167 01168 // Texture manager 01169 // A concrete class of this will be created and 01170 // made available under the TextureManager singleton, 01171 // managed by the RenderSystem 01172 TextureManager* mTextureManager; 01173 01175 RenderSystemCapabilities* mCapabilities; 01176 01177 // Active viewport (dest for future rendering operations) 01178 Viewport* mActiveViewport; 01179 01180 CullingMode mCullingMode; 01181 01182 bool mVSync; 01183 bool mWBuffer; 01184 01185 size_t mBatchCount; 01186 size_t mFaceCount; 01187 size_t mVertexCount; 01188 01190 ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2]; 01191 01192 bool mInvertVertexWinding; 01193 01195 size_t mDisabledTexUnitsFrom; 01196 01198 size_t mCurrentPassIterationCount; 01199 01204 bool updatePassIterationRenderState(void); 01205 01207 StringVector mEventNames; 01208 01210 virtual void fireEvent(const String& name, const NameValuePairList* params = 0); 01211 01212 typedef std::list<Listener*> ListenerList; 01213 ListenerList mEventListeners; 01214 01215 typedef std::list<HardwareOcclusionQuery*> HardwareOcclusionQueryList; 01216 HardwareOcclusionQueryList mHwOcclusionQueries; 01217 01218 bool mVertexProgramBound; 01219 bool mFragmentProgramBound; 01220 01221 01222 01223 }; 01224 } 01225 01226 #endif
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun May 6 10:54:23 2007