Abstract singleton class for managing hardware buffers, a concrete instance of this will be created by the RenderSystem.
Inheritance: HardwareBufferManagerBase
Exemplo n.º 1
0
		public GLESHardwareIndexBuffer( HardwareBufferManager mgr, IndexType idxType, int numIndexes, BufferUsage usage, bool useShadowBuffer )
			: base( idxType, numIndexes, usage, false, useShadowBuffer )
		{
			if ( idxType == IndexType.Size32 )
			{
				throw new AxiomException( "32 bit hardware buffers are not allowed in OpenGL ES." );
			}

			if ( !useShadowBuffer )
			{
				throw new AxiomException( "Only support with shadowBuffer" );
			}

			OpenGL.GenBuffers( 1, ref _bufferId );
			GLESConfig.GlCheckError( this );
			if ( _bufferId == 0 )
			{
				throw new AxiomException( "Cannot create GL index buffer" );
			}

			OpenGL.BindBuffer( All.ElementArrayBuffer, _bufferId );
			GLESConfig.GlCheckError( this );
			OpenGL.BufferData( All.ElementArrayBuffer, new IntPtr( sizeInBytes ), IntPtr.Zero, GLESHardwareBufferManager.GetGLUsage( usage ) );
			GLESConfig.GlCheckError( this );
		}
Exemplo n.º 2
0
		protected internal HardwareBufferManager( HardwareBufferManagerBase baseInstance )
			: base()
		{
			if ( instance == null )
			{
				instance = this;
				this._baseInstance = baseInstance;
			}
		}
Exemplo n.º 3
0
        /// <summary>
        ///     Internal constructor.  This class cannot be instantiated externally.
        /// </summary>
        /// <remarks>
        ///     Protected internal because this singleton will actually hold the instance of a subclass
        ///     created by a render system plugin.
        /// </remarks>
        protected internal HardwareBufferManager()
        {
            if (instance == null)
            {
                instance = this;

                freeTempVertexBufferMap = new Hashtable(new BufferComparer());
            }
        }
