Concrete Factory for GL Frame Buffer Objects, and related things.
Наследование: GLRTTManager
Пример #1
0
        public GLFrameBufferObject(GLFBORTTManager manager)
        {
            this._manager = manager;

            /// Generate framebuffer object
            Gl.glGenFramebuffersEXT(1, out this._frameBuffer);

            /// Initialize state
            this._color = new GLSurfaceDesc[Config.MaxMultipleRenderTargets];
        }
Пример #2
0
        public GLFBORenderTexture(GLFBORTTManager manager, string name, GLSurfaceDesc target, bool writeGamma, int fsaa)
            : base(name, target, writeGamma, fsaa)
        {
            this._fbo = new GLFrameBufferObject(manager);

            // Bind target to surface 0 and initialise
            this._fbo.BindSurface(0, target);

            // Get attributes
            width  = this._fbo.Width;
            height = this._fbo.Height;
        }
Пример #3
0
		public GLFBORenderTexture( GLFBORTTManager manager, string name, GLSurfaceDesc target, bool writeGamma, int fsaa )
			: base( name, target, writeGamma, fsaa )
		{
			this._fbo = new GLFrameBufferObject( manager );

			// Bind target to surface 0 and initialise
			this._fbo.BindSurface( 0, target );

			// Get attributes
			width = this._fbo.Width;
			height = this._fbo.Height;
		}
Пример #4
0
        /// <summary>
        /// Class level dispose method
        /// </summary>
        /// <param name="disposeManagedResources">True if Unmanaged resources should be released.</param>
        protected virtual void dispose(bool disposeManagedResources)
        {
            if (!IsDisposed)
            {
                if (disposeManagedResources)
                {
                    // Dispose managed resources.
                    this._manager.ReleaseRenderBuffer(this._depth);
                    this._manager.ReleaseRenderBuffer(this._stencil);
                    this._manager = null;
                }

                /// Delete framebuffer object
                try
                {
                    Gl.glDeleteFramebuffersEXT(1, ref this._frameBuffer);
                }
                catch (AccessViolationException ave)
                {
                    LogManager.Instance.Write("Error Deleting Framebuffer[{0}].", this._frameBuffer);
                }
            }
            base.dispose(disposeManagedResources);
        }
Пример #5
0
		/// <summary>
		/// Class level dispose method
		/// </summary>
		/// <param name="disposeManagedResources">True if Unmanaged resources should be released.</param>
		protected virtual void dispose( bool disposeManagedResources )
		{
			if ( !IsDisposed )
			{
				if ( disposeManagedResources )
				{
					// Dispose managed resources.
					this._manager.ReleaseRenderBuffer( this._depth );
					this._manager.ReleaseRenderBuffer( this._stencil );
					this._manager = null;
				}

				/// Delete framebuffer object
				try
				{
					Gl.glDeleteFramebuffersEXT( 1, ref this._frameBuffer );
				}
				catch ( AccessViolationException ave )
				{
					LogManager.Instance.Write( "Error Deleting Framebuffer[{0}].", this._frameBuffer );
				}
			}
			base.dispose( disposeManagedResources );
		}
Пример #6
0
		public GLFrameBufferObject( GLFBORTTManager manager )
		{
			this._manager = manager;

			/// Generate framebuffer object
			Gl.glGenFramebuffersEXT( 1, out this._frameBuffer );

			/// Initialize state
			this._color = new GLSurfaceDesc[Config.MaxMultipleRenderTargets];
		}
Пример #7
0
 public GLFBOMultiRenderTarget(GLFBORTTManager manager, string name)
     : base(name)
 {
     this._manager = manager;
 }
