Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class 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 (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         GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const;
00084 
00085         void setLights();
00086 
00087         // Store last depth write state
00088         bool mDepthWrite;
00089         // Store last stencil mask state
00090         uint32 mStencilMask;
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 system and capabilities
00112         void initGL(RenderTarget *primary);
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 
00134         GLRTTManager *mRTTManager;
00135     public:
00136         // Default constructor / destructor
00137         GLRenderSystem();
00138         ~GLRenderSystem();
00139 
00140         // ----------------------------------
00141         // Overridden RenderSystem functions
00142         // ----------------------------------
00146         const String& getName(void) const;
00150         ConfigOptionMap& getConfigOptions(void);
00154         void setConfigOption(const String &name, const String &value);
00158         String validateConfigOptions(void);
00162         RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
00166         void reinitialise(void); // Used if settings changed mid-rendering
00170         void shutdown(void);
00171 
00175         void setAmbientLight(float r, float g, float b);
00179         void setShadingType(ShadeOptions so);
00183         void setLightingEnabled(bool enabled);
00184         
00186         RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 
00187             bool fullScreen, const NameValuePairList *miscParams = 0);
00188 
00190         virtual MultiRenderTarget * createMultiRenderTarget(const String & name); 
00191         
00195         void destroyRenderWindow(RenderWindow* pWin);
00199         String getErrorDescription(long errorNumber) const;
00200 
00204         VertexElementType getColourVertexElementType(void) const;
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 _setPointParameters(Real size, bool attenuationEnabled, 
00240             Real constant, Real linear, Real quadratic, Real minSize, Real maxSize);
00244         void _setPointSpritesEnabled(bool enabled);
00248         void _setTexture(size_t unit, bool enabled, const String &texname);
00252         void _setTextureCoordSet(size_t stage, size_t index);
00256         void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, 
00257             const Frustum* frustum = 0);
00261         void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm);
00265         void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw);
00269         void _setTextureBorderColour(size_t stage, const ColourValue& colour);
00273         void _setTextureMatrix(size_t stage, const Matrix4& xform);
00277         void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor);
00281         void _setAlphaRejectSettings(CompareFunction func, unsigned char value);
00285         void _setViewport(Viewport *vp);
00289         void _beginFrame(void);
00293         void _endFrame(void);
00297         void _setCullingMode(CullingMode mode);
00301         void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL);
00305         void _setDepthBufferCheckEnabled(bool enabled = true);
00309         void _setDepthBufferWriteEnabled(bool enabled = true);
00313         void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL);
00317         void _setDepthBias(ushort bias);
00321         void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha);
00325         void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end);
00329         void _convertProjectionMatrix(const Matrix4& matrix,
00330             Matrix4& dest, bool forGpuProgram = false);
00334         void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
00335             Matrix4& dest, bool forGpuProgram = false);
00339         void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 
00340             Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false);
00344         void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 
00345             Matrix4& dest, bool forGpuProgram = false);
00349         void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 
00350             bool forGpuProgram);
00354         void setClipPlane (ushort index, Real A, Real B, Real C, Real D);
00358         void enableClipPlane (ushort index, bool enable);
00362         void _setPolygonMode(PolygonMode level);
00366         void setStencilCheckEnabled(bool enabled);
00369         void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 
00370             uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 
00371             StencilOperation stencilFailOp = SOP_KEEP, 
00372             StencilOperation depthFailOp = SOP_KEEP,
00373             StencilOperation passOp = SOP_KEEP, 
00374             bool twoSidedOperation = false);
00378         void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter);
00382         void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy);
00386         void setVertexDeclaration(VertexDeclaration* decl);
00390         void setVertexBufferBinding(VertexBufferBinding* binding);
00394         void _render(const RenderOperation& op);
00398         void bindGpuProgram(GpuProgram* prg);
00402         void unbindGpuProgram(GpuProgramType gptype);
00406         void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params);
00410         void bindGpuProgramPassIterationParameters(GpuProgramType gptype);
00414         void setClipPlanes(const PlaneList& clipPlanes);
00418         void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ;
00419         void clearFrameBuffer(unsigned int buffers, 
00420             const ColourValue& colour = ColourValue::Black, 
00421             Real depth = 1.0f, unsigned short stencil = 0);
00422         HardwareOcclusionQuery* createHardwareOcclusionQuery(void);
00423         Real getHorizontalTexelOffset(void);
00424         Real getVerticalTexelOffset(void);
00425         Real getMinimumDepthInputValue(void);
00426         Real getMaximumDepthInputValue(void);
00427 
00428         // ----------------------------------
00429         // GLRenderSystem specific members
00430         // ----------------------------------
00434         void _oneTimeContextInitialization();
00437         void _switchContext(GLContext *context);
00441         void _setRenderTarget(RenderTarget *target);
00449         void _unregisterContext(GLContext *context);
00453         GLContext *_getMainContext();
00454     };
00455 }
00456 #endif
00457 

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:41 2006