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 00029 #ifndef __GL3PlusRenderSystem_H__ 00030 #define __GL3PlusRenderSystem_H__ 00031 00032 #include "OgreGL3PlusPrerequisites.h" 00033 00034 #include "OgreMaterialManager.h" 00035 #include "OgreRenderSystem.h" 00036 #include "OgreGL3PlusGpuProgram.h" 00037 00038 namespace Ogre { 00039 class GL3PlusContext; 00040 class GL3PlusSupport; 00041 class GL3PlusRTTManager; 00042 class GL3PlusGpuProgramManager; 00043 class GLSLProgramFactory; 00044 class GLSLGpuProgram; 00045 class GLSLLinkProgram; 00046 class HardwareBufferManager; 00047 00051 class _OgreGL3PlusExport GL3PlusRenderSystem : public RenderSystem 00052 { 00053 private: 00055 bool mStopRendering; 00056 00057 typedef HashMap<GLenum, GLuint> BindBufferMap; 00058 00060 Matrix4 mViewMatrix; 00061 Matrix4 mWorldMatrix; 00062 Matrix4 mTextureMatrix; 00063 00065 FilterOptions mMinFilter; 00066 FilterOptions mMipFilter; 00067 00068 bool mTextureCompareEnabled; 00069 00073 size_t mTextureMipmapCount; 00074 00076 size_t mTextureCoordIndex[OGRE_MAX_TEXTURE_LAYERS]; 00077 00079 GLenum mTextureTypes[OGRE_MAX_TEXTURE_LAYERS]; 00080 00082 unsigned short mFixedFunctionTextureUnits; 00083 00084 void initConfigOptions(void); 00085 00087 bool mColourWrite[4]; 00088 00090 bool mDepthWrite; 00091 00093 uint32 mStencilWriteMask; 00094 00095 GLfloat mAutoTextureMatrix[16]; 00096 00097 bool mUseAutoTextureMatrix; 00098 00100 GL3PlusSupport *mGLSupport; 00101 00102 /* The main GL context - main thread only */ 00103 GL3PlusContext *mMainContext; 00104 00105 /* The current GL context - main thread only */ 00106 GL3PlusContext *mCurrentContext; 00107 00108 typedef list<GL3PlusContext*>::type GL3PlusContextList; 00110 GL3PlusContextList mBackgroundContextList; 00111 00112 GL3PlusGpuProgramManager *mGpuProgramManager; 00113 GLSLProgramFactory* mGLSLProgramFactory; 00114 HardwareBufferManager* mHardwareBufferManager; 00115 00121 GL3PlusRTTManager *mRTTManager; 00122 00127 GLenum mActiveTextureUnit; 00128 BindBufferMap mActiveBufferMap; 00129 00131 bool mGLInitialised; 00132 00133 // local data members of _render that were moved here to improve performance 00134 // (save allocations) 00135 vector<GLuint>::type mRenderAttribsBound; 00136 vector<GLuint>::type mRenderInstanceAttribsBound; 00137 00141 GLenum mPolygonMode; 00142 00143 GLint getCombinedMinMipFilter(void) const; 00144 00145 GL3PlusGpuProgram* mCurrentVertexProgram; 00146 GL3PlusGpuProgram* mCurrentFragmentProgram; 00147 GL3PlusGpuProgram* mCurrentGeometryProgram; 00148 GL3PlusGpuProgram* mCurrentHullProgram; 00149 GL3PlusGpuProgram* mCurrentDomainProgram; 00150 GL3PlusGpuProgram* mCurrentComputeProgram; 00151 00152 GLint getTextureAddressingMode(TextureUnitState::TextureAddressingMode tam) const; 00153 GLenum getBlendMode(SceneBlendFactor ogreBlend) const; 00154 00155 bool activateGLTextureUnit(size_t unit); 00156 void bindVertexElementToGpu( const VertexElement &elem, HardwareVertexBufferSharedPtr vertexBuffer, 00157 const size_t vertexStart, 00158 vector<GLuint>::type &attribsBound, 00159 vector<GLuint>::type &instanceAttribsBound, 00160 bool updateVAO); 00161 00162 public: 00163 // Default constructor / destructor 00164 GL3PlusRenderSystem(); 00165 ~GL3PlusRenderSystem(); 00166 00167 friend class ShaderGeneratorTechniqueResolverListener; 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); 00211 void setAmbientLight(float r, float g, float b) { }; // Not supported 00215 void setShadingType(ShadeOptions so) { }; // Not supported 00219 void setLightingEnabled(bool enabled) { }; // Not supported 00220 00222 RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 00223 bool fullScreen, const NameValuePairList *miscParams = 0); 00224 00226 bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions, 00227 RenderWindowList& createdWindows); 00228 00230 DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget ); 00231 00233 void _getDepthStencilFormatFor( GLenum internalColourFormat, GLenum *depthFormat, 00234 GLenum *stencilFormat ); 00235 00237 virtual MultiRenderTarget * createMultiRenderTarget(const String & name); 00238 00242 void destroyRenderWindow(RenderWindow* pWin); 00246 String getErrorDescription(long errorNumber) const; 00250 VertexElementType getColourVertexElementType(void) const; 00254 void setNormaliseNormals(bool normalise) { }; // Not supported 00255 00256 // ----------------------------- 00257 // Low-level overridden members 00258 // ----------------------------- 00262 void _useLights(const LightList& lights, unsigned short limit) { }; // Not supported 00266 bool areFixedFunctionLightsInViewSpace() const { return true; } 00270 void _setWorldMatrix(const Matrix4 &m); 00274 void _setViewMatrix(const Matrix4 &m); 00278 void _setProjectionMatrix(const Matrix4 &m); 00282 void _setSurfaceParams(const ColourValue &ambient, 00283 const ColourValue &diffuse, const ColourValue &specular, 00284 const ColourValue &emissive, Real shininess, 00285 TrackVertexColourType tracking) {} 00289 void _setPointParameters(Real size, bool attenuationEnabled, 00290 Real constant, Real linear, Real quadratic, Real minSize, Real maxSize); 00294 void _setPointSpritesEnabled(bool enabled); 00298 void _setTexture(size_t unit, bool enabled, const TexturePtr &tex); 00302 void _setTextureCoordSet(size_t stage, size_t index); 00306 void _setTextureCoordCalculation(size_t stage, TexCoordCalcMethod m, 00307 const Frustum* frustum = 0) { }; // Not supported 00311 void _setTextureBlendMode(size_t stage, const LayerBlendModeEx& bm) { }; // Not supported 00315 void _setTextureAddressingMode(size_t stage, const TextureUnitState::UVWAddressingMode& uvw); 00319 void _setTextureBorderColour(size_t stage, const ColourValue& colour); 00323 void _setTextureMipmapBias(size_t unit, float bias); 00327 void _setTextureMatrix(size_t stage, const Matrix4& xform) { }; // Not supported 00331 void _setViewport(Viewport *vp); 00335 void _beginFrame(void); 00339 void _endFrame(void); 00343 void _setCullingMode(CullingMode mode); 00347 void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL); 00351 void _setDepthBufferCheckEnabled(bool enabled = true); 00355 void _setDepthBufferWriteEnabled(bool enabled = true); 00359 void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL); 00363 void _setDepthBias(float constantBias, float slopeScaleBias); 00367 void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha); 00371 void _setFog(FogMode mode, const ColourValue& colour, Real density, Real start, Real end); 00375 void _convertProjectionMatrix(const Matrix4& matrix, 00376 Matrix4& dest, bool forGpuProgram = false); 00380 void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00381 Matrix4& dest, bool forGpuProgram = false); 00385 void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top, 00386 Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false); 00390 void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane, 00391 Matrix4& dest, bool forGpuProgram = false); 00395 void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane, 00396 bool forGpuProgram); 00400 void setClipPlane (ushort index, Real A, Real B, Real C, Real D); 00404 void enableClipPlane (ushort index, bool enable); 00408 void _setPolygonMode(PolygonMode level); 00412 void setStencilCheckEnabled(bool enabled); 00416 void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, 00417 uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF, 00418 StencilOperation stencilFailOp = SOP_KEEP, 00419 StencilOperation depthFailOp = SOP_KEEP, 00420 StencilOperation passOp = SOP_KEEP, 00421 bool twoSidedOperation = false); 00425 void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter); 00429 void _setTextureUnitCompareFunction(size_t unit, CompareFunction function); 00433 void _setTextureUnitCompareEnabled(size_t unit, bool compare); 00437 void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy); 00441 void setVertexDeclaration(VertexDeclaration* decl) {} 00445 void setVertexDeclaration(VertexDeclaration* decl, VertexBufferBinding* binding) {} 00449 void setVertexBufferBinding(VertexBufferBinding* binding) {} 00453 void _render(const RenderOperation& op); 00457 void setScissorTest(bool enabled, size_t left = 0, size_t top = 0, size_t right = 800, size_t bottom = 600); 00458 00459 void clearFrameBuffer(unsigned int buffers, 00460 const ColourValue& colour = ColourValue::Black, 00461 Real depth = 1.0f, unsigned short stencil = 0); 00462 HardwareOcclusionQuery* createHardwareOcclusionQuery(void); 00463 Real getHorizontalTexelOffset(void) { return 0.0; } // No offset in GL 00464 Real getVerticalTexelOffset(void) { return 0.0; } // No offset in GL 00465 Real getMinimumDepthInputValue(void) { return -1.0f; } // Range [-1.0f, 1.0f] 00466 Real getMaximumDepthInputValue(void) { return 1.0f; } // Range [-1.0f, 1.0f] 00467 OGRE_MUTEX(mThreadInitMutex); 00468 void registerThread(); 00469 void unregisterThread(); 00470 void preExtraThreadsStarted(); 00471 void postExtraThreadsStarted(); 00472 void setClipPlanesImpl(const Ogre::PlaneList& planeList); 00473 00474 // ---------------------------------- 00475 // GL3PlusRenderSystem specific members 00476 // ---------------------------------- 00478 GL3PlusContext* _getMainContext() { return mMainContext; } 00486 void _unregisterContext(GL3PlusContext *context); 00489 void _switchContext(GL3PlusContext *context); 00493 void _oneTimeContextInitialization(); 00494 void initialiseContext(RenderWindow* primary); 00498 void _setRenderTarget(RenderTarget *target); 00499 00500 GLint convertCompareFunction(CompareFunction func) const; 00501 GLint convertStencilOp(StencilOperation op, bool invert = false) const; 00502 00503 void bindGpuProgram(GpuProgram* prg); 00504 void unbindGpuProgram(GpuProgramType gptype); 00505 void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params, uint16 mask); 00506 void bindGpuProgramPassIterationParameters(GpuProgramType gptype); 00507 00509 void _setSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op ); 00511 void _setSeparateSceneBlending( SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha, SceneBlendOperation op, SceneBlendOperation alphaOp ); 00513 void _setAlphaRejectSettings( CompareFunction func, unsigned char value, bool alphaToCoverage ); 00515 unsigned int getDisplayMonitorCount() const; 00516 00518 GLfloat _getCurrentAnisotropy(size_t unit); 00519 00520 GLenum _getPolygonMode(void) { return mPolygonMode; } 00521 00522 void _setSceneBlendingOperation(SceneBlendOperation op); 00523 void _setSeparateSceneBlendingOperation(SceneBlendOperation op, SceneBlendOperation alphaOp); 00525 virtual bool hasAnisotropicMipMapFilter() const { return false; } 00526 00528 virtual void beginProfileEvent( const String &eventName ); 00529 00531 virtual void endProfileEvent( void ); 00532 00534 virtual void markProfileEvent( const String &eventName ); 00535 }; 00536 } 00537 00538 #endif
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