예제 #1
0
        public GraphicsDevice(Game game, OpenTK.Graphics.IGraphicsContext context)
        {
            this.context = context;
            this.game    = game;

#if DEBUG
            int count;
            GL.GetInteger(GetPName.NumExtensions, out count);
            for (int i = 0; i < count; i++)
            {
                string extension = GL.GetString(StringNameIndexed.Extensions, i);
                extensions.Add(extension, true);
            }
            if (extensions.ContainsKey("GL_ARB_debug_output"))
            {
                this.context.ErrorChecking = true;
                //GL.Enable(EnableCap.DebugOutput);
                //GL.Enable(EnableCap.DebugOutputSynchronous);
                //GL.DebugMessageCallback(DebugCallbackInstance, IntPtr.Zero);
            }
#endif



            Textures = new TextureCollection();
            CheckError();
            //TODO: samplerstate
        }
예제 #2
0
        /// <summary>
        /// Dispose of current Window.
        /// </summary>
        /// <param name="disposing">If <c>false</c> we are being called from the Finalizer.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (SdlHandle != IntPtr.Zero)
            {
                if (disposing)
                {
                    // Dispose managed state (managed objects).
                    Disposed?.Invoke(this, EventArgs.Empty);
                    Application.UnregisterWindow(this);
                }

#if STRIDE_GRAPHICS_API_OPENGL
                // Dispose OpenGL context
                DummyGLContext?.Dispose();
                DummyGLContext = null;
                if (glContext != IntPtr.Zero)
                {
                    SDL.SDL_GL_DeleteContext(glContext);
                    glContext = IntPtr.Zero;
                }
#endif

                // Free unmanaged resources (unmanaged objects) and override a finalizer below.
                SDL.SDL_DestroyWindow(SdlHandle);
                SdlHandle = IntPtr.Zero;
                Handle    = IntPtr.Zero;
            }
        }
예제 #3
0
 public ShaderProgram(string vertexFile, string fragmentFile, OpenTK.Graphics.IGraphicsContext context)
 {
     m_context = context;
     System.Diagnostics.Debug.Assert(m_context.IsCurrent);
     vp = AddShaderProgram(File.ReadAllText(vertexFile), ShaderType.VertexShader);
     fp = AddShaderProgram(File.ReadAllText(fragmentFile), ShaderType.FragmentShader);
 }
예제 #4
0
파일: Graphics.cs 프로젝트: merlish/ventis
        public static void Init(OpenTK.Graphics.IGraphicsContext context, OpenTK.Platform.IWindowInfo wininf)
        {
            Graphics.context = context;
            Graphics.windowInfo = wininf;

            init = true;
        }
예제 #5
0
파일: OTKDraw.cs 프로젝트: windygu/noForms
 public OpenTK_RenderElements(OTK.Graphics.IGraphicsContext gc, int fd, int td, int fw, int tw)
 {
     graphicsContext = gc;
     FBO_Draw        = fd;
     FBO_Window      = fw;
     T2D_Draw        = td;
     T2D_Window      = tw;
     renderData      = new RenderData();
 }
예제 #6
0
        protected void Render(IGraphicsContext context, PrimitiveType mode, Subset subset)
        {
            GL.BindBuffer(BufferTarget.ArrayBuffer, _array);
            var stride = Specification.Stride;

            for (var j = 0; j < Specification.Indices.Count; j++)
            {
                var ai = Specification.Indices[j];
                GL.EnableVertexAttribArray(j);
                GL.VertexAttribPointer(j, ai.Length, ai.Type, false, stride, ai.Offset);
            }
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, _elementArray);

            GL.DrawElements(mode, subset.Count, DrawElementsType.UnsignedInt, subset.Start * sizeof(uint));

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
        }
예제 #7
0
파일: Game.cs 프로젝트: marsat02/engenious
        private void ConstructContext()
        {
            OpenTK.Graphics.GraphicsContextFlags flags = OpenTK.Graphics.GraphicsContextFlags.Default;
            int major = 1;
            int minor = 0;

            OpenTK.Platform.IWindowInfo windowInfo = Window.window.WindowInfo;
            if (System.Environment.OSVersion.Platform == PlatformID.Win32NT ||
                System.Environment.OSVersion.Platform == PlatformID.Win32S ||
                System.Environment.OSVersion.Platform == PlatformID.Win32Windows ||
                System.Environment.OSVersion.Platform == PlatformID.WinCE)
            {
                major = 4;
                minor = 4;
            }
            if (this.Context == null || this.Context.IsDisposed)
            {
                OpenTK.Graphics.ColorFormat colorFormat = new OpenTK.Graphics.ColorFormat(8, 8, 8, 8);
                int depth   = 24;//TODO: wth?
                int stencil = 8;
                int samples = 4;

                OpenTK.Graphics.GraphicsMode mode = new OpenTK.Graphics.GraphicsMode(colorFormat, depth, stencil, samples);
                try
                {
                    this.Context = new OpenTK.Graphics.GraphicsContext(mode, windowInfo, major, minor, flags);
                    //this.Context = Window.Context;
                }
                catch (Exception ex)
                {
                    mode         = OpenTK.Graphics.GraphicsMode.Default;
                    major        = 1;
                    minor        = 0;
                    flags        = OpenTK.Graphics.GraphicsContextFlags.Default;
                    this.Context = new OpenTK.Graphics.GraphicsContext(mode, windowInfo, major, minor, flags);
                }
            }

            this.Context.MakeCurrent(windowInfo);
            (this.Context as OpenTK.Graphics.IGraphicsContextInternal).LoadAll();
            ThreadingHelper.Initialize(windowInfo, major, minor, contextFlags);
            this.Context.MakeCurrent(windowInfo);
        }
예제 #8
0
 abstract public FractalEngine CreateFractalEngine(OpenTK.Graphics.IGraphicsContext graphicsContext);
예제 #9
0
        /// <summary>
        /// Dispose of current Window.
        /// </summary>
        /// <param name="disposing">If <c>false</c> we are being called from the Finalizer.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (SdlHandle != IntPtr.Zero)
            {
                if (disposing)
                {
                    // Dispose managed state (managed objects).
                    Disposed?.Invoke(this, EventArgs.Empty);
                    Application.UnregisterWindow(this);
                }

#if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGL
                // Dispose OpenGL context
                DummyGLContext?.Dispose();
                DummyGLContext = null;
                if (glContext != IntPtr.Zero)
                {
                    SDL.SDL_GL_DeleteContext(glContext);
                    glContext = IntPtr.Zero;
                }
#endif

                // Free unmanaged resources (unmanaged objects) and override a finalizer below.
                SDL.SDL_DestroyWindow(SdlHandle);
                SdlHandle = IntPtr.Zero;
                Handle = IntPtr.Zero;
            }
        }
예제 #10
0
        public void Init(int w, int h, OpenTK.Graphics.IGraphicsContext context)
        {
            Width  = w;
            Height = h;

            int temp = -99;

            GL.GetInteger(GetPName.DrawBuffer, out temp);

            //setup
            GL.GenTextures(1, out textureColor);
            GL.BindTexture(TextureTarget.Texture2D, textureColor);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.R32f, Width, Height, 0, PixelFormat.Red, PixelType.Float, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.GenTextures(1, out textureHandle0);
            GL.BindTexture(TextureTarget.Texture2D, textureHandle0);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.R32f, Width, Height, 0, PixelFormat.Red, PixelType.Float, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.GenTextures(1, out textureHandle1);
            GL.BindTexture(TextureTarget.Texture2D, textureHandle1);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.R32f, Width, Height, 0, PixelFormat.Red, PixelType.Float, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.GenTextures(1, out textureHandleRGB);
            GL.BindTexture(TextureTarget.Texture2D, textureHandleRGB);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba32f, Width, Height, 0, PixelFormat.Rgba, PixelType.Float, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.GenTextures(1, out textureDist0);
            GL.BindTexture(TextureTarget.Texture2D, textureDist0);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba32f, Width, Height, 0, PixelFormat.Rgba, PixelType.Float, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.GenTextures(1, out textureDist1);
            GL.BindTexture(TextureTarget.Texture2D, textureDist1);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba32f, Width, Height, 0, PixelFormat.Rgba, PixelType.Float, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            string version = GL.GetString(StringName.Version);

            GL.GenFramebuffers(1, out fboHandle);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, fboHandle);

            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, textureHandle0, 0);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

            GL.ActiveTexture(TextureUnit.Texture0);

            temp = -99;
            GL.GetInteger(GetPName.DrawBuffer, out temp);

            blurProgram = new ShaderProgram("Opengl\\blur.vert", "Opengl\\blur.frag", context);
            blurProgram.Link();

            coloring = new ShaderProgram("Opengl\\blur.vert", "Opengl\\color.frag", context);
            coloring.Link();

            JFA = new ShaderProgram("Opengl\\blur.vert", "Opengl\\jfa.frag", context);
            JFA.Link();

            System.GC.Collect();
            BlurData  = new float[Width * Height];
            ColorData = new float[Width * Height];
            DistData  = new float[Width * Height];
        }
예제 #11
0
 public override FractalEngine CreateFractalEngine(OpenTK.Graphics.IGraphicsContext graphicsContext)
 {
     return(new OpenCLFractalEngine(graphicsContext, this.platform, this.device));
 }
예제 #12
0
 public override FractalEngine CreateFractalEngine(OpenTK.Graphics.IGraphicsContext graphicsContext)
 {
     return(new CudaFractalEngine(this.device));
 }
