Axiom.RenderSystems.OpenGLES.GLESFrameBufferObject.Intialize C# (CSharp) Method

Intialize() private method

private Intialize ( ) : void
return void
		private void Intialize()
		{
			// Release depth and stencil, if they were bound
			Manager.ReleaseRenderbuffer( _depth );
			Manager.ReleaseRenderbuffer( _stencil );
			Manager.ReleaseRenderbuffer( _multisampleColorBuffer );

			/// First buffer must be bound
			if ( _color[ 0 ].Buffer == null )
				throw new AxiomException( "Attachment 0 must have surface attached" );

			// If we're doing multisampling, then we need another FBO which contains a
			// renderbuffer which is set up to multisample, and we'll blit it to the final 
			// FBO afterwards to perform the multisample resolve. In that case, the 
			// mMultisampleFB is bound during rendering and is the one with a depth/stencil

			/// Store basic stats
			int width = _color[ 0 ].Buffer.Width;
			int height = _color[ 0 ].Buffer.Height;
			All format = _color[ 0 ].Buffer.GLFormat;
			Media.PixelFormat axiomFormat = _color[ 0 ].Buffer.Format;

			// Bind simple buffer to add colour attachments
			OpenGLOES.BindFramebuffer( All.FramebufferOes, _fb );
			GLESConfig.GlCheckError( this );

			/// Bind all attachment points to frame buffer
			for ( int x = 0; x < Configuration.Config.MaxMultipleRenderTargets; x++ )
			{
				if ( _color[ x ].Buffer != null )
				{
					if ( _color[ x ].Buffer.Width != width || _color[ x ].Buffer.Height != height )
					{
						string ss = string.Empty;
						ss += "Attachment " + x + " has incompatible size ";
						ss += _color[ x ].Buffer.Width + "x" + _color[ 0 ].Buffer.Height;
						ss += ". It must be of the same as the size of surface 0, ";
						ss += width + "x" + height;
						ss += ".";
						throw new AxiomException( ss );
					}
					if ( _color[ x ].Buffer.GLFormat != format )
					{
						string ss = string.Empty;
						ss += "Attachment " + x + " has incompatible format.";
						throw new AxiomException( ss );
					}
					_color[ x ].Buffer.BindToFramebuffer( All.ColorAttachment0Oes + x, _color[ x ].ZOffset );
				}
				else
				{
					// Detach
					OpenGLOES.FramebufferRenderbuffer( All.FramebufferOes, All.ColorAttachment0Oes + x, All.RenderbufferOes, 0 );
					GLESConfig.GlCheckError( this );
				}
			}//end for x

			// Now deal with depth / stencil
			if ( _multiSampleFB != 0 )
			{
				// Bind multisample buffer
				OpenGLOES.BindFramebuffer( All.FramebufferOes, _multiSampleFB );
				GLESConfig.GlCheckError( this );

				// Create AA render buffer (color)
				// note, this can be shared too because we blit it to the final FBO
				// right after the render is finished
				_multisampleColorBuffer = Manager.RequestRenderbuffer( format, width, height, _numSamples );

				// Attach it, because we won't be attaching below and non-multisample has
				// actually been attached to other FBO
				_multisampleColorBuffer.Buffer.BindToFramebuffer( All.ColorAttachment0Oes, _multisampleColorBuffer.ZOffset );

				// depth & stencil will be dealt with below
			}

			/// Depth buffer is not handled here anymore.
			/// See GLESFrameBufferObject::attachDepthBuffer() & RenderSystem::setDepthBufferFor()

			/// Do glDrawBuffer calls
			All[] bufs = new All[ Configuration.Config.MaxMultipleRenderTargets ];
			int n = 0;
			for ( int x = 0; x < Configuration.Config.MaxMultipleRenderTargets; x++ )
			{
				// Fill attached colour buffers
				if ( _color[ x ].Buffer != null )
				{
					bufs[ x ] = All.ColorAttachment0Oes + x;
					// Keep highest used buffer + 1
					n = x + 1;
				}
				else
				{
					bufs[ x ] = All.Never;
				}
			}//end for x

			/// Check status
			All status = OpenGLOES.CheckFramebufferStatus( All.FramebufferOes );
			GLESConfig.GlCheckError( this );
			/// Bind main buffer
#if AXIOM_PLATFORM_IPHONE
            // The screen buffer is 1 on iPhone
            OpenGLOES.BindFramebuffer(All.FramebufferOes, 1);
#else
			OpenGLOES.BindFramebuffer( All.FramebufferOes, 0 );
#endif
			GLESConfig.GlCheckError( this );

			switch ( status )
			{
				case All.FramebufferCompleteOes:
					// everything is fine
					break;
				case All.FramebufferUnsupportedOes:
					throw new AxiomException( "All framebuffer formats with this texture internal format unsupported" );
				default:
					throw new AxiomException( "Framebuffer incomplete or other FBO status error" );
			}
		}
	}