A
A
Anton Nadtoka2016-08-06 10:01:33
Android
Anton Nadtoka, 2016-08-06 10:01:33

One shader or for each sprite in OpenGL ES2?

The question is, I can't figure it out. There is an iOS application in which you need to display graphics through OpenGL ES2 in C ++. Initialization, loading of textures is. The question arose as follows:
There are several different sprites with different textures, all sprites of the same shape - a square (2 polygons).
There are several polygonal sprites, where each sprite is several 3+ polygons.
Each sprite can move in X,Y. Change scale. Do you need to make vertex & fragment shaders for each sprite or can you make it universal for both variants of sprites?
Need to maintain:
1. Scale (float)
2. Movement (float,float)
3. Dimensions (float,float)
4. Texture coordinates (float,float,float)
Как лучше в спрайте хранить координаты - массивом или отдельными переменными.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Виталий Столяров, 2016-08-06
@Ni55aN

Лучше использовать один, так как переключение шейдеров дорого обходится

A
Anton Nadtoka, 2016-08-08
@engune

I created a buffer:
glGenBuffers(1, &vbo_object);
glBindBuffer(GL_ARRAY_BUFFER, vbo_object);
glBufferData(GL_ARRAY_BUFFER, size, data, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
the sprites themselves are in classes that have their own x,y (coordinates), u,v (texture coordinates) - I can convert this to an array. Sprites, let's say 100 pieces, then write separate float arrays into one VBO buffer.
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float) * nSize * 4, &pVertex); -> so update?
glBufferData(GL_ARRAY_BUFFER, nSize, &pVertex[0], GL_DYNAMIC_DRAW); -> so update?
let's say on each frame you need to shift the coordinates of each sprite at different times. Rewrite VBO every time or is there a better way? Is it possible to pass a VBO buffer to all sprites? Or every time a frame is rendered - always update the VBO?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question