protected override void DoInitialize() { base.DoInitialize(); // 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); // Reset atomic counter IntPtr data = buffer.MapBuffer(MapBufferAccess.WriteOnly); unsafe { var array = (uint *)data.ToPointer(); array[0] = 0; } buffer.UnmapBuffer(); this.atomicCounterBuffer = buffer; } { this.depthTestState = new DepthTestState(false); this.cullFaceState = new CullFaceState(false); } }
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); }
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); }