Beispiel #1
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    Bitmap.Dispose();
                    Bitmap = null;
                    Image.Dispose();
                    Image   = null;
                    CQ      = null;
                    Context = null;
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                // If disposing is false,
                // only the following code is executed.

                // Note disposing has been done.
                disposed = true;
            }
        }
Beispiel #2
0
        protected virtual void Initialize(Context context, CommandQueue cq, int width, int height)
        {
            BitmapData bd;

            Bitmap  = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            bd      = LockEntireBitmap(Bitmap, ImageLockMode.ReadOnly);
            Image   = context.CreateImage2D(MemFlags.COPY_HOST_PTR, OpenCLNet.ImageFormat.ARGB8U, width, height, bd.Stride, bd.Scan0);
            Context = context;
            CQ      = cq;
        }
Beispiel #3
0
        public CLImage CreateImage3D(MemFlags flags, CLImageFormat imageFormat, IntPtr imageWidth, IntPtr imageHeight, IntPtr imageDepth, IntPtr imageRowPitch, IntPtr imageSlicePitch, IntPtr pHost)
        {
            CLImage   mem;
            IntPtr    memID;
            ErrorCode result;

            memID = (IntPtr)OpenCL.CreateImage3D(ContextID, (ulong)flags, imageFormat, imageWidth, imageHeight, imageDepth, imageRowPitch, imageSlicePitch, pHost.ToPointer(), out result);
            if (result != ErrorCode.SUCCESS)
            {
                throw new OpenCLException("CreateImage3D failed with error code " + result, result);
            }
            mem = new CLImage(this, memID);
            OpenCLObjectList[memID] = new WeakReference(mem);
            return(mem);
        }
Beispiel #4
0
        public void ReleaseDeviceResources()
        {
            oclFullyInitialized = false;
            if (OCLSampler != null)
            {
                OCLSampler.Dispose();
                OCLSampler = null;
            }
            if (OCLInputImage != null)
            {
                OCLInputImage.Dispose();
                OCLInputImage = null;
            }

            if (OCLOutputImage != null)
            {
                OCLOutputImage.Dispose();
                OCLOutputImage = null;
            }

            if (FilterKernel != null)
            {
                FilterKernel.Dispose();
                FilterKernel = null;
            }

            if (oclProgram != null)
            {
                oclProgram.Dispose();
                oclProgram = null;
            }

            if (oclCQ != null)
            {
                oclCQ.Dispose();
                oclCQ = null;
            }

            if (oclContext != null)
            {
                oclContext.Dispose();
                oclContext = null;
            }
        }
Beispiel #5
0
 public void CreateOCLImages(Context context)
 {
     OCLInputImage  = CreateOCLBitmapFromBitmap(TestImage);
     OCLOutputImage = oclContext.CreateImage2D(MemFlags.WRITE_ONLY, CL.CLImageFormat.RGBA8U, panelScaled.Width, panelScaled.Height, 0, IntPtr.Zero);
     OCLSampler     = oclContext.CreateSampler(true, AddressingMode.CLAMP_TO_EDGE, FilterMode.LINEAR);
 }