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 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, GLenum 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 /* The main GL context */ 00125 GLContext *mMainContext; 00126 /* The current GL context */ 00127 GLContext *mCurrentContext; 00128 /* Type that maps render targets to contexts */ 00129 typedef std::map<RenderTarget*,GLContext*> ContextMap; 00130 /* Map of render target -> context mappings. This is used to find the 00131 * GL context for a certain render target */ 00132 ContextMap mContextMap; 00133 public: 00134 // Default constructor / destructor 00135 GLRenderSystem(); 00136 ~GLRenderSystem(); 00137 00138 // ---------------------------------- 00139 // Overridden RenderSystem functions 00140 // ---------------------------------- 00144 const String& getName(void) const; 00148 ConfigOptionMap& getConfigOptions(void); 00152 void setConfigOption(const String &name, const String &value); 00156 String validateConfigOptions(void); 00160 RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"); 00164 void reinitialise(void); // Used if settings changed mid-rendering 00168 void shutdown(void); 00169 00173 void setAmbientLight(float r, float g, float b); 00177 void setShadingType(ShadeOptions so); 00181 void setLightingEnabled(bool enabled); 00182 00184 RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 00185 bool fullScreen, const NameValuePairList *miscParams = 0); 00186 00188 RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height, 00189 TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8, 00190 const NameValuePairList *miscParams = 0 ); 00191 00195 void destroyRenderWindow(RenderWindow* pWin); 00199 String getErrorDescription(long errorNumber) const; 00200 00204 void convertColourValue(const ColourValue& colour, uint32* pDest); 00208 void setNormaliseNormals(bool normalise); 00209 00210 // ----------------------------- 00211 // Low-level overridden members 00212 // ----------------------------- 00216 void _useLights(const LightList& lights, unsigned short limit); 00220 void _setWorldMatrix(const Matrix4 &m); 00224 void _setViewMatrix(const Matrix4 &m); 00228 void _setProjectionMatrix(const Matrix4 &m); 00232 void _setSurfaceParams(const ColourValue &ambient, 00233 const ColourValue &diffuse, const ColourValue &specular, 00234 const ColourValue &emissive, Real shininess, 00235 TrackVertexColourType tracking); 00239 void _setTexture(size_t unit, bool enabled, const String &texname); 00243 void _setTextureCoordSet(size_t stage, size_t index); 00247 void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, 00248 const Frustum* frustum = 0); 00252 void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm); 00256 void _setTextureAddressingMode(size_t stage, TextureUnitState::TextureAddressingMode tam); 00260 void _setTextureMatrix(size_t stage, const Matrix4& xform); 00264 void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor); 00268 void _setAlphaRejectSettings(CompareFunction func, unsigned char value); 00272 void _setViewport(Viewport *vp); 00276 void _beginFrame(void); 00280 void _endFrame(void); 00284 void _setCullingMode(CullingMode mode); 00288 void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL); 00292 void _setDepthBufferCheckEnabled(bool enabled = true); 00296 void _setDepthBufferWriteEnabled(bool enabled = true); 00300 void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL); 00304 void _setDepthBias(ushort bias); 00308 void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha); 00312 void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end); 00316 void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00317 Matrix4& dest, bool forGpuProgram = false); 00321 void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 00322 Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false); 00326 void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00327 Matrix4& dest, bool forGpuProgram = false); 00331 void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 00332 bool forGpuProgram); 00336 void setClipPlane (ushort index, Real A, Real B, Real C, Real D); 00340 void enableClipPlane (ushort index, bool enable); 00344 void _setRasterisationMode(SceneDetailLevel level); 00348 void setStencilCheckEnabled(bool enabled); 00351 void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 00352 uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 00353 StencilOperation stencilFailOp = SOP_KEEP, 00354 StencilOperation depthFailOp = SOP_KEEP, 00355 StencilOperation passOp = SOP_KEEP, 00356 bool twoSidedOperation = false); 00360 void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter); 00364 void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy); 00368 void setVertexDeclaration(VertexDeclaration* decl); 00372 void setVertexBufferBinding(VertexBufferBinding* binding); 00376 void _render(const RenderOperation& op); 00380 void bindGpuProgram(GpuProgram* prg); 00384 void unbindGpuProgram(GpuProgramType gptype); 00388 void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params); 00392 void setClipPlanes(const PlaneList& clipPlanes); 00396 void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ; 00397 void clearFrameBuffer(unsigned int buffers, 00398 const ColourValue& colour = ColourValue::Black, 00399 Real depth = 1.0f, unsigned short stencil = 0); 00400 HardwareOcclusionQuery* createHardwareOcclusionQuery(void); 00401 Real getHorizontalTexelOffset(void); 00402 Real getVerticalTexelOffset(void); 00403 Real getMinimumDepthInputValue(void); 00404 Real getMaximumDepthInputValue(void); 00405 00406 // ---------------------------------- 00407 // GLRenderSystem specific members 00408 // ---------------------------------- 00413 void _oneTimeContextInitialization(); 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
Last modified Sun Apr 10 23:21:15 2005