Added debugging information for pixel formats.

This commit is contained in:
kanato 2008-12-29 01:31:21 +00:00
parent 14ea26c866
commit 23f4858e2c

View file

@ -8,6 +8,7 @@
// //
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Control = System.Windows.Forms.Control; using Control = System.Windows.Forms.Control;
@ -47,32 +48,63 @@ namespace OpenTK.Platform.MacOS
CreateContext(mode, carbonWindow, shareContext); CreateContext(mode, carbonWindow, shareContext);
} }
private void AddPixelAttrib(List<int> aglAttributes, Agl.PixelFormatAttribute pixelFormatAttribute)
{
Debug.Print(pixelFormatAttribute.ToString());
aglAttributes.Add((int)pixelFormatAttribute);
}
private void AddPixelAttrib(List<int> aglAttributes, Agl.PixelFormatAttribute pixelFormatAttribute, int value)
{
Debug.Print("{0} : {1}", pixelFormatAttribute, value);
aglAttributes.Add((int)pixelFormatAttribute);
aglAttributes.Add(value);
}
void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IGraphicsContext shareContext) void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IGraphicsContext shareContext)
{ {
int[] attributes = List<int> aglAttributes = new List<int>();
Debug.Print("AGL 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)
{ {
(int)Agl.PixelFormatAttribute.AGL_RGBA, AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
(int)Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER, AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
(int)Agl.PixelFormatAttribute.AGL_RED_SIZE, mode.ColorFormat.Red, AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
(int)Agl.PixelFormatAttribute.AGL_GREEN_SIZE, mode.ColorFormat.Green, AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
(int)Agl.PixelFormatAttribute.AGL_BLUE_SIZE, mode.ColorFormat.Blue, }
(int)Agl.PixelFormatAttribute.AGL_ALPHA_SIZE, mode.ColorFormat.Alpha, //AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
(int)Agl.PixelFormatAttribute.AGL_DEPTH_SIZE, mode.Depth, AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE);
(int)Agl.PixelFormatAttribute.AGL_STENCIL_SIZE, mode.Stencil,
(int)Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red, Debug.Unindent();
(int)Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green,
(int)Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue, Debug.Write("Attribute array: ");
(int)Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha, for (int i = 0; i < aglAttributes.Count; i++)
(int)Agl.PixelFormatAttribute.AGL_FULLSCREEN, Debug.Write(aglAttributes[i].ToString() + " ");
(int)Agl.PixelFormatAttribute.AGL_NONE, Debug.WriteLine("");
};
AGLPixelFormat myAGLPixelFormat; AGLPixelFormat myAGLPixelFormat;
IntPtr shareContextRef = IntPtr.Zero; IntPtr shareContextRef = IntPtr.Zero;
// Choose a pixel format with the attributes we specified. // Choose a pixel format with the attributes we specified.
myAGLPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attributes); myAGLPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, aglAttributes.ToArray());
MyAGLReportError(); MyAGLReportError("aglChoosePixelFormat");
if (shareContext != null) if (shareContext != null)
{ {
@ -84,11 +116,11 @@ namespace OpenTK.Platform.MacOS
// create the context and share it with the share reference. // create the context and share it with the share reference.
this.contextRef = Agl.aglCreateContext(myAGLPixelFormat, shareContextRef); this.contextRef = Agl.aglCreateContext(myAGLPixelFormat, shareContextRef);
MyAGLReportError(); MyAGLReportError("aglCreateContext");
// Free the pixel format from memory. // Free the pixel format from memory.
Agl.aglDestroyPixelFormat(myAGLPixelFormat); Agl.aglDestroyPixelFormat(myAGLPixelFormat);
MyAGLReportError(); MyAGLReportError("aglDestroyPixelFormat");
Debug.Print("IsControl: {0}", carbonWindow.IsControl); Debug.Print("IsControl: {0}", carbonWindow.IsControl);
@ -100,6 +132,7 @@ namespace OpenTK.Platform.MacOS
Debug.Print("context: {0}", contextRef); Debug.Print("context: {0}", contextRef);
} }
void SetBufferRect(CarbonWindowInfo carbonWindow) void SetBufferRect(CarbonWindowInfo carbonWindow)
{ {
if (carbonWindow.IsControl == false) if (carbonWindow.IsControl == false)
@ -129,10 +162,10 @@ namespace OpenTK.Platform.MacOS
glrect[3] = rect.Height; glrect[3] = rect.Height;
Agl.aglSetInteger(contextRef, Agl.ParameterNames.AGL_BUFFER_RECT, glrect); Agl.aglSetInteger(contextRef, Agl.ParameterNames.AGL_BUFFER_RECT, glrect);
MyAGLReportError(); MyAGLReportError("aglSetInteger");
Agl.aglEnable(contextRef, Agl.ParameterNames.AGL_BUFFER_RECT); Agl.aglEnable(contextRef, Agl.ParameterNames.AGL_BUFFER_RECT);
MyAGLReportError(); MyAGLReportError("aglEnable");
} }
void SetDrawable(CarbonWindowInfo carbonWindow) void SetDrawable(CarbonWindowInfo carbonWindow)
@ -152,7 +185,7 @@ namespace OpenTK.Platform.MacOS
Agl.aglSetDrawable(contextRef, windowPort); Agl.aglSetDrawable(contextRef, windowPort);
MyAGLReportError(); MyAGLReportError("aglSetDrawable");
} }
public void Update(IWindowInfo window) public void Update(IWindowInfo window)
@ -165,12 +198,13 @@ namespace OpenTK.Platform.MacOS
Agl.aglUpdateContext(contextRef); Agl.aglUpdateContext(contextRef);
} }
void MyAGLReportError() void MyAGLReportError(string function)
{ {
Agl.AglError err = Agl.GetError(); Agl.AglError err = Agl.GetError();
if (err != Agl.AglError.NoError) if (err != Agl.AglError.NoError)
throw new MacOSException((OSStatus)err, "AGL Error: " + err.ToString() + " " + Agl.ErrorString(err)); throw new MacOSException((OSStatus)err, string.Format(
"AGL Error from function {0}: {1} {2}", err, Agl.ErrorString(err)));
} }
static ContextHandle GetCurrentContext() static ContextHandle GetCurrentContext()
@ -191,13 +225,13 @@ namespace OpenTK.Platform.MacOS
} }
Agl.aglSwapBuffers(contextRef); Agl.aglSwapBuffers(contextRef);
MyAGLReportError(); MyAGLReportError("aglSwapBuffers");
} }
public void MakeCurrent(IWindowInfo window) public void MakeCurrent(IWindowInfo window)
{ {
if (Agl.aglSetCurrentContext(contextRef) == false) if (Agl.aglSetCurrentContext(contextRef) == false)
MyAGLReportError(); MyAGLReportError("aglSetCurrentContext");
} }
public bool IsCurrent public bool IsCurrent