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(); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="internalFormat"></param> /// <param name="elementCount"></param> /// <param name="usage"></param> /// <param name="noDataCopyed"></param> /// <returns></returns> public static Texture CreateBufferTexture <T>(uint internalFormat, int elementCount, BufferUsage usage, bool noDataCopyed = false) where T : struct { var buffer = new TextureBuffer <T>(usage, noDataCopyed); buffer.Create(elementCount); BufferPtr bufferPtr = buffer.GetBufferPtr(); return(bufferPtr.DumpBufferTexture(internalFormat, autoDispose: true)); }
/// <summary> /// Dump a <see cref="Texture"/> filled with this <see cref="BufferPtr"/>. /// </summary> /// <param name="bufferPtr"></param> /// <param name="internalFormat"></param> /// <param name="autoDispose">Dispose <paramref name="bufferPtr"/> when disposing returned texture.</param> /// <returns></returns> public static Texture DumpBufferTexture(this BufferPtr bufferPtr, uint internalFormat, bool autoDispose) { var texture = new Texture(TextureTarget.TextureBuffer, new TexBufferImageFiller(internalFormat, bufferPtr, autoDispose), new NullSampler()); texture.Initialize(); return(texture); }
/// <summary> /// /// </summary> /// <param name="internalFormat"></param> /// <param name="bufferPtr"></param> /// <param name="autoDispose">Dispose <paramref name="bufferPtr"/> when disposing returned texture.</param> /// <returns></returns> public static Texture CreateBufferTexture(uint internalFormat, BufferPtr bufferPtr, bool autoDispose) { return(bufferPtr.DumpBufferTexture(internalFormat, autoDispose)); }
public ParticleComputeRenderer(BufferPtr positionBufferPtr, BufferPtr velocityBufferPtr) { this.positionBufferPtr = positionBufferPtr; this.velocityBufferPtr = velocityBufferPtr; }