protected override void OnHandleCreated(EventArgs e)
 {
     base.OnHandleCreated(e);
     if (!DesignMode)
     {
         this.Context = GlContextFactory.CreateFromWindowHandle(this.Handle);
         this.Context.MakeCurrent();
     }
 }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <see cref="http://www.opentk.com/doc/graphics/graphicscontext"/>
        //[HandleProcessCorruptedStateExceptions]
        public override void InitSynchronizedOnce()
        {
            //Memory.WriteBytesHook += OnMemoryWrite;
            ScaleViewport = PspStoredConfig.RenderScale;

            if (!AlreadyInitialized)
            {
                AlreadyInitialized = true;
                var completedEvent = new AutoResetEvent(false);
                new Thread(() =>
                {
                    Thread.CurrentThread.CurrentCulture = new CultureInfo(GlobalConfig.ThreadCultureName);

                    OpenglContext = GlContextFactory.CreateWindowless();
                    OpenglContext.MakeCurrent();

                    Console.Out.WriteLineColored(ConsoleColor.White, "## OpenGL Context Version: {0}",
                                                 GlGetString(GL.GL_VERSION));
                    Console.Out.WriteLineColored(ConsoleColor.White, "## Depth Bits: {0}",
                                                 GL.glGetInteger(GL.GL_DEPTH_BITS));
                    Console.Out.WriteLineColored(ConsoleColor.White, "## Stencil Bits: {0}",
                                                 GL.glGetInteger(GL.GL_STENCIL_BITS));
                    Console.Out.WriteLineColored(ConsoleColor.White, "## Color Bits: {0},{1},{2},{3}",
                                                 GL.glGetInteger(GL.GL_RED_BITS), GL.glGetInteger(GL.GL_GREEN_BITS),
                                                 GL.glGetInteger(GL.GL_BLUE_BITS), GL.glGetInteger(GL.GL_ALPHA_BITS));

                    if (GL.glGetInteger(GL.GL_STENCIL_BITS) <= 0)
                    {
                        Console.Error.WriteLineColored(ConsoleColor.Red, "No stencil bits available!");
                    }

                    OpenglContext.ReleaseCurrent();

                    completedEvent.Set();
                    Console.WriteLine("OpenglGpuImpl.Init.Start()");
                    try
                    {
                        while (Running)
                        {
                            Thread.Sleep(10);
                        }
                        StopEvent.Set();
                    }
                    finally
                    {
                        Console.WriteLine("OpenglGpuImpl.Init.End()");
                    }
                })
                {
                    Name         = "GpuImplEventHandling",
                    IsBackground = true
                }.Start();

                completedEvent.WaitOne();
            }
        }
示例#3
0
        private static void _MainData()
        {
            var context = GlContextFactory.CreateWindowless().MakeCurrent();
            //var BitmapIn = new Bitmap(Image.FromFile(@"C:\temp\1.png"));
            var bitmapIn = new Bitmap(@"C:\temp\in.png");

            Console.WriteLine("{0}", string.Join("\n", Assembly.GetExecutingAssembly().GetManifestResourceNames()));

            var textureOut = new XBRShader().Process(GlTextureCreateFromBitmap(bitmapIn));

            new Bitmap(textureOut.Width, textureOut.Height)
            .SetChannelsDataInterleaved(textureOut.GetDataFromGpu(), BitmapChannelList.Rgba)
            .Save(@"c:\temp\out.png");

            //var Smaa = new Smaa();
            //var TextureIn = GLTextureCreateFromBitmap(BitmapIn);
            //var TextureOut = Smaa.Process(TextureIn, null);
            //
            //new Bitmap(TextureOut.Width, TextureOut.Height).SetChannelsDataInterleaved(TextureOut.GetDataFromGpu(), BitmapChannelList.RGBA).Save(@"c:\temp\test.out.png");
            //
            //File.WriteAllBytes(@"c:\temp\test.out.bin", TextureOut.GetDataFromGpu());

            Environment.Exit(0);
        }