GetError() 개인적인 메소드

private GetError ( ) : AglError
리턴 AglError
예제 #1
0
        public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil,
                                               int samples, ColorFormat accum, int buffers, bool stereo)
        {
            IntPtr pixelformat;

            do
            {
                pixelformat = SelectPixelFormat(
                    color, depth, stencil, samples, accum, buffers, stereo,
                    true, Device);

                Agl.AglError err = Agl.GetError();
                if (pixelformat == IntPtr.Zero || err == Agl.AglError.BadPixelFormat)
                {
                    Debug.Print("Failed to create full screen pixel format.");
                    Debug.Print("Trying again to create a non-fullscreen pixel format.");
                    pixelformat = SelectPixelFormat(
                        color, depth, stencil, samples, accum, buffers, stereo,
                        false, IntPtr.Zero);
                }

                if (pixelformat == IntPtr.Zero)
                {
                    if (!Utilities.RelaxGraphicsMode(
                            ref color, ref depth, ref stencil, ref samples, ref accum,
                            ref buffers, ref stereo))
                    {
                        throw new GraphicsModeException("Requested GraphicsMode not available.");
                    }
                }
            }while (pixelformat == IntPtr.Zero);

            return(GetGraphicsModeFromPixelFormat(pixelformat));
        }
예제 #2
0
        void Dispose(bool disposing)
        {
            if (IsDisposed || Handle.Handle == IntPtr.Zero)
            {
                return;
            }
            Debug.Print("Disposing of AGL context.");
            Agl.aglSetCurrentContext(IntPtr.Zero);
            //Debug.Print("Setting drawable to null for context {0}.", Handle.Handle);
            //Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero);

            // I do not know MacOS allows us to destroy a context from a separate thread,
            // like the finalizer thread.  It's untested, but worst case is probably
            // an exception on application exit, which would be logged to the console.
            Debug.Print("Destroying context");
            if (Agl.aglDestroyContext(Handle.Handle) == true)
            {
                Debug.Print("Context destruction completed successfully.");
                Handle = ContextHandle.Zero;
                return;
            }

            // failed to destroy context.
            Debug.WriteLine("Failed to destroy context.");
            Debug.WriteLine(Agl.ErrorString(Agl.GetError()));
            // don't throw an exception from the finalizer thread.
            if (disposing)
            {
                throw new MacOSException((OSStatus)Agl.GetError(), Agl.ErrorString(Agl.GetError()));
            }

            IsDisposed = true;
        }
예제 #3
0
 private void MyAGLReportError(string function)
 {
     Agl.AglError error = Agl.GetError();
     if (error != Agl.AglError.NoError)
     {
         throw new MacOSException((OSStatus)error, string.Format("AGL Error from function {0}: {1}  {2}", (object)function, (object)error, (object)Agl.ErrorString(error)));
     }
 }
예제 #4
0
파일: Agl.cs 프로젝트: conankzhang/fez
 internal static void aglSetFullScreen(IntPtr ctx, int width, int height, int freq, int device)
 {
     if ((int)Agl._aglSetFullScreen(ctx, width, height, freq, device) != 0)
     {
         return;
     }
     Agl.AglError error = Agl.GetError();
     throw new MacOSException(error, Agl.ErrorString(error));
 }
예제 #5
0
파일: Agl.cs 프로젝트: conankzhang/fez
 internal static void aglSetDrawable(IntPtr ctx, IntPtr draw)
 {
     if ((int)Agl._aglSetDrawable(ctx, draw) != 0)
     {
         return;
     }
     Agl.AglError error = Agl.GetError();
     throw new MacOSException(error, Agl.ErrorString(error));
 }
예제 #6
0
        private void MyAGLReportError(string function)
        {
            Agl.AglError err = Agl.GetError();

            if (err != Agl.AglError.NoError)
            {
                throw new Exception(String.Format(
                                        "AGL Error from function {0}: {1}  {2}",
                                        function, err, Agl.ErrorString(err)));
            }
        }
예제 #7
0
 private void Dispose(bool disposing)
 {
     if (this.IsDisposed || this.Handle.Handle == IntPtr.Zero)
     {
         return;
     }
     Agl.aglSetCurrentContext(IntPtr.Zero);
     if (Agl.aglDestroyContext(this.Handle.Handle))
     {
         this.Handle = ContextHandle.Zero;
     }
     else
     {
         if (disposing)
         {
             throw new MacOSException((OSStatus)Agl.GetError(), Agl.ErrorString(Agl.GetError()));
         }
         this.IsDisposed = true;
     }
 }
