cginternals / globjects

C++ library strictly wrapping OpenGL objects.
https://globjects.org
MIT License
539 stars 59 forks source link

New binding system concept #348

Open ghost opened 7 years ago

ghost commented 7 years ago

Hello. I suggest to make new binding system. I suggest to add binding objects.

auto BufferBinding = new BufferBaseBinding(0, GL_SHADER_STORAGE_BUFFER);
BufferBinding.setBuffer(SomeBufferObject);
BufferBinding.apply();

// or Context.apply();

After will possible to just use BufferBinding.apply();. I suggest to base buffer binding on WeakPtr.

Also I suggest to make multi-bind support. https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_multi_bind.txt

auto MultiBinding = new MultiBufferBindingBase(0, GL_SHADER_STORAGE_BUFFER); 
MultiBinding.addBuffer(SomeBufferObject);
MultiBinding.addBuffer(AnotherBufferObject);

// removing buffers
MultiBinding.spliceBuffer(0);
MultiBinding.spliceBuffer(AnotherBufferObject);

MultiBinding.apply();

Also, I tired support my own OpenGL wrapper. I also planned rewrite ray tracer host code.

About ranged binding and setting.

auto Range = new Range<GLint>(0, 16);
auto Range = new Range(0, strided<GLint>(16)); // probably this (without template)

RangedBinding.setBuffer(SomeBuffer, Range);
MultiRangedBinding.addBuffer(SomeBuffer, Range);

Only, I don't know how should work multi-bind with range objects.

I suggest to multi-bind textures.

auto MultiBindTexture = new MultiTextureBinding(0); // bind from zeros
MultiBindTexture.addTexture(TextureObject); 
MultiBindTexture.apply();
MultiBindTexture.setUniformStride(UniformLocation, 48); // if uniform is array, length optional
MultiBindTexture.setUniformStride(UniformLocation, new Range(0, 48)); // if need offset from 

auto MultiBindSampler = new MultiSamplerBinding(0); // from zero texture bindings
MultiBindSampler.addSampler(SamplerObject);
MultiBindSampler.apply();

And just binding textures.

auto TextureBindingObject = new TextureBinding(0);
TextureBindingObject.setTexture(TextureObject);
TextureBindingObject.apply();
TextureBindingObject.setUniform(UniformLocation); // to uniform