OpenGL wishlist 4.0: the slot model

Time for a fourth wish-list this time i will go into more detail about one specific thing i like OpenGL to adopt, while clarifying a few things about two oldies, perhaps for openGL 5.0 but who knows.

The slot model

This model should be seen as a vision on how to unify Data and shader management within openGL, especially regarding texturing as a lot of details is actually already implemented on the geometry side, this is mostly written against the new openGL 4 specification but i make no promises of conformity.

There are three main bits to this model, these are data, slots and shaders.
Each part are separate but still connected, especially the first two.

New data model

Currently we have at least two or more ways to upload or use various forms of data.
We have vertex buffers, textures, framebuffers, uniform buffers and so on.

This model proposes that all data buffers should be unified in a similar way that vertex buffers are used, well more or less.
Currently to create a VBO, upload data and make it usable you have to do this little dance

glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER_ARB, buffer);
glBufferData(GL_ARRAY_BUFFER_ARB, sizeof(data),data,GL_DYNAMIC_DRAW_ARB);

But that won’t do if you have to load textures, also bind to edit is so out of date. So this model am suggesting something like this.

glGenBuffers(1, &buffer);
glBufferMetaData(buffer, GL_BUFFER_DATA_TYPE, GL_VERTEX_ARRAY);
glBufferMetaData(buffer, GL_HINT, GL_DYNAMIC_DRAW_ARB);
glBufferData(buffer, sizeof(data),data);

Now in the case of texturing you could end up with a lot of glBufferMetaData entries, so you should be able to use something along the lines of wglCreateContextAttribs.

int attribList[12] =
{
GL_BUFFER_DATA_TYPE, GL_TEXTURE_2D,
GL_WIDTH, 512,
GL_HEIGHT, 512,
GL_FORMAT, GL_RGBA,
GL_TEXTURE_MIPMAP, GL_TRUE,
0, 0
};
glBufferMetaDataList(buffer,attribList);

Now glBufferData is optional, you could also use other tools like glBufferFill or glGenerateMipmap and functions like that.
So using this method all data is treated equally, that means you could in theory use all data wherewer you like, also copying data is done trough the same tools.

The slots

The slots themselves that the model is named from can trace their liniage from vartex attribute arrays, within these you have to link each VBO to a number and then that number to a name within shaders.
To be honest it’s a great system and the slot model is an extension of this, the basic idea is that it should also extend this to textures, samplers, shaders, framebuffers and so on.
So instead of binding textures vertex arrays or shaders the normal way one would do it sort of like this

glBind(GL_TEXTURE_SLOT,0,buffer);
or
glBind(GL_VERTEX_SLOT,2,buffer);
or
glBind(GL_SHADER_SLOT,GL_VERTEXSHADER, shader);

On the shader side though you have to first use glBindAttribLocation and then use them in the shader, in this mode we would probably allow you to do something similar but the easiest way would be to within the shader itself call something like this

#link GL_TEXTURE_SLOT 0 texture1

The largest change though is the replacement of FBO and MRT with this slot model, simply put you link one or more textures to one or more output slots, slots that is then linked to out variables, though you might want to make sure that openGL knows about this possibility by saying so in the meta data.
Feedback mode would kinda work the same way, just bind a buffer to a feedback slot and an output variable.
It would also make it pretty easy to modify and extend VAOs to this system so that there would be similar functions for texturing, shaders and so forth.

New shader types

Object shader: this is my suggestion for a new instancing type shader, it sits before the vertex shader feeding vertics to it, it would have similar functions to the geometry shaders EmitVertex and EndPrimitive, but instead the code would look something like this

out vec4 Position;
in vec4 Positionbuffer[];   //this is basically a whole VBO

void main(void)
{
Position = SetArray(Positionbuffer[0]);
EmitArray(46);
}

The operative functions SetArray and EmitArray sets up which arrays to emit and then emit a specified number of them, in this case it would emit 46 vertics starting with the first one.
In case you want to use this as instancing you only have to put the last two lines inside a loop updating lets the matrix for each time.
Using EmitArray(1); would allow you to emit single vertics.

Blend shader: probably the most wished for, so much so that people might be a bit disappointed once it’s implemented, but here is essentially how a GL_ONE GL_ONE shader would be written

in vec4 Colorin;
out vec4 Colorout; 		//inside a blendshader this already has a value
void main(void)
{
Colorout =+ Colorin;
}

Note that only simple arithmetic could be preformed inside a blend shader, only input from the vertex shader and uniforms are allowed which means no textures, if you want texture data you have to pass it from the fragment shader.

Well that’s all I guess for now


No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

*


WordPress Themes