本文整理汇总了C#中IGraphicsContext.MakeCurrent方法的典型用法代码示例。如果您正苦于以下问题:C# IGraphicsContext.MakeCurrent方法的具体用法?C# IGraphicsContext.MakeCurrent怎么用?C# IGraphicsContext.MakeCurrent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGraphicsContext
的用法示例。
在下文中一共展示了IGraphicsContext.MakeCurrent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GameWindow
/// <summary>Constructs a new GameWindow with the specified attributes.</summary>
/// <param name="width">The width of the GameWindow in pixels.</param>
/// <param name="height">The height of the GameWindow in pixels.</param>
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
/// <param name="title">The title of the GameWindow.</param>
/// <param name="options">GameWindow options regarding window appearance and behavior.</param>
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
public GameWindow(int width, int height, GraphicsMode mode, string title, bool nullContext,
GameWindowFlags options, DisplayDevice device)
: base(width, height, title, options, mode, device)
{
try {
glContext = nullContext ? new NullContext() :
Factory.Default.CreateGLContext(mode, WindowInfo);
glContext.MakeCurrent(WindowInfo);
glContext.LoadAll();
VSync = true;
} catch (Exception e) {
Debug.Print(e.ToString());
base.Dispose();
throw;
}
}
示例2: Initialize
public void Initialize()
{
// <Rant>
// OpenTK has a great fuckup in its design here. It's absolutly nohm it possible to create
// a render context for offscreen rendering without creating an OpenTK window.
// before.
// Passing Utilities.CreateDummyWindowInfo() or anything else will cause an invalid cast exception
// Using Utilities.CreateWindowsWindowInfo(IntPtr.Zero) binds the code to windows only
// Really great, why do i need to have a window in order to render to memory? -_-
//</Rant>
_window = new NativeWindow { Visible = false };
_context = new GraphicsContext(GraphicsMode.Default, _window.WindowInfo, 2, 0, GraphicsContextFlags.Default);
_context.MakeCurrent(_window.WindowInfo);
_context.LoadAll();
// create offscreen rendertarget with high precision
_rtt = new RenderToTexture(1, 1, false, 4, typeof(float));
int precision;
int range;
GL.GetShaderPrecisionFormat(OpenTK.Graphics.OpenGL.ShaderType.FragmentShader, ShaderPrecisionType.HighFloat, out range, out precision);
Debug.WriteLine("Precision: {0}, Range {1}", precision, range);
// init SL#
Bindings.OpenTK.SLSharp.Init();
}
示例3: BindContext
public static bool BindContext(IGraphicsContext context)
{
if (!context.IsDisposed)
{
context.MakeCurrent(Contexts[context].Window);
return true;
} else {
return false;
}
}
示例4: SDL2GLContext
public SDL2GLContext (GraphicsMode mode, IWindowInfo windowInfo, IGraphicsContext shared, bool direct,
int major, int minor, GraphicsContextFlags flags)
{
SDL2WindowInfo currentWindow = (SDL2WindowInfo)windowInfo;
window = currentWindow.WindowHandle;
if (shared != null) {
shared.MakeCurrent (windowInfo);
lock (API.sdl_api_lock) {
API.GL_SetAttribute (API.GLAttr.ShareWithCurrentContext, 1);
}
}
lock (API.sdl_api_lock) {
context = API.GL_CreateContext (currentWindow.WindowHandle);
}
MakeCurrent (windowInfo);
if (shared != null) {
shared.MakeCurrent (windowInfo);
}
Handle = new ContextHandle(context);
}
示例5: UseOpenGLCreationContext
public UseOpenGLCreationContext(GraphicsDevice graphicsDevice)
: this()
{
#if SILICONSTUDIO_PLATFORM_ANDROID
// Unfortunately, android seems to not use GraphicsContext.CurrentContext to register its AndroidGraphicsContext,
// so let's query EGL directly.
if (GraphicsDevice.EglGetCurrentContext() == IntPtr.Zero)
#elif SILICONSTUDIO_PLATFORM_IOS
if (OpenGLES.EAGLContext.CurrentContext == null)
#else
if (GraphicsContext.CurrentContext == null)
#endif
{
needUnbindContext = true;
useDeviceCreationContext = true;
#if SILICONSTUDIO_PLATFORM_ANDROID
tegraWorkaround = graphicsDevice.Workaround_Context_Tegra2_Tegra3;
// Notify main rendering thread there is some pending async work to do
if (tegraWorkaround)
{
useDeviceCreationContext = false; // We actually use real main context, so states will be kept
graphicsDevice.AsyncPendingTaskWaiting = true;
}
#endif
// Lock, since there is only one deviceCreationContext.
// TODO: Support multiple deviceCreationContext (TLS creation of context was crashing, need to investigate why)
asyncCreationLockObject = graphicsDevice.asyncCreationLockObject;
Monitor.Enter(graphicsDevice.asyncCreationLockObject, ref asyncCreationLockTaken);
#if SILICONSTUDIO_PLATFORM_ANDROID
if (tegraWorkaround)
graphicsDevice.AsyncPendingTaskWaiting = false;
// On android, bind the actual android context
// The deviceCreationContext is a dummy one, so that CurrentContext works.
androidDeviceCreationContext = graphicsDevice.androidAsyncDeviceCreationContext;
if (androidDeviceCreationContext != null)
androidDeviceCreationContext.MakeCurrent(graphicsDevice.deviceCreationWindowInfo);
#endif
// Bind the context
deviceCreationContext = graphicsDevice.deviceCreationContext;
deviceCreationContext.MakeCurrent(graphicsDevice.deviceCreationWindowInfo);
}
}
示例6: GLService
static GLService()
{
Lock = new object();
ContextReferenceCount = new ThreadLocal<int>(() => 0, false);
GLControl = new GLControl(GraphicsMode.Default);
GLControl.CreateControl();
//GLWindow = new NativeWindow();
GLGraphicsContext = GLControl.Context;
//GLGraphicsContext = new GraphicsContext(GraphicsMode.Default, GLControl.WindowInfo);
SubscribeContexts = new ConcurrentDictionary<WindowsFormsHost, SubscribeContext>();
DrawingContexts = new ConcurrentDictionary<Action, DrawingContext>();
GLGraphicsContext.MakeCurrent(null);
DisposableSerivce.Register(new DisposableAction(Dispose));
}
示例7: Program
public Program(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device,
int major, int minor, GraphicsContextFlags flags, IGraphicsContext sharedContext)
: base(width, height, title, options,
mode == null ? GraphicsMode.Default : mode,
device == null ? DisplayDevice.Default : device)
{
try
{
glContext = new GraphicsContext(mode == null ? GraphicsMode.Default : mode, WindowInfo, major, minor, flags);
glContext.MakeCurrent(WindowInfo);
(glContext as IGraphicsContextInternal).LoadAll();
}
catch (Exception e)
{
Debug.Print(e.ToString());
base.Dispose();
throw;
}
}
示例8: UseOpenGLCreationContext
public UseOpenGLCreationContext(GraphicsDevice graphicsDevice)
: this()
{
if (OpenTK.Graphics.GraphicsContext.CurrentContextHandle.Handle == IntPtr.Zero)
{
needUnbindContext = true;
useDeviceCreationContext = true;
#if SILICONSTUDIO_PLATFORM_ANDROID
tegraWorkaround = graphicsDevice.Workaround_Context_Tegra2_Tegra3;
// Notify main rendering thread there is some pending async work to do
if (tegraWorkaround)
{
useDeviceCreationContext = false; // We actually use real main context, so states will be kept
graphicsDevice.AsyncPendingTaskWaiting = true;
}
#endif
// Lock, since there is only one deviceCreationContext.
// TODO: Support multiple deviceCreationContext (TLS creation of context was crashing, need to investigate why)
asyncCreationLockObject = graphicsDevice.asyncCreationLockObject;
Monitor.Enter(graphicsDevice.asyncCreationLockObject, ref asyncCreationLockTaken);
#if SILICONSTUDIO_PLATFORM_ANDROID
if (tegraWorkaround)
graphicsDevice.AsyncPendingTaskWaiting = false;
#endif
// Bind the context
deviceCreationContext = graphicsDevice.deviceCreationContext;
deviceCreationContext.MakeCurrent(graphicsDevice.deviceCreationWindowInfo);
}
else
{
// TODO Hardcoded to the fact it uses only one command list, this should be fixed
CommandList = graphicsDevice.MainCommandList;
}
}
示例9: InitSynchronizedOnce
/// <summary>
///
/// </summary>
/// <see cref="http://www.opentk.com/doc/graphics/graphicscontext"/>
public override void InitSynchronizedOnce()
{
if (!AlreadyInitialized)
{
AlreadyInitialized = true;
AutoResetEvent CompletedEvent = new AutoResetEvent(false);
var CThread = new Thread(() =>
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(PspConfig.ThreadCultureName);
var UsedGraphicsMode = new GraphicsMode(
color: new OpenTK.Graphics.ColorFormat(8, 8, 8, 8),
depth: 16,
stencil: 8,
samples: 0,
accum: new OpenTK.Graphics.ColorFormat(16, 16, 16, 16),
//accum: new OpenTK.Graphics.ColorFormat(0, 0, 0, 0),
buffers: 2,
stereo: false
);
var UsedGameWindowFlags = GameWindowFlags.Default;
//Console.Error.WriteLine(UsedGraphicsMode);
//Console.ReadKey();
#if USE_GL_CONTROL
GLControl = new GLControl(UsedGraphicsMode, 3, 0, GraphicsContextFlags.Default);
#else
NativeWindow = new NativeWindow(512, 272, "PspGraphicEngine", UsedGameWindowFlags, UsedGraphicsMode, DisplayDevice.GetDisplay(DisplayIndex.Default));
#endif
#if SHOW_WINDOW
NativeWindow.Visible = true;
#endif
//Utilities.CreateWindowsWindowInfo(handle);
GraphicsContext = new GraphicsContext(UsedGraphicsMode, WindowInfo);
GraphicsContext.MakeCurrent(WindowInfo);
{
GraphicsContext.LoadAll();
Initialize();
}
GraphicsContext.SwapInterval = 0;
#if true
//Console.WriteLine("## {0}", UsedGraphicsMode);
Console.WriteLine("## UsedGraphicsMode: {0}", UsedGraphicsMode);
Console.WriteLine("## GraphicsContext.GraphicsMode: {0}", GraphicsContext.GraphicsMode);
Console.WriteLine("## OpenGL Context Version: {0}.{1}", GlGetInteger(GetPName.MajorVersion), GlGetInteger(GetPName.MinorVersion));
Console.WriteLine("## Depth Bits: {0}", GlGetInteger(GetPName.DepthBits));
Console.WriteLine("## Stencil Bits: {0}", GlGetInteger(GetPName.StencilBits));
Console.WriteLine("## Accum Bits: {0},{1},{2},{3}", GlGetInteger(GetPName.AccumRedBits), GlGetInteger(GetPName.AccumGreenBits), GlGetInteger(GetPName.AccumBlueBits), GlGetInteger(GetPName.AccumAlphaBits));
if (GlGetInteger(GetPName.StencilBits) <= 0)
{
ConsoleUtils.SaveRestoreConsoleState(() =>
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine("No stencil bits available!");
});
}
/*
GL.Enable(EnableCap.StencilTest);
GL.StencilMask(0xFF);
GL.ClearColor(new Color4(Color.FromArgb(0x11, 0x22, 0x33, 0x44)));
GL.ClearStencil(0x7F);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit);
var TestData = new uint[16 * 16];
TestData[0] = 0x12345678;
GL.ReadPixels(0, 0, 16, 16, PixelFormat.Rgba, PixelType.UnsignedInt8888Reversed, TestData);
Console.WriteLine(GL.GetError());
for (int n = 0; n < TestData.Length; n++) Console.Write("{0:X}", TestData[n]);
*/
#endif
GraphicsContext.MakeCurrent(null);
CompletedEvent.Set();
while (Running)
{
#if !USE_GL_CONTROL
NativeWindow.ProcessEvents();
#endif
Thread.Sleep(1);
}
StopEvent.Set();
});
CThread.Name = "GpuImplEventHandling";
CThread.IsBackground = true;
CThread.Start();
CompletedEvent.WaitOne();
}
}
示例10: CreateGraphicsContext
/// <summary>
/// Create Graphcis Context
/// </summary>
/// <returns></returns>
public bool CreateGraphicsContext()
{
// If this looks uninitialized... initialize.
if (ColorBPP == 0)
{
ColorBPP = 32;
if (DepthBPP == 0) DepthBPP = 16;
}
ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP);
ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP);
int buffers = 2;
if (SingleBuffer) buffers--;
GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);
#if MAC
IntPtr windowHandle = gdk_quartz_window_get_nswindow(GdkWindow.Handle);
// Problem: gdk_window_ensure_native() crashes when used more than once.
// For now, just create a NSView in place and use that instead.
// Needs some care updating when resizing, hiding, etc, but seems to work.
// (I'd guess this is pretty much what gdk_window_ensure_native() does internally.)
var customView = NativeClass.AllocateClass("CustomNSView" + uniqueId++, "NSView");
NativeClass.RegisterClass(customView);
nsView = SendIntPtr(SendIntPtr(customView, sel_registerName("alloc")), sel_registerName("initWithFrame:"), new RectangleF(0, 0, 400, 400));
bool native = gdk_window_ensure_native(GdkWindow.Handle);
if (!native)
{
throw new PlatformNotSupportedException("Could not create native view.");
}
nsView = gdk_quartz_window_get_nsview(GdkWindow.Handle);
windowInfo = OpenTK.Platform.Utilities.CreateMacOSWindowInfo(windowHandle, nsView);
UpdateNSView();
#elif LINUX
IntPtr display = gdk_x11_display_get_xdisplay(Display.Handle);
int screen = Screen.Number;
IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle);
IntPtr rootWindow = gdk_x11_drawable_get_xid(RootWindow.Handle);
IntPtr visualInfo;
if (graphicsMode.Index.HasValue)
{
XVisualInfo info = new XVisualInfo();
info.VisualID = graphicsMode.Index.Value;
int dummy;
visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy);
}
else
{
visualInfo = GetVisualInfo(display);
}
windowInfo = OpenTK.Platform.Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo);
XFree(visualInfo);
#endif
// GraphicsContext
graphicsContext = new GraphicsContext(graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, graphicsContextFlags);
graphicsContext.MakeCurrent(windowInfo);
if (GraphicsContext.ShareContexts)
{
Interlocked.Increment(ref graphicsContextCount);
if (!sharedContextInitialized)
{
sharedContextInitialized = true;
((IGraphicsContextInternal)graphicsContext).LoadAll();
OnGraphicsContextInitialized();
}
}
else
{
((IGraphicsContextInternal)graphicsContext).LoadAll();
OnGraphicsContextInitialized();
}
this.OnInitialized(this, null);
this.timerId = GLib.Timeout.Add(16, new GLib.TimeoutHandler(this.Render));
return false;
}
示例11: OnExposeEvent
// Called when the widget needs to be (fully or partially) redrawn.
protected override bool OnExposeEvent(Gdk.EventExpose eventExpose)
{
if (!initialized) {
initialized = true;
// If this looks uninitialized... initialize.
if (ColorBPP == 0) {
ColorBPP = 32;
if (DepthBPP == 0)
DepthBPP = 16;
}
ColorFormat colorBufferColorFormat = new ColorFormat (ColorBPP);
ColorFormat accumulationColorFormat = new ColorFormat (AccumulatorBPP);
int buffers = 2;
if (SingleBuffer)
buffers--;
GraphicsMode graphicsMode = new GraphicsMode (colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);
// IWindowInfo
if (Configuration.RunningOnWindows) {
IntPtr windowHandle = gdk_win32_drawable_get_handle (GdkWindow.Handle);
windowInfo = Utilities.CreateWindowsWindowInfo (windowHandle);
} else if (Configuration.RunningOnMacOS) {
IntPtr windowHandle = gdk_x11_drawable_get_xid (GdkWindow.Handle);
const bool ownHandle = true;
const bool isControl = true;
windowInfo = Utilities.CreateMacOSCarbonWindowInfo (windowHandle, ownHandle, isControl);
} else if (Configuration.RunningOnX11) {
IntPtr display = gdk_x11_display_get_xdisplay (Display.Handle);
int screen = Screen.Number;
IntPtr windowHandle = gdk_x11_drawable_get_xid (GdkWindow.Handle);
IntPtr rootWindow = gdk_x11_drawable_get_xid (RootWindow.Handle);
IntPtr visualInfo;
if (graphicsMode.Index.HasValue) {
XVisualInfo info = new XVisualInfo ();
info.VisualID = graphicsMode.Index.Value;
int dummy;
visualInfo = XGetVisualInfo (display, XVisualInfoMask.ID, ref info, out dummy);
} else {
visualInfo = GetVisualInfo (display);
}
windowInfo = Utilities.CreateX11WindowInfo (display, screen, windowHandle, rootWindow, visualInfo);
XFree (visualInfo);
} else
throw new PlatformNotSupportedException ();
// GraphicsContext
graphicsContext = new GraphicsContext (graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, GraphicsContextFlags);
graphicsContext.MakeCurrent (windowInfo);
if (GraphicsContext.ShareContexts) {
Interlocked.Increment (ref graphicsContextCount);
if (!sharedContextInitialized) {
sharedContextInitialized = true;
((IGraphicsContextInternal)graphicsContext).LoadAll ();
OnGraphicsContextInitialized ();
}
} else {
((IGraphicsContextInternal)graphicsContext).LoadAll ();
OnGraphicsContextInitialized ();
}
OnInitialized ();
} else {
graphicsContext.MakeCurrent (windowInfo);
}
bool result = base.OnExposeEvent (eventExpose);
OnRenderFrame ();
eventExpose.Window.Display.Sync (); // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync?
graphicsContext.SwapBuffers ();
return result;
}
示例12: InitSynchronizedOnce
/// <summary>
///
/// </summary>
/// <see cref="http://www.opentk.com/doc/graphics/graphicscontext"/>
public override void InitSynchronizedOnce()
{
if (!AlreadySynchronized)
{
AlreadySynchronized = true;
AutoResetEvent CompletedEvent = new AutoResetEvent(false);
var CThread = new Thread(() =>
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(PspConfig.CultureName);
NativeWindow = new OpenTK.NativeWindow(512, 272, "PspGraphicEngine", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default);
NativeWindow.Visible = false;
GraphicsContext = new GraphicsContext(GraphicsMode.Default, NativeWindow.WindowInfo);
GraphicsContext.MakeCurrent(NativeWindow.WindowInfo);
{
(GraphicsContext as IGraphicsContextInternal).LoadAll();
Initialize();
}
GraphicsContext.MakeCurrent(null);
CompletedEvent.Set();
while (Running)
{
NativeWindow.ProcessEvents();
Thread.Sleep(1);
}
StopEvent.Set();
});
CThread.IsBackground = true;
CThread.Start();
CompletedEvent.WaitOne();
}
}
示例13: GameWindow
/// <summary>Constructs a new GameWindow with the specified attributes.</summary>
/// <param name="width">The width of the GameWindow in pixels.</param>
/// <param name="height">The height of the GameWindow in pixels.</param>
/// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
/// <param name="title">The title of the GameWindow.</param>
/// <param name="options">GameWindow options regarding window appearance and behavior.</param>
/// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device)
: base(width, height, title, options, mode == null ? GraphicsMode.Default : mode, device == null ? DisplayDevice.Default : device)
{
try {
glContext = Factory.Default.CreateGLContext(mode == null ? GraphicsMode.Default : mode, WindowInfo);
glContext.MakeCurrent(WindowInfo);
glContext.LoadAll();
VSync = true;
//glWindow.WindowInfoChanged += delegate(object sender, EventArgs e) { OnWindowInfoChangedInternal(e); };
} catch (Exception e) {
Debug.Print(e.ToString());
base.Dispose();
throw;
}
}
示例14: OnExposeEvent
// Called when the widget needs to be (fully or partially) redrawn.
protected override bool OnExposeEvent(Gdk.EventExpose eventExpose)
{
if (!initialized)
{
Console.WriteLine("GLWIDGET IS INITIALIZING!");
initialized = true;
// If this looks uninitialized... initialize.
if (ColorBPP == 0)
{
ColorBPP = 32;
if (DepthBPP == 0) DepthBPP = 16;
}
ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP);
ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP);
int buffers = 2;
if (SingleBuffer) buffers--;
graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);
this.SetupWindowInfo();
poisonedWindowHandle = false;
// GraphicsContext
graphicsContext = new GraphicsContext(graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, graphicsContextFlags);
graphicsContext.MakeCurrent(windowInfo);
if (false)
{
Interlocked.Increment(ref graphicsContextCount);
if (!sharedContextInitialized)
{
sharedContextInitialized = true;
((IGraphicsContextInternal)graphicsContext).LoadAll();
OnGraphicsContextInitialized();
}
}
else
{
((IGraphicsContextInternal)graphicsContext).LoadAll();
OnGraphicsContextInitialized();
}
OnInitialized();
}
else
{
if (poisonedWindowHandle)
{
this.SetupWindowInfo();
poisonedWindowHandle = false;
}
graphicsContext.MakeCurrent(windowInfo);
}
bool result = base.OnExposeEvent(eventExpose);
OnRenderFrame();
eventExpose.Window.Display.Sync(); // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync?
graphicsContext.SwapBuffers();
return result;
}
示例15: OnLoad
// This gets called when the drawing surface is ready
protected override void OnLoad (EventArgs e)
{
base.OnLoad (e);
try {
// Clear the current Context
GraphicsContext.MakeCurrent (null);
// Create a secondary context using the same information the primary
// context was created with
backgroundContext = new AndroidGraphicsContext(GraphicsMode, WindowInfo, GraphicsContext, ContextRenderingApi, GraphicsContextFlags.Embedded);
}catch {
// secondary context not supported
backgroundContext = null;
}
MakeCurrent();
var vertexShader = LoadShader(ShaderType.VertexShader, vertexShaderCode);
var fragmentShader = LoadShader(ShaderType.FragmentShader, fragmentShaderCode);
program = GL.CreateProgram (); // create empty OpenGL Program
GL.AttachShader (program, vertexShader); // add the vertex shader to program
GL.AttachShader (program, fragmentShader); // add the fragment shader to program
GL.BindAttribLocation (program, ATTRIB_VERTEX, "position");
GL.BindAttribLocation (program, ATTRIB_TEXCOORD, "texcoord");
GL.LinkProgram (program); // create OpenGL program executables
uniformTextureLocation = GL.GetUniformLocation (program, "texture");
if (vertexShader != 0) {
GL.DetachShader (program, vertexShader);
GL.DeleteShader (vertexShader);
}
if (fragmentShader != 0) {
GL.DetachShader (program, fragmentShader);
GL.DeleteShader (fragmentShader);
}
GL.Viewport (0, 0, Width, Height);
// Run the render loop
Run ();
Task.Factory.StartNew (() => {
//Thread.Sleep(500);
// load the bitmap
bitmap = BitmapFactory.DecodeResource (Context.Resources, Resource.Drawable.f_spot);
// the device may or may not support a background Context. But rather than
// duplicating this code we just create an Action which we can invoke on this
// background thread later or queue to be executed on the rendering thread.
Action acton = new Action (() => {
GL.Enable (EnableCap.Texture2D);
GL.GenTextures(1, out textureid);
GL.ActiveTexture (TextureUnit.Texture0);
GL.BindTexture (TextureTarget.Texture2D, textureid);
// setup texture parameters
GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
GL.TexParameter (TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
Android.Opengl.GLUtils.TexImage2D ((int)TextureTarget.Texture2D, 0, bitmap, 0);
// make sure the texture is pushed to the GPU.
GL.Flush();
// make sure we free resources
bitmap.Recycle();
bitmap.Dispose();
bitmap = null;
});
// take a lock so the main rendering thread does not try to draw anything
// there are other ways to do this, but its is probably the simplest
lock (lockobject) {
if (backgroundContext != null) {
// Clear the current context bound to the Display
backgroundContext.MakeCurrent (null);
// make this context active
backgroundContext.MakeCurrent (WindowInfo);
// do our processing
acton.Invoke ();
// clear the current context again so we don't error on the main thread
backgroundContext.MakeCurrent (null);
} else {
// Secondary Context's are not supported on this device
// queue the action for execution later.
actions.Enqueue (acton);
}
}
});
}