Exemplo n.º 4
0
 protected internal HardwareBufferManager(HardwareBufferManagerBase baseInstance)
     : base()
 {
     if (instance == null)
     {
         instance           = this;
         this._baseInstance = baseInstance;
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Class level dispose method
        /// </summary>
        protected override void dispose(bool disposeManagedResources)
        {
            if (!IsDisposed)
            {
                if (disposeManagedResources)
                {
                    // Destroy all necessary objects
                    instance = null;
                }
            }

            base.dispose(disposeManagedResources);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Called when the engine is shutting down.
        /// </summary>
        public virtual void Dispose()
        {
            // Destroy all necessary objects
            vertexDeclarations.Clear();
            vertexBufferBindings.Clear();

            // destroy all vertex buffers
            foreach (HardwareBuffer buffer in vertexBuffers)
            {
                buffer.Dispose();
            }

            // destroy all index buffers
            foreach (HardwareBuffer buffer in indexBuffers)
            {
                buffer.Dispose();
            }

            instance = null;
        }
Exemplo n.º 7
0
		public GLESHardwareVertexBuffer( HardwareBufferManager mgr, int vertexSize, int numVertices, BufferUsage usage, bool useShadowBuffer )
			: base( numVertices, vertexSize, usage, false, useShadowBuffer )
		{
			if ( !useShadowBuffer )
			{
				throw new AxiomException( "Only supported with shadowBuffer" );
			}

			OpenGL.GenBuffers( 1, ref _bufferId );
			GLESConfig.GlCheckError( this );
			if ( _bufferId == 0 )
			{
				throw new AxiomException( "Cannot create GL vertex buffer" );
			}

			OpenGL.BindBuffer( All.ArrayBuffer, _bufferId );
			GLESConfig.GlCheckError( this );
			OpenGL.BufferData( All.ArrayBuffer, new IntPtr( sizeInBytes ), IntPtr.Zero, GLESHardwareBufferManager.GetGLUsage( usage ) );
			GLESConfig.GlCheckError( this );
		}
        /// <summary>
        ///		Utility method, extract info from the given VertexData
        /// </summary>
        public void ExtractFrom(VertexData sourceData)
        {
            // Release old buffer copies first
            HardwareBufferManager mgr = HardwareBufferManager.Instance;

            if (destPositionBuffer != null)
            {
                mgr.ReleaseVertexBufferCopy(destPositionBuffer);
                Debug.Assert(destPositionBuffer == null);
            }
            if (destNormalBuffer != null)
            {
                mgr.ReleaseVertexBufferCopy(destNormalBuffer);
                Debug.Assert(destNormalBuffer == null);
            }

            VertexDeclaration   decl       = sourceData.vertexDeclaration;
            VertexBufferBinding bind       = sourceData.vertexBufferBinding;
            VertexElement       posElem    = decl.FindElementBySemantic(VertexElementSemantic.Position);
            VertexElement       normElem   = decl.FindElementBySemantic(VertexElementSemantic.Normal);
            VertexElement       tanElem    = decl.FindElementBySemantic(VertexElementSemantic.Tangent);
            VertexElement       binormElem = decl.FindElementBySemantic(VertexElementSemantic.Binormal);

            Debug.Assert(posElem != null, "Positions are required");

            posBindIndex      = posElem.Source;
            srcPositionBuffer = bind.GetBuffer(posBindIndex);

            if (normElem == null)
            {
                posNormalShareBuffer = false;
                srcNormalBuffer      = null;
            }
            else
            {
                normBindIndex = normElem.Source;
                if (normBindIndex == posBindIndex)
                {
                    posNormalShareBuffer = true;
                    srcNormalBuffer      = null;
                }
                else
                {
                    posNormalShareBuffer = false;
                    srcNormalBuffer      = bind.GetBuffer(normBindIndex);
                }
            }
            if (tanElem == null)
            {
                srcTangentBuffer = null;
            }
            else
            {
                tanBindIndex     = tanElem.Source;
                srcTangentBuffer = bind.GetBuffer(tanBindIndex);
            }

            if (binormElem == null)
            {
                srcBinormalBuffer = null;
            }
            else
            {
                binormBindIndex   = binormElem.Source;
                srcBinormalBuffer = bind.GetBuffer(binormBindIndex);
            }
        }
Exemplo n.º 9
0
		/// <summary>
		/// Class level dispose method
		/// </summary>
		protected override void dispose( bool disposeManagedResources )
		{
			if ( !IsDisposed )
			{
				if ( disposeManagedResources )
				{
					// Destroy all necessary objects
					instance = null;
				}
			}

			base.dispose( disposeManagedResources );
		}
Exemplo n.º 10
0
		public GLES2RenderSystem()
		{
			this.depthWrite = true;
			this.stencilMask = 0xFFFFFFFF;
			this.gpuProgramManager = null;
			this.glslESProgramFactory = null;
			this.hardwareBufferManager = null;
			this.rttManager = null;

			int i;

			LogManager.Instance.Write( this.Name + " created." );
			this.renderAttribsBound = new List<int>( 100 );


#if RTSHADER_SYSTEM_BUILD_CORE_SHADERS
			enableFixedPipeline = false;
#endif

			this.CreateGlSupport();

			this.worldMatrix = Matrix4.Identity;
			this.viewMatrix = Matrix4.Identity;

			this.glSupport.AddConfig();

			this.colorWrite[ 0 ] = this.colorWrite[ 1 ] = this.colorWrite[ 2 ] = this.colorWrite[ 3 ] = true;

			for ( i = 0; i < Config.MaxTextureLayers; i++ )
			{
				//Dummy value
				this.textureCoordIndex[ i ] = 99;
				this.textureTypes[ i ] = 0;
			}

			activeRenderTarget = null;
			this.currentContext = null;
			this.mainContext = null;
			this.glInitialized = false;
			this.minFilter = FilterOptions.Linear;
			this.mipFilter = FilterOptions.Point;
			this.currentVertexProgram = null;
			this.currentFragmentProgram = null;
			//todo
			//polygonMode = GL_FILL;
		}
Exemplo n.º 11
0
		public override void Shutdown()
		{
			//Deleting the GLSL program factory
			if ( this.glslESProgramFactory != null )
			{
				//Remove from manager safely
				if ( HighLevelGpuProgramManager.Instance != null )
				{
					HighLevelGpuProgramManager.Instance.RemoveFactory( this.glslESProgramFactory );
				}
				this.glslESProgramFactory.Dispose();
				this.glslESProgramFactory = null;
			}
			//Deleting the GLSL program factory
			if ( this.glslESCgProgramFactory != null )
			{
				if ( HighLevelGpuProgramManager.Instance != null )
				{
					HighLevelGpuProgramManager.Instance.RemoveFactory( this.glslESCgProgramFactory );
				}
				this.glslESCgProgramFactory.Dispose();
				this.glslESCgProgramFactory = null;
			}

			//Deleting the GPU program manager and hardware buffer manager. Has to be done before the glSupport.Stop()
			if ( null != this.gpuProgramManager )
			{
				this.gpuProgramManager.Dispose();
				this.gpuProgramManager = null;
			}

			this.hardwareBufferManager = null;

			this.rttManager = null;

			if ( null != this.textureManager ) 
			{
				textureManager.Dispose();
				textureManager = null;
			}

			base.Shutdown();

			this.glSupport.Stop();

			this.glInitialized = false;
		}
Exemplo n.º 12
0
		public override void InitializeFromRenderSystemCapabilities( RenderSystemCapabilities caps, RenderTarget primary )
		{
			if ( caps.RendersystemName != this.Name )
			{
				throw new AxiomException( "Trying to initialize GLES2RenderSystem from RenderSystemCapabilities that do not support OpenGL ES" );
			}

			this.gpuProgramManager = new GLES2GpuProgramManager();
			this.glslESProgramFactory = new GLSLES.GLSLESProgramFactory();
			HighLevelGpuProgramManager.Instance.AddFactory( this.glslESProgramFactory );

			//todo: check what can/can't support cg
			this.glslESCgProgramFactory = new GLSLES.GLSLESCgProgramFactory();
			HighLevelGpuProgramManager.Instance.AddFactory( this.glslESCgProgramFactory );

			//Set texture the number of texture units
			this.fixedFunctionTextureUnits = caps.TextureUnitCount;

			//Use VBO's by default
			this.hardwareBufferManager = new GLES2HardwareBufferManager();

			//Create FBO manager
			LogManager.Instance.Write( "GL ES 2: Using FBOs for rendering to textures" );
			this.rttManager = new GLES2FBOManager();
			caps.SetCapability( Graphics.Capabilities.RTTSerperateDepthBuffer );

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

			textureManager = new GLES2TextureManager( this.glSupport );

			this.glInitialized = true;
		}
        /// <summary>
        ///     Called when the engine is shutting down.
        /// </summary>
        public virtual void Dispose()
        {
            // Destroy all necessary objects
            vertexDeclarations.Clear();
            vertexBufferBindings.Clear();

            // destroy all vertex buffers
            foreach (HardwareBuffer buffer in vertexBuffers) {
                buffer.Dispose();
            }

            // destroy all index buffers
            foreach (HardwareBuffer buffer in indexBuffers) {
                buffer.Dispose();
            }

            instance = null;
        }
        /// <summary>
        ///     Internal constructor.  This class cannot be instantiated externally.
        /// </summary>
        /// <remarks>
        ///     Protected internal because this singleton will actually hold the instance of a subclass
        ///     created by a render system plugin.
        /// </remarks>
        protected internal HardwareBufferManager()
        {
            if (instance == null) {
                instance = this;

                freeTempVertexBufferMap = new Hashtable(new BufferComparer());
            }
        }