public override Stream OpenResource( string resourceName, string groupName, bool searchGroupsIfNotFound, Resource resourceBeingLoaded ) { var extension = Path.GetExtension( resourceName ).Substring( 1 ); if ( extension == "xnb" ) { return base.OpenResource( resourceName, groupName, searchGroupsIfNotFound, resourceBeingLoaded ); } if ( Root.Instance.RenderSystem.ConfigOptions[ "Use Content Pipeline" ].Value == "Yes" ) { if ( CodecManager.Instance.GetCodec( extension ).GetType().Name != "NullCodec" ) { var acm = new AxiomContentManager( (XnaRenderSystem)Root.Instance.RenderSystem, "" ); #if SILVERLIGHT var texture = acm.Load<WriteableBitmap>(resourceName); #else var texture = acm.Load<Texture2D>( resourceName ); #endif return new XnaImageCodecStream( texture ); } return base.OpenResource( resourceName, groupName, searchGroupsIfNotFound, resourceBeingLoaded ); } return base.OpenResource( resourceName, groupName, searchGroupsIfNotFound, resourceBeingLoaded ); }
public void LoadResource( Resource resource ) { Mesh mesh = (Mesh)resource; bool prefab = PrefabFactory.Create( mesh ); if ( !prefab ) { MeshBuildParams mbp = _meshBuildParams[ mesh ]; _loadManual( mesh, mbp ); } }
public override void Load(Resource resource, int priority) { base.Load (resource, priority); }
private string ResolveCgIncludes(string inSource, Resource resourceBeingLoaded, string fileName) { var outSource = ""; var startMarker = 0; var i = inSource.IndexOf( "#include" ); while ( i != -1 ) { var includePos = i; var afterIncludePos = includePos + 8; var newLineBefore = inSource.LastIndexOf( "\n", 0, includePos ); // check we're not in a comment var lineCommentIt = inSource.LastIndexOf( "//", 0, includePos ); if ( lineCommentIt != -1 ) { if ( newLineBefore == -1 || lineCommentIt > newLineBefore ) { // commented i = inSource.IndexOf( "#include", afterIncludePos ); continue; } } var blockCommentIt = inSource.LastIndexOf( "/*", 0, includePos ); if ( blockCommentIt != -1 ) { var closeCommentIt = inSource.LastIndexOf( "*/", 0, includePos ); if ( closeCommentIt == -1 || closeCommentIt < blockCommentIt ) { // commented i = inSource.IndexOf( "#include", afterIncludePos ); continue; } } // find following newline (or EOF) var newLineAfter = inSource.IndexOf( "\n", afterIncludePos ); // find include file string container var endDelimeter = "\""; var startIt = inSource.IndexOf( "\"", afterIncludePos ); if ( startIt == -1 || startIt > newLineAfter ) { // try <> startIt = inSource.IndexOf( "<", afterIncludePos ); if ( startIt == -1 || startIt > newLineAfter ) { throw new AxiomException( "Badly formed #include directive (expected \" or <) in file " + fileName + ": " + inSource.Substring( includePos, newLineAfter - includePos ) ); } else { endDelimeter = ">"; } } var endIt = inSource.IndexOf( endDelimeter, startIt + 1 ); if ( endIt == -1 || endIt <= startIt ) { throw new AxiomException( "Badly formed #include directive (expected " + endDelimeter + ") in file " + fileName + ": " + inSource.Substring( includePos, newLineAfter - includePos ) ); } // extract filename var filename = inSource.Substring( startIt + 1, endIt - startIt - 1 ); // open included file var resource = ResourceGroupManager.Instance.OpenResource( filename, resourceBeingLoaded.Group, true, resourceBeingLoaded ); // replace entire include directive line // copy up to just before include if ( newLineBefore != -1 && newLineBefore >= startMarker ) outSource += inSource.Substring( startMarker, newLineBefore - startMarker + 1 ); var lineCount = 0; var lineCountPos = 0; // Count the line number of #include statement lineCountPos = outSource.IndexOf( '\n' ); while ( lineCountPos != -1 ) { lineCountPos = outSource.IndexOf( '\n', lineCountPos + 1 ); lineCount++; } // Add #line to the start of the included file to correct the line count outSource += ( "#line 1 \"" + filename + "\"\n" ); outSource += ( resource.AsString() ); // Add #line to the end of the included file to correct the line count outSource += ( "\n#line " + lineCount + "\"" + fileName + "\"\n" ); startMarker = newLineAfter; if ( startMarker != -1 ) i = inSource.IndexOf( "#include", startMarker ); else i = -1; } // copy any remaining characters outSource += ( inSource.Substring( startMarker ) ); return outSource; }
/// <summary> /// Add a newly created resource to the manager /// </summary> /// <param name="res"></param> protected virtual void _add( Resource res ) { if ( !this._resourceHandleMap.ContainsKey( res.Handle ) ) { this._resourceHandleMap.Add( res.Handle, res ); } else { throw new AxiomException( String.Format( "Resource '{0}' with the handle {1} already exists.", res.Name, res.Handle ) ); } }
public virtual void NotifyResourceTouched( Resource res ) { // TODO }
/// <summary> /// Unloads a Resource from the managed resources list, calling it's Unload() method. /// </summary> /// <remarks> /// This method removes a resource from the list maintained by this manager, and unloads it from /// memory. It does NOT destroy the resource itself, although the memory used by it will be largely /// freed up. This would allow you to reload the resource again if you wished. /// </remarks> /// <param name="resource"></param> public virtual void Unload( Resource resource ) { // unload the resource resource.Unload(); // remove the resource this._resources.Remove( resource.Name ); // update memory usage this._memoryUsage -= resource.Size; }
public void PreparingComplete( Resource res ) { //NOTHING TO DO }
/// <see cref="IManualResourceLoader.LoadResource"/> public void LoadResource( Resource resource ) { var mesh = (Mesh)resource; // attempt to create a prefab mesh var prefab = PrefabFactory.Create( mesh ); // the mesh was not a prefab.. if ( !prefab ) { // Find build parameters if ( !this._meshBuildParams.ContainsKey( mesh ) ) { throw new AxiomException( "Cannot find build parameters for {0}", mesh.Name ); } var parameters = this._meshBuildParams[ mesh ]; switch ( parameters.Type ) { case MeshBuildType.Plane: //TODO //loadManualPlane(msh, parameters); break; case MeshBuildType.CurvedIllusionPlane: //TODO //loadManualCurvedIllusionPlane(msh, parameters); break; case MeshBuildType.CurvedPlane: //TODO //loadManualCurvedPlane(msh, parameters); break; default: throw new AxiomException( "Unknown build parameters for {0}", mesh.Name ); } _loadManual( mesh, parameters ); } }
public virtual void NotifyResourceTouched(Resource res) { // TODO }
/// <overloads> /// <summary> /// Remove a single resource. /// </summary> /// <remarks> /// Removes a single resource, meaning it will be removed from the list /// of valid resources in this manager, also causing it to be unloaded. /// <para/> /// The word 'Destroy' is not used here, since /// if any other pointers are referring to this resource, it will persist /// until they have finished with it; however to all intents and purposes /// it no longer exists and will likely get destroyed imminently. /// <para/> /// If you do have references to resources hanging around after the /// ResourceManager is destroyed, you may get problems on destruction of /// these resources if they were relying on the manager (especially if /// it is a plugin). If you find you get problems on shutdown in the /// destruction of resources, try making sure you release all your /// references before you shutdown OGRE. /// </remarks> /// </overloads> /// <param name="resource">The resource to remove</param> public virtual void Remove(Resource resource) { _remove(resource); }
/// <summary>Notify this manager that a resource which it manages has been unloaded.</summary> /// <param name="res">the resource</param> public virtual void NotifyResourceUnloaded( Resource res ) { _memoryUsage -= res.Size; }
public void LoadResource( Resource resource ) { this.Generate(); }
protected bool resourceCollision( Resource resource, ResourceManager resourceManager ) { return false; }
protected Stream resourceLoading( string name, string group, Resource resource ) { return new MemoryStream(); }
public void LoadingComplete( Resource res ) { // Need to re-create parameters if ( this.recreateParams ) { RecreateParameters(); } }
/// <summary> /// This event is fired when a declared resource is about to be loaded. /// </summary> /// <param name="resource">Weak reference to the resource loaded</param> public void ResourceLoadStarted( Resource resource ) { this.LoadBar.Comment = resource.Name; this.mWindow.Update(); // allow OS events to process (if the platform requires it if ( WindowEventMonitor.Instance.MessagePump != null ) { WindowEventMonitor.Instance.MessagePump(); } }
public void UnloadingComplete( Resource res ) { this.recreateParams = true; }
/// <summary> /// /// </summary> /// <param name="resource"></param> public void ResourcePrepareStarted( Resource resource ) { }
/// <overloads> /// <summary> /// Remove a single resource. /// </summary> /// <remarks> /// Removes a single resource, meaning it will be removed from the list /// of valid resources in this manager, also causing it to be unloaded. /// <para/> /// The word 'Destroy' is not used here, since /// if any other pointers are referring to this resource, it will persist /// until they have finished with it; however to all intents and purposes /// it no longer exists and will likely get destroyed imminently. /// <para/> /// If you do have references to resources hanging around after the /// ResourceManager is destroyed, you may get problems on destruction of /// these resources if they were relying on the manager (especially if /// it is a plugin). If you find you get problems on shutdown in the /// destruction of resources, try making sure you release all your /// references before you shutdown OGRE. /// </remarks> /// </overloads> /// <param name="resource">The resource to remove</param> public virtual void Remove( Resource resource ) { _remove( resource ); }
public static void DoImageIO( string name, string group, string ext, ref List<Image> images, Resource r ) { int imgIdx = images.Count; images.Add( new Image() ); var dstream = ResourceGroupManager.Instance.OpenResource( name, group, true, r ); images[ imgIdx ] = Image.FromStream( dstream, ext ); int w = 0, h = 0; //Scale to nearest power 2 w = GLES2PixelUtil.OptionalPO2( images[ imgIdx ].Width ); h = GLES2PixelUtil.OptionalPO2( images[ imgIdx ].Height ); if ( ( images[ imgIdx ].Width != w ) || ( images[ imgIdx ].Height != h ) ) { images[ imgIdx ].Resize( w, h ); } }
public virtual void NotifyResourceUnloaded( Resource res ) { lock ( _autoMutex ) { this._memoryUsage -= res.Size; } }
/// <summary> /// Add a resource to this manager; normally only done by subclasses. /// </summary> /// <param name="resource">Resource to add.</param> public virtual void Add(Resource resource) { resource.Handle = GetNextHandle(); // note: just overwriting existing for now resourceList[resource.Name] = resource; resourceHandleMap[resource.Handle] = resource; }
/// <summary> /// Remove a resource from this manager; remove it from the lists. /// </summary> /// <param name="res"></param> protected virtual void _remove( Resource res ) { if ( this._resources.ContainsKey( res.Name ) ) { this._resources.Remove( res.Name ); } if ( this._resourceHandleMap.ContainsKey( res.Handle ) ) { this._resourceHandleMap.Remove( res.Handle ); } ResourceGroupManager.Instance.notifyResourceRemoved( res ); }
/// <summary> /// Loads a resource. Resource will be subclasses of Resource. /// </summary> /// <param name="resource">Resource to load.</param> /// <param name="priority"></param> public virtual void Load(Resource resource, int priority) { // load and touch the resource resource.Load(); resource.Touch(); // cache the resource Add(resource); }
public void LoadResource( Resource resource ) { // TODO : Revisit after checking current Imaging support in Mono. #if !( XBOX || XBOX360 || ANDROID || IPHONE) string current = Environment.CurrentDirectory; IntPtr ftLibrary = IntPtr.Zero; if ( FT.FT_Init_FreeType( out ftLibrary ) != 0 ) throw new AxiomException( "Could not init FreeType library!" ); IntPtr face = IntPtr.Zero; int char_space = 5; Stream fileStream = ResourceGroupManager.Instance.OpenResource( Source, Group ); byte[] data = new byte[ fileStream.Length ]; fileStream.Read( data, 0, data.Length ); //Load font int success = FT.FT_New_Memory_Face( ftLibrary, data, data.Length, 0, out face ); if ( success != 0 ) { throw new AxiomException( "Could not open font face!" ); } // Convert our point size to freetype 26.6 fixed point format int ttfSize = _ttfSize * ( 1 << 6 ); success = FT.FT_Set_Char_Size( face, ttfSize, 0, (uint)_ttfResolution, (uint)_ttfResolution ); if ( success != 0 ) { { throw new AxiomException( "Could not set char size!" ); } } int max_height = 0, max_width = 0; List<KeyValuePair<int, int>> codePointRange = new List<KeyValuePair<int, int>>(); // Backwards compatibility - if codepoints not supplied, assume 33-166 if ( codePointRange.Count == 0 ) { codePointRange.Add( new KeyValuePair<int, int>( 33, 166 ) ); } int glyphCount = 0; foreach ( KeyValuePair<int, int> r in codePointRange ) { KeyValuePair<int, int> range = r; for ( int cp = range.Key; cp <= range.Value; ++cp, ++glyphCount ) { FT.FT_Load_Char( face, (uint)cp, 4 ); //4 == FT_LOAD_RENDER FT_FaceRec rec = (FT_FaceRec)Marshal.PtrToStructure( face, typeof( FT_FaceRec ) ); FT_GlyphSlotRec glyp = (FT_GlyphSlotRec)Marshal.PtrToStructure( rec.glyph, typeof( FT_GlyphSlotRec ) ); if ( ( 2 * ( glyp.bitmap.rows << 6 ) - glyp.metrics.horiBearingY ) > max_height ) max_height = ( 2 * ( glyp.bitmap.rows << 6 ) - glyp.metrics.horiBearingY ); if ( glyp.metrics.horiBearingY > maxBearingY ) maxBearingY = glyp.metrics.horiBearingY; if ( ( glyp.advance.x >> 6 ) + ( glyp.metrics.horiBearingX >> 6 ) > max_width ) max_width = ( glyp.advance.x >> 6 ) + ( glyp.metrics.horiBearingX >> 6 ); } } // Now work out how big our texture needs to be int rawSize = ( max_width + char_space ) * ( ( max_height >> 6 ) + char_space ) * glyphCount; int tex_side = (int)System.Math.Sqrt( (Real)rawSize ); // just in case the size might chop a glyph in half, add another glyph width/height tex_side += System.Math.Max( max_width, ( max_height >> 6 ) ); // Now round up to nearest power of two int roundUpSize = (int)Bitwise.FirstPO2From( (uint)tex_side ); // Would we benefit from using a non-square texture (2X width( int finalWidth = 0, finalHeight = 0; if ( roundUpSize * roundUpSize * 0.5 >= rawSize ) { finalHeight = (int)( roundUpSize * 0.5 ); } else { finalHeight = roundUpSize; } finalWidth = roundUpSize; Real textureAspec = (Real)finalWidth / (Real)finalHeight; int pixelBytes = 2; int dataWidth = finalWidth * pixelBytes; int data_size = finalWidth * finalHeight * pixelBytes; LogManager.Instance.Write( "Font " + _name + " using texture size " + finalWidth.ToString() + "x" + finalHeight.ToString() ); byte[] imageData = new byte[ data_size ]; for ( int i = 0; i < data_size; i += pixelBytes ) { imageData[ i + 0 ] = 0xff;// luminance imageData[ i + 1 ] = 0x00;// alpha } int l = 0, m = 0; foreach ( KeyValuePair<int, int> r in codePointRange ) { KeyValuePair<int, int> range = r; for ( int cp = range.Key; cp <= range.Value; ++cp ) { int result = FT.FT_Load_Char( face, (uint)cp, 4 );//4 == FT_LOAD_RENDER if ( result != 0 ) { // problem loading this glyph, continue LogManager.Instance.Write( "Info: cannot load character '" + char.ConvertFromUtf32( cp ) + "' in font " + _name + "." ); continue; } FT_FaceRec rec = (FT_FaceRec)Marshal.PtrToStructure( face, typeof( FT_FaceRec ) ); FT_GlyphSlotRec glyp = (FT_GlyphSlotRec)Marshal.PtrToStructure( rec.glyph, typeof( FT_GlyphSlotRec ) ); int advance = glyp.advance.x >> 6; unsafe { if ( glyp.bitmap.buffer == IntPtr.Zero ) { LogManager.Instance.Write( "Info: Freetype returned null for character '" + char.ConvertFromUtf32( cp ) + "' in font " + _name + "." ); continue; } byte* buffer = (byte*)glyp.bitmap.buffer; byte* imageDataPtr = (byte*)Memory.PinObject( imageData ); int y_bearing = ( ( maxBearingY >> 6 ) - ( glyp.metrics.horiBearingY >> 6 ) ); int x_bearing = glyp.metrics.horiBearingX >> 6; for ( int j = 0; j < glyp.bitmap.rows; j++ ) { int row = j + m + y_bearing; byte* pDest = &imageDataPtr[ ( row * dataWidth ) + ( l + x_bearing ) * pixelBytes ]; for ( int k = 0; k < glyp.bitmap.width; k++ ) { if ( AntialiasColor ) { // Use the same greyscale pixel for all components RGBA *pDest++ = *buffer; } else { // Always white whether 'on' or 'off' pixel, since alpha // will turn off *pDest++ = (byte)0xFF; } // Always use the greyscale value for alpha *pDest++ = *buffer++; }//end k }//end j // this.SetGlyphTexCoords( (uint)cp, (Real)l / (Real)finalWidth,//u1 (Real)m / (Real)finalHeight,//v1 (Real)( l + ( glyp.advance.x >> 6 ) ) / (Real)finalWidth, //u2 ( m + ( max_height >> 6 ) ) / (Real)finalHeight, textureAspec ); //v2 // textureAspec ); //SetGlyphTexCoords( c, u1, v1, u2, v2 ); //Glyphs.Add( new KeyValuePair<CodePoint, GlyphInfo>( (uint)cp, // new GlyphInfo( (uint)cp, // new UVRect( // (Real)l / (Real)finalWidth,//u1 // (Real)m / (Real)finalHeight,//v1 // (Real)( l + ( glyp.advance.x >> 6 ) ) / (Real)finalWidth, //u2 // ( m + ( max_height >> 6 ) ) / (Real)finalHeight //v2 // ), textureAspec ) ) ); // Advance a column l += ( advance + char_space ); // If at end of row if ( finalWidth - 1 < l + ( advance ) ) { m += ( max_height >> 6 ) + char_space; l = 0; } } } }//end foreach MemoryStream memStream = new MemoryStream( imageData ); Image img = Image.FromRawStream( memStream, finalWidth, finalHeight, PixelFormat.BYTE_LA ); Texture tex = (Texture)resource; Image[] images = new Image[ 1 ]; images[ 0 ] = img; tex.LoadImages( images ); FT.FT_Done_FreeType( ftLibrary ); //img.Save( "C:\\" + Name + ".png" ); //FileStream file = new FileStream( "C:\\" + Name + ".fontdef", FileMode.Create ); //StreamWriter str = new StreamWriter( file ); //str.WriteLine( Name ); //str.WriteLine( "{" ); //str.WriteLine( "\ttype\timage" ); //str.WriteLine( "\tsource\t{0}.png\n", Name ); //for ( uint i = 0; i < (uint)( END_CHAR - START_CHAR ); i++ ) //{ // char c = (char)( i + START_CHAR ); // str.WriteLine( "\tglyph\t{0}\t{1:F6}\t{2:F6}\t{3:F6}\t{4:F6}", c, Glyphs[ c ].uvRect.Top, Glyphs[ c ].uvRect.Left, Glyphs[ c ].uvRect.Bottom, Glyphs[ c ].uvRect.Right ); //} //str.WriteLine( "}" ); //str.Close(); //file.Close(); #endif }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="group"></param> /// <param name="ext"></param> /// <param name="images"></param> /// <param name="r"></param> public static void DoImageIO( string name, string group, string ext, ref List<Image> images, Resource r ) { int imgIdx = images.Count; images.Add( new Image() ); Stream stream = ResourceGroupManager.Instance.OpenResource( name, group, true, r ); images[ imgIdx ] = Image.FromStream( stream, ext ); }
public void LoadResource( Resource res ) { // TODO : Revisit after checking current Imaging support in Mono. #if !(XBOX || XBOX360 || ANDROID || IPHONE || SILVERLIGHT) var current = Environment.CurrentDirectory; var ftLibrary = IntPtr.Zero; if ( FT.FT_Init_FreeType( out ftLibrary ) != 0 ) { throw new AxiomException( "Could not init FreeType library!" ); } var face = IntPtr.Zero; // Add a gap between letters vert and horz // prevents nasty artefacts when letters are too close together var char_space = 5; // Locate ttf file, load it pre-buffered into memory by wrapping the // original DataStream in a MemoryDataStream var fileStream = ResourceGroupManager.Instance.OpenResource( Source, Group, true, this ); var ttfchunk = new byte[fileStream.Length]; fileStream.Read( ttfchunk, 0, ttfchunk.Length ); //Load font if ( FT.FT_New_Memory_Face( ftLibrary, ttfchunk, ttfchunk.Length, 0, out face ) != 0 ) { throw new AxiomException( "Could not open font face!" ); } // Convert our point size to freetype 26.6 fixed point format var ftSize = this._ttfSize*( 1 << 6 ); if ( FT.FT_Set_Char_Size( face, ftSize, 0, (uint)this._ttfResolution, (uint)this._ttfResolution ) != 0 ) { throw new AxiomException( "Could not set char size!" ); } int max_height = 0, max_width = 0; // Backwards compatibility - if codepoints not supplied, assume 33-166 if ( this.codePointRange.Count == 0 ) { this.codePointRange.Add( new KeyValuePair<int, int>( 33, 166 ) ); } // Calculate maximum width, height and bearing var glyphCount = 0; foreach ( var r in this.codePointRange ) { var range = r; for ( var cp = range.Key; cp <= range.Value; ++cp, ++glyphCount ) { FT.FT_Load_Char( face, (uint)cp, 4 ); //4 == FT_LOAD_RENDER var rec = face.PtrToStructure<FT_FaceRec>(); var glyp = rec.glyph.PtrToStructure<FT_GlyphSlotRec>(); if ( ( 2*( glyp.bitmap.rows << 6 ) - glyp.metrics.horiBearingY ) > max_height ) { max_height = ( 2*( glyp.bitmap.rows << 6 ) - glyp.metrics.horiBearingY ); } if ( glyp.metrics.horiBearingY > this.maxBearingY ) { this.maxBearingY = glyp.metrics.horiBearingY; } if ( ( glyp.advance.x >> 6 ) + ( glyp.metrics.horiBearingX >> 6 ) > max_width ) { max_width = ( glyp.advance.x >> 6 ) + ( glyp.metrics.horiBearingX >> 6 ); } } } // Now work out how big our texture needs to be var rawSize = ( max_width + char_space )*( ( max_height >> 6 ) + char_space )*glyphCount; var tex_side = (int)System.Math.Sqrt( (Real)rawSize ); // just in case the size might chop a glyph in half, add another glyph width/height tex_side += System.Math.Max( max_width, ( max_height >> 6 ) ); // Now round up to nearest power of two var roundUpSize = (int)Bitwise.FirstPO2From( (uint)tex_side ); // Would we benefit from using a non-square texture (2X width) int finalWidth = 0, finalHeight = 0; if ( roundUpSize*roundUpSize*0.5 >= rawSize ) { finalHeight = (int)( roundUpSize*0.5 ); } else { finalHeight = roundUpSize; } finalWidth = roundUpSize; var textureAspec = (Real)finalWidth/(Real)finalHeight; var pixelBytes = 2; var dataWidth = finalWidth*pixelBytes; var dataSize = finalWidth*finalHeight*pixelBytes; LogManager.Instance.Write( "Font {0} using texture size {1}x{2}", _name, finalWidth.ToString(), finalHeight.ToString() ); var imageData = new byte[dataSize]; // Reset content (White, transparent) for ( var i = 0; i < dataSize; i += pixelBytes ) { imageData[ i + 0 ] = 0xff; // luminance imageData[ i + 1 ] = 0x00; // alpha } int l = 0, m = 0; foreach ( var r in this.codePointRange ) { var range = r; for ( var cp = range.Key; cp <= range.Value; ++cp ) { // Load & render glyph var ftResult = FT.FT_Load_Char( face, (uint)cp, 4 ); //4 == FT_LOAD_RENDER if ( ftResult != 0 ) { // problem loading this glyph, continue LogManager.Instance.Write( "Info: cannot load character '{0}' in font {1}.", #if (SILVERLIGHT || WINDOWS_PHONE) cp, #else char.ConvertFromUtf32( cp ), #endif _name ); continue; } var rec = face.PtrToStructure<FT_FaceRec>(); var glyp = rec.glyph.PtrToStructure<FT_GlyphSlotRec>(); var advance = glyp.advance.x >> 6; if ( glyp.bitmap.buffer == IntPtr.Zero ) { LogManager.Instance.Write( "Info: Freetype returned null for character '{0} in font {1}.", #if (SILVERLIGHT || WINDOWS_PHONE) cp, #else char.ConvertFromUtf32( cp ), #endif _name ); continue; } #if !AXIOM_SAFE_ONLY unsafe #endif { var buffer = BufferBase.Wrap( glyp.bitmap.buffer, glyp.bitmap.rows*glyp.bitmap.pitch ); var bufferPtr = buffer.ToBytePointer(); var idx = 0; var imageDataBuffer = BufferBase.Wrap( imageData ); var imageDataPtr = imageDataBuffer.ToBytePointer(); var y_bearing = ( ( this.maxBearingY >> 6 ) - ( glyp.metrics.horiBearingY >> 6 ) ); var x_bearing = glyp.metrics.horiBearingX >> 6; for ( var j = 0; j < glyp.bitmap.rows; j++ ) { var row = j + m + y_bearing; var pDest = ( row*dataWidth ) + ( l + x_bearing )*pixelBytes; for ( var k = 0; k < glyp.bitmap.width; k++ ) { if ( AntialiasColor ) { // Use the same greyscale pixel for all components RGBA imageDataPtr[ pDest++ ] = bufferPtr[ idx ]; } else { // Always white whether 'on' or 'off' pixel, since alpha // will turn off imageDataPtr[ pDest++ ] = (byte)0xFF; } // Always use the greyscale value for alpha imageDataPtr[ pDest++ ] = bufferPtr[ idx++ ]; } //end k } //end j buffer.Dispose(); imageDataBuffer.Dispose(); SetGlyphTexCoords( (uint)cp, (Real)l/(Real)finalWidth, //u1 (Real)m/(Real)finalHeight, //v1 (Real)( l + ( glyp.advance.x >> 6 ) )/(Real)finalWidth, //u2 ( m + ( max_height >> 6 ) )/(Real)finalHeight, //v2 textureAspec ); // Advance a column l += ( advance + char_space ); // If at end of row if ( finalWidth - 1 < l + ( advance ) ) { m += ( max_height >> 6 ) + char_space; l = 0; } } } } //end foreach var memStream = new MemoryStream( imageData ); var img = Image.FromRawStream( memStream, finalWidth, finalHeight, PixelFormat.BYTE_LA ); var tex = (Texture)res; // Call internal _loadImages, not loadImage since that's external and // will determine load status etc again, and this is a manual loader inside load() var images = new Image[1]; images[ 0 ] = img; tex.LoadImages( images ); FT.FT_Done_FreeType( ftLibrary ); //img.Save( "C:" + Path.DirectorySeparatorChar + Name + ".png" ); //FileStream file = new FileStream( "C:" + Path.DirectorySeparatorChar + Name + ".fontdef", FileMode.Create ); //StreamWriter str = new StreamWriter( file ); //str.WriteLine( Name ); //str.WriteLine( "{" ); //str.WriteLine( "\ttype\timage" ); //str.WriteLine( "\tsource\t{0}.png\n", Name ); //for ( uint i = 0; i < (uint)( END_CHAR - START_CHAR ); i++ ) //{ // char c = (char)( i + START_CHAR ); // str.WriteLine( "\tglyph\t{0}\t{1:F6}\t{2:F6}\t{3:F6}\t{4:F6}", c, Glyphs[ c ].uvRect.Top, Glyphs[ c ].uvRect.Left, Glyphs[ c ].uvRect.Bottom, Glyphs[ c ].uvRect.Right ); //} //str.WriteLine( "}" ); //str.Close(); //file.Close(); #endif }
public void BackgroundLoadingComplete( Resource res ) { //NOTHING TO DO }
public HLSLIncludeHandler( Resource sourceProgram ) { this.program = sourceProgram; }
public void ResourceLoadStarted( Resource resource ) { mLoadingDescriptionElement.Text = resource.Name; mWindow.Update(); }