예제 #8
0
        void Dispose(bool disposing)
        {
            if (IsDisposed || Handle.Handle == IntPtr.Zero)
            {
                return;
            }

            Debug.Print("Disposing of AGL context.");

            try
            {
                throw new Exception();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }

            Agl.aglSetCurrentContext(IntPtr.Zero);
            Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero);

            Debug.Print("Set drawable to null for context {0}.", Handle.Handle);

            if (Agl.aglDestroyContext(Handle.Handle) == true)
            {
                Handle = ContextHandle.Zero;
                return;
            }

            // failed to destroy context.
            Debug.WriteLine("Failed to destroy context.");
            Debug.WriteLine(Agl.ErrorString(Agl.GetError()));

            // don't throw an exception from the finalizer thread.
            if (disposing)
            {
                throw new MacOSException((OSStatus)Agl.GetError(), Agl.ErrorString(Agl.GetError()));
            }

            IsDisposed = true;
        }
        public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil,
                                               int samples, ColorFormat accum, int buffers, bool stereo, out IntPtr pixelformat)
        {
            do
            {
                pixelformat = SelectPixelFormat(
                    color, depth, stencil, samples, accum, buffers, stereo);

                if (pixelformat == IntPtr.Zero)
                {
                    if (!RelaxGraphicsMode(
                            ref color, ref depth, ref stencil, ref samples, ref accum,
                            ref buffers, ref stereo))
                    {
                        throw new GraphicsModeException(
                                  "Requested GraphicsMode not available, error: " + Agl.GetError());
                    }
                }
            } while (pixelformat == IntPtr.Zero);

            return(GetGraphicsModeFromPixelFormat(pixelformat));
        }
예제 #10
0
        void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow,
                           IntPtr shareContextRef, bool fullscreen)
        {
            List <int> aglAttributes = new List <int>();

            Debug.Print("AGL pixel format attributes:");
            Debug.Indent();

            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RGBA);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RED_SIZE, mode.ColorFormat.Red);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_GREEN_SIZE, mode.ColorFormat.Green);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_BLUE_SIZE, mode.ColorFormat.Blue);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ALPHA_SIZE, mode.ColorFormat.Alpha);

            if (mode.Depth > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DEPTH_SIZE, mode.Depth);
            }

            if (mode.Stencil > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_STENCIL_SIZE, mode.Stencil);
            }

            if (mode.AccumulatorFormat.BitsPerPixel > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
            }

            if (mode.Samples > 1)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB, 1);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLES_ARB, mode.Samples);
            }

            if (fullscreen)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
            }
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE);

            Debug.Unindent();

            Debug.Write("Attribute array:  ");
            for (int i = 0; i < aglAttributes.Count; i++)
            {
                Debug.Write(aglAttributes[i].ToString() + "  ");
            }
            Debug.WriteLine("");

            AGLPixelFormat myAGLPixelFormat;

            // Choose a pixel format with the attributes we specified.
            if (fullscreen)
            {
                IntPtr gdevice;
                IntPtr cgdevice = GetQuartzDevice(carbonWindow);

                if (cgdevice == IntPtr.Zero)
                {
                    cgdevice = QuartzDisplayDeviceDriver.MainDisplay;
                }

                OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(
                    cgdevice, out gdevice, false);

                if (status != OSStatus.NoError)
                {
                    throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
                }

                myAGLPixelFormat = Agl.aglChoosePixelFormat(
                    ref gdevice, 1,
                    aglAttributes.ToArray());

                Agl.AglError err = Agl.GetError();

                if (err == Agl.AglError.BadPixelFormat)
                {
                    Debug.Print("Failed to create full screen pixel format.");
                    Debug.Print("Trying again to create a non-fullscreen pixel format.");

                    CreateContext(mode, carbonWindow, shareContextRef, false);
                    return;
                }
            }
            else
            {
                myAGLPixelFormat = Agl.aglChoosePixelFormat(
                    IntPtr.Zero, 0,
                    aglAttributes.ToArray());

                MyAGLReportError("aglChoosePixelFormat");
            }


            Debug.Print("Creating AGL context.  Sharing with {0}", shareContextRef);

            // create the context and share it with the share reference.
            Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
            MyAGLReportError("aglCreateContext");

            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(myAGLPixelFormat);
            MyAGLReportError("aglDestroyPixelFormat");

            Debug.Print("IsControl: {0}", carbonWindow.IsControl);

            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);
            Update(carbonWindow);

            MakeCurrent(carbonWindow);

            Debug.Print("context: {0}", Handle.Handle);
        }
