Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="localName"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="format"></param>
        /// <param name="aa"></param>
        /// <param name="aaHint"></param>
        /// <param name="srgb"></param>
        /// <param name="textureAllreadyAssigned"></param>
        /// <param name="instance"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        public Texture GetPooledTexture( string name, string localName, int width, int height, PixelFormat format, int aa,
            string aaHint, bool srgb, List<Texture> textureAllreadyAssigned,
            CompositorInstance instance, CompositionTechnique.TextureScope scope)
        {
            if ( scope == CompositionTechnique.TextureScope.Global )
            {
                throw new AxiomException( "Global scope texture can not be pooled." );
            }

            var def = new TextureDefinition( width, height, format, aa, aaHint, srgb );
            if ( scope == CompositionTechnique.TextureScope.Chain )
            {
                var pair = new Pair<string>( instance.Compositor.Name, localName );
                SortedList<TextureDefinition, Texture> defMap = null;
                if ( this.chainTexturesByRef.TryGetValue( pair, out defMap ) )
                {
                    Texture tex;
                    if ( defMap.TryGetValue( def, out tex ) )
                    {
                        return tex;
                    }
                }
                // ok, we need to create a new one
                if ( defMap == null )
                {
                    defMap = new SortedList<TextureDefinition, Texture>( new TextureDefLess() );
                }

                var newTex = TextureManager.Instance.CreateManual( name, ResourceGroupManager.InternalResourceGroupName,
                                                                   TextureType.TwoD, width, height, 0, format,
                                                                   TextureUsage.RenderTarget, null, srgb, aa, aaHint );

                defMap.Add( def, newTex );

                if ( this.chainTexturesByRef.ContainsKey( pair ) )
                {
                    this.chainTexturesByRef[ pair ] = defMap;
                }
                else
                {
                    this.chainTexturesByRef.Add( pair, defMap );
                }

                return newTex;
            } //end if scope

            List<Texture> i = null;
            if ( !this.texturesByDef.TryGetValue( def, out i ) )
            {
                i = new List<Texture>();
                this.texturesByDef.Add( def, i );
            }

            var previous = instance.Chain.GetPreviousInstance( instance );
            var next = instance.Chain.GetNextInstance( instance );

            Texture ret = null;
            // iterate over the existing textures and check if we can re-use
            foreach ( var tex in i )
            {
                // check not already used
                if ( !textureAllreadyAssigned.Contains( tex ) )
                {
                    var allowReuse = true;
                    // ok, we didn't use this one already
                    // however, there is an edge case where if we re-use a texture
                    // which has an 'input previous' pass, and it is chained from another
                    // compositor, we can end up trying to use the same texture for both
                    // so, never allow a texture with an input previous pass to be
                    // shared with its immediate predecessor in the chain
                    if ( IsInputPreviousTarget( instance, localName ) )
                    {
                        // Check whether this is also an input to the output target of previous
                        // can't use CompositorInstance._previousInstance, only set up
                        // during compile
                        if ( previous != null && IsInputToOutputTarget( previous, tex ) )
                        {
                            allowReuse = false;
                        }
                    }
                    // now check the other way around since we don't know what order they're bound in
                    if ( IsInputToOutputTarget( instance, localName ) )
                    {
                        if ( next != null && IsInputPreviousTarget( next, tex ) )
                        {
                            allowReuse = false;
                        }
                    }
                    if ( allowReuse )
                    {
                        ret = tex;
                        break;
                    }
                }
            }

            if ( ret == null )
            {
                // ok, we need to create a new one
                ret = TextureManager.Instance.CreateManual( name, ResourceGroupManager.InternalResourceGroupName, TextureType.TwoD,
                                                            width, height, 0, format, TextureUsage.RenderTarget, null, srgb, aa,
                                                            aaHint );
                i.Add( ret );
                this.texturesByDef[ def ] = i;
            }

            // record that we used this one in the requester's list
            textureAllreadyAssigned.Add( ret );

            return ret;
        }
Пример #2
0
        public TexturePtr getPooledTexture(string name, string localName, uint w, uint h, PixelFormat f, uint aa, string aaHint, bool srgb, SWIGTYPE_p_std__setT_Ogre__Texture_p_t texturesAlreadyAssigned, CompositorInstance inst, CompositionTechnique.TextureScope scope)
        {
            TexturePtr ret = new TexturePtr(OgrePINVOKE.CompositorManager_getPooledTexture(swigCPtr, name, localName, w, h, (int)f, aa, aaHint, srgb, SWIGTYPE_p_std__setT_Ogre__Texture_p_t.getCPtr(texturesAlreadyAssigned), CompositorInstance.getCPtr(inst), (int)scope), true);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }