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();
            }
            {
                GLBuffer buffer  = this.positionBuffer;
                Texture  texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
                texture.Initialize();
                this.positionTexture = texture;
            }
            {
                GLBuffer buffer  = this.velocityBuffer;
                Texture  texture = buffer.DumpBufferTexture(OpenGL.GL_RGBA32F, autoDispose: false);
                texture.Initialize();
                this.velocityTexture = texture;
            }
            {
                const int     length = 64;
                UniformBuffer buffer = UniformBuffer.Create(typeof(vec4), length, BufferUsage.DynamicCopy);
                buffer.Bind();
                OpenGL.BindBufferBase((BindBufferBaseTarget)BufferTarget.UniformBuffer, 0, buffer.BufferId);
                buffer.Unbind();
                this.attractorBuffer = buffer;

                OpenGL.CheckError();
            }
        }
Ejemplo n.º 2
0
 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();
     }
 }
Ejemplo n.º 3
0
        protected override void DoRender(RenderEventArgs arg)
        {
            {
                this.computeProgram.Bind();
                // Also bind created texture ...
                this.texture.Bind();
                // ... and bind this texture as an image, as we will write to it. see binding = 0 in shader.
                //glBindImageTexture(0, g_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
                OpenGL.BindImageTexture(0, this.texture.Id, 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA8);
                //glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, g_directionSSBO);
                OpenGL.BindBufferBase(BindBufferBaseTarget.ShaderStorageBuffer, 1, this.g_directionSSBO.BufferId);
                //glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, g_positionSSBO);
                OpenGL.BindBufferBase(BindBufferBaseTarget.ShaderStorageBuffer, 2, this.g_positionSSBO.BufferId);
                //glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, g_stackSSBO);
                OpenGL.BindBufferBase(BindBufferBaseTarget.ShaderStorageBuffer, 3, this.g_stackSSBO.BufferId);
                //glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, g_sphereSSBO);
                OpenGL.BindBufferBase(BindBufferBaseTarget.ShaderStorageBuffer, 4, this.g_sphereSSBO.BufferId);
                //glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, g_pointLightSSBO);
                OpenGL.BindBufferBase(BindBufferBaseTarget.ShaderStorageBuffer, 3, this.g_pointLightSSBO.BufferId);
            }
            {
                //mat4 mvp = arg.Camera.GetProjectionMatrix() * arg.Camera.GetViewMatrix();
                this.computeProgram.Bind();
                OpenGL.GetDelegateFor <OpenGL.glDispatchCompute>()(WIDTH / g_localSize, HEIGHT / g_localSize, 1);
                this.computeProgram.Unbind();

                this.Program.Bind();
                this.texture.Bind();
                // ... and bind this texture as an image, as we will write to it. see binding = 0 in shader.
                //glBindImageTexture(0, g_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
                OpenGL.BindImageTexture(0, this.texture.Id, 0, false, 0, OpenGL.GL_WRITE_ONLY, OpenGL.GL_RGBA8);

                mat4 mvp = arg.Camera.GetProjectionMatrix() * arg.Camera.GetViewMatrix();
                this.SetUniform("mvp", mvp);
                base.DoRender(arg);
            }
        }