00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 00006 00007 Copyright (c) 2000-2005 The OGRE Team 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 */ 00025 #ifndef __GLRenderSystem_H__ 00026 #define __GLRenderSystem_H__ 00027 00028 #include "OgreGLPrerequisites.h" 00029 #include "OgrePlatform.h" 00030 #include "OgreRenderSystem.h" 00031 #include "OgreGLHardwareBufferManager.h" 00032 #include "OgreGLGpuProgramManager.h" 00033 #include "OgreVector4.h" 00034 00035 00036 namespace Ogre { 00040 class GLRenderSystem : public RenderSystem 00041 { 00042 private: 00043 // Rendering loop control 00044 bool mStopRendering; 00045 00046 // Array of up to 8 lights, indexed as per API 00047 // Note that a null value indicates a free slot 00048 #define MAX_LIGHTS 8 00049 Light* mLights[MAX_LIGHTS]; 00050 00051 // clip planes 00052 typedef std::vector<Vector4> PlaneList2; 00053 PlaneList2 mClipPlanes; 00054 void setGLClipPlanes() const; 00055 00056 00057 // view matrix to set world against 00058 Matrix4 mViewMatrix; 00059 Matrix4 mWorldMatrix; 00060 Matrix4 mTextureMatrix; 00061 00062 // Last min & mip filtering options, so we can combine them 00063 FilterOptions mMinFilter; 00064 FilterOptions mMipFilter; 00065 00066 // XXX 8 max texture units? 00067 size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_COORD_SETS]; 00068 00070 GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS]; 00071 00073 unsigned short mFixedFunctionTextureUnits; 00074 00075 void initConfigOptions(void); 00076 void initInputDevices(void); 00077 void processInputDevices(void); 00078 00079 void setGLLight(size_t index, Light* lt); 00080 void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m); 00081 00082 GLint getBlendMode(SceneBlendFactor ogreBlend) const; 00083 00084 void setLights(); 00085 00086 // Store last depth write state 00087 bool mDepthWrite; 00088 // Store last colour write state 00089 bool mColourWrite[4]; 00090 00091 GLint convertCompareFunction(CompareFunction func) const; 00092 GLint convertStencilOp(StencilOperation op, bool invert = false) const; 00093 00094 // internal method for anisotrophy validation 00095 GLfloat _getCurrentAnisotropy(size_t unit); 00096 00098 GLSupport* mGLSupport; 00099 00101 void setGLLightPositionDirection(Light* lt, GLenum lightindex); 00102 00103 bool mUseAutoTextureMatrix; 00104 GLfloat mAutoTextureMatrix[16]; 00105 00106 // check if the GL system has already been initialized 00107 bool mGLInitialized; 00108 // Initialise GL context 00109 void initGL(void); 00110 00111 HardwareBufferManager* mHardwareBufferManager; 00112 GLGpuProgramManager* mGpuProgramManager; 00113 00114 unsigned short mCurrentLights; 00115 00116 GLuint getCombinedMinMipFilter(void) const; 00117 00118 GLGpuProgram* mCurrentVertexProgram; 00119 GLGpuProgram* mCurrentFragmentProgram; 00120 00121 /* The main GL context */ 00122 GLContext *mMainContext; 00123 /* The current GL context */ 00124 GLContext *mCurrentContext; 00125 /* Type that maps render targets to contexts */ 00126 typedef std::map<RenderTarget*,GLContext*> ContextMap; 00127 /* Map of render target -> context mappings. This is used to find the 00128 * GL context for a certain render target */ 00129 ContextMap mContextMap; 00130 public: 00131 // Default constructor / destructor 00132 GLRenderSystem(); 00133 ~GLRenderSystem(); 00134 00135 // ---------------------------------- 00136 // Overridden RenderSystem functions 00137 // ---------------------------------- 00141 const String& getName(void) const; 00145 ConfigOptionMap& getConfigOptions(void); 00149 void setConfigOption(const String &name, const String &value); 00153 String validateConfigOptions(void); 00157 RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"); 00161 void reinitialise(void); // Used if settings changed mid-rendering 00165 void shutdown(void); 00166 00170 void setAmbientLight(float r, float g, float b); 00174 void setShadingType(ShadeOptions so); 00178 void setLightingEnabled(bool enabled); 00179 00181 RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 00182 bool fullScreen, const NameValuePairList *miscParams = 0); 00183 00185 RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height, 00186 TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8, 00187 const NameValuePairList *miscParams = 0 ); 00188 00192 void destroyRenderWindow(RenderWindow* pWin); 00196 String getErrorDescription(long errorNumber) const; 00197 00201 void convertColourValue(const ColourValue& colour, uint32* pDest); 00205 void setNormaliseNormals(bool normalise); 00206 00207 // ----------------------------- 00208 // Low-level overridden members 00209 // ----------------------------- 00213 void _useLights(const LightList& lights, unsigned short limit); 00217 void _setWorldMatrix(const Matrix4 &m); 00221 void _setViewMatrix(const Matrix4 &m); 00225 void _setProjectionMatrix(const Matrix4 &m); 00229 void _setSurfaceParams(const ColourValue &ambient, 00230 const ColourValue &diffuse, const ColourValue &specular, 00231 const ColourValue &emissive, Real shininess, 00232 TrackVertexColourType tracking); 00236 void _setTexture(size_t unit, bool enabled, const String &texname); 00240 void _setTextureCoordSet(size_t stage, size_t index); 00244 void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, 00245 const Frustum* frustum = 0); 00249 void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm); 00253 void _setTextureAddressingMode(size_t stage, TextureUnitState::TextureAddressingMode tam); 00257 void _setTextureMatrix(size_t stage, const Matrix4& xform); 00261 void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor); 00265 void _setAlphaRejectSettings(CompareFunction func, unsigned char value); 00269 void _setViewport(Viewport *vp); 00273 void _beginFrame(void); 00277 void _endFrame(void); 00281 void _setCullingMode(CullingMode mode); 00285 void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL); 00289 void _setDepthBufferCheckEnabled(bool enabled = true); 00293 void _setDepthBufferWriteEnabled(bool enabled = true); 00297 void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL); 00301 void _setDepthBias(ushort bias); 00305 void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha); 00309 void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end); 00313 void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00314 Matrix4& dest, bool forGpuProgram = false); 00318 void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 00319 Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false); 00323 void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00324 Matrix4& dest, bool forGpuProgram = false); 00328 void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 00329 bool forGpuProgram); 00333 void setClipPlane (ushort index, Real A, Real B, Real C, Real D); 00337 void enableClipPlane (ushort index, bool enable); 00341 void _setRasterisationMode(SceneDetailLevel level); 00345 void setStencilCheckEnabled(bool enabled); 00348 void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 00349 uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 00350 StencilOperation stencilFailOp = SOP_KEEP, 00351 StencilOperation depthFailOp = SOP_KEEP, 00352 StencilOperation passOp = SOP_KEEP, 00353 bool twoSidedOperation = false); 00357 void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter); 00361 void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy); 00365 void setVertexDeclaration(VertexDeclaration* decl); 00369 void setVertexBufferBinding(VertexBufferBinding* binding); 00373 void _render(const RenderOperation& op); 00377 void bindGpuProgram(GpuProgram* prg); 00381 void unbindGpuProgram(GpuProgramType gptype); 00385 void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params); 00389 void setClipPlanes(const PlaneList& clipPlanes); 00393 void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ; 00394 void clearFrameBuffer(unsigned int buffers, 00395 const ColourValue& colour = ColourValue::Black, 00396 Real depth = 1.0f, unsigned short stencil = 0); 00397 HardwareOcclusionQuery* createHardwareOcclusionQuery(void); 00398 Real getHorizontalTexelOffset(void); 00399 Real getVerticalTexelOffset(void); 00400 Real getMinimumDepthInputValue(void); 00401 Real getMaximumDepthInputValue(void); 00402 00403 // ---------------------------------- 00404 // GLRenderSystem specific members 00405 // ---------------------------------- 00410 void _oneTimeContextInitialization(); 00413 void _switchContext(GLContext *context); 00417 void _setRenderTarget(RenderTarget *target); 00421 void _registerContext(RenderTarget *target, GLContext *context); 00427 void _unregisterContext(RenderTarget *target); 00432 GLContext *_getMainContext(); 00433 }; 00434 } 00435 #endif 00436
Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:45 2006