00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org 00006 00007 Copyright (c) 2000-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __GLRenderSystem_H__ 00029 #define __GLRenderSystem_H__ 00030 00031 #include "OgreGLPrerequisites.h" 00032 #include "OgrePlatform.h" 00033 #include "OgreRenderSystem.h" 00034 #include "OgreGLHardwareBufferManager.h" 00035 #include "OgreGLGpuProgramManager.h" 00036 #include "OgreVector4.h" 00037 00038 00039 namespace Ogre { 00040 00041 class GLSLProgramFactory; 00042 00046 class _OgreGLExport GLRenderSystem : public RenderSystem 00047 { 00048 private: 00050 bool mStopRendering; 00051 00055 #define MAX_LIGHTS 8 00056 Light* mLights[MAX_LIGHTS]; 00057 00059 Matrix4 mViewMatrix; 00060 Matrix4 mWorldMatrix; 00061 Matrix4 mTextureMatrix; 00062 00064 FilterOptions mMinFilter; 00065 FilterOptions mMipFilter; 00066 00068 size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS]; 00069 00071 GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS]; 00072 00074 unsigned short mFixedFunctionTextureUnits; 00075 00076 void initConfigOptions(void); 00077 void initInputDevices(void); 00078 void processInputDevices(void); 00079 00080 void setGLLight(size_t index, Light* lt); 00081 void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m); 00082 00083 GLint getBlendMode(SceneBlendFactor ogreBlend) const; 00084 GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const; 00085 void initialiseContext(RenderWindow* primary); 00086 00087 void setLights(); 00088 00090 bool mDepthWrite; 00092 uint32 mStencilMask; 00094 bool mColourWrite[4]; 00095 00096 GLint convertCompareFunction(CompareFunction func) const; 00097 GLint convertStencilOp(StencilOperation op, bool invert = false) const; 00098 00100 GLfloat _getCurrentAnisotropy(size_t unit); 00101 00103 GLSupport* mGLSupport; 00104 00106 void setGLLightPositionDirection(Light* lt, GLenum lightindex); 00107 00108 bool mUseAutoTextureMatrix; 00109 GLfloat mAutoTextureMatrix[16]; 00110 00112 bool mGLInitialised; 00113 00114 HardwareBufferManager* mHardwareBufferManager; 00115 GLGpuProgramManager* mGpuProgramManager; 00116 GLSLProgramFactory* mGLSLProgramFactory; 00117 00118 unsigned short mCurrentLights; 00119 00120 GLuint getCombinedMinMipFilter(void) const; 00121 00122 GLGpuProgram* mCurrentVertexProgram; 00123 GLGpuProgram* mCurrentFragmentProgram; 00124 GLGpuProgram* mCurrentGeometryProgram; 00125 00126 /* The main GL context - main thread only */ 00127 GLContext *mMainContext; 00128 /* The current GL context - main thread only */ 00129 GLContext *mCurrentContext; 00130 typedef list<GLContext*>::type GLContextList; 00132 GLContextList mBackgroundContextList; 00133 00139 GLRTTManager *mRTTManager; 00140 00141 ushort mActiveTextureUnit; 00142 00143 // local data members of _render that were moved here to improve performance 00144 // (save allocations) 00145 vector<GLuint>::type mRenderAttribsBound; 00146 vector<GLuint>::type mRenderInstanceAttribsBound; 00147 00148 00149 protected: 00150 void setClipPlanesImpl(const PlaneList& clipPlanes); 00151 bool activateGLTextureUnit(size_t unit); 00152 void bindVertexElementToGpu( const VertexElement &elem, HardwareVertexBufferSharedPtr vertexBuffer, 00153 const size_t vertexStart, 00154 vector<GLuint>::type &attribsBound, vector<GLuint>::type &instanceAttribsBound ); 00155 public: 00156 // Default constructor / destructor 00157 GLRenderSystem(); 00158 ~GLRenderSystem(); 00159 00160 // ---------------------------------- 00161 // Overridden RenderSystem functions 00162 // ---------------------------------- 00166 const String& getName(void) const; 00170 ConfigOptionMap& getConfigOptions(void); 00174 void setConfigOption(const String &name, const String &value); 00178 String validateConfigOptions(void); 00182 RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"); 00186 virtual RenderSystemCapabilities* createRenderSystemCapabilities() const; 00190 void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary); 00194 void reinitialise(void); // Used if settings changed mid-rendering 00198 void shutdown(void); 00199 00203 void setAmbientLight(float r, float g, float b); 00207 void setShadingType(ShadeOptions so); 00211 void setLightingEnabled(bool enabled); 00212 00214 RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 00215 bool fullScreen, const NameValuePairList *miscParams = 0); 00216 00218 bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions, 00219 RenderWindowList& createdWindows); 00220 00222 DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget ); 00223 00225 void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat, 00226 GLenum *stencilFormat ); 00227 00229 virtual MultiRenderTarget * createMultiRenderTarget(const String & name); 00230 00234 void destroyRenderWindow(RenderWindow* pWin); 00238 String getErrorDescription(long errorNumber) const; 00239 00243 VertexElementType getColourVertexElementType(void) const; 00247 void setNormaliseNormals(bool normalise); 00248 00249 // ----------------------------- 00250 // Low-level overridden members 00251 // ----------------------------- 00255 void _useLights(const LightList& lights, unsigned short limit); 00259 bool areFixedFunctionLightsInViewSpace() const { return true; } 00263 void _setWorldMatrix(const Matrix4 &m); 00267 void _setViewMatrix(const Matrix4 &m); 00271 void _setProjectionMatrix(const Matrix4 &m); 00275 void _setSurfaceParams(const ColourValue &ambient, 00276 const ColourValue &diffuse, const ColourValue &specular, 00277 const ColourValue &emissive, Real shininess, 00278 TrackVertexColourType tracking); 00282 void _setPointParameters(Real size, bool attenuationEnabled, 00283 Real constant, Real linear, Real quadratic, Real minSize, Real maxSize); 00287 void _setPointSpritesEnabled(bool enabled); 00291 void _setTexture(size_t unit, bool enabled, const TexturePtr &tex); 00295 void _setTextureCoordSet(size_t stage, size_t index); 00299 void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, 00300 const Frustum* frustum = 0); 00304 void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm); 00308 void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw); 00312 void _setTextureBorderColour(size_t stage, const ColourValue& colour); 00316 void _setTextureMipmapBias(size_t unit, float bias); 00320 void _setTextureMatrix(size_t stage, const Matrix4& xform); 00324 void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op ); 00328 void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp ); 00332 void _setSceneBlendingOperation(SceneBlendOperation op); 00336 void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp); 00340 void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage); 00344 void _setViewport(Viewport *vp); 00348 void _beginFrame(void); 00352 void _endFrame(void); 00356 void _setCullingMode(CullingMode mode); 00360 void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL); 00364 void _setDepthBufferCheckEnabled(bool enabled = true); 00368 void _setDepthBufferWriteEnabled(bool enabled = true); 00372 void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL); 00376 void _setDepthBias(float constantBias, float slopeScaleBias); 00380 void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha); 00384 void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end); 00388 void _convertProjectionMatrix(const Matrix4& matrix, 00389 Matrix4& dest, bool forGpuProgram = false); 00393 void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00394 Matrix4& dest, bool forGpuProgram = false); 00398 void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 00399 Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false); 00403 void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00404 Matrix4& dest, bool forGpuProgram = false); 00408 void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 00409 bool forGpuProgram); 00413 void setClipPlane (ushort index, Real A, Real B, Real C, Real D); 00417 void enableClipPlane (ushort index, bool enable); 00421 void _setPolygonMode(PolygonMode level); 00425 void setStencilCheckEnabled(bool enabled); 00429 void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 00430 uint32 refValue = 0, uint32 mask = 0xFFFFFFFF, 00431 StencilOperation stencilFailOp = SOP_KEEP, 00432 StencilOperation depthFailOp = SOP_KEEP, 00433 StencilOperation passOp = SOP_KEEP, 00434 bool twoSidedOperation = false); 00438 void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter); 00442 void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy); 00446 void setVertexDeclaration(VertexDeclaration* decl); 00450 void setVertexBufferBinding(VertexBufferBinding* binding); 00454 void _render(const RenderOperation& op); 00455 00459 void bindGpuProgram(GpuProgram* prg); 00463 void unbindGpuProgram(GpuProgramType gptype); 00467 void bindGpuProgramParameters(GpuProgramType gptype, 00468 GpuProgramParametersSharedPtr params, uint16 variabilityMask); 00472 void bindGpuProgramPassIterationParameters(GpuProgramType gptype); 00476 void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ; 00477 void clearFrameBuffer(unsigned int buffers, 00478 const ColourValue& colour = ColourValue::Black, 00479 Real depth = 1.0f, unsigned short stencil = 0); 00480 HardwareOcclusionQuery* createHardwareOcclusionQuery(void); 00481 Real getHorizontalTexelOffset(void); 00482 Real getVerticalTexelOffset(void); 00483 Real getMinimumDepthInputValue(void); 00484 Real getMaximumDepthInputValue(void); 00485 OGRE_MUTEX(mThreadInitMutex) 00486 void registerThread(); 00487 void unregisterThread(); 00488 void preExtraThreadsStarted(); 00489 void postExtraThreadsStarted(); 00490 00491 // ---------------------------------- 00492 // GLRenderSystem specific members 00493 // ---------------------------------- 00497 void _oneTimeContextInitialization(); 00500 void _switchContext(GLContext *context); 00504 void _setRenderTarget(RenderTarget *target); 00512 void _unregisterContext(GLContext *context); 00514 GLContext* _getMainContext() {return mMainContext;} 00515 00517 unsigned int getDisplayMonitorCount() const; 00518 00520 virtual void beginProfileEvent( const String &eventName ); 00521 00523 virtual void endProfileEvent( void ); 00524 00526 virtual void markProfileEvent( const String &eventName ); 00527 }; 00528 } 00529 #endif 00530
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21