Пример #8
0
		public GLFBOMultiRenderTarget( GLFBORTTManager manager, string name )
			: base( name )
		{
			this._manager = manager;
		}
        public override void InitializeFromRenderSystemCapabilities(
            RenderSystemCapabilities caps, RenderTarget primary )
        {
            if ( caps.RendersystemName != Name )
            {
                throw new AxiomException(
                    "Trying to initialize GLRenderSystem from RenderSystemCapabilities that do not support OpenGL" );
            }

            // set texture the number of texture units
            _fixedFunctionTextureUnits = caps.TextureUnitCount;

            //In GL there can be less fixed function texture units than general
            //texture units. Get the minimum of the two.
            if ( caps.HasCapability( Graphics.Capabilities.FragmentPrograms ) )
            {
                int maxTexCoords;
                Gl.glGetIntegerv( Gl.GL_MAX_TEXTURE_COORDS_ARB, out maxTexCoords );
                if ( _fixedFunctionTextureUnits > maxTexCoords )
                {
                    _fixedFunctionTextureUnits = maxTexCoords;
                }
            }

            /* Axiom: assume that OpenTK/Tao does this already
             * otherwise we will need to use delegates for these gl calls ..
             * 
            if (caps.HasCapability(Graphics.Capabilities.GL15NoVbo))
            {
                // Assign ARB functions same to GL 1.5 version since
                // interface identical

                Gl.glBindBufferARB = Gl.glBindBuffer;
                Gl.glBufferDataARB = Gl.glBufferData;
                Gl.glBufferSubDataARB = Gl.glBufferSubData;
                Gl.glDeleteBuffersARB = Gl.glDeleteBuffers;
                Gl.glGenBuffersARB = Gl.glGenBuffers;
                Gl.glGetBufferParameterivARB = Gl.glGetBufferParameteriv;
                Gl.glGetBufferPointervARB = Gl.glGetBufferPointerv;
                Gl.glGetBufferSubDataARB = Gl.glGetBufferSubData;
                Gl.glIsBufferARB = Gl.glIsBuffer;
                Gl.glMapBufferARB = Gl.glMapBuffer;
                Gl.glUnmapBufferARB = Gl.glUnmapBuffer;
            }
             */

            if ( caps.HasCapability( Graphics.Capabilities.VertexBuffer ) )
            {

                _hardwareBufferManager = new GLHardwareBufferManager();
            }
            else
            {
                _hardwareBufferManager = new GLDefaultHardwareBufferManager();
            }

            // XXX Need to check for nv2 support and make a program manager for it
            // XXX Probably nv1 as well for older cards
            // GPU Program Manager setup
            gpuProgramMgr = new GLGpuProgramManager();

            if ( caps.HasCapability( Graphics.Capabilities.VertexPrograms ) )
            {
                if ( caps.IsShaderProfileSupported( "arbvp1" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "arbvp1", new ARBGpuProgramFactory() );
                }

                if ( caps.IsShaderProfileSupported( "vp30" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "vp30", new ARBGpuProgramFactory() );
                }

                if ( caps.IsShaderProfileSupported( "vp40" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "vp40", new ARBGpuProgramFactory() );
                }

                if ( caps.IsShaderProfileSupported( "gp4vp" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "gp4vp", new ARBGpuProgramFactory() );
                }

                if ( caps.IsShaderProfileSupported( "gpu_vp" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "gpu_vp", new ARBGpuProgramFactory() );
                }
            }

            if ( caps.HasCapability( Graphics.Capabilities.GeometryPrograms ) )
            {
                //TODO : Should these be createGLArbGpuProgram or createGLGpuNVparseProgram?
                if ( caps.IsShaderProfileSupported( "nvgp4" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "nvgp4", new ARBGpuProgramFactory() );
                }
                if ( caps.IsShaderProfileSupported( "gp4gp" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "gp4gp", new ARBGpuProgramFactory() );
                }
                if ( caps.IsShaderProfileSupported( "gpu_gp" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "gpu_gp", new ARBGpuProgramFactory() );
                }
            }

            if ( caps.HasCapability( Graphics.Capabilities.FragmentPrograms ) )
            {

                if ( caps.IsShaderProfileSupported( "fp20" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "fp20", new Nvidia.NvparseProgramFactory() );
                }

                if ( caps.IsShaderProfileSupported( "ps_1_4" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "ps_1_4", new ATI.ATIFragmentShaderFactory() );
                }

                if ( caps.IsShaderProfileSupported( "ps_1_3" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "ps_1_3", new ATI.ATIFragmentShaderFactory() );
                }

                if ( caps.IsShaderProfileSupported( "ps_1_2" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "ps_1_2", new ATI.ATIFragmentShaderFactory() );
                }

                if ( caps.IsShaderProfileSupported( "ps_1_1" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "ps_1_1", new ATI.ATIFragmentShaderFactory() );
                }

                if ( caps.IsShaderProfileSupported( "arbfp1" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "arbfp1", new ARBGpuProgramFactory() );
                }

                if ( caps.IsShaderProfileSupported( "fp40" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "fp40", new ARBGpuProgramFactory() );
                }

                if ( caps.IsShaderProfileSupported( "fp30" ) )
                {
                    gpuProgramMgr.RegisterProgramFactory( "fp30", new ARBGpuProgramFactory() );
                }

            }

            if ( caps.IsShaderProfileSupported( "glsl" ) )
            {
                // NFZ - check for GLSL vertex and fragment shader support successful
                _GLSLProgramFactory = new GLSL.GLSLProgramFactory();
                HighLevelGpuProgramManager.Instance.AddFactory( _GLSLProgramFactory );
                LogManager.Instance.Write( "GLSL support detected" );
            }

            /* Axiom: assume that OpenTK/Tao does this already
             * otherwise we will need to use delegates for these gl calls ..
             * 
            if ( caps.HasCapability( Graphics.Capabilities.HardwareOcculusion ) )
            {
                if ( caps.HasCapability( Graphics.Capabilities.GL15NoHardwareOcclusion ) )
                {
                    // Assign ARB functions same to GL 1.5 version since
                    // interface identical
                    Gl.glBeginQueryARB = Gl.glBeginQuery;
                    Gl.glDeleteQueriesARB = Gl.glDeleteQueries;
                    Gl.glEndQueryARB = Gl.glEndQuery;
                    Gl.glGenQueriesARB = Gl.glGenQueries;
                    Gl.glGetQueryObjectivARB = Gl.glGetQueryObjectiv;
                    Gl.glGetQueryObjectuivARB = Gl.glGetQueryObjectuiv;
                    Gl.glGetQueryivARB = Gl.glGetQueryiv;
                    Gl.glIsQueryARB = Gl.glIsQuery;
                }
            }
             */

            // Do this after extension function pointers are initialised as the extension
            // is used to probe further capabilities.
            ConfigOption cfi;
            var rttMode = 0;
            if ( ConfigOptions.TryGetValue( "RTT Preferred Mode", out cfi ) )
            {
                if ( cfi.Value == "PBuffer" )
                {
                    rttMode = 1;
                }
                else if ( cfi.Value == "Copy" )
                {
                    rttMode = 2;
                }
            }


            // Check for framebuffer object extension
		    if(caps.HasCapability(Graphics.Capabilities.FrameBufferObjects) && rttMode < 1)
		    {
			    // Before GL version 2.0, we need to get one of the extensions
			    //if(caps.HasCapability(Graphics.Capabilities.FrameBufferObjectsARB))
				//    GLEW_GET_FUN(__glewDrawBuffers) = Gl.glDrawBuffersARB;
			    //else if(caps.HasCapability(Graphics.Capabilities.FrameBufferObjectsATI))
				//    GLEW_GET_FUN(__glewDrawBuffers) = Gl.glDrawBuffersATI;

			    if(caps.HasCapability(Graphics.Capabilities.HardwareRenderToTexture))
			    {
				    // Create FBO manager
				    LogManager.Instance.Write("GL: Using GL_EXT_framebuffer_object for rendering to textures (best)");
				    rttManager = new GLFBORTTManager(_glSupport, false);
				    caps.SetCapability(Graphics.Capabilities.RTTSerperateDepthBuffer);

				    //TODO: Check if we're using OpenGL 3.0 and add RSC_RTT_DEPTHBUFFER_RESOLUTION_LESSEQUAL flag
			    }
		    } 
            else
		    {
		        // Check GLSupport for PBuffer support
		        if ( caps.HasCapability( Graphics.Capabilities.PBuffer ) && rttMode < 2 )
		        {
		            if ( caps.HasCapability( Graphics.Capabilities.HardwareRenderToTexture ) )
		            {
		                // Use PBuffers
		                rttManager = new GLPBRTTManager( _glSupport, primary );
		                LogManager.Instance.Write( "GL: Using PBuffers for rendering to textures" );

		                //TODO: Depth buffer sharing in pbuffer is left unsupported
		            }
		        }
		        else
		        {
		            // No pbuffer support either -- fallback to simplest copying from framebuffer
		            rttManager = new GLCopyingRTTManager(_glSupport);
		            LogManager.Instance.Write( "GL: Using framebuffer copy for rendering to textures (worst)" );
		            LogManager.Instance.Write(
		                "GL: Warning: RenderTexture size is restricted to size of framebuffer. If you are on Linux, consider using GLX instead of SDL." );

		            //Copy method uses the main depth buffer but no other depth buffer
		            caps.SetCapability( Graphics.Capabilities.RTTMainDepthbufferAttachable );
		            caps.SetCapability( Graphics.Capabilities.RTTDepthbufferResolutionLessEqual );
		        }

		        // Downgrade number of simultaneous targets
		        caps.MultiRenderTargetCount = 1;
		    }

            var defaultLog = LogManager.Instance.DefaultLog;
		    if (defaultLog != null)
		    {
			    caps.Log(defaultLog);
		    }

		    // Create the texture manager        
		    textureManager = new GLTextureManager(_glSupport); 

		    _glInitialised = true;
        }