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 © 2000-2002 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 00034 #include "OgreGLSupport.h" 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 // view matrix to set world against 00052 Matrix4 mViewMatrix; 00053 Matrix4 mWorldMatrix; 00054 Matrix4 mTextureMatrix; 00055 00056 // Last min & mip filtering options, so we can combine them 00057 FilterOptions mMinFilter; 00058 FilterOptions mMipFilter; 00059 00060 // XXX 8 max texture units? 00061 size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_COORD_SETS]; 00062 00064 GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS]; 00065 00066 void initConfigOptions(void); 00067 void initInputDevices(void); 00068 void processInputDevices(void); 00069 00070 void setGLLight(size_t index, Light* lt); 00071 void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m); 00072 00073 GLint getBlendMode(SceneBlendFactor ogreBlend); 00074 00075 void setLights(); 00076 00077 // Store last depth write state 00078 bool mDepthWrite; 00079 // Store last colour write state 00080 bool mColourWrite[4]; 00081 00082 GLint convertCompareFunction(CompareFunction func); 00083 GLint convertStencilOp(StencilOperation op); 00084 00085 // Save stencil settings since GL insists on having them in groups 00086 // Means we have to call functions more than once, but what the hey 00087 GLint mStencilFunc, mStencilRef; 00088 GLuint mStencilMask; 00089 GLint mStencilFail, mStencilZFail, mStencilPass; 00090 00091 // internal method for anisotrophy validation 00092 GLfloat _getCurrentAnisotropy(size_t unit); 00093 00095 GLSupport* mGLSupport; 00096 00098 void setGLLightPositionDirection(Light* lt, size_t lightindex); 00099 00100 bool mUseAutoTextureMatrix; 00101 GLfloat mAutoTextureMatrix[16]; 00102 00103 // Initialise GL context 00104 void initGL(void); 00105 00106 HardwareBufferManager* mHardwareBufferManager; 00107 GLGpuProgramManager* mGpuProgramManager; 00108 00109 unsigned short mCurrentLights; 00110 00111 GLuint getCombinedMinMipFilter(void); 00112 00113 GLGpuProgram* mCurrentVertexProgram; 00114 GLGpuProgram* mCurrentFragmentProgram; 00115 00116 public: 00117 // Default constructor / destructor 00118 GLRenderSystem(); 00119 ~GLRenderSystem(); 00120 00121 // ---------------------------------- 00122 // Overridden RenderSystem functions 00123 // ---------------------------------- 00127 const String& getName(void) const; 00131 ConfigOptionMap& getConfigOptions(void); 00135 void setConfigOption(const String &name, const String &value); 00139 String validateConfigOptions(void); 00143 RenderWindow* initialise(bool autoCreateWindow); 00147 void reinitialise(void); // Used if settings changed mid-rendering 00151 void shutdown(void); 00152 00156 void setAmbientLight(float r, float g, float b); 00160 void setShadingType(ShadeOptions so); 00164 void setLightingEnabled(bool enabled); 00168 RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, unsigned int colourDepth, 00169 bool fullScreen, int left = 0, int top = 0, bool depthBuffer = true, 00170 RenderWindow* parentWindowHandle = 0); 00171 00172 RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height ); 00173 00177 void destroyRenderWindow(RenderWindow* pWin); 00181 String getErrorDescription(long errorNumber); 00182 00186 void convertColourValue(const ColourValue& colour, unsigned long* pDest); 00190 void setNormaliseNormals(bool normalise); 00191 00192 // ----------------------------- 00193 // Low-level overridden members 00194 // ----------------------------- 00198 void _useLights(const LightList& lights, unsigned short limit); 00202 void _setWorldMatrix(const Matrix4 &m); 00206 void _setViewMatrix(const Matrix4 &m); 00210 void _setProjectionMatrix(const Matrix4 &m); 00214 void _setSurfaceParams(const ColourValue &ambient, 00215 const ColourValue &diffuse, const ColourValue &specular, 00216 const ColourValue &emissive, Real shininess); 00220 void _setTexture(size_t unit, bool enabled, const String &texname); 00224 void _setTextureCoordSet(size_t stage, size_t index); 00228 void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m); 00232 void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm); 00236 void _setTextureAddressingMode(size_t stage, TextureUnitState::TextureAddressingMode tam); 00240 void _setTextureMatrix(size_t stage, const Matrix4& xform); 00244 void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor); 00248 void _setAlphaRejectSettings(CompareFunction func, unsigned char value); 00252 void _setViewport(Viewport *vp); 00256 void _beginFrame(void); 00260 void _endFrame(void); 00264 void _setCullingMode(CullingMode mode); 00268 void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL); 00272 void _setDepthBufferCheckEnabled(bool enabled = true); 00276 void _setDepthBufferWriteEnabled(bool enabled = true); 00280 void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL); 00284 void _setDepthBias(ushort bias); 00288 void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha); 00292 void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end); 00296 void _makeProjectionMatrix(Real fovy, Real aspect, Real nearPlane, Real farPlane, 00297 Matrix4& dest, bool forGpuProgram = false); 00301 void _setRasterisationMode(SceneDetailLevel level); 00305 void setStencilCheckEnabled(bool enabled); 00309 void setStencilBufferFunction(CompareFunction func); 00313 void setStencilBufferReferenceValue(ulong refValue); 00317 void setStencilBufferMask(ulong mask); 00321 void setStencilBufferFailOperation(StencilOperation op); 00325 void setStencilBufferDepthFailOperation(StencilOperation op); 00329 void setStencilBufferPassOperation(StencilOperation op); 00335 void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 00336 ulong refValue = 0, ulong mask = 0xFFFFFFFF, 00337 StencilOperation stencilFailOp = SOP_KEEP, 00338 StencilOperation depthFailOp = SOP_KEEP, 00339 StencilOperation passOp = SOP_KEEP); 00343 void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter); 00347 void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy); 00351 void setVertexDeclaration(VertexDeclaration* decl); 00355 void setVertexBufferBinding(VertexBufferBinding* binding); 00359 void _render(const RenderOperation& op); 00363 void bindGpuProgram(GpuProgram* prg); 00367 void unbindGpuProgram(GpuProgramType gptype); 00371 void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params); 00372 00373 // ---------------------------------- 00374 // End Overridden members 00375 // ---------------------------------- 00376 }; 00377 } 00378 #endif 00379
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:12 2004