mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 17:45:37 +00:00
First commit which includes support for drawing to a WinForms control.
This commit is contained in:
parent
ec92b72469
commit
11430665f3
6
Source/Examples/ExampleLauncher.Designer.cs
generated
6
Source/Examples/ExampleLauncher.Designer.cs
generated
|
@ -1,4 +1,4 @@
|
|||
namespace Examples
|
||||
namespace Examples
|
||||
{
|
||||
partial class ExampleLauncher
|
||||
{
|
||||
|
@ -85,9 +85,9 @@
|
|||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(292, 266);
|
||||
this.ClientSize = new System.Drawing.Size(292, 366);
|
||||
this.Controls.Add(this.splitContainer1);
|
||||
this.MinimumSize = new System.Drawing.Size(300, 300);
|
||||
this.MinimumSize = new System.Drawing.Size(300, 400);
|
||||
this.Name = "ExampleLauncher";
|
||||
this.Text = "OpenTK Example Launcher";
|
||||
this.Load += new System.EventHandler(this.ExampleLauncher_Load);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region --- License ---
|
||||
#region --- License ---
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
|
@ -37,7 +37,7 @@ namespace Examples.Tutorial
|
|||
|
||||
#region --- Constructor ---
|
||||
|
||||
public T03_Immediate_Mode_Cube() : base(800, 600, new GraphicsMode(16, 16))
|
||||
public T03_Immediate_Mode_Cube() : base(800, 600, new GraphicsMode(32, 16))
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace Examples.WinForms
|
||||
namespace Examples.WinForms
|
||||
{
|
||||
partial class W01_First_Window
|
||||
{
|
||||
|
@ -69,13 +69,13 @@
|
|||
//
|
||||
// glControl1
|
||||
//
|
||||
this.glControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
this.glControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.glControl1.BackColor = System.Drawing.SystemColors.ControlDarkDark;
|
||||
this.glControl1.Location = new System.Drawing.Point(1, 0);
|
||||
this.glControl1.Location = new System.Drawing.Point(10, 10);
|
||||
this.glControl1.Name = "glControl1";
|
||||
this.glControl1.Size = new System.Drawing.Size(629, 565);
|
||||
this.glControl1.Size = new System.Drawing.Size(629, 225);
|
||||
this.glControl1.TabIndex = 0;
|
||||
this.glControl1.VSync = false;
|
||||
this.glControl1.Resize += new System.EventHandler(this.glControl1_Resize);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region --- License ---
|
||||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
|
@ -59,6 +59,8 @@ namespace Examples.WinForms
|
|||
|
||||
private void glControl1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
System.Diagnostics.Debug.Print("Repainting glControl.");
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
glControl1.SwapBuffers();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region --- License ---
|
||||
#region --- License ---
|
||||
/* This source file is released under the MIT license. See License.txt for more information.
|
||||
* Coded by Erik Ylvisaker and Stefanos Apostolopoulos.
|
||||
*/
|
||||
|
@ -155,6 +155,7 @@ namespace Examples.WinForms
|
|||
DrawCube();
|
||||
|
||||
glControl.SwapBuffers();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -28,12 +28,25 @@ namespace OpenTK.Platform.MacOS
|
|||
bool mVSync = false;
|
||||
IntPtr displayID;
|
||||
|
||||
GraphicsMode mode;
|
||||
CarbonWindowInfo carbonWindow;
|
||||
IGraphicsContext shareContext;
|
||||
|
||||
static AglContext()
|
||||
{
|
||||
if (GraphicsContext.GetCurrentContext == null)
|
||||
GraphicsContext.GetCurrentContext = AglContext.GetCurrentContext;
|
||||
}
|
||||
public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
|
||||
{
|
||||
this.mode = mode;
|
||||
this.carbonWindow = (CarbonWindowInfo)window;
|
||||
this.shareContext = shareContext;
|
||||
|
||||
CreateContext(mode, carbonWindow, shareContext);
|
||||
}
|
||||
|
||||
void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IGraphicsContext shareContext)
|
||||
{
|
||||
int[] attributes =
|
||||
{
|
||||
|
@ -53,10 +66,8 @@ namespace OpenTK.Platform.MacOS
|
|||
(int)Agl.PixelFormatAttribute.AGL_NONE,
|
||||
};
|
||||
|
||||
AGLContext myAGLContext = IntPtr.Zero;
|
||||
AGLPixelFormat myAGLPixelFormat;
|
||||
IntPtr shareContextRef = IntPtr.Zero;
|
||||
CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window;
|
||||
|
||||
// Choose a pixel format with the attributes we specified.
|
||||
myAGLPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attributes);
|
||||
|
@ -71,70 +82,25 @@ namespace OpenTK.Platform.MacOS
|
|||
shareContextRef = ((AglContext)shareContext).contextRef;
|
||||
|
||||
// create the context and share it with the share reference.
|
||||
myAGLContext = Agl.aglCreateContext(myAGLPixelFormat, shareContextRef);
|
||||
this.contextRef = Agl.aglCreateContext(myAGLPixelFormat, shareContextRef);
|
||||
MyAGLReportError();
|
||||
|
||||
// Free the pixel format from memory.
|
||||
Agl.aglDestroyPixelFormat(myAGLPixelFormat);
|
||||
MyAGLReportError();
|
||||
|
||||
|
||||
IntPtr windowPort;
|
||||
|
||||
Debug.Print("IsControl: {0}", carbonWindow.IsControl);
|
||||
if (carbonWindow.IsControl)
|
||||
{
|
||||
IntPtr controlOwner = API.GetControlOwner(carbonWindow.WindowRef);
|
||||
|
||||
Debug.Print("GetControlOwner: {0}", controlOwner);
|
||||
SetDrawable(carbonWindow);
|
||||
SetBufferRect(carbonWindow);
|
||||
Update(carbonWindow);
|
||||
|
||||
windowPort = API.GetWindowPort(controlOwner);
|
||||
}
|
||||
else
|
||||
windowPort = API.GetWindowPort(carbonWindow.WindowRef);
|
||||
|
||||
windowPort = API.GetWindowPort(carbonWindow.WindowRef);
|
||||
Agl.aglSetDrawable(myAGLContext, windowPort);
|
||||
|
||||
MyAGLReportError();
|
||||
|
||||
if (carbonWindow.IsControl)
|
||||
{
|
||||
Rect rect = API.GetControlBounds(carbonWindow.WindowRef);
|
||||
HIRect hirect = API.HIViewGetFrame(carbonWindow.WindowRef);
|
||||
|
||||
Debug.Print("Setting buffer_rect for control.");
|
||||
Debug.Print("Rect: {0}", rect);
|
||||
Debug.Print("HIRect: {0}", hirect);
|
||||
|
||||
int[] glrect = new int[4];
|
||||
|
||||
glrect[0] = rect.Left;
|
||||
glrect[1] = rect.Top;
|
||||
glrect[2] = rect.Width;
|
||||
glrect[3] = rect.Height;
|
||||
|
||||
Agl.aglSetInteger(myAGLContext, Agl.ParameterNames.AGL_BUFFER_RECT, glrect);
|
||||
MyAGLReportError();
|
||||
|
||||
Agl.aglEnable(myAGLContext, Agl.ParameterNames.AGL_BUFFER_RECT);
|
||||
MyAGLReportError();
|
||||
}
|
||||
|
||||
//
|
||||
MyAGLReportError();
|
||||
|
||||
MakeCurrent(window);
|
||||
|
||||
this.contextRef = myAGLContext;
|
||||
MakeCurrent(carbonWindow);
|
||||
|
||||
Debug.Print("context: {0}", contextRef);
|
||||
}
|
||||
|
||||
public void Update(IWindowInfo window)
|
||||
void SetBufferRect(CarbonWindowInfo carbonWindow)
|
||||
{
|
||||
CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window;
|
||||
|
||||
if (carbonWindow.IsControl)
|
||||
{
|
||||
Rect rect = API.GetControlBounds(carbonWindow.WindowRef);
|
||||
|
@ -154,10 +120,38 @@ namespace OpenTK.Platform.MacOS
|
|||
Agl.aglSetInteger(contextRef, Agl.ParameterNames.AGL_BUFFER_RECT, glrect);
|
||||
MyAGLReportError();
|
||||
|
||||
Agl.aglEnable(contextRef, Agl.ParameterNames.AGL_BUFFER_RECT);
|
||||
MyAGLReportError();
|
||||
}
|
||||
}
|
||||
void SetDrawable(CarbonWindowInfo carbonWindow)
|
||||
{
|
||||
IntPtr windowPort;
|
||||
|
||||
if (carbonWindow.IsControl)
|
||||
{
|
||||
IntPtr controlOwner = API.GetControlOwner(carbonWindow.WindowRef);
|
||||
|
||||
Debug.Print("GetControlOwner: {0}", controlOwner);
|
||||
|
||||
windowPort = API.GetWindowPort(controlOwner);
|
||||
}
|
||||
else
|
||||
windowPort = API.GetWindowPort(carbonWindow.WindowRef);
|
||||
|
||||
Agl.aglSetDrawable(contextRef, windowPort);
|
||||
|
||||
MyAGLReportError();
|
||||
|
||||
}
|
||||
public void Update(IWindowInfo window)
|
||||
{
|
||||
CarbonWindowInfo carbonWindow = (CarbonWindowInfo)window;
|
||||
|
||||
SetBufferRect(carbonWindow);
|
||||
|
||||
//Agl.aglSetCurrentContext(contextRef);
|
||||
Agl.aglUpdateContext(contextRef);
|
||||
//Agl.aglSetDrawable(contextRef, API.GetWindowPort(carbonWindow.WindowRef));
|
||||
|
||||
}
|
||||
void MyAGLReportError()
|
||||
|
@ -174,9 +168,17 @@ namespace OpenTK.Platform.MacOS
|
|||
}
|
||||
|
||||
#region IGraphicsContext Members
|
||||
|
||||
bool first = false;
|
||||
public void SwapBuffers()
|
||||
{
|
||||
if (first == false && carbonWindow.IsControl)
|
||||
{
|
||||
Debug.WriteLine("--> Resetting drawable. <--");
|
||||
first = true;
|
||||
SetDrawable(carbonWindow);
|
||||
Update(carbonWindow);
|
||||
}
|
||||
|
||||
Agl.aglSwapBuffers(contextRef);
|
||||
MyAGLReportError();
|
||||
}
|
||||
|
|
|
@ -25,9 +25,15 @@ namespace OpenTK.Platform.MacOS
|
|||
return new GraphicsContext(mode, WindowInfo);
|
||||
}
|
||||
|
||||
// TODO: Fix this
|
||||
bool lastIsIdle = false;
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return true; }
|
||||
get
|
||||
{
|
||||
lastIsIdle = !lastIsIdle;
|
||||
return lastIsIdle;
|
||||
}
|
||||
}
|
||||
|
||||
public IWindowInfo WindowInfo
|
||||
|
|
Loading…
Reference in a new issue