protected override void DoInitialize()
 {
     {
         // particleSimulator-fountain.comp is also OK.
         var shaderCode = new ShaderCode(File.ReadAllText(@"shaders\ParticleSimulatorRenderer\particleSimulator.comp"), ShaderType.ComputeShader);
         this.computeProgram = shaderCode.CreateProgram();
     }
     {
         BufferPtr bufferPtr = this.positionBufferPtr;
         Texture   texture   = bufferPtr.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
         texture.Initialize();
         this.positionTexture = texture;
     }
     {
         BufferPtr bufferPtr = this.velocityBufferPtr;
         Texture   texture   = bufferPtr.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
         texture.Initialize();
         this.velocityTexture = texture;
     }
     {
         IndependentBufferPtr bufferPtr = null;
         using (var buffer = new UniformBuffer <vec4>(BufferUsage.DynamicCopy, noDataCopyed: true))
         {
             buffer.Create(elementCount: 64);
             bufferPtr = buffer.GetBufferPtr();
         }
         bufferPtr.Bind();
         OpenGL.BindBufferBase((BindBufferBaseTarget)BufferTarget.UniformBuffer, 0, bufferPtr.BufferId);
         this.attractorBufferPtr = bufferPtr;
         bufferPtr.Unbind();
     }
 }
Example #2
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);
 }
Example #3
0
        /// <summary>
        /// 将此Buffer的数据上传到GPU内存,并获取在GPU上的指针。执行此方法后,此对象中的非托管内存即可释放掉,不再占用CPU内存。
        /// Uploads this buffer to GPU memory and gets its pointer.
        /// It's totally OK to free memory of unmanaged array stored in this buffer object after this method invoked.
        /// </summary>
        /// <returns></returns>
        public IndependentBufferPtr GetBufferPtr()
        {
            if (bufferPtr == null)
            {
                if (glGenBuffers == null)
                {
                    glGenBuffers = OpenGL.GetDelegateFor <OpenGL.glGenBuffers>();
                    glBindBuffer = OpenGL.GetDelegateFor <OpenGL.glBindBuffer>();
                    glBufferData = OpenGL.GetDelegateFor <OpenGL.glBufferData>();
                }

                bufferPtr = Upload2GPU();
            }

            return(bufferPtr);
        }