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-2013 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 00042 namespace GLSL { 00043 class GLSLProgramFactory; 00044 } 00045 00046 class GLStateCacheManager; 00047 00051 class _OgreGLExport GLRenderSystem : public RenderSystem 00052 { 00053 private: 00055 bool mStopRendering; 00056 00060 #define MAX_LIGHTS 8 00061 Light* mLights[MAX_LIGHTS]; 00062 00064 Matrix4 mViewMatrix; 00065 Matrix4 mWorldMatrix; 00066 Matrix4 mTextureMatrix; 00067 00069 FilterOptions mMinFilter; 00070 FilterOptions mMipFilter; 00071 00073 size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS]; 00074 00076 GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS]; 00077 00079 unsigned short mFixedFunctionTextureUnits; 00080 00081 void initConfigOptions(void); 00082 void initInputDevices(void); 00083 void processInputDevices(void); 00084 00085 void setGLLight(size_t index, Light* lt); 00086 void makeGLMatrix(GLfloat gl_matrix[16], const Matrix4& m); 00087 00088 GLint getBlendMode(SceneBlendFactor ogreBlend) const; 00089 GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const; 00090 void initialiseContext(RenderWindow* primary); 00091 00092 void setLights(); 00093 00095 bool mDepthWrite; 00097 uint32 mStencilWriteMask; 00099 bool mColourWrite[4]; 00100 00102 int mScissorBox[4]; 00103 00104 GLint convertCompareFunction(CompareFunction func) const; 00105 GLint convertStencilOp(StencilOperation op, bool invert = false) const; 00106 00108 GLfloat _getCurrentAnisotropy(size_t unit); 00109 00111 GLSupport* mGLSupport; 00112 00114 void setGLLightPositionDirection(Light* lt, GLenum lightindex); 00115 00116 bool mUseAutoTextureMatrix; 00117 GLfloat mAutoTextureMatrix[16]; 00118 00120 bool mGLInitialised; 00121 00122 HardwareBufferManager* mHardwareBufferManager; 00123 GLGpuProgramManager* mGpuProgramManager; 00124 GLSL::GLSLProgramFactory* mGLSLProgramFactory; 00125 00126 unsigned short mCurrentLights; 00127 00128 GLuint getCombinedMinMipFilter(void) const; 00129 00130 GLGpuProgram* mCurrentVertexProgram; 00131 GLGpuProgram* mCurrentFragmentProgram; 00132 GLGpuProgram* mCurrentGeometryProgram; 00133 00134 /* The main GL context - main thread only */ 00135 GLContext *mMainContext; 00136 /* The current GL context - main thread only */ 00137 GLContext *mCurrentContext; 00138 typedef list<GLContext*>::type GLContextList; 00140 GLContextList mBackgroundContextList; 00141 00142 GLStateCacheManager* mStateCacheManager; 00143 00149 GLRTTManager *mRTTManager; 00150 00151 ushort mActiveTextureUnit; 00152 00153 // local data members of _render that were moved here to improve performance 00154 // (save allocations) 00155 vector<GLuint>::type mRenderAttribsBound; 00156 vector<GLuint>::type mRenderInstanceAttribsBound; 00157 00158 00159 protected: 00160 void setClipPlanesImpl(const PlaneList& clipPlanes); 00161 void bindVertexElementToGpu( const VertexElement &elem, HardwareVertexBufferSharedPtr vertexBuffer, 00162 const size_t vertexStart, 00163 vector<GLuint>::type &attribsBound, vector<GLuint>::type &instanceAttribsBound ); 00164 public: 00165 // Default constructor / destructor 00166 GLRenderSystem(); 00167 ~GLRenderSystem(); 00168 00169 // ---------------------------------- 00170 // Overridden RenderSystem functions 00171 // ---------------------------------- 00175 const String& getName(void) const; 00179 ConfigOptionMap& getConfigOptions(void); 00183 void setConfigOption(const String &name, const String &value); 00187 String validateConfigOptions(void); 00191 RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"); 00195 virtual RenderSystemCapabilities* createRenderSystemCapabilities() const; 00199 void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary); 00203 void reinitialise(void); // Used if settings changed mid-rendering 00207 void shutdown(void); 00208 00212 void setAmbientLight(float r, float g, float b); 00216 void setShadingType(ShadeOptions so); 00220 void setLightingEnabled(bool enabled); 00221 00223 RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 00224 bool fullScreen, const NameValuePairList *miscParams = 0); 00225 00227 bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions, 00228 RenderWindowList& createdWindows); 00229 00231 DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget ); 00232 00234 void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat, 00235 GLenum *stencilFormat ); 00236 00238 virtual MultiRenderTarget * createMultiRenderTarget(const String & name); 00239 00243 void destroyRenderWindow(RenderWindow* pWin); 00247 String getErrorDescription(long errorNumber) const; 00248 00252 VertexElementType getColourVertexElementType(void) const; 00256 void setNormaliseNormals(bool normalise); 00257 00258 // ----------------------------- 00259 // Low-level overridden members 00260 // ----------------------------- 00264 void _useLights(const LightList& lights, unsigned short limit); 00268 bool areFixedFunctionLightsInViewSpace() const { return true; } 00272 void _setWorldMatrix(const Matrix4 &m); 00276 void _setViewMatrix(const Matrix4 &m); 00280 void _setProjectionMatrix(const Matrix4 &m); 00284 void _setSurfaceParams(const ColourValue &ambient, 00285 const ColourValue &diffuse, const ColourValue &specular, 00286 const ColourValue &emissive, Real shininess, 00287 TrackVertexColourType tracking); 00291 void _setPointParameters(Real size, bool attenuationEnabled, 00292 Real constant, Real linear, Real quadratic, Real minSize, Real maxSize); 00296 void _setPointSpritesEnabled(bool enabled); 00300 void _setTexture(size_t unit, bool enabled, const TexturePtr &tex); 00304 void _setTextureCoordSet(size_t stage, size_t index); 00308 void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, 00309 const Frustum* frustum = 0); 00313 void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm); 00317 void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw); 00321 void _setTextureBorderColour(size_t stage, const ColourValue& colour); 00325 void _setTextureMipmapBias(size_t unit, float bias); 00329 void _setTextureMatrix(size_t stage, const Matrix4& xform); 00333 void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op ); 00337 void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp ); 00341 void _setSceneBlendingOperation(SceneBlendOperation op); 00345 void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp); 00349 void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage); 00353 void _setViewport(Viewport *vp); 00357 void _beginFrame(void); 00361 void _endFrame(void); 00365 void _setCullingMode(CullingMode mode); 00369 void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL); 00373 void _setDepthBufferCheckEnabled(bool enabled = true); 00377 void _setDepthBufferWriteEnabled(bool enabled = true); 00381 void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL); 00385 void _setDepthBias(float constantBias, float slopeScaleBias); 00389 void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha); 00393 void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end); 00397 void _convertProjectionMatrix(const Matrix4& matrix, 00398 Matrix4& dest, bool forGpuProgram = false); 00402 void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00403 Matrix4& dest, bool forGpuProgram = false); 00407 void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 00408 Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false); 00412 void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00413 Matrix4& dest, bool forGpuProgram = false); 00417 void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 00418 bool forGpuProgram); 00422 void setClipPlane (ushort index, Real A, Real B, Real C, Real D); 00426 void enableClipPlane (ushort index, bool enable); 00430 void _setPolygonMode(PolygonMode level); 00434 void setStencilCheckEnabled(bool enabled); 00438 void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 00439 uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF, 00440 StencilOperation stencilFailOp = SOP_KEEP, 00441 StencilOperation depthFailOp = SOP_KEEP, 00442 StencilOperation passOp = SOP_KEEP, 00443 bool twoSidedOperation = false); 00447 void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter); 00451 void _setTextureUnitCompareFunction(size_t unit, CompareFunction function); 00455 void _setTextureUnitCompareEnabled(size_t unit, bool compare); 00459 void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy); 00463 void setVertexDeclaration(VertexDeclaration* decl); 00467 void setVertexBufferBinding(VertexBufferBinding* binding); 00471 void _render(const RenderOperation& op); 00472 00476 void bindGpuProgram(GpuProgram* prg); 00480 void unbindGpuProgram(GpuProgramType gptype); 00484 void bindGpuProgramParameters(GpuProgramType gptype, 00485 GpuProgramParametersSharedPtr params, uint16 variabilityMask); 00489 void bindGpuProgramPassIterationParameters(GpuProgramType gptype); 00493 void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600) ; 00494 void clearFrameBuffer(unsigned int buffers, 00495 const ColourValue& colour = ColourValue::Black, 00496 Real depth = 1.0f, unsigned short stencil = 0); 00497 HardwareOcclusionQuery* createHardwareOcclusionQuery(void); 00498 Real getHorizontalTexelOffset(void); 00499 Real getVerticalTexelOffset(void); 00500 Real getMinimumDepthInputValue(void); 00501 Real getMaximumDepthInputValue(void); 00502 OGRE_MUTEX(mThreadInitMutex); 00503 void registerThread(); 00504 void unregisterThread(); 00505 void preExtraThreadsStarted(); 00506 void postExtraThreadsStarted(); 00507 GLSupport* getGLSupportRef() { return mGLSupport; } 00508 00509 // ---------------------------------- 00510 // GLRenderSystem specific members 00511 // ---------------------------------- 00515 void _oneTimeContextInitialization(); 00518 void _switchContext(GLContext *context); 00522 void _setRenderTarget(RenderTarget *target); 00530 void _unregisterContext(GLContext *context); 00532 GLContext* _getMainContext() {return mMainContext;} 00533 00535 unsigned int getDisplayMonitorCount() const; 00536 00538 virtual bool hasAnisotropicMipMapFilter() const { return false; } 00539 00541 virtual void beginProfileEvent( const String &eventName ); 00542 00544 virtual void endProfileEvent( void ); 00545 00547 virtual void markProfileEvent( const String &eventName ); 00548 }; 00549 } 00550 #endif 00551
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:42