public void CreateContext(bool direct, IGLContext source) { Debug.WriteLine(String.Format("OpenGL context is bound to handle: {0}", this.windowInfo.Handle)); Debug.Write("Creating render context... "); // Do not rely on OpenTK.Platform.Windows.Wgl - the context is not ready yet, // and Wgl extensions will fail to load. renderContext = new ContextHandle(Wgl.Imports.CreateContext(deviceContext)); if (renderContext == IntPtr.Zero) throw new ApplicationException("Could not create OpenGL render context (Wgl.CreateContext() return 0)."); Debug.WriteLine(String.Format("done! (id: {0})", renderContext)); Wgl.Imports.MakeCurrent(deviceContext, renderContext); Wgl.LoadAll(); GL.LoadAll(); Glu.LoadAll(); vsync_supported = Wgl.Arb.SupportsExtension(this.deviceContext, "WGL_EXT_swap_control") && Wgl.Load("wglGetSwapIntervalEXT") && Wgl.Load("wglSwapIntervalEXT"); if (source != null) { Debug.Print("Sharing state with context {0}", (source as IGLContextInternal).Context); Wgl.Imports.ShareLists(renderContext, (source as IGLContextInternal).Context); } }
public static IFontProvider GetFontProvider(IGLContext context) { var fontFolder = new DirectoryInfo(Environment.GetFolderPath( Environment.SpecialFolder.Fonts)); return(new FreeTypeFontProvider(fontFolder, context)); }
public FontBitmapEntry(IFont font, IGLContext context, UInt32 listBase, UInt32 listCount) { Font = font; _context = context; Height = (Int32)(font.Size * (16.0f / 12.0f)); ListBase = listBase; ListCount = listCount; }
public static Shader GenShader(IEnumerable <ShaderSource> source, IGLContext context) { var shader = GenShader(source, context.Context); if (shader != null) { context.ShaderBinding(shader); } return(shader); }
public GLRenderContext(IViewPerspective perspective, IGLContext openGlContext, IFontProvider fontProvider, IVisualSurrogateProvider surrogateProvider, IThemeProvider themeProvider, IVisualLineage visualLineage, Dictionary <IVisualElement, ValueCube> renderPositions, ILayoutQueue layoutQueue) : base(perspective, surrogateProvider, themeProvider, visualLineage, renderPositions, layoutQueue) { _openGlContext = openGlContext; _fontProvider = fontProvider; }
/// <summary> /// /// </summary> /// <see cref="http://www.opentk.com/doc/graphics/graphicscontext"/> //[HandleProcessCorruptedStateExceptions] public override void InitSynchronizedOnce() { //Memory.WriteBytesHook += OnMemoryWrite; this.ScaleViewport = PspStoredConfig.RenderScale; if (!AlreadyInitialized) { AlreadyInitialized = true; AutoResetEvent CompletedEvent = new AutoResetEvent(false); var CThread = 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()"); } }); CThread.Name = "GpuImplEventHandling"; CThread.IsBackground = true; CThread.Start(); CompletedEvent.WaitOne(); } }
public FreeTypeFontProvider(DirectoryInfo fontDirectory, IGLContext context) { _context = context; _cached = new Dictionary <IFont, GLFont>(); _fontFiles = new Dictionary <String, Dictionary <FontStyle, FileInfo> >( StringComparer.OrdinalIgnoreCase); var ret = FT.FT_Init_FreeType(out var library); if (ret != FtErrors.Ok) { throw new Exception("FreeType library Exception: " + ret); } foreach (var fi in fontDirectory.GetFiles("*.ttf")) { ret = FT.FT_New_Face(library, fi.FullName, 0, out var facePtr); if (ret != FtErrors.Ok) { continue; } var ftFont = (FreeTypeFont)Marshal.PtrToStructure(facePtr, typeof(FreeTypeFont)); var strName = Marshal.PtrToStringAnsi(ftFont.family_name); var styleName = Marshal.PtrToStringAnsi(ftFont.style_name) ?? String.Empty; var fontStyle = GetFontStyle(styleName); if (fontStyle == FontStyle.Unusable) { continue; } if (String.IsNullOrWhiteSpace(strName)) { continue; } if (!_fontFiles.TryGetValue(strName, out var styleDic)) { styleDic = new Dictionary <FontStyle, FileInfo>(); _fontFiles[strName] = styleDic; } styleDic[fontStyle] = fi; } }
public GLFont(IFont font, String fontFile, UInt32 size, IGLContext context) { Font = font; _fontSize = size; _context = context; _wordRects = new Dictionary <String, Rectangle>(); _charGlyphs = new Dictionary <Int32, Glyph>(); var ret = FT.FT_Init_FreeType(out var library); if (ret != FtErrors.Ok) { throw new Exception("FreeType library Exception: " + ret); } ret = FT.FT_New_Face(library, fontFile, 0, out _facePtr); if (ret != FtErrors.Ok) { throw new Exception("FreeType font Exception: " + ret); } _ftFont = (FreeTypeFont)Marshal.PtrToStructure(_facePtr, typeof(FreeTypeFont)); _hasKerning = ((FaceFlags)_ftFont.face_flags & FaceFlags.Kerning) == FaceFlags.Kerning; var w = IntPtr.Zero; var h = (IntPtr)(size << 6); FT.FT_Set_Char_Size(_facePtr, w, h, 0, 96); _textures = new UInt32[128]; _extentX = new Int32[128]; _listBase = GL.glGenLists(128); GL.glGenTextures(128, _textures); for (var c = 0; c < 128; c++) { CompileCharacter(_facePtr, c); } }
public OpenGLRenderKit(IFontProvider fontProvider, IGLContext glContext, IThemeProvider themeProvider, IImageProvider imageProvider) : base(imageProvider, Serializer, new SvgPathBuilder(imageProvider, Serializer), null) //: base(themeProvider, Serializer.AttributeParser, // Serializer.TypeInferrer, Serializer.TypeManipulator, // new Dictionary<IVisualElement, ValueCube>(), imageProvider, // Serializer.AssemblyList, Serializer) { var lastMeasurements = new Dictionary <IVisualElement, ValueSize>(); var lastRender = new Dictionary <IVisualElement, ValueCube>(); var visualLineage = new VisualLineage(); var layoutQueue = new LayoutQueue(); MeasureContext = new GLMeasureContext(fontProvider, this, lastMeasurements, themeProvider, visualLineage, layoutQueue); RenderContext = new GLRenderContext(new BasePerspective(), glContext, fontProvider, this, themeProvider, visualLineage, lastRender, layoutQueue); }
public UseOpenGLCreationContext(GraphicsDevice graphicsDevice) : this() { GL = graphicsDevice.GL; if (graphicsDevice.CurrentGraphicsContext == IntPtr.Zero) { needUnbindContext = true; useDeviceCreationContext = true; // 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); // Bind the context deviceCreationContext = graphicsDevice.deviceCreationContext; deviceCreationContext.MakeCurrent(); } else { // TODO Hardcoded to the fact it uses only one command list, this should be fixed CommandList = graphicsDevice.InternalMainCommandList; } }
public MaterialDetailRepository() { baseContext = new IGLContext(); _connectionString = baseContext.Database.GetDbConnection().ConnectionString; }
public GenericRepository() { baseContext = new IGLContext(); TEntities = baseContext.Set <TEntity>(); }
public async Task <bool> CreateNewContext() { baseContext = new IGLContext(); return(await Task.Run(() => true)); }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); if (!DesignMode) { this.Context = GLContextFactory.CreateFromWindowHandle(this.Handle); this.Context.MakeCurrent(); } }
public WindowsFontProvider(IGLContext context) : base(context) { _context = context; }
public void CreateContext(bool direct, IGLContext source) { }
public void CreateWindow(DisplayMode windowMode, out IGLContext context) { Debug.Print("Creating native window with mode: {0}", windowMode.ToString()); Debug.Indent(); CreateParams cp = new CreateParams(); cp.ClassStyle = (int)WindowClassStyle.OwnDC | (int)WindowClassStyle.VRedraw | (int)WindowClassStyle.HRedraw | (int)WindowClassStyle.Ime; cp.Style = (int)WindowStyle.Visible | (int)WindowStyle.ClipChildren | (int)WindowStyle.ClipSiblings | (int)WindowStyle.OverlappedWindow; Rectangle rect = new Rectangle(); rect.top = rect.left = 0; rect.bottom = windowMode.Height; rect.right = windowMode.Width; Functions.AdjustWindowRect(ref rect, WindowStyle.OverlappedWindow, false); // Not used Top = 0; Left = 0; Right = windowMode.Width; Bottom = windowMode.Height; // -------- top_border = -rect.top; left_border = -rect.left; bottom_border = rect.bottom - windowMode.Height; right_border = rect.right - windowMode.Width; cp.Width = rect.right - rect.left; cp.Height = rect.bottom - rect.top; cp.Caption = "OpenTK Game Window"; // Keep in mind that some construction code runs in WM_CREATE, // which is raised CreateHandle() CreateHandle(cp); if (this.Handle != IntPtr.Zero) { Debug.WriteLine("Window creation succesful."); //context.Info = new OpenTK.Platform.WindowInfo(this); //context.CreateContext(); //Debug.WriteLine("Context creation successful."); exists = true; } else throw new ApplicationException(String.Format( "Could not create native window and/or context. Handle: {0}", this.Handle)); Functions.SetWindowPos(this.Handle, WindowPlacementOptions.TOP, Left, Top, cp.Width, cp.Height, SetWindowPosFlags.SHOWWINDOW); //context = new GLContext(mode, window); //context.CreateContext(); context = new WinGLContext(); (context as IGLContextCreationHack).SetWindowHandle(window.Handle); (context as IGLContextCreationHack).SelectDisplayMode(mode, window); context.CreateContext(true, null); Debug.Unindent(); }
public VendorWisePoStatusReportRepository() { baseContext = new IGLContext(); _connectionString = baseContext.Database.GetDbConnection().ConnectionString; }
public FontProvider(IGLContext context) { _context = context; _fontBitmapEntries = new List <FontBitmapEntry>(); }
public ProductReturnRepository() { baseContext = new IGLContext(); _connectionString = baseContext.Database.GetDbConnection().ConnectionString; }
public StringRenderer(FontProvider fontProvider, IGLContext context) { _fontProvider = fontProvider; _context = context; }
public void CreateContext(bool direct, IGLContext shareContext) { try { Debug.WriteLine("Creating opengl context."); Debug.Indent(); ContextHandle shareHandle = shareContext != null ? (shareContext as IGLContextInternal).Context : (ContextHandle)IntPtr.Zero; Debug.Write(direct ? "Context is direct, " : "Context is indirect, "); Debug.WriteLine(shareHandle.Handle == IntPtr.Zero ? "not shared." : String.Format("shared with ({0}).", shareHandle)); // Try to call Glx.CreateContext with the specified parameters. context = Glx.CreateContext(windowInfo.Display, visual, shareHandle.Handle, direct); // Context creation succeeded, return. if (context != IntPtr.Zero) { Debug.Print("New opengl context created. (id: {0})", context); this.MakeCurrent(); GL.LoadAll(); Glu.LoadAll(); return; } // Context creation failed. Retry with a non-shared context with the // direct/indirect rendering mode flipped. Debug.Print("Cotnext creation failed, retrying with a non-shared, {0} context.", !direct ? "direct" : "indirect"); context = Glx.CreateContext(windowInfo.Display, visual, IntPtr.Zero, !direct); if (context != IntPtr.Zero) { Debug.Print("New opengl context created. (id: {0})", context); this.MakeCurrent(); GL.LoadAll(); Glu.LoadAll(); return; } throw new ApplicationException("Glx.CreateContext call failed (returned 0)."); } finally { Debug.Unindent(); } }
/// <summary> /// Creates a GLContext and attaches it to this GLControl. /// </summary> public void CreateContext() { if (display_mode == null) display_mode = new DisplayMode(); WindowInfo info = new WindowInfo(this); if (!this.DesignMode) { // Mono's implementation of Windows.Forms on X11 does not allow the context to // have a different colordepth from the parent. To combat this, we do not set a // specific depth for the DisplayMode - we let the driver select one instead. display_mode.Color = new ColorMode(0); context = new GLContext(display_mode, info); idle = new PlatformIdle(info); } else { context = new DummyGLContext(display_mode); idle = new DummyPlatformIdle(); } }
/// <summary> /// Opens a new render window with the given DisplayMode. /// </summary> /// <param name="mode">The DisplayMode of the render window.</param> /// <remarks> /// Creates the window visual and colormap. Associates the colormap/visual /// with the window and raises the window on top of the window stack. /// <para> /// Colormap creation is currently disabled. /// </para> /// </remarks> public void CreateWindow(DisplayMode mode, out IGLContext glContext) { if (exists) throw new ApplicationException("Render window already exists!"); Debug.Print("Creating GameWindow with mode: {0}", mode != null ? mode.ToString() : "default"); Debug.Indent(); glContext = new X11GLContext(); (glContext as IGLContextCreationHack).SelectDisplayMode(mode, window); if (glContext == null) throw new ApplicationException("Could not create GLContext"); Debug.Print("Created GLContext"); window.VisualInfo = ((X11.WindowInfo)((IGLContextInternal)glContext).Info).VisualInfo; //window.VisualInfo = Marshal.PtrToStructure(Glx.ChooseVisual(window.Display, window.Screen, // Create a window on this display using the visual above Debug.Write("Opening render window... "); XSetWindowAttributes attributes = new XSetWindowAttributes(); attributes.background_pixel = IntPtr.Zero; attributes.border_pixel = IntPtr.Zero; attributes.colormap = API.CreateColormap(window.Display, window.RootWindow, window.VisualInfo.visual, 0/*AllocNone*/); window.EventMask = EventMask.StructureNotifyMask | EventMask.SubstructureNotifyMask | EventMask.ExposureMask | EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.PointerMotionMask | /* Bad! EventMask.PointerMotionHintMask | */ EventMask.ButtonPressMask | EventMask.ButtonReleaseMask; attributes.event_mask = (IntPtr)window.EventMask; uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask | (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel; window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow, 0, 0, mode.Width, mode.Height, 0, window.VisualInfo.depth/*(int)CreateWindowArgs.CopyFromParent*/, (int)CreateWindowArgs.InputOutput, window.VisualInfo.visual, (UIntPtr)mask, ref attributes); if (window.Handle == IntPtr.Zero) throw new ApplicationException("XCreateWindow call failed (returned 0)."); // Set the window hints XSizeHints hints = new XSizeHints(); hints.x = 0; hints.y = 0; hints.width = mode.Width; hints.height = mode.Height; hints.flags = (IntPtr)(XSizeHintsFlags.USSize | XSizeHintsFlags.USPosition); Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints); // Register for window destroy notification IntPtr wm_destroy_atom = Functions.XInternAtom(window.Display, "WM_DELETE_WINDOW", true); XWMHints hint = new XWMHints(); Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { wm_destroy_atom }, 1); Top = Left = 0; Right = Width; Bottom = Height; //XTextProperty text = new XTextProperty(); //text.value = "OpenTK Game Window"; //text.format = 8; //Functions.XSetWMName(window.Display, window.Handle, ref text); //Functions.XSetWMProperties(display, window, name, name, 0, /*None*/ null, 0, hints); Debug.Print("done! (id: {0})", window.Handle); (glContext as IGLContextCreationHack).SetWindowHandle(window.Handle); API.MapRaised(window.Display, window.Handle); mapped = true; glContext.CreateContext(true, null); driver = new X11Input(window); Debug.Unindent(); Debug.WriteLine("GameWindow creation completed successfully!"); exists = true; }
public PurchaseOrderRepository() { baseContext = new IGLContext(); _connectionString = baseContext.Database.GetDbConnection().ConnectionString; }