это чертовски раздражает меня.
Я реструктурировал некрасивый код, который генерирует пару индексных массивов. насколько я вижу, все должно быть идентично. Я записал элементы массивов в обоих случаях; генерируются массивы одинакового размера и заполняются одними и теми же данными. Создаются те же идентификаторы буфера ... но старый код работает, а новый код дает сбой.
Может кто-нибудь помочь?
- (void) setupIndexArray_
{
NSLog(@"OLD (works)");
// shape with centerpoint (4 triangles)
#define INDICES_FOR_SHAPE 10
// fill out indices for the first button
static GLushort shapeIndices[INDICES_FOR_SHAPE * NUM_QUADS] = {2, 2, 0, 1, 4, 4, 0, 3, 2, 2};
indexCount_background = INDICES_FOR_SHAPE * NUM_QUADS;
// make the remaining 11 buttons the same pattern
for (int j=INDICES_FOR_SHAPE; j < indexCount_background; j++)
shapeIndices[j] = shapeIndices[j-INDICES_FOR_SHAPE] + VERTICES_FOR_BUTTON;
glGenBuffers( 1, & indexBufID_btnBg );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBufID_btnBg );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof( shapeIndices ), shapeIndices, GL_STATIC_DRAW );
NSLog(@"BufID: %d", (int) indexBufID_btnBg);
NSLog(@"writing %d bytes... ", (int) sizeof( shapeIndices ));
for (int j=0; j < sizeof( shapeIndices ) / sizeof( GLushort ); j++)
printf( "%d,", shapeIndices[j] );
printf("\n");
//for (int j=0; j < indexCount_background; j++)
// printf("%d,",shapeIndices[j]);
// - - -
// text rect (2 triangles)
#define INDICES_FOR_TEXTRECT 6
GLushort textIndices[INDICES_FOR_TEXTRECT * NUM_QUADS] = {5, 5, 8, 6, 7, 7};
indexCount_text = INDICES_FOR_TEXTRECT * NUM_QUADS;
// glGenBuffers( 1, & indexBufID_btnText );
// make the remaining 11 buttons the same pattern
for (int j=INDICES_FOR_TEXTRECT; j < indexCount_text; j++)
textIndices[j] = textIndices[j-INDICES_FOR_TEXTRECT] + VERTICES_FOR_BUTTON;
glGenBuffers( 1, & indexBufID_btnText );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBufID_btnText );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof( textIndices ), textIndices, GL_STATIC_DRAW );
NSLog(@"BufID: %d", (int) indexBufID_btnText);
NSLog(@"writing %d bytes... ", (int) sizeof( textIndices ));
for (int j=0; j < sizeof( textIndices ) / sizeof( GLushort ); j++)
printf( "%d,", textIndices[j] );
}
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// make triangle-shapes for each button-background-shape
// and text-quad from vertex-array
- (void) setupIndexArray
{
NSLog(@"NEW (fails)");
// SHAPE
static GLushort shapeIndexPattern [] = {2, 2, 0, 1, 4, 4, 0, 3, 2, 2};
[self createIABufForPattern: shapeIndexPattern
bytes: sizeof(shapeIndexPattern)
vertexArrayStep: VERTICES_FOR_BUTTON
makingClones: 12
returningBufID: & indexBufID_btnBg ];
// TEXT
static GLushort textIndexPattern [] = {5, 5, 8, 6, 7, 7};
[self createIABufForPattern: textIndexPattern
bytes: sizeof(textIndexPattern)
vertexArrayStep: VERTICES_FOR_BUTTON
makingClones: 12
returningBufID: & indexBufID_btnText ];
}
- (void) createIABufForPattern: (GLushort *) pattern
bytes: (size_t) bytesPattern
vertexArrayStep: (int) STEP
makingClones: (int) copies
returningBufID: (GLuint *) pBufID
{
size_t eltsPattern = bytesPattern / sizeof( GLushort );
size_t eltsTotal = eltsPattern * copies;
size_t bytesTotal = bytesPattern * copies;
GLushort * array = (GLushort *) malloc( bytesTotal );
// copy pattern into big array
memcpy( (void *) array,
( const void *) pattern,
bytesPattern );
// make the remaining items follow the same pattern
for (int j = eltsPattern; j < eltsTotal; j++)
array[j] = array[ j - eltsPattern ] + STEP;
GLuint bufID;
glGenBuffers( 1, & bufID );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, bufID );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, bytesTotal, array, GL_STATIC_DRAW );
NSLog(@"BufID: %d", (int) bufID);
NSLog(@"writing %d bytes... ", (int) bytesTotal);
for (int j=0; j < eltsTotal; j++)
printf( "%d,", array[j] );
printf("\n");
free (array);
* pBufID = bufID;
}
А вот и вывод (идентичный):
2011-03-17 14:53:10.010 glWheel1[321:207] OLD (works)
2011-03-17 14:53:10.016 glWheel1[321:207] BufID: 2
2011-03-17 14:53:10.018 glWheel1[321:207] writing 240 bytes...
2,2,0,1,4,4,0,3,2,2,11,11,9,10,13,13,9,12,11,11,20,20,18,19,22,22,18,21,20,20,29,29,27,28,31,31,27,30,29,29,38,38,36,37,40,40,36,39,38,38,47,47,45,46,49,49,45,48,47,47,56,56,54,55,58,58,54,57,56,56,65,65,63,64,67,67,63,66,65,65,74,74,72,73,76,76,72,75,74,74,83,83,81,82,85,85,81,84,83,83,92,92,90,91,94,94,90,93,92,92,101,101,99,100,103,103,99,102,101,101,
2011-03-17 14:53:10.022 glWheel1[321:207] BufID: 3
2011-03-17 14:53:10.023 glWheel1[321:207] writing 144 bytes...
5,5,8,6,7,7,14,14,17,15,16,16,23,23,26,24,25,25,32,32,35,33,34,34,41,41,44,42,43,43,50,50,53,51,52,52,59,59,62,60,61,61,68,68,71,69,70,70,77,77,80,78,79,79,86,86,89,87,88,88,95,95,98,96,97,97,104,104,107,105,106,106,
2011-03-17 14:54:11.015 glWheel1[365:207] NEW (fails)
2011-03-17 14:54:11.018 glWheel1[365:207] BufID: 2
2011-03-17 14:54:11.020 glWheel1[365:207] writing 240 bytes...
2,2,0,1,4,4,0,3,2,2,11,11,9,10,13,13,9,12,11,11,20,20,18,19,22,22,18,21,20,20,29,29,27,28,31,31,27,30,29,29,38,38,36,37,40,40,36,39,38,38,47,47,45,46,49,49,45,48,47,47,56,56,54,55,58,58,54,57,56,56,65,65,63,64,67,67,63,66,65,65,74,74,72,73,76,76,72,75,74,74,83,83,81,82,85,85,81,84,83,83,92,92,90,91,94,94,90,93,92,92,101,101,99,100,103,103,99,102,101,101,
2011-03-17 14:54:11.024 glWheel1[365:207] BufID: 3
2011-03-17 14:54:11.025 glWheel1[365:207] writing 144 bytes...
5,5,8,6,7,7,14,14,17,15,16,16,23,23,26,24,25,25,32,32,35,33,34,34,41,41,44,42,43,43,50,50,53,51,52,52,59,59,62,60,61,61,68,68,71,69,70,70,77,77,80,78,79,79,86,86,89,87,88,88,95,95,98,96,97,97,104,104,107,105,106,106,