예제 #11
0
        private IntPtr SelectPixelFormat(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
        {
            List <int> list = new List <int>();

            if (color.BitsPerPixel > 0)
            {
                if (!color.IsIndexed)
                {
                    list.Add(4);
                }
                list.Add(8);
                list.Add(color.Red);
                list.Add(9);
                list.Add(color.Green);
                list.Add(10);
                list.Add(color.Blue);
                list.Add(11);
                list.Add(color.Alpha);
            }
            if (depth > 0)
            {
                list.Add(12);
                list.Add(depth);
            }
            if (buffers > 1)
            {
                list.Add(5);
            }
            if (stencil > 1)
            {
                list.Add(13);
                list.Add(stencil);
            }
            if (accum.BitsPerPixel > 0)
            {
                list.Add(17);
                list.Add(accum.Alpha);
                list.Add(16);
                list.Add(accum.Blue);
                list.Add(15);
                list.Add(accum.Green);
                list.Add(14);
                list.Add(accum.Red);
            }
            if (samples > 0)
            {
                list.Add(55);
                list.Add(1);
                list.Add(56);
                list.Add(samples);
            }
            if (stereo)
            {
                list.Add(6);
            }
            list.Add(0);
            list.Add(0);
            IntPtr num = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, list.ToArray());

            if (num == IntPtr.Zero)
            {
                throw new GraphicsModeException(string.Format("[Error] Failed to select GraphicsMode, error {0}.", (object)Agl.GetError()));
            }
            else
            {
                return(num);
            }
        }
예제 #12
0
        private void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
        {
            List <int> aglAttributes = new List <int>();

            this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RGBA);
            this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER);
            this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RED_SIZE, mode.ColorFormat.Red);
            this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_GREEN_SIZE, mode.ColorFormat.Green);
            this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_BLUE_SIZE, mode.ColorFormat.Blue);
            this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ALPHA_SIZE, mode.ColorFormat.Alpha);
            if (mode.Depth > 0)
            {
                this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DEPTH_SIZE, mode.Depth);
            }
            if (mode.Stencil > 0)
            {
                this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_STENCIL_SIZE, mode.Stencil);
            }
            if (mode.AccumulatorFormat.BitsPerPixel > 0)
            {
                this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
                this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
                this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
                this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
            }
            if (mode.Samples > 1)
            {
                this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB, 1);
                this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLES_ARB, mode.Samples);
            }
            if (fullscreen)
            {
                this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
            }
            this.AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE);
            int num = 0;

            while (num < aglAttributes.Count)
            {
                ++num;
            }
            IntPtr pix;

            if (fullscreen)
            {
                IntPtr displayID = this.GetQuartzDevice(carbonWindow);
                if (displayID == IntPtr.Zero)
                {
                    displayID = (IntPtr)DisplayDevice.Default.Id;
                }
                IntPtr   displayDevice;
                OSStatus gdeviceByDisplayId = API.DMGetGDeviceByDisplayID(displayID, out displayDevice, false);
                if (gdeviceByDisplayId != OSStatus.NoError)
                {
                    throw new MacOSException(gdeviceByDisplayId, "DMGetGDeviceByDisplayID failed.");
                }
                pix = Agl.aglChoosePixelFormat(ref displayDevice, 1, aglAttributes.ToArray());
                if (Agl.GetError() == Agl.AglError.BadPixelFormat)
                {
                    this.CreateContext(mode, carbonWindow, shareContextRef, false);
                    return;
                }
            }
            else
            {
                pix = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, aglAttributes.ToArray());
                this.MyAGLReportError("aglChoosePixelFormat");
            }
            this.Handle = new ContextHandle(Agl.aglCreateContext(pix, shareContextRef));
            this.MyAGLReportError("aglCreateContext");
            Agl.aglDestroyPixelFormat(pix);
            this.MyAGLReportError("aglDestroyPixelFormat");
            this.SetDrawable(carbonWindow);
            this.SetBufferRect(carbonWindow);
            this.Update((IWindowInfo)carbonWindow);
            this.MakeCurrent((IWindowInfo)carbonWindow);
        }
예제 #13
0
        IntPtr SelectPixelFormat(ColorFormat color, int depth, int stencil, int samples,
                                 ColorFormat accum, int buffers, bool stereo)
        {
            List <int> attribs = new List <int>();

            Debug.Print("Bits per pixel: {0}", color.BitsPerPixel);

            if (color.BitsPerPixel > 0)
            {
                if (!color.IsIndexed)
                {
                    attribs.Add((int)Agl.PixelFormatAttribute.AGL_RGBA);
                }
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_RED_SIZE);
                attribs.Add(color.Red);
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_GREEN_SIZE);
                attribs.Add(color.Green);
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_BLUE_SIZE);
                attribs.Add(color.Blue);
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_ALPHA_SIZE);
                attribs.Add(color.Alpha);
            }

            Debug.Print("Depth: {0}", depth);

            if (depth > 0)
            {
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_DEPTH_SIZE);
                attribs.Add(depth);
            }

            if (buffers > 1)
            {
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER);
            }

            if (stencil > 1)
            {
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_STENCIL_SIZE);
                attribs.Add(stencil);
            }

            if (accum.BitsPerPixel > 0)
            {
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE);
                attribs.Add(accum.Alpha);
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE);
                attribs.Add(accum.Blue);
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE);
                attribs.Add(accum.Green);
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE);
                attribs.Add(accum.Red);
            }

            if (samples > 0)
            {
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB);
                attribs.Add(1);
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_SAMPLES_ARB);
                attribs.Add(samples);
            }

            if (stereo)
            {
                attribs.Add((int)Agl.PixelFormatAttribute.AGL_STEREO);
            }

            attribs.Add(0);
            attribs.Add(0);

            IntPtr pixelformat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs.ToArray());

            if (pixelformat == IntPtr.Zero)
            {
                throw new GraphicsModeException(String.Format(
                                                    "[Error] Failed to select GraphicsMode, error {0}.", Agl.GetError()));
            }
            return(pixelformat);
        }
예제 #14
0
        void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
        {
            Debug.Print("AGL pixel format attributes:");

            AGLPixelFormat myAGLPixelFormat;

            // Choose a pixel format with the attributes we specified.
            if (fullscreen)
            {
                IntPtr gdevice;
                IntPtr cgdevice = GetQuartzDevice(carbonWindow);

                if (cgdevice == IntPtr.Zero)
                {
                    cgdevice = (IntPtr)DisplayDevice.Default.Id;
                }

                OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(cgdevice, out gdevice, false);

                if (status != OSStatus.NoError)
                {
                    throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
                }

                myAGLPixelFormat = ModeSelector.SelectPixelFormat(
                    mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
                    mode.AccumulatorFormat, mode.Buffers, mode.Stereo,
                    true, gdevice);

                Agl.AglError err = Agl.GetError();
                if (myAGLPixelFormat == IntPtr.Zero || err == Agl.AglError.BadPixelFormat)
                {
                    Debug.Print("Failed to create full screen pixel format.");
                    Debug.Print("Trying again to create a non-fullscreen pixel format.");

                    CreateContext(mode, carbonWindow, shareContextRef, false);
                    return;
                }
            }
            else
            {
                myAGLPixelFormat = ModeSelector.SelectPixelFormat(
                    mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
                    mode.AccumulatorFormat, mode.Buffers, mode.Stereo,
                    false, IntPtr.Zero);
                MyAGLReportError("aglChoosePixelFormat");
            }

            Debug.Print("Creating AGL context.  Sharing with {0}", shareContextRef);

            // create the context and share it with the share reference.
            Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
            MyAGLReportError("aglCreateContext");

            Mode = ModeSelector.GetGraphicsModeFromPixelFormat(myAGLPixelFormat);

            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(myAGLPixelFormat);
            MyAGLReportError("aglDestroyPixelFormat");

            Debug.Print("IsControl: {0}", carbonWindow.IsControl);

            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);
            Update(carbonWindow);

            MakeCurrent(carbonWindow);
            Debug.Print("context: {0}", Handle.Handle);
        }