Beispiel #1
0
        //public static DispatchComputeDelegate DispatchComputePointer;
        //public static TexStorage2DDelegate TexStorage2DPointer;
        //public static VertexAttribFormatDelegate VertexAttribFormatPointer;

        public static void Setup(IGraphicsContextInternal context)
        {
            Context = context;
            //MustGet(context, "glDispatchCompute", out DispatchCompute);
            //MustGet(context, "glTexStorage2D", out TexStorage2D);
            //MustGet(context, "glVertexAttribFormat", out VertexAttribFormat);
        }
        // Loads all available entry points for the current API.
        // Note: we prefer IGraphicsContextInternal.GetAddress over
        // this.GetAddress to improve loading performance (less
        // validation necessary.)
        internal override void LoadEntryPoints()
        {
            Debug.Print("Loading entry points for {0}", GetType().FullName);

            IGraphicsContext context = GraphicsContext.CurrentContext;

            if (context == null)
            {
                throw new GraphicsContextMissingException();
            }

            IGraphicsContextInternal context_internal = context as IGraphicsContextInternal;

            unsafe
            {
                fixed(byte *name = _EntryPointNamesInstance)
                {
                    for (int i = 0; i < _EntryPointsInstance.Length; i++)
                    {
                        _EntryPointsInstance[i] = context_internal.GetAddress(
                            new IntPtr(name + _EntryPointNameOffsetsInstance[i]));
                    }
                }
            }
        }
Beispiel #3
0
        static void RemoveContext(IGraphicsContextInternal context)
        {
            ContextHandle ctx = context.Context;

            if (available_contexts.ContainsKey(ctx))
            {
                available_contexts.Remove(ctx);
            }
            else
            {
                Debug.Print("Tried to remove non-existent GraphicsContext handle {0}. Call Dispose() to avoid this error.", ctx);
            }
        }
Beispiel #4
0
        private static void RemoveContext(IGraphicsContextInternal context)
        {
            ContextHandle ctx = context.Context;

            if (available_contexts.ContainsKey(ctx))
            {
                available_contexts.Remove(ctx);
            }
            else
            {
                Debug.WriteLine("");
                Debug.WriteLine($"Tried to remove non-existent GraphicsContext handle {ctx}. Call Dispose() to avoid this error.");
            }
        }
Beispiel #5
0
        private static void AddContext(IGraphicsContextInternal context)
        {
            ContextHandle ctx = context.Context;

            if (!available_contexts.ContainsKey(ctx))
            {
                available_contexts.Add(ctx, (IGraphicsContext)context);
            }
            else
            {
                Debug.WriteLine($"A GraphicsContext with handle {ctx} already exists.");
                Debug.WriteLine("Did you forget to call Dispose()?");
                available_contexts[ctx] = (IGraphicsContext)context;
            }
        }
Beispiel #6
0
        public static void AddContext(IGraphicsContextInternal context)
        {
            ContextHandle ctx = context.Context;

            if (!available_contexts.ContainsKey(ctx))
            {
                available_contexts.Add(ctx, (IGraphicsContext)context);
            }
            else
            {
                Debug.Print("A GraphicsContext with handle {0} already exists.", ctx);
                Debug.Print("Did you forget to call Dispose()?");
                available_contexts[ctx] = (IGraphicsContext)context;
            }
        }
Beispiel #7
0
        // Loads all available entry points for the current API.
        // Note: we prefer IGraphicsContextInternal.GetAddress over
        // this.GetAddress to improve loading performance (less
        // validation necessary.)
        internal override void LoadEntryPoints()
        {
            IGraphicsContext context = GraphicsContext.CurrentContext;

            if (context == null)
            {
                throw new GraphicsContextMissingException();
            }

            IGraphicsContextInternal context_internal = context as IGraphicsContextInternal;

            for (int i = 0; i < EntryPointsInstance.Length; i++)
            {
                EntryPointsInstance[i] = context_internal.GetAddress(EntryPointNamesInstance[i]);
            }
        }
Beispiel #8
0
        public void SetupClContext()
        {
            CanUseDouble = CanUseInterop = false;

            if (clPlatform == null ||
                comboBoxDevice.SelectedIndex >= clPlatform.Devices.Count)
            {
                clDevice  = null;
                clContext = null;
                return;
            }

            try
            {
                clDevice = clPlatform.Devices[comboBoxDevice.SelectedIndex];
                ComputeContextPropertyList properties = new ComputeContextPropertyList(clPlatform);
                IGraphicsContextInternal   ctx        = (IGraphicsContextInternal)GraphicsContext.CurrentContext;
                properties.Add(new ComputeContextProperty(ComputeContextPropertyName.CL_GL_CONTEXT_KHR, ctx.Context.Handle));
                properties.Add(new ComputeContextProperty(ComputeContextPropertyName.CL_WGL_HDC_KHR, OpenGL.wglGetCurrentDC()));
                properties.Add(new ComputeContextProperty(ComputeContextPropertyName.Platform, clPlatform.Handle.Value));
                clContext = new ComputeContext(new ComputeDevice[] { clDevice }, properties, null, IntPtr.Zero);

                // check the double-extension:
                CanUseDouble  = ClInfo.ExtensionCheck(clContext, "cl_khr_fp64");
                CanUseInterop = ClInfo.ExtensionCheck(clContext, "cl_khr_gl_sharing");
                ClInfo.LogCLProperties(clContext, true);
            }
            catch (Exception exc)
            {
                Util.LogFormat("OpenCL error: {0}", exc.Message);
                clDevice  = null;
                clContext = null;
            }

            bool enableDouble = !checkOpenCL.Checked ||
                                CanUseDouble;

            checkDouble.Enabled  = enableDouble;
            checkInterop.Enabled = CanUseInterop;
        }
 static void RemoveContext(IGraphicsContextInternal context)
 {
     ContextHandle ctx = context.Context;
     if (available_contexts.ContainsKey(ctx))
     {
         available_contexts.Remove(ctx);
     }
     else
     {
         Debug.Print("Tried to remove non-existent GraphicsContext handle {0}. Call Dispose() to avoid this error.", ctx);
     }
 }
 static void AddContext(IGraphicsContextInternal context)
 {
     ContextHandle ctx = context.Context;
     if (!available_contexts.ContainsKey(ctx))
     {
         available_contexts.Add(ctx, (IGraphicsContext)context);
     }
     else
     {
         Debug.Print("A GraphicsContext with handle {0} already exists.", ctx);
         Debug.Print("Did you forget to call Dispose()?");
         available_contexts[ctx] = (IGraphicsContext)context;
     }
 }
Beispiel #11
0
        static void MustGet <T>(IGraphicsContextInternal context, string name, out T result) where T : class
        {
            IntPtr pointer = context.GetAddress(name);

            result = (T)(object)Marshal.GetDelegateForFunctionPointer(pointer, typeof(T));
        }
		public void SetTarget(IGraphicsContext graphicsContext)
		{
			target = graphicsContext;
			targetInternal = (IGraphicsContextInternal)graphicsContext;
		}