0

Im learning opengl and using examples of VBOs which consists of a color array, a vertex array, a normals array and index array to be used by GL.DrawElements() and the structure looks like(a dot mean next element/item):

 Rgba.Rgba.Rgba.....Xyz.Xyz.Xyz.Xyz....n1n2n3.n1n2n3.n1n2n3.....ijklmn.ijklmn.ijklmn

I need them to be used as:

 R.R.R.R.R....g.g.g.g.g......b.b.b.b.b.....a.a.a.a.a.a.....X.X.X.X.X.X....y.y.y.y.y.y..
 ...z.z.z.z.z.z.......n1.n1.n1.n1.n1.n1......n2.n2.n2.n2.n2.n2.n2......n3.n3.n3.n3.n3...
 ...i.i.i.i.i.i......j.j.j.j.j.j.j.j......k.k.k.k.k.k.k.k.k

because Im using buffers' data for opencl kernel as cl-gl-interop and the first type structure makes strided memory accesses which chops the performance of main memory access because Im using only one component of each element/item such as only "x" or only "r". But the second type structure is using all memory banks equally and fits for my needs. Is this kind of structure usable/suitable for opengl drawing operations?

1 Answer 1

1

You normally pass images as textures. In your case you'd use either 3 separate textures or a 3 layer texture array which you combine into a RGB tuple in the fragment shader.

The geometry data (XYZ) you'd pass as 3 separate 1-component vertex attributes with 0 stride and each attribute offset pointing to the beginning of the respective data.

Sign up to request clarification or add additional context in comments.

5 Comments

How can I tell opengl that a buffer is 1-component vertex attribute? Im noob. If there is a stride hint, then that must be an optimizaiton parameter that we can choose freely as long as there is enough memory?
@huseyintugrulbuyukisik the second argument of glVertexAttribPointer
But I would need to change elementarray data ?
Im using opentk I wish it has shader wrappers.
@huseyintugrulbuyukisik this won't work without shaders. You need to use the shaders to take the one-component data and put it together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.