示例#1
0
 protected override void DoInitialize()
 {
     this.buildListsRenderer.Initialize();
     this.resolve_lists.Initialize();
     {
         var texture = new Texture(TextureTarget.Texture2D,
                                   new NullImageFiller(MAX_FRAMEBUFFER_WIDTH, MAX_FRAMEBUFFER_HEIGHT, OpenGL.GL_R32UI, OpenGL.GL_RED_INTEGER, OpenGL.GL_UNSIGNED_BYTE),
                                   new SamplerParameters(TextureWrapping.Repeat, TextureWrapping.Repeat, TextureWrapping.Repeat, TextureFilter.Nearest, TextureFilter.Nearest));
         texture.Initialize();
         this.headTexture = texture;
         OpenGL.BindImageTexture(0, this.headTexture.Id, 0, true, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_R32UI);
     }
     // Create buffer for clearing the head pointer texture
     //var buffer = new IndependentBuffer<uint>(BufferTarget.PixelUnpackBuffer, BufferUsage.StaticDraw, false);
     using (var buffer = new PixelUnpackBuffer <uint>(BufferUsage.StaticDraw, false))
     {
         buffer.Create(MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT);
         // NOTE: not all initial values are zero in this unmanged array.
         //unsafe
         //{
         //    var array = (uint*)buffer.Header.ToPointer();
         //    for (int i = 0; i < MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT; i++)
         //    {
         //        array[i] = 0;
         //    }
         //}
         this.headClearBufferPtr = buffer.GetBufferPtr() as PixelUnpackBufferPtr;
     }
     // Create the atomic counter buffer
     using (var buffer = new AtomicCounterBuffer <uint>(BufferUsage.DynamicCopy, false))
     {
         buffer.Create(1);
         this.atomicCountBufferPtr = buffer.GetBufferPtr() as AtomicCounterBufferPtr;
     }
     // Bind it to a texture (for use as a TBO)
     using (var buffer = new TextureBuffer <vec4>(BufferUsage.DynamicCopy, noDataCopyed: false))
     {
         buffer.Create(elementCount: MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT * 3);
         IndependentBufferPtr bufferPtr = buffer.GetBufferPtr();
         Texture texture = bufferPtr.DumpBufferTexture(OpenGL.GL_RGBA32UI, autoDispose: true);
         texture.Initialize();
         bufferPtr.Dispose();// dispose it ASAP.
         this.linkedListTexture = texture;
     }
     {
         OpenGL.BindImageTexture(1, this.linkedListTexture.Id, 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA32UI);
     }
     OpenGL.ClearDepth(1.0f);
 }
示例#2
0
        private void UpdateResources(int width, int height)
        {
            {
                if (this.headTexture != null)
                {
                    this.headTexture.Dispose();
                }

                int  level = 0, border = 0;
                uint internalformat = GL.GL_R32UI, format = GL.GL_RED_INTEGER, type = GL.GL_UNSIGNED_BYTE;
                var  storage = new TexImage2D(TexImage2D.Target.Texture2D, level, internalformat, width, height, border, format, type);
                var  texture = new Texture(TextureTarget.Texture2D, storage,
                                           TexParameter.Create(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT),
                                           TexParameter.Create(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT),
                                           TexParameter.Create(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT),
                                           TexParameter.Create(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_NEAREST),
                                           TexParameter.Create(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_NEAREST)
                                           );
                texture.Initialize();

                this.headTexture = texture;
            }
            // Create buffer for clearing the head pointer texture
            {
                if (this.headClearBuffer != null)
                {
                    this.headClearBuffer.Dispose();
                }

                int length = width * height;
                // NOTE: not all initial values are zero in this unmanged array.
                PixelUnpackBuffer buffer = PixelUnpackBuffer.Create(typeof(uint), length, BufferUsage.StaticDraw);
                // initialize buffer's value to 0.
                //unsafe
                //{
                //    IntPtr pointer = ptr.MapBuffer(MapBufferAccess.WriteOnly);
                //    var array = (uint*)pointer.ToPointer();
                //    for (int i = 0; i < MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT; i++)
                //    {
                //        array[i] = 0;
                //    }
                //}
                // another way to initialize buffer's value to 0.
                //using (var data = new UnmanagedArray<uint>(1))
                //{
                //    data[0] = 0;
                //    ptr.ClearBufferData(OpenGL.GL_UNSIGNED_INT, OpenGL.GL_RED, OpenGL.GL_UNSIGNED_INT, data);
                //}

                this.headClearBuffer = buffer;
            }
            // Bind it to a texture (for use as a TBO)
            {
                if (this.linkedListTexture != null)
                {
                    this.linkedListTexture.Dispose();
                }

                int           length         = width * height * 3;
                TextureBuffer buffer         = TextureBuffer.Create(typeof(vec4), length, BufferUsage.DynamicCopy);
                uint          internalFormat = GL.GL_RGBA32UI;
                Texture       texture        = buffer.DumpBufferTexture(internalFormat, autoDispose: true);
                texture.Initialize();
                buffer.Dispose();// dispose it ASAP.

                this.linkedListTexture = texture;
            }
        }
 protected override void DoInitialize()
 {
     this.buildListsRenderer.Initialize();
     this.resolve_lists.Initialize();
     {
         var texture = new Texture(TextureTarget.Texture2D,
             new NullImageFiller(MAX_FRAMEBUFFER_WIDTH, MAX_FRAMEBUFFER_HEIGHT, OpenGL.GL_R32UI, OpenGL.GL_RED_INTEGER, OpenGL.GL_UNSIGNED_BYTE),
             new SamplerParameters(TextureWrapping.Repeat, TextureWrapping.Repeat, TextureWrapping.Repeat, TextureFilter.Nearest, TextureFilter.Nearest));
         texture.Initialize();
         this.headTexture = texture;
         OpenGL.BindImageTexture(0, this.headTexture.Id, 0, true, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_R32UI);
     }
     // Create buffer for clearing the head pointer texture
     {
         const int length = MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT;
         PixelUnpackBuffer buffer = PixelUnpackBuffer.Create(typeof(uint), length, BufferUsage.StaticDraw);
         // NOTE: not all initial values are zero in this unmanged array.
         // initialize buffer's value to 0.
         //unsafe
         //{
         //    IntPtr pointer = ptr.MapBuffer(MapBufferAccess.WriteOnly);
         //    var array = (uint*)pointer.ToPointer();
         //    for (int i = 0; i < MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT; i++)
         //    {
         //        array[i] = 0;
         //    }
         //}
         // another way to initialize buffer's value to 0.
         //using (var data = new UnmanagedArray<uint>(1))
         //{
         //    data[0] = 0;
         //    ptr.ClearBufferData(OpenGL.GL_UNSIGNED_INT, OpenGL.GL_RED, OpenGL.GL_UNSIGNED_INT, data);
         //}
         this.headClearBuffer = buffer;
     }
     // Create the atomic counter buffer
     {
         const int length = 1;
         AtomicCounterBuffer buffer = AtomicCounterBuffer.Create(typeof(uint), length, BufferUsage.DynamicCopy);
         // another way to do this:
         //uint data = 1;
         //AtomicCounterBuffer buffer = data.GenAtomicCounterBuffer(BufferUsage.DynamicCopy);
         this.atomicCountBuffer = buffer;
     }
     // Bind it to a texture (for use as a TBO)
     {
         const int length = MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT * 3;
         TextureBuffer buffer = TextureBuffer.Create(typeof(vec4), length, BufferUsage.DynamicCopy);
         Texture texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32UI, autoDispose: true);
         texture.Initialize();
         buffer.Dispose();// dispose it ASAP.
         this.linkedListTexture = texture;
     }
     {
         //TextureBuffer buffer = TextureBuffer.Create()
     }
     {
         OpenGL.BindImageTexture(1, this.linkedListTexture.Id, 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA32UI);
     }
     OpenGL.ClearDepth(1.0f);
 }
示例#4
0
 protected override void DoInitialize()
 {
     this.buildListsRenderer.Initialize();
     this.resolve_lists.Initialize();
     {
         var texture = new Texture(TextureTarget.Texture2D,
                                   new NullImageFiller(MAX_FRAMEBUFFER_WIDTH, MAX_FRAMEBUFFER_HEIGHT, OpenGL.GL_R32UI, OpenGL.GL_RED_INTEGER, OpenGL.GL_UNSIGNED_BYTE),
                                   new SamplerParameters(TextureWrapping.Repeat, TextureWrapping.Repeat, TextureWrapping.Repeat, TextureFilter.Nearest, TextureFilter.Nearest));
         texture.Initialize();
         this.headTexture = texture;
         OpenGL.BindImageTexture(0, this.headTexture.Id, 0, true, 0, OpenGL.GL_READ_WRITE, OpenGL.GL_R32UI);
     }
     // Create buffer for clearing the head pointer texture
     {
         const int         length = MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT;
         PixelUnpackBuffer buffer = PixelUnpackBuffer.Create(typeof(uint), length, BufferUsage.StaticDraw);
         // NOTE: not all initial values are zero in this unmanged array.
         // initialize buffer's value to 0.
         //unsafe
         //{
         //    IntPtr pointer = ptr.MapBuffer(MapBufferAccess.WriteOnly);
         //    var array = (uint*)pointer.ToPointer();
         //    for (int i = 0; i < MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT; i++)
         //    {
         //        array[i] = 0;
         //    }
         //}
         // another way to initialize buffer's value to 0.
         //using (var data = new UnmanagedArray<uint>(1))
         //{
         //    data[0] = 0;
         //    ptr.ClearBufferData(OpenGL.GL_UNSIGNED_INT, OpenGL.GL_RED, OpenGL.GL_UNSIGNED_INT, data);
         //}
         this.headClearBuffer = buffer;
     }
     // Create the atomic counter buffer
     {
         const int           length = 1;
         AtomicCounterBuffer buffer = AtomicCounterBuffer.Create(typeof(uint), length, BufferUsage.DynamicCopy);
         // another way to do this:
         //uint data = 1;
         //AtomicCounterBuffer buffer = data.GenAtomicCounterBuffer(BufferUsage.DynamicCopy);
         this.atomicCountBuffer = buffer;
     }
     // Bind it to a texture (for use as a TBO)
     {
         const int     length  = MAX_FRAMEBUFFER_WIDTH * MAX_FRAMEBUFFER_HEIGHT * 3;
         TextureBuffer buffer  = TextureBuffer.Create(typeof(vec4), length, BufferUsage.DynamicCopy);
         Texture       texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32UI, autoDispose: true);
         texture.Initialize();
         buffer.Dispose();// dispose it ASAP.
         this.linkedListTexture = texture;
     }
     {
         //TextureBuffer buffer = TextureBuffer.Create()
     }
     {
         OpenGL.BindImageTexture(1, this.linkedListTexture.Id, 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA32UI);
     }
     OpenGL.ClearDepth(1.0f);
 }