before i do a large data set to test, i thought i'd pick your brain first,
which of these two vbo setups for an iOS device do you think is faster? in an openGL-ES 1.x environment.
one sets up a blank main GL_ELEMENT_ARRAY_BUFFER then sub-fills with what ever index data is needed at the time using the glBufferSubData in the run loop,
other setup is to set up individual GL_ELEMENT_ARRAY_BUFFERs before hand and use the glBindBuffer in the run loop.
(in both situations below the "DrawOutShape" is the only routine within a run loop)
update: for people's future reference, i believe i've found the best way to do this in example 3: (please correct if wrong).
quick question: is there a better way to do this line "(GLushort*)(sizeof(GLushort)*shapetest2->deOffset)"
update 2: for people's future reference, in pseudo instancing, if you want instancing in iOS at this time, there is no way to setup your data in the run loop (have lots of pieces, then rotated and scaled and placed) and have a single glDrawElements at the end of the run loop to draw them all out at the same time, before starting the loop over (without making your speed worse than it is), you have to have a glDrawElements for each "shape" in your run loop unfortunately.... i've determined if openGL-ES or Apple in a future version, made it so that you could have instancing with a single glDrawElements, this can increase FPS by a significant amount, like 5 times. it is a brick wall that is holding ES back speedwise IMO.
example 1:
static const GLushort test2Trips[] =
{
24, 25, 27, 25, 26, 27,
28, 29, 31, 29, 30, 31,
32, 33, 35, 33, 34, 35,
36, 37, 39, 37, 38, 39,
40, 41, 43, 41, 42, 43,
44, 45, 47, 45, 46, 47,
48, 49, 51, 49, 50, 51,
52, 53, 55, 53, 54, 55,
56, 57, 59, 57, 58, 59,
60, 61, 63, 61, 62, 63,
64, 65, 67, 65, 66, 67,
68, 69, 71, 69, 70, 71,
};
//-------------------------
static inline void shapetest2Setup(void)
{
shapetest2 = malloc(sizeof(shapeBase));
shapetest2->stripsName[1] = NULL;
shapetest2->tripsName = &test2Trips;
shapetest2->fansName = NULL;
shapetest2->dataName = &test2Data;
shapetest2->totStrips = 0;
shapetest2->stripsNum[1] = 0;
shapetest2->tripsNum = 72;
shapetest2->totFans = 0;
shapetest2->listOfInserts = NULL;
shapetest2->center = Vertex3DMake( 0.000000, -0.000000, 2.000000 );
shapetest2->radius = Vertex3DMake( 1.000000, 1.000000, 2.000000 );
shapetest2->indexSize = sizeof(test2Trips);
shapetest2->deOffset = 24;
dataSize += sizeof(test2Data);
if (sizeof(test2Trips) >开发者_如何转开发 indexSize) indexSize = sizeof(test2Trips);
}
// endOfShapetest2
//--------------------------------------------------------
//-------------------------
static inline void CreateVBOs(void)
{
GLsizeiptr theDataSize = 0;
glGenBuffers(1, &mainBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mainBuffer);
glBufferData(GL_ARRAY_BUFFER, dataSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, theDataSize, sizeof(test1Data), test1Data);
theDataSize += sizeof(test1Data);
glBufferSubData(GL_ARRAY_BUFFER, theDataSize, sizeof(test2Data), test2Data);
glGenBuffers(1, &mainIndex);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mainIndex);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize, NULL, GL_STATIC_DRAW);
}
//------------------------------------------------------
static inline void DrawOutShape(void)
{
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, shapetest2->indexSize, shapetest2->tripsName);
glDrawElements(GL_TRIANGLES, shapetest2->tripsNum, GL_UNSIGNED_SHORT, (void*)0);
}
example 2:
static const GLushort test2Trips[] =
{
24, 25, 27, 25, 26, 27,
28, 29, 31, 29, 30, 31,
32, 33, 35, 33, 34, 35,
36, 37, 39, 37, 38, 39,
40, 41, 43, 41, 42, 43,
44, 45, 47, 45, 46, 47,
48, 49, 51, 49, 50, 51,
52, 53, 55, 53, 54, 55,
56, 57, 59, 57, 58, 59,
60, 61, 63, 61, 62, 63,
64, 65, 67, 65, 66, 67,
68, 69, 71, 69, 70, 71,
};
//-------------------------
static inline void shapetest2Setup(void)
{
shapetest2 = malloc(sizeof(shapeBase));
shapetest2->stripsName[1] = NULL;
shapetest2->tripsName = &test2Trips;
shapetest2->fansName = NULL;
shapetest2->dataName = &test2Data;
shapetest2->totStrips = 0;
shapetest2->stripsNum[1] = 0;
shapetest2->tripsNum = 72;
shapetest2->totFans = 0;
shapetest2->listOfInserts = NULL;
shapetest2->center = Vertex3DMake( 0.000000, -0.000000, 2.000000 );
shapetest2->radius = Vertex3DMake( 1.000000, 1.000000, 2.000000 );
shapetest2->indexSize = sizeof(test2Trips);
shapetest2->deOffset = 24;
dataSize += sizeof(test2Data);
if (sizeof(test2Trips) > indexSize) indexSize = sizeof(test2Trips);
glGenBuffers(1, &shapetest2->indexName);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, shapetest2->indexName);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(test2Trips), test2Trips, GL_STATIC_DRAW);
}
// endOfShapetest2
//--------------------------------------------------------
//-------------------------
static inline void CreateVBOs(void)
{
GLsizeiptr theDataSize = 0;
glGenBuffers(1, &mainBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mainBuffer);
glBufferData(GL_ARRAY_BUFFER, dataSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, theDataSize, sizeof(test1Data), test1Data);
theDataSize += sizeof(test1Data);
glBufferSubData(GL_ARRAY_BUFFER, theDataSize, sizeof(test2Data), test2Data);
}
//------------------------------------------------------
static inline void DrawOutShape(void)
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, shapetest2->indexName);
glDrawElements(GL_TRIANGLES, shapetest2->tripsNum, GL_UNSIGNED_SHORT, (void*)0);
}
example 3:
static const GLushort test1Trips[] =
{
0, 1, 3, 1, 2, 3,
4, 5, 7, 5, 6, 7,
8, 9, 11, 9, 10, 11,
12, 13, 15, 13, 14, 15,
16, 17, 19, 17, 18, 19,
20, 21, 23, 21, 22, 23,
};
static const GLushort test2Trips[] =
{
24, 25, 27, 25, 26, 27,
28, 29, 31, 29, 30, 31,
32, 33, 35, 33, 34, 35,
36, 37, 39, 37, 38, 39,
40, 41, 43, 41, 42, 43,
44, 45, 47, 45, 46, 47,
48, 49, 51, 49, 50, 51,
52, 53, 55, 53, 54, 55,
56, 57, 59, 57, 58, 59,
60, 61, 63, 61, 62, 63,
64, 65, 67, 65, 66, 67,
68, 69, 71, 69, 70, 71,
};
//-------------------------
static inline void shapetest2Setup(void)
{
shapetest2 = malloc(sizeof(shapeBase));
shapetest2->stripsName[1] = NULL;
shapetest2->tripsName = &test2Trips;
shapetest2->fansName = NULL;
shapetest2->dataName = &test2Data;
shapetest2->totStrips = 0;
shapetest2->stripsNum[1] = 0;
shapetest2->tripsNum = 72;
shapetest2->totFans = 0;
shapetest2->listOfInserts = NULL;
shapetest2->center = Vertex3DMake( 0.000000, -0.000000, 2.000000 );
shapetest2->radius = Vertex3DMake( 1.000000, 1.000000, 2.000000 );
shapetest2->indexSize = sizeof(test2Trips);
shapetest2->deOffset = 24;
dataSize += sizeof(test2Data);
indexSize += sizeof(test2Trips);
}
// endOfShapetest2
//--------------------------------------------------------
//-------------------------
static inline void CreateVBOs(void)
{
GLintptr theDataOffset = 0;
GLintptr theIndexOffset = 0;
glGenBuffers(1, &mainBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mainBuffer);
glBufferData(GL_ARRAY_BUFFER, dataSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, theDataOffset, sizeof(test1Data), test1Data);
theDataOffset += sizeof(test1Data);
glBufferSubData(GL_ARRAY_BUFFER, theDataOffset, sizeof(test2Data), test2Data);
theDataOffset += sizeof(test2Data);
glGenBuffers(1, &mainIndex);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mainIndex);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, theIndexOffset, sizeof(test1Trips), test1Trips);
theIndexOffset += sizeof(test1Trips);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, theIndexOffset, sizeof(test2Trips), test2Trips);
theIndexOffset += sizeof(test2Trips);
}
//------------------------------------------------------
static inline void DrawOutShape(void)
{
glDrawElements(GL_TRIANGLES, shapetest2->tripsNum, GL_UNSIGNED_SHORT, (GLushort*)(sizeof(GLushort)*shapetest2->deOffset));
}
精彩评论