Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreGLRenderSystem.h

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

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:13 2004