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 #include "OgreVector4.h" 00034 00035 00036 namespace Ogre { 00040 class GLRenderSystem : public RenderSystem 00041 { 00042 public: 00043 virtual void setExternalWindowHandle(void *ptr){mExternalWindowHandle = ptr;}; 00044 virtual void resizeRepositionWindow(void*); 00045 00046 private: 00047 void* mExternalWindowHandle; 00048 00049 // Rendering loop control 00050 bool mStopRendering; 00051 00052 // Array of up to 8 lights, indexed as per API 00053 // Note that a null value indicates a free slot 00054 #define MAX_LIGHTS 8 00055 Light* mLights[MAX_LIGHTS]; 00056 00057 // clip planes 00058 typedef std::vector<Vector4> PlaneList2; 00059 PlaneList2 mClipPlanes; 00060 void setGLClipPlanes() const; 00061 00062 00063 // view matrix to set world against 00064 Matrix4 mViewMatrix; 00065 Matrix4 mWorldMatrix; 00066 Matrix4 mTextureMatrix; 00067 00068 // Last min & mip filtering options, so we can combine them 00069 FilterOptions mMinFilter; 00070 FilterOptions mMipFilter; 00071 00072 // XXX 8 max texture units? 00073 size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_COORD_SETS]; 00074 00076 GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS]; 00077 00078 void initConfigOptions(void); 00079 void initInputDevices(void); 00080 void processInputDevices(void); 00081 00082 void setGLLight(size_t index, Light* lt); 00083 void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m); 00084 00085 GLint getBlendMode(SceneBlendFactor ogreBlend) const; 00086 00087 void setLights(); 00088 00089 // Store last depth write state 00090 bool mDepthWrite; 00091 // Store last colour write state 00092 bool mColourWrite[4]; 00093 00094 GLint convertCompareFunction(CompareFunction func) const; 00095 GLint convertStencilOp(StencilOperation op, bool invert = false) const; 00096 00097 // internal method for anisotrophy validation 00098 GLfloat _getCurrentAnisotropy(size_t unit); 00099 00101 GLSupport* mGLSupport; 00102 00104 void setGLLightPositionDirection(Light* lt, size_t lightindex); 00105 00106 bool mUseAutoTextureMatrix; 00107 GLfloat mAutoTextureMatrix[16]; 00108 00109 // check if the GL system has already been initialized 00110 bool mGLInitialized; 00111 // Initialise GL context 00112 void initGL(void); 00113 00114 HardwareBufferManager* mHardwareBufferManager; 00115 GLGpuProgramManager* mGpuProgramManager; 00116 00117 unsigned short mCurrentLights; 00118 00119 GLuint getCombinedMinMipFilter(void) const; 00120 00121 GLGpuProgram* mCurrentVertexProgram; 00122 GLGpuProgram* mCurrentFragmentProgram; 00123 00124 public: 00125 // Default constructor / destructor 00126 GLRenderSystem(); 00127 ~GLRenderSystem(); 00128 00129 // ---------------------------------- 00130 // Overridden RenderSystem functions 00131 // ---------------------------------- 00135 const String& getName(void) const; 00139 ConfigOptionMap& getConfigOptions(void); 00143 void setConfigOption(const String &name, const String &value); 00147 String validateConfigOptions(void); 00151 RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"); 00155 void reinitialise(void); // Used if settings changed mid-rendering 00159 void shutdown(void); 00160 00164 void setAmbientLight(float r, float g, float b); 00168 void setShadingType(ShadeOptions so); 00172 void setLightingEnabled(bool enabled); 00176 RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, unsigned int colourDepth, 00177 bool fullScreen, int left = 0, int top = 0, bool depthBuffer = true, 00178 RenderWindow* parentWindowHandle = 0); 00179 00180 RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height ); 00181 00185 void destroyRenderWindow(RenderWindow* pWin); 00189 String getErrorDescription(long errorNumber) const; 00190 00194 void convertColourValue(const ColourValue& colour, unsigned long* pDest); 00198 void setNormaliseNormals(bool normalise); 00199 00200 // ----------------------------- 00201 // Low-level overridden members 00202 // ----------------------------- 00206 void _useLights(const LightList& lights, unsigned short limit); 00210 void _setWorldMatrix(const Matrix4 &m); 00214 void _setViewMatrix(const Matrix4 &m); 00218 void _setProjectionMatrix(const Matrix4 &m); 00222 void _setSurfaceParams(const ColourValue &ambient, 00223 const ColourValue &diffuse, const ColourValue &specular, 00224 const ColourValue &emissive, Real shininess); 00228 void _setTexture(size_t unit, bool enabled, const String &texname); 00232 void _setTextureCoordSet(size_t stage, size_t index); 00236 void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, 00237 const Frustum* frustum = 0); 00241 void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm); 00245 void _setTextureAddressingMode(size_t stage, TextureUnitState::TextureAddressingMode tam); 00249 void _setTextureMatrix(size_t stage, const Matrix4& xform); 00253 void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor); 00257 void _setAlphaRejectSettings(CompareFunction func, unsigned char value); 00261 void _setViewport(Viewport *vp); 00265 void _beginFrame(void); 00269 void _endFrame(void); 00273 void _setCullingMode(CullingMode mode); 00277 void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL); 00281 void _setDepthBufferCheckEnabled(bool enabled = true); 00285 void _setDepthBufferWriteEnabled(bool enabled = true); 00289 void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL); 00293 void _setDepthBias(ushort bias); 00297 void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha); 00301 void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end); 00305 void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00306 Matrix4& dest, bool forGpuProgram = false); 00310 void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 00311 Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false); 00315 void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00316 Matrix4& dest, bool forGpuProgram = false); 00320 void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 00321 bool forGpuProgram); 00325 void setClipPlane (ushort index, Real A, Real B, Real C, Real D); 00329 void enableClipPlane (ushort index, bool enable); 00333 void _setRasterisationMode(SceneDetailLevel level); 00337 void setStencilCheckEnabled(bool enabled); 00340 void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 00341 ulong refValue = 0, ulong mask = 0xFFFFFFFF, 00342 StencilOperation stencilFailOp = SOP_KEEP, 00343 StencilOperation depthFailOp = SOP_KEEP, 00344 StencilOperation passOp = SOP_KEEP, 00345 bool twoSidedOperation = false); 00349 void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter); 00353 void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy); 00357 void setVertexDeclaration(VertexDeclaration* decl); 00361 void setVertexBufferBinding(VertexBufferBinding* binding); 00365 void _render(const RenderOperation& op); 00369 void bindGpuProgram(GpuProgram* prg); 00373 void unbindGpuProgram(GpuProgramType gptype); 00377 void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params); 00381 void setClipPlanes(const PlaneList& clipPlanes); 00385 void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ; 00386 void clearFrameBuffer(unsigned int buffers, 00387 const ColourValue& colour = ColourValue::Black, 00388 Real depth = 1.0f, unsigned short stencil = 0); 00389 HardwareOcclusionQuery* createHardwareOcclusionQuery(void); 00390 Real getHorizontalTexelOffset(void); 00391 Real getVerticalTexelOffset(void); 00392 Real getMinimumDepthInputValue(void); 00393 Real getMaximumDepthInputValue(void); 00394 00395 // ---------------------------------- 00396 // End Overridden members 00397 // ---------------------------------- 00398 }; 00399 } 00400 #endif 00401
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:26 2004