         let region = MTLRegionMake2D(0, 0, Int(image.size.width), Int(image.size.height))
         texture.replace(region: region, mipmapLevel: 0, slice: 0, withBytes: image.bitmapData!, bytesPerRow: image.bytesPerRow, bytesPerImage: image.bytesPerRow * Int(image.size.height))
 
-//        var rect = NSMakeRect(0, 0, image.size.width, image.size.height)
-//        let cgImage = image.cgImage(forProposedRect: &rect, context: nil, hints: nil)!
-//        let loader = MTKTextureLoader(device: device)
-//        let texture = try! loader.newTexture(with:cgImage, options: nil)
-        
         return texture
     }
 

        color.set()
        path.fill()
        
//        NSGraphicsContext.restoreGraphicsState()
        
        image.unlockFocus()

        image.lockFocus()
        let imageRep = NSBitmapImageRep(focusedViewRect: NSMakeRect(0, 0, CGFloat(imageSize), CGFloat(imageSize)))
        image.unlockFocus()
            
        return imageRep!
    }
    
    func createTextureForBitmapImageRep(_ image: NSBitmapImageRep) -> MTLTexture

        let overscan = CGFloat(0.05) // the glyph is a little bigger than 1x1
        let imageSize = Int(floor(glyphSize * (1 + overscan)))
        
        let imageRep = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: imageSize, pixelsHigh: imageSize, bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: NSCalibratedRGBColorSpace, bytesPerRow: imageSize*4, bitsPerPixel:32)!
        
        NSGraphicsContext.saveGraphicsState()
        NSGraphicsContext.setCurrent(NSGraphicsContext(bitmapImageRep: imageRep))
#if false
        let p0 = NSBezierPath()
        p0.appendRect(NSMakeRect(0, 0, CGFloat(imageSize), CGFloat(imageSize)))