예제 #13
0
        internal OpenCLFractalEngine(OpenTK.Graphics.IGraphicsContext graphicsContext, Platform platform, Device device)
        {
            if (graphicsContext == null || !(graphicsContext is OpenTK.Graphics.IGraphicsContextInternal))
            {
                throw new ArgumentException("Invalid graphics context for OpenCLFractalEngine.", "graphicsContext");
            }

            if (platform == null)
            {
                throw new ArgumentException("Invalid platform for OpenCLFractalEngine", "platform");
            }

            if (device == null)
            {
                throw new ArgumentException("Invalid device for OpenCLFractalEngine", "device");
            }

            this.platform = platform;
            this.device   = device;

            useLowProfile = !device.ImageSupport;

            IntPtr curDC = wglGetCurrentDC();

            OpenTK.Graphics.IGraphicsContextInternal gCtx = (OpenTK.Graphics.IGraphicsContextInternal)graphicsContext;

            context = OpenCL.Context.Create(new Device[] { device },
                                            new ContextParam(ContextProperties.Platform, platform),
                                            new ContextParam(ContextProperties.GlContext, gCtx.Context.Handle),
                                            new ContextParam(ContextProperties.WglHdc, curDC));

            iterBlockCount = Util.Clamp((int)device.MaxComputeUnits * 2, 2, 64);

            string source = null;

            if (useLowProfile)
            {
                source = Kernels.KernelResources.kernels_low_cl;
            }
            else
            {
                source = Kernels.KernelResources.kernels_cl;
            }

            string opts = "";

            try{
                program = OpenCL.Program.CreateFromSource(context, new string[] { source });
                program.Build(new Device[] { device }, opts);
            }
            catch (OpenCLCallFailedException ex)
            {
                if (ex.ErrorCode == OpenCL.ErrorCode.BuildProgramFailure)
                {
                    ex.Data.Add("build_log", program.GetBuildLog(device));
                }
                throw ex;
            }

            initIteratorsKernel  = Kernel.Create(program, "init_iterators_kernel");
            resetIteratorsKernel = Kernel.Create(program, "reset_iterators_kernel");
            iterateKernel        = Kernel.Create(program, "iterate_kernel");
            updateStatsKernel    = Kernel.Create(program, "update_stats_kernel");
            resetOutputKernel    = Kernel.Create(program, "reset_output_kernel");
            updateOutputKernel   = Kernel.Create(program, "update_output_kernel");
            glOutputBufferID     = 0;

            queue = CommandQueue.Create(context, device, CommandQueueFlags.ProfilingEnable);

            fractalBuffer    = context.CreateBuffer(MemFlags.ReadOnly, Marshal.SizeOf(typeof(NativeFractal)));
            branchBuffer     = context.CreateBuffer(MemFlags.ReadOnly, Marshal.SizeOf(typeof(NativeBranch)) * NativeFractal.MaxBranches);
            variWeightBuffer = context.CreateBuffer(MemFlags.ReadOnly, 4 * NativeFractal.MaxBranches * NativeFractal.MaxVariations);

            iterPosStateBuffer   = context.CreateBuffer(MemFlags.ReadWrite, (8 * IteratorCount));
            iterColorStateBuffer = context.CreateBuffer(MemFlags.ReadWrite, (8 * IteratorCount));
            iterStatBuffer       = context.CreateBuffer(MemFlags.ReadWrite, Marshal.SizeOf(typeof(NativeIterStatEntry)) * IteratorCount);
            globalStatBuffer     = context.CreateBuffer(MemFlags.ReadWrite, Marshal.SizeOf(typeof(NativeGlobalStatEntry)));

            entropyXBuffer    = context.CreateBuffer(MemFlags.ReadWrite, (16 * IteratorCount));
            entropyCBuffer    = context.CreateBuffer(MemFlags.ReadWrite, (4 * IteratorCount));
            entropySeedBuffer = context.CreateBuffer(MemFlags.ReadWrite, (4 * IteratorCount));

            uint[] seeds = new uint[IteratorCount];
            for (int i = 0; i < IteratorCount; i++)
            {
                seeds[i] = (uint)rand.Next(65536);
            }
            entropySeedBuffer.Write(queue, seeds);

            paletteSize   = new Size(0, 0);
            paletteImage  = null;
            paletteBuffer = null;
            if (!useLowProfile)
            {
                paletteSampler = Sampler.Create(context, true, AddressingMode.ClampToEdge, FilterMode.Linear);
            }

            initIteratorsKernel.SetArgs(entropyXBuffer, entropyCBuffer, entropySeedBuffer);
            Event initEvt;

            initIteratorsKernel.EnqueueLaunch(queue, IteratorCount, IterGroupSize, null, out initEvt);
            initEvt.Wait();
            disposeAndNullify(ref initEvt);

            queue.Finish